sillyGirl
sillyGirl copied to clipboard
能不能写一个调用天性机器人的脚本阿。让他更智能化,chatgpt受限制太多,下面是gpt3.5写的不能用
// [rule: 小二]
const { App } = require('silly-girl'); const axios = require('axios');
// 请将下面的YOUR_API_KEY替换为你自己的天行API密钥
async function getRobotResponse(question) {
try {
const response = await axios.get(https://api.tianapi.com/txapi/robot/index?key=3d0d558dd7ec47718faf0bfa97801bea&question=${encodeURIComponent(question)}
);
const data = response.data;
if (data.code === 200) {
return data.newslist[0].reply;
} else {
return '获取机器人回答失败';
}
} catch (error) {
console.error('获取机器人回答失败', error);
return '获取机器人回答失败';
}
}
App.command('机器人', async (user, say) => { const question = user.text.replace('机器人', '').trim(); if (question) { const robotResponse = await getRobotResponse(question); say(robotResponse); } else { say('你可以向我提问,我会尽力回答!'); } });
App.start();