Merge pull request #3396 from pcpthm/text-completion-include-reasoning

Support reasoning for OpenRouter Text Completion
This commit is contained in:
Cohee
2025-01-31 21:04:30 +02:00
committed by GitHub
7 changed files with 39 additions and 17 deletions

View File

@@ -298,7 +298,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,
show_thoughts: true,
seed: -1,
n: 1,
};
@@ -377,7 +377,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,
show_thoughts: true,
seed: -1,
n: 1,
};
@@ -1913,7 +1913,7 @@ async function sendOpenAIRequest(type, messages, signal) {
'user_name': name1,
'char_name': name2,
'group_names': getGroupNames(),
'show_thoughts': Boolean(oai_settings.show_thoughts),
'include_reasoning': Boolean(oai_settings.show_thoughts),
};
// Empty array will produce a validation error
@@ -2151,7 +2151,7 @@ function getStreamingReply(data, state) {
return data?.delta?.text || '';
} else if (oai_settings.chat_completion_source === chat_completion_sources.MAKERSUITE) {
if (oai_settings.show_thoughts) {
state.reasoning += (data?.candidates?.[0]?.content?.parts?.filter(x => x.thought)?.map(x => x.text)?.[0] || '');
state.reasoning += (data?.candidates?.[0]?.content?.parts?.filter(x => x.thought)?.map(x => x.text)?.[0] || '');
}
return data?.candidates?.[0]?.content?.parts?.filter(x => !x.thought)?.map(x => x.text)?.[0] || '';
} else if (oai_settings.chat_completion_source === chat_completion_sources.COHERE) {
@@ -2166,7 +2166,7 @@ function getStreamingReply(data, state) {
state.reasoning += (data.choices?.filter(x => x?.delta?.reasoning)?.[0]?.delta?.reasoning || '');
}
return data.choices?.[0]?.delta?.content ?? data.choices?.[0]?.message?.content ?? data.choices?.[0]?.text ?? '';
} else {
} else {
return data.choices?.[0]?.delta?.content ?? data.choices?.[0]?.message?.content ?? data.choices?.[0]?.text ?? '';
}
}

View File

@@ -586,6 +586,7 @@ class PresetManager {
'tabby_model',
'derived',
'generic_model',
'include_reasoning',
];
const settings = Object.assign({}, getSettingsByApiId(this.apiId));

View File

@@ -172,6 +172,7 @@ const settings = {
//truncation_length: 2048,
ban_eos_token: false,
skip_special_tokens: true,
include_reasoning: true,
streaming: false,
mirostat_mode: 0,
mirostat_tau: 5,
@@ -263,6 +264,7 @@ export const setting_names = [
'add_bos_token',
'ban_eos_token',
'skip_special_tokens',
'include_reasoning',
'streaming',
'mirostat_mode',
'mirostat_tau',
@@ -740,6 +742,7 @@ jQuery(function () {
'add_bos_token_textgenerationwebui': true,
'temperature_last_textgenerationwebui': true,
'skip_special_tokens_textgenerationwebui': true,
'include_reasoning_textgenerationwebui': true,
'top_a_textgenerationwebui': 0,
'top_a_counter_textgenerationwebui': 0,
'mirostat_mode_textgenerationwebui': 0,
@@ -986,7 +989,7 @@ export async function generateTextGenWithStreaming(generate_data, signal) {
let logprobs = null;
const swipes = [];
const toolCalls = [];
const state = {};
const state = { reasoning: '' };
while (true) {
const { done, value } = await reader.read();
if (done) return;
@@ -1003,6 +1006,7 @@ export async function generateTextGenWithStreaming(generate_data, signal) {
const newText = data?.choices?.[0]?.text || data?.content || '';
text += newText;
logprobs = parseTextgenLogprobs(newText, data.choices?.[0]?.logprobs || data?.completion_probabilities);
state.reasoning += data?.choices?.[0]?.reasoning ?? '';
}
yield { text, swipes, logprobs, toolCalls, state };
@@ -1266,6 +1270,7 @@ export function getTextGenGenerationData(finalPrompt, maxTokens, isImpersonate,
'truncation_length': max_context,
'ban_eos_token': settings.ban_eos_token,
'skip_special_tokens': settings.skip_special_tokens,
'include_reasoning': settings.include_reasoning,
'top_a': settings.top_a,
'tfs': settings.tfs,
'epsilon_cutoff': [OOBA, MANCER].includes(settings.type) ? settings.epsilon_cutoff : undefined,