C# 在使用LUIS的对话框中,处理图像输入的正确流程是什么?

C# 在使用LUIS的对话框中,处理图像输入的正确流程是什么?,c#,botframework,azure-language-understanding,C#,Botframework,Azure Language Understanding,我正在用c编写一个机器人,它接受用户的图像输入和文本输入。我使用LUIS作为AI框架来确定对话模式中的意图。然而,这两种类型的输入似乎不能共存:路易斯和附件。我想知道这个场景是否有一个推荐的模式。请帮忙| 您可以过滤掉MessageController中包含附件的邮件 您可以使用检查附件 activity.Attachments == null 在MessageController中,您可以获取图像/附件值 activity.Attachments LuSudio将处理文本消息,

我正在用c编写一个机器人,它接受用户的图像输入和文本输入。我使用LUIS作为AI框架来确定对话模式中的意图。然而,这两种类型的输入似乎不能共存:路易斯和附件。我想知道这个场景是否有一个推荐的模式。请帮忙|

您可以过滤掉MessageController中包含附件的邮件

您可以使用检查附件

activity.Attachments == null

在MessageController中,您可以获取图像/附件值

activity.Attachments    

LuSudio将处理文本消息,除了文本之外,它将考虑所有其他事物作为空参数。但是,

Prompts.attachment方法将要求用户上传文件附件,如图像或视频。用户响应将作为IPrompAttachmentResult返回


是参考链接。

因此我找到了一个更好的模式,尽管它与Praveen的答案一致

在MessageController中,您希望检查附件活动。附件==null,但除此之外,您必须创建一个称为RootDialog的对话框,并将所有对话发送到该对话框,您可以从该对话框将对话转发到其他对话

在我的例子中,我将希望LUIS处理的消息转发给一个将LUIS作为服务继承的对话类。其他消息(如附件)将发送到另一个对话框类进行处理

获取附件并在对话框代码中处理它的另一种方法是使用PrompAttachment调用作为用户输入附件的捕捉器:

 var dialog = new PromptDialog.PromptAttachment(message.ToString(), "Sorry, I didn't get the receipt. Try again please.", 2);
        context.Call(dialog, AddImageToReceiptRecord);

干杯

您也可以在LUIS对话框中处理它

以下是使用PromptDialog的示例。附件:

[LuisIntent("SomeIntent")]
    public async Task SomeIntent(IDialogContext context, LuisResult result)
    {

        PromptDialog.Attachment(
               context: context,
               resume: ResumeAfterExpenseUpload,
               prompt: "I see you are trying to add an expense. Please upload a picture of your expense and I will try to perform character recognition (OCR) on it.",
               retry: "Sorry, I didn't understand that. Please try again."
           );
     }

    private async Task ResumeAfterExpenseUpload(IDialogContext context, IAwaitable<IEnumerable<Attachment>> result)
    {
        var attachment = await result as IEnumerable<Attachment>;
        var attachmentList = attachment.GetEnumerator();
        if (attachmentList.MoveNext())
        {
            //output link to the uploaded file
            await context.PostAsync(attachmentList.Current.ContentUrl); 

        }
        else
        {
            await context.PostAsync("Sorry, no attachments found!");
        }

    }

谢谢你的回答,普拉文!巧合的是,经过一些研究,我刚刚回答了同样的问题,我们得出了相似的结论。我唯一要添加的是RootDialogs的概念,您可以使用activity.Attachment属性筛选包含附件的邮件。
[LuisIntent("SomeIntent")]
    public async Task SomeIntent(IDialogContext context, LuisResult result)
    {

        PromptDialog.Attachment(
               context: context,
               resume: ResumeAfterExpenseUpload,
               prompt: "I see you are trying to add an expense. Please upload a picture of your expense and I will try to perform character recognition (OCR) on it.",
               retry: "Sorry, I didn't understand that. Please try again."
           );
     }

    private async Task ResumeAfterExpenseUpload(IDialogContext context, IAwaitable<IEnumerable<Attachment>> result)
    {
        var attachment = await result as IEnumerable<Attachment>;
        var attachmentList = attachment.GetEnumerator();
        if (attachmentList.MoveNext())
        {
            //output link to the uploaded file
            await context.PostAsync(attachmentList.Current.ContentUrl); 

        }
        else
        {
            await context.PostAsync("Sorry, no attachments found!");
        }

    }