Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#6588] UserId not being passed to AzureDiagnostics #6623

Merged
merged 2 commits into from
May 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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