MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / getModel

Function getModel

src/api/providers/router-provider.ts:64–97  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

62 }
63
64 override getModel(): { id: string; info: ModelInfo } {
65 // Use `||` (not `??`) so an empty-string modelId also falls back to the default,
66 // guaranteeing a non-empty id rather than forwarding "" to the API as an invalid
67 // request. Note this guarantees non-empty, not viable: defaultModelId is provider-
68 // supplied and may not be a model that actually exists on the user's server (e.g.
69 // OpenAI-compatible have no inherent default), so a configured-but-empty selection
70 // can still resolve to a model the server rejects.
71 const id = this.modelId || this.defaultModelId
72
73 // First check instance models (populated by fetchModel)
74 if (this.models[id]) {
75 return { id, info: this.models[id] }
76 }
77
78 // Fall back to global cache (synchronous disk/memory cache).
79 // Pass the full options so URL-scoped providers (litellm, ollama, etc.)
80 // resolve the same compound cache key that fetchModel() wrote under.
81 const cachedModels = getModelsFromCache({
82 provider: this.name,
83 baseUrl: this.client.baseURL,
84 apiKey: this.client.apiKey,
85 })
86 if (cachedModels?.[id]) {
87 // Also populate instance models for future calls
88 this.models = cachedModels
89 return { id, info: cachedModels[id] }
90 }
91
92 // Last resort: preserve the configured model ID (falling back to the default
93 // only when none is configured) so an as-yet-unfetched model isn't silently
94 // swapped for the hardcoded default. info still comes from defaults since we
95 // have no fetched or cached metadata for the configured model at this point.
96 return { id, info: this.defaultModelInfo }
97 }
98
99 protected supportsTemperature(modelId: string): boolean {
100 return !modelId.startsWith("openai/o3-mini")

Callers

nothing calls this directly

Calls 1

getModelsFromCacheFunction · 0.90

Tested by

no test coverage detected