Add prompt type selection for LLM expressions in settings

9efd40980fbac085c29b5d62013486e8c7ee4fd3

Cohee <18619528+Cohee1207@users.noreply.github.com>

3 files changed, +44 -1Showing whitespace changes
public/scripts/extensions.js+1 -0
@@ -178,6 +178,7 @@ export const extension_settings = {
178178 llmPrompt: undefined,
179179 allowMultiple: true,
180180 rerollIfSame: false,
181+ promptType: 'raw',
181182 },
182183 connectionManager: {
183184 selectedProfile: '',
public/scripts/extensions/expressions/index.js+29 -0
@@ -86,6 +86,12 @@ const EXPRESSION_API = {
8686 none: 99,
8787};
8888
89+/** @enum {string} */
90+const PROMPT_TYPE = {
91+ raw: 'raw',
92+ full: 'full',
93+};
94+
8995let expressionsList = null;
9096let lastCharacter = undefined;
9197let lastMessage = null;
@@ -1047,7 +1053,14 @@ export async function getExpressionLabel(text, expressionsApi = extension_settin
10471053 let emotionResponse;
10481054 try {
10491055 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:
10501061 emotionResponse = await generateQuietPrompt(prompt, false, false);
1062+ break;
1063+ }
10511064 } finally {
10521065 inApiCall = false;
10531066 }
@@ -1705,6 +1718,7 @@ function onExpressionApiChanged() {
17051718 if (tempApi) {
17061719 extension_settings.expressions.api = Number(tempApi);
17071720 $('.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);
17081722 expressionsList = null;
17091723 spriteCache = {};
17101724 moduleWorker();
@@ -2105,6 +2119,11 @@ function migrateSettings() {
21052119 extension_settings.expressions.showDefault = false;
21062120 saveSettingsDebounced();
21072121 }
2122+
2123+ if (extension_settings.expressions.promptType === undefined) {
2124+ extension_settings.expressions.promptType = PROMPT_TYPE.raw;
2125+ saveSettingsDebounced();
2126+ }
21082127}
21092128
21102129(async function () {
@@ -2172,6 +2191,16 @@ function migrateSettings() {
21722191 extension_settings.expressions.llmPrompt = DEFAULT_LLM_PROMPT;
21732192 saveSettingsDebounced();
21742193 });
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);
21752204
21762205 $('#expression_custom_add').on('click', onClickExpressionAddCustom);
21772206 $('#expression_custom_remove').on('click', onClickExpressionRemoveCustom);
public/scripts/extensions/expressions/settings.html+14 -1
@@ -41,7 +41,20 @@
4141 </div>
4242 </label>
4343 <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>
4444 <textarea id="expression_llm_prompt" type="text" class="text_pole textarea_compact autoSetHeight" rows="2" placeholder="Use &lcub;&lcub;labels&rcub;&rcub; 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>
4558 </div>
4659 <div class="expression_fallback_block m-b-1 m-t-1">
4760 <label for="expression_fallback" data-i18n="Default / Fallback Expression">Default / Fallback Expression</label>