Support reasoning for OpenRouter text completion

This commit is contained in:
pcpthm
2025-01-31 21:41:42 +09:00
parent dfc2eb32c8
commit 753a99faf9
6 changed files with 35 additions and 14 deletions

View File

@ -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 ?? '';
}
}