DEV-004: 环节4完成 - 接入 Kimi API

This commit is contained in:
之之 2026-03-06 10:52:34 +08:00
parent b91d081901
commit 9ef7cd04bd
2 changed files with 22 additions and 1 deletions

1
.env
View File

@ -3,3 +3,4 @@ DINGTALK_APP_SECRET=vJnmeF0B1yaYRv7u4IzdKsC6wPfStyUWEQnBdjas-NH5JUAKUwj7Dc659Bau
DINGTALK_ROBOT_CODE=dingzerc04si7jmyvasq
PORT=3000
KIMI_API_KEY=sk-A1STcZTjWTYOiG864MCt31VHHq8fD1r9E7LBDxoaMDDoGGbx

View File

@ -7,11 +7,31 @@ const app = express();
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
// 调用 Kimi API
async function callKimiAPI(content) {
const response = await fetch('https://api.moonshot.cn/v1/chat/completions', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${process.env.KIMI_API_KEY}`
},
body: JSON.stringify({
model: 'moonshot-v1-8k',
messages: [
{ role: 'system', content: '你是之之秋秋,光湖纪元的钉钉机器人助手。' },
{ role: 'user', content: content }
]
})
});
const data = await response.json();
return data.choices[0].message.content;
}
// AI 处理函数
async function processWithAI(content) {
// 这里接入 Kimi API
// 暂时返回测试回复
return `🤖 收到:"${content}"\n\n我是之之秋秋,正在开发中...`;
return await callKimiAPI(content);
}
// 验证签名