修改open ai被覆盖
This commit is contained in:
65
server2.js
65
server2.js
@@ -42,10 +42,49 @@ app.use(express.json({ limit: "200mb" })); // 支持大 JSON
|
|||||||
app.use(express.urlencoded({ extended: true })); // 支持 form-data 字段
|
app.use(express.urlencoded({ extended: true })); // 支持 form-data 字段
|
||||||
|
|
||||||
// 初始化混元客户端
|
// 初始化混元客户端
|
||||||
|
// const client = new OpenAI({
|
||||||
|
// apiKey: "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",
|
||||||
|
// baseURL: "https://openrouter.ai/api/v1",
|
||||||
|
// timeout: 120000,
|
||||||
|
// });
|
||||||
|
|
||||||
|
// const client = new OpenAI({
|
||||||
|
// baseURL:"https://openrouter.ai/api/v1",
|
||||||
|
// apiKey:"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",
|
||||||
|
// timeout: 120000
|
||||||
|
// });
|
||||||
|
|
||||||
|
// const client = new OpenAI({
|
||||||
|
// baseURL:"https://satabot.openai.azure.com/",
|
||||||
|
// apiKey:"DxvRiQWROzLTapiSHcK0FXKAAXDBlhci1XaqTTpr50sgUsAkmxfUJQQJ99BIACYeBjFXJ3w3AAABACOGZdHp",
|
||||||
|
// timeout: 120000
|
||||||
|
// });
|
||||||
|
|
||||||
|
|
||||||
|
//https://satabot.openai.azure.com/
|
||||||
|
// const client = new OpenAI({
|
||||||
|
// apiKey: "DxvRiQWROzLTapiSHcK0FXKAAXDBlhci1XaqTTpr50sgUsAkmxfUJQQJ99BIACYeBjFXJ3w3AAABACOGZdHp", // 推荐放环境变量
|
||||||
|
// baseURL: "https://satabot.openai.azure.com/openai/deployments/gpt-4.1/chat/completions?api-version=2025-01-01-preview",
|
||||||
|
// defaultQuery: { "api-version": "2024-02-15-preview" },
|
||||||
|
// defaultHeaders: { "api-key": process.env.AZURE_OPENAI_KEY },
|
||||||
|
// timeout: 120000
|
||||||
|
// });
|
||||||
|
|
||||||
|
// https://satabot.openai.azure.com/openai/deployments/gpt-4.1/
|
||||||
|
// https://satabot.openai.azure.com/openai/deployments/gpt-5-mini/
|
||||||
|
// 初始化客户端
|
||||||
|
|
||||||
const client = new OpenAI({
|
const client = new OpenAI({
|
||||||
apiKey: "sk-LVfG90qgdhf9kKQUucqBSLioxamDu7gBeW9boXqKOxIDJt7H",
|
apiKey: "DxvRiQWROzLTapiSHcK0FXKAAXDBlhci1XaqTTpr50sgUsAkmxfUJQQJ99BIACYeBjFXJ3w3AAABACOGZdHp",
|
||||||
baseURL: "https://api.hunyuan.cloud.tencent.com/v1",
|
baseURL: "https://satabot.openai.azure.com/openai/deployments/gpt-4.1",
|
||||||
timeout: 120000,
|
defaultQuery: { "api-version": "2024-04-01-preview" },
|
||||||
|
timeout: 120000
|
||||||
|
});
|
||||||
|
const client1 = new OpenAI({
|
||||||
|
apiKey: "DxvRiQWROzLTapiSHcK0FXKAAXDBlhci1XaqTTpr50sgUsAkmxfUJQQJ99BIACYeBjFXJ3w3AAABACOGZdHp",
|
||||||
|
baseURL: "https://satabot.openai.azure.com/openai/deployments/gpt-5-mini/",
|
||||||
|
defaultQuery: { "api-version": "2024-04-01-preview" },
|
||||||
|
timeout: 120000
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get("/test-db", async (req, res) => {
|
app.get("/test-db", async (req, res) => {
|
||||||
@@ -63,8 +102,10 @@ app.get("/test-db", async (req, res) => {
|
|||||||
|
|
||||||
// 查询用户所有会话列表
|
// 查询用户所有会话列表
|
||||||
app.get("/sessions", async (req, res) => {
|
app.get("/sessions", async (req, res) => {
|
||||||
|
|
||||||
|
console.log("收到的 userId:", req.query.userId);
|
||||||
try {
|
try {
|
||||||
const { userId } = req.query;
|
const { userId } = req.query.userId;
|
||||||
if (!userId || userId === "NaN" || isNaN(Number(userId))) {
|
if (!userId || userId === "NaN" || isNaN(Number(userId))) {
|
||||||
// return res.status(400).json({ code: 1, error: "userId 必填" });
|
// return res.status(400).json({ code: 1, error: "userId 必填" });
|
||||||
return res.redirect('http://1.95.137.212/#/login?redirect=%2Findex&goRemote=1');
|
return res.redirect('http://1.95.137.212/#/login?redirect=%2Findex&goRemote=1');
|
||||||
@@ -87,7 +128,9 @@ app.get("/sessions", async (req, res) => {
|
|||||||
userId,
|
userId,
|
||||||
sessions: rows.map((r) => r.session_id), // 只返回 session_id 列表
|
sessions: rows.map((r) => r.session_id), // 只返回 session_id 列表
|
||||||
});
|
});
|
||||||
} catch (err) {
|
}
|
||||||
|
catch (err)
|
||||||
|
{
|
||||||
console.error("查询会话列表失败:", err);
|
console.error("查询会话列表失败:", err);
|
||||||
res.status(500).json({ code: 1, error: err.message });
|
res.status(500).json({ code: 1, error: err.message });
|
||||||
}
|
}
|
||||||
@@ -139,11 +182,11 @@ app.post("/analyze", upload.single("file"), async (req, res) => {
|
|||||||
|
|
||||||
// ------------------ 2️⃣ 图像分析 ------------------
|
// ------------------ 2️⃣ 图像分析 ------------------
|
||||||
const completion = await client.chat.completions.create({
|
const completion = await client.chat.completions.create({
|
||||||
model: "hunyuan-vision",
|
model: "gpt-4.1",
|
||||||
stream: true,
|
stream: true,
|
||||||
do_scene: true,
|
// do_scene: true,
|
||||||
do_behavior: true,
|
// do_behavior: true,
|
||||||
llm_model: "hunyuan-turbos-latest",
|
// llm_model: "hunyuan-turbos-latest",
|
||||||
messages: [
|
messages: [
|
||||||
{
|
{
|
||||||
role: "system",
|
role: "system",
|
||||||
@@ -186,8 +229,8 @@ app.post("/analyze", upload.single("file"), async (req, res) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// ------------------ 3️⃣ LLM 分析 ------------------
|
// ------------------ 3️⃣ LLM 分析 ------------------
|
||||||
const llmStream = await client.chat.completions.create({
|
const llmStream = await client1.chat.completions.create({
|
||||||
model: "hunyuan-turbos-latest",
|
model: "gpt-5-mini",
|
||||||
stream: true,
|
stream: true,
|
||||||
messages: [
|
messages: [
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user