Watson Assistant API V2会“自动管理上下文". - 更多细节? [英] Watson Assistant API V2 "manages the context automatically" - more details?

查看:62
本文介绍了Watson Assistant API V2会“自动管理上下文". - 更多细节?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是有关Watson Assistant API V1/V2差异的问题. 文档像这样说:

请注意,如果您的应用程序使用v1 API,它将直接与对话技巧进行通信,而绕过了助手的编排和状态管理功能.这意味着您的应用程序负责维护状态信息.这是使用上下文完成的,该上下文是在应用程序和Watson Assistant服务之间来回传递的对象.您的应用程序必须维护上下文,方法是保存每个响应收到的上下文,并随每个新消息请求将其发送回服务. 使用v2 API的应用程序还可以使用上下文来访问和存储持久性信息,但是该上下文由助手自动维护(基于每个会话).

似乎在V2中,上下文由助手自动自动维护".这到底是什么意思?如果我想将一些数据传递给对话框流,则可以在"/message"上使用上下文.是否允许在V2中使用?(是的,似乎.)然后在V1天内,我必须从响应中接收上下文,并在每次请求时将其发送回去.助手还会在V2中发回上下文吗?我的客户端应用程序在V2中应该做什么?任何详细信息都欢迎..谢谢.

解决方案

首先回答您的第二个问题-如果检查Watson Assistant V2的API文档

在客户端,您可以使用此代码

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"
                        }
                    }
                }
            }
        }

参考链接

检查 API方法摘要了解到目前为止V2支持的功能.

在V2中有一个称为Session的新概念.会话用于向技能发送用户输入并接收响应.它还会自动为您维护会话的状态,即上下文".

V2 API(截至今天) 支持运行时方法,这些方法使客户端应用程序可以与(但不能修改)现有助手或技能进行交互.您可以使用这些方法来开发可部署用于生产用途的面向用户的客户端,用于代理助手和另一项服务(例如,聊天服务或后端系统)之间的通信的应用程序或测试应用程序. /p>

适用于我的完整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"

对于会话ID,请运行以下命令

curl -u "apikey:<API_KEY>" -X POST "https://gateway.watsonplatform.net/assistant/api/v2/assistants/{ASSISTANT_ID}/sessions?version=2018-11-08"

响应包括用户定义的技能背景

{"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"}}}}}

This is a question about Watson Assistant API V1/V2 difference. The doc says like this:

Note that if your app uses the v1 API, it communicates directly with the dialog skill, bypassing the orchestration and state-management capabilities of the assistant. This means that your application is responsible for maintaining state information. This is done using the context, an object that is passed back and forth between your application and the Watson Assistant service. Your application must maintain the context by saving the context received with each response and sending it back to the service with each new message request. An application using the v2 API can also use the context to access and store persistent information, but the context is maintained automatically (on a per-session basis) by the assistant.

It seems that in V2, "the context is maintained automatically by the assistant". What does this mean exactly ? If I'd like to pass some data to the dialog flow, I might use context on "/message". Is is allowed in V2?( yes, it seems.) Then in V1 days, I have to receive context from responses and send it back on every request. Does assistant also send the context back in V2? What should my client-app do in V2? Any detailed info is welcomed ..Thanks.

解决方案

Answering your second question first - If you check the API docs for Watson Assistant V2 here, there is a MessageContext object in the response with Global Context and skill specific context values.

You also have a sample Request where you can manually pass the context (both global and user-defined)

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"

From the client side, you can use this code

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"
                        }
                    }
                }
            }
        }

Reference link

Check the API Methods Summary to understand what is supported in V2 as of today.

There is a new concept in V2 called Session. A session is used to send user input to a skill and receive responses. It also maintains the state of the conversation which is Context automatically for you.

V2 API as of today supports Runtime Methods, methods that enable a client application to interact with (but not modify) an existing assistant or skill. You can use these methods to develop a user-facing client that can be deployed for production use, an application that brokers communication between an assistant and another service (such as a chat service or back-end system), or a testing application.

The complete cURL example that works for me

    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"

for session ID, run this command

curl -u "apikey:<API_KEY>" -X POST "https://gateway.watsonplatform.net/assistant/api/v2/assistants/{ASSISTANT_ID}/sessions?version=2018-11-08"

The response includes user_defined skill context

{"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"}}}}}

这篇关于Watson Assistant API V2会“自动管理上下文". - 更多细节?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