最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

ibm watson - IBM WatsonX Assistant - Accessing Context in Actions - python Slack bot - Stack Overflow

programmeradmin10浏览0评论

I am building a slack bot with an IBM Watson X Assistant. I am sending some details to IBM Watson in the context in my python code, and I am wondering how I access these values in the "Actions" section of the watsonx assistant. I have this working currently in the dialog section of watson, but I am trying to move to using just actions.

Please see code snippet below of the section of my code which sends the message from my slack bot to the assistant. The commented out section is the old code that works in the dialog version of this journey. And the new uncommented code is me trying to do similar in an action instead. I was referring to this document for the structure of this context:

I have also attached a screenshot below of the 2 watson assistants, the left being the actions only one, and the right being the one that uses dialog too. Is there another way I should be pulling these variables from the context to set in my action?

Is what I am trying to do possible? Am I doing something wrong? Or are actions more limited when it comes to this?

Thanks, Claire

watsonx action vs dialog

Here is the code snippet which I have tried:

##################################################################################
    # Message
    ##################################################################################
    response = assistant.message_stateless(
        assistant_id=ibmAssistantID,
        user_id=user_id_generated,
        # 
        input={
            'message_type': 'text',
            'text': sanitized_text,
            'options': {
                'return_context': True
            }
        },
        context={
            "skills": {
                "action skill": {  # Use "action skill" instead of "main skill"
                    "skill_variables": {
                        "slackEmailAddress": user_email,
                        "slackUserId": slack_userid,
                        "currentTimeStamp": thread_ts,
                        "slackWorkspaceEnv": slack_workspace_env
                    }
                }
            },
        # context={
        #     'skills': {
        #         'main skill': {
        #             'user_defined': {
        #                 'slackEmailAddress': user_email,
        #                 'currentTimeStamp': thread_ts,
        #                 'slackUserId': slack_userid,
        #                 'slackWorkspaceEnv': slack_workspace_env,
        #                 'cleanup_session': False  # Set a default value to 'False'
        #             }
        #         }
        #     },
            **user_context.get(user_id_generated, {})
        }
    ).get_result()
发布评论

评论列表(0)

  1. 暂无评论