MCPcopy Index your code
hub / github.com/di-sukharev/opencommit / fetchModelsForProvider

Function fetchModelsForProvider

src/utils/modelCache.ts:223–314  ·  view source on GitHub ↗
(
  provider: string,
  apiKey?: string,
  baseUrl?: string,
  forceRefresh: boolean = false
)

Source from the content-addressed store, hash-verified

221}
222
223export async function fetchModelsForProvider(
224 provider: string,
225 apiKey?: string,
226 baseUrl?: string,
227 forceRefresh: boolean = false
228): Promise<string[]> {
229 const cache = readCache();
230
231 // Return cached models if valid (unless force refresh)
232 if (!forceRefresh && isCacheValid(cache) && cache!.models[provider]) {
233 return cache!.models[provider];
234 }
235
236 let models: string[] = [];
237
238 switch (provider.toLowerCase()) {
239 case OCO_AI_PROVIDER_ENUM.OPENAI:
240 if (apiKey) {
241 models = await fetchOpenAIModels(apiKey);
242 } else {
243 models = MODEL_LIST.openai;
244 }
245 break;
246
247 case OCO_AI_PROVIDER_ENUM.OLLAMA:
248 models = await fetchOllamaModels(baseUrl);
249 break;
250
251 case OCO_AI_PROVIDER_ENUM.LLAMACPP:
252 models = await fetchLlamaCppModels(baseUrl);
253 break;
254
255 case OCO_AI_PROVIDER_ENUM.ANTHROPIC:
256 if (apiKey) {
257 models = await fetchAnthropicModels(apiKey);
258 } else {
259 models = MODEL_LIST.anthropic;
260 }
261 break;
262
263 case OCO_AI_PROVIDER_ENUM.GEMINI:
264 // Google's API doesn't easily list generative models, use hardcoded list
265 models = MODEL_LIST.gemini;
266 break;
267
268 case OCO_AI_PROVIDER_ENUM.GROQ:
269 if (apiKey) {
270 models = await fetchGroqModels(apiKey);
271 } else {
272 models = MODEL_LIST.groq;
273 }
274 break;
275
276 case OCO_AI_PROVIDER_ENUM.MISTRAL:
277 if (apiKey) {
278 models = await fetchMistralModels(apiKey);
279 } else {
280 models = MODEL_LIST.mistral;

Callers 2

refreshModelsFunction · 0.90
selectModelFunction · 0.90

Calls 12

toLowerCaseMethod · 0.80
readCacheFunction · 0.70
isCacheValidFunction · 0.70
fetchOpenAIModelsFunction · 0.70
fetchOllamaModelsFunction · 0.70
fetchLlamaCppModelsFunction · 0.70
fetchAnthropicModelsFunction · 0.70
fetchGroqModelsFunction · 0.70
fetchMistralModelsFunction · 0.70
fetchDeepSeekModelsFunction · 0.70
fetchOpenRouterModelsFunction · 0.70
writeCacheFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…