/// <summary>
 /// Initializes a new instance of the <see cref="QnaServiceProvider"/> class.
 /// </summary>
 /// <param name="configurationStorageProvider">storage provider.</param>
 /// <param name="configuration">configuration.</param>
 /// <param name="qnaMakerClient">qna service client.</param>
 /// <param name="qnaMakerRuntimeClient">qna service runtime client.</param>
 public QnaServiceProvider(IConfigurationStorageProvider configurationStorageProvider, IConfiguration configuration, IQnAMakerClient qnaMakerClient, IQnAMakerRuntimeClient qnaMakerRuntimeClient)
 {
     this.configurationStorageProvider = configurationStorageProvider;
     this.qnaMakerClient        = qnaMakerClient;
     this.qnaMakerRuntimeClient = qnaMakerRuntimeClient;
     this.scoreThreshold        = Convert.ToDouble(configuration["ScoreThreshold"]);
 }
Example #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="QnaServiceProvider"/> class.
 /// </summary>
 /// <param name="configurationProvider">ConfigurationProvider fetch and store information in storage table.</param>
 /// <param name="optionsAccessor">A set of key/value application configuration properties.</param>
 /// <param name="qnaMakerClient">Qna service client.</param>
 /// <param name="qnaMakerRuntimeClient">Qna service runtime client.</param>
 public QnaServiceProvider(IConfigurationDataProvider configurationProvider, IOptionsMonitor <QnAMakerSettings> optionsAccessor, IQnAMakerClient qnaMakerClient, IQnAMakerRuntimeClient qnaMakerRuntimeClient)
 {
     this.configurationProvider = configurationProvider;
     this.qnaMakerClient        = qnaMakerClient;
     this.options = optionsAccessor.CurrentValue;
     this.qnaMakerRuntimeClient = qnaMakerRuntimeClient;
 }
        // </DownloadKB>

        // <GenerateAnswer>
        private static async Task GenerateAnswer(IQnAMakerRuntimeClient runtimeClient, string kbId)
        {
            var response = await runtimeClient.Runtime.GenerateAnswerAsync(kbId, new QueryDTO { Question = "How do I manage my knowledgebase?" });

            Console.WriteLine("Endpoint Response: {0}.", response.Answers[0].Answer);

            // Do something meaningful with answer
        }
Example #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="QnAService"/> class.
 /// </summary>
 /// <param name="appConfigRepository">Repository for app config data activity.</param>
 /// <param name="optionsAccessor">A set of key/value application configuration properties.</param>
 /// <param name="qnaMakerRuntimeClient">QnA service runtime client.</param>
 public QnAService(
     AppConfigRepository appConfigRepository,
     IOptionsMonitor <QnAMakerSettings> optionsAccessor,
     IQnAMakerRuntimeClient qnaMakerRuntimeClient)
 {
     this.appConfigRepository   = appConfigRepository ?? throw new ArgumentNullException(nameof(appConfigRepository));
     this.options               = optionsAccessor.CurrentValue ?? throw new ArgumentNullException(nameof(optionsAccessor.CurrentValue));
     this.qnaMakerRuntimeClient = qnaMakerRuntimeClient ?? throw new ArgumentNullException(nameof(qnaMakerRuntimeClient));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="QnAService"/> class.
 /// </summary>
 /// <param name="qnAClient">QnA Maker client.</param>
 /// <param name="qnARuntimeClient">QnA Maker runtime client.</param>
 /// <param name="settings">QnA Service settings.</param>
 /// <param name="logger">Logger.</param>
 public QnAService(
     IQnAMakerClient qnAClient,
     IQnAMakerRuntimeClient qnARuntimeClient,
     IQnAServiceSettings settings,
     ILogger <QnAService> logger)
 {
     this.qnAClient        = qnAClient ?? throw new ArgumentNullException(nameof(qnAClient));
     this.qnARuntimeClient = qnARuntimeClient ?? throw new ArgumentNullException(nameof(qnARuntimeClient));
     this.settings         = settings ?? throw new ArgumentNullException(nameof(settings));
     this.logger           = logger ?? throw new ArgumentNullException(nameof(logger));
 }
        /// <summary>
        /// get answer from kb for a given question.
        /// </summary>
        /// <param name="isTest">prod or test.</param>
        /// <param name="question">question text.</param>
        /// <param name="teamId">team id.</param>
        /// <returns>qnaSearchResult response.</returns>
        public async Task <QnASearchResultList> GenerateAnswerAsync(bool isTest, string question, string teamId)
        {
            var kb = await this.GetKbMappingAsync(teamId);

            this.qnaMakerRuntimeClient = new QnAMakerRuntimeClient(new EndpointKeyServiceClientCredentials(kb.EndpointKey))
            {
                RuntimeEndpoint = this.configuration["QnAMakerHostUrl"]
            };

            QnASearchResultList qnaSearchResult = await this.qnaMakerRuntimeClient.Runtime.GenerateAnswerAsync(kb?.KbId, new QueryDTO()
            {
                IsTest         = isTest,
                Question       = question,
                ScoreThreshold = double.Parse(this.configuration["ScoreThreshold"]),
                StrictFilters  = new List <MetadataDTO> {
                    new MetadataDTO()
                    {
                        Name = Constants.MetadataTeamId, Value = HttpUtility.UrlEncode(teamId)
                    }
                },
            });

            return(qnaSearchResult);
        }
Example #7
0
        private static async Task <String> GenerateAnswer(IQnAMakerRuntimeClient runtimeClient, string question)
        {
            var response = await runtimeClient.Runtime.GenerateAnswerAsync(kbId, new QueryDTO { Question = question });

            return(response.Answers[0].Answer);
        }