2023-03-29 17:45:26 +00:00
|
|
|
import { NextRequest, NextResponse } from "next/server";
|
|
|
|
import { requestOpenai } from "../common";
|
|
|
|
|
|
|
|
async function makeRequest(req: NextRequest) {
|
|
|
|
try {
|
2023-04-01 09:34:33 +00:00
|
|
|
const api = await requestOpenai(req);
|
|
|
|
const res = new NextResponse(api.body);
|
2023-04-02 05:45:34 +00:00
|
|
|
res.headers.set("Content-Type", "application/json");
|
2023-04-06 09:28:09 +00:00
|
|
|
res.headers.set("Cache-Control", "no-cache");
|
2023-04-01 09:34:33 +00:00
|
|
|
return res;
|
2023-03-29 17:45:26 +00:00
|
|
|
} catch (e) {
|
|
|
|
console.error("[OpenAI] ", req.body, e);
|
|
|
|
return NextResponse.json(
|
|
|
|
{
|
|
|
|
error: true,
|
|
|
|
msg: JSON.stringify(e),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
status: 500,
|
2023-04-17 03:36:32 +00:00
|
|
|
}
|
2023-03-29 17:45:26 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function POST(req: NextRequest) {
|
|
|
|
return makeRequest(req);
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function GET(req: NextRequest) {
|
|
|
|
return makeRequest(req);
|
|
|
|
}
|
2023-04-17 03:36:32 +00:00
|
|
|
|
|
|
|
export const config = {
|
|
|
|
runtime: "edge",
|
|
|
|
};
|