【问题标题】:Bot Framework C# Luis Getting > Exception: Response status code does not indicate success: 400 (Bad Request)Bot Framework C# Luis Getting > 异常:响应状态码不表示成功:400(错误请求)
【发布时间】:2018-09-12 06:21:12
【问题描述】:

我需要帮助将我的 Luis 应用程序集成到 C# Bot Framework Bot 中

当我将 Luis App 添加到我的 C# Microsoft Bot Framework 聊天机器人并在模拟器中运行时,我遇到了异常。

异常:响应状态码不表示成功:400(错误请求)。

Github 上另一位开发人员的调试帖子建议添加域,我必须将其添加到我的 LuisModel(见下文)。这并没有解决问题。

[LuisModel("", "", 域:“australiaeast.api.cognitive.microsoft.com”,Staging = true)]

单步执行代码,我的本地人在调用 new Dialog.RootLuisDialog() 时似乎是正确的这是屏幕截图

消息控制器代码片段

public async Task<HttpResponseMessage> Post([FromBody] Activity activity)
{
    // check if activity is of type message
    if (activity.Type == ActivityTypes.Message)
    {
        await Conversation.SendAsync(activity, () => new Dialogs.RootLuisDialog());
    }
    else
    {
        HandleSystemMessage(activity);
    }
    var response = Request.CreateResponse(HttpStatusCode.OK);
    return response;
}

Luis 对话框类

namespace HalChatBot.Dialogs
{
        [LuisModel("<MyLuisAppID>", "<MyLuisKey>", 
            domain: "australiaeast.api.cognitive.microsoft.com", Staging = true)]
        [Serializable]
        public class RootLuisDialog : LuisDialog<object>
        {
            [LuisIntent("")]
            [LuisIntent("None")]
            public async Task None(IDialogContext context, LuisResult result)
            {
                await context.PostAsync("I am the Default intent");
                context.Wait(MessageReceived);
            }

           [LuisIntent("Greeting")]
           public async Task Greeting(IDialogContext context, LuisResult result)
           {
                await context.PostAsync("I am the Greeting intent");
                context.Wait(MessageReceived);
           }
        }
}

【问题讨论】:

  • HTTP 错误 400 表示服务器告诉您它不喜欢您发送的内容(或不理解)。您可以使用 fiddler 之类的工具来检查它是否在 HTTP 响应正文中发送了其他信息,以便您修复代码。
  • 感谢@SimonMourier,Fiddler 显示模型未发布。请在到达端点之前发布您的模型。我已经发布了 Luis 应用程序,然后返回并重新发布。还有其他想法吗?
  • 如果它一直告诉你你的模型已经发布,不,除了检查你发布了正确的模型:-)

标签: c# botframework azure-language-understanding


【解决方案1】:
  1. 运行提琴手,加密 400(错误请求),其中声明 模型未发布。请在到达端点之前发布您的模型
  2. 重新发布 MyLuisApp
  3. 从 LuisModel [LuisModel("&lt;MyLuisAppID&gt;", "&lt;MyLuisKey&gt;", domain: "australiaeast.api.cognitive.microsoft.com")] 中删除了登台

现在 Luis 集成正在运行。

【讨论】:

  • 问题在于您指向的是暂存环境,而不是生产环境。第二步不是必需的,您只需要确保使用相同的环境即可。 (如果不是 Westus,您还指定了域,并且您的 API 密钥被定义到同一个域)
猜你喜欢
  • 2014-09-04
  • 1970-01-01
  • 2021-04-02
  • 2019-02-16
  • 2018-11-07
  • 2020-07-09
  • 2019-03-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多