mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-12-02 14:26:07 +08:00
feat: 增加Azure opanai 能力支持
This commit is contained in:
@@ -1,15 +1,21 @@
|
||||
import { NextRequest } from "next/server";
|
||||
|
||||
const OPENAI_URL = "api.openai.com";
|
||||
const AZURE_OPENAI_URL = "azure-openai-gpt.openai.azure.com";
|
||||
const DEFAULT_PROTOCOL = "https";
|
||||
const PROTOCOL = process.env.PROTOCOL ?? DEFAULT_PROTOCOL;
|
||||
const BASE_URL = process.env.BASE_URL ?? OPENAI_URL;
|
||||
|
||||
export async function requestOpenai(req: NextRequest) {
|
||||
const apiKey = req.headers.get("token");
|
||||
const openaiPath = req.headers.get("path");
|
||||
|
||||
let baseUrl = BASE_URL;
|
||||
let baseUrl = OPENAI_URL;
|
||||
if (openaiPath?.includes("/deployments/")) {
|
||||
baseUrl = AZURE_OPENAI_URL;
|
||||
}
|
||||
if (process.env.BASE_URL) {
|
||||
baseUrl = process.env.BASE_URL;
|
||||
}
|
||||
|
||||
if (!baseUrl.startsWith("http")) {
|
||||
baseUrl = `${PROTOCOL}://${baseUrl}`;
|
||||
@@ -22,6 +28,7 @@ export async function requestOpenai(req: NextRequest) {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${apiKey}`,
|
||||
"api-key": apiKey || "",
|
||||
},
|
||||
method: req.method,
|
||||
body: req.body,
|
||||
|
||||
Reference in New Issue
Block a user