💠 feat: Extend thinkingLevel Support to Gemma 4 Models (#13088)

This commit is contained in:
King-of-Infinite-Space 2026-05-30 10:16:27 -04:00 committed by GitHub
parent b01d34abe2
commit b61d5377ef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 43 additions and 6 deletions

View file

@ -949,6 +949,43 @@ describe('getGoogleConfig', () => {
expect(config).toMatchObject({ includeThoughts: true });
});
it('should use thinkingLevel for Gemma 4 models', () => {
const credentials = {
[AuthKeys.GOOGLE_API_KEY]: 'test-api-key',
};
const result = getGoogleConfig(credentials, {
modelOptions: {
model: 'gemma-4-31b-it',
thinking: true,
thinkingLevel: ThinkingLevel.high,
},
});
expect((result.llmConfig as Record<string, unknown>).thinkingConfig).toMatchObject({
includeThoughts: true,
thinkingLevel: 'HIGH',
});
});
it('should ignore thinkingBudget for Gemma 4 models', () => {
const credentials = {
[AuthKeys.GOOGLE_API_KEY]: 'test-api-key',
};
const result = getGoogleConfig(credentials, {
modelOptions: {
model: 'gemma-4-31b-it',
thinking: true,
thinkingBudget: 5000,
},
});
const config = (result.llmConfig as Record<string, unknown>).thinkingConfig;
expect(config).not.toHaveProperty('thinkingBudget');
expect(config).toMatchObject({ includeThoughts: true });
});
it('should NOT classify gemini-2.9-flash as Gemini 3+', () => {
const credentials = {
[AuthKeys.GOOGLE_API_KEY]: 'test-api-key',

View file

@ -398,18 +398,18 @@ export function getGoogleConfig(
const modelName = (modelOptions?.model ?? '') as string;
/**
* Gemini 3+ uses a qualitative `thinkingLevel` ('minimal'|'low'|'medium'|'high')
* instead of the numeric `thinkingBudget` used by Gemini 2.5 and earlier.
* Gemini 3+ and Gemma 4+ use a qualitative `thinkingLevel` ('minimal'|'low'|'medium'|'high')
* instead of the numeric `thinkingBudget` used by earlier models.
* When `thinking` is enabled (default: true), we always send `thinkingConfig`
* with `includeThoughts: true`. The `thinkingBudget` param is ignored for Gemini 3+.
* with `includeThoughts: true`. The `thinkingBudget` param is ignored for these models.
*
* For Vertex AI, top-level `includeThoughts` is still required because
* `@librechat/agents/langchain/google-common`'s `formatGenerationConfig` reads it separately
* from `thinkingConfig` they serve different purposes in the request pipeline.
*/
const isGemini3Plus = /gemini-([3-9]|\d{2,})/i.test(modelName);
const supportsThinkingLevel = /gemini-([3-9]|\d{2,})|gemma-([4-9]|\d{2,})/i.test(modelName);
if (isGemini3Plus && thinking) {
if (supportsThinkingLevel && thinking) {
const thinkingConfig: GoogleThinkingConfig = {
includeThoughts: true,
};
@ -423,7 +423,7 @@ export function getGoogleConfig(
(llmConfig as { thinkingConfig?: GoogleThinkingConfig }).thinkingConfig = thinkingConfig;
(llmConfig as VertexAIClientOptions).includeThoughts = true;
}
} else if (!isGemini3Plus) {
} else if (!supportsThinkingLevel) {
const shouldEnableThinking =
thinking && thinkingBudget != null && (thinkingBudget > 0 || thinkingBudget === -1);