Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Nov 6, 2025

This PR addresses Issue #8270 based on @bozoweed's suggestion.

Problem

When using DeepSeek V3.1 Terminus via OpenRouter, reasoning/thinking appears to be enabled by default with no way to turn it off. This leads to worse answers for some tasks and increases token usage.

Solution

Following @bozoweed's insight, this PR implements the chat_template_kwargs approach with the thinking parameter for DeepSeek V3.1 Terminus models:

  • Add support for chat_template_kwargs in the OpenRouter handler
  • For DeepSeek V3.1 Terminus models, convert reasoning configuration to chat_template_kwargs: { thinking: boolean }
  • Remove the reasoning parameter for these models (replaced by chat_template_kwargs)
  • Default to thinking: false when no reasoning is configured

Changes

  • src/api/providers/openrouter.ts: Add DeepSeek V3.1 Terminus special handling for both streaming and non-streaming requests
  • src/api/providers/tests/openrouter.spec.ts: Add comprehensive tests for the new behavior

Testing

  • Added unit tests to verify:
    • thinking: true when reasoning is enabled
    • thinking: false when reasoning is disabled (default)
    • No chat_template_kwargs for non-Terminus models
    • Both streaming and non-streaming paths work correctly
  • All existing tests continue to pass

Fixes #8270

Thanks to @bozoweed for the solution!


Important

This PR implements chat_template_kwargs for DeepSeek V3.1 Terminus models to control reasoning, with tests added to verify the new behavior.

  • Behavior:
    • Implements chat_template_kwargs for DeepSeek V3.1 Terminus models in openrouter.ts.
    • Converts reasoning configuration to chat_template_kwargs: { thinking: boolean }.
    • Defaults thinking: false when no reasoning is configured.
  • Testing:
    • Adds tests in openrouter.spec.ts to verify thinking: true when reasoning is enabled and thinking: false when disabled.
    • Ensures no chat_template_kwargs for non-Terminus models.
    • Tests both streaming and non-streaming paths.
  • Misc:
    • Fixes indentation in multiple README.md files.

This description was created by Ellipsis for 4eb98a7. You can customize this summary. It will automatically update as commits are pushed.

…ntrol

- Add chat_template_kwargs support to OpenRouterChatCompletionParams type
- Convert reasoning configuration to chat_template_kwargs for DeepSeek V3.1 Terminus models
- Set thinking parameter based on reasoning enabled state (not excluded)
- Add comprehensive tests for the new behavior
- Ensures reasoning can be properly disabled (default OFF) for DeepSeek V3.1 Terminus

Fixes #8270
@roomote roomote bot requested review from cte, jr and mrubens as code owners November 6, 2025 18:59
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Nov 6, 2025
@roomote
Copy link
Contributor Author

roomote bot commented Nov 6, 2025

Rooviewer Clock   See task on Roo Cloud

Review complete - no new issues found. The merge commit (4eb98a7) integrates main branch changes without introducing any DeepSeek V3.1 Terminus-specific regressions. Previous feedback has been properly addressed.

Previous reviews

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Nov 6, 2025

const transforms = (this.options.openRouterUseMiddleOutTransform ?? true) ? ["middle-out"] : undefined

// Special handling for DeepSeek V3.1 Terminus models
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider extracting the DeepSeek-specific logic (converting reasoning to chat_template_kwargs) into a helper function to reduce duplication (appears in both createMessage and completePrompt).

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@roomote sould we really do that ?

Copy link
Contributor Author

@roomote roomote bot Nov 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixaroo Clock   See task on Roo Cloud

Extracted the duplicated DeepSeek V3.1 Terminus logic into a helper method. All tests and checks passed.

View commit | Revert commit

Extract duplicated DeepSeek V3.1 Terminus specific logic from createMessage and completePrompt methods into a reusable handleDeepSeekV31Terminus helper method. This improves code maintainability by following the DRY principle.
Copy link

@bozoweed bozoweed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@roomote you have to investigate if needed and apply or not as you want

chatTemplateKwargs: { thinking?: boolean } | undefined
finalReasoning: OpenRouterReasoningParams | undefined
} {
if (!modelId.startsWith("deepseek/deepseek-v3.1-terminus")) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modelId.startsWith("deepseek/deepseek-v3.1-terminus") can be made more efficience by using modelId.include("deepseek-v3.1-terminus") because of distilled version or something like that

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@roomote can you look at my rievew and validate or invalidate it ?

Copy link
Contributor Author

@roomote roomote bot Nov 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixaroo Clock   See task on Roo Cloud

Changed startsWith() to includes() to support DeepSeek V3.1 Terminus model variants (including :exacto). All tests pass.

View commit | Revert commit

@bozoweed
Copy link

@roomote resolve conflicts of that pr appeared from latest change in target branch

@roomote
Copy link
Contributor Author

roomote bot commented Nov 15, 2025

Fixaroo Clock   See task on Roo Cloud

Merge conflicts resolved successfully. All local tests and checks passed.

View commit | Revert commit

Resolved merge conflict by combining:
- DeepSeek V3.1 Terminus chat_template_kwargs support from PR
- Tool metadata support from main branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

[BUG] OpenRouter DeepSeek V3.1 Terminus forces reasoning; cannot disable

4 participants