代码之家  ›  专栏  ›  技术社区  ›  juliano.net

记住前面的答案来指导对话

  •  0
  • juliano.net  · 技术社区  · 7 年前

    我正在使用LUIS模板创建一个聊天机器人,我有一个名为StartTest的意图,其中包含如下语句:

    Begin [TestNameEntity] on [GearEntity] and [RPMEntity]
    Begin [TestNameEntity] on [GearEntity]
    Begin [TestNameEntity]
    

    但是对于第二次和第三次的发言,我需要知道用户对第二次发言说了什么 [TestNameEntity] ,如下所示:

    User: Begin test 1 on second gear
    Bot: What RPM?
    User: 2500
    

    我怎样才能做到这一点?

    1 回复  |  直到 7 年前
        1
  •  1
  •   Ein2012    7 年前

    result.Entities[0].Type to get entity name
    

    所以你可以迭代 result.Entities

    //global variables
    public string CurrentGear { get; set; }
    public string CurrentRpm { get; set; }
    
    
    
    [LuisIntent("StartTest")]
    public async Task StartTestIntent(IDialogContext context, LuisResult result)
    {
         if (result.Entities != null && result.Entities.Count >0)
        {
            //sample you will get selected entity type 
             //var ent1=result.Entities[0].Type;
    
            var userValues=GetUserEntities(result);
            if(userValues["GearEntity"]==null)
                showGearPrompt(context);
            if(userValues["RPMEntity"]==null)
                showRpmPrompt(context);
        }
    }
    
    private string[] GetUserEntities(LuisResult result)
    {
        //your logic here
        //return list of entities;
    }
    
    private async Task showGearPrompt(IDialogContext context)
    {
         PromptDialog.Text(  
            context: context,  
            resume: OnGearOptionReceivedAsync,  
            prompt: "please enter Gear Value",  
            retry: "Sorry, I didn't understand that. Please try again."  
        );  
    
    }
    
     public virtual async Task OnGearOptionReceivedAsync(IDialogContext context, IAwaitable<string> gear)
    {
        string response = await gear;  
        CurrentGear = response; 
    }
    
    private async Task showRpmPrompt(IDialogContext context)
    {
        PromptDialog.Text(  
            context: context,  
            resume: OnRpmOptionReceivedAsync,  
            prompt: "please enter RPM Value",  
            retry: "Sorry, I didn't understand that. Please try again."  
        );  
    }
    
     public virtual async Task OnRpmOptionReceivedAsync(IDialogContext context, IAwaitable<string> rpm)
    {
        string response = await rpm;  
        CurrentRpm  = response; 
    }
    

    prompts