How to pass variables as context to IBM Cloud Watson Assistant with V2?

妖精的绣舞 提交于 2019-12-25 03:34:52

问题


I am trying to use the new API version V2 for 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. I am interested in sending information as part of client dialog actions.


回答1:


Based on testing the Python SDK and the API V2 using a tool, I came to the following conclusion. 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. However, in contrast to the V1 API I needed to place the key / value pairs "down below" in the user_defined part:

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.



来源:https://stackoverflow.com/questions/53434543/how-to-pass-variables-as-context-to-ibm-cloud-watson-assistant-with-v2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!