mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
OpenRouter: Support reasoning blocks
This commit is contained in:
@@ -413,8 +413,3 @@ export const VLLM_KEYS = [
|
||||
'guided_decoding_backend',
|
||||
'guided_whitespace_pattern',
|
||||
];
|
||||
|
||||
/**
|
||||
* Custom boundary for splitting the text between the model's reasoning and the actual response.
|
||||
*/
|
||||
export const THINK_BREAK = '##<23>THINK_BREAK<41>##';
|
||||
|
@@ -7,7 +7,6 @@ import {
|
||||
CHAT_COMPLETION_SOURCES,
|
||||
GEMINI_SAFETY,
|
||||
OPENROUTER_HEADERS,
|
||||
THINK_BREAK,
|
||||
} from '../../constants.js';
|
||||
import {
|
||||
forwardFetchResponse,
|
||||
@@ -392,11 +391,7 @@ async function sendMakerSuiteRequest(request, response) {
|
||||
const responseContent = candidates[0].content ?? candidates[0].output;
|
||||
console.log('Google AI Studio response:', responseContent);
|
||||
|
||||
if (Array.isArray(responseContent?.parts) && isThinking && !showThoughts) {
|
||||
responseContent.parts = responseContent.parts.filter(part => !part.thought);
|
||||
}
|
||||
|
||||
const responseText = typeof responseContent === 'string' ? responseContent : responseContent?.parts?.map(part => part.text)?.join(THINK_BREAK);
|
||||
const responseText = typeof responseContent === 'string' ? responseContent : responseContent?.parts?.filter(part => !part.thought)?.map(part => part.text)?.join('\n\n');
|
||||
if (!responseText) {
|
||||
let message = 'Google AI Studio Candidate text empty';
|
||||
console.log(message, generateResponseJson);
|
||||
@@ -404,7 +399,7 @@ async function sendMakerSuiteRequest(request, response) {
|
||||
}
|
||||
|
||||
// Wrap it back to OAI format
|
||||
const reply = { choices: [{ 'message': { 'content': responseText } }] };
|
||||
const reply = { choices: [{ 'message': { 'content': responseText } }], responseContent };
|
||||
return response.send(reply);
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -993,6 +988,10 @@ router.post('/generate', jsonParser, function (request, response) {
|
||||
bodyParams['route'] = 'fallback';
|
||||
}
|
||||
|
||||
if (request.body.show_thoughts) {
|
||||
bodyParams['include_reasoning'] = true;
|
||||
}
|
||||
|
||||
let cachingAtDepth = getConfigValue('claude.cachingAtDepth', -1);
|
||||
if (Number.isInteger(cachingAtDepth) && cachingAtDepth >= 0 && request.body.model?.startsWith('anthropic/claude-3')) {
|
||||
cachingAtDepthForOpenRouterClaude(request.body.messages, cachingAtDepth);
|
||||
|
Reference in New Issue
Block a user