官术网_书友最值得收藏!

Context variables

Before we go further, we need to discuss context variables. Any robust conversational agent will benefit from context. Context enables memory between turns in the conversation and enables anaphora—reducing the awkward need to repeat words, especially nouns, used earlier in the exchange. Context is represented within the dialog as a set of developer-defined context variables, represented with the $ prefix, and passed between the application and the conversation service through a JSON structure.

Keep in mind that the Watson Assistant conversational API is statelessthat is, it doesn't maintain any memory of prior calls to the service, and therefore any state, such as context, must be passed back and forth between your application and the service. This will become more obvious when we show how your application can call the service API, later in this chapter. 

In the preceding example, the dialog node will check for the existence of the @Accounts entity in the user's utterance. If it finds it, the value of the @Accounts entity will be assigned to the $FromAccount context variable.

If that slot @Accounts entity is not found, the dialog node will prompt the user with the What account do you want to debit? question, all of which you will enter into the slot fields. Let's try it out.

Enter transfer funds in the Try it out tool:

Notice, that Watson recognized that the utterance is intended to mean #Funds-Transfer, and that it didn't find any @Accounts entities, so it prompted for it. You can now respond to that with savings. Watson realized that you are still responding to the #Funds-Transfer intent, and that you expressed an @Accounts entity of savings:

Now, if you press the Manage Context button at the top of the panel, you will see that the $FromAccount context variable was filled in. The $timezone context variable is always filled in automatically by Watson:

Now, we can return to editing the dialog node to create slots for the target account and amount to transfer:

The same entity type is sought to fill in the $FromAccount and $ToAccount context variables. Watson is smart enough to realize these should represent two different instances of the @Accounts entity.

We can finish out the node by instructing Watson to acknowledge the transfer by filling in the Then respond with: field of the node with something such as Thank you. We will transfer $$Amount from $FromAccount to $ToAccount:

We can then try it out in various ways, as follows:

You can fill in multiple slots with the same utterance.

While Watson remains quite robust with this simple example—able to understand your intent even when expressed in a variety of different ways—it's also not entirely infallible. For example, if you reverse the from and to accounts in your expression, as follows, Watson can get confused:

However, the Watson tooling is quite sophisticated. There are a variety of techniques that can be used to overcome this type of confusion. We won't go into the details at this time, but we do encourage you to explore the tooling and the wide range of educational materials posted on the Web to learn more.

主站蜘蛛池模板: 顺昌县| 同德县| 营山县| 高尔夫| 迁安市| 永安市| 涿州市| 大田县| 栾城县| 新化县| 左权县| 田林县| 宁强县| 大埔区| 阿巴嘎旗| 广昌县| 信阳市| 鹿泉市| 青阳县| 宜兴市| 武清区| 长泰县| 鸡泽县| 灌云县| 大连市| 肇东市| 武威市| 霍林郭勒市| 壶关县| 贵港市| 大余县| 灵寿县| 宁陵县| 乌苏市| 唐河县| 通河县| 大姚县| 涿鹿县| 平顺县| 石泉县| 鲁甸县|