From 21c8b98f9c45908b63c11a0ae7b93f7ce34a181a Mon Sep 17 00:00:00 2001 From: Frost Ming Date: Wed, 5 Mar 2025 16:12:46 +0800 Subject: [PATCH] feat: fallback to openai compatible provider if url host doesn't match --- packages/server/src/utils/ai/select-ai-provider.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/server/src/utils/ai/select-ai-provider.ts b/packages/server/src/utils/ai/select-ai-provider.ts index efbc5730..f56c5e8c 100644 --- a/packages/server/src/utils/ai/select-ai-provider.ts +++ b/packages/server/src/utils/ai/select-ai-provider.ts @@ -17,7 +17,7 @@ function getProviderName(apiUrl: string) { if (apiUrl.includes("localhost:11434") || apiUrl.includes("ollama")) return "ollama"; if (apiUrl.includes("api.deepinfra.com")) return "deepinfra"; - throw new Error(`Unsupported AI provider for URL: ${apiUrl}`); + return "custom"; } export function selectAIProvider(config: { apiUrl: string; apiKey: string }) { @@ -68,6 +68,12 @@ export function selectAIProvider(config: { apiUrl: string; apiKey: string }) { apiKey: config.apiKey, }); default: - throw new Error(`Unsupported AI provider: ${providerName}`); + return createOpenAICompatible({ + name: "custom", + baseURL: config.apiUrl, + headers: { + Authorization: `Bearer ${config.apiKey}`, + }, + )}; } }