/** * @module botbuilder-ai */ /** * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ import { BotTelemetryClient, TurnContext } from 'botbuilder-core'; import { FeedbackRecords, QnAMakerEndpoint, QnAMakerOptions, QnAMakerResult, QnAMakerResults } from './qnamaker-interfaces'; export declare const QNAMAKER_TRACE_TYPE = "https://www.qnamaker.ai/schemas/trace"; export declare const QNAMAKER_TRACE_NAME = "QnAMaker"; export declare const QNAMAKER_TRACE_LABEL = "QnAMaker Trace"; /** * Turn state key for QnAMakerClient. */ export declare const QnAMakerClientKey: unique symbol; /** * Client to access a QnA Maker knowledge base. */ export interface QnAMakerClient { /** * Generates an answer from the knowledge base. * * @param {TurnContext} turnContext The Turn Context that contains the user question to be queried against your knowledge base. * @param {QnAMakerOptions} options The options for the QnA Maker knowledge base. If null, constructor option is used for this instance. * @param {Record} telemetryProperties Additional properties to be logged to telemetry with the QnaMessage event. * @param {Record} telemetryMetrics Additional metrics to be logged to telemetry with the QnaMessage event. * @returns {Promise} A list of answers for the user query, sorted in decreasing order of ranking score. */ getAnswers(turnContext: TurnContext, options?: QnAMakerOptions, telemetryProperties?: Record, telemetryMetrics?: Record): Promise; /** * Generates an answer from the knowledge base. * * @param {TurnContext} turnContext The Turn Context that contains the user question to be queried against your knowledge base. * @param {QnAMakerOptions} options The options for the QnA Maker knowledge base. If null, constructor option is used for this instance. * @param {Record} telemetryProperties Additional properties to be logged to telemetry with the QnaMessage event. * @param {Record} telemetryMetrics Additional metrics to be logged to telemetry with the QnaMessage event. * @returns {Promise} A list of answers for the user query, sorted in decreasing order of ranking score. */ getAnswersRaw(turnContext: TurnContext, options?: QnAMakerOptions, telemetryProperties?: Record, telemetryMetrics?: Record): Promise; /** * Filters the ambiguous question for active learning. * * @param {QnAMakerResult[]} queryResult User query output. * @returns {QnAMakerResult[]} Filtered array of ambiguous question. */ getLowScoreVariation(queryResult: QnAMakerResult[]): QnAMakerResult[]; /** * Send feedback to the knowledge base. * * @param {FeedbackRecords} feedbackRecords Feedback records. */ callTrain(feedbackRecords: FeedbackRecords): Promise; } /** * Interface for adding telemetry logging capabilities to QnAMaker. */ export interface QnAMakerTelemetryClient { /** * Gets a value indicating whether determines whether to log personal information that came from the user. */ readonly logPersonalInformation: boolean; /** * Gets the currently configured botTelemetryClient that logs the events. */ readonly telemetryClient: BotTelemetryClient; /** * Calls the QnA Maker service to generate answer(s) for a question. * * @summary * Returns an array of answers sorted by score with the top scoring answer returned first. * * In addition to returning the results from QnA Maker, [getAnswers()](#getAnswers) will also * emit a trace activity that contains the QnA Maker results. * * @param {TurnContext} context The Turn Context that contains the user question to be queried against your knowledge base. * @param {QnAMakerOptions} options (Optional) The options for the QnA Maker knowledge base. If null, constructor option is used for this instance. * @param {object} telemetryProperties Additional properties to be logged to telemetry with the QnaMessage event. * @param {object} telemetryMetrics Additional metrics to be logged to telemetry with the QnaMessage event. * @returns {Promise} A promise resolving to the QnAMaker result */ getAnswers(context: TurnContext, options?: QnAMakerOptions, telemetryProperties?: { [key: string]: string; }, telemetryMetrics?: { [key: string]: number; }): Promise; } /** * Query a QnA Maker knowledge base for answers and provide feedbacks. * * @summary * This class is used to make queries to a single QnA Maker knowledge base and return the result. * * Use this to process incoming messages with the [getAnswers()](#getAnswers) method. */ export declare class QnAMaker implements QnAMakerClient, QnAMakerTelemetryClient { private readonly endpoint; private readonly _logPersonalInformation; private readonly _telemetryClient; private readonly _options; private readonly generateAnswerUtils; private readonly trainUtils; /** * Creates a new QnAMaker instance. * * @param {QnAMakerEndpoint} endpoint The endpoint of the knowledge base to query. * @param {QnAMakerOptions} options (Optional) additional settings used to configure the instance. * @param {BotTelemetryClient} telemetryClient The BotTelemetryClient used for logging telemetry events. * @param {boolean} logPersonalInformation Set to true to include personally identifiable information in telemetry events. */ constructor(endpoint: QnAMakerEndpoint, options?: QnAMakerOptions, telemetryClient?: BotTelemetryClient, logPersonalInformation?: boolean); /** * Gets a value indicating whether determines whether to log personal information that came from the user. * * @returns True if will log personal information into the BotTelemetryClient.TrackEvent method; otherwise the properties will be filtered. */ get logPersonalInformation(): boolean; /** * Gets the currently configured BotTelemetryClient that logs the events. * * @returns The currently configured BotTelemetryClient that logs the QnaMessage event. */ get telemetryClient(): BotTelemetryClient; /** * Calls the QnA Maker service to generate answer(s) for a question. * * @summary * Returns an array of answers sorted by score with the top scoring answer returned first. * * In addition to returning the results from QnA Maker, [getAnswers()](#getAnswers) will also * emit a trace activity that contains the QnA Maker results. * * @param {TurnContext} context The Turn Context that contains the user question to be queried against your knowledge base. * @param {QnAMakerOptions} options (Optional) The options for the QnA Maker knowledge base. If null, constructor option is used for this instance. * @param {object} telemetryProperties Additional properties to be logged to telemetry with the QnaMessage event. * @param {object} telemetryMetrics Additional metrics to be logged to telemetry with the QnaMessage event. * @returns {Promise} A promise resolving to the QnAMaker result */ getAnswers(context: TurnContext, options?: QnAMakerOptions, telemetryProperties?: { [key: string]: string; }, telemetryMetrics?: { [key: string]: number; }): Promise; /** * Generates an answer from the knowledge base. * * @param {TurnContext} context The [TurnContext](xref:botbuilder-core.TurnContext) that contains the user question to be queried against your knowledge base. * @param {QnAMakerOptions} options Optional. The [QnAMakerOptions](xref:botbuilder-ai.QnAMakerOptions) for the QnA Maker knowledge base. If null, constructor option is used for this instance. * @param {object} telemetryProperties Optional. Additional properties to be logged to telemetry with the QnaMessage event. * @param {object} telemetryMetrics Optional. Additional metrics to be logged to telemetry with the QnaMessage event. * @returns {Promise} A list of answers for the user query, sorted in decreasing order of ranking score. */ getAnswersRaw(context: TurnContext, options: QnAMakerOptions, telemetryProperties: { [key: string]: string; }, telemetryMetrics: { [key: string]: number; }): Promise; /** * Generates an answer from the QnA Maker knowledge base. * * @param {TurnContext} context The [TurnContext](xref:botbuilder-core.TurnContext) that contains the user question to be queried against your knowledge base. * @param {QnAMakerOptions} options Optional. The [QnAMakerOptions](xref:botbuilder-ai.QnAMakerOptions) for the QnA Maker knowledge base. If null, constructor option is used for this instance. * @param {object} telemetryProperties Optional. Additional properties to be logged to telemetry with the QnaMessage event. * @param {object} telemetryMetrics Optional. Additional metrics to be logged to telemetry with the QnaMessage event. * @returns {Promise} A list of answers for the user query, sorted in decreasing order of ranking score. */ getLegacyAnswersRaw(context: TurnContext, options?: QnAMakerOptions, telemetryProperties?: { [key: string]: string; }, telemetryMetrics?: { [key: string]: number; }): Promise; /** * Calls [generateAnswer()](#generateanswer) and sends the resulting answer as a reply to the user. * * @deprecated Instead, favor using [QnAMaker.getAnswers()](#getAnswers) to generate answers for a question. * * @summary * Returns a value of `true` if an answer was found and sent. If multiple answers are * returned the first one will be delivered. * @param {TurnContext} context Context for the current turn of conversation with the user. * @returns {Promise} A promise resolving to true if an answer was sent */ answer(context: TurnContext): Promise; /** * Calls the QnA Maker service to generate answer(s) for a question. * * @deprecated Instead, favor using [QnAMaker.getAnswers()](#getAnswers) to generate answers for a question. * * @summary * Returns an array of answers sorted by score with the top scoring answer returned first. * * @param {string | undefined} question The question to answer. * @param {number} top (Optional) number of answers to return. Defaults to a value of `1`. * @param {number} _scoreThreshold (Optional) minimum answer score needed to be considered a match to questions. Defaults to a value of `0.001`. * @returns {Promise} A promise resolving to the QnAMaker results */ generateAnswer(question: string | undefined, top?: number, _scoreThreshold?: number): Promise; /** * Filters the ambiguous question for active learning. * * @summary Returns a filtered array of ambiguous question. * * @param {QnAMakerResult[]} queryResult User query output. * @returns {QnAMakerResult[]} the filtered results */ getLowScoreVariation(queryResult: QnAMakerResult[]): QnAMakerResult[]; /** * Send feedback to the knowledge base. * * @param {FeedbackRecords} feedbackRecords Feedback records. * @returns {Promise} A promise representing the async operation */ callTrain(feedbackRecords: FeedbackRecords): Promise; /** * Called internally to query the QnA Maker service. * * @summary This is exposed to enable better unit testing of the service. * * @param {QnAMakerEndpoint} endpoint the qna maker endpoint * @param {string} question the question * @param {number} top number of results to return * @returns {Promise} a promise resolving to the qna maker results */ protected callService(endpoint: QnAMakerEndpoint, question: string, top: number): Promise; /** * Invoked prior to a QnaMessage Event being logged. * * @param {QnAMakerResult[]} qnaResults The QnA Results for the call. * @param {TurnContext} turnContext Context object containing information for a single turn of conversation with a user. * @param {object} telemetryProperties Additional properties to be logged to telemetry with the QnaMessage event. * @param {object} telemetryMetrics Additional metrics to be logged to telemetry with the QnaMessage event. * @returns {Promise} A promise representing the async operation */ protected onQnaResults(qnaResults: QnAMakerResult[], turnContext: TurnContext, telemetryProperties?: { [key: string]: string; }, telemetryMetrics?: { [key: string]: number; }): Promise; /** * Fills the event properties for QnaMessage event for telemetry. * These properties are logged when the recognizer is called. * * @param {QnAMakerResult[]} qnaResults Last activity sent from user. * @param {TurnContext} turnContext Context object containing information for a single turn of conversation with a user. * @param {object} telemetryProperties Additional properties to be logged to telemetry with the QnaMessage event. * @param {object} telemetryMetrics Additional properties to be logged to telemetry with the QnaMessage event. * @returns {Promise<[object, object]>} A dictionary that is sent as properties to BotTelemetryClient.trackEvent method for the QnaMessage event. */ protected fillQnAEvent(qnaResults: QnAMakerResult[], turnContext: TurnContext, telemetryProperties?: Record, telemetryMetrics?: Record): Promise<[Record, Record]>; private getTrimmedMessageText; } //# sourceMappingURL=qnaMaker.d.ts.map