Skip to content

Commit

Permalink
Add userId property to Language Service QnA (#4493)
Browse files Browse the repository at this point in the history
Co-authored-by: JhontSouth <[email protected]>
  • Loading branch information
ceciliaavila and JhontSouth authored Jul 14, 2023
1 parent 6cae128 commit a44bfbc
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions libraries/botbuilder-ai/etc/botbuilder-ai.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,7 @@ export interface QnAMakerOptions {
strictFiltersJoinOperator?: JoinOperator;
timeout?: number;
top?: number;
userId?: string;
}

// @public
Expand Down
3 changes: 2 additions & 1 deletion libraries/botbuilder-ai/src/customQuestionAnswering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ export class CustomQuestionAnswering implements QnAMakerClient, QnAMakerTelemetr
telemetryMetrics: { [key: string]: number }
): Promise<QnAMakerResults> {
const question: string = this.getTrimmedMessageText(context);
const queryOptions: QnAMakerOptions = { ...this._options, ...options } as QnAMakerOptions;
const userId = context?.activity?.from?.id;
const queryOptions: QnAMakerOptions = { ...this._options, ...options, userId } as QnAMakerOptions;

let result: QnAMakerResults;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,9 @@ export interface QnAMakerOptions {
* includeUnstructuredSources - option to fetch answers from unsrtuctured sources
*/
includeUnstructuredSources?: boolean;

/**
* Channel id for the user or bot on this channel
*/
userId?: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export class LanguageServiceUtils {
context: queryOptions.context,
answerSpanRequest: { enable: queryOptions.enablePreciseAnswer },
includeUnstructuredSources: queryOptions.includeUnstructuredSources,
userId: options.userId,
});

const qnaResults = await this.httpRequestUtils.executeHttpRequest(
Expand Down
2 changes: 1 addition & 1 deletion libraries/botbuilder-ai/tests/languageService.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ describe('LanguageService', function () {

it('sorts the answers in the qna results from highest to lowest score', async function () {
const qna = new CustomQuestionAnswering(endpoint);
const context = new TestContext({ text: "what's your favorite animal?" });
const context = new TestContext({ text: "what's your favorite animal?", from: { id: 'user' } });
const options = { top: 5 };

const results = await qna.getAnswers(context, options);
Expand Down

0 comments on commit a44bfbc

Please sign in to comment.