Botframework 使用C将话语添加到LUIS应用程序#

Botframework 使用C将话语添加到LUIS应用程序#,botframework,chatbot,azure-language-understanding,Botframework,Chatbot,Azure Language Understanding,我正在尝试实现一个C#代码,它可以在我的luisapi中添加语句,如中所示 因此,我只对函数addutrancess()感兴趣,为了测试它,我将它放在函数ShowLuisResult()中,以确保每次向聊天机器人发送消息时都会使用它,但当我查看API时,我发现没有添加任何语句 我将文件utternces.json放在与BasicLuisDialog.cs相同的位置,并放在kudu控制台的/d/home中,以确保它能正常工作 代码如下: using System; using System.Con

我正在尝试实现一个
C#
代码,它可以在我的
luisapi
中添加语句,如中所示

因此,我只对函数
addutrancess()
感兴趣,为了测试它,我将它放在函数
ShowLuisResult()
中,以确保每次向聊天机器人发送消息时都会使用它,但当我查看API时,我发现没有添加任何语句

我将文件
utternces.json
放在与
BasicLuisDialog.cs
相同的位置,并放在
kudu
控制台的
/d/home
中,以确保它能正常工作

代码如下:

using System;
using System.Configuration;
using System.Threading.Tasks;

using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Builder.Luis;
using Microsoft.Bot.Builder.Luis.Models;

using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.IO;
using System.Net.Http;
using System.Xml.Linq;

namespace Microsoft.Bot.Sample.LuisBot
{
    // For more information about this template visit http://aka.ms/azurebots-csharp-luis
    [Serializable]
    public class BasicLuisDialog : LuisDialog<object>
    {

        // NOTE: Replace this example LUIS application ID with the ID of your LUIS application.
        static string appID = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";

        // NOTE: Replace this example LUIS application version number with the version number of your LUIS application.
        static string appVersion = "0.1";

        // NOTE: Replace this example LUIS authoring key with a valid key.
        static string authoringKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

        static string host = "https://westus.api.cognitive.microsoft.com";
        static string path = "/luis/api/v2.0/apps/" + appID + "/versions/" + appVersion + "/";


    public BasicLuisDialog() : base(new LuisService(new LuisModelAttribute(
        ConfigurationManager.AppSettings["LuisAppId"], 
        ConfigurationManager.AppSettings["LuisAPIKey"], 
        domain: ConfigurationManager.AppSettings["LuisAPIHostName"])))
    {
    }

    [LuisIntent("None")]
    public async Task NoneIntent(IDialogContext context, LuisResult result)
    {
        await this.ShowLuisResult(context, result);
    }

    // Go to https://luis.ai and create a new intent, then train/publish your luis app.
    // Finally replace "Greeting" with the name of your newly created intent in the following handler
    [LuisIntent("Greeting")]
    public async Task GreetingIntent(IDialogContext context, LuisResult result)
    {
        await this.ShowLuisResult(context, result);
    }

    [LuisIntent("Cancel")]
    public async Task CancelIntent(IDialogContext context, LuisResult result)
    {
        await this.ShowLuisResult(context, result);
    }

    [LuisIntent("Help")]
    public async Task HelpIntent(IDialogContext context, LuisResult result)
    {
        await this.ShowLuisResult(context, result);
    }

    private async Task ShowLuisResult(IDialogContext context, LuisResult result) 
    {
        AddUtterances("utterances.json");
        await context.PostAsync($"You have reached {result.Intents[0].Intent}. You said: {result.Query}");
        context.Wait(MessageReceived);
    }


    async static Task AddUtterances(string input_file)
    {
        string uri = host + path + "examples";
        string requestBody = File.ReadAllText(input_file);
        var response = await SendPost(uri, requestBody);
        var result = await response.Content.ReadAsStringAsync();
    }

    async static Task<HttpResponseMessage> SendPost(string uri, string requestBody)
    {
        using (var client = new HttpClient())
        using (var request = new HttpRequestMessage())
        {
            request.Method = HttpMethod.Post;
            request.RequestUri = new Uri(uri);
            request.Content = new StringContent(requestBody, Encoding.UTF8, "text/json");
            request.Headers.Add("Ocp-Apim-Subscription-Key", authoringKey);
            return await client.SendAsync(request);
        }
    }


}

无论出于什么原因,Luis的Botbuilder工具从Github中消失了,因为2周前它们还在这里-


我还不能发布图片,因此这里有一个图片链接

我还没有测试您的代码,但注意到您没有等待从ShowLuisResult中添加话语的调用:

private async Task ShowLuisResult(IDialogContext context, LuisResult result)
{
    AddUtterances("utterances.json"); //<-- NOTE: this line should be awaited
    await context.PostAsync($"You have reached {result.Intents[0].Intent}. You said: {result.Query}");
    context.Wait(MessageReceived);
}
private异步任务showsluisresult(IDialogContext上下文,LuisResult结果)
{

AddUtterants(“utterants.json”);//您确实为自己更改了应用程序id和创作密钥,对吗?您是如何做到的“我查看了API,发现没有添加任何语句…”?您能确认即使登录也没有更改吗?@DFBerry是的,我做了。很抱歉我没有提到它。@FerdinandFejskid没有更改。我使用您的链接登录API,并更改了“yourAppId”和“yourVersion”和我的一样,但我看不到意图上的差异,也没有添加任何话语。你知道更新话语的代码在机器人框架之外工作吗?也许只是在一个控制台应用程序中?
private async Task ShowLuisResult(IDialogContext context, LuisResult result)
{
    AddUtterances("utterances.json"); //<-- NOTE: this line should be awaited
    await context.PostAsync($"You have reached {result.Intents[0].Intent}. You said: {result.Query}");
    context.Wait(MessageReceived);
}