Skip to content

Project NOMAD is an offline-first knowledge and education server. Wikipedia, thousands of books, courses, maps, and optional local AI, all running on hardware you own with no internet required.

TypeScript

fix(ai): probe a model the list reports without vision before disabling images

Chris Sherwood26f40baf58a1
diff --git a/admin/app/services/ollama_service.ts b/admin/app/services/ollama_service.ts
index f17b1bd2..54f8e9da 100644
--- a/admin/app/services/ollama_service.ts
+++ b/admin/app/services/ollama_service.ts
@@ -22,7 +22,6 @@ import { NOMAD_API_DEFAULT_BASE_URL } from '../../constants/misc.js'
import KVStore from '#models/kv_store'
import type { ModelCapabilities } from '../utils/model_capabilities.js'
import {
- capabilitiesFromOllamaShow,
installedModelsFromOpenAIResponse,
resolveModelCapabilities,
} from '../utils/model_capabilities.js'
@@ -928,23 +927,14 @@ export class OllamaService {
await this._ensureDependencies()
if (!this.baseUrl) return { thinking: false, vision: 'unknown' }
- // Composite OpenAI-compatible routers can advertise different capabilities for each model.
- // Prefer that per-model metadata before probing backend-specific endpoints.
- const advertised = capabilitiesFromOllamaShow(advertisedMetadata)
- if (advertised) {
- this.modelCapabilityCache.set(modelName, {
- value: advertised,
- expiresAt: Number.POSITIVE_INFINITY,
- })
- return advertised
- }
-
const cached = this.modelCapabilityCache.get(modelName)
if (cached && cached.expiresAt > Date.now()) return cached.value
- // Probe per model instead of relying on the backend-wide classification from getModels().
+ // Composite OpenAI-compatible routers can advertise different capabilities for each
+ // model, and that metadata is passed through here. A list that omits vision is not
+ // trusted on its own (see resolveModelCapabilities), so the model is still probed.
// Hybrid routers may expose /v1/models plus /api/show without exposing /api/tags.
- const detected = await resolveModelCapabilities(null, {
+ const detected = await resolveModelCapabilities(advertisedMetadata, {
ollamaShow: async () => {
const response = await axios.post(
`${this.baseUrl}/api/show`,
diff --git a/admin/app/utils/model_capabilities.ts b/admin/app/utils/model_capabilities.ts
index c709b997..ebe2ab1b 100644
--- a/admin/app/utils/model_capabilities.ts
+++ b/admin/app/utils/model_capabilities.ts
@@ -49,7 +49,11 @@ export async function resolveModelCapabilities(
probes: ModelCapabilityProbes
): Promise<ModelCapabilities | null> {
const advertised = capabilitiesFromOllamaShow(advertisedMetadata)
- if (advertised) return advertised
+ // A model list that reports vision is trusted outright. One that does not is
+ // not conclusive: Ollama's /api/tags lists gemma3 as ['completion'] while its
+ // /api/show for the same model reports ['completion', 'vision'], which left
+ // image upload disabled for one of the most common small vision models.
+ if (advertised?.vision === 'supported') return advertised
try {
const ollama = capabilitiesFromOllamaShow(await probes.ollamaShow())
@@ -58,10 +62,10 @@ export async function resolveModelCapabilities(
try {
const vision = visionCapabilityFromLlamaProps(await probes.llamaProps())
- if (vision) return { thinking: false, vision }
+ if (vision) return { thinking: advertised?.thinking ?? false, vision }
} catch {}
- return null
+ return advertised
}
export function installedModelsFromOpenAIResponse(value: unknown): InstalledModelMetadata[] {
diff --git a/admin/tests/unit/chat_images.spec.ts b/admin/tests/unit/chat_images.spec.ts
index 7f4e06f2..b2755f42 100644
--- a/admin/tests/unit/chat_images.spec.ts
+++ b/admin/tests/unit/chat_images.spec.ts
@@ -164,8 +164,26 @@ test('resolves per-model capabilities advertised by a hybrid router', async () =
assert.deepEqual(visionModel, { thinking: true, vision: 'supported' })
assert.deepEqual(textModel, { thinking: true, vision: 'unsupported' })
- assert.equal(showProbeCalls, 0)
- assert.equal(propsProbeCalls, 0)
+ // A listed vision model is trusted without probing. A listed text-only model is
+ // probed once, and the router's answer stands when the probes have nothing better.
+ assert.equal(showProbeCalls, 1)
+ assert.equal(propsProbeCalls, 1)
+})
+
+test('probes a model the list reports without vision, as Ollama does for gemma3', async () => {
+ // Measured on Ollama 0.33.3: /api/tags lists gemma3:4b as ['completion'] while
+ // /api/show for the same model reports ['completion', 'vision'].
+ const gemma = await resolveModelCapabilities(
+ { capabilities: ['completion'] },
+ {
+ ollamaShow: async () => ({ capabilities: ['completion', 'vision'] }),
+ llamaProps: async () => {
+ throw new Error('not used')
+ },
+ }
+ )
+
+ assert.deepEqual(gemma, { thinking: false, vision: 'supported' })
})
test('preserves per-model capabilities from an OpenAI-compatible model list', () => {
@@ -243,9 +261,7 @@ test('classifies the four supported backend capability cases', async () => {
{
name: 'known text-only',
advertised: { capabilities: ['completion', 'thinking'] },
- ollamaShow: async () => {
- throw new Error('not used')
- },
+ ollamaShow: async () => ({ capabilities: ['completion', 'thinking'] }),
llamaProps: async () => {
throw new Error('not used')
},