Watson Assistant Easy Tool
Watson assistant
根据官方文档,已经提供了sdk, 自己的这个package只是使用 官方的sdk基础上,做了小小的封闭。代码托管在github上 watson
目前只有一个assitant package,提供方法来开始一个session并且发送message从而得到结果。
使用方法也比较简单,NewSession之后就可以发送消息了
package assistant
import "testing"
func TestAssistant(t *testing.T) {
// start a new session
bot := NewSession(&WAConfig{
ApiKey: "your key",
ApiUrl: "your url",
AssistantId: "your assistant id",
Version: "2020-04-01",
})
defer bot.Close()
// prepare a message
msg := "your message"
// send the message to watson assistant
output := bot.Send(msg)
t.Logf("%+v", output)
}
返回的结果也是和实际返回的一致
type Intent struct {
Intent string `json:"intent"`
Confidence float32 `json:"confidence"`
}
type Generic struct {
Type string `json:"response_type"`
Text string `json:"text"`
}
type WAOutput struct {
Generic []Generic `json:"generic"`
Intents []Intent `json:"intents"`
}
type WAResult struct {
Output WAOutput `json:"output"`
}
实际的一个例子
{"output":{"generic":[{"response_type":"text","text":"I didn't understand. You can try rephrasing."}],"intents":[{"intent":"taocan-88","confidence":0.33275983}]}}