/** * @module botbuilder-ai */ /** * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ import { RequestOptionsBase } from 'botbuilder-stdlib/lib/azureCoreHttpCompat'; import { BotTelemetryClient, RecognizerResult, TurnContext } from 'botbuilder-core'; import { DynamicList } from './dynamicList'; import { ExternalEntity } from './externalEntity'; import { DialogContext, Recognizer } from 'botbuilder-dialogs'; /** * Description of a LUIS application used for initializing a LuisRecognizer. */ export interface LuisApplication { /** * Your models application Id from LUIS */ applicationId: string; /** * (Optional) LUIS endpoint with a default of https://westus.api.cognitive.microsoft.com */ endpoint?: string; /** * Endpoint key for talking to LUIS */ endpointKey: string; } /** * * Options per LUIS prediction. */ export interface LuisPredictionOptions extends RequestOptionsBase { /** * If true, return all intents instead of just the top scoring intent. */ verbose?: boolean; /** * (Optional) Bing Spell Check subscription key. */ bingSpellCheckSubscriptionKey?: string; /** * (Optional) Determine if all intents come back or only the top one. */ includeAllIntents?: boolean; /** * (Optional) A value indicating whether or not instance data should be included in response. */ includeInstanceData?: boolean; /** * (Optional) If queries should be logged in LUIS. */ log?: boolean; /** * (Optional) Whether to spell check query. */ spellCheck?: boolean; /** * (Optional) Whether to use the staging endpoint. */ staging?: boolean; /** * (Optional) The time zone offset for resolving datetimes. */ timezoneOffset?: number; /** * (Optional) Telemetry Client. */ telemetryClient?: BotTelemetryClient; /** * (Optional) Designates whether personal information should be logged in telemetry. */ logPersonalInformation?: boolean; } export interface LuisRecognizerTelemetryClient { /** * 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 LUIS to recognize intents and entities in a users utterance. * * @summary * Returns a [RecognizerResult](../botbuilder-core/recognizerresult) containing any intents and entities recognized by LUIS. * * @param {TurnContext} context Context for the current turn of conversation with the use. * @param {object} telemetryProperties Additional properties to be logged to telemetry with the LuisResult event. * @param {object} telemetryMetrics Additional metrics to be logged to telemetry with the LuisResult event. * @returns {Promise} A promise that resolves to the recognizer result. */ recognize(context: TurnContext, telemetryProperties?: { [key: string]: string; }, telemetryMetrics?: { [key: string]: number; }): Promise; } export interface LuisRecognizerOptions { /** * (Optional) Telemetry Client. */ telemetryClient?: BotTelemetryClient; /** * (Optional) Designates whether personal information should be logged in telemetry. */ logPersonalInformation?: boolean; /** * (Optional) Force the inclusion of LUIS Api call in results returned by [recognize()](#recognize). Defaults to a value of `false` */ includeAPIResults?: boolean; } export interface LuisRecognizerOptionsV3 extends LuisRecognizerOptions { /** * (Optional) Luis Api endpoint version. */ apiVersion: 'v3'; /** * (Optional) External recognizer to recognize external entities to pass to LUIS. */ externalEntityRecognizer?: Recognizer; /** * (Optional) Determine if all intents come back or only the top one. */ includeAllIntents?: boolean; /** * (Optional) A value indicating whether or not instance data should be included in response. */ includeInstanceData?: boolean; /** * (Optional) If queries should be logged in LUIS. */ log?: boolean; /** * (Optional) Dynamic lists of things like contact names to recognize at query time.. */ dynamicLists?: Array; /** * (Optional) External entities recognized in query. */ externalEntities?: Array; /** * (Optional) Boolean for if external entities should be preferred to the results from LUIS models. */ preferExternalEntities?: boolean; /** * (Optional) Timezone applied to datetimeV2 entities. */ datetimeReference?: string; /** * (Optional) By default this uses the production slot. You can find other standard slots in . * If you specify a Version, then a private version of the application is used instead of a slot. */ slot?: 'production' | 'staging'; /** * (Optional) LUIS supports versions and this is the version to use instead of a slot. * If this is specified, then the is ignored.. */ version?: string; } export interface LuisRecognizerOptionsV2 extends LuisRecognizerOptions { /** * Luis Api endpoint version. */ apiVersion: 'v2'; /** * (Optional) Bing Spell Check subscription key. */ bingSpellCheckSubscriptionKey?: string; /** * (Optional) Determine if all intents come back or only the top one. */ includeAllIntents?: boolean; /** * (Optional) A value indicating whether or not instance data should be included in response. */ includeInstanceData?: boolean; /** * (Optional) If queries should be logged in LUIS. */ log?: boolean; /** * (Optional) Whether to spell check query. */ spellCheck?: boolean; /** * (Optional) Whether to use the staging endpoint. */ staging?: boolean; /** * (Optional) The time zone offset for resolving datetimes. */ timezoneOffset?: number; } /** * Recognize intents in a user utterance using a configured LUIS model. * * @summary * This class is used to recognize intents and extract entities from incoming messages. * See this class in action [in this sample application](https://github.com/microsoft/BotBuilder-Samples/tree/main/samples/javascript_nodejs/14.nlp-with-dispatch). * * This component can be used within your bots logic by calling [recognize()](#recognize). */ export declare class LuisRecognizer implements LuisRecognizerTelemetryClient { private readonly _logPersonalInformation; private readonly _telemetryClient; private application; private options; private cacheKey; private luisRecognizerInternal; /** * Creates a new [LuisRecognizer](xref:botbuilder-ai.LuisRecognizer) instance. * * @param application The LUIS application endpoint, usually retrieved from https://luis.ai. * @param options Optional. Options object used to control predictions. Should conform to the [LuisPredictionOptions](xref:botbuilder-ai.LuisPredictionOptions) definition. * @param includeApiResults (Deprecated) Flag that if set to `true` will force the inclusion of LUIS Api call in results returned by the [LuisRecognizer.recognize](xref:botbuilder-ai.LuisRecognizer.recognize) method. Defaults to a value of `false`. */ constructor(application: string, options?: LuisPredictionOptions, includeApiResults?: boolean); /** * Creates a new [LuisRecognizer](xref:botbuilder-ai.LuisRecognizer) instance. * * @param application An object conforming to the [LuisApplication](xref:botbuilder-ai.LuisApplication) definition. * @param options Optional. Options object used to control predictions. Should conform to the [LuisPredictionOptions](xref:botbuilder-ai.LuisPredictionOptions) definition. * @param includeApiResults (Deprecated) Flag that if set to `true` will force the inclusion of LUIS Api call in results returned by the [LuisRecognizer.recognize](xref:botbuilder-ai.LuisRecognizer.recognize) method. Defaults to a value of `false`. */ constructor(application: LuisApplication, options?: LuisPredictionOptions, includeApiResults?: boolean); /** * Creates a new [LuisRecognizer](xref:botbuilder-ai.LuisRecognizer) instance. * * @param application An object conforming to the [LuisApplication](xref:botbuilder-ai.LuisApplication) definition or a string representing a LUIS application endpoint, usually retrieved from https://luis.ai. * @param options Optional. Options object used to control predictions. Should conform to the [LuisRecognizerOptionsV3](xref:botbuilder-ai.LuisRecognizerOptionsV3) or [LuisRecognizerOptionsV2](xref:botbuilder-ai.LuisRecognizerOptionsV2) definition. */ constructor(application: LuisApplication | string, options?: LuisRecognizerOptionsV3 | LuisRecognizerOptionsV2); /** * 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 Currently configured BotTelemetryClient that logs the LuisResult event. */ get telemetryClient(): BotTelemetryClient; /** * Returns the name of the top scoring intent from a set of LUIS results. * * @param {RecognizerResult} results Result set to be searched. * @param {string} defaultIntent (Optional) intent name to return should a top intent be found. Defaults to a value of `None`. * @param {number} minScore (Optional) minimum score needed for an intent to be considered as a top intent. If all intents in the set are below this threshold then the `defaultIntent` will be returned. Defaults to a value of `0.0`. * @returns {string} the top intent */ static topIntent(results?: RecognizerResult, defaultIntent?: string, minScore?: number): string; /** * Sorts recognizer result intents in ascending order by score, filtering those that * have scores less that `minScore`. * * @param {RecognizerResult} result recognizer result to be sorted and filtered * @param {number} minScore minimum score threshold, lower score results will be filtered * @returns {Array<{intent: string; score: number}>} sorted result intents */ static sortedIntents(result?: RecognizerResult, minScore?: number): Array<{ intent: string; score: number; }>; /** * Calls LUIS to recognize intents and entities in a users utterance. * * @summary * Returns a [RecognizerResult](../botbuilder-core/recognizerresult) containing any intents and entities recognized by LUIS. * * In addition to returning the results from LUIS, [recognize()](#recognize) will also * emit a trace activity that contains the LUIS results. * * Here is an example of recognize being used within a bot's turn handler: to interpret an incoming message: * * ```javascript * async onTurn(context) { * if (turnContext.activity.type === ActivityTypes.Message) { * const results = await luisRecognizer.recognize(turnContext); * const topIntent = LuisRecognizer.topIntent(results); * switch (topIntent) { * case 'MyIntent': * // ... handle intent ... * break; * case 'None': * // ... handle intent ... * break; * } * } * } * ``` * * @param {DialogContext | TurnContext} context Context for the current turn of conversation with the use. * @param {object} telemetryProperties Additional properties to be logged to telemetry with the LuisResult event. * @param {object} telemetryMetrics Additional metrics to be logged to telemetry with the LuisResult event. * @param {LuisRecognizerOptionsV2 | LuisRecognizerOptionsV3 | LuisPredictionOptions} options (Optional) options object used to override control predictions. Should conform to the [LuisRecognizerOptionsV2] or [LuisRecognizerOptionsV3] definition. * @returns {Promise} A promise that resolved to the recognizer result. */ recognize(context: DialogContext | TurnContext, telemetryProperties?: Record, telemetryMetrics?: Record, options?: LuisRecognizerOptionsV2 | LuisRecognizerOptionsV3 | LuisPredictionOptions): Promise; /** * Calls LUIS to recognize intents and entities in a users utterance. * * @param {string} utterance The utterance to be recognized. * @param {LuisRecognizerOptionsV2 | LuisRecognizerOptionsV3 | LuisPredictionOptions} options (Optional) options object used to override control predictions. Should conform to the [LuisRecognizerOptionsV2] or [LuisRecognizerOptionsV3] definition. */ recognize(utterance: string, options?: LuisRecognizerOptionsV2 | LuisRecognizerOptionsV3 | LuisPredictionOptions): Promise; /** * Invoked prior to a LuisResult Event being logged. * * @param {RecognizerResult} recognizerResult The Luis 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 LuisResult event. * @param {object} telemetryMetrics Additional metrics to be logged to telemetry with the LuisResult event. */ protected onRecognizerResults(recognizerResult: RecognizerResult, turnContext: TurnContext, telemetryProperties?: { [key: string]: string; }, telemetryMetrics?: { [key: string]: number; }): Promise; /** * Fills the event properties for LuisResult event for telemetry. These properties are logged when the recognizer is called. * * @param {RecognizerResult} recognizerResult 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 LuisResult event. * @returns {Promise} A dictionary that is sent as properties to BotTelemetryClient.trackEvent method for the LuisResult event. */ protected fillTelemetryProperties(recognizerResult: RecognizerResult, turnContext: TurnContext, telemetryProperties?: { [key: string]: string; }): Promise<{ [key: string]: string; }>; private prepareErrorMessage; private setLuisPredictionOptions; private validateLuisApplication; private buildRecognizer; } //# sourceMappingURL=luisRecognizer.d.ts.map