[英]How to pass variables as context to IBM Cloud Watson Assistant with V2?
I am trying to use the new API version V2 for IBM Cloud Watson Assistant . 我正在尝试将新的API版本V2用于IBM Cloud Watson Assistant 。 Instead of sending a message for a workspace I need to send a message to an assistant. 我不需要向工作空间发送消息,而是需要向助手发送消息。 The context structure has global and skill-related sections now. 上下文结构现在具有全局和与技能相关的部分。
How would my app pass in values as context variables? 我的应用程序如何将值作为上下文变量传递? Where in the structure would they need to be placed? 需要将它们放置在结构中的什么位置? I am using the Python SDK. 我正在使用Python SDK。 I am interested in sending information as part of client dialog actions . 我有兴趣在客户端对话操作中发送信息。
Based on testing the Python SDK and the API V2 using a tool , I came to the following conclusion. 基于使用工具测试Python SDK和API V2,我得出以下结论。 Context is provided by the assistant if it is requested as part of the input options . 如果请求将上下文作为输入选项的一部分,则由助手提供。
"context": {
"skills": {
"main skill": {
"user_defined": {
"topic": "some chatbot talk",
"skip_user_input": true
}
}
},
"global": {
"system": {
"turn_count": 2
}
}
}
To pass back values from my client / app to the assistant, I could use the context parameter. 要将值从客户端/应用程序传递回助手,我可以使用context参数。 However, in contrast to the V1 API I needed to place the key / value pairs "down below" in the user_defined part: 但是,与V1 API相比,我需要将键/值对“向下放置”在user_defined部分中:
context['skills']['main skill']['user_defined'].update({'mydateOUT':'2018-10-08'})
The above is a code snippet from this sample file for a client action. 上面是此示例文件中用于客户端操作的代码段。 With that placement of my context variables everything works and I can implement client actions using the API Version 2. 通过放置上下文变量,一切正常,我可以使用API版本2实施客户端操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.