( apiKey?: string, apiBase?: string, )
| 174 | } |
| 175 | |
| 176 | async function fetchGeminiModels( |
| 177 | apiKey?: string, |
| 178 | apiBase?: string, |
| 179 | ): Promise<FetchedModel[]> { |
| 180 | const base = apiBase || "https://generativelanguage.googleapis.com/v1beta/"; |
| 181 | const url = new URL("models", base); |
| 182 | url.searchParams.set("key", apiKey ?? ""); |
| 183 | const response = await fetch(url); |
| 184 | if (!response.ok) { |
| 185 | throw new Error(`Failed to fetch Gemini models: ${response.status}`); |
| 186 | } |
| 187 | const data = await response.json(); |
| 188 | return (data.models ?? []) |
| 189 | .filter((m: any) => { |
| 190 | const id: string = m.name?.replace("models/", "") ?? ""; |
| 191 | const methods: string[] = m.supportedGenerationMethods ?? []; |
| 192 | return ( |
| 193 | !id.startsWith("gemini-2.0") && |
| 194 | !id.startsWith("gemma-") && // Gemma models are supported through Ollama, not the Gemini API |
| 195 | !id.startsWith("nano-banana") && |
| 196 | !id.startsWith("lyria") && |
| 197 | methods.includes("generateContent") && |
| 198 | !methods.includes("embedContent") && |
| 199 | !methods.includes("predict") && |
| 200 | !methods.includes("predictLongRunning") && |
| 201 | !methods.includes("bidiGenerateContent") && |
| 202 | !id.includes("tts") && |
| 203 | !id.includes("image") && |
| 204 | !id.includes("robotics") && |
| 205 | !id.includes("computer-use") |
| 206 | ); |
| 207 | }) |
| 208 | .map((m: any) => ({ |
| 209 | name: m.displayName ?? m.name?.replace("models/", ""), |
| 210 | modelId: m.name?.replace("models/", ""), |
| 211 | icon: "gemini.png", |
| 212 | contextLength: m.inputTokenLimit, |
| 213 | maxTokens: m.outputTokenLimit, |
| 214 | supportsTools: true, |
| 215 | })); |
| 216 | } |
| 217 | |
| 218 | async function fetchProviderModelsViaListModels( |
| 219 | provider: string, |
no test coverage detected