Skip to content

feat: Add DeepSeek AI provider support#1026

Open
haosenwang1018 wants to merge 1 commit intoItzCrazyKns:masterfrom
haosenwang1018:feat/deepseek-provider
Open

feat: Add DeepSeek AI provider support#1026
haosenwang1018 wants to merge 1 commit intoItzCrazyKns:masterfrom
haosenwang1018:feat/deepseek-provider

Conversation

@haosenwang1018
Copy link

@haosenwang1018 haosenwang1018 commented Mar 6, 2026

This PR adds DeepSeek as a new model provider option for Perplexica.

Changes

  • Added full LLM implementation with streaming support
  • Added embedding model support for document search
  • Default models: deepseek-chat and deepseek-reasoner
  • OpenAI-compatible API integration
  • Configuration fields for API key and base URL

Why DeepSeek?

DeepSeek provides high-quality language models at competitive pricing with strong performance on various benchmarks.

Testing

  • Code follows existing provider patterns
  • Includes proper TypeScript types
  • Error handling implemented

Fixes #XXX (if there's a related issue)


Summary by cubic

Added DeepSeek as a new model provider for chat and embeddings using an OpenAI-compatible API. Supports streaming and tool calls with default models deepseek-chat, deepseek-reasoner, and deepseek-embedding.

  • New Features

    • Chat LLM with streaming responses and tool call support.
    • Embeddings for documents and queries.
    • Provider config fields: apiKey and baseURL (default https://api.deepseek.com/v1).
    • Registered provider and exposed default models.
  • Migration

    • Set DEEPSEEK_API_KEY and optionally DEEPSEEK_BASE_URL.
    • Select DeepSeek models in settings; no code changes needed.

Written for commit 16df10e. Summary will update on new commits.

Add DeepSeek as a new model provider option, including:
- DeepSeek LLM implementation with streaming and object generation
- DeepSeek Embedding implementation for document/query embeddings
- Provider configuration with default models (deepseek-chat, deepseek-reasoner)
- Registration in the providers index

DeepSeek provides high-quality language models at competitive pricing
and uses an OpenAI-compatible API for easy integration.
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

3 issues found across 4 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/lib/models/providers/deepseek/deepseekLLM.ts">

<violation number="1" location="src/lib/models/providers/deepseek/deepseekLLM.ts:90">
P2: DeepSeek chat-completions payload uses `max_completion_tokens` instead of the documented `max_tokens`, risking ignored limits or request errors.</violation>

<violation number="2" location="src/lib/models/providers/deepseek/deepseekLLM.ts:106">
P2: Unguarded `JSON.parse` of model tool arguments can throw and fail the entire non-stream completion when one tool call contains invalid JSON.</violation>

<violation number="3" location="src/lib/models/providers/deepseek/deepseekLLM.ts:165">
P1: Streaming tool-call reconstruction is mis-indexed: new calls are appended with `push()` but subsequent chunks are merged by `tc.index`, which can corrupt multi-tool outputs.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

id: tc.id!,
arguments: tc.function?.arguments || '',
};
recievedToolCalls.push(call);
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Mar 6, 2026

Choose a reason for hiding this comment

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

P1: Streaming tool-call reconstruction is mis-indexed: new calls are appended with push() but subsequent chunks are merged by tc.index, which can corrupt multi-tool outputs.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/lib/models/providers/deepseek/deepseekLLM.ts, line 165:

<comment>Streaming tool-call reconstruction is mis-indexed: new calls are appended with `push()` but subsequent chunks are merged by `tc.index`, which can corrupt multi-tool outputs.</comment>

<file context>
@@ -0,0 +1,228 @@
+                  id: tc.id!,
+                  arguments: tc.function?.arguments || '',
+                };
+                recievedToolCalls.push(call);
+                return { ...call, arguments: parse(call.arguments || '{}') };
+              } else {
</file context>
Fix with Cubic

messages: this.convertToDeepSeekMessages(input.messages),
temperature: input.options?.temperature ?? 1.0,
top_p: input.options?.topP,
max_completion_tokens: input.options?.maxTokens,
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Mar 6, 2026

Choose a reason for hiding this comment

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

P2: DeepSeek chat-completions payload uses max_completion_tokens instead of the documented max_tokens, risking ignored limits or request errors.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/lib/models/providers/deepseek/deepseekLLM.ts, line 90:

<comment>DeepSeek chat-completions payload uses `max_completion_tokens` instead of the documented `max_tokens`, risking ignored limits or request errors.</comment>

<file context>
@@ -0,0 +1,228 @@
+      messages: this.convertToDeepSeekMessages(input.messages),
+      temperature: input.options?.temperature ?? 1.0,
+      top_p: input.options?.topP,
+      max_completion_tokens: input.options?.maxTokens,
+      stop: input.options?.stopSequences,
+      frequency_penalty: input.options?.frequencyPenalty,
</file context>
Fix with Cubic

return {
name: tc.function.name,
id: tc.id,
arguments: JSON.parse(tc.function.arguments),
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Mar 6, 2026

Choose a reason for hiding this comment

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

P2: Unguarded JSON.parse of model tool arguments can throw and fail the entire non-stream completion when one tool call contains invalid JSON.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/lib/models/providers/deepseek/deepseekLLM.ts, line 106:

<comment>Unguarded `JSON.parse` of model tool arguments can throw and fail the entire non-stream completion when one tool call contains invalid JSON.</comment>

<file context>
@@ -0,0 +1,228 @@
+                return {
+                  name: tc.function.name,
+                  id: tc.id,
+                  arguments: JSON.parse(tc.function.arguments),
+                };
+              }
</file context>
Fix with Cubic

Copy link

@xkonjin xkonjin left a comment

Choose a reason for hiding this comment

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

Quick review pass:

  • Main risk area here is auth/session state and stale credential handling.
  • I didn’t see targeted regression coverage in the diff; please add or point CI at a focused test for the changed path in deepseekEmbedding.ts, deepseekLLM.ts, index.ts (+1 more).
  • Before merge, I’d smoke-test the behavior touched by deepseekEmbedding.ts, deepseekLLM.ts, index.ts (+1 more) with malformed input / retry / rollback cases, since that’s where this class of change usually breaks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants