-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add support for DeepSeek #1444
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add support for DeepSeek #1444
Conversation
# what changed - Introduced a new `DeepseekAIClient` class for handling chat completions with the Deepseek API. - Updated `LLMProvider` to include support for the Deepseek model, allowing it to instantiate `DeepseekAIClient` based on the model name. - Modified the `AvailableModel` type to include "deepseek" as a valid model provider. # test plan - Ensure that the new client correctly handles chat completion requests and integrates seamlessly with existing LLM functionality.
…ntegration with LLMProvider
…rove data extraction safety # what changed - Modified the instruction for JSON responses to clarify that the response must be in JSON format. - Added optional chaining to safely access the message content in the response, preventing potential runtime errors. # test plan - Verify that the updated JSON response instructions are correctly interpreted by the client. - Ensure that the optional chaining prevents errors when the message content is undefined.
…appings # what changed - Updated the LLMProvider constructor to accept a `manual` boolean option. - Adjusted the logic in `getModelProvider` to conditionally handle model names based on the `manual` flag. - Removed deprecated Deepseek model entries and added support for "deepseek/deepseek-reasoner" in the AvailableModel type. - Introduced a new `manual` option in the V3Options interface. # test plan - Verify that the LLMProvider correctly initializes with the manual option. - Ensure that model provider mappings function as expected with the new logic. - Test the integration of the new "deepseek/deepseek-reasoner" model.
# what changed - Added an optional `manual` parameter to the V3Evaluator class constructor. - Updated the LLMProvider constructor to accept a `manual` boolean option, allowing for more flexible model handling. - Adjusted the logic in the getClient method to utilize the new manual parameter. # test plan - Verify that the V3Evaluator initializes correctly with the manual option. - Ensure that the LLMProvider functions as expected with the manual flag.
# what changed - Added spaces in catch blocks for consistency. - Introduced optional chaining for the manual option in LLMProvider initialization. - Minor formatting adjustments to enhance readability. # test plan - Ensure that the V3 class functions correctly with the updated formatting and optional chaining.
# Conflicts: # packages/core/package.json
🦋 Changeset detectedLatest commit: 460b19c The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
- Use .filter() with type guards instead of .map().join() for message formatting - Remove duplicate requestId logging from response to match OpenAI - Maintains type safety and consistency across LLM clients
The manual flag was a workaround for the routing bug where deepseek models bypassed DeepseekAIClient. Since we fixed the routing by checking modelToProviderMap first, the manual flag is no longer needed.
Completes removal of unused manual flag workaround from all locations.
There was a problem hiding this 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 12 files
Architecture diagram
sequenceDiagram
participant Agent as V3AgentHandler
participant Provider as LLMProvider
participant DSClient as DeepSeekAIClient
participant Tools as Agent Tools (Act/Extract)
participant API as DeepSeek API
Note over Agent,API: Scenario: Agent execution using new DeepSeek integration
%% Initialization & Routing Phase
Agent->>Provider: getClient("deepseek/deepseek-chat")
Note right of Provider: CHANGED: Routing Fix<br/>Checks explicit map before generic "/" fallback
alt Model in modelToProviderMap (NEW)
Provider->>DSClient: NEW: Instantiate DeepSeekAIClient
DSClient-->>Provider: Client Instance
else Generic Model (e.g. custom/other)
Provider->>Provider: Use generic AI SDK fallback
end
Provider-->>Agent: Return LLMClient
%% Execution Phase
loop Agent Step
Agent->>Tools: Initialize Tool (e.g., act, extract)
Note right of Agent: CHANGED: executionModel passed as<br/>ModelConfiguration object (was string)
Agent->>DSClient: createChatCompletion(messages, schema)
opt Schema Validation (NEW)
DSClient->>DSClient: Convert Zod to JSON Schema
Note right of DSClient: Ensures compatibility with<br/>DeepSeek JSON mode
end
DSClient->>API: POST /chat/completions
API-->>DSClient: 200 OK (JSON string)
DSClient->>DSClient: NEW: Safe JSON Parse & Validation
DSClient-->>Agent: Structured Response
end
Greptile SummaryThis PR adds DeepSeek chat completion support by implementing Key Changes:
Issues Found:
Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant V3
participant LLMProvider
participant DeepSeekAIClient
participant OpenAI SDK
participant DeepSeek API
participant AISDK
User->>V3: agent({ model: "deepseek/deepseek-chat" })
V3->>LLMProvider: getClient("deepseek/deepseek-chat")
Note over LLMProvider: Check modelToProviderMap
LLMProvider->>LLMProvider: Find provider = "deepseek"
LLMProvider->>DeepSeekAIClient: new DeepSeekAIClient()
DeepSeekAIClient->>OpenAI SDK: new OpenAI({ baseURL: "https://api.deepseek.com/v1" })
LLMProvider-->>V3: Return DeepSeekAIClient
V3->>DeepSeekAIClient: createChatCompletion()
alt With response_model (JSON mode)
DeepSeekAIClient->>DeepSeekAIClient: Add JSON schema instructions
DeepSeekAIClient->>DeepSeekAIClient: Set response_format: { type: "json_object" }
end
DeepSeekAIClient->>OpenAI SDK: chat.completions.create()
OpenAI SDK->>DeepSeek API: POST /v1/chat/completions
DeepSeek API-->>OpenAI SDK: Response
OpenAI SDK-->>DeepSeekAIClient: Response
alt With response_model
DeepSeekAIClient->>DeepSeekAIClient: JSON.parse(content)
DeepSeekAIClient->>DeepSeekAIClient: validateZodSchema()
alt Validation fails
DeepSeekAIClient->>DeepSeekAIClient: Retry with retries-1
end
end
DeepSeekAIClient-->>V3: Return response
V3-->>User: Agent execution result
Note over V3,AISDK: For AI SDK integration (e.g., streamText)
User->>V3: Use AI SDK methods
V3->>DeepSeekAIClient: getLanguageModel()
DeepSeekAIClient->>AISDK: createDeepSeek({ apiKey })
AISDK-->>DeepSeekAIClient: DeepSeek provider
DeepSeekAIClient-->>V3: LanguageModelV2
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
10 files reviewed, 1 comment
| throw new CreateChatCompletionResponseError(errorMessage); | ||
| } | ||
|
|
||
| const parsedData = JSON.parse(extractedData); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: JSON.parse can throw an error if the response is malformed. Wrap in try-catch to handle gracefully (see GoogleClient:364-373 for reference pattern)
| const parsedData = JSON.parse(extractedData); | |
| let parsedData; | |
| try { | |
| parsedData = JSON.parse(extractedData); | |
| } catch (e) { | |
| logger({ | |
| category: "deepseek", | |
| message: `Failed to parse JSON response: ${e.message}`, | |
| level: 0, | |
| }); | |
| if (retries > 0) { | |
| return this.createChatCompletion({ | |
| options: options as ChatCompletionOptions, | |
| logger, | |
| retries: retries - 1, | |
| }); | |
| } | |
| throw new CreateChatCompletionResponseError("Failed to parse JSON response"); | |
| } |
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/core/lib/v3/llm/DeepSeekAIClient.ts
Line: 274:274
Comment:
**logic:** `JSON.parse` can throw an error if the response is malformed. Wrap in try-catch to handle gracefully (see GoogleClient:364-373 for reference pattern)
```suggestion
let parsedData;
try {
parsedData = JSON.parse(extractedData);
} catch (e) {
logger({
category: "deepseek",
message: `Failed to parse JSON response: ${e.message}`,
level: 0,
});
if (retries > 0) {
return this.createChatCompletion({
options: options as ChatCompletionOptions,
logger,
retries: retries - 1,
});
}
throw new CreateChatCompletionResponseError("Failed to parse JSON response");
}
```
How can I resolve this? If you propose a fix, please make it concise.
why
what changed
test plan
Summary by cubic
Adds Deepseek chat completion support and fixes provider routing. Improves JSON-only responses, schema validation, and standardizes executionModel typing.
New Features
Bug Fixes
Written for commit 460b19c. Summary will update automatically on new commits.