Merge pull request #4157 from kingbri1/staging Emotions: Use the full context for main API
Signed| @@ -178,6 +178,7 @@ export const extension_settings = { | ||
| 178 | 178 | llmPrompt: undefined, |
| 179 | 179 | allowMultiple: true, |
| 180 | 180 | rerollIfSame: false, |
| 181 | + promptType: 'raw', | |
| 181 | 182 | }, |
| 182 | 183 | connectionManager: { |
| 183 | 184 | selectedProfile: '', |
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | import { Fuse } from '../../../lib.js'; |
| 2 | 2 | |
| 3 | 3 | import { characters, eventSource, event_types, generateQuietPrompt, generateRaw, getRequestHeaders, main_api, online_status, saveSettingsDebounced, substituteParams, substituteParamsExtended, system_message_types, this_chid } from '../../../script.js'; |
| 4 | 4 | import { dragElement, isMobile } from '../../RossAscends-mods.js'; |
| 5 | 5 | import { getContext, getApiUrl, modules, extension_settings, ModuleWorkerWrapper, doExtrasFetch, renderExtensionTemplateAsync } from '../../extensions.js'; |
| 6 | 6 | import { loadMovingUIState, performFuzzySearch, power_user } from '../../power-user.js'; |
| @@ -86,6 +86,12 @@ const EXPRESSION_API = { | ||
| 86 | 86 | none: 99, |
| 87 | 87 | }; |
| 88 | 88 | |
| 89 | +/** @enum {string} */ | |
| 90 | +const PROMPT_TYPE = { | |
| 91 | + raw: 'raw', | |
| 92 | + full: 'full', | |
| 93 | +}; | |
| 94 | + | |
| 89 | 95 | let expressionsList = null; |
| 90 | 96 | let lastCharacter = undefined; |
| 91 | 97 | let lastMessage = null; |
| @@ -909,10 +915,6 @@ function sampleClassifyText(text) { | ||
| 909 | 915 | * @returns {Promise<string>} Prompt for the LLM API. |
| 910 | 916 | */ |
| 911 | 917 | async function getLlmPrompt(labels) { |
| 912 | - if (isJsonSchemaSupported()) { | |
| 913 | - return ''; | |
| 914 | - } | |
| 915 | - | |
| 916 | 918 | const labelsString = labels.map(x => `"${x}"`).join(', '); |
| 917 | 919 | const prompt = substituteParamsExtended(String(extension_settings.expressions.llmPrompt), { labels: labelsString }); |
| 918 | 920 | return prompt; |
| @@ -1047,7 +1049,21 @@ export async function getExpressionLabel(text, expressionsApi = extension_settin | ||
| 1047 | 1049 | const expressionsList = await getExpressionsList({ filterAvailable: filterAvailable }); |
| 1048 | 1050 | const prompt = substituteParamsExtended(customPrompt, { labels: expressionsList }) || await getLlmPrompt(expressionsList); |
| 1049 | 1051 | eventSource.once(event_types.TEXT_COMPLETION_SETTINGS_READY, onTextGenSettingsReady); |
| 1050 | - const emotionResponse = await generateRaw(text, main_api, false, false, prompt); | |
| 1052 | + | |
| 1053 | + let emotionResponse; | |
| 1054 | + try { | |
| 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: | |
| 1061 | + emotionResponse = await generateQuietPrompt(prompt, false, false); | |
| 1062 | + break; | |
| 1063 | + } | |
| 1064 | + } finally { | |
| 1065 | + inApiCall = false; | |
| 1066 | + } | |
| 1051 | 1067 | return parseLlmResponse(emotionResponse, expressionsList); |
| 1052 | 1068 | } |
| 1053 | 1069 | // Using WebLLM |
| @@ -1702,6 +1718,7 @@ function onExpressionApiChanged() { | ||
| 1702 | 1718 | if (tempApi) { |
| 1703 | 1719 | extension_settings.expressions.api = Number(tempApi); |
| 1704 | 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); | |
| 1705 | 1722 | expressionsList = null; |
| 1706 | 1723 | spriteCache = {}; |
| 1707 | 1724 | moduleWorker(); |
| @@ -2102,6 +2119,11 @@ function migrateSettings() { | ||
| 2102 | 2119 | extension_settings.expressions.showDefault = false; |
| 2103 | 2120 | saveSettingsDebounced(); |
| 2104 | 2121 | } |
| 2122 | + | |
| 2123 | + if (extension_settings.expressions.promptType === undefined) { | |
| 2124 | + extension_settings.expressions.promptType = PROMPT_TYPE.raw; | |
| 2125 | + saveSettingsDebounced(); | |
| 2126 | + } | |
| 2105 | 2127 | } |
| 2106 | 2128 | |
| 2107 | 2129 | (async function () { |
| @@ -2169,6 +2191,16 @@ function migrateSettings() { | ||
| 2169 | 2191 | extension_settings.expressions.llmPrompt = DEFAULT_LLM_PROMPT; |
| 2170 | 2192 | saveSettingsDebounced(); |
| 2171 | 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); | |
| 2172 | 2204 | |
| 2173 | 2205 | $('#expression_custom_add').on('click', onClickExpressionAddCustom); |
| 2174 | 2206 | $('#expression_custom_remove').on('click', onClickExpressionRemoveCustom); |
| @@ -41,7 +41,20 @@ | ||
| 41 | 41 | </div> |
| 42 | 42 | </label> |
| 43 | 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 | 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 | 58 | </div> |
| 46 | 59 | <div class="expression_fallback_block m-b-1 m-t-1"> |
| 47 | 60 | <label for="expression_fallback" data-i18n="Default / Fallback Expression">Default / Fallback Expression</label> |