Skip to content

feat: Complete DeepSeek API adapter implementation#11130

Open
dixoxib wants to merge 49 commits intocontinuedev:mainfrom
dixoxib:deepseek-api
Open

feat: Complete DeepSeek API adapter implementation#11130
dixoxib wants to merge 49 commits intocontinuedev:mainfrom
dixoxib:deepseek-api

Conversation

@dixoxib
Copy link

@dixoxib dixoxib commented Mar 6, 2026

Description

Enhanced DeepSeek API adapter from a minimal 73‑line implementation to a complete, production‑ready adapter with all features expected from a modern LLM provider integration following official docs.

Key improvements:

  • Added streaming & non‑streaming chat completions with reasoning support
  • Implemented tool calling compatibility and thinking tool-call chains
  • Implemented model listing via DeepSeek's /models endpoint
  • Enhanced FIM beta endpoint
  • Added type safety with comprehensive TypeScript types
  • Improved converting with detailed warnings
  • Added prefix completion support (beta chat endpoint)
  • Added workarounds for DeepSeek Reasoner edge cases
  • Improved documentation, configuration and onboarding
  • minimal invasive to codebase
  • Issue (Apply/edit writes raw model reasoning into files instead of filtering #10783) fixed by adding role filter to chat() (function seems not fully implemented yet)
  • token counter now handles pre-filled messages

Files changed: 39 files, including core implementation, tests, documentation, and configuration updates, small fixes.

AI Code Review

  • Team members only: AI review runs automatically when PR is opened or marked ready for review
  • Team members can also trigger a review by commenting @continue-review

Checklist

  • I've read the contributing guide
  • The relevant docs have been updated or created
  • The relevant tests have been updated or created

Screen recording or screenshot

Key demonstrations:

  1. Onboarding
  2. DeepSeek Reasoner showing reasoning_content in responses
  3. Thinking-Tool-calling-Chains
  4. Non-streaming summarize functionality
sv.mp4

Tests

Added/updated tests:

  • packages/openai-adapters/src/test/deepseek-converters.test.ts – Comprehensive unit tests for converter functions
  • core/llm/llms/DeepSeek.unit.test.ts – Unit tests for DeepSeek provider class
  • core/llm/llms/DeepSeek.vitest.ts – Integration tests
  • packages/openai-adapters/src/test/DeepSeekApi.test.ts – API adapter test
  • core/llm/llms/DeepSeek.tools.test.ts – Thinking tool chain test

The enhancement addresses limitations in the current minimal implementation and enables full DeepSeek functionality including Agent mode with tool calling for Reasoner model.


I have read the CLA Document and I hereby sign the CLA


Continue Tasks: 🔄 7 running — View all


Summary by cubic

Complete DeepSeek provider with chat, reasoning, tools, and FIM (beta). Adds assistant‑only streaming, streamed usage/cost reporting (with cache stats), improved token counting/prefill handling, and a useBetaEndpoints flag while preserving apiBase for official and proxy setups.

  • New Features

    • DeepSeek provider: streaming/non‑streaming chat, reasoning_content, thinking→tool call pairing, tool choice, model autodetect; added to onboarding, llm-info, and UI/VS Code.
    • FIM via deepseek-fim-beta; supportsFim true only for FIM beta; uses /beta chat/completions on official api.deepseek.com or when useBetaEndpoints is true; otherwise standard endpoints (no /beta in apiBase, no stray fim prefix).
    • Token/cost: reserve full maxTokens, 1.05 token multiplier, improved pruning, prefill fix, streamed usage stats, DeepSeek pricing with cache hit/miss.
    • Stability: stream/accumulate assistant chunks only; provider supports parallel gen; tests added; docs include proxy guidance.
  • Migration

    • Use provider: deepseek with models: deepseek-chat, deepseek-reasoner, deepseek-fim-beta. deepseek-chat is recommended for Agent mode.
    • apiBase defaults to https://api.deepseek.com/ (do not include /beta). Adapter auto‑selects beta endpoints for the official base or when useBetaEndpoints: true (for proxies that require beta paths).
    • Config schema: DeepSeek now uses DeepseekConfig (extends BasePlusConfig) instead of OpenAIConfigSchema; existing configs continue to work.

Written for commit 18263ca. Summary will update on new commits.

CI Bot and others added 27 commits February 14, 2026 10:55
…model provider updates

- Add DeepSeek model provider implementation with proper FIM support
- Implement DeepSeek API adapter with OpenAI-compatible interface
- Add tool call support and thinking mode integration
- Update model provider configuration and onboarding
- Add comprehensive type definitions and validation
- Update documentation for DeepSeek model capabilities
- Fix file rename from Deepseek.ts to DeepSeek.ts for consistency
- Enhance DeepSeek provider with improved FIM support
- Update onboarding configuration for DeepSeek
- Refactor token counting and autodetection logic
- Improve system tool call interception
- Streamline chat response streaming
- Update UI and extension components for better integration
- Refactor token counting logic
- Enhance DeepSeek provider capabilities
- Update chat and edit templates
- Improve system tool call interception
- Streamline API adapters and converters
- Add unit test enhancements
Integrate latest upstream changes including:
- zAI provider support
- Background job service
- CLI tool improvements
- Updated model configurations
- Maintain DeepSeek integration
- Rewrite setupProviderConfig to use direct model config instead of uses/with syntax
- Add roles property to model config schema
- Improve DeepSeek message conversion with toChatBody
- Update conversationCompaction imports
- Add roles field to config schema for VS Code
- Update DeepSeek provider description
- Add debug logging to DeepSeekApi adapter
- Simplify DeepSeek onboarding config to use direct model objects
- Improve token counting for DeepSeek models (reserve full maxTokens)
- Fix FIM support tests for DeepSeek models
- Adjust maxTokens for DeepSeek Reasoner to 32k (API limit)
- Update DeepSeek provider info with correct context lengths
- Enhance DeepSeek converters to handle max_completion_tokens
- Clean up imports and schema definitions
- Update documentation with accurate DeepSeek capabilities
- Remove debug console logs from DeepSeek adapter
@dixoxib dixoxib requested a review from a team as a code owner March 6, 2026 16:59
@dixoxib dixoxib requested review from sestinj and removed request for a team March 6, 2026 16:59
dixoxib and others added 3 commits March 6, 2026 18:30
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
…roviders

- Remove trailing slash normalization in DeepSeekApi constructor
- Update test expectations to match actual behavior
- All tests pass, including main integration test
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.

2 issues found across 2 files (changes from recent commits).

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="packages/openai-adapters/src/apis/DeepSeek.ts">

<violation number="1" location="packages/openai-adapters/src/apis/DeepSeek.ts:50">
P2: apiBase trailing-slash normalization was removed; relative URL construction can drop path segments for custom bases like https://host/v1, misrouting requests.</violation>

<violation number="2" location="packages/openai-adapters/src/apis/DeepSeek.ts:316">
P2: FIM is a beta feature that requires the beta base URL; building the endpoint as `new URL("completions", this.apiBase)` sends FIM requests to the non‑beta `/completions` path when using the default base URL, which breaks FIM. Restore beta-aware routing or force the beta base URL for FIM calls.</violation>
</file>

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

dixoxib added 7 commits March 6, 2026 19:16
- Update test expectations to match actual regex logic
- deepseek-chat matches /deepseek/ and /r1|reasoner|-chat/ regex combo
- Keep deepseek-coder as non-recommended
- Fix code style issues in DeepSeek.ts and DeepSeekApi.test.ts
- Ensure consistent formatting before PR merge
…licit type annotation from static defaultOptions to ensure proper inheritance\n- Remove overridden chat() method that bypassed adapter disable in tests\n- Tests now pass: default API base correctly detected and chat requests use mocked fetch
- Move applyToolOverrides import to avoid potential circular dependencies
- Filter chat() accumulation to only assistant messages (ignore thinking messages)
- Maintains backward compatibility with existing functionality
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.

1 issue found across 2 files (changes from recent commits).

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="packages/openai-adapters/src/apis/DeepSeek.ts">

<violation number="1" location="packages/openai-adapters/src/apis/DeepSeek.ts:123">
P2: Chat endpoint base normalization is applied to all chat requests, causing `/beta/`-scoped `apiBase` values to be stripped for normal chat and potentially breaking custom `/beta/` deployments.</violation>
</file>

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

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.

2 issues found across 5 files (changes from recent commits).

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="packages/openai-adapters/src/apis/DeepSeek.ts">

<violation number="1" location="packages/openai-adapters/src/apis/DeepSeek.ts:123">
P1: Removed `/beta/` base normalization causes malformed or incorrect chat endpoints for clients configured with `apiBase` ending in `/beta/`.</violation>

<violation number="2" location="packages/openai-adapters/src/apis/DeepSeek.ts:321">
P1: FIM endpoint now double-prefixes `beta` when `apiBase` already includes `/beta/`, breaking beta-configured clients.</violation>
</file>

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

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.

1 issue found across 2 files (changes from recent commits).

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="core/llm/countTokens.ts">

<violation number="1" location="core/llm/countTokens.ts:464">
P1: Prefill token budgeting double-counts `msgsCopy` as both non-negotiable and prunable history, causing incorrect pruning and possible premature context overflow errors.</violation>
</file>

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

dixoxib added 2 commits March 11, 2026 04:19
- Fix double-counting of tokens in prefill scenarios that caused incorrect pruning
- Treat last assistant message as non-negotiable instead of entire conversation
- Prevents 'Error parsing chat history: no user/tool message found' during edits
- Update DeepSeek token multiplier from 1.00 to 1.05

Resolves issue where edit requests with DeepSeek and other prefill-enabled models
would fail due to incorrect token budgeting in compileChatMessages.
@dixoxib
Copy link
Author

dixoxib commented Mar 11, 2026

@cubic-dev-ai something went wrong, re-run a review.

@cubic-dev-ai
Copy link
Contributor

cubic-dev-ai bot commented Mar 11, 2026

@cubic-dev-ai something went wrong, re-run a review.

@dixoxib I have started the AI code review. It will take a few minutes to complete.

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.

No issues found across 39 files

dixoxib added 2 commits March 12, 2026 20:46
- Only use beta endpoints (beta/chat/completions, beta/completions) when connecting to official DeepSeek API (api.deepseek.com)
- For other API bases (e.g., local proxies, other providers), use regular endpoints (chat/completions, completions)
- This ensures compatibility with non-official DeepSeek API implementations
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.

1 issue found across 1 file (changes from recent commits).

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="packages/openai-adapters/src/apis/DeepSeek.ts">

<violation number="1" location="packages/openai-adapters/src/apis/DeepSeek.ts:57">
P2: Hostname-gating beta endpoints changes established routing for custom `apiBase` domains, causing prefix/FIM requests to switch off beta paths and potentially break existing proxy setups.</violation>
</file>

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

- Extend DeepseekConfigSchema with optional useBetaEndpoints boolean
- Update DeepSeekApi constructor to respect config.useBetaEndpoints with fallback to hostname detection
- Add comprehensive proxy configuration documentation
- Explain when to manually enable/disable beta endpoints for proxy setups
- Maintain backward compatibility for official API and custom deployments
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.

2 issues found across 5 files (changes from recent commits).

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="packages/openai-adapters/src/types.ts">

<violation number="1" location="packages/openai-adapters/src/types.ts:264">
P1: Added `DeepseekConfigSchema` duplicates the `deepseek` discriminator already present in `OpenAIConfigSchema`, which can make `z.discriminatedUnion("provider", ...)` throw at initialization.</violation>
</file>

<file name="docs/customize/model-providers/more/deepseek.mdx">

<violation number="1" location="docs/customize/model-providers/more/deepseek.mdx:147">
P2: Docs incorrectly label `fim/completions` as a standard OpenAI-compatible endpoint, which can mislead proxy/local users and cause FIM/autocomplete 404s.</violation>
</file>

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

dixoxib added 3 commits March 15, 2026 01:49
- Remove 'deepseek' from OpenAIConfigSchema provider union
- Create DeepseekConfigSchema extending BasePlusConfig with useBetaEndpoints option
- Change OpenAIApi constructor to accept BasePlusConfig instead of OpenAIConfig
- Update LLMConfigSchema to use union of DeepseekConfigSchema and other providers
- Fix documentation to reflect correct FIM endpoint paths
- All tests pass, no breaking changes for existing configurations
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.

1 issue found across 1 file (changes from recent commits).

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="docs/customize/model-providers/more/deepseek.mdx">

<violation number="1" location="docs/customize/model-providers/more/deepseek.mdx:147">
P2: Documentation incorrectly claims standard `chat/completions` supports prefill for proxy/custom deployments, conflicting with beta-only prefix completion guidance and likely causing misconfiguration.</violation>
</file>

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

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

Labels

ai-merge size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

1 participant