diff --git a/server2.js b/server2.js index 8a01a82..8c70165 100755 --- a/server2.js +++ b/server2.js @@ -42,10 +42,49 @@ app.use(express.json({ limit: "200mb" })); // 支持大 JSON 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({ - apiKey: "sk-LVfG90qgdhf9kKQUucqBSLioxamDu7gBeW9boXqKOxIDJt7H", - baseURL: "https://api.hunyuan.cloud.tencent.com/v1", - timeout: 120000, + apiKey: "DxvRiQWROzLTapiSHcK0FXKAAXDBlhci1XaqTTpr50sgUsAkmxfUJQQJ99BIACYeBjFXJ3w3AAABACOGZdHp", + baseURL: "https://satabot.openai.azure.com/openai/deployments/gpt-4.1", + 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) => { @@ -63,34 +102,38 @@ app.get("/test-db", async (req, res) => { // 查询用户所有会话列表 app.get("/sessions", async (req, res) => { - try { - const { userId } = req.query; - if (!userId || userId === "NaN" || isNaN(Number(userId))) { - // return res.status(400).json({ code: 1, error: "userId 必填" }); - return res.redirect('http://1.95.137.212/#/login?redirect=%2Findex&goRemote=1'); - } - // 查该用户所有的会话,按最后活跃时间倒序 - const [rows] = await pool.query( - ` - SELECT session_id, MAX(created_at) AS last_time - FROM ai_chat_messages - WHERE user_id = ? - GROUP BY session_id - ORDER BY last_time DESC - `, - [userId] - ); + console.log("收到的 userId:", req.query.userId); + try { + const { userId } = req.query.userId; + if (!userId || userId === "NaN" || isNaN(Number(userId))) { + // return res.status(400).json({ code: 1, error: "userId 必填" }); + return res.redirect('http://1.95.137.212/#/login?redirect=%2Findex&goRemote=1'); + } - res.json({ - code: 0, - userId, - sessions: rows.map((r) => r.session_id), // 只返回 session_id 列表 - }); - } catch (err) { - console.error("查询会话列表失败:", err); - res.status(500).json({ code: 1, error: err.message }); - } + // 查该用户所有的会话,按最后活跃时间倒序 + const [rows] = await pool.query( + ` + SELECT session_id, MAX(created_at) AS last_time + FROM ai_chat_messages + WHERE user_id = ? + GROUP BY session_id + ORDER BY last_time DESC + `, + [userId] + ); + + res.json({ + code: 0, + userId, + sessions: rows.map((r) => r.session_id), // 只返回 session_id 列表 + }); + } + catch (err) + { + console.error("查询会话列表失败:", err); + res.status(500).json({ code: 1, error: err.message }); + } }); // 查询会话历史 @@ -139,11 +182,11 @@ app.post("/analyze", upload.single("file"), async (req, res) => { // ------------------ 2️⃣ 图像分析 ------------------ const completion = await client.chat.completions.create({ - model: "hunyuan-vision", + model: "gpt-4.1", stream: true, - do_scene: true, - do_behavior: true, - llm_model: "hunyuan-turbos-latest", + // do_scene: true, + // do_behavior: true, + // llm_model: "hunyuan-turbos-latest", messages: [ { role: "system", @@ -186,8 +229,8 @@ app.post("/analyze", upload.single("file"), async (req, res) => { ); // ------------------ 3️⃣ LLM 分析 ------------------ - const llmStream = await client.chat.completions.create({ - model: "hunyuan-turbos-latest", + const llmStream = await client1.chat.completions.create({ + model: "gpt-5-mini", stream: true, messages: [ {