forked from XiaoMo/ChatGPT-Next-Web
feat: update dev config
This commit is contained in:
parent
144eb68414
commit
b17a6a7f61
@ -1 +0,0 @@
|
|||||||
export const apiKey = "your dev api key here";
|
|
@ -3,26 +3,15 @@ import { ChatRequest } from "./typing";
|
|||||||
|
|
||||||
const isProd = process.env.NODE_ENV === "production";
|
const isProd = process.env.NODE_ENV === "production";
|
||||||
|
|
||||||
let openai: OpenAIApi | undefined;
|
let apiKey = process.env.OPENAI_API_KEY;
|
||||||
async function initService() {
|
|
||||||
let apiKey = process.env.OPENAI_API_KEY;
|
|
||||||
|
|
||||||
if (!isProd) {
|
const openai = new OpenAIApi(
|
||||||
apiKey = await (await import("./config")).apiKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
openai = new OpenAIApi(
|
|
||||||
new Configuration({
|
new Configuration({
|
||||||
apiKey,
|
apiKey,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
export async function POST(req: Request) {
|
export async function POST(req: Request) {
|
||||||
if (!openai) {
|
|
||||||
await initService();
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const requestBody = (await req.json()) as ChatRequest;
|
const requestBody = (await req.json()) as ChatRequest;
|
||||||
const completion = await openai!.createChatCompletion(
|
const completion = await openai!.createChatCompletion(
|
||||||
|
Loading…
Reference in New Issue
Block a user