|
@@ -18,6 +18,7 @@ app.post("/api/openai", async (req, res) => {
|
|
|
|
|
|
|
|
let requestUrl = open_ai_url;
|
|
let requestUrl = open_ai_url;
|
|
|
let apiKey = api_key;
|
|
let apiKey = api_key;
|
|
|
|
|
+ let aiBody = payload;
|
|
|
// 验证必需的参数
|
|
// 验证必需的参数
|
|
|
if (!model_id) {
|
|
if (!model_id) {
|
|
|
if (!open_ai_url || !api_key || !payload) {
|
|
if (!open_ai_url || !api_key || !payload) {
|
|
@@ -42,6 +43,7 @@ app.post("/api/openai", async (req, res) => {
|
|
|
if (model.ok) {
|
|
if (model.ok) {
|
|
|
requestUrl = model.data.url;
|
|
requestUrl = model.data.url;
|
|
|
apiKey = model.data.key;
|
|
apiKey = model.data.key;
|
|
|
|
|
+ aiBody.model = model.data.model;
|
|
|
} else {
|
|
} else {
|
|
|
return res.status(400).json({
|
|
return res.status(400).json({
|
|
|
error:
|
|
error:
|
|
@@ -65,7 +67,7 @@ app.post("/api/openai", async (req, res) => {
|
|
|
const isClaudeAPI =
|
|
const isClaudeAPI =
|
|
|
requestUrl.includes("anthropic.com") || requestUrl.includes("claude");
|
|
requestUrl.includes("anthropic.com") || requestUrl.includes("claude");
|
|
|
|
|
|
|
|
- const isStreaming = payload.stream === true;
|
|
|
|
|
|
|
+ const isStreaming = aiBody.stream === true;
|
|
|
|
|
|
|
|
// 构建请求URL和headers
|
|
// 构建请求URL和headers
|
|
|
|
|
|
|
@@ -92,7 +94,7 @@ app.post("/api/openai", async (req, res) => {
|
|
|
const response = await fetch(requestUrl, {
|
|
const response = await fetch(requestUrl, {
|
|
|
method: "POST",
|
|
method: "POST",
|
|
|
headers: headers,
|
|
headers: headers,
|
|
|
- body: JSON.stringify(payload),
|
|
|
|
|
|
|
+ body: JSON.stringify(aiBody),
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
// 复制响应头到客户端
|
|
// 复制响应头到客户端
|
|
@@ -111,7 +113,7 @@ app.post("/api/openai", async (req, res) => {
|
|
|
|
|
|
|
|
// 设置响应状态码(直接使用大模型返回的状态码)
|
|
// 设置响应状态码(直接使用大模型返回的状态码)
|
|
|
res.status(response.status);
|
|
res.status(response.status);
|
|
|
-
|
|
|
|
|
|
|
+ logger.info(response.status);
|
|
|
if (!response.ok) {
|
|
if (!response.ok) {
|
|
|
// 对于错误响应,也要透传原始数据
|
|
// 对于错误响应,也要透传原始数据
|
|
|
const reader = response.body.getReader();
|
|
const reader = response.body.getReader();
|
|
@@ -158,7 +160,7 @@ app.post("/api/openai", async (req, res) => {
|
|
|
const response = await fetch(requestUrl, {
|
|
const response = await fetch(requestUrl, {
|
|
|
method: "POST",
|
|
method: "POST",
|
|
|
headers: headers,
|
|
headers: headers,
|
|
|
- body: JSON.stringify(payload),
|
|
|
|
|
|
|
+ body: JSON.stringify(aiBody),
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
// 复制响应头到客户端
|
|
// 复制响应头到客户端
|