gpt4 book ai didi

c# - Microsoft Bot Framework 在本地工作,但在远程失败

转载 作者:太空宇宙 更新时间:2023-11-03 15:11:39 24 4
gpt4 key购买 nike

我有一个相当复杂的机器人,但它可以在本地运行。但一旦我发布它,它就会失败并出现错误:

Sorry, my bot code is having an issue.

我尝试使用 Application Insights,但它没有显示错误详细信息。错误总是发生在同一点:

/// <summary>
/// Start our response
/// </summary>
/// <param name="context">The current context</param>
/// <returns></returns>
public async Task StartAsync(IDialogContext context)
{

// Get our current step
_groups = await _groupProvider.ListAsync();
_group = _groups.First();

// Post the question header
await context.PostAsync(_group.Text);

// Wait for the users response
context.Wait(AskQuestion);
}

/// <summary>
/// When our message is recieved we execute this delegate
/// </summary>
/// <param name="context">The current context</param>
/// <param name="result">The result object</param>
/// <returns></returns>
private async Task AskQuestion(IDialogContext context, IAwaitable<IMessageActivity> result)
{

// Get our question and answers
var question = this._group.Questions[_currentQuestion];
var questionText = question.Text;
var answers = question.Answers.Select(m => m.Text).ToList();
var answerCount = question.Answers.Count;

// Create our options
var options = new PromptOptions<string>(questionText, options: answers);

// Ask our question
Choice<string>(context, GetAnswer, options);
}

/// <summary>
/// Get our answer and decide what to do next
/// </summary>
/// <param name="context">The current context</param>
/// <param name="result">The answer text</param>
/// <returns></returns>
private async Task GetAnswer(IDialogContext context, IAwaitable<string> result)
{

// Get our quest
var questions = _group.Questions;
var length = questions.Count;
var question = _group.Questions[_currentQuestion];
var selectedAnswer = await result;

// Assign our answer to our question
foreach (var answer in question.Answers)
if (answer.Text == selectedAnswer)
question.Answer = answer;

// If we have an answer, filter the products
if (question.Answer != null)
_productProvider.Score(await GetCurrentProducts(), _groups);

// Increase our index
_currentQuestion++;

// If our current index is greater or equal than the length of the questions
if (_currentQuestion == length)
{

// Create our dialog
var dialog = _dialogFactory.CreateSecondStepDialog(_dialogFactory, _groupProvider, _questionProvider, _productProvider, await GetCurrentProducts());

// Otherwise, got to the next step
await context.Forward(dialog, ResumeAfter, new Activity { }, CancellationToken.None);
return;
}

// Ask our next question
await AskQuestion(context, null);
}

因此,当此对话框启动时,它会将问题介绍发布给客户端。然后我调用 context.Wait 并提出问题。问题是一个选择。我相信这就是问题所在,因为它总是在问题出现时立即抛出该消息。

有人能从代码中发现任何明显的东西吗?

最佳答案

您引用的错误消息是在您的机器人抛出 500 时给出的。查看您的代码,我猜测您有一个 null ref 异常。在“//获取我们的问题和答案”下的部分中,尝试检查group.Questions是否不为空,以及_currentQuestion是否是该数组的有效索引。

关于c# - Microsoft Bot Framework 在本地工作,但在远程失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40977140/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com