From d4d39aaeb05e90d43d495beb8fb7f623f79bf42e Mon Sep 17 00:00:00 2001 From: Fred Bricon Date: Fri, 12 Sep 2025 12:05:30 +0200 Subject: [PATCH] fix: improve modelSupportsImages logic --- core/llm/autodetect.ts | 45 +++++++++++++++++++++--------------------- core/llm/index.test.ts | 18 +++++++++++++++++ 2 files changed, 41 insertions(+), 22 deletions(-) diff --git a/core/llm/autodetect.ts b/core/llm/autodetect.ts index 900ff173c..7323f15ec 100644 --- a/core/llm/autodetect.ts +++ b/core/llm/autodetect.ts @@ -85,26 +85,23 @@ const PROVIDER_SUPPORTS_IMAGES: string[] = [ "watsonx", ]; -const MODEL_SUPPORTS_IMAGES: string[] = [ - "llava", - "gpt-4-turbo", - "gpt-4o", - "gpt-4o-mini", - "gpt-4-vision", - "claude-3", - "c4ai-aya-vision-8b", - "c4ai-aya-vision-32b", - "gemini-ultra", - "gemini-1.5-pro", - "gemini-1.5-flash", - "sonnet", - "opus", - "haiku", - "pixtral", - "llama3.2", - "llama-3.2", - "llama4", - "granite-vision", +const MODEL_SUPPORTS_IMAGES: RegExp[] = [ + /llava/, + /gpt-4-turbo/, + /gpt-4o/, + /gpt-4o-mini/, + /claude-3/, + /gemini-ultra/, + /gemini-1\.5-pro/, + /gemini-1\.5-flash/, + /sonnet/, + /opus/, + /haiku/, + /pixtral/, + /llama-?3\.2/, + /llama-?4/, // might use something like /llama-?(?:[4-9](?:\.\d+)?|\d{2,}(?:\.\d+)?)/ for forward compat, if needed + /\bgemma-?3(?!n)/, // gemma3 supports vision, but gemma3n doesn't! + /\b(pali|med)gemma/, ]; function modelSupportsImages( @@ -120,10 +117,14 @@ function modelSupportsImages( return false; } - const lower = model.toLowerCase(); + const lowerModel = model.toLowerCase(); + const lowerTitle = title?.toLowerCase() ?? ""; + if ( + lowerModel.includes("vision") || + lowerTitle.includes("vision") || MODEL_SUPPORTS_IMAGES.some( - (modelName) => lower.includes(modelName) || title?.includes(modelName), + (modelrx) => modelrx.test(lowerModel) || modelrx.test(lowerTitle), ) ) { return true; diff --git a/core/llm/index.test.ts b/core/llm/index.test.ts index 1e7031f50..a4f9953b0 100644 --- a/core/llm/index.test.ts +++ b/core/llm/index.test.ts @@ -95,10 +95,28 @@ describe("BaseLLM", () => { test("should return true when modelSupportsImages returns true", () => { baseLLM.model = "gpt-4-vision"; expect(baseLLM.supportsImages()).toBe(true); + + baseLLM.model = "fancy-vision-model"; + expect(baseLLM.supportsImages()).toBe(true); + + baseLLM.model = "gemma3:4b"; + expect(baseLLM.supportsImages()).toBe(true); + + baseLLM.model = "google/gemma-3-270m"; + expect(baseLLM.supportsImages()).toBe(true); + + baseLLM.model = "foo/paligemma-custom-100"; + expect(baseLLM.supportsImages()).toBe(true); + + baseLLM.model = "foo/medgemma_4b_it_16Q"; + expect(baseLLM.supportsImages()).toBe(true); }); test("should return false when modelSupportsImages returns false", () => { expect(baseLLM.supportsImages()).toBe(false); + + baseLLM.model = "gemma3n"; + expect(baseLLM.supportsImages()).toBe(false); }); });