Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions packages/core/src/core/openaiContentGenerator/pipeline.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,47 @@ describe('ContentGenerationPipeline', () => {
expect(apiCall.enable_thinking).toBe(false);
});

it('skips enable_thinking:false for thinking-only models (#7332)', async () => {
// qwen3.8-max-preview rejects enable_thinking=false with a 400 error.
// When the model's preset sets extra_body.enable_thinking=true, the
// pipeline must NOT override it with false.
mockContentGeneratorConfig = {
...mockContentGeneratorConfig,
baseUrl: 'https://dashscope.aliyuncs.com/compatible-mode/v1',
model: 'qwen3.8-max-preview',
extra_body: { enable_thinking: true },
} as ContentGeneratorConfig;
mockConfig = {
...mockConfig,
contentGeneratorConfig: mockContentGeneratorConfig,
};
pipeline = new ContentGenerationPipeline(mockConfig);

const request: GenerateContentParameters = {
model: 'qwen3.8-max-preview',
contents: [{ parts: [{ text: 'Summarize' }], role: 'user' }],
config: { thinkingConfig: { includeThoughts: false } },
};

(mockConverter.convertGeminiRequestToOpenAI as Mock).mockReturnValue([
{ role: 'user', content: 'Summarize' },
]);
(mockConverter.convertOpenAIResponseToGemini as Mock).mockReturnValue(
new GenerateContentResponse(),
);
(mockClient.chat.completions.create as Mock).mockResolvedValue({
id: 'r',
choices: [{ message: { content: 'ok' }, finish_reason: 'stop' }],
} as OpenAI.Chat.ChatCompletion);

await pipeline.execute(request, 'forked_query');

const apiCall = (mockClient.chat.completions.create as Mock).mock
.calls[0][0];
// Must NOT set enable_thinking to false for thinking-only models
expect(apiCall.enable_thinking).not.toBe(false);
});

it('emits enable_thinking:false on DashScope hostname when reasoning is configured to false', async () => {
// Config-level opt-out (`reasoning: false`) should also disable
// qwen3 thinking, mirroring the DeepSeek pair above.
Expand Down
10 changes: 9 additions & 1 deletion packages/core/src/core/openaiContentGenerator/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,15 @@ export class ContentGenerationPipeline {
this.contentGeneratorConfig,
)
) {
typed['enable_thinking'] = false;
// Skip disabling thinking for models whose preset explicitly
// requires it (e.g. qwen3.8-max-preview). These models reject
// enable_thinking=false with a 400 error (#7332). The preset
// signals this via extra_body.enable_thinking=true.
const presetThinking =
this.contentGeneratorConfig.extra_body?.['enable_thinking'];
if (presetThinking !== true) {
typed['enable_thinking'] = false;
}
} else {
// Non-DashScope OpenAI-compatible servers (vLLM, SGLang, ...) render
// the model's chat template server-side and read the thinking switch
Expand Down
Loading