supporting for customize BASE_PATH
This commit is contained in:
parent
7f3cbaa064
commit
06d279ac56
|
@ -1,5 +1,6 @@
|
|||
import { createParser } from "eventsource-parser";
|
||||
import { NextRequest } from "next/server";
|
||||
import { BASE_PATH } from "openai/base";
|
||||
|
||||
async function createStream(req: NextRequest) {
|
||||
const encoder = new TextEncoder();
|
||||
|
@ -13,7 +14,12 @@ async function createStream(req: NextRequest) {
|
|||
console.log("[Stream] using user api key");
|
||||
}
|
||||
|
||||
const res = await fetch("https://api.openai.com/v1/chat/completions", {
|
||||
let basePath = BASE_PATH;
|
||||
if (process.env.OPENAI_API_BASE_PATH) {
|
||||
basePath = process.env.OPENAI_API_BASE_PATH.replace(/\/+$/, "");
|
||||
}
|
||||
|
||||
const res = await fetch(basePath + "/chat/completions", {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${apiKey}`,
|
||||
|
|
|
@ -10,10 +10,16 @@ export async function POST(req: Request) {
|
|||
apiKey = userApiKey;
|
||||
}
|
||||
|
||||
let basePath = undefined;
|
||||
if (process.env.OPENAI_API_BASE_PATH) {
|
||||
basePath = process.env.OPENAI_API_BASE_PATH.replace(/\/+$/, "");
|
||||
}
|
||||
|
||||
const openai = new OpenAIApi(
|
||||
new Configuration({
|
||||
apiKey,
|
||||
})
|
||||
}),
|
||||
basePath
|
||||
);
|
||||
|
||||
const requestBody = (await req.json()) as ChatRequest;
|
||||
|
|
Loading…
Reference in New Issue