mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-11-22 00:36:48 +08:00
add basePath for api env inject
This commit is contained in:
@@ -6,14 +6,18 @@ async function createStream(req: NextRequest) {
|
||||
const decoder = new TextDecoder();
|
||||
|
||||
let apiKey = process.env.OPENAI_API_KEY;
|
||||
|
||||
let apiBasePath = process.env.OPENAI_API_BASE_PATH;
|
||||
if (apiBasePath) {
|
||||
apiBasePath = apiBasePath.replace(/\/+$/, "");
|
||||
}
|
||||
|
||||
const userApiKey = req.headers.get("token");
|
||||
if (userApiKey) {
|
||||
apiKey = userApiKey;
|
||||
console.log("[Stream] using user api key");
|
||||
}
|
||||
|
||||
const res = await fetch("https://api.openai.com/v1/chat/completions", {
|
||||
const res = await fetch(`${apiBasePath ? apiBasePath : 'https://api.openai.com/v1'}/chat/completions`, {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${apiKey}`,
|
||||
|
||||
Reference in New Issue
Block a user