|
@@ -10,6 +10,7 @@ import delay from "delay"
|
|
|
// Add custom interface for OpenRouter params
|
|
// Add custom interface for OpenRouter params
|
|
|
type OpenRouterChatCompletionParams = OpenAI.Chat.ChatCompletionCreateParams & {
|
|
type OpenRouterChatCompletionParams = OpenAI.Chat.ChatCompletionCreateParams & {
|
|
|
transforms?: string[]
|
|
transforms?: string[]
|
|
|
|
|
+ include_reasoning?: boolean
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Add custom interface for OpenRouter usage chunk
|
|
// Add custom interface for OpenRouter usage chunk
|
|
@@ -110,14 +111,23 @@ export class OpenRouterHandler implements ApiHandler, SingleCompletionHandler {
|
|
|
maxTokens = 8_192
|
|
maxTokens = 8_192
|
|
|
break
|
|
break
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ let temperature = 0
|
|
|
|
|
+ switch (this.getModel().id) {
|
|
|
|
|
+ case "deepseek/deepseek-r1":
|
|
|
|
|
+ // Recommended temperature for DeepSeek reasoning models
|
|
|
|
|
+ temperature = 0.6
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// https://openrouter.ai/docs/transforms
|
|
// https://openrouter.ai/docs/transforms
|
|
|
let fullResponseText = ""
|
|
let fullResponseText = ""
|
|
|
const stream = await this.client.chat.completions.create({
|
|
const stream = await this.client.chat.completions.create({
|
|
|
model: this.getModel().id,
|
|
model: this.getModel().id,
|
|
|
max_tokens: maxTokens,
|
|
max_tokens: maxTokens,
|
|
|
- temperature: 0,
|
|
|
|
|
|
|
+ temperature: temperature,
|
|
|
messages: openAiMessages,
|
|
messages: openAiMessages,
|
|
|
stream: true,
|
|
stream: true,
|
|
|
|
|
+ include_reasoning: true,
|
|
|
// This way, the transforms field will only be included in the parameters when openRouterUseMiddleOutTransform is true.
|
|
// This way, the transforms field will only be included in the parameters when openRouterUseMiddleOutTransform is true.
|
|
|
...(this.options.openRouterUseMiddleOutTransform && { transforms: ["middle-out"] }),
|
|
...(this.options.openRouterUseMiddleOutTransform && { transforms: ["middle-out"] }),
|
|
|
} as OpenRouterChatCompletionParams)
|
|
} as OpenRouterChatCompletionParams)
|
|
@@ -137,6 +147,12 @@ export class OpenRouterHandler implements ApiHandler, SingleCompletionHandler {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const delta = chunk.choices[0]?.delta
|
|
const delta = chunk.choices[0]?.delta
|
|
|
|
|
+ if ("reasoning" in delta && delta.reasoning) {
|
|
|
|
|
+ yield {
|
|
|
|
|
+ type: "reasoning",
|
|
|
|
|
+ text: delta.reasoning,
|
|
|
|
|
+ } as ApiStreamChunk
|
|
|
|
|
+ }
|
|
|
if (delta?.content) {
|
|
if (delta?.content) {
|
|
|
fullResponseText += delta.content
|
|
fullResponseText += delta.content
|
|
|
yield {
|
|
yield {
|