gpt4 book ai didi

c# - 如何将参数从 Controller 传递到 FormDialog 状态模型

转载 作者:行者123 更新时间:2023-11-30 15:15:59 26 4
gpt4 key购买 nike

要求FormStateModel 已经包含用户键入的第一个输入。

代码只是我想将 activity.Text 中的字符串放在 FormStateModel 中:

private IDialog<FormStateModel> MakeRootDialog(string input)
{
return Chain.From(() => new FormDialog<FormStateModel>(
new FormStateModel() { Question = input },
ContactDetailsForm.BuildForm,
FormOptions.None));
}

=

public async Task<HttpResponseMessage> Post([FromBody] Activity activity)
{
if (activity.Type == ActivityTypes.Message)
{
await Conversation.SendAsync(
toBot: activity,
MakeRoot: () => this.MakeRootDialog(activity.Text));
}
else
{
await HandleSystemMessageAsync(activity);
}

var response = this.Request.CreateResponse(HttpStatusCode.OK);
return response;
}

在 ConversationUpdate 上,我只需询问“请输入您的问题:”即可开始对话

private static async Task<Activity> HandleSystemMessageAsync(Activity message)
{
switch (message.Type)
{
case ActivityTypes.DeleteUserData:
break;

case ActivityTypes.ConversationUpdate:
await Welcome(message);
break;
(...)

这样:

    private static async Task Welcome(Activity activity)
{
(...)
reply.Text = string.Format("Hello, how can we help you today? Please type your Question:");

await client.Conversations.ReplyToActivityAsync(reply);
(...)
}

但我找不到如何通过它的方法。在这种情况下会发生此异常:

anonymous method closures that capture the environment are not serializable, consider removing environment capture or using a reflection serialization surrogate: 

在这一步有什么办法可以填充状态模型吗?

最佳答案

通过在 MessagesController 中调用 RootDialog,然后通过 context.Call(form, (...)); 调用 new FormDialog 解决

  public async Task<HttpResponseMessage> Post([FromBody] Activity activity)
{
await Conversation.SendAsync(activity, () => new LayerDialog());
}

图层对话框:

   [Serializable]
public class LayerDialog: IDialog<IMessageActivity>
{
public async Task StartAsync(IDialogContext context)
{
context.Wait(this.OnMessageReceivedAsync);
}

private async Task OnMessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> result)
{
var awaited = await result;

FormStateModel model = new FormStateModel();
model.Value = awaited.Text;

var form = new FormDialog<FormStateModel >(model ,
BuildForm , FormOptions.PromptInStart);

context.Call(form , this.AfterResume);
}

关于c# - 如何将参数从 Controller 传递到 FormDialog 状态模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50989500/

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