ish*_*330 6 watson-conversation ibm-cloud
这是有关Watson Assistant API V1 / V2差异的问题。该文档是这样说的:
请注意,如果您的应用程序使用v1 API,则它会直接与对话技巧通信,从而绕过了助手的编排和状态管理功能。这意味着您的应用程序负责维护状态信息。这是使用上下文完成的,上下文是在应用程序和Watson Assistant服务之间来回传递的对象。您的应用程序必须维护上下文,方法是保存每个响应收到的上下文,并随每个新消息请求将其发送回服务。使用v2 API的应用程序也可以使用上下文访问和存储持久性信息,但是助手会自动(在每个会话的基础上)维护上下文。
似乎在V2中,“上下文由助手自动维护 ”。这到底是什么意思?如果我想将一些数据传递到对话框流,则可以在“ / message”上使用上下文。是否允许在V2中使用?(是的,似乎。)然后在V1天内,我必须从响应中接收上下文,并在每次请求时将其发送回去。助手还会在V2中发回上下文吗?我的客户端应用在V2中应该做什么?任何详细信息都欢迎..谢谢。
首先回答您的第二个问题 - 如果您在此处检查 Watson Assistant V2 的 API 文档,响应中会有一个 MessageContext 对象,其中包含全局上下文和技能特定的上下文值。
您还有一个示例请求,您可以在其中手动传递上下文(全局和用户定义的)
curl -u "apikey:{apikey}" -X POST -H "Content-Type:application/json" -d "{\"input\": {\"text\": \"Hello\"}, \"context\": {\"global\": {\"system\": {\"user_id\": \"my_user_id\"}}}}" "https://gateway.watsonplatform.net/conversation/api/v2/assistants/{assistant_id}/sessions/{session_id}/message?version=2018-11-08"
Run Code Online (Sandbox Code Playgroud)
从客户端,您可以使用此代码
service.message({
assistant_id: '{assistant_id}',
session_id: '{session_id}',
input: {
'message_type': 'text',
'text': 'Hello'
},
context: {
'global': {
'system': {
'user_id': 'my_user_id'
}
},
"skills": {
"main skill": {
"user_defined": {
"my_result_variable": "result_value"
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
参考链接
检查API 方法摘要以了解 V2 迄今为止支持的内容。
V2 中有一个新概念,称为 Session。会话用于将用户输入发送到技能并接收响应。它还会自动为您维护对话的状态,即上下文。
截至目前, V2 API支持运行时方法,这些方法使客户端应用程序能够与现有助手或技能交互(但不能修改)。您可以使用这些方法来开发可部署用于生产用途的面向用户的客户端、代理助手与其他服务(例如聊天服务或后端系统)之间通信的应用程序或测试应用程序。
对我有用的完整 cURL 示例
curl -u "apikey:<API_KEY>" -X POST -H "Content-Type:application/json" -d "{
\"input\": {
\"text\": \"What's the time?\",
\"options\": {
\"alternate_intents\": true,
\"debug\": true,\"return_context\": true
}
},
\"context\": {
\"global\": {
\"system\": {
\"user_id\": \"derp\",\"turn_count\":1
}
}
},
\"skills\": {
\"main_skill\":{\"user_defined\": {
\"chosen_service\": \"dental\"
}}
}
}" "https://gateway.watsonplatform.net/assistant/api/v2/assistants/{ASSISTANT_ID}/sessions/{SESSION_ID}/message?version=2018-11-08"
Run Code Online (Sandbox Code Playgroud)
对于会话 ID,运行此命令
curl -u "apikey:<API_KEY>" -X POST "https://gateway.watsonplatform.net/assistant/api/v2/assistants/{ASSISTANT_ID}/sessions?version=2018-11-08"
Run Code Online (Sandbox Code Playgroud)
响应包括用户定义的技能上下文
{"output":{"generic":[{"response_type":"text","text":"Hey ! how are you today? Let me know if you need any help or get stuck looking for information."}],"debug":{"nodes_visited":[{"dialog_node":"node_6_1475611948267","title":null,"conditions":"conversation_start"}],"log_messages":[],"branch_exited":true,"branch_exited_reason":"completed"},"intents":[{"intent":"General_Greetings","confidence":0.32179955244064334},{"intent":"General_Jokes","confidence":0.296911633014679},{"intent":"goodbye","confidence":0.2852578103542328},{"intent":"General_Ending","confidence":0.2513303637504578},{"intent":"off_topic","confidence":0.24435781836509707},{"intent":"select_detail","confidence":0.24206179082393647},{"intent":"list_options","confidence":0.22829059958457948},{"intent":"still-here","confidence":0.22606439888477325},{"intent":"select_service","confidence":0.22488142400979996},{"intent":"General_Security_Assurance","confidence":0.2210852071642876}],"entities":[]},"context":{"global":{"system":{"turn_count":1,"user_id":"derp"}},"skills":{"main skill":{"user_defined":{"chosen_service":"dental"}}}}}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1360 次 |
| 最近记录: |