Merge pull request #4157 from kingbri1/staging

Emotions: Use the full context for main API
This commit is contained in:
Cohee
2025-06-14 20:46:23 +03:00
committed by GitHub
3 changed files with 53 additions and 7 deletions
+1
View File
@@ -178,6 +178,7 @@ export const extension_settings = {
llmPrompt: undefined,
allowMultiple: true,
rerollIfSame: false,
promptType: 'raw',
},
connectionManager: {
selectedProfile: '',
+38 -6
View File
@@ -1,6 +1,6 @@
import { Fuse } from '../../../lib.js';
import { characters, eventSource, event_types, generateRaw, getRequestHeaders, main_api, online_status, saveSettingsDebounced, substituteParams, substituteParamsExtended, system_message_types, this_chid } from '../../../script.js';
import { characters, eventSource, event_types, generateQuietPrompt, generateRaw, getRequestHeaders, main_api, online_status, saveSettingsDebounced, substituteParams, substituteParamsExtended, system_message_types, this_chid } from '../../../script.js';
import { dragElement, isMobile } from '../../RossAscends-mods.js';
import { getContext, getApiUrl, modules, extension_settings, ModuleWorkerWrapper, doExtrasFetch, renderExtensionTemplateAsync } from '../../extensions.js';
import { loadMovingUIState, performFuzzySearch, power_user } from '../../power-user.js';
@@ -86,6 +86,12 @@ const EXPRESSION_API = {
none: 99,
};
/** @enum {string} */
const PROMPT_TYPE = {
raw: 'raw',
full: 'full',
};
let expressionsList = null;
let lastCharacter = undefined;
let lastMessage = null;
@@ -909,10 +915,6 @@ function sampleClassifyText(text) {
* @returns {Promise<string>} Prompt for the LLM API.
*/
async function getLlmPrompt(labels) {
if (isJsonSchemaSupported()) {
return '';
}
const labelsString = labels.map(x => `"${x}"`).join(', ');
const prompt = substituteParamsExtended(String(extension_settings.expressions.llmPrompt), { labels: labelsString });
return prompt;
@@ -1047,7 +1049,21 @@ export async function getExpressionLabel(text, expressionsApi = extension_settin
const expressionsList = await getExpressionsList({ filterAvailable: filterAvailable });
const prompt = substituteParamsExtended(customPrompt, { labels: expressionsList }) || await getLlmPrompt(expressionsList);
eventSource.once(event_types.TEXT_COMPLETION_SETTINGS_READY, onTextGenSettingsReady);
const emotionResponse = await generateRaw(text, main_api, false, false, prompt);
let emotionResponse;
try {
inApiCall = true;
switch (extension_settings.expressions.promptType) {
case PROMPT_TYPE.raw:
emotionResponse = await generateRaw(text, main_api, false, false, prompt);
break;
case PROMPT_TYPE.full:
emotionResponse = await generateQuietPrompt(prompt, false, false);
break;
}
} finally {
inApiCall = false;
}
return parseLlmResponse(emotionResponse, expressionsList);
}
// Using WebLLM
@@ -1702,6 +1718,7 @@ function onExpressionApiChanged() {
if (tempApi) {
extension_settings.expressions.api = Number(tempApi);
$('.expression_llm_prompt_block').toggle([EXPRESSION_API.llm, EXPRESSION_API.webllm].includes(extension_settings.expressions.api));
$('.expression_prompt_type_block').toggle(extension_settings.expressions.api === EXPRESSION_API.llm);
expressionsList = null;
spriteCache = {};
moduleWorker();
@@ -2102,6 +2119,11 @@ function migrateSettings() {
extension_settings.expressions.showDefault = false;
saveSettingsDebounced();
}
if (extension_settings.expressions.promptType === undefined) {
extension_settings.expressions.promptType = PROMPT_TYPE.raw;
saveSettingsDebounced();
}
}
(async function () {
@@ -2169,6 +2191,16 @@ function migrateSettings() {
extension_settings.expressions.llmPrompt = DEFAULT_LLM_PROMPT;
saveSettingsDebounced();
});
$('#expression_prompt_raw').on('input', function () {
extension_settings.expressions.promptType = PROMPT_TYPE.raw;
saveSettingsDebounced();
});
$('#expression_prompt_full').on('input', function () {
extension_settings.expressions.promptType = PROMPT_TYPE.full;
saveSettingsDebounced();
});
$(`input[name="expression_prompt_type"][value="${extension_settings.expressions.promptType}"]`).prop('checked', true);
$('.expression_prompt_type_block').toggle(extension_settings.expressions.api === EXPRESSION_API.llm);
$('#expression_custom_add').on('click', onClickExpressionAddCustom);
$('#expression_custom_remove').on('click', onClickExpressionRemoveCustom);
@@ -41,7 +41,20 @@
</div>
</label>
<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>
<textarea id="expression_llm_prompt" type="text" class="text_pole textarea_compact" rows="2" placeholder="Use &lcub;&lcub;labels&rcub;&rcub; special macro."></textarea>
<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>
</div>
<div class="expression_prompt_type_block flex-container flexFlowColumn">
<div data-i18n="LLM Prompt Strategy" class="title_restorable">
LLM Prompt Strategy
</div>
<label for="expression_prompt_raw" class="checkbox_label">
<input id="expression_prompt_raw" type="radio" name="expression_prompt_type" value="raw">
<span data-i18n="Limited Context">Limited Context</span>
</label>
<label for="expression_prompt_full" class="checkbox_label">
<input id="expression_prompt_full" type="radio" name="expression_prompt_type" value="full">
<span data-i18n="Full Context">Full Context</span>
</label>
</div>
<div class="expression_fallback_block m-b-1 m-t-1">
<label for="expression_fallback" data-i18n="Default / Fallback Expression">Default / Fallback Expression</label>