Skip to content

Commit

Permalink
fixup: ChatGPTNextWeb#1815 req.body will be broken in edge runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
Yidadaa authored and chenzeyu committed Nov 8, 2023
1 parent e352ce1 commit f5f7d6a
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions app/api/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,19 @@ export async function requestOpenai(req: NextRequest) {
},
cache: "no-store",
method: req.method,
body: req.clone().body,
body: req.body,
signal: controller.signal,
};

// #1815 try to refuse gpt4 request
if (DISABLE_GPT4) {
if (DISABLE_GPT4 && req.body) {
try {
const clonedBody = await req.clone().json();
if ((clonedBody?.model ?? "").includes("gpt-4")) {
const clonedBody = await req.text();
fetchOptions.body = clonedBody;

const jsonBody = JSON.parse(clonedBody);

if ((jsonBody?.model ?? "").includes("gpt-4")) {
return NextResponse.json(
{
error: true,
Expand Down

0 comments on commit f5f7d6a

Please sign in to comment.