-
Notifications
You must be signed in to change notification settings - Fork 14.6k
Expand file tree
/
Copy pathapi-key.ts
More file actions
36 lines (29 loc) · 1.11 KB
/
api-key.ts
File metadata and controls
36 lines (29 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { env } from 'node:process';
import type { LLMProvider } from './model';
export function getAPIKey(cloudflareEnv: Env) {
/**
* The `cloudflareEnv` is only used when deployed or when previewing locally.
* In development the environment variables are available through `env`.
*/
return env.ANTHROPIC_API_KEY || cloudflareEnv.ANTHROPIC_API_KEY;
}
export function getMiniMaxAPIKey(cloudflareEnv: Env) {
return env.MINIMAX_API_KEY || cloudflareEnv.MINIMAX_API_KEY || '';
}
export function getLLMProvider(cloudflareEnv: Env): LLMProvider {
const provider = (env.DEFAULT_LLM_PROVIDER || cloudflareEnv.DEFAULT_LLM_PROVIDER || 'anthropic').toLowerCase();
if (provider === 'minimax') {
return 'minimax';
}
return 'anthropic';
}
export function getProviderAPIKey(cloudflareEnv: Env): { provider: LLMProvider; apiKey: string } {
const provider = getLLMProvider(cloudflareEnv);
switch (provider) {
case 'minimax':
return { provider, apiKey: getMiniMaxAPIKey(cloudflareEnv) };
case 'anthropic':
default:
return { provider: 'anthropic', apiKey: getAPIKey(cloudflareEnv) };
}
}