From 999cebd66b2da161d838bcabf915706935302ba5 Mon Sep 17 00:00:00 2001 From: Daniel McKnight <34697904+NeonDaniel@users.noreply.github.com> Date: Mon, 8 Jan 2024 17:43:51 -0800 Subject: [PATCH] Update to handle missing resource in CQS handler (#43) Co-authored-by: Daniel McKnight --- __init__.py | 118 +++++++++++++++++++++++++++------------------------- 1 file changed, 61 insertions(+), 57 deletions(-) diff --git a/__init__.py b/__init__.py index 81e1e56..c22bff2 100644 --- a/__init__.py +++ b/__init__.py @@ -90,67 +90,71 @@ def email(self): return self.settings.get("email") or "developers@neon.ai" def CQS_match_query_phrase(self, phrase, message): - if not self.voc_match(phrase, 'you'): - return None - if self.voc_match(phrase, 'born'): - if self.voc_match(phrase, 'when'): - match_level = CQSMatchLevel.EXACT - dialog = self.dialog_renderer.render( - "when_was_i_born", {"year": self.year_born}) - elif self.voc_match(phrase, 'where'): + try: + if not self.voc_match(phrase, 'you'): + return None + if self.voc_match(phrase, 'born'): + if self.voc_match(phrase, 'when'): + match_level = CQSMatchLevel.EXACT + dialog = self.dialog_renderer.render( + "when_was_i_born", {"year": self.year_born}) + elif self.voc_match(phrase, 'where'): + match_level = CQSMatchLevel.EXACT + dialog = self.dialog_renderer.render( + "where_was_i_born", {"birthplace": self.birthplace}) + else: + LOG.debug(f"handling as birthday request: {phrase}") + match_level = CQSMatchLevel.CATEGORY + dialog = self.dialog_renderer.render( + "when_was_i_born", {"year": self.year_born}) + return phrase, match_level, dialog, {} + if self.voc_match(phrase, 'made'): + if self.voc_match(phrase, 'who'): + match_level = CQSMatchLevel.EXACT + dialog = self.dialog_renderer.render( + "who_made_me", {"creator": self.creator}) + elif self.voc_match(phrase, 'when'): + match_level = CQSMatchLevel.EXACT + dialog = self.dialog_renderer.render( + "when_was_i_born", {"year": self.year_born}) + else: + LOG.debug(f"ignoring query: {phrase}") + return None + return phrase, match_level, dialog, {} + if self.voc_match(phrase, 'are'): match_level = CQSMatchLevel.EXACT + if self.voc_match(phrase, 'who'): + dialog = self.dialog_renderer.render( + "who_am_i", {"name": self.ai_name}) + elif self.voc_match(phrase, 'what'): + dialog = self.dialog_renderer.render( + "what_am_i", {"name": self.ai_name}) + elif self.voc_match(phrase, 'how'): + dialog = self.dialog_renderer.render("how_am_i") + elif self.voc_match(phrase, 'where'): + dialog = self.dialog_renderer.render("where_am_i") + else: + LOG.debug(f"ignoring query: {phrase}") + return None + return phrase, match_level, dialog, {} + if self.voc_match(phrase, 'email'): + if self.voc_match(phrase, 'what'): + match_level = CQSMatchLevel.EXACT + else: + match_level = CQSMatchLevel.CATEGORY dialog = self.dialog_renderer.render( - "where_was_i_born", {"birthplace": self.birthplace}) - else: - LOG.debug(f"handling as birthday request: {phrase}") + "my_email_address", {"email": self.email} + ) + return phrase, match_level, dialog, {} + if self.voc_match(phrase, 'name'): match_level = CQSMatchLevel.CATEGORY dialog = self.dialog_renderer.render( - "when_was_i_born", {"year": self.year_born}) - return phrase, match_level, dialog, {} - if self.voc_match(phrase, 'made'): - if self.voc_match(phrase, 'who'): - match_level = CQSMatchLevel.EXACT - dialog = self.dialog_renderer.render( - "who_made_me", {"creator": self.creator}) - elif self.voc_match(phrase, 'when'): - match_level = CQSMatchLevel.EXACT - dialog = self.dialog_renderer.render( - "when_was_i_born", {"year": self.year_born}) - else: - LOG.debug(f"ignoring query: {phrase}") - return None - return phrase, match_level, dialog, {} - if self.voc_match(phrase, 'are'): - match_level = CQSMatchLevel.EXACT - if self.voc_match(phrase, 'who'): - dialog = self.dialog_renderer.render( - "who_am_i", {"name": self.ai_name}) - elif self.voc_match(phrase, 'what'): - dialog = self.dialog_renderer.render( - "what_am_i", {"name": self.ai_name}) - elif self.voc_match(phrase, 'how'): - dialog = self.dialog_renderer.render("how_am_i") - elif self.voc_match(phrase, 'where'): - dialog = self.dialog_renderer.render("where_am_i") - else: - LOG.debug(f"ignoring query: {phrase}") - return None - return phrase, match_level, dialog, {} - if self.voc_match(phrase, 'email'): - if self.voc_match(phrase, 'what'): - match_level = CQSMatchLevel.EXACT - else: - match_level = CQSMatchLevel.CATEGORY - dialog = self.dialog_renderer.render( - "my_email_address", {"email": self.email} - ) - return phrase, match_level, dialog, {} - if self.voc_match(phrase, 'name'): - match_level = CQSMatchLevel.CATEGORY - dialog = self.dialog_renderer.render( - "my_name", {"position": self.translate('word_name'), - "name": self.ai_name}) - return phrase, match_level, dialog, {} + "my_name", {"position": self.translate('word_name'), + "name": self.ai_name}) + return phrase, match_level, dialog, {} + except FileNotFoundError as e: + LOG.warning(f"Missing resource for lang: {self.lang} - {e}") + return None @intent_file_handler("WhenWereYouBorn.intent") def handle_when_were_you_born(self, message):