Add prompt type selection for LLM expressions in settings
| @@ -178,6 +178,7 @@ export const extension_settings = { | |||
| 178 | llmPrompt: undefined, | 178 | llmPrompt: undefined, |
| 179 | allowMultiple: true, | 179 | allowMultiple: true, |
| 180 | rerollIfSame: false, | 180 | rerollIfSame: false, |
| 181 | promptType: 'raw', | ||
| 181 | }, | 182 | }, |
| 182 | connectionManager: { | 183 | connectionManager: { |
| 183 | selectedProfile: '', | 184 | selectedProfile: '', |
| @@ -86,6 +86,12 @@ const EXPRESSION_API = { | |||
| 86 | none: 99, | 86 | none: 99, |
| 87 | }; | 87 | }; |
| 88 | 88 | ||
| 89 | /** @enum {string} */ | ||
| 90 | const PROMPT_TYPE = { | ||
| 91 | raw: 'raw', | ||
| 92 | full: 'full', | ||
| 93 | }; | ||
| 94 | |||
| 89 | let expressionsList = null; | 95 | let expressionsList = null; |
| 90 | let lastCharacter = undefined; | 96 | let lastCharacter = undefined; |
| 91 | let lastMessage = null; | 97 | let lastMessage = null; |
| @@ -1047,7 +1053,14 @@ export async function getExpressionLabel(text, expressionsApi = extension_settin | |||
| 1047 | let emotionResponse; | 1053 | let emotionResponse; |
| 1048 | try { | 1054 | try { |
| 1049 | inApiCall = true; | 1055 | inApiCall = true; |
| 1056 | switch (extension_settings.expressions.promptType) { | ||
| 1057 | case PROMPT_TYPE.raw: | ||
| 1058 | emotionResponse = await generateRaw(text, main_api, false, false, prompt); | ||
| 1059 | break; | ||
| 1060 | case PROMPT_TYPE.full: | ||
| 1050 | emotionResponse = await generateQuietPrompt(prompt, false, false); | 1061 | emotionResponse = await generateQuietPrompt(prompt, false, false); |
| 1062 | break; | ||
| 1063 | } | ||
| 1051 | } finally { | 1064 | } finally { |
| 1052 | inApiCall = false; | 1065 | inApiCall = false; |
| 1053 | } | 1066 | } |
| @@ -1705,6 +1718,7 @@ function onExpressionApiChanged() { | |||
| 1705 | if (tempApi) { | 1718 | if (tempApi) { |
| 1706 | extension_settings.expressions.api = Number(tempApi); | 1719 | extension_settings.expressions.api = Number(tempApi); |
| 1707 | $('.expression_llm_prompt_block').toggle([EXPRESSION_API.llm, EXPRESSION_API.webllm].includes(extension_settings.expressions.api)); | 1720 | $('.expression_llm_prompt_block').toggle([EXPRESSION_API.llm, EXPRESSION_API.webllm].includes(extension_settings.expressions.api)); |
| 1721 | $('.expression_prompt_type_block').toggle(extension_settings.expressions.api === EXPRESSION_API.llm); | ||
| 1708 | expressionsList = null; | 1722 | expressionsList = null; |
| 1709 | spriteCache = {}; | 1723 | spriteCache = {}; |
| 1710 | moduleWorker(); | 1724 | moduleWorker(); |
| @@ -2105,6 +2119,11 @@ function migrateSettings() { | |||
| 2105 | extension_settings.expressions.showDefault = false; | 2119 | extension_settings.expressions.showDefault = false; |
| 2106 | saveSettingsDebounced(); | 2120 | saveSettingsDebounced(); |
| 2107 | } | 2121 | } |
| 2122 | |||
| 2123 | if (extension_settings.expressions.promptType === undefined) { | ||
| 2124 | extension_settings.expressions.promptType = PROMPT_TYPE.raw; | ||
| 2125 | saveSettingsDebounced(); | ||
| 2126 | } | ||
| 2108 | } | 2127 | } |
| 2109 | 2128 | ||
| 2110 | (async function () { | 2129 | (async function () { |
| @@ -2172,6 +2191,16 @@ function migrateSettings() { | |||
| 2172 | extension_settings.expressions.llmPrompt = DEFAULT_LLM_PROMPT; | 2191 | extension_settings.expressions.llmPrompt = DEFAULT_LLM_PROMPT; |
| 2173 | saveSettingsDebounced(); | 2192 | saveSettingsDebounced(); |
| 2174 | }); | 2193 | }); |
| 2194 | $('#expression_prompt_raw').on('input', function () { | ||
| 2195 | extension_settings.expressions.promptType = PROMPT_TYPE.raw; | ||
| 2196 | saveSettingsDebounced(); | ||
| 2197 | }); | ||
| 2198 | $('#expression_prompt_full').on('input', function () { | ||
| 2199 | extension_settings.expressions.promptType = PROMPT_TYPE.full; | ||
| 2200 | saveSettingsDebounced(); | ||
| 2201 | }); | ||
| 2202 | $(`input[name="expression_prompt_type"][value="${extension_settings.expressions.promptType}"]`).prop('checked', true); | ||
| 2203 | $('.expression_prompt_type_block').toggle(extension_settings.expressions.api === EXPRESSION_API.llm); | ||
| 2175 | 2204 | ||
| 2176 | $('#expression_custom_add').on('click', onClickExpressionAddCustom); | 2205 | $('#expression_custom_add').on('click', onClickExpressionAddCustom); |
| 2177 | $('#expression_custom_remove').on('click', onClickExpressionRemoveCustom); | 2206 | $('#expression_custom_remove').on('click', onClickExpressionRemoveCustom); |
| @@ -41,7 +41,20 @@ | |||
| 41 | </div> | 41 | </div> |
| 42 | </label> | 42 | </label> |
| 43 | <small data-i18n="Will be used if the API doesn't support JSON schemas or function calling.">Will be used if the API doesn't support JSON schemas or function calling.</small> | 43 | <small data-i18n="Will be used if the API doesn't support JSON schemas or function calling.">Will be used if the API doesn't support JSON schemas or function calling.</small> |
| 44 | <textarea id="expression_llm_prompt" type="text" class="text_pole textarea_compact" rows="2" placeholder="Use {{labels}} special macro."></textarea> | 44 | <textarea id="expression_llm_prompt" type="text" class="text_pole textarea_compact autoSetHeight" rows="2" placeholder="Use {{labels}} special macro."></textarea> |
| 45 | </div> | ||
| 46 | <div class="expression_prompt_type_block flex-container flexFlowColumn"> | ||
| 47 | <div data-i18n="LLM Prompt Strategy" class="title_restorable"> | ||
| 48 | LLM Prompt Strategy | ||
| 49 | </div> | ||
| 50 | <label for="expression_prompt_raw" class="checkbox_label"> | ||
| 51 | <input id="expression_prompt_raw" type="radio" name="expression_prompt_type" value="raw"> | ||
| 52 | <span data-i18n="Limited Context">Limited Context</span> | ||
| 53 | </label> | ||
| 54 | <label for="expression_prompt_full" class="checkbox_label"> | ||
| 55 | <input id="expression_prompt_full" type="radio" name="expression_prompt_type" value="full"> | ||
| 56 | <span data-i18n="Full Context">Full Context</span> | ||
| 57 | </label> | ||
| 45 | </div> | 58 | </div> |
| 46 | <div class="expression_fallback_block m-b-1 m-t-1"> | 59 | <div class="expression_fallback_block m-b-1 m-t-1"> |
| 47 | <label for="expression_fallback" data-i18n="Default / Fallback Expression">Default / Fallback Expression</label> | 60 | <label for="expression_fallback" data-i18n="Default / Fallback Expression">Default / Fallback Expression</label> |