// ============================================================ // MODEL VISION SUPPORT // ============================================================ // Can this model be shown a picture? // // Three answers, not two: true, false, and "the gateway does not say". Only an // explicit false is actionable. Most of a roster carries no supports_vision at // all, and treating silence as blindness would route perfectly good models // through a delegation they do not need. // // Asked of the gateway, never inferred from the model id: "gemini-3.8-flash" // says nothing about whether this deployment's copy of it accepts images, and a // name-matching rule is the kind of thing that quietly rots. // // Cached briefly. This is asked on requests that carry an attachment, and a // /model/info round trip per request would add latency to exactly the requests // that are already the slowest. var CACHE_MS = 5 * 60 * 1000; var cache = { at: 0, byId: null }; async function roster() { if (cache.byId && Date.now() - cache.at < CACHE_MS) return cache.byId; var axios = require('axios'); var { getLiteLLMAdminHeaders, liteLLMBaseUrl } = require('./litellm'); var response = await axios.get(liteLLMBaseUrl() + '/model/info', { headers: getLiteLLMAdminHeaders(), timeout: 10000 }); var byId = Object.create(null); ((response.data && response.data.data) || []).forEach(function (model) { var id = model && model.model_name; if (!id) return; var info = model.model_info || {}; byId[id] = typeof info.supports_vision === 'boolean' ? info.supports_vision : null; }); cache = { at: Date.now(), byId: byId }; return byId; } /** true, false, or null when the gateway does not say (or cannot be reached). */ async function supportsVision(modelId) { if (!modelId || !process.env.LITELLM_API_BASE) return null; try { var byId = await roster(); return Object.prototype.hasOwnProperty.call(byId, modelId) ? byId[modelId] : null; } catch (e) { // The gateway being unreachable is not evidence about the model. return null; } } function forget() { cache = { at: 0, byId: null }; } module.exports = { supportsVision, forget, CACHE_MS };