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 committed Jun 6, 2023
1 parent d8284ef commit 675abe4
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 675abe4

Please sign in to comment.