/classify allows custom prompt for LLM api

2472b2605766eb032253d96a4f3fb27ed20522ff

Wolfsblvt <wolfsblvt@gmail.com>

1 files changed, +11 -4Ignore whitespace
public/scripts/extensions/expressions/index.js+11 -4
@@ -921,7 +921,7 @@ async function setSpriteSetCommand(_, folder) {
921921 return '';
922922}
923923
924924async function classifyCallback(/** @type {{api: string?, prompt: string?}} */ { api = null, prompt = null }, text) {
925925 if (!text) {
926926 toastr.warning('No text provided');
927927 return '';
@@ -938,7 +938,7 @@ async function classifyCallback(/** @type {{api: string?}} */ { api = null }, te
938938 return '';
939939 }
940940
941941 const label = getExpressionLabel(text, expressionApi, { customPrompt: prompt });
942942 console.debug(`Classification result for "${text}": ${label}`);
943943 return label;
944944}
@@ -1120,9 +1120,11 @@ function onTextGenSettingsReady(args) {
11201120 * Optionally allows to override the expressions API being used.
11211121 * @param {string} text - The text to classify and retrieve the expression label for.
11221122 * @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.
11231125 * @returns {Promise<string>} - The label of the expression.
11241126 */
11251127export async function getExpressionLabel(text, expressionsApi = extension_settings.expressions.api, { customPrompt = null } = {}) {
11261128 // Return if text is undefined, saving a costly fetch request
11271129 if ((!modules.includes('classify') && expressionsApi == EXPRESSION_API.extras) || !text) {
11281130 return getFallbackExpression();
@@ -1159,7 +1161,7 @@ export async function getExpressionLabel(text, expressionsApi = extension_settin
11591161 }
11601162
11611163 const expressionsList = await getExpressionsList();
11621164 const prompt = customPrompt || await getLlmPrompt(expressionsList);
11631165 let functionResult = null;
11641166 eventSource.once(event_types.TEXT_COMPLETION_SETTINGS_READY, onTextGenSettingsReady);
11651167 eventSource.once(event_types.LLM_FUNCTION_TOOL_REGISTER, onFunctionToolRegister);
@@ -2127,6 +2129,11 @@ function migrateSettings() {
21272129 typeList: [ARGUMENT_TYPE.STRING],
21282130 enumList: Object.keys(EXPRESSION_API).map(api => new SlashCommandEnumValue(api, null, enumTypes.enum)),
21292131 }),
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+ }),
21302137 ],
21312138 unnamedArgumentList: [
21322139 new SlashCommandArgument(