fix: improve modelSupportsImages logic

This commit is contained in:
Fred Bricon 2025-09-12 12:05:30 +02:00
parent 0040290328
commit d4d39aaeb0
2 changed files with 41 additions and 22 deletions

View file

@ -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;

View file

@ -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);
});
});