Gemini: Thought toggle

Closes #3220
This commit is contained in:
Cohee
2024-12-29 18:23:07 +02:00
parent c3ad87cea1
commit 662f0e9c73
4 changed files with 40 additions and 3 deletions

View File

@ -295,6 +295,7 @@ const default_settings = {
names_behavior: character_names_behavior.DEFAULT,
continue_postfix: continue_postfix_types.SPACE,
custom_prompt_post_processing: custom_prompt_post_processing_types.NONE,
show_thoughts: false,
seed: -1,
n: 1,
};
@ -372,6 +373,7 @@ const oai_settings = {
names_behavior: character_names_behavior.DEFAULT,
continue_postfix: continue_postfix_types.SPACE,
custom_prompt_post_processing: custom_prompt_post_processing_types.NONE,
show_thoughts: false,
seed: -1,
n: 1,
};
@ -1884,6 +1886,7 @@ async function sendOpenAIRequest(type, messages, signal) {
'user_name': name1,
'char_name': name2,
'group_names': getGroupNames(),
'show_thoughts': Boolean(oai_settings.show_thoughts),
};
// Empty array will produce a validation error
@ -2098,7 +2101,7 @@ function getStreamingReply(data) {
if (oai_settings.chat_completion_source === chat_completion_sources.CLAUDE) {
return data?.delta?.text || '';
} else if (oai_settings.chat_completion_source === chat_completion_sources.MAKERSUITE) {
return data?.candidates?.[0]?.content?.parts?.map(x => x.text)?.join('\n\n') || '';
return data?.candidates?.[0]?.content?.parts?.filter(x => oai_settings.show_thoughts || !x.thought)?.map(x => x.text)?.filter(x => x)?.join('\n\n') || '';
} else if (oai_settings.chat_completion_source === chat_completion_sources.COHERE) {
return data?.delta?.message?.content?.text || data?.delta?.message?.tool_plan || '';
} else {
@ -3056,6 +3059,7 @@ function loadOpenAISettings(data, settings) {
oai_settings.image_inlining = settings.image_inlining ?? default_settings.image_inlining;
oai_settings.inline_image_quality = settings.inline_image_quality ?? default_settings.inline_image_quality;
oai_settings.bypass_status_check = settings.bypass_status_check ?? default_settings.bypass_status_check;
oai_settings.show_thoughts = settings.show_thoughts ?? default_settings.show_thoughts;
oai_settings.seed = settings.seed ?? default_settings.seed;
oai_settings.n = settings.n ?? default_settings.n;
@ -3181,6 +3185,7 @@ function loadOpenAISettings(data, settings) {
$('#repetition_penalty_counter_openai').val(Number(oai_settings.repetition_penalty_openai));
$('#seed_openai').val(oai_settings.seed);
$('#n_openai').val(oai_settings.n);
$('#openai_show_thoughts').prop('checked', oai_settings.show_thoughts);
if (settings.reverse_proxy !== undefined) oai_settings.reverse_proxy = settings.reverse_proxy;
$('#openai_reverse_proxy').val(oai_settings.reverse_proxy);
@ -3441,6 +3446,7 @@ async function saveOpenAIPreset(name, settings, triggerUi = true) {
continue_prefill: settings.continue_prefill,
continue_postfix: settings.continue_postfix,
function_calling: settings.function_calling,
show_thoughts: settings.show_thoughts,
seed: settings.seed,
n: settings.n,
};
@ -3897,6 +3903,7 @@ function onSettingsPresetChange() {
continue_prefill: ['#continue_prefill', 'continue_prefill', true],
continue_postfix: ['#continue_postfix', 'continue_postfix', false],
function_calling: ['#openai_function_calling', 'function_calling', true],
show_thoughts: ['#openai_show_thoughts', 'show_thoughts', true],
seed: ['#seed_openai', 'seed', false],
n: ['#n_openai', 'n', false],
};
@ -5390,6 +5397,11 @@ export function initOpenAI() {
saveSettingsDebounced();
});
$('#openai_show_thoughts').on('input', function () {
oai_settings.show_thoughts = !!$(this).prop('checked');
saveSettingsDebounced();
});
if (!CSS.supports('field-sizing', 'content')) {
$(document).on('input', '#openai_settings .autoSetHeight', function () {
resetScrollHeight($(this));