fix(litellm): detect Gemini models with space-separated names for thought signature injection (#10787)

This commit is contained in:
Daniel 2026-01-16 17:43:51 -05:00 committed by GitHub
parent c40c882561
commit 95be704ebf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 22 additions and 1 deletions

View file

@ -414,6 +414,18 @@ describe("LiteLLMHandler", () => {
expect(isGeminiModel("gemini-2.5-flash")).toBe(true)
})
it("should detect Gemini models with spaces (LiteLLM model groups)", () => {
const handler = new LiteLLMHandler(mockOptions)
const isGeminiModel = (handler as any).isGeminiModel.bind(handler)
// LiteLLM model groups often use space-separated names with title case
expect(isGeminiModel("Gemini 3 Pro")).toBe(true)
expect(isGeminiModel("Gemini 3 Flash")).toBe(true)
expect(isGeminiModel("gemini 3 pro")).toBe(true)
expect(isGeminiModel("Gemini 2.5 Pro")).toBe(true)
expect(isGeminiModel("gemini 2.5 flash")).toBe(true)
})
it("should detect provider-prefixed Gemini models", () => {
const handler = new LiteLLMHandler(mockOptions)
const isGeminiModel = (handler as any).isGeminiModel.bind(handler)
@ -421,6 +433,9 @@ describe("LiteLLMHandler", () => {
expect(isGeminiModel("google/gemini-3-pro")).toBe(true)
expect(isGeminiModel("vertex_ai/gemini-3-pro")).toBe(true)
expect(isGeminiModel("vertex/gemini-2.5-pro")).toBe(true)
// Space-separated variants with provider prefix
expect(isGeminiModel("google/gemini 3 pro")).toBe(true)
expect(isGeminiModel("vertex_ai/gemini 2.5 pro")).toBe(true)
})
it("should not detect non-Gemini models", () => {

View file

@ -46,15 +46,21 @@ export class LiteLLMHandler extends RouterProvider implements SingleCompletionHa
private isGeminiModel(modelId: string): boolean {
// Match various Gemini model patterns:
// - gemini-3-pro, gemini-3-flash, gemini-3-*
// - gemini 3 pro, Gemini 3 Pro (space-separated, case-insensitive)
// - gemini/gemini-3-*, google/gemini-3-*
// - vertex_ai/gemini-3-*, vertex/gemini-3-*
// Also match Gemini 2.5+ models which use similar validation
const lowerModelId = modelId.toLowerCase()
return (
// Match hyphenated versions: gemini-3, gemini-2.5
lowerModelId.includes("gemini-3") ||
lowerModelId.includes("gemini-2.5") ||
// Match space-separated versions: "gemini 3", "gemini 2.5"
// This handles model names like "Gemini 3 Pro" from LiteLLM model groups
lowerModelId.includes("gemini 3") ||
lowerModelId.includes("gemini 2.5") ||
// Also match provider-prefixed versions
/\b(gemini|google|vertex_ai|vertex)\/gemini-(3|2\.5)/i.test(modelId)
/\b(gemini|google|vertex_ai|vertex)\/gemini[-\s](3|2\.5)/i.test(modelId)
)
}