Merge pull request #7721 from fbricon/refactor-vision-support-detection
fix: improve modelSupportsImages logic
This commit is contained in:
commit
24df311fbb
3 changed files with 47 additions and 23 deletions
|
|
@ -85,26 +85,24 @@ 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/,
|
||||
/qwen(.*)vl/,
|
||||
];
|
||||
|
||||
function modelSupportsImages(
|
||||
|
|
@ -120,10 +118,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;
|
||||
|
|
|
|||
|
|
@ -95,10 +95,31 @@ 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);
|
||||
|
||||
baseLLM.model = "qwen2.5vl";
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -231,12 +231,13 @@ This matrix shows which models support tool use and image input capabilities. Co
|
|||
| Model | Tool Use | Image Input | Context Window |
|
||||
| :------------- | -------- | ----------- | -------------- |
|
||||
| Qwen 3 Coder | Yes | No | 32k |
|
||||
| Qwen 2.5 VL | No | Yes | 128k |
|
||||
| Devstral Small | Yes | No | 32k |
|
||||
| Llama 3.1 | Yes | No | 128k |
|
||||
| Llama 3 | Yes | No | 8k |
|
||||
| Mistral | Yes | No | 32k |
|
||||
| Codestral | Yes | No | 32k |
|
||||
| Gemma 3 4B | Yes | No | 8k |
|
||||
| Gemma 3 4B | Yes | Yes | 128k |
|
||||
|
||||
### Notes
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue