diff --git a/app/api/chat/config.template.ts b/app/api/chat/config.template.ts deleted file mode 100644 index 1b297a9fc..000000000 --- a/app/api/chat/config.template.ts +++ /dev/null @@ -1 +0,0 @@ -export const apiKey = "your dev api key here"; diff --git a/app/api/chat/route.ts b/app/api/chat/route.ts index 447b36dc6..5790ca35d 100644 --- a/app/api/chat/route.ts +++ b/app/api/chat/route.ts @@ -3,26 +3,15 @@ import { ChatRequest } from "./typing"; const isProd = process.env.NODE_ENV === "production"; -let openai: OpenAIApi | undefined; -async function initService() { - let apiKey = process.env.OPENAI_API_KEY; +let apiKey = process.env.OPENAI_API_KEY; - if (!isProd) { - apiKey = await (await import("./config")).apiKey; - } - - openai = new OpenAIApi( - new Configuration({ - apiKey, - }) - ); -} +const openai = new OpenAIApi( + new Configuration({ + apiKey, + }) +); export async function POST(req: Request) { - if (!openai) { - await initService(); - } - try { const requestBody = (await req.json()) as ChatRequest; const completion = await openai!.createChatCompletion(