Openrouter reasoning fixes (#1951)

* Fix for OpenRouter reasoning models
This commit is contained in:
Neal Shah
2025-11-09 15:33:36 -05:00
committed by GitHub
parent 65c213f9a7
commit 0077944bd4
3 changed files with 8 additions and 6 deletions

View File

@@ -396,7 +396,7 @@ class AIChatService extends BaseService {
if ( model_max_tokens ) {
parameters.max_tokens = Math.floor(Math.min(parameters.max_tokens ?? Number.POSITIVE_INFINITY,
max_allowed_output_tokens,
model_max_tokens));
model_max_tokens - (Math.ceil(text.length / 4))));
}
try {
ret = await svc_driver.call_new_({

View File

@@ -126,8 +126,7 @@ class OpenRouterService extends BaseService {
const actor = Context.get('actor');
messages = await OpenAIUtil.process_input_messages(messages);
const completion = await this.openai.chat.completions.create({
const sdk_params = {
messages,
model: model ?? this.get_default_model(),
...(tools ? { tools } : {}),
@@ -137,7 +136,9 @@ class OpenRouterService extends BaseService {
...(stream ? {
stream_options: { include_usage: true },
} : {}),
});
}
const completion = await this.openai.chat.completions.create(sdk_params);
const modelDetails = (await this.models_()).find(m => m.id === 'openrouter:' + model);
const rawPriceModelDetails = (await this.models_(true)).find(m => m.id === 'openrouter:' + model);

View File

@@ -120,8 +120,9 @@ const create_chat_stream_handler = ({
const choice = chunk.choices[0];
if ( choice.delta.reasoning_content ){
textblock.addReasoning(choice.delta.reasoning_content);
// Deepseek returns choice.delta.reasoning_content, openrouter returns choice.delta.reasoning.
if ( choice.delta.reasoning_content || choice.delta.reasoning ) {
textblock.addReasoning(choice.delta.reasoning_content || choice.delta.reasoning);
// Q: Why don't "continue" to next chunk here?
// A: For now, reasoning_content and content never appear together, but Im not sure if theyll always be mutually exclusive.
}