-
Notifications
You must be signed in to change notification settings - Fork 132
fix: enable Alibaba DeepSeek v3.2 thinking #1903
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1878,6 +1878,65 @@ export async function prepareRequestBody( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case "alibaba": { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (stream) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| requestBody.stream_options = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| include_usage: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (response_format) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| requestBody.response_format = response_format; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (temperature !== undefined) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| requestBody.temperature = temperature; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (max_tokens !== undefined) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| requestBody.max_tokens = max_tokens; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (top_p !== undefined) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| requestBody.top_p = top_p; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (frequency_penalty !== undefined) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| requestBody.frequency_penalty = frequency_penalty; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (presence_penalty !== undefined) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| requestBody.presence_penalty = presence_penalty; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| usedModel === "deepseek-v3.2" && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| supportsReasoning && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (reasoning_effort !== undefined || reasoning_max_tokens !== undefined) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+1907
to
+1911
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The new Useful? React with 👍 / 👎. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| requestBody.enable_thinking = true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (reasoning_max_tokens !== undefined) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| requestBody.thinking_budget = Math.min(reasoning_max_tokens, 32768); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else if (reasoning_effort !== undefined) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+1914
to
+1916
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Normalize At Line 1915, negative/non-finite values can propagate directly into Proposed fix- if (reasoning_max_tokens !== undefined) {
- requestBody.thinking_budget = Math.min(reasoning_max_tokens, 32768);
+ if (reasoning_max_tokens !== undefined) {
+ const normalizedBudget = Number.isFinite(reasoning_max_tokens)
+ ? Math.max(1, Math.min(Math.floor(reasoning_max_tokens), 32768))
+ : 8192;
+ requestBody.thinking_budget = normalizedBudget;🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const getThinkingBudget = (effort: string) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| switch (effort) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case "minimal": | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return 512; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case "low": | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return 2048; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case "high": | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return 24576; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case "xhigh": | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return 32768; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case "medium": | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| default: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return 8192; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| requestBody.thinking_budget = getThinkingBudget(reasoning_effort); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+1910
to
+1934
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (reasoning_effort !== undefined || reasoning_max_tokens !== undefined) | |
| ) { | |
| requestBody.enable_thinking = true; | |
| if (reasoning_max_tokens !== undefined) { | |
| requestBody.thinking_budget = Math.min(reasoning_max_tokens, 32768); | |
| } else if (reasoning_effort !== undefined) { | |
| const getThinkingBudget = (effort: string) => { | |
| switch (effort) { | |
| case "minimal": | |
| return 512; | |
| case "low": | |
| return 2048; | |
| case "high": | |
| return 24576; | |
| case "xhigh": | |
| return 32768; | |
| case "medium": | |
| default: | |
| return 8192; | |
| } | |
| }; | |
| requestBody.thinking_budget = getThinkingBudget(reasoning_effort); | |
| } | |
| reasoning_effort !== undefined | |
| ) { | |
| requestBody.enable_thinking = true; | |
| const getThinkingBudget = (effort: string) => { | |
| switch (effort) { | |
| case "minimal": | |
| return 512; | |
| case "low": | |
| return 2048; | |
| case "high": | |
| return 24576; | |
| case "xhigh": | |
| return 32768; | |
| case "medium": | |
| default: | |
| return 8192; | |
| } | |
| }; | |
| requestBody.thinking_budget = getThinkingBudget(reasoning_effort); |
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.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== Alibaba model mappings with reasoning flags =="
rg -nP --type=ts -C3 'providerId:\s*"alibaba"|modelName:\s*"|reasoning:\s*true|supportedParameters' packages/models/src/models
echo
echo "== Alibaba request-body handling =="
rg -nP --type=ts -C4 'case\s+"alibaba"|reasoning_effort|reasoning_max_tokens|enable_thinking|thinking_budget' packages/actions/src/prepare-request-body.tsRepository: theopenco/llmgateway
Length of output: 50377
🏁 Script executed:
# Search for deepseek-v3.2 model in the codebase to verify it exists
rg -n "deepseek-v3\.2" packages/models/src/models
# Get full Alibaba case from prepare-request-body.ts
sed -n '1881,1937p' packages/actions/src/prepare-request-body.ts
# Find all Alibaba models to see the complete list
rg -n 'providerId:\s*"alibaba"' packages/models/src/models --type=ts -A 5 | grep -E 'modelName|providerId|reasoning' | head -50Repository: theopenco/llmgateway
Length of output: 5286
🏁 Script executed:
# Check if deepseek-v3.2 has reasoning flag set
sed -n '119,185p' packages/models/src/models/deepseek.ts
# Check kimi-k2-thinking Alibaba model for reasoning flag
sed -n '164,180p' packages/models/src/models/moonshot.ts
# Check kimi-k2.5 Alibaba model for reasoning flag
sed -n '266,281p' packages/models/src/models/moonshot.ts
# Check glm-5 Alibaba model for reasoning flag
sed -n '76,105p' packages/models/src/models/zai.ts
# Check glm-4.7 Alibaba model for reasoning flag
sed -n '487,516p' packages/models/src/models/zai.tsRepository: theopenco/llmgateway
Length of output: 3619
🏁 Script executed:
# Find where supportsReasoning is defined
rg -n "supportsReasoning" packages/actions/src/prepare-request-body.ts -B 5 | head -50
# Search for test cases related to Alibaba reasoning
fd -e test.ts -e spec.ts packages/ | xargs grep -l "alibaba.*reason" 2>/dev/null || echo "No Alibaba reasoning tests found"
# Check how supportsReasoning is derived - look for reasoning field usage
rg -n "\.reasoning" packages/actions/src/prepare-request-body.ts -B 3 -A 1Repository: theopenco/llmgateway
Length of output: 3029
🏁 Script executed:
# Get context around line 804-807 to see full logic for supportsReasoning
sed -n '800,815p' packages/actions/src/prepare-request-body.ts
# Check if deepseek-v3.2 alibaba provider has any reasoning field definition
rg -A 8 'providerId.*alibaba.*deepseek-v3' packages/models/src/models/deepseek.ts
# Check what happens after the Alibaba case - is there any fallback for other models?
sed -n '1937,1945p' packages/actions/src/prepare-request-body.tsRepository: theopenco/llmgateway
Length of output: 741
🏁 Script executed:
# Check the full default case for any reasoning handling
sed -n '1937,2000p' packages/actions/src/prepare-request-body.tsRepository: theopenco/llmgateway
Length of output: 1618
🏁 Script executed:
# Find where enable_thinking is initially set for Alibaba models
rg -n "enable_thinking" packages/actions/src/prepare-request-body.ts | head -20
# Check if there's any reasoning handling before the Alibaba case that might catch it
sed -n '1800,1881p' packages/actions/src/prepare-request-body.ts | grep -A 10 -B 10 "enable_thinking\|thinking_budget\|reasoning"Repository: theopenco/llmgateway
Length of output: 733
Fix Alibaba reasoning support for all capable models.
The current implementation only attempts reasoning handling for deepseek-v3.2, but that model lacks the reasoning: true flag, so the condition will never activate. Meanwhile, other Alibaba models with reasoning capability (kimi-k2-thinking, kimi-k2.5, glm-5, glm-4.7) are silently blocked.
Replace the model-specific check with a general condition that applies reasoning fields to all Alibaba models with supportsReasoning === true:
if (supportsReasoning && (reasoning_effort !== undefined || reasoning_max_tokens !== undefined)) {
requestBody.enable_thinking = true;
if (reasoning_max_tokens !== undefined) {
requestBody.thinking_budget = Math.min(reasoning_max_tokens, 32768);
} else if (reasoning_effort !== undefined) {
const getThinkingBudget = (effort: string) => {
switch (effort) {
case "minimal":
return 512;
case "low":
return 2048;
case "high":
return 24576;
case "xhigh":
return 32768;
case "medium":
default:
return 8192;
}
};
requestBody.thinking_budget = getThinkingBudget(reasoning_effort);
}
}🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@packages/actions/src/prepare-request-body.ts` around lines 1881 - 1937, The
Alibaba branch currently gates reasoning logic on a specific model name
("deepseek-v3.2"), which prevents reasoning flags from being set for other
capable models; remove the usedModel check and change the condition to: if
(supportsReasoning && (reasoning_effort !== undefined || reasoning_max_tokens
!== undefined)) then set requestBody.enable_thinking = true and set
requestBody.thinking_budget to Math.min(reasoning_max_tokens, 32768) when
reasoning_max_tokens is provided, otherwise map reasoning_effort to the same
budgets via the existing getThinkingBudget logic; update the code paths that
reference supportsReasoning, reasoning_effort, reasoning_max_tokens,
requestBody.enable_thinking, and requestBody.thinking_budget accordingly.
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.
Test coverage only exercises the
reasoning_effort→thinking_budgetmapping for the default ("medium") case. Since the implementation also supportsreasoning_max_tokens(including clamping to 32768) and multiple effort levels, add unit tests covering thereasoning_max_tokenspath and at least one non-default effort (and/or clamping) to prevent regressions.