def __init__( self, configuration: dict, dialog_id: str = None, telemetry_client: BotTelemetryClient = NullTelemetryClient(), ): super(MainDialog, self).__init__(dialog_id or MainDialog.__name__) self._configuration = configuration self.telemetry_client = telemetry_client text_prompt = TextPrompt(TextPrompt.__name__) text_prompt.telemetry_client = self.telemetry_client booking_dialog = BookingDialog(telemetry_client=self._telemetry_client) booking_dialog.telemetry_client = self.telemetry_client wf_dialog = WaterfallDialog( "WFDialog", [self.intro_step, self.act_step, self.final_step]) wf_dialog.telemetry_client = self.telemetry_client self.add_dialog(text_prompt) self.add_dialog(booking_dialog) self.add_dialog(wf_dialog) self.initial_dialog_id = "WFDialog"
def __init__( self, endpoint: QnAMakerEndpoint, options: QnAMakerOptions = None, http_client: ClientSession = None, telemetry_client: BotTelemetryClient = None, log_personal_information: bool = None, ): super().__init__(log_personal_information, telemetry_client) if not isinstance(endpoint, QnAMakerEndpoint): raise TypeError( "QnAMaker.__init__(): endpoint is not an instance of QnAMakerEndpoint" ) self._endpoint: str = endpoint opt = options or QnAMakerOptions() self._validate_options(opt) instance_timeout = ClientTimeout(total=opt.timeout / 1000) self._http_client = http_client or ClientSession(timeout=instance_timeout) self.telemetry_client: Union[ BotTelemetryClient, NullTelemetryClient ] = telemetry_client or NullTelemetryClient() self.log_personal_information = log_personal_information or False self._generate_answer_helper = GenerateAnswerUtils( self.telemetry_client, self._endpoint, options, self._http_client ) self._active_learning_train_helper = TrainUtils( self._endpoint, self._http_client )
def __init__(self, dialog_state: StatePropertyAccessor = None): # pylint: disable=import-outside-toplevel if dialog_state is None: frame = inspect.currentframe().f_back try: # try to access the caller's "self" try: self_obj = frame.f_locals["self"] except KeyError: raise TypeError( "DialogSet(): dialog_state cannot be None.") # Only ComponentDialog can initialize with None dialog_state from .component_dialog import ComponentDialog from .dialog_manager import DialogManager from .dialog_container import DialogContainer if not isinstance( self_obj, (ComponentDialog, DialogContainer, DialogManager)): raise TypeError( "DialogSet(): dialog_state cannot be None.") finally: # make sure to clean up the frame at the end to avoid ref cycles del frame self._dialog_state = dialog_state self.__telemetry_client = NullTelemetryClient() self._dialogs: Dict[str, Dialog] = {} self._version: str = None
def __init__( self, include_all_intents: bool = False, include_instance_data: bool = True, log: bool = True, prefer_external_entities: bool = True, datetime_reference: str = None, dynamic_lists: List = None, external_entities: List = None, slot: str = "production", version: str = None, include_api_results: bool = True, telemetry_client: BotTelemetryClient = NullTelemetryClient(), log_personal_information: bool = False, ): super().__init__(include_api_results, telemetry_client, log_personal_information) self.include_all_intents = include_all_intents self.include_instance_data = include_instance_data self.log = log self.prefer_external_entities = prefer_external_entities self.datetime_reference = datetime_reference self.dynamic_lists = dynamic_lists self.external_entities = external_entities self.slot = slot self.version: str = version
def __init__( self, configuration: DefaultConfig, telemetry_client: BotTelemetryClient = None ): self._recognizer = None luis_is_configured = ( configuration.LUIS_APP_ID and configuration.LUIS_API_KEY and configuration.LUIS_API_HOST_NAME ) if luis_is_configured: # Set the recognizer options depending on which endpoint version you want to use e.g v2 or v3. # More details can be found in https://docs.microsoft.com/azure/cognitive-services/luis/luis-migration-api-v3 luis_application = LuisApplication( configuration.LUIS_APP_ID, configuration.LUIS_API_KEY, "https://" + configuration.LUIS_API_HOST_NAME, ) options = LuisPredictionOptions() options.telemetry_client = telemetry_client or NullTelemetryClient() self._recognizer = LuisRecognizer( luis_application, prediction_options=options )
def __init__( self, dialog_id: str, telemetry_client: BotTelemetryClient = NullTelemetryClient(), ): super(CancelAndHelpDialog, self).__init__(dialog_id) self.telemetry_client = telemetry_client
def __init__( self, dialog_id: str = None, telemetry_client: BotTelemetryClient = NullTelemetryClient(), ): super(BookingDialog, self).__init__(dialog_id or BookingDialog.__name__, telemetry_client) self.telemetry_client = telemetry_client text_prompt = TextPrompt(TextPrompt.__name__) text_prompt.telemetry_client = telemetry_client waterfall_dialog = WaterfallDialog( WaterfallDialog.__name__, [ self.destination_step, self.origin_step, self.travel_date_step, # self.confirm_step, self.final_step, ], ) waterfall_dialog.telemetry_client = telemetry_client self.add_dialog(text_prompt) # self.add_dialog(ConfirmPrompt(ConfirmPrompt.__name__)) self.add_dialog( DateResolverDialog(DateResolverDialog.__name__, self.telemetry_client)) self.add_dialog(waterfall_dialog) self.initial_dialog_id = WaterfallDialog.__name__
def __init__(self, endpoint: QnAMakerEndpoint, options: QnAMakerOptions = None, http_client: ClientSession = None, telemetry_client: BotTelemetryClient = None, log_personal_information: bool = None): if not isinstance(endpoint, QnAMakerEndpoint): raise TypeError( 'QnAMaker.__init__(): endpoint is not an instance of QnAMakerEndpoint' ) if endpoint.host.endswith('v2.0'): raise ValueError( 'v2.0 of QnA Maker service is no longer supported in the Bot Framework. Please upgrade your QnA Maker service at www.qnamaker.ai.' ) self._endpoint: str = endpoint self._is_legacy_protocol: bool = self._endpoint.host.endswith('v3.0') self._options = options or QnAMakerOptions() self._validate_options(self._options) instance_timeout = ClientTimeout(total=self._options.timeout / 1000) self._req_client = http_client or ClientSession( timeout=instance_timeout) self._telemetry_client: Union[ BotTelemetryClient, NullTelemetryClient] = telemetry_client or NullTelemetryClient() self._log_personal_information = log_personal_information or False
def __init__( self, luis_recognizer: FlightBookingRecognizer, booking_dialog: BookingDialog, telemetry_client: BotTelemetryClient = None, ): super(MainDialog, self).__init__(MainDialog.__name__) self.telemetry_client = telemetry_client or NullTelemetryClient() text_prompt = TextPrompt(TextPrompt.__name__) text_prompt.telemetry_client = self.telemetry_client booking_dialog.telemetry_client = self.telemetry_client wf_dialog = WaterfallDialog( "WFDialog", [self.intro_step, self.act_step, self.final_step]) wf_dialog.telemetry_client = self.telemetry_client self._luis_recognizer = luis_recognizer self._booking_dialog_id = booking_dialog.id self.add_dialog(text_prompt) self.add_dialog(booking_dialog) self.add_dialog(wf_dialog) self.initial_dialog_id = "WFDialog"
def telemetry_client(self, value: BotTelemetryClient) -> None: """ Sets the telemetry client for logging events. """ if value is None: self._telemetry_client = NullTelemetryClient() else: self._telemetry_client = value
async def execute_luis_query( configuration, turn_context: TurnContext, telemetry_client: BotTelemetryClient = None, ) -> BookingDetails: """Invoke LUIS service to perform prediction/evaluation of utterance.""" booking_details = BookingDetails() # pylint:disable=broad-except try: luis_application = LuisApplication( configuration.get("LUIS_APP_ID"), configuration.get("LUIS_API_KEY"), configuration.get("LUIS_API_HOST_NAME"), ) options = LuisPredictionOptions() options.telemetry_client = ( telemetry_client if telemetry_client is not None else NullTelemetryClient() ) recognizer = LuisRecognizer(luis_application, prediction_options=options) recognizer_result = await recognizer.recognize(turn_context) print(f"Recognize Result: {recognizer_result}") if recognizer_result.intents: intent = sorted( recognizer_result.intents, key=recognizer_result.intents.get, reverse=True, )[:1][0] if intent == "Book_flight": # We need to get the result from the LUIS JSON which at every level returns an array. to_entities = recognizer_result.entities.get("$instance", {}).get( "To", [] ) if to_entities: booking_details.destination = to_entities[0]["text"] from_entities = recognizer_result.entities.get("$instance", {}).get( "From", [] ) if from_entities: booking_details.origin = from_entities[0]["text"] # This value will be a TIMEX. And we are only interested in a Date so grab the first result and drop the Time part. # TIMEX is a format that represents DateTime expressions that include some ambiguity. e.g. missing a Year. date_entities = recognizer_result.entities.get("$instance", {}).get( "datetime", [] ) if date_entities: booking_details.travel_date = ( None ) # Set when we get a timex format except Exception as exception: print(exception) return booking_details
def __init__( self, include_api_results: bool = None, telemetry_client: BotTelemetryClient = NullTelemetryClient(), log_personal_information: bool = False, ): self.include_api_results = include_api_results self.telemetry_client = telemetry_client self.log_personal_information = log_personal_information
def telemetry_client(self, value: BotTelemetryClient) -> None: """ Sets the telemetry client for all dialogs in this set. """ if value is None: self.__telemetry_client = NullTelemetryClient() else: self.__telemetry_client = value for dialog in self._dialogs.values(): dialog.telemetry_client = self.__telemetry_client
def __init__(self, timeout: float = 100000): self._bing_spell_check_subscription_key: str = None self._include_all_intents: bool = None self._include_instance_data: bool = None self._log: bool = None self._spell_check: bool = None self._staging: bool = None self._timeout: float = timeout self._timezone_offset: float = None self._telemetry_client: BotTelemetryClient = NullTelemetryClient() self._log_personal_information: bool = False
def telemetry_client(self, value: BotTelemetryClient) -> None: """ Sets the telemetry client for all dialogs in this set. """ if value is None: self._telemetry_client = NullTelemetryClient() else: self._telemetry_client = value # Care! Dialogs.TelemetryClient assignment internally assigns the # TelemetryClient for each dialog which could lead to an eventual stack # overflow in cyclical dialog structures. # Don't set the telemetry client if the candidate instance is the same as # the currently set one. if self.dialogs.telemetry_client != value: self.dialogs.telemetry_client = self._telemetry_client
def __init__( self, endpoint: QnAMakerEndpoint, options: QnAMakerOptions = None, http_client: ClientSession = None, telemetry_client: BotTelemetryClient = None, log_personal_information: bool = None, ): super().__init__(log_personal_information, telemetry_client) if not isinstance(endpoint, QnAMakerEndpoint): raise TypeError( "QnAMaker.__init__(): endpoint is not an instance of QnAMakerEndpoint" ) if endpoint.host.endswith("v2.0"): raise ValueError( "v2.0 of QnA Maker service is no longer supported in the Bot Framework. Please upgrade your QnA Maker" " service at www.qnamaker.ai." ) self._endpoint: str = endpoint opt = options or QnAMakerOptions() self._validate_options(opt) instance_timeout = ClientTimeout(total=opt.timeout / 1000) self._http_client = http_client or ClientSession(timeout=instance_timeout) self.telemetry_client: Union[ BotTelemetryClient, NullTelemetryClient ] = telemetry_client or NullTelemetryClient() self.log_personal_information = log_personal_information or False self._generate_answer_helper = GenerateAnswerUtils( self.telemetry_client, self._endpoint, options, self._http_client ) self._active_learning_train_helper = TrainUtils( self._endpoint, self._http_client )
def __init__(self, dialog_id: str = None, telemetry_client: BotTelemetryClient = NullTelemetryClient()): super(DateResolverDialog, self).__init__(dialog_id or DateResolverDialog.__name__, telemetry_client) self.telemetry_client = telemetry_client date_time_prompt = DateTimePrompt( DateTimePrompt.__name__, DateResolverDialog.datetime_prompt_validator) date_time_prompt.telemetry_client = telemetry_client waterfall_dialog = WaterfallDialog( WaterfallDialog.__name__ + '2', [self.initial_step, self.final_step]) waterfall_dialog.telemetry_client = telemetry_client self.add_dialog(date_time_prompt) self.add_dialog(waterfall_dialog) self.initial_dialog_id = WaterfallDialog.__name__ + '2'
def __init__( self, bing_spell_check_subscription_key: str = None, include_all_intents: bool = None, include_instance_data: bool = None, log: bool = None, spell_check: bool = None, staging: bool = None, timeout: float = 100000, timezone_offset: float = None, telemetry_client: BotTelemetryClient = NullTelemetryClient(), log_personal_information: bool = False, ): self.bing_spell_check_subscription_key: str = bing_spell_check_subscription_key self.include_all_intents: bool = include_all_intents self.include_instance_data: bool = include_instance_data self.log: bool = log self.spell_check: bool = spell_check self.staging: bool = staging self.timeout: float = timeout self.timezone_offset: float = timezone_offset self.telemetry_client: BotTelemetryClient = telemetry_client self.log_personal_information: bool = log_personal_information
def __init__(self, dialog_id: str): if dialog_id is None or not dialog_id.strip(): raise TypeError("Dialog(): dialogId cannot be None.") self._telemetry_client = NullTelemetryClient() self._id = dialog_id
async def test_create_middleware(self): telemetry = NullTelemetryClient() my_logger = TelemetryLoggerMiddleware(telemetry, True) assert my_logger