Skip to content

Commit ba1d5f0

Browse files
committed
fix: normalizeDeepSeekReasoningEffort
1 parent df966fe commit ba1d5f0

1 file changed

Lines changed: 42 additions & 8 deletions

File tree

src/api/providers/deepseek.ts

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
DEEP_SEEK_DEFAULT_TEMPERATURE,
88
OPENAI_AZURE_AI_INFERENCE_PATH,
99
type ModelInfo,
10+
DeepSeekModelId,
1011
} from "@roo-code/types"
1112

1213
import type { ApiHandlerOptions } from "../../shared/api"
@@ -23,7 +24,7 @@ import { handleOpenAIError } from "./utils/error-handler"
2324
// Custom interface for DeepSeek params to support thinking mode
2425
type DeepSeekChatCompletionParams = Omit<OpenAI.Chat.ChatCompletionCreateParamsStreaming, "reasoning_effort"> & {
2526
thinking?: { type: "enabled" | "disabled" }
26-
reasoning_effort?: "high" | "max"
27+
reasoning_effort?: "low" | "high" | "max"
2728
}
2829

2930
const deepSeekV4ThinkingModels = new Set(["deepseek-v4-flash", "deepseek-v4-pro"])
@@ -40,13 +41,46 @@ const isDeepSeekThinkingEnabled = (modelId: string, options: ApiHandlerOptions)
4041
return supportsDeepSeekThinkingToggle(modelId)
4142
}
4243

43-
const normalizeDeepSeekReasoningEffort = (reasoningEffort?: string): "high" | "max" | undefined => {
44-
if (!reasoningEffort || reasoningEffort === "disable") {
45-
return undefined
44+
// https://api-docs.deepseek.com/guides/thinking_mode/
45+
const normalizeDeepSeekReasoningEffort = (
46+
modelId: DeepSeekModelId,
47+
reasoningEffort?: string,
48+
): "low" | "high" | "max" | undefined => {
49+
switch (modelId) {
50+
case "deepseek-v4-flash":
51+
switch (reasoningEffort) {
52+
case "low":
53+
return "low"
54+
55+
case "high":
56+
return "high"
57+
58+
case "xhigh":
59+
return "high"
60+
61+
case "max":
62+
return "max"
63+
}
64+
break
65+
66+
case "deepseek-v4-pro":
67+
switch (reasoningEffort) {
68+
case "low":
69+
return "high"
70+
71+
case "high":
72+
return "high"
73+
74+
case "xhigh":
75+
return "max"
76+
77+
case "max":
78+
return "max"
79+
}
80+
break
4681
}
4782

48-
// DeepSeek currently maps low/medium to high and xhigh to max in thinking mode.
49-
return reasoningEffort === "xhigh" ? "max" : "high"
83+
return undefined
5084
}
5185

5286
// Use the computed maxTokens from getModelParams rather than raw model metadata.
@@ -92,7 +126,7 @@ export class DeepSeekHandler extends OpenAiHandler {
92126
messages: Anthropic.Messages.MessageParam[],
93127
metadata?: ApiHandlerCreateMessageMetadata,
94128
): ApiStream {
95-
const modelId = this.options.apiModelId ?? deepSeekDefaultModelId
129+
const modelId = (this.options.apiModelId as DeepSeekModelId) ?? deepSeekDefaultModelId
96130
const { info: modelInfo, temperature, reasoningEffort, maxTokens } = this.getModel()
97131

98132
const isThinkingModel = isDeepSeekThinkingEnabled(modelId, this.options)
@@ -101,7 +135,7 @@ export class DeepSeekHandler extends OpenAiHandler {
101135
: isThinkingModel
102136
? ({ type: "enabled" } as const)
103137
: undefined
104-
const deepSeekReasoningEffort = isThinkingModel ? normalizeDeepSeekReasoningEffort(reasoningEffort) : undefined
138+
const deepSeekReasoningEffort = normalizeDeepSeekReasoningEffort(modelId, reasoningEffort)
105139

106140
// Convert messages to R1 format (merges consecutive same-role messages)
107141
// This is required for DeepSeek which does not support successive messages with the same role

0 commit comments

Comments
 (0)