对话流中的数据上下文在哪里 (API.ai)
Where is the data context in Dialog Flow (API.ai)
我一直在阅读有关 Dialog Flow 的内容,但有一件事我仍然不清楚。我会试着举个例子。
我想实现如下转换:
User: Hello Google, what are some interesting cities?
Bot: Hello there! Sydney, New York and Berlin are nice.
User: Could you tell more about the second city?
Bot: Sure. New York is amazing. In New York, you can ...
如您所见,我正在构建数据上下文。第一题过后应该记得我们回答的是Sydney, New York and Berlin
,这样才明白第二题中the second city
其实是什么意思
我们应该将此数据存储在 webhook 服务中还是存储在对话流的上下文中?如果我们必须将此类数据存储在 webhook 服务中,我们如何区分正在进行的不同对话?
将其存储在 Dialogflow 上下文中是一个理想的解决方案 - 这正是上下文的用途!您使用相同的术语来表达您的问题,这并非巧合。
从概念上讲,您可以使用如下设置来执行此操作:
User: What are some interesting cities?
Dialogflow sees no contexts and matches an Intent asking for cities.
Agent replies: Sydney, New York, and Berlin are nice.
Agent sets context "cities" with parameter "cities" -> "Sydney, New York, Berlin"
User: Tell me more about the second one?
Dialogflow has an Intent that expects an incoming context of "cities" with a text pattern like "Tell me more about the (number index) one?" It sends the request to that Intent along with the currently active contexts.
Agent get a parameter with the index and the context "cities". It looks up the parameter for it, turns the string into an array, and gets the city based on the index.
Agent replies: New York is a fun place to visit!
Agent sets context "city" with parameter "current" -> "New York"
User: Tell me more!
Dialogflow matches this phrase and that the "city" context is still active and sends it to an event that reports more.
Agent says: More awesome stuff about New York.
User: Tell me about that first city instead.
Dialogflow matches it against the same intent as before.
Agent says: Sydney is pretty cool.
Agent changes the "city" context so the parameter "current" -> "Sydney" and "previous" -> "New York".
您现在可以创建其他意图来处理 "Compare these two" 或 "tell me more about the other one" 等短语。
更新
此设置在 Dialogflow 擅长的方面(解析消息并确定对话的当前状态)和您的 webhook 擅长的方面(确定这些问题的最佳答案)之间取得了很好的平衡。
您可以可能会在 Dialogflow 中完成大部分工作,但它会很快变得非常非常混乱。您需要创建多个 Intent 来单独处理每个值的结果,这不会缩放。您还需要为每个城市创建一个上下文(因此您将有一个 "city_ny" 和 "city_sydney" 上下文),因为您只能匹配上下文的存在,而不是它可能的参数有。
使用 webhook(甚至是我们现在拥有的内置履行系统)可能会更好。
我一直在阅读有关 Dialog Flow 的内容,但有一件事我仍然不清楚。我会试着举个例子。
我想实现如下转换:
User: Hello Google, what are some interesting cities?
Bot: Hello there! Sydney, New York and Berlin are nice.
User: Could you tell more about the second city?
Bot: Sure. New York is amazing. In New York, you can ...
如您所见,我正在构建数据上下文。第一题过后应该记得我们回答的是Sydney, New York and Berlin
,这样才明白第二题中the second city
其实是什么意思
我们应该将此数据存储在 webhook 服务中还是存储在对话流的上下文中?如果我们必须将此类数据存储在 webhook 服务中,我们如何区分正在进行的不同对话?
将其存储在 Dialogflow 上下文中是一个理想的解决方案 - 这正是上下文的用途!您使用相同的术语来表达您的问题,这并非巧合。
从概念上讲,您可以使用如下设置来执行此操作:
User: What are some interesting cities?
Dialogflow sees no contexts and matches an Intent asking for cities.
Agent replies: Sydney, New York, and Berlin are nice.
Agent sets context "cities" with parameter "cities" -> "Sydney, New York, Berlin"
User: Tell me more about the second one?
Dialogflow has an Intent that expects an incoming context of "cities" with a text pattern like "Tell me more about the (number index) one?" It sends the request to that Intent along with the currently active contexts.
Agent get a parameter with the index and the context "cities". It looks up the parameter for it, turns the string into an array, and gets the city based on the index.
Agent replies: New York is a fun place to visit!
Agent sets context "city" with parameter "current" -> "New York"
User: Tell me more!
Dialogflow matches this phrase and that the "city" context is still active and sends it to an event that reports more.
Agent says: More awesome stuff about New York.
User: Tell me about that first city instead.
Dialogflow matches it against the same intent as before.
Agent says: Sydney is pretty cool.
Agent changes the "city" context so the parameter "current" -> "Sydney" and "previous" -> "New York".
您现在可以创建其他意图来处理 "Compare these two" 或 "tell me more about the other one" 等短语。
更新
此设置在 Dialogflow 擅长的方面(解析消息并确定对话的当前状态)和您的 webhook 擅长的方面(确定这些问题的最佳答案)之间取得了很好的平衡。
您可以可能会在 Dialogflow 中完成大部分工作,但它会很快变得非常非常混乱。您需要创建多个 Intent 来单独处理每个值的结果,这不会缩放。您还需要为每个城市创建一个上下文(因此您将有一个 "city_ny" 和 "city_sydney" 上下文),因为您只能匹配上下文的存在,而不是它可能的参数有。
使用 webhook(甚至是我们现在拥有的内置履行系统)可能会更好。