chore: update env variables in readme

This commit is contained in:
steven
2023-03-30 16:34:42 +08:00
parent 04ab812070
commit be7a4c7078
3 changed files with 17 additions and 8 deletions

View File

@ -6,9 +6,11 @@ export const config = {
runtime: "edge",
};
const apiEndpoint = new URL(`${openAIApiEndpoint}/v1/chat/completions`);
const handler = async (req: NextRequest) => {
const reqBody = await req.json();
const rawRes = await fetch(`${openAIApiEndpoint}/v1/chat/completions`, {
const res = await fetch(apiEndpoint, {
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${openAIApiKey}`,
@ -23,10 +25,10 @@ const handler = async (req: NextRequest) => {
stream: true,
}),
});
if (!rawRes.ok) {
return new Response(rawRes.body, {
status: rawRes.status,
statusText: rawRes.statusText,
if (!res.ok) {
return new Response(res.body, {
status: res.status,
statusText: res.statusText,
});
}
@ -52,7 +54,7 @@ const handler = async (req: NextRequest) => {
}
};
const parser = createParser(streamParser);
for await (const chunk of rawRes.body as any) {
for await (const chunk of res.body as any) {
parser.feed(decoder.decode(chunk));
}
},