This commit is contained in:
Hk-Gosuto
2024-03-24 11:42:06 +08:00
parent 428bf81801
commit a18cb2c525
12 changed files with 112 additions and 18 deletions

View File

@@ -67,9 +67,16 @@ export async function requestOpenai(req: NextRequest) {
let jsonBody;
let clonedBody;
if (req.method !== "GET" && req.method !== "HEAD") {
const contentType = req.headers.get("Content-Type");
if (
req.method !== "GET" &&
req.method !== "HEAD" &&
contentType?.includes("json")
) {
clonedBody = await req.text();
jsonBody = JSON.parse(clonedBody) as { model?: string };
} else {
clonedBody = req.body;
}
if (serverConfig.isAzure) {
baseUrl = `${baseUrl}/${jsonBody?.model}`;
@@ -77,7 +84,7 @@ export async function requestOpenai(req: NextRequest) {
const fetchUrl = `${baseUrl}/${path}`;
const fetchOptions: RequestInit = {
headers: {
"Content-Type": "application/json",
"Content-Type": contentType ?? "application/json",
"Cache-Control": "no-store",
[authHeaderName]: authValue,
...(serverConfig.openaiOrgId && {