-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.ts
31 lines (25 loc) · 964 Bytes
/
config.ts
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
import type { Config, Provider } from './types';
function parseProviderConfig(): Config {
const config: Config = {
providers: {},
defaultProxy: process.env.RELAY_PROXY_HTTP,
};
// Get all provider configurations from environment variables
for (const [key, value] of Object.entries(process.env)) {
if (!key.startsWith('RELAY_PROVIDER_')) continue;
if (!value) continue;
const providerName = key.replace('RELAY_PROVIDER_', '').toLowerCase();
const models = process.env[`RELAY_MODEL_${key.replace('RELAY_PROVIDER_', '')}`]?.split(',') || [];
const apiKey = process.env[`RELAY_API_KEY_${key.replace('RELAY_PROVIDER_', '')}`] || '';
const proxy = process.env[`RELAY_PROXY_HTTP_${key.replace('RELAY_PROVIDER_', '')}`];
config.providers[providerName] = {
prefix: providerName,
baseURL: value,
models,
apiKey,
proxy,
};
}
return config;
}
export const config = parseProviderConfig();