我一直在阅读有关对话流的内容,但有一件事我仍然不清楚。我将尝试举一个例子。
我想实现如下转换:
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".
您现在可以创建其他意图来处理“比较这两个”或“告诉我有关另一个的更多信息”等短语。
Update
此设置在 Dialogflow 的优势(解析消息并确定对话的当前状态)和 Webhook 的优势(确定这些问题的最佳答案)之间取得了良好的平衡。
You could可能在 Dialogflow 中完成大部分工作,但它很快就会开始变得非常非常混乱。您需要创建多个 Intent 来单独处理每个值的结果,这无法扩展。您还需要为每个城市创建一个上下文(因此您将有一个“city_ny”和“city_sydney”上下文),因为您只能匹配上下文的存在,而不是它可能具有的参数。
使用 webhook(甚至是我们现在拥有的内置履行系统)可能会效果更好。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)