什么是大模型意图推理
其实很简单,当你和ESP-AI设备对话时,系统需要判断用户的意图,如果有意图,则执行相应代码。
在早期版本中,是通过正则匹配,这样虽然简单快速,但是准确率并不高,所以现在有了大模型推理。
简单来说就是用大模型来判断用户意图。
看看测试结果
下载插件
现在就来简单使用插件
npm i esp-ai-plugin-nlp-doubao --registry=https://registry.npmmirror.com
配置插件
分为3步
- 引入插件
- 配置插件
- 配置豆包大模型
首先先引入插件,这段代码放在服务端最开头位置
const nlp = require('esp-ai-plugin-nlp-doubao/index');
// 定义全局变量 globalText
global.globalText = "";
配置插件
这段代码放在gen_client_config: ()里
onIATcb: (arg) => {
global.globalText = arg.text;
arg.sendToClient();
},
配置豆包
注意,这里你只需要修改api_key,并且这里的api_key并不是开发者平台里的api_key!示例的值中用 & 符号进行分割,前半部分是豆包大模型的apikey,后半部分是豆包大模型的epId,一定注意,这极其重要!
intention: [
{
nlp_server: "http://localhost:3000/api/nlp",
key: ["开灯"],
api_key: "4ef198767-6e85-4d73-a462-e7f3576343b2&ep-20250122131540-dfb6f",
texts: ["开灯", global.globalText],
instruct: "test",
message: "好的,灯已打开,请查看"
}
]
这段代码放在gen_client_config: () 外面
// 启动服务器
const port = 3000;
nlp.listen(port, () => {
console.log(`Server is running on port ${port}`);
});
完整示例
const nlp = require('esp-ai-plugin-nlp-doubao/index');
// 定义全局变量 globalText
global.globalText = "";
const espAi = require("esp-ai");
const config = {
gen_client_config: () => ({
// 调用讯飞语音识别
iat_server: "xun_fei",
iat_config: {
appid: "8651a627",
apiSecret: "523e4adaa74bd51b9d9364a4559b4e05",
apiKey: "523e4adaa74bd51b9d9364a4559b4e05",
},
// 调用讯飞LLM
llm_server: "volcengine",
llm_config: {
apiKey: "523e4adaa74bd51b9d9364a4559b4e05",
epId : "ep-20240820185825-4zxj2"
},
tts_server: "volcengine",
tts_config: {
appid: "12345678",
accessToken: "523e4adaa74bd51b9d9364a4559b4e05",
voice_type: "zh_female_wanwanxiaohe_moon_bigtts",
},
llm_init_messages: [
{
role: 'system',
content: `
你是一名AI虚拟角色,扮演用户的虚拟女友
`
}
],
onIATcb: (arg) => {
global.globalText = arg.text;
arg.sendToClient();
},
intention: [
{
nlp_server: "http://localhost:3000/api/nlp",
key: ["开灯"],
api_key: "523e4adaa74bd51b9d9364a4559b4e05&ep-20250122131540-dfb6f",
texts: ["开灯", global.globalText],
instruct: "test",
message: "好的,灯已打开,请查看"
}
]
})
};
// 启动服务器
const port = 3000;
nlp.listen(port, () => {
console.log(`Server is running on port ${port}`);
});
const espAiIns = espAi(config);
没有回复内容