Skip to content

Commit

Permalink
[#6588] UserId not being passed to AzureDiagnostics (#6623)
Browse files Browse the repository at this point in the history
* Add userId property to Language Service

* Change unit test name
  • Loading branch information
sw-joelmut authored May 11, 2023
1 parent c09099a commit 11597ca
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ private async Task<QueryResults> QueryKbAsync(Activity messageActivity, QnAMaker
qnaId = options.QnAId,
rankerType = options.RankerType,
answerSpanRequest = new { enable = options.EnablePreciseAnswer },
includeUnstructuredSources = options.IncludeUnstructuredSources
includeUnstructuredSources = options.IncludeUnstructuredSources,
userId = messageActivity.From?.Id
}, Formatting.None,
_settings);
var httpRequestHelper = new HttpRequestUtils(_httpClient);
Expand Down
48 changes: 44 additions & 4 deletions tests/Microsoft.Bot.Builder.AI.QnA.Tests/LanguageServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ public AdaptiveDialog LanguageServiceAction_ActiveLearningDialogBase()
var mockHttp = new MockHttpMessageHandler();
mockHttp.When(HttpMethod.Post, GetFeedbackUrl())
.Respond(HttpStatusCode.NoContent, "application/json", "{ }");
mockHttp.When(HttpMethod.Post, GetRequestUrl()).WithContent("{\"question\":\"Q12\",\"top\":3,\"filters\":{\"MetadataFilter\":{\"Metadata\":[],\"LogicalOperation\":\"AND\"},\"SourceFilter\":[],\"LogicalOperation\":null},\"confidenceScoreThreshold\":0.3,\"context\":{\"previousQnAId\":0,\"previousUserQuery\":\"\"},\"qnaId\":0,\"rankerType\":\"Default\",\"answerSpanRequest\":{\"enable\":true},\"includeUnstructuredSources\":true}")
mockHttp.When(HttpMethod.Post, GetRequestUrl()).WithContent("{\"question\":\"Q12\",\"top\":3,\"filters\":{\"MetadataFilter\":{\"Metadata\":[],\"LogicalOperation\":\"AND\"},\"SourceFilter\":[],\"LogicalOperation\":null},\"confidenceScoreThreshold\":0.3,\"context\":{\"previousQnAId\":0,\"previousUserQuery\":\"\"},\"qnaId\":0,\"rankerType\":\"Default\",\"answerSpanRequest\":{\"enable\":true},\"includeUnstructuredSources\":true,\"userId\":\"user1\"}")
.Respond("application/json", GetResponse("LanguageService_ReturnsAnswer_WhenNoAnswerFoundInKb.json"));
mockHttp.When(HttpMethod.Post, GetRequestUrl()).WithContent("{\"question\":\"Q11\",\"top\":3,\"filters\":{\"MetadataFilter\":{\"Metadata\":[],\"LogicalOperation\":\"AND\"},\"SourceFilter\":[],\"LogicalOperation\":null},\"confidenceScoreThreshold\":0.3,\"context\":{\"previousQnAId\":0,\"previousUserQuery\":\"\"},\"qnaId\":0,\"rankerType\":\"Default\",\"answerSpanRequest\":{\"enable\":true},\"includeUnstructuredSources\":true}")
mockHttp.When(HttpMethod.Post, GetRequestUrl()).WithContent("{\"question\":\"Q11\",\"top\":3,\"filters\":{\"MetadataFilter\":{\"Metadata\":[],\"LogicalOperation\":\"AND\"},\"SourceFilter\":[],\"LogicalOperation\":null},\"confidenceScoreThreshold\":0.3,\"context\":{\"previousQnAId\":0,\"previousUserQuery\":\"\"},\"qnaId\":0,\"rankerType\":\"Default\",\"answerSpanRequest\":{\"enable\":true},\"includeUnstructuredSources\":true,\"userId\":\"user1\"}")
.Respond("application/json", GetResponse("LanguageService_TopNAnswer.json"));
return CreateLanguageServiceActionDialog(mockHttp, false);
}
Expand Down Expand Up @@ -144,9 +144,9 @@ public AdaptiveDialog LanguageServiceAction_MultiTurnDialogBase()
{
var mockHttp = new MockHttpMessageHandler();

mockHttp.When(HttpMethod.Post, GetRequestUrl()).WithContent("{\"question\":\"I have issues related to KB\",\"top\":3,\"filters\":{\"MetadataFilter\":{\"Metadata\":[],\"LogicalOperation\":\"AND\"},\"SourceFilter\":[],\"LogicalOperation\":null},\"confidenceScoreThreshold\":0.3,\"context\":{\"previousQnAId\":0,\"previousUserQuery\":\"\"},\"qnaId\":0,\"rankerType\":\"Default\",\"answerSpanRequest\":{\"enable\":true},\"includeUnstructuredSources\":true}")
mockHttp.When(HttpMethod.Post, GetRequestUrl()).WithContent("{\"question\":\"I have issues related to KB\",\"top\":3,\"filters\":{\"MetadataFilter\":{\"Metadata\":[],\"LogicalOperation\":\"AND\"},\"SourceFilter\":[],\"LogicalOperation\":null},\"confidenceScoreThreshold\":0.3,\"context\":{\"previousQnAId\":0,\"previousUserQuery\":\"\"},\"qnaId\":0,\"rankerType\":\"Default\",\"answerSpanRequest\":{\"enable\":true},\"includeUnstructuredSources\":true,\"userId\":\"user1\"}")
.Respond("application/json", GetResponse("LanguageService_ReturnAnswer_withPrompts.json"));
mockHttp.When(HttpMethod.Post, GetRequestUrl()).WithContent("{\"question\":\"Accidently deleted KB\",\"top\":3,\"filters\":{\"MetadataFilter\":{\"Metadata\":[],\"LogicalOperation\":\"AND\"},\"SourceFilter\":[],\"LogicalOperation\":null},\"confidenceScoreThreshold\":0.3,\"context\":{\"previousQnAId\":27,\"previousUserQuery\":\"\"},\"qnaId\":1,\"rankerType\":\"Default\",\"answerSpanRequest\":{\"enable\":true},\"includeUnstructuredSources\":true}")
mockHttp.When(HttpMethod.Post, GetRequestUrl()).WithContent("{\"question\":\"Accidently deleted KB\",\"top\":3,\"filters\":{\"MetadataFilter\":{\"Metadata\":[],\"LogicalOperation\":\"AND\"},\"SourceFilter\":[],\"LogicalOperation\":null},\"confidenceScoreThreshold\":0.3,\"context\":{\"previousQnAId\":27,\"previousUserQuery\":\"\"},\"qnaId\":1,\"rankerType\":\"Default\",\"answerSpanRequest\":{\"enable\":true},\"includeUnstructuredSources\":true,\"userId\":\"user1\"}")
.Respond("application/json", GetResponse("LanguageService_ReturnAnswer_MultiTurnLevel1.json"));

return CreateLanguageServiceActionDialog(mockHttp, false);
Expand Down Expand Up @@ -1245,6 +1245,46 @@ public async Task LanguageService_ReturnsAnswerWithMetadataBoost()
Assert.StartsWith("Kiki", results[0].Answer);
}

