Skip to content

Commit

Permalink
feat: Added support for CQA with unit tests. (#4162)
Browse files Browse the repository at this point in the history
* Added support for CQA with unit tests.

* Edited package.json

* Code refactored and version updated.

* Increased compatibility with sample.

* Changed qnaServiceType to enum from string

* Reverted package.json

* Updated documentational comments.

* Updated tests for QnACardBuilder.

* Resolved conflicts.

* Updated QnAMaker tests.

* Ensured backward compat in qnaCardBuilder.ts

* Updated reference to serviceType

* Updated api signature for botbuilder-ai

* Updated test for increasing coverage.

* Updated tests for increasing coverage.

* Updated exports with newly added files.

* Updated api signature.

* Undo eslint changes and update comments.

* Applied eslint
  • Loading branch information
Arsh-Kashyap authored Apr 7, 2022
1 parent c5de442 commit da9999e
Show file tree
Hide file tree
Showing 76 changed files with 3,275 additions and 117 deletions.
154 changes: 145 additions & 9 deletions libraries/botbuilder-ai/etc/botbuilder-ai.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ import { WaterfallStepContext } from 'botbuilder-dialogs';
// @public
export class ActiveLearningUtils {
static getLowScoreVariation(qnaSearchResults: QnAMakerResult[]): QnAMakerResult[];
static MaximumScoreForLowScoreVariation: number;
static MinimumScoreForLowScoreVariation: number;
static readonly MaximumScoreForLowScoreVariation = 95;
static readonly MaxLowScoreVariationMultiplier = 1;
static readonly MinimumScoreForLowScoreVariation = 20;
static readonly PreviousLowScoreVariationMultiplier = 0.7;
}

// @public
Expand All @@ -52,6 +54,49 @@ export enum Anchor {
Start = "start"
}

// @public
export interface AnswerSpanResponse {
endIndex?: number;
score: number;
startIndex?: number;
text: string;
}

// Warning: (ae-forgotten-export) The symbol "QnAMakerClient" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "QnAMakerTelemetryClient" needs to be exported by the entry point index.d.ts
//
// @public
export class CustomQuestionAnswering implements QnAMakerClient_2, QnAMakerTelemetryClient_2 {
constructor(endpoint: QnAMakerEndpoint, options?: QnAMakerOptions, telemetryClient?: BotTelemetryClient, logPersonalInformation?: boolean);
callTrain(feedbackRecords: FeedbackRecords): Promise<void>;
protected fillQnAEvent(qnaResults: QnAMakerResult[], turnContext: TurnContext, telemetryProperties?: Record<string, string>, telemetryMetrics?: Record<string, number>): Promise<[Record<string, string>, Record<string, number>]>;
getAnswers(context: TurnContext, options?: QnAMakerOptions, telemetryProperties?: {
[key: string]: string;
}, telemetryMetrics?: {
[key: string]: number;
}): Promise<QnAMakerResult[]>;
getAnswersRaw(context: TurnContext, options: QnAMakerOptions, telemetryProperties: {
[key: string]: string;
}, telemetryMetrics: {
[key: string]: number;
}): Promise<QnAMakerResults>;
getKnowledgebaseAnswersRaw(context: TurnContext, options: QnAMakerOptions, telemetryProperties: {
[key: string]: string;
}, telemetryMetrics: {
[key: string]: number;
}): Promise<QnAMakerResults>;
getLowScoreVariation(queryResult: QnAMakerResult[]): QnAMakerResult[];
// (undocumented)
get logPersonalInformation(): boolean;
protected onQnaResults(qnaResults: QnAMakerResult[], turnContext: TurnContext, telemetryProperties?: {
[key: string]: string;
}, telemetryMetrics?: {
[key: string]: number;
}): Promise<void>;
// (undocumented)
get telemetryClient(): BotTelemetryClient;
}

// @public
export interface DateTimeSpec {
timex: string[];
Expand Down Expand Up @@ -84,6 +129,16 @@ export interface FeedbackRecords {
feedbackRecords: FeedbackRecord[];
}

// @public
export interface Filters {
// (undocumented)
logicalOperation: string;
// (undocumented)
metadataFilter: MetadataFilter;
// (undocumented)
sourceFilter: Array<string>;
}

// @public
export interface GeographyV2 {
location: string;
Expand Down Expand Up @@ -125,6 +180,44 @@ export enum JoinOperator {
OR = "OR"
}

// @public
export interface KnowledgeBaseAnswer {
// (undocumented)
answer: string;
// (undocumented)
answerSpan: KnowledgeBaseAnswerSpan;
// (undocumented)
confidenceScore: number;
// (undocumented)
dialog: QnAResponseContext;
// (undocumented)
id: number;
// (undocumented)
metadata: Map<string, string>;
// (undocumented)
questions: string[];
// (undocumented)
source: string;
}

// @public
export interface KnowledgeBaseAnswers {
// (undocumented)
answers: KnowledgeBaseAnswer[];
}

// @public
export interface KnowledgeBaseAnswerSpan {
// (undocumented)
confidenceScore: number;
// (undocumented)
length: number;
// (undocumented)
offset: number;
// (undocumented)
text: string;
}

// @public
export interface ListElement {
canonicalForm?: string;
Expand Down Expand Up @@ -311,6 +404,17 @@ export class LuisTelemetryConstants {
static readonly sentimentScoreProperty = "sentimentScore";
}

// @public
export interface MetadataFilter {
// (undocumented)
logicalOperation: string;
// (undocumented)
metadata: Array<{
key: string;
value: string;
}>;
}

// @public
export interface NumberWithUnits {
number?: number;
Expand All @@ -325,6 +429,7 @@ export interface OrdinalV2 {

// @public
export class QnACardBuilder {
static getQnAAnswerCard(result: QnAMakerResult, displayPreciseAnswerOnly: boolean): Partial<Activity>;
static getQnAPromptsCard(result: QnAMakerResult): Partial<Activity>;
static getSuggestionsCard(suggestionsList: string[], cardTitle: string, cardNoMatchText: string): Partial<Activity>;
}
Expand All @@ -338,13 +443,18 @@ export class QnAMaker implements QnAMakerClient, QnAMakerTelemetryClient {
callTrain(feedbackRecords: FeedbackRecords): Promise<void>;
protected fillQnAEvent(qnaResults: QnAMakerResult[], turnContext: TurnContext, telemetryProperties?: Record<string, string>, telemetryMetrics?: Record<string, number>): Promise<[Record<string, string>, Record<string, number>]>;
// @deprecated
generateAnswer(question: string | undefined, top?: number, scoreThreshold?: number): Promise<QnAMakerResult[]>;
generateAnswer(question: string | undefined, top?: number, _scoreThreshold?: number): Promise<QnAMakerResult[]>;
getAnswers(context: TurnContext, options?: QnAMakerOptions, telemetryProperties?: {
[key: string]: string;
}, telemetryMetrics?: {
[key: string]: number;
}): Promise<QnAMakerResult[]>;
getAnswersRaw(context: TurnContext, options?: QnAMakerOptions, telemetryProperties?: {
getAnswersRaw(context: TurnContext, options: QnAMakerOptions, telemetryProperties: {
[key: string]: string;
}, telemetryMetrics: {
[key: string]: number;
}): Promise<QnAMakerResults>;
getLegacyAnswersRaw(context: TurnContext, options?: QnAMakerOptions, telemetryProperties?: {
[key: string]: string;
}, telemetryMetrics?: {
[key: string]: number;
Expand Down Expand Up @@ -399,23 +509,27 @@ export class QnAMakerComponentRegistration extends ComponentRegistration {
export class QnAMakerDialog extends WaterfallDialog implements QnAMakerDialogConfiguration {
// (undocumented)
static $kind: string;
constructor(knowledgeBaseId?: string, endpointKey?: string, hostname?: string, noAnswer?: Activity, threshold?: number, activeLearningCardTitle?: string, cardNoMatchText?: string, top?: number, cardNoMatchResponse?: Activity, strictFilters?: QnAMakerMetadata[], dialogId?: string, strictFiltersJoinOperator?: JoinOperator);
constructor(knowledgeBaseId?: string, endpointKey?: string, hostname?: string, noAnswer?: Activity, threshold?: number, suggestionsActivityFactory?: QnASuggestionsActivityFactory, cardNoMatchText?: string, top?: number, cardNoMatchResponse?: Activity, strictFilters?: QnAMakerMetadata[], dialogId?: string, strictFiltersJoinOperator?: JoinOperator);
constructor(knowledgeBaseId?: string, endpointKey?: string, hostname?: string, noAnswer?: Activity, threshold?: number, activeLearningCardTitle?: string, cardNoMatchText?: string, top?: number, cardNoMatchResponse?: Activity, rankerType?: RankerTypes, strictFilters?: QnAMakerMetadata[], dialogId?: string, strictFiltersJoinOperator?: JoinOperator, enablePreciseAnswer?: boolean, displayPreciseAnswerOnly?: boolean, qnaServiceType?: ServiceType);
constructor(knowledgeBaseId?: string, endpointKey?: string, hostname?: string, noAnswer?: Activity, threshold?: number, suggestionsActivityFactory?: QnASuggestionsActivityFactory, cardNoMatchText?: string, top?: number, cardNoMatchResponse?: Activity, rankerType?: RankerTypes, strictFilters?: QnAMakerMetadata[], dialogId?: string, strictFiltersJoinOperator?: JoinOperator, enablePreciseAnswer?: boolean, displayPreciseAnswerOnly?: boolean, qnaServiceType?: ServiceType);
activeLearningCardTitle: StringExpression;
beginDialog(dc: DialogContext, options?: object): Promise<DialogTurnResult>;
cardNoMatchResponse: TemplateInterface<Partial<Activity>, DialogStateManager>;
cardNoMatchText: StringExpression;
continueDialog(dc: DialogContext): Promise<DialogTurnResult>;
protected defaultThreshold: number;
protected defaultTopN: number;
displayPreciseAnswerOnly: boolean;
protected displayQnAResult(step: WaterfallStepContext): Promise<DialogTurnResult>;
enablePreciseAnswer: boolean;
endpointKey: StringExpression;
filters: Filters;
// (undocumented)
getConverter(property: keyof QnAMakerDialogConfiguration): Converter | ConverterFactory;
protected getQnAMakerClient(dc: DialogContext): Promise<QnAMakerClient>;
protected getQnAMakerOptions(dc: DialogContext): Promise<QnAMakerOptions>;
protected getQnAResponseOptions(dc: DialogContext): Promise<QnAMakerDialogResponseOptions>;
hostname: StringExpression;
includeUnstructuredSources: boolean;
isTest: boolean;
knowledgeBaseId: StringExpression;
logPersonalInformation: BoolExpression;
Expand All @@ -424,11 +538,13 @@ export class QnAMakerDialog extends WaterfallDialog implements QnAMakerDialogCon
protected options: string;
protected previousQnAId: string;
protected qnAContextData: string;
qnaServiceType: ServiceType;
rankerType: EnumExpression<RankerTypes>;
strictFilters: ArrayExpression<QnAMakerMetadata>;
strictFilters: QnAMakerMetadata[];
strictFiltersJoinOperator: JoinOperator;
threshold: NumberExpression;
top: IntExpression;
}
}

// @public
export interface QnAMakerDialogOptions {
Expand All @@ -441,6 +557,7 @@ export interface QnAMakerDialogResponseOptions {
activeLearningCardTitle: string;
cardNoMatchResponse: Partial<Activity>;
cardNoMatchText: string;
displayPreciseAnswerOnly: boolean;
noAnswer: Partial<Activity>;
}

Expand All @@ -449,6 +566,7 @@ export interface QnAMakerEndpoint {
endpointKey: string;
host: string;
knowledgeBaseId: string;
qnaServiceType?: ServiceType;
}

// @public
Expand All @@ -460,6 +578,10 @@ export interface QnAMakerMetadata {
// @public
export interface QnAMakerOptions {
context?: QnARequestContext;
enablePreciseAnswer?: boolean;
// (undocumented)
filters?: Filters;
includeUnstructuredSources?: boolean;
isTest?: boolean;
metadataBoost?: QnAMakerMetadata[];
qnaId?: number;
Expand All @@ -471,6 +593,14 @@ export interface QnAMakerOptions {
top?: number;
}

// @public
export interface QnAMakerPrompt {
displayOrder: number;
displayText: string;
qna?: object;
qnaId: number;
}

// @public
export class QnAMakerRecognizer extends Recognizer implements QnAMakerRecognizerConfiguration {
// (undocumented)
Expand Down Expand Up @@ -537,6 +667,7 @@ export interface QnAMakerRecognizerConfiguration extends RecognizerConfiguration
// @public
export interface QnAMakerResult {
answer: string;
answerSpan?: AnswerSpanResponse;
context?: QnAResponseContext;
id?: number;
metadata?: any;
Expand Down Expand Up @@ -583,7 +714,6 @@ export interface QnARequestContext {

// @public
export interface QnAResponseContext {
// Warning: (ae-forgotten-export) The symbol "QnAMakerPrompt" needs to be exported by the entry point index.d.ts
prompts: QnAMakerPrompt[];
}

Expand All @@ -597,6 +727,12 @@ export enum RankerTypes {
questionOnly = "QuestionOnly"
}

// @public
export enum ServiceType {
language = "Language",
qnaMaker = "QnAMaker"
}

// @public
export function validateDynamicList(dynamicList: DynamicList): void;

Expand Down
Loading

0 comments on commit da9999e

Please sign in to comment.