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