1 line
9.6 KiB
JSON
1 line
9.6 KiB
JSON
{"repo": "alitabe/taotie", "files": {"api/interpret.js": {"0092dd1660d12f9377e2ec1063878494214ad10f": {"t": 1785746624.0017402, "n": 2110, "h": "c9bde2a592133b30", "c": "// server.js —— Express + DeepSeek 完成 /api/interpret\r\nimport 'dotenv/config'; // 自动读取 .env\r\nimport express from 'express';\r\nimport cors from 'cors';\r\nimport OpenAI from 'openai';\r\n\r\nconst app = express();\r\napp.use(cors());\r\napp.use(express.json());\r\n\r\n// 1. 初始化 DeepSeek 客户端(官方兼容 OpenAI 格式)\r\nconst openai = new OpenAI({\r\n baseURL: 'https://api.deepseek.com/v1', // 末尾必须 /v1,且无空格\r\n apiKey: 'sk-33e6e70d121543eeb038f7221b0a4abb', // .env 里:DEEPSEEK_KEY=sk-xxx\r\n});\r\n\r\n// 2. 矿产报告解读接口\r\napp.post('/api/interpret', async (req, res) => {\r\n const {\r\n miningType,\r\n highPercent,\r\n mediumPercent,\r\n lowPercent,\r\n confidence,\r\n weights,\r\n hotspotCount,\r\n areaKm2,\r\n } = req.body;\r\n\r\n const prompt = `\r\n你是一位矿产勘探 AI 助手。请根据以下模型预测结果,严格按格式输出三段文字(每段 150~200 字):\r\n1 报告摘要\r\n2 主要结论(用 <li> 包裹)\r\n3 勘探建议(用 <li> 包裹)\r\n\r\n矿产类型:${miningType}\r\n高概率区域:${highPercent} 中概率:${mediumPercent} 低概率:${lowPercent} 置信度:${confidence}\r\n数据权重:地球化学 ${weights.geochemical}% 地球物理 ${weights.geophysical}% 钻探 ${weights.drilling}% 遥感 ${weights.remoteSensing}%\r\n高值区块数:${hotspotCount} 面积:${areaKm2} km²\r\n`;\r\n\r\n try {\r\n // 3. 调用 DeepSeek\r\n const completion = await openai.chat.completions.create({\r\n model: 'deepseek-chat', // 官方唯一聊天模型\r\n messages: [\r\n { role: 'system', content: 'You are a helpful assistant.' },\r\n { role: 'user', content: prompt },\r\n ],\r\n temperature: 0.7,\r\n max_tokens: 800,\r\n });\r\n\r\n const fullText = completion.choices[0].message.content;\r\n\r\n // 4. 简单拆三段\r\n const parts = fullText.split(/\\d\\s*(报告摘要|主要结论|勘探建议)/);\r\n const summary = (parts[2] || '').trim();\r\n const conclusion = (parts[4] || '').trim();\r\n const suggestion = (parts[6] || '').trim();\r\n\r\n res.json({ summary, conclusion, suggestion });\r\n } catch (err) {\r\n // 5. 把真正的 DeepSeek 错误打出来\r\n console.error('DeepSeek error:', err);\r\n const msg = err.response?.data || err.message;\r\n res.status(500).json({ error: msg });\r\n }\r\n});\r\n\r\n// 6. 启动\r\nconst PORT = process.env.PORT || 3000;\r\napp.listen(PORT, () => console.log(`Interpret API on :${PORT}`));\r\n"}, "af09d7c51bac2bb673ebcdf0b0d2c1763aadc3ca": {"t": 1785766377.3823245, "n": 2110, "h": "c9bde2a592133b30", "c": "// server.js —— Express + DeepSeek 完成 /api/interpret\r\nimport 'dotenv/config'; // 自动读取 .env\r\nimport express from 'express';\r\nimport cors from 'cors';\r\nimport OpenAI from 'openai';\r\n\r\nconst app = express();\r\napp.use(cors());\r\napp.use(express.json());\r\n\r\n// 1. 初始化 DeepSeek 客户端(官方兼容 OpenAI 格式)\r\nconst openai = new OpenAI({\r\n baseURL: 'https://api.deepseek.com/v1', // 末尾必须 /v1,且无空格\r\n apiKey: 'sk-33e6e70d121543eeb038f7221b0a4abb', // .env 里:DEEPSEEK_KEY=sk-xxx\r\n});\r\n\r\n// 2. 矿产报告解读接口\r\napp.post('/api/interpret', async (req, res) => {\r\n const {\r\n miningType,\r\n highPercent,\r\n mediumPercent,\r\n lowPercent,\r\n confidence,\r\n weights,\r\n hotspotCount,\r\n areaKm2,\r\n } = req.body;\r\n\r\n const prompt = `\r\n你是一位矿产勘探 AI 助手。请根据以下模型预测结果,严格按格式输出三段文字(每段 150~200 字):\r\n1 报告摘要\r\n2 主要结论(用 <li> 包裹)\r\n3 勘探建议(用 <li> 包裹)\r\n\r\n矿产类型:${miningType}\r\n高概率区域:${highPercent} 中概率:${mediumPercent} 低概率:${lowPercent} 置信度:${confidence}\r\n数据权重:地球化学 ${weights.geochemical}% 地球物理 ${weights.geophysical}% 钻探 ${weights.drilling}% 遥感 ${weights.remoteSensing}%\r\n高值区块数:${hotspotCount} 面积:${areaKm2} km²\r\n`;\r\n\r\n try {\r\n // 3. 调用 DeepSeek\r\n const completion = await openai.chat.completions.create({\r\n model: 'deepseek-chat', // 官方唯一聊天模型\r\n messages: [\r\n { role: 'system', content: 'You are a helpful assistant.' },\r\n { role: 'user', content: prompt },\r\n ],\r\n temperature: 0.7,\r\n max_tokens: 800,\r\n });\r\n\r\n const fullText = completion.choices[0].message.content;\r\n\r\n // 4. 简单拆三段\r\n const parts = fullText.split(/\\d\\s*(报告摘要|主要结论|勘探建议)/);\r\n const summary = (parts[2] || '').trim();\r\n const conclusion = (parts[4] || '').trim();\r\n const suggestion = (parts[6] || '').trim();\r\n\r\n res.json({ summary, conclusion, suggestion });\r\n } catch (err) {\r\n // 5. 把真正的 DeepSeek 错误打出来\r\n console.error('DeepSeek error:', err);\r\n const msg = err.response?.data || err.message;\r\n res.status(500).json({ error: msg });\r\n }\r\n});\r\n\r\n// 6. 启动\r\nconst PORT = process.env.PORT || 3000;\r\napp.listen(PORT, () => console.log(`Interpret API on :${PORT}`));\r\n"}, "b445ea7ef5cf3c183cc3ef7961686167e703e5aa": {"t": 1785766378.88078, "n": 1617, "h": "998e8a9cf6115535", "c": "// POST /api/interpret\r\nimport express from 'express';\r\nimport cors from 'cors';\r\nimport { config } from 'dotenv';\r\nconfig();\r\n\r\nconst app = express();\r\napp.use(cors());\r\napp.use(express.json());\r\n\r\nconst LLM_URL = 'https://api.deepseek.com';\r\nconst API_KEY = 'sk-21a511574b4f40d2abb651eba7c7e516'; // 保密\r\n\r\napp.post('/api/interpret', async (req,res)=>{\r\n const {miningType, highPercent, mediumPercent, lowPercent, confidence, weights, hotspotCount, areaKm2} = req.body;\r\n const prompt = `\r\n你是一位矿产勘探 AI 助手。请根据以下模型预测结果,严格按格式输出三段文字,每段 150~200 字:\r\n1 报告摘要\r\n2 主要结论(用<li>包裹)\r\n3 勘探建议(用<li>包裹)\r\n\r\n矿产类型:${miningType}\r\n高概率区域:${highPercent} 中概率:${mediumPercent} 低概率:${lowPercent} 置信度:${confidence}\r\n数据权重:地球化学 ${weights.geochemical}% 地球物理 ${weights.geophysical}% 钻探 ${weights.drilling}% 遥感 ${weights.remoteSensing}%\r\n高值区块数:${hotspotCount} 面积:${areaKm2}km²\r\n`;\r\n\r\n const body={\r\n model:'kimi-chat',\r\n messages:[{role:'user', content:prompt}],\r\n temperature:0.7,\r\n max_tokens:1000\r\n };\r\n const r = await fetch(LLM_URL,{\r\n method:'POST',\r\n headers:{Authorization:`Bearer ${API_KEY}`,'Content-Type':'application/json'},\r\n body:JSON.stringify(body)\r\n });\r\n if(!r.ok) return res.status(r.status).send({error:'LLM 调用失败'});\r\n const data = await r.json();\r\n const text = data.choices[0].message.content;\r\n\r\n // 简单解析三段\r\n const parts = text.split(/\\n*\\d\\s+/).filter(Boolean);\r\n const [summary, conclusion, suggestion] = parts.map(p=>\r\n p.trim().replace(/^报告摘要|主要结论|勘探建议/gi,'')\r\n );\r\n res.json({summary, conclusion, suggestion});\r\n});\r\n\r\napp.listen(3000,()=>console.log('Interpret API on :3000'));\r\n\r\n"}, "8f012a5737142f9016687024ea42515f4cdf6963": {"t": 1785766380.0134351, "n": 1617, "h": "ef13eae2b5ba83cd", "c": "// POST /api/interpret\r\nimport express from 'express';\r\nimport cors from 'cors';\r\nimport { config } from 'dotenv';\r\nconfig();\r\n\r\nconst app = express();\r\napp.use(cors());\r\napp.use(express.json());\r\n\r\nconst LLM_URL = 'https://api.moonshot.cn/v1/chat/completions';\r\nconst API_KEY = process.env.KIMI_KEY; // 保密\r\n\r\napp.post('/api/interpret', async (req,res)=>{\r\n const {miningType, highPercent, mediumPercent, lowPercent, confidence, weights, hotspotCount, areaKm2} = req.body;\r\n const prompt = `\r\n你是一位矿产勘探 AI 助手。请根据以下模型预测结果,严格按格式输出三段文字,每段 150~200 字:\r\n1 报告摘要\r\n2 主要结论(用<li>包裹)\r\n3 勘探建议(用<li>包裹)\r\n\r\n矿产类型:${miningType}\r\n高概率区域:${highPercent} 中概率:${mediumPercent} 低概率:${lowPercent} 置信度:${confidence}\r\n数据权重:地球化学 ${weights.geochemical}% 地球物理 ${weights.geophysical}% 钻探 ${weights.drilling}% 遥感 ${weights.remoteSensing}%\r\n高值区块数:${hotspotCount} 面积:${areaKm2}km²\r\n`;\r\n\r\n const body={\r\n model:'kimi-chat',\r\n messages:[{role:'user', content:prompt}],\r\n temperature:0.7,\r\n max_tokens:1000\r\n };\r\n const r = await fetch(LLM_URL,{\r\n method:'POST',\r\n headers:{Authorization:`Bearer ${API_KEY}`,'Content-Type':'application/json'},\r\n body:JSON.stringify(body)\r\n });\r\n if(!r.ok) return res.status(r.status).send({error:'LLM 调用失败'});\r\n const data = await r.json();\r\n const text = data.choices[0].message.content;\r\n\r\n // 简单解析三段\r\n const parts = text.split(/\\n*\\d\\s+/).filter(Boolean);\r\n const [summary, conclusion, suggestion] = parts.map(p=>\r\n p.trim().replace(/^报告摘要|主要结论|勘探建议/gi,'')\r\n );\r\n res.json({summary, conclusion, suggestion});\r\n});\r\n\r\napp.listen(3000,()=>console.log('Interpret API on :3000'));\r\n"}}}} |