2016-11-14 72 views
5

我想用LUIS建立一個機器人,但它比我想象的要困難得多。 到目前爲止,我已經成功地創建我LUIS應用程序並創建一個意圖實體,我設計了幾個話語,似乎很好地工作。微軟Bot框架,LUIS和動作參數

然後我創建了我的機器人,並將它連接到路易斯。當我測試我的機器人時,它按預期工作。 現在,有趣的部分。我想處理參數。在路易斯我添加了一個動作我意圖

enter image description here

正如你可以看到我已經添加了一個提示。 我在我的機器人代碼目前看起來是這樣的:

/// <summary> 
/// Tries to find the category 
/// </summary> 
/// <param name="result">The Luis result</param> 
/// <param name="alarm"></param> 
/// <returns></returns> 
public string TryFindCategory(LuisResult result) 
{ 

    // Variable for the title 
    EntityRecommendation title; 

    // If we find our enenty, return it 
    if (result.TryFindEntity(PiiiCK.Category, out title)) 
     return title.Entity; 

    // Default fallback 
    return null; 
} 

[LuisIntent("Choose category")] 
public async Task ChooseCategory(IDialogContext context, LuisResult result) 
{ 

    // Get our category 
    var category = TryFindCategory(result); 
    var response = "The category you have chosen is not in the system just yet."; 

    switch (category) 
    { 
     case "camera": 
      response = $"You need help buying a { category }, is this correct?"; 
      this.started = true; 
      break; 
     default: 
      if (!string.IsNullOrEmpty(category)) response = $"Sorry, PiiiCK does not deal with { category.Pluralise() } just yet."; 
      break; 
    } 

    // Post our response back to the user 
    await context.PostAsync(response); 

    // Execute the message recieved delegate 
    context.Wait(MessageReceived); 
} 

我想你能猜出我與這是怎麼回事。如果用戶輸入幫我購買相機,它會得到選擇類別意圖和將有正確的實體選中。 但是,如果他們鍵入幫我買,它仍然會去正確的意圖,但它不會有一個選定的實體。我希望我的機器人能夠看到並使用我在LUIS中創建的提示中的文本,並且當用戶選擇他們的實體我希望它返回LUIS並使用該參數。

我不知道如何做到這一點,我找不到任何教程。 任何幫助將不勝感激(甚至鏈接!)

+0

您可以添加您的LUIS模型的圖像,以便我們瞭解您擁有的意圖/實體嗎?TryFindCategory在做什麼? –

+0

目前只有1個意圖(選擇類別)和1個實體(類別)。 TryFindCategory只是一個摘錄從https://github.com/Microsoft/BotBuilder/blob/master/CSharp/Samples/AlarmBot/Dialogs/AlarmLuisDialog.cs第60行,而不是布爾我只是返回實體或null。 – r3plica

回答

1

首先,你需要確保在你的話語包含類別,你被標記爲類別實體。這是通過選擇表示你的實體的單詞/單詞,然後在提交你的話語之前點擊實際類別來完成的。

Labeling utterances

這是獨立於您添加的動作參數。要檢查動作參數,您需要瀏覽實際的意圖。 IntentRecommendation具有Actions集合屬性;其中包含一個Parameters集合屬性。

Action parameters

的東西在這裏補充,是在develop分公司,BotFramework隊剛剛添加了對LUIS V2 API並增加了一些全新的capabilitites。

例如,現在如果您的意圖需要參數並且沒有提供這些參數,則LuisDialog將採取行動。在這種情況下(它似乎是你的),LuisDialog將automatically launch a LuisActionDialog並使用在action參數中定義的提示消息詢問用戶缺少的參數。

請注意,這還沒有作爲Nuget軟件包發佈。

+0

對您有幫助嗎? –