feat: close #3300 support multiple api keys

This commit is contained in:
Yidadaa
2023-11-19 18:42:30 +08:00
parent 45b88ebb2a
commit 6aade62ce2
3 changed files with 11 additions and 3 deletions

View File

@@ -62,9 +62,17 @@ export const getServerSideConfig = () => {
const isAzure = !!process.env.AZURE_URL;
const apiKeyEnvVar = process.env.OPENAI_API_KEY ?? "";
const apiKeys = apiKeyEnvVar.split(",").map((v) => v.trim());
const randomIndex = Math.floor(Math.random() * apiKeys.length);
const apiKey = apiKeys[randomIndex];
console.log(
`[Server Config] using ${randomIndex + 1} of ${apiKeys.length} api key`,
);
return {
baseUrl: process.env.BASE_URL,
apiKey: process.env.OPENAI_API_KEY,
apiKey,
openaiOrgId: process.env.OPENAI_ORG_ID,
isAzure,