修改open ai被覆盖

This commit is contained in:
xiaobao
2025-09-17 15:42:09 +08:00
parent 94e3575d68
commit 09ee65072f

View File

@@ -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,34 +102,38 @@ app.get("/test-db", async (req, res) => {
// 查询用户所有会话列表 // 查询用户所有会话列表
app.get("/sessions", 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');
}
// 查该用户所有的会话,按最后活跃时间倒序 console.log("收到的 userId:", req.query.userId);
const [rows] = await pool.query( try {
` const { userId } = req.query.userId;
SELECT session_id, MAX(created_at) AS last_time if (!userId || userId === "NaN" || isNaN(Number(userId))) {
FROM ai_chat_messages // return res.status(400).json({ code: 1, error: "userId 必填" });
WHERE user_id = ? return res.redirect('http://1.95.137.212/#/login?redirect=%2Findex&goRemote=1');
GROUP BY session_id }
ORDER BY last_time DESC
`,
[userId]
);
res.json({ // 查该用户所有的会话,按最后活跃时间倒序
code: 0, const [rows] = await pool.query(
userId, `
sessions: rows.map((r) => r.session_id), // 只返回 session_id 列表 SELECT session_id, MAX(created_at) AS last_time
}); FROM ai_chat_messages
} catch (err) { WHERE user_id = ?
console.error("查询会话列表失败:", err); GROUP BY session_id
res.status(500).json({ code: 1, error: err.message }); 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️⃣ 图像分析 ------------------ // ------------------ 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: [
{ {