class LuisConnect(ActivityHandler): def __init__(self): self.config_reader = ConfigReader() self.configuration = self.config_reader.read_config() self.luis_app_id = self.configuration['LUIS_APP_ID'] self.luis_endpoint_key = self.configuration['LUIS_ENDPOINT_KEY'] self.luis_endpoint = self.configuration['LUIS_ENDPOINT'] self.luis_app = LuisApplication(self.luis_app_id, self.luis_endpoint_key, self.luis_endpoint) self.luis_options = LuisPredictionOptions(include_all_intents=True, include_instance_data=True) self.luis_recognizer = LuisRecognizer( application=self.luis_app, prediction_options=self.luis_options, include_api_results=True) self.luis_util = LuisUtil() self.log = Log() async def on_message_activity(self, turn_context: TurnContext): #weather_info=WeatherInformation() luis_result = await self.luis_recognizer.recognize(turn_context) result = luis_result.properties["luisResult"] out = self.luis_util.luis_result_as_dict(result) print(out) weather = out['topScoringIntent']['intent'] weather = d[weather] #json_str = json.loads((str("hello")).replace("'", "\"")) #weather=weather_info.get_weather_info(json_str.get('entity')) #weather = "i dont have anaswer" self.log.write_log(sessionID='session1', log_message="Bot Says: " + str(weather)) await turn_context.send_activity(f"{weather}")
def __init__(self): self.config_reader = ConfigReader() self.configuration = self.config_reader.read_config() self.luis_app_id = self.configuration['LUIS_APP_ID'] self.luis_endpoint_key = self.configuration['LUIS_ENDPOINT_KEY'] self.luis_endpoint = self.configuration['LUIS_ENDPOINT'] self.luis_app = LuisApplication(self.luis_app_id, self.luis_endpoint_key, self.luis_endpoint) self.luis_options = LuisPredictionOptions(include_all_intents=True, include_instance_data=True) self.luis_recognizer = LuisRecognizer( application=self.luis_app, prediction_options=self.luis_options, include_api_results=True) self.luis_util = LuisUtil() self.log = Log()
async def _test_json_v3(self, response_file: str) -> None: # Arrange expected_json = LuisRecognizerV3Test._get_json_for_file(response_file) response_json = expected_json["v3"]["response"] utterance = expected_json.get("text") if utterance is None: utterance = expected_json.get("Text") test_options = expected_json["v3"]["options"] options = LuisRecognizerOptionsV3( include_all_intents=test_options["includeAllIntents"], include_instance_data=test_options["includeInstanceData"], log=test_options["log"], prefer_external_entities=test_options["preferExternalEntities"], slot=test_options["slot"], include_api_results=test_options["includeAPIResults"], ) if "version" in test_options: options.version = test_options["version"] if "externalEntities" in test_options: options.external_entities = test_options["externalEntities"] # dynamic_lists: List = None, # external_entities: List = None, # telemetry_client: BotTelemetryClient = NullTelemetryClient(), # log_personal_information: bool = False,) # , # Act _, result = await LuisRecognizerV3Test._get_recognizer_result( utterance, response_json, options=options, include_api_results=True) # Assert actual_result_json = LuisUtil.recognizer_result_as_dict(result) del expected_json["v3"] trimmed_expected = LuisRecognizerV3Test._remove_none_property( expected_json) trimmed_actual = LuisRecognizerV3Test._remove_none_property( actual_result_json) self.assertEqual(trimmed_expected, trimmed_actual)
async def _test_json(self, response_file: str) -> None: # Arrange expected_json = LuisRecognizerTest._get_json_for_file(response_file) response_json = expected_json["luisResult"] utterance = expected_json.get("text") if utterance is None: utterance = expected_json.get("Text") options = LuisPredictionOptions(include_all_intents=True) # Act _, result = await LuisRecognizerTest._get_recognizer_result( utterance, response_json, options=options, include_api_results=True ) # Assert actual_result_json = LuisUtil.recognizer_result_as_dict(result) trimmed_expected = LuisRecognizerTest._remove_none_property(expected_json) trimmed_actual = LuisRecognizerTest._remove_none_property(actual_result_json) self.assertEqual(trimmed_expected, trimmed_actual)
async def _emit_trace_info( self, turn_context: TurnContext, luis_result, recognizer_result: RecognizerResult, options: LuisRecognizerOptionsV3, ) -> None: trace_info: Dict[str, object] = { "recognizerResult": LuisUtil.recognizer_result_as_dict(recognizer_result), "luisModel": {"ModelID": self._application.application_id}, "luisOptions": {"Slot": options.slot}, "luisResult": luis_result, } trace_activity = ActivityUtil.create_trace( turn_context.activity, "LuisRecognizer", trace_info, LuisRecognizerV3.luis_trace_type, LuisRecognizerV3.luis_trace_label, ) await turn_context.send_activity(trace_activity)