Skip to content

Commit

Permalink
feat: support multiple keys
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmyLv committed Mar 2, 2023
1 parent 6e9c173 commit ff62145
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions utils/OpenAIResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
ReconnectInterval,
} from "eventsource-parser";

export type ChatGPTAgent = "user" | "system";
// TODO: maybe chat with video?
export type ChatGPTAgent = "user" | "system" | "assistant";

export interface ChatGPTMessage {
role: ChatGPTAgent;
Expand Down Expand Up @@ -42,7 +43,10 @@ export async function OpenAIResult(
) {
const encoder = new TextEncoder();
const decoder = new TextDecoder();
const openai_api_key = apiKey || process.env.OPENAI_API_KEY || "";
const myApiKeyList = process.env.OPENAI_API_KEY;
const luckyApiKey = myApiKeyList?.split(",").sort(() => Math.random() - 0.5)[0]

const openai_api_key = apiKey || luckyApiKey || "";

if (!checkApiKey(openai_api_key)) {
throw new Error("OpenAI API Key Format Error");
Expand Down

1 comment on commit ff62145

@vercel
Copy link

@vercel vercel bot commented on ff62145 Mar 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.