Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/api/providers/openrouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,21 @@ export class OpenRouterHandler implements ApiHandler, SingleCompletionHandler {
}

let temperature = 0
if (this.getModel().id === "deepseek/deepseek-r1" || this.getModel().id.startsWith("deepseek/deepseek-r1:")) {
let topP: number | undefined = undefined

// Handle models based on deepseek-r1
if (
this.getModel().id === "deepseek/deepseek-r1" ||
this.getModel().id.startsWith("deepseek/deepseek-r1:") ||
this.getModel().id === "perplexity/sonar-reasoning"
) {
// Recommended temperature for DeepSeek reasoning models
temperature = 0.6
// DeepSeek highly recommends using user instead of system role
// DeepSeek highly recommends using user instead of system
// role
openAiMessages = convertToR1Format([{ role: "user", content: systemPrompt }, ...messages])
// Some provider support topP and 0.95 is value that Deepseek used in their benchmarks
topP = 0.95
}

// https://openrouter.ai/docs/transforms
Expand All @@ -127,6 +137,7 @@ export class OpenRouterHandler implements ApiHandler, SingleCompletionHandler {
model: this.getModel().id,
max_tokens: maxTokens,
temperature: temperature,
top_p: topP,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there any chance of this breaking API calls to providers who don't support top_p? If so we might consider doing what we do with the transforms field below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the same as with include_reasoning: it's passed to every model, not only for deepseek.

From oupenrouter docs:

Non-standard parameters: If the chosen model doesn't support a request parameter (such as logit_bias in non-OpenAI models, or top_k for OpenAI), then the parameter is ignored. The rest are forwarded to the underlying model API.

messages: openAiMessages,
stream: true,
include_reasoning: true,
Expand Down