明树Git Lab

Commit 063cafe5 authored by zfp1's avatar zfp1

update

parent 524c55bd
......@@ -10,8 +10,8 @@ const port = 3001;
// 微信服务号配置
const WECHAT_TOKEN = 'deepseektest';
const DEEPSEEK_API_URL = 'https://api.deepseek.com/v1/ask'; // 请替换为 DeepSeek 的具体 API 地址
const DEEPSEEK_API_KEY = 'your_deepseek_api_key'; // 请替换为你的 DeepSeek API 密钥
const DEEPSEEK_API_URL = 'https://api.deepseek.com/v1'; // 请替换为 DeepSeek 的具体 API 地址
const DEEPSEEK_API_KEY = 'sk-14f0cf16bad245169cd2563e0f9b678e'; // 请替换为你的 DeepSeek API 密钥
// 最大消息长度(微信最大支持2048字节)
const MAX_TEXT_LENGTH = 2048;
......@@ -49,15 +49,14 @@ function escapeXml(str) {
// 处理微信消息
app.post('/wechat', async (req, res) => {
const parser = new xml2js.Parser({ explicitArray: false, ignoreAttrs: true });
try {
// 解析微信发来的 XML 数据
const xmlData = await parser.parseStringPromise(req.body);
const xmlData = await xml2js.parseStringPromise(req.body);
// 获取用户提问的内容
const userMessage = xmlData.xml.Content;
console.log(userMessage, "===============")
if (!userMessage) {
return res.send('No content');
}
......@@ -67,9 +66,9 @@ app.post('/wechat', async (req, res) => {
apiKey: DEEPSEEK_API_KEY,
question: userMessage,
});
console.log(deepSeekResponse, "============")
// 获取 DeepSeek API 返回的答案
let answer = deepSeekResponse.data.answer || 'Sorry, I could not find an answer.';
let answer = deepSeekResponse.choices[0].message.content || 'Sorry, I could not find an answer.';
// 如果回答超长,截取并添加提示
if (answer.length > MAX_TEXT_LENGTH) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment