-
Notifications
You must be signed in to change notification settings - Fork 2.4k
fix(core): mirror Qwen reasoning history field #4289
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?
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 | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -11,6 +11,8 @@ import { | |||||||||||||||||||||||
| hasExplicitOutputLimit, | ||||||||||||||||||||||||
| } from '../../tokenLimits.js'; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const QWEN_MODEL_MARKER = 'qwen'; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||
| * Default provider for standard OpenAI-compatible APIs | ||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||
|
|
@@ -76,10 +78,11 @@ export class DefaultOpenAICompatibleProvider | |||||||||||||||||||||||
| // This prevents occupying too much context window with output reservation | ||||||||||||||||||||||||
| const requestWithTokenLimits = this.applyOutputTokenLimit(request); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||
| const builtRequest = { | ||||||||||||||||||||||||
| ...requestWithTokenLimits, | ||||||||||||||||||||||||
| ...(extraBody ? extraBody : {}), | ||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||
| return this.mirrorQwenReasoningContent(builtRequest); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| getDefaultGenerationConfig(): GenerateContentConfig { | ||||||||||||||||||||||||
|
|
@@ -167,4 +170,45 @@ export class DefaultOpenAICompatibleProvider | |||||||||||||||||||||||
| max_tokens: effectiveMaxTokens, | ||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
Collaborator
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. [Suggestion] Missing JSDoc on
Suggested change
— DeepSeek/deepseek-v4-pro via Qwen Code /review |
||||||||||||||||||||||||
| private mirrorQwenReasoningContent( | ||||||||||||||||||||||||
| request: OpenAI.Chat.ChatCompletionCreateParams, | ||||||||||||||||||||||||
| ): OpenAI.Chat.ChatCompletionCreateParams { | ||||||||||||||||||||||||
| const model = request.model.toLowerCase(); | ||||||||||||||||||||||||
| if (!model.includes(QWEN_MODEL_MARKER)) { | ||||||||||||||||||||||||
| return request; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| let changed = false; | ||||||||||||||||||||||||
| const messages = request.messages.map((message) => { | ||||||||||||||||||||||||
| if (message.role !== 'assistant') { | ||||||||||||||||||||||||
| return message; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const extended = message as unknown as Record<string, unknown>; | ||||||||||||||||||||||||
|
Collaborator
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. [Suggestion] The double-cast
Suggested change
This catches typos, provides IDE support, and is consistent with how — qwen-latest-series-invite-beta-v28 via Qwen Code /review |
||||||||||||||||||||||||
| const reasoningContent = extended['reasoning_content']; | ||||||||||||||||||||||||
| if ( | ||||||||||||||||||||||||
| typeof reasoningContent !== 'string' || | ||||||||||||||||||||||||
| reasoningContent.length === 0 || | ||||||||||||||||||||||||
| typeof extended['reasoning'] === 'string' | ||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||
| return message; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| changed = true; | ||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||
| ...extended, | ||||||||||||||||||||||||
| reasoning: reasoningContent, | ||||||||||||||||||||||||
| } as unknown as OpenAI.Chat.ChatCompletionMessageParam; | ||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| if (!changed) { | ||||||||||||||||||||||||
| return request; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||
| ...request, | ||||||||||||||||||||||||
| messages, | ||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
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.
[Suggestion] The single test covers only the happy path (one assistant message with
reasoning_content). Four critical branches are untested:model: 'gpt-4'withreasoning_contentshould NOT injectreasoningreasoning_content—reasoning_content: ''should skip mirroring (explicitlength === 0guard)reasoningfield — assistant message with bothreasoningandreasoning_contentshould NOT overwritereasoningreasoning_contentshould be ignored (role !== 'assistant'guard)These guards are the most frequently hit code paths and regressions here would silently break API behavior.
— DeepSeek/deepseek-v4-pro via Qwen Code /review