/// <summary>
/// The LanguageService_ReturnsAnswer_WithNullUserId.
/// </summary>
/// <returns>The <see cref="Task"/>.</returns>
[Fact]
[Trait("TestCategory", "AI")]
[Trait("TestCategory", "LanguageService")]
public async Task LanguageService_ReturnsAnswer_WithNullUserId()
{
var mockHttp = new MockHttpMessageHandler();
mockHttp.When(HttpMethod.Post, GetRequestUrl())
.WithContent("{\"question\":\"how do I clean the stove?\",\"top\":1,\"filters\":{\"MetadataFilter\":{\"Metadata\":[],\"LogicalOperation\":\"AND\"},\"SourceFilter\":[],\"LogicalOperation\":null},\"confidenceScoreThreshold\":0.3,\"context\":null,\"qnaId\":0,\"rankerType\":\"Default\",\"answerSpanRequest\":{\"enable\":true},\"includeUnstructuredSources\":true,\"userId\":null}")
.Respond("application/json", GetResponse("LanguageService_ReturnsAnswer.json"));

var adapter = new TestAdapter(TestAdapter.CreateConversation(nameof(LanguageService_ReturnsAnswer_WithNullUserId)));
var activity = new Activity
{
Type = ActivityTypes.Message,
Text = "how do I clean the stove?",
Conversation = new ConversationAccount(),
Recipient = new ChannelAccount(),
};
var context = new TurnContext(adapter, activity);
var client = new HttpClient(mockHttp);

var endpoint = new QnAMakerEndpoint
{
KnowledgeBaseId = _projectName,
EndpointKey = _endpointKey,
Host = _endpoint,
QnAServiceType = ServiceType.Language
};

var qna = new CustomQuestionAnswering(endpoint, httpClient: client);
var results = await qna.GetAnswersAsync(context);

Assert.NotNull(results);
Assert.Single(results);
}

/// <summary>
/// The LanguageService_TestThresholdInQueryOption.
/// </summary>
Expand Down

0 comments on commit 11597ca

Please sign in to comment.