Add reasoning effort control for CC OpenRouter

Closes #3890
This commit is contained in:
Cohee
2025-04-23 21:38:31 +03:00
parent cfc41163e2
commit 5241b22a73
3 changed files with 7 additions and 2 deletions

View File

@ -2048,11 +2048,11 @@
</span>
</div>
</div>
<div class="flex-container flexFlowColumn wide100p textAlignCenter marginTop10" data-source="openai,custom,claude,xai,makersuite">
<div class="flex-container flexFlowColumn wide100p textAlignCenter marginTop10" data-source="openai,custom,claude,xai,makersuite,openrouter">
<div class="flex-container oneline-dropdown" title="Constrains effort on reasoning for reasoning models.&#10;Reducing reasoning effort can result in faster responses and fewer tokens used on reasoning in a response." data-i18n="[title]Constrains effort on reasoning for reasoning models.">
<label for="openai_reasoning_effort">
<span data-i18n="Reasoning Effort">Reasoning Effort</span>
<i data-source="openai,custom,xai" class="opacity50p fa-solid fa-circle-info" title="OpenAI-style options: low, medium, high. Minimum and maximum are aliased to low and high. Auto does not send an effort level."></i>
<i data-source="openai,custom,xai,openrouter" class="opacity50p fa-solid fa-circle-info" title="OpenAI-style options: low, medium, high. Minimum and maximum are aliased to low and high. Auto does not send an effort level."></i>
<i data-source="claude,makersuite" class="opacity50p fa-solid fa-circle-info" title="Allocates a portion of the response length for thinking (low: 10%, medium: 25%, high: 50%). Other options are model-dependent."></i>
</label>
<select id="openai_reasoning_effort">

View File

@ -1952,6 +1952,7 @@ function getReasoningEffort() {
chat_completion_sources.OPENAI,
chat_completion_sources.CUSTOM,
chat_completion_sources.XAI,
chat_completion_sources.OPENROUTER,
];
if (!reasoningEffortSources.includes(oai_settings.chat_completion_source)) {

View File

@ -1225,6 +1225,10 @@ router.post('/generate', function (request, response) {
bodyParams['route'] = 'fallback';
}
if (request.body.reasoning_effort) {
bodyParams['reasoning'] = { effort: request.body.reasoning_effort };
}
let cachingAtDepth = getConfigValue('claude.cachingAtDepth', -1, 'number');
if (Number.isInteger(cachingAtDepth) && cachingAtDepth >= 0 && request.body.model?.startsWith('anthropic/claude-3')) {
cachingAtDepthForOpenRouterClaude(request.body.messages, cachingAtDepth);