Dialog Flow(API.ai)中的数据上下文在哪里

时间:2017-12-01 11:01:32

标签: dialogflow

我一直在阅读关于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服务中还是存储在Dialog Flow中的上下文中?如果我们必须在webhook服务中存储这些数据,我们如何区分不同的正在进行的对话?

1 个答案:

答案 0 :(得分:5)

将它存储在Dialogflow环境中是一种理想的解决方案 - 这正是Contexts的用途!你用同一个词来表达你的问题,这不是巧合。

从概念上讲,您可以使用以下设置执行此操作:

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

您现在可以创建其他意图来处理像&#34这样的短语;比较这两个"或者"告诉我更多关于另一个"。

<强>更新

此设置在Dialogflow表现良好(解析消息并确定对话的当前状态)与您的webhook表现良好(确定这些问题的最佳答案)之间取得了良好的平衡。

可能可能会在Dialogflow中做很多事情,但它会很快变得非常混乱。您需要创建多个Intent来单独处理每个值的结果,这不会扩展。您还需要为每个城市创建一个上下文(因此您拥有&#34; city_ny&#34;以及&#34; city_sydney&#34;上下文),因为您只能匹配存在上下文,而不是它可能具有的参数。

使用webhook(甚至是我们现有的内置履行系统)可能会更好。