我强烈建议您使用 Microsoft LUIS 之类的语言理解服务工具(它是 Microsoft 认知服务的一部分)构建更多的助手,而不是简单的机器人。
然后,您可以将此自然语言处理工具与上述 Microsoft Botframework 等机器人 SDK 结合使用,以便您可以轻松地以自然语言运行查询,在 entities 和 intents 的对话框中解析响应,以及以自然语言提供回复。
例如,解析后的对话响应将具有类似 json 的内容
{
"intent": "MusicIntent",
"score": 0.0006564476,
"actions": [
{
"triggered": false,
"name": "MusicIntent",
"parameters": [
{
"name": "ArtistName",
"required": false,
"value": [
{
"entity": "queen",
"type": "ArtistName",
"score": 0.9402311
}
]
}
]
}
]
}
你可以看到这个MusicIntent有一个queen类型的实体ArtistName已经被语言理解系统识别了。
也就是用BotFramework就好办
var artistName=BotBuilder.EntityRecognizer.findEntity(args.entities, Entity.Type.ArtistName);
一个好的现代机器人助手框架应该至少支持一个multi-turn dialog mode,它是一个对话,两方之间存在交互,比如
>User:Which artist plays Stand By Me?
(intents=SongIntent, songEntity=`Stand By Me`)
>Assistant:The song `Stand by Me` was played by several artists. Do you mean the first recording?
>User:Yes, that one!
(intents=YesIntent)
>Assistant: The first recording was by `Ben E. King` in 1962. Do you want to play it?
>(User)Which is the first album composed by Ben E.King?
(intents=MusicIntent, entity:ArtistName)
>(Assistant) The first album by Ben E.King was "Double Decker" in 1960.
>(User) Thank you!
(intents=Thankyou)
>(Assistant)
You are welcome!
一些机器人框架使用WaterFall model 来处理这种语言模型交互:
self.dialog.on(Intent.Type.MusicIntent,
[
// Waterfall step 1
function (session, args, next)
{
// prompts something to the user...
BotBuilder.Prompts.text(session, msg);
},
// waterfall step 2
function (session, args, next)
{
// get the response
var response=args.response;
// do something...
next();//trigger next interaction
},
// waterfall step 3 (last)
function (session, args)
{
}
]);
其他需要考虑的特性是:
- 支持多语言和自动翻译;
- 第三方服务集成(Slack、Messenger、Telegram、Skype 等);
- 富媒体(图像、音频、视频播放等);
- 安全性(密码学);
- 跨平台 SDK;