2024-10-13 18:53:43 +00:00
|
|
|
// @ts-nocheck
|
|
|
|
// Preventing TS checks with files presented in the video for a better presentation.
|
2024-07-10 16:44:39 +00:00
|
|
|
import { env } from 'node:process';
|
|
|
|
|
2024-10-13 18:53:43 +00:00
|
|
|
export function getAPIKey(cloudflareEnv: Env, provider: string) {
|
2024-07-10 16:44:39 +00:00
|
|
|
/**
|
|
|
|
* The `cloudflareEnv` is only used when deployed or when previewing locally.
|
|
|
|
* In development the environment variables are available through `env`.
|
|
|
|
*/
|
2024-10-15 21:47:35 +00:00
|
|
|
|
2024-10-13 18:53:43 +00:00
|
|
|
switch (provider) {
|
|
|
|
case 'Anthropic':
|
|
|
|
return env.ANTHROPIC_API_KEY || cloudflareEnv.ANTHROPIC_API_KEY;
|
|
|
|
case 'OpenAI':
|
|
|
|
return env.OPENAI_API_KEY || cloudflareEnv.OPENAI_API_KEY;
|
2024-10-15 21:47:35 +00:00
|
|
|
case 'Google':
|
|
|
|
return env.GOOGLE_GENERATIVE_AI_API_KEY || cloudflareEnv.GOOGLE_GENERATIVE_AI_API_KEY;
|
2024-10-13 18:53:43 +00:00
|
|
|
case 'Groq':
|
|
|
|
return env.GROQ_API_KEY || cloudflareEnv.GROQ_API_KEY;
|
2024-10-15 00:40:21 +00:00
|
|
|
case 'OpenRouter':
|
|
|
|
return env.OPEN_ROUTER_API_KEY || cloudflareEnv.OPEN_ROUTER_API_KEY;
|
2024-10-22 22:19:27 +00:00
|
|
|
case 'Deepseek':
|
|
|
|
return env.DEEPSEEK_API_KEY || cloudflareEnv.DEEPSEEK_API_KEY
|
2024-10-13 18:53:43 +00:00
|
|
|
default:
|
|
|
|
return "";
|
|
|
|
}
|
2024-07-10 16:44:39 +00:00
|
|
|
}
|