第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用C#在一個Bot中進行多個QnA服務(wù)

使用C#在一個Bot中進行多個QnA服務(wù)

C#
溫溫醬 2021-05-12 17:14:18
我有3個QnA服務(wù)。我希望它們可以同時在單個BOT中使用。如何使用C#來實現(xiàn)。我最初的想法是將KB ID和Sub Key放入數(shù)組中(如何實現(xiàn)該數(shù)組或數(shù)組是否起作用?)。我在Node.JS中看到了一些代碼,但無法弄清楚如何在C#中轉(zhuǎn)換代碼。public class QnaDialog : QnAMakerDialog{    public QnaDialog() : base(        new QnAMakerService(new QnAMakerAttribute(ConfigurationManager.AppSettings["QnaSubscriptionKey1"],        ConfigurationManager.AppSettings["QnaKnowledgebaseId1"], "Hmm, I wasn't able to find an article about that. Can you try asking in a different way?", 0.5)),        new QnAMakerService(new QnAMakerAttribute(ConfigurationManager.AppSettings["QnaSubscriptionKey2"],        ConfigurationManager.AppSettings["QnaKnowledgebaseId2"], "Hmm, I wasn't able to find an article about that. Can you try asking in a different way?", 0.5)),        new QnAMakerService(new QnAMakerAttribute(ConfigurationManager.AppSettings["QnaSubscriptionKey3"],        ConfigurationManager.AppSettings["QnaKnowledgebaseId4"], "Hmm, I wasn't able to find an article about that. Can you try asking in a different way?", 0.5))        )    {    }}
查看完整描述

1 回答

?
慕桂英4014372

TA貢獻1871條經(jīng)驗 獲得超13個贊

QnAMaker通過在屬性中提供多種服務(wù),您可以在單個bot中使用多種知識庫。


使用QnAMakerDialogNuget包的基本實現(xiàn)BotBuilder.CognitiveServices是:


[Serializable]

[QnAMaker("QnaSubscriptionKey1", "QnaKnowledgebaseId1", "Hmm, I wasn't able to find an article about that. Can you try asking in a different way?", 0.50, 3)]

[QnAMaker("QnaSubscriptionKey2", "QnaKnowledgebaseId2", "Hmm, I wasn't able to find an article about that. Can you try asking in a different way?", 0.5, 3)]

[QnAMaker("QnaSubscriptionKey3", "QnaKnowledgebaseId3", "Hmm, I wasn't able to find an article about that. Can you try asking in a different way?", 0.5, 3)]

public class RootDialog : QnAMakerDialog

{

}

但是(是的,有一個“但是”)在某些情況下,您在處理消息時可能會遇到異常。正如QnAMakerDialog開源的一樣(您可以在此處找到源代碼),您可以輕松地發(fā)現(xiàn)問題出在服務(wù)調(diào)用返回的實現(xiàn)中MessageReceivedAsync:


var sendDefaultMessageAndWait = true;

qnaMakerResults = tasks.FirstOrDefault(x => x.Result.ServiceCfg != null)?.Result;

if (tasks.Count(x => x.Result.Answers?.Count > 0) > 0)

{

    var maxValue = tasks.Max(x => x.Result.Answers[0].Score);

    qnaMakerResults = tasks.First(x => x.Result.Answers[0].Score == maxValue).Result;


    if (qnaMakerResults != null && qnaMakerResults.Answers != null && qnaMakerResults.Answers.Count > 0)

    {

        if (this.IsConfidentAnswer(qnaMakerResults))

        {

            await this.RespondFromQnAMakerResultAsync(context, message, qnaMakerResults);

            await this.DefaultWaitNextMessageAsync(context, message, qnaMakerResults);

        }

        else

        {

            feedbackRecord = new FeedbackRecord { UserId = message.From.Id, UserQuestion = message.Text };

            await this.QnAFeedbackStepAsync(context, qnaMakerResults);

        }


        sendDefaultMessageAndWait = false;

    }

}


if (sendDefaultMessageAndWait)

{

    await context.PostAsync(qnaMakerResults.ServiceCfg.DefaultMessage);

    await this.DefaultWaitNextMessageAsync(context, message, qnaMakerResults);

}

在此代碼中,如果并非所有服務(wù)都對您的問題有答案(例如:如果您的QnAMaker KB至少有一個沒有對您的問題的回答),則此行代碼將中斷。


tasks.Max(x => x.Result.Answers[0].Score);

解決方法:例如,您可以通過獲取源代碼并修復(fù)如下方法來實現(xiàn)自己的QnAMakerDialog:


public async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> argument)

{

    var message = await argument;


    if (message != null && !string.IsNullOrEmpty(message.Text))

    {

        var tasks = this.services.Select(s => s.QueryServiceAsync(message.Text)).ToArray();

        await Task.WhenAll(tasks);


        if (tasks.Any())

        {

            var sendDefaultMessageAndWait = true;

            qnaMakerResults = tasks.FirstOrDefault(x => x.Result.ServiceCfg != null)?.Result;


            var qnaMakerFoundResults = tasks.Where(x => x.Result.Answers.Any()).ToList();

            if (qnaMakerFoundResults.Any())

            {

                var maxValue = qnaMakerFoundResults.Max(x => x.Result.Answers[0].Score);

                qnaMakerResults = qnaMakerFoundResults.First(x => x.Result.Answers[0].Score == maxValue).Result;


                if (qnaMakerResults?.Answers != null && qnaMakerResults.Answers.Count > 0)

                {

                    if (this.IsConfidentAnswer(qnaMakerResults))

                    {

                        await this.RespondFromQnAMakerResultAsync(context, message, qnaMakerResults);

                        await this.DefaultWaitNextMessageAsync(context, message, qnaMakerResults);

                    }

                    else

                    {

                        feedbackRecord = new FeedbackRecord { UserId = message.From.Id, UserQuestion = message.Text };

                        await this.QnAFeedbackStepAsync(context, qnaMakerResults);

                    }


                    sendDefaultMessageAndWait = false;

                }

            }


            if (sendDefaultMessageAndWait)

            {

                await context.PostAsync(qnaMakerResults.ServiceCfg.DefaultMessage);

                await this.DefaultWaitNextMessageAsync(context, message, qnaMakerResults);

            }

        }

    }

}


查看完整回答
反對 回復(fù) 2021-05-23
  • 1 回答
  • 0 關(guān)注
  • 133 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號