fix(small-model): omit thinkingConfig for non-reasoning Google models
This commit is contained in:
@@ -96,7 +96,8 @@ other runtime API.
|
|||||||
`auth.openai.com` (single-flight) and written back to `auth.json`.
|
`auth.openai.com` (single-flight) and written back to `auth.json`.
|
||||||
- **Anthropic** (`type: api`): `/v1/messages` with `x-api-key`.
|
- **Anthropic** (`type: api`): `/v1/messages` with `x-api-key`.
|
||||||
- **Google** (`type: api`): `generateContent` with `x-goog-api-key`; Gemini 3
|
- **Google** (`type: api`): `generateContent` with `x-goog-api-key`; Gemini 3
|
||||||
uses `thinkingLevel` while older Flash models use `thinkingBudget: 0`.
|
uses `thinkingLevel`, Gemini 2.x uses `thinkingBudget: 0`, and all other
|
||||||
|
models omit `thinkingConfig` entirely.
|
||||||
- Everything else: OpenAI-compatible `/chat/completions` against the
|
- Everything else: OpenAI-compatible `/chat/completions` against the
|
||||||
provider's base URL, resolved from (1) `provider.<id>.options.baseURL`
|
provider's base URL, resolved from (1) `provider.<id>.options.baseURL`
|
||||||
in the OpenCode config, (2) the hardcoded `https://api.openai.com/v1`
|
in the OpenCode config, (2) the hardcoded `https://api.openai.com/v1`
|
||||||
|
|||||||
@@ -402,9 +402,10 @@ const getCopilotEndpoint = async ({ baseURL, headers, modelID }) => {
|
|||||||
|
|
||||||
const callGoogle = async ({ apiKey, modelID, prompt, system, maxOutputTokens, responseSchema, timeoutMs, signal }) => {
|
const callGoogle = async ({ apiKey, modelID, prompt, system, maxOutputTokens, responseSchema, timeoutMs, signal }) => {
|
||||||
const url = `https://generativelanguage.googleapis.com/v1beta/models/${encodeURIComponent(modelID)}:generateContent`;
|
const url = `https://generativelanguage.googleapis.com/v1beta/models/${encodeURIComponent(modelID)}:generateContent`;
|
||||||
const thinkingConfig = modelID.toLowerCase().startsWith('gemini-3')
|
const lowerModelID = modelID.toLowerCase();
|
||||||
? { thinkingLevel: modelID.toLowerCase().includes('flash') ? 'minimal' : 'low' }
|
const thinkingConfig = lowerModelID.startsWith('gemini-3')
|
||||||
: { thinkingBudget: 0 };
|
? { thinkingLevel: lowerModelID.includes('flash') ? 'minimal' : 'low' }
|
||||||
|
: lowerModelID.startsWith('gemini-2') ? { thinkingBudget: 0 } : null;
|
||||||
const response = await fetch(url, {
|
const response = await fetch(url, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
@@ -414,13 +415,11 @@ const callGoogle = async ({ apiKey, modelID, prompt, system, maxOutputTokens, re
|
|||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
contents: [{ role: 'user', parts: [{ text: prompt }] }],
|
contents: [{ role: 'user', parts: [{ text: prompt }] }],
|
||||||
...(system ? { systemInstruction: { parts: [{ text: system }] } } : {}),
|
...(system && { systemInstruction: { parts: [{ text: system }] } }),
|
||||||
generationConfig: {
|
generationConfig: {
|
||||||
maxOutputTokens,
|
maxOutputTokens,
|
||||||
thinkingConfig,
|
...(thinkingConfig && { thinkingConfig }),
|
||||||
...(responseSchema
|
...(responseSchema && { responseMimeType: 'application/json', responseSchema: toGoogleSchema(responseSchema) }),
|
||||||
? { responseMimeType: 'application/json', responseSchema: toGoogleSchema(responseSchema) }
|
|
||||||
: {}),
|
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
signal: requestSignal(timeoutMs, signal),
|
signal: requestSignal(timeoutMs, signal),
|
||||||
|
|||||||
@@ -457,6 +457,22 @@ describe('callSmallModel — Google thinking configuration', () => {
|
|||||||
const body = JSON.parse(lastCall(fetchMock).init.body);
|
const body = JSON.parse(lastCall(fetchMock).init.body);
|
||||||
expect(body.generationConfig.thinkingConfig).toEqual({ thinkingBudget: 0 });
|
expect(body.generationConfig.thinkingConfig).toEqual({ thinkingBudget: 0 });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('omits thinkingConfig for other Google/Gemini models', async () => {
|
||||||
|
fetchMock.mockResolvedValue(googleResponse('generated commit'));
|
||||||
|
|
||||||
|
await callSmallModel({
|
||||||
|
auth: { google: { type: 'api', key: 'google-key' } },
|
||||||
|
catalog: {},
|
||||||
|
workingDirectory: '/proj',
|
||||||
|
providerID: 'google',
|
||||||
|
modelID: 'gemini-1.5-flash',
|
||||||
|
prompt: 'generate',
|
||||||
|
});
|
||||||
|
|
||||||
|
const body = JSON.parse(lastCall(fetchMock).init.body);
|
||||||
|
expect(body.generationConfig.thinkingConfig).toBeUndefined();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('callSmallModel — GitHub Copilot endpoint routing', () => {
|
describe('callSmallModel — GitHub Copilot endpoint routing', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user