(model: string)
| 261 | } |
| 262 | |
| 263 | export function getProviderFromModel(model: string): ProviderId { |
| 264 | const normalizedModel = model.toLowerCase() |
| 265 | |
| 266 | let providerId: ProviderId | null = null |
| 267 | |
| 268 | if (normalizedModel in getAllModelProviders()) { |
| 269 | providerId = getAllModelProviders()[normalizedModel] |
| 270 | } else { |
| 271 | for (const [id, config] of Object.entries(providers)) { |
| 272 | if (config.modelPatterns) { |
| 273 | for (const pattern of config.modelPatterns) { |
| 274 | if (pattern.test(normalizedModel)) { |
| 275 | providerId = id as ProviderId |
| 276 | break |
| 277 | } |
| 278 | } |
| 279 | } |
| 280 | if (providerId) break |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | if (!providerId) { |
| 285 | logger.warn(`No provider found for model: ${model}, defaulting to ollama`) |
| 286 | providerId = 'ollama' |
| 287 | } |
| 288 | |
| 289 | if (isProviderBlacklisted(providerId)) { |
| 290 | throw new Error(`Provider "${providerId}" is not available`) |
| 291 | } |
| 292 | |
| 293 | if (isModelBlacklisted(normalizedModel)) { |
| 294 | throw new Error(`Model "${model}" is not available`) |
| 295 | } |
| 296 | |
| 297 | return providerId |
| 298 | } |
| 299 | |
| 300 | export function getProvider(id: string): ProviderMetadata | undefined { |
| 301 | const providerId = id.split('/')[0] as ProviderId |
no test coverage detected