gpt4 book ai didi

c# - PromptDialog 用于未确定数量的问题

转载 作者:太空狗 更新时间:2023-10-30 01:15:35 25 4
gpt4 key购买 nike

我正在尝试编写一个允许用户创建请求的机器人(例如。我想买一件 T 恤或我想修理我的电脑)。根据他们选择的请求,他们将被问及与该请求相关的一系列问题;这些问题与他们选择的请求直接相关。目前我正在尝试遍历这个问题列表并使用 PromptDialog.Text 方法来获得答案。但是,这只询问列表中的最后一个问题,当给出答案时,我收到一条错误信息,invalid need: expected Wait, have Done 作为消息。

private async Task ListOfferings(IDialogContext context, IAwaitable<string>  result)
{
string name = await result;
var offerings = Offerings.Where((x) =>
CultureInfo.CurrentCulture.CompareInfo.IndexOf(x.Name, name,
CompareOptions.IgnoreCase) >= 0
);
if (offerings.Count() != 0)
{
PromptDialog.Choice(context, CreateOffering, offerings, "Which of these would you like?");
}
else
{
await context.PostAsync(string.Format("Could not find an offering with name {0}", name));
context.Wait(MessageReceived);
}
}


private async Task CreateOffering(IDialogContext context, IAwaitable<Offering> result)
{
var offering = result.GetAwaiter().GetResult();
await context.PostAsync(string.Format("***CREATING {0}***", offering.Name.ToUpper()));

foreach (var question in offering.Questions)
{
PromptDialog.Text(context, null, question.Question);
}
}

是否有可能做这样的事情,我想动态决定用户将在运行时被问到的问题,或者我是否需要采取更静态的脚本方法?

最佳答案

您不能在循环中多次调用 PromptDialog.Text,因为您必须在每个问题后等待用户回复。尝试这样做:

private int questionNumber;
private Offering offering;

private async Task CreateOffering(IDialogContext context, IAwaitable<Offering> result)
{
offering = await result;
await context.PostAsync($"***CREATING {offering.Name.ToUpper()}***");
questionNumber = 0;
// fix access to a particular question in case Questions is not an IList
PromptDialog.Text(context, OnQuestionReply, offering.Questions[questionNumber].Question);
}

private async Task OnQuestionReply(IDialogContext context, IAwaitable<string> result)
{
var answer = await result;
// handle the answer for questionNumber as you need

questionNumber++;
// use Count instead of Length in case it is not an array
if (questionNumber < offering.Questions.Length)
{
PromptDialog.Text(context, OnQuestionReply, offering.Questions[questionNumber].Question);
}
else
{
// do what you need when all the questions are answered
await context.PostAsync("I have no more questions for this offering.");
context.Wait(MessageReceived);
}
}

关于c# - PromptDialog 用于未确定数量的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37700076/

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