gpt4 book ai didi

botframework - `Feedback` 机器人对话中未显示文本

转载 作者:行者123 更新时间:2023-12-01 12:11:58 25 4
gpt4 key购买 nike

我的表单流对话框包含一个应用了自定义验证的字段...

 var form = builder
.Field(new FieldReflector<CarValuationDialog>(nameof(UserName))
.SetActive(state => string.IsNullOrEmpty(state.UserName)))
.Field(new FieldReflector<CarValuationDialog>(nameof(ValuationOption))
.SetPrompt(new PromptAttribute($"Hello {{UserName}}.<br /><br />Are you looking to get an price estimate for a car you’re selling, or for a car you’re looking to buy? {{||}}")))
.Field(new FieldReflector<CarValuationDialog>(nameof(RegistrationNumber))
.SetDefine(RegistrationNumberDefinitionMethod))
.Field(new FieldReflector<CarValuationDialog>(nameof(Mileage))
.SetValidate(async (state, value) =>
{
var result = new ValidateResult { IsValid = true, Value = value };

if (int.TryParse(value.ToString(), out int mileage))
{
result.IsValid = true;
}
else
{
result.Feedback = "That isn't valid number. Can you enter it again please?";
result.IsValid = false;
}

return await Task.FromResult(result);
}))
.Field(nameof(PreviousOwnerOption),
active: carValuationDialog => carValuationDialog.ValuationOption == ValuationOptions.LookingToSell)
.Field(nameof(ServiceHistoryOption),
active: carValuationDialog => carValuationDialog.ValuationOption == ValuationOptions.LookingToSell)
.Confirm(Confirmation)
.OnCompletion(GetValuationAndDisplaySummaryToUser);

SetValidate() 执行时,给定的里程值不是 intresult.Feedback = ... 行是执行。但是,没有看到消息“这不是有效的里程值。请再输入一次好吗?”我看到这个...

enter image description here

完全公开,我确实在对话框类中声明了以下属性

[Template(TemplateUsage.NotUnderstood, "抱歉,我不明白'{0}'。")]

但我认为在这种情况下会向用户显示 result.Feedback 文本?不使用 Template[] 会导致在用户输入无效里程时显示以下文本...

"d" is not a car mileage option.

这看起来很垃圾,这就是我使用 Template[] 覆盖的原因。

最佳答案

编辑我能够通过将模板应用于字段本身进行验证来实现这一点。这应该是您正在寻找的确切行为。请注意,我没有进行广泛的测试,我只是想让总体思路发挥作用。这是我使用的代码:

[Serializable]
public class SandwichOrder
{
//public PreviousOwnerOptions Options;
[Template(TemplateUsage.NotUnderstood, "Sorry, I don't understand '{0}'.")]
[Prompt("What is the {&}?")]
public int Mileage;

[Template(TemplateUsage.NotUnderstood, "Sorry, This is not valid '{0}'.")]
[Prompt("How many {&}?")]
public int Days;


public static IForm<SandwichOrder> BuildForm()
{
var form = new FormBuilder<SandwichOrder>()
.Field(new FieldReflector<SandwichOrder>(nameof(Mileage))
.SetValidate(async (state, value) =>
{
var result = new ValidateResult {IsValid = true, Value = value};

if (int.TryParse(value.ToString(), out int mileage))
{
result.IsValid = true;
}
else
{
result.IsValid = false;
}

return await Task.FromResult(result);
}))
.Field(new FieldReflector<SandwichOrder>(nameof(Days))
.SetValidate(async (state, value) =>
{
var result = new ValidateResult { IsValid = true, Value = value };

if (int.TryParse(value.ToString(), out int days))
{
result.IsValid = true;
}
else
{
result.IsValid = false;
}

return await Task.FromResult(result);
}));
return form.Build();
}
}

这产生了这个结果:

enter image description here

关于botframework - `Feedback` 机器人对话中未显示文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51136774/

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