fix: disable thinking for Qwen agent requests

This commit is contained in:
2026-10-20 10:10:48 +09:00
parent 85bd539052
commit d0f2779471
2 changed files with 14 additions and 0 deletions
+13
View File
@@ -18,6 +18,17 @@ describe('AiProviderService', () => {
const body = JSON.parse(String(fetchMock.mock.calls[0][1].body)); const body = JSON.parse(String(fetchMock.mock.calls[0][1].body));
expect(body.messages[1]).toEqual({ role: 'user', content: [{ type: 'text', text: 'Inspect this screenshot' }, { type: 'image_url', image_url: { url: 'data:image/png;base64,aW1hZ2U=' } }] }); expect(body.messages[1]).toEqual({ role: 'user', content: [{ type: 'text', text: 'Inspect this screenshot' }, { type: 'image_url', image_url: { url: 'data:image/png;base64,aW1hZ2U=' } }] });
expect(body.response_format).toEqual({ type: 'json_object' }); expect(body.response_format).toEqual({ type: 'json_object' });
expect(body.enable_thinking).toBe(false);
});
it.each(['qwen3.8-max', 'qwen3.8-flash', 'qwen3.7-plus'])('explicitly disables thinking for Qwen model %s', async model => {
const fetchMock = jest.fn().mockResolvedValue({ ok: true, json: async () => ({ choices: [{ message: { content: '{"ok":true}' } }] }) });
global.fetch = fetchMock as typeof fetch;
const service = new AiProviderService({ get: jest.fn() } as unknown as ConfigService);
await service.complete({ provider: 'QWEN', model, apiKey: 'fixture', system: 'Return JSON', json: true, messages: [{ role: 'user', content: 'Find the steering configuration' }] });
const body = JSON.parse(String(fetchMock.mock.calls[0][1].body));
expect(body).toMatchObject({ model, enable_thinking: false, response_format: { type: 'json_object' } });
expect(body.messages).toEqual([{ role: 'system', content: 'Return JSON' }, { role: 'user', content: 'Find the steering configuration' }]);
}); });
it('never silently drops an image on unsupported provider adapters', async () => { it('never silently drops an image on unsupported provider adapters', async () => {
@@ -77,6 +88,7 @@ describe('AiProviderService', () => {
const result = await service.complete({ provider, model, apiKey: 'fixture', system: 'Return JSON', messages: [{ role: 'user', content: 'test' }], json: true }); const result = await service.complete({ provider, model, apiKey: 'fixture', system: 'Return JSON', messages: [{ role: 'user', content: 'test' }], json: true });
const body = JSON.parse(String(fetchMock.mock.calls[0][1].body)); const body = JSON.parse(String(fetchMock.mock.calls[0][1].body));
expect(provider === 'GEMINI' ? body.generationConfig : body).not.toHaveProperty('temperature'); expect(provider === 'GEMINI' ? body.generationConfig : body).not.toHaveProperty('temperature');
expect(body).not.toHaveProperty('enable_thinking');
if (provider !== 'GEMINI') expect(body.model).toBe(model); if (provider !== 'GEMINI') expect(body.model).toBe(model);
if (provider === 'OPENAI') expect(body.response_format).toEqual({ type: 'json_object' }); if (provider === 'OPENAI') expect(body.response_format).toEqual({ type: 'json_object' });
if (provider === 'GEMINI') expect(body.generationConfig.responseMimeType).toBe('application/json'); if (provider === 'GEMINI') expect(body.generationConfig.responseMimeType).toBe('application/json');
@@ -96,6 +108,7 @@ describe('AiProviderService', () => {
await service.complete({ provider, model, apiKey: 'fixture', system: 'system', messages: [{ role: 'user', content: 'test' }] }); await service.complete({ provider, model, apiKey: 'fixture', system: 'system', messages: [{ role: 'user', content: 'test' }] });
const body = JSON.parse(String(fetchMock.mock.calls[0][1].body)); const body = JSON.parse(String(fetchMock.mock.calls[0][1].body));
expect(provider === 'GEMINI' ? body.generationConfig.temperature : body.temperature).toBe(0.2); expect(provider === 'GEMINI' ? body.generationConfig.temperature : body.temperature).toBe(0.2);
if (provider !== 'QWEN') expect(body).not.toHaveProperty('enable_thinking');
if (provider !== 'GEMINI') expect(body.model).toBe(model); if (provider !== 'GEMINI') expect(body.model).toBe(model);
}); });
}); });
+1
View File
@@ -146,6 +146,7 @@ export class AiProviderService {
body: JSON.stringify({ body: JSON.stringify({
model: input.model, model: input.model,
temperature: 0.2, temperature: 0.2,
enable_thinking: false,
response_format: input.json ? { type: 'json_object' } : undefined, response_format: input.json ? { type: 'json_object' } : undefined,
messages: [{ role: 'system', content: input.system }, ...input.messages.map(message => ({ messages: [{ role: 'system', content: input.system }, ...input.messages.map(message => ({
role: message.role, role: message.role,