/classify allows custom prompt for LLM api
| @@ -921,7 +921,7 @@ async function setSpriteSetCommand(_, folder) { | ||
| 921 | 921 | return ''; |
| 922 | 922 | } |
| 923 | 923 | |
| 924 | 924 | async function classifyCallback(/** @type {{api: string?, prompt: string?}} */ { api = null, prompt = null }, text) { |
| 925 | 925 | if (!text) { |
| 926 | 926 | toastr.warning('No text provided'); |
| 927 | 927 | return ''; |
| @@ -938,7 +938,7 @@ async function classifyCallback(/** @type {{api: string?}} */ { api = null }, te | ||
| 938 | 938 | return ''; |
| 939 | 939 | } |
| 940 | 940 | |
| 941 | 941 | const label = getExpressionLabel(text, expressionApi, { customPrompt: prompt }); |
| 942 | 942 | console.debug(`Classification result for "${text}": ${label}`); |
| 943 | 943 | return label; |
| 944 | 944 | } |
| @@ -1120,9 +1120,11 @@ function onTextGenSettingsReady(args) { | ||
| 1120 | 1120 | * Optionally allows to override the expressions API being used. |
| 1121 | 1121 | * @param {string} text - The text to classify and retrieve the expression label for. |
| 1122 | 1122 | * @param {EXPRESSION_API} [expressionsApi=extension_settings.expressions.api] - The expressions API to use for classification. |
| 1123 | + * @param {object} [options={}] - Optional arguments. | |
| 1124 | + * @param {string?} [options.customPrompt=null] - The custom prompt to use for classification. | |
| 1123 | 1125 | * @returns {Promise<string>} - The label of the expression. |
| 1124 | 1126 | */ |
| 1125 | 1127 | export async function getExpressionLabel(text, expressionsApi = extension_settings.expressions.api, { customPrompt = null } = {}) { |
| 1126 | 1128 | // Return if text is undefined, saving a costly fetch request |
| 1127 | 1129 | if ((!modules.includes('classify') && expressionsApi == EXPRESSION_API.extras) || !text) { |
| 1128 | 1130 | return getFallbackExpression(); |
| @@ -1159,7 +1161,7 @@ export async function getExpressionLabel(text, expressionsApi = extension_settin | ||
| 1159 | 1161 | } |
| 1160 | 1162 | |
| 1161 | 1163 | const expressionsList = await getExpressionsList(); |
| 1162 | 1164 | const prompt = customPrompt || await getLlmPrompt(expressionsList); |
| 1163 | 1165 | let functionResult = null; |
| 1164 | 1166 | eventSource.once(event_types.TEXT_COMPLETION_SETTINGS_READY, onTextGenSettingsReady); |
| 1165 | 1167 | eventSource.once(event_types.LLM_FUNCTION_TOOL_REGISTER, onFunctionToolRegister); |
| @@ -2127,6 +2129,11 @@ function migrateSettings() { | ||
| 2127 | 2129 | typeList: [ARGUMENT_TYPE.STRING], |
| 2128 | 2130 | enumList: Object.keys(EXPRESSION_API).map(api => new SlashCommandEnumValue(api, null, enumTypes.enum)), |
| 2129 | 2131 | }), |
| 2132 | + SlashCommandNamedArgument.fromProps({ | |
| 2133 | + name: 'prompt', | |
| 2134 | + description: 'Custom prompt for classification. Only relevant if Classifier API is set to LLM.', | |
| 2135 | + typeList: [ARGUMENT_TYPE.STRING], | |
| 2136 | + }), | |
| 2130 | 2137 | ], |
| 2131 | 2138 | unnamedArgumentList: [ |
| 2132 | 2139 | new SlashCommandArgument( |