C# LUIS Chatbot 从 LuisResult 中提取所有意图

标签 c# json bots botframework azure-language-understanding

我有一个与 LUIS 连接的聊天机器人,我知道虽然对话只会进入具有最高匹配意图的对话,但我仍然想显示其余意图的分数,有没有办法要做到这一点? 我已经有了

[LuisModel("XXXX", "XXXX", Verbose = true)]

到目前为止,这是我正在使用的:

    [LuisIntent("")]
    [LuisIntent("None")]
    public async Task None(IDialogContext context, LuisResult result)
    {

        string allIntents = "";



        //Loop throught all intents found in JSON
        foreach (var foundIntent in result.Intents)
        {
            allIntents += ("Intent: " + foundIntent.Intent + "\n\n" + "Score: " + foundIntent.Score + "\n\n");
        }
        await context.PostAsync(allIntents);
        context.Wait(this.MessageReceived);
    }

我的 JSON 是这样的

{
  "query": "hey there",
  "topScoringIntent": {
  "intent": "None",
  "score": 0.17292054
  },
  "intents": [
    {
      "intent": "None",
      "score": 0.17292054
    },
    {
      "intent": "intentSearch",
      "score": 0.122199811
    },
    {
      "intent": "fromIntent",
      "score": 0.0327471271
    },
    {
      "intent": "goWithIntent",
      "score": 0.010828237
    }
  ],
  "entities": []
}

但是我的机器人只会返回无意图及其分数。有没有办法返回对话框中的所有意图?

编辑:答案在某种程度上对新项目有效,我不知道为什么

最佳答案

您必须像这样在您的 LuisModelAttribute 中将详细标志设置为 true:

[LuisModel("e7a9c2d5-0b92-47d3-9d73-xxxxxxxxxxxx",
"4941fa348c49494db1e8e8xxxxxxxxxx", Verbose = true)]

这是获取所有意图的代码,您可以从中获取分数

    [LuisIntent("greeting")]
    public async Task Greeting(IDialogContext context, LuisResult result)
    {
        string allIntents = "";
        //Loop throught all intents found in JSON
        foreach (var foundIntent in result.Intents)
        {
            allIntents += ("Intent: " + foundIntent.Intent + "\n\n" + "Score: " + foundIntent.Score + "\n\n");
        }
        await context.PostAsync(allIntents);

        context.Wait(this.MessageReceived);
    }

使用这段代码我得到了这个结果: enter image description here

关于C# LUIS Chatbot 从 LuisResult 中提取所有意图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47684559/

相关文章:

javascript - 使用 Javascript/JQUery 解析 JSON 文件

javascript - 获取 Telegram 群的所有用户

python - Python编写的IRC机器人——加入 channel 功能

php - 如何使用 line bot webhook 请求在线路组中使用 @mention/@tag 标记用户

c# - 是否可以使用非特殊文件夹作为 FolderBrowserDialog 的根文件夹?

c# - 定义用于执行程序的工作目录 (C#)

c# - 一对扑克牌的 GetHashCode C#

c# - SharpSVN 使用 'SvnLookClient' 获取提交后 Hook

json - Serde JSON反序列化枚举

json - NSJSONSerialization.JSONObjectWithData 泄漏内存