feat: update dev config

This commit is contained in:
Yidadaa 2023-03-11 02:53:34 +08:00
parent 144eb68414
commit b17a6a7f61
2 changed files with 6 additions and 18 deletions

View File

@ -1 +0,0 @@
export const apiKey = "your dev api key here";

View File

@ -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(