mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-05-19 20:20:16 +09:00
32 lines
708 B
TypeScript
32 lines
708 B
TypeScript
import { OpenAIApi, Configuration } from "openai";
|
|
import { apiKey } from "./config";
|
|
import { ChatRequest } from "./typing";
|
|
|
|
// set up openai api client
|
|
const config = new Configuration({
|
|
apiKey,
|
|
});
|
|
const openai = new OpenAIApi(config);
|
|
|
|
export async function POST(req: Request) {
|
|
try {
|
|
const requestBody = (await req.json()) as ChatRequest;
|
|
const completion = await openai.createChatCompletion(
|
|
{
|
|
...requestBody,
|
|
},
|
|
{
|
|
proxy: {
|
|
protocol: "socks",
|
|
host: "127.0.0.1",
|
|
port: 7890,
|
|
},
|
|
}
|
|
);
|
|
|
|
return new Response(JSON.stringify(completion.data));
|
|
} catch (e) {
|
|
return new Response(JSON.stringify(e));
|
|
}
|
|
}
|