Skip to content
Draft
Show file tree
Hide file tree
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
13 changes: 13 additions & 0 deletions packages/types/src/providers/deepseek.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@ export const deepSeekModels = {
cacheReadsPrice: 0.028, // $0.028 per million tokens (cache hit) - Updated Dec 9, 2025
description: `DeepSeek-V3.2 (Thinking Mode) achieves performance comparable to OpenAI-o1 across math, code, and reasoning tasks. Supports Chain of Thought reasoning with up to 8K output tokens. Supports JSON output, tool calls, and chat prefix completion (beta).`,
},
// DeepSeek V4 models - https://api-docs.deepseek.com/quick_start/pricing
"deepseek-v4-0324": {
maxTokens: 16_384, // 16K max output
contextWindow: 128_000,
supportsImages: true,
supportsPromptCache: true,
preserveReasoning: true,
inputPrice: 2.19, // $2.19 per million tokens (cache miss)
outputPrice: 8.87, // $8.87 per million tokens
cacheWritesPrice: 2.19, // $2.19 per million tokens (cache miss)
cacheReadsPrice: 0.219, // $0.219 per million tokens (cache hit)
description: `DeepSeek-V4-0324 is the latest flagship reasoning model with significantly improved performance across math, code, and complex reasoning tasks. Features enhanced thinking mode with interleaved reasoning and supports vision, JSON output, tool calls, and extended context.`,
},
} as const satisfies Record<string, ModelInfo>

// https://api-docs.deepseek.com/quick_start/parameter_settings
Expand Down
64 changes: 63 additions & 1 deletion src/api/providers/__tests__/deepseek.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ vi.mock("openai", () => {
}

// Check if this is a reasoning_content test by looking at model
const isReasonerModel = options.model?.includes("deepseek-reasoner")
const isReasonerModel =
options.model?.includes("deepseek-reasoner") || options.model?.includes("deepseek-v4")
const isToolCallTest = options.tools?.length > 0

// Return async iterator for streaming
Expand Down Expand Up @@ -247,6 +248,29 @@ describe("DeepSeekHandler", () => {
expect((model.info as ModelInfo).preserveReasoning).toBeUndefined()
})

it("should return correct model info for deepseek-v4-0324", () => {
const handlerWithV4 = new DeepSeekHandler({
...mockOptions,
apiModelId: "deepseek-v4-0324",
})
const model = handlerWithV4.getModel()
expect(model.id).toBe("deepseek-v4-0324")
expect(model.info).toBeDefined()
expect(model.info.maxTokens).toBe(16_384)
expect(model.info.contextWindow).toBe(128_000)
expect(model.info.supportsImages).toBe(true)
expect(model.info.supportsPromptCache).toBe(true)
})

it("should have preserveReasoning enabled for deepseek-v4-0324", () => {
const handlerWithV4 = new DeepSeekHandler({
...mockOptions,
apiModelId: "deepseek-v4-0324",
})
const model = handlerWithV4.getModel()
expect((model.info as ModelInfo).preserveReasoning).toBe(true)
})

it("should return provided model ID with default model info if model does not exist", () => {
const handlerWithInvalidModel = new DeepSeekHandler({
...mockOptions,
Expand Down Expand Up @@ -475,6 +499,44 @@ describe("DeepSeekHandler", () => {
expect(callArgs.thinking).toBeUndefined()
})

it("should pass thinking parameter for deepseek-v4-0324 model", async () => {
const v4Handler = new DeepSeekHandler({
...mockOptions,
apiModelId: "deepseek-v4-0324",
})

const stream = v4Handler.createMessage(systemPrompt, messages)
for await (const _chunk of stream) {
// Consume the stream
}

// Verify that the thinking parameter was passed to the API for v4 model
expect(mockCreate).toHaveBeenCalledWith(
expect.objectContaining({
thinking: { type: "enabled" },
}),
{},
)
})

it("should handle reasoning_content in streaming responses for deepseek-v4-0324", async () => {
const v4Handler = new DeepSeekHandler({
...mockOptions,
apiModelId: "deepseek-v4-0324",
})

const stream = v4Handler.createMessage(systemPrompt, messages)
const chunks: any[] = []
for await (const chunk of stream) {
chunks.push(chunk)
}

// Should have reasoning chunks since v4 model has preserveReasoning
const reasoningChunks = chunks.filter((chunk) => chunk.type === "reasoning")
expect(reasoningChunks.length).toBeGreaterThan(0)
expect(reasoningChunks[0].text).toBe("Let me think about this...")
})

it("should handle tool calls with reasoning_content", async () => {
const reasonerHandler = new DeepSeekHandler({
...mockOptions,
Expand Down
6 changes: 4 additions & 2 deletions src/api/providers/deepseek.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
deepSeekDefaultModelId,
DEEP_SEEK_DEFAULT_TEMPERATURE,
OPENAI_AZURE_AI_INFERENCE_PATH,
type ModelInfo,
} from "@roo-code/types"

import type { ApiHandlerOptions } from "../../shared/api"
Expand Down Expand Up @@ -55,8 +56,9 @@ export class DeepSeekHandler extends OpenAiHandler {
const modelId = this.options.apiModelId ?? deepSeekDefaultModelId
const { info: modelInfo } = this.getModel()

// Check if this is a thinking-enabled model (deepseek-reasoner)
const isThinkingModel = modelId.includes("deepseek-reasoner")
// Check if this is a thinking-enabled model via the preserveReasoning flag
// This covers deepseek-reasoner and newer v4 models that support thinking mode
const isThinkingModel = (modelInfo as ModelInfo).preserveReasoning === true

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