* Fetch available models from an AI provider endpoint. * Supports OpenAI-compatible (/v1/models), Anthropic, and Google Gemini.
(endpoint: AIEndpoint)
| 88 | * Supports OpenAI-compatible (/v1/models), Anthropic, and Google Gemini. |
| 89 | */ |
| 90 | async function fetchModelsFromEndpoint(endpoint: AIEndpoint): Promise<string[]> { |
| 91 | if (providerRequiresApiKey(endpoint.provider) && !endpoint.apiKey) return []; |
| 92 | if (endpoint.useExactRequestUrl && providerSupportsExactRequestUrl(endpoint.provider)) { |
| 93 | throw new Error( |
| 94 | "Exact request URL mode cannot infer the model list automatically. Add models manually.", |
| 95 | ); |
| 96 | } |
| 97 | |
| 98 | switch (endpoint.provider) { |
| 99 | case "anthropic": |
| 100 | return fetchAnthropicModels(endpoint); |
| 101 | case "google": |
| 102 | return fetchGoogleModels(endpoint); |
| 103 | case "deepseek": |
| 104 | return fetchDeepSeekModels(endpoint); |
| 105 | case "ollama": |
| 106 | return fetchOllamaModels(endpoint); |
| 107 | case "lmstudio": |
| 108 | return fetchLMStudioModels(endpoint); |
| 109 | case "openai": |
| 110 | default: |
| 111 | return fetchOpenAIModels(endpoint); |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | /** OpenAI-compatible /v1/models */ |
| 116 | async function fetchOpenAIModels(endpoint: AIEndpoint): Promise<string[]> { |
no test coverage detected