MCPcopy Create free account
hub / github.com/Open-Dev-Society/OpenStock / callAIProviderWithFallback

Function callAIProviderWithFallback

lib/ai-provider.ts:168–184  ·  view source on GitHub ↗
(
  prompt: string
)

Source from the content-addressed store, hash-verified

166 * Tries the primary provider first; on failure switches to the fallback.
167 */
168export async function callAIProviderWithFallback(
169 prompt: string
170): Promise<string> {
171 const primaryName =
172 (process.env.AI_PROVIDER as AIProviderName) || "gemini";
173 const fallbackName = getFallbackProviderName(primaryName);
174
175 try {
176 return await callAIProvider(prompt, primaryName);
177 } catch (primaryError) {
178 console.error(
179 `⚠️ ${primaryName} failed, switching to ${fallbackName} fallback`,
180 primaryError
181 );
182 return await callAIProvider(prompt, fallbackName);
183 }
184}

Callers 2

functions.tsFile · 0.90

Calls 2

getFallbackProviderNameFunction · 0.85
callAIProviderFunction · 0.85

Tested by

no test coverage detected