( provider: string, apiKey?: string, baseUrl?: string, forceRefresh: boolean = false )
| 221 | } |
| 222 | |
| 223 | export 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; |
no test coverage detected
searching dependent graphs…