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

1

1

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.

Antihero answered 22/11, 2018 at 15:55 Comment(5)
What language are you using?Subtract
added info about Python SDKAntihero
There seems to be an issue with the SDK where only 3 documented variables are sent as part of the context github.com/watson-developer-cloud/python-sdk/issues/597. The developer is looking at the problem but I don't think it will get fixed before MondaySubtract
I tried context->skills->main skill->user_defined and it seems to workAntihero
@GermanAttanasio I updated my answer with complete cURL request and response for your reference - #53404749Philipson
A
2

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.

Antihero answered 23/11, 2018 at 7:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.