public async Task QnaMaker_UserAgent() { var mockHttp = new MockHttpMessageHandler(); mockHttp.When(HttpMethod.Post, GetRequestUrl()) .Respond("application/json", GetResponse("QnaMaker_ReturnsAnswer.json")); var interceptHttp = new InterceptRequestHandler(mockHttp); var qna = GetQnAMaker(interceptHttp, new QnAMakerEndpoint { KnowledgeBaseId = _knowlegeBaseId, EndpointKey = _endpointKey, Host = _hostname }, new QnAMakerOptions { Top = 1 }); var results = await qna.GetAnswersAsync(GetContext("how do I clean the stove?")); Assert.IsNotNull(results); Assert.AreEqual(results.Length, 1, "should get one result"); StringAssert.StartsWith(results[0].Answer, "BaseCamp: You can use a damp rag to clean around the Power Pack"); // Verify that we added the bot.builder package details. Assert.IsTrue(interceptHttp.UserAgent.Contains("Microsoft.Bot.Builder.AI.QnA/4")); }
public async Task QnaMaker_ReturnsAnswerWithFiltering() { var mockHttp = new MockHttpMessageHandler(); mockHttp.When(HttpMethod.Post, GetRequestUrl()) .Respond("application/json", GetResponse("QnaMaker_UsesStrictFilters_ToReturnAnswer.json")); var interceptHttp = new InterceptRequestHandler(mockHttp); var qna = GetQnAMaker(interceptHttp, new QnAMakerEndpoint { KnowledgeBaseId = _knowlegeBaseId, EndpointKey = _endpointKey, Host = _hostname }); var options = new QnAMakerOptions { StrictFilters = new Metadata[] { new Metadata() { Name = "topic", Value = "value" } }, Top = 1 }; var results = await qna.GetAnswersAsync(GetContext("how do I clean the stove?"), options); Assert.IsNotNull(results); Assert.AreEqual(results.Length, 1, "should get one result"); StringAssert.StartsWith(results[0].Answer, "BaseCamp: You can use a damp rag to clean around the Power Pack"); Assert.AreEqual("topic", results[0].Metadata[0].Name); Assert.AreEqual("value", results[0].Metadata[0].Value); // verify we are actually passing on the options var obj = JObject.Parse(interceptHttp.Content); Assert.AreEqual(1, obj["top"].Value <int>()); Assert.AreEqual("topic", obj["strictFilters"][0]["name"].Value <string>()); Assert.AreEqual("value", obj["strictFilters"][0]["value"].Value <string>()); }
public async Task QnaMaker_TestThresholdInQueryOption() { var mockHttp = new MockHttpMessageHandler(); mockHttp.When(HttpMethod.Post, GetRequestUrl()) .Respond("application/json", GetResponse("QnaMaker_ReturnsAnswer_GivenScoreThresholdQueryOption.json")); var interceptHttp = new InterceptRequestHandler(mockHttp); var qna = GetQnAMaker( interceptHttp, new QnAMakerEndpoint() { KnowledgeBaseId = _knowlegeBaseId, EndpointKey = _endpointKey, Host = _hostname }); var queryOptionsWithScoreThreshold = new QnAMakerOptions() { ScoreThreshold = 0.5F, Top = 2 }; var result = await qna.GetAnswersAsync( GetContext("What happens when you hug a porcupine?"), queryOptionsWithScoreThreshold ); Assert.IsNotNull(result); var obj = JObject.Parse(interceptHttp.Content); Assert.AreEqual(2, obj["top"].Value <int>()); Assert.AreEqual(0.5F, obj["scoreThreshold"].Value <float>()); }
public async Task QnaMaker_ReturnsAnswerWithMetadataBoost() { var mockHttp = new MockHttpMessageHandler(); mockHttp.When(HttpMethod.Post, GetRequestUrl()) .Respond("application/json", GetResponse("QnaMaker_ReturnsAnswersWithMetadataBoost.json")); var interceptHttp = new InterceptRequestHandler(mockHttp); var qna = GetQnAMaker( interceptHttp, new QnAMakerEndpoint { KnowledgeBaseId = _knowlegeBaseId, EndpointKey = _endpointKey, Host = _hostname }); var options = new QnAMakerOptions { MetadataBoost = new Metadata[] { new Metadata() { Name = "artist", Value = "drake" } }, Top = 1 }; var results = await qna.GetAnswersAsync(GetContext("who loves me?"), options); Assert.IsNotNull(results); Assert.AreEqual(results.Length, 1, "should get one result"); StringAssert.StartsWith(results[0].Answer, "Kiki"); }