async def _recognize_internal( self, turn_context: TurnContext, telemetry_properties: Dict[str, str], telemetry_metrics: Dict[str, float], ) -> RecognizerResult: BotAssert.context_not_null(turn_context) if turn_context.activity.type != ActivityTypes.message: return None utterance: str = turn_context.activity.text if turn_context.activity is not None else None recognizer_result: RecognizerResult = None luis_result: LuisResult = None if not utterance or utterance.isspace(): recognizer_result = RecognizerResult( text=utterance, intents={"": IntentScore(score=1.0)}, entities={}) else: luis_result = self._runtime.prediction.resolve( self._application.application_id, utterance, timezone_offset=self._options.timezone_offset, verbose=self._options.include_all_intents, staging=self._options.staging, spell_check=self._options.spell_check, bing_spell_check_subscription_key=self._options. bing_spell_check_subscription_key, log=self._options.log if self._options.log is not None else True, ) recognizer_result = RecognizerResult( text=utterance, altered_text=luis_result.altered_query, intents=LuisUtil.get_intents(luis_result), entities=LuisUtil.extract_entities_and_metadata( luis_result.entities, luis_result.composite_entities, self._options.include_instance_data if self._options.include_instance_data is not None else True, ), ) LuisUtil.add_properties(luis_result, recognizer_result) if self._include_api_results: recognizer_result.properties["luisResult"] = luis_result # Log telemetry self.on_recognizer_result(recognizer_result, turn_context, telemetry_properties, telemetry_metrics) await self._emit_trace_info(turn_context, luis_result, recognizer_result) return recognizer_result
async def create_context(self, turn_context: TurnContext) -> DialogContext: BotAssert.context_not_none(turn_context) if not self._dialog_state: raise RuntimeError("DialogSet.CreateContextAsync(): DialogSet created with a null IStatePropertyAccessor.") state = await self._dialog_state.get(turn_context, lambda: DialogState()) return DialogContext(self, turn_context, state)
async def create_context(self, turn_context: TurnContext) -> "DialogContext": # This import prevents circular dependency issues # pylint: disable=import-outside-toplevel from .dialog_context import DialogContext # pylint: disable=unnecessary-lambda BotAssert.context_not_none(turn_context) if not self._dialog_state: raise RuntimeError( "DialogSet.CreateContextAsync(): DialogSet created with a null IStatePropertyAccessor." ) state: DialogState = await self._dialog_state.get( turn_context, lambda: DialogState()) return DialogContext(self, turn_context, state)
async def _recognize_internal( self, turn_context: TurnContext, telemetry_properties: Dict[str, str], telemetry_metrics: Dict[str, float], luis_prediction_options: Union[LuisPredictionOptions, LuisRecognizerOptionsV2, LuisRecognizerOptionsV3] = None, ) -> RecognizerResult: BotAssert.context_not_none(turn_context) if turn_context.activity.type != ActivityTypes.message: return None utterance: str = turn_context.activity.text if turn_context.activity is not None else None recognizer_result: RecognizerResult = None if luis_prediction_options: options = luis_prediction_options else: options = self._options if not utterance or utterance.isspace(): recognizer_result = RecognizerResult( text=utterance, intents={"": IntentScore(score=1.0)}, entities={}) else: luis_recognizer = self._build_recognizer(options) recognizer_result = await luis_recognizer.recognizer_internal( turn_context) # Log telemetry self.on_recognizer_result(recognizer_result, turn_context, telemetry_properties, telemetry_metrics) return recognizer_result