From 275ca88cb7f643f13ead05725c293d854dde1caa Mon Sep 17 00:00:00 2001 From: miro Date: Tue, 9 Apr 2024 01:24:16 +0100 Subject: [PATCH 1/7] refactor/ui->qt5 drop the old "ui" folder to avoid warning logs --- __init__.py | 2 +- ui/logo.png => logo.png | Bin {ui => qt5}/wolf.qml | 0 scripts/prepare_skillstore.py | 2 +- setup.py | 2 +- 5 files changed, 3 insertions(+), 3 deletions(-) rename ui/logo.png => logo.png (100%) rename {ui => qt5}/wolf.qml (100%) diff --git a/__init__.py b/__init__.py index 3ff3cf4..742ac0c 100644 --- a/__init__.py +++ b/__init__.py @@ -296,7 +296,7 @@ def display_wolfie(self): if image: self.gui["wolfram_image"] = image # scrollable full result page - self.gui.show_page(join(self.root_dir, "ui", "wolf"), override_idle=45) + self.gui.show_page(join(self.root_dir, "qt5", "wolf"), override_idle=45) def stop_session(self, sess): if sess.session_id in self.session_results: diff --git a/ui/logo.png b/logo.png similarity index 100% rename from ui/logo.png rename to logo.png diff --git a/ui/wolf.qml b/qt5/wolf.qml similarity index 100% rename from ui/wolf.qml rename to qt5/wolf.qml diff --git a/scripts/prepare_skillstore.py b/scripts/prepare_skillstore.py index 6dc728a..11d6d3f 100644 --- a/scripts/prepare_skillstore.py +++ b/scripts/prepare_skillstore.py @@ -19,7 +19,7 @@ base_dir = dirname(dirname(__file__)) desktop_dir = join(base_dir, "res", "desktop") -android_ui = join(base_dir, "ui", "+android") +android_ui = join(base_dir, "qt5", "+android") makedirs(desktop_dir, exist_ok=True) readme = join(base_dir, "README.md") diff --git a/setup.py b/setup.py index b0067ef..4f02069 100755 --- a/setup.py +++ b/setup.py @@ -31,7 +31,7 @@ def get_requirements(requirements_filename: str): def find_resource_files(): - resource_base_dirs = ("locale", "ui", "vocab", "dialog", "regex", "skill") + resource_base_dirs = ("locale", "qt5") base_dir = path.dirname(__file__) package_data = ["*.json"] for res in resource_base_dirs: From a84eb19e075ae57761fa2574e400103bc8579c76 Mon Sep 17 00:00:00 2001 From: miro Date: Sun, 21 Apr 2024 03:49:38 +0100 Subject: [PATCH 2/7] feat/units_from_session --- __init__.py | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/__init__.py b/__init__.py index 742ac0c..13744d2 100644 --- a/__init__.py +++ b/__init__.py @@ -28,13 +28,13 @@ class WolframAlphaApi(_WA): - def get_image(self, query): + def get_image(self, query: str, units: str = None): """ query assured to be in self.default_lang return path/url to a single image to acompany spoken_answer """ # TODO - extend backend-client method for picture - units = Configuration().get("system_unit", "metric") + units = units or Configuration().get("system_unit", "metric") url = 'http://api.wolframalpha.com/v1/simple' params = {"appid": self.credentials["wolfram"], "i": query, @@ -123,7 +123,7 @@ def get_data(self, query, context=None): query assured to be in self.default_lang return a dict response """ - units = Configuration().get("system_unit", "metric") + units = context.get("units") or Configuration().get("system_unit", "metric") return self.api.full_results(query, units=units) # image api (simple) @@ -132,7 +132,8 @@ def get_image(self, query, context=None): query assured to be in self.default_lang return path/url to a single image to acompany spoken_answer """ - return self.api.get_image(query) + units = context.get("units") or Configuration().get("system_unit", "metric") + return self.api.get_image(query, units) # spoken answers api (spoken) def get_spoken_answer(self, query, context): @@ -140,7 +141,7 @@ def get_spoken_answer(self, query, context): query assured to be in self.default_lang return a single sentence text response """ - units = Configuration().get("system_unit", "metric") + units = context.get("units") or Configuration().get("system_unit", "metric") answer = self.api.spoken(query, units=units) bad_answers = ["no spoken result available", "wolfram alpha did not understand your input"] @@ -158,7 +159,6 @@ def get_expanded_answer(self, query, context=None): "summary": "speak this", "img": "optional/path/or/url } - """ data = self.get_data(query, context) # these are returned in spoken answer or otherwise unwanted @@ -213,12 +213,12 @@ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.session_results = {} # session_id: {} self.wolfie = WolframAlphaSolver({ - "units": self.config_core['system_unit'], "appid": self.settings.get("api_key") }) @classproperty def runtime_requirements(self): + """this skill requires internet""" return RuntimeRequirements(internet_before_load=True, network_before_load=True, gui_before_load=False, @@ -236,8 +236,10 @@ def handle_search(self, message: Message): sess = SessionManager.get(message) self.session_results[sess.session_id] = {"phrase": query, "image": None, + "lang": sess.lang, + "system_unit": sess.system_unit, "spoken_answer": ""} - response = self.ask_the_wolf(query) + response = self.ask_the_wolf(query, sess.lang, sess.system_unit) if response: self.session_results[sess.session_id]["spoken_answer"] = response self.speak(response) @@ -254,9 +256,11 @@ def CQS_match_query_phrase(self, phrase: str): sess = SessionManager.get() self.session_results[sess.session_id] = {"phrase": phrase, "image": None, + "lang": sess.lang, + "system_unit": sess.system_unit, "spoken_answer": None} - response = self.ask_the_wolf(phrase, sess.lang) + response = self.ask_the_wolf(phrase, sess.lang, sess.system_unit) if response: self.session_results[sess.session_id]["spoken_answer"] = response self.log.debug(f"WolframAlpha response: {response}") @@ -268,7 +272,8 @@ def CQS_action(self, phrase: str, data: dict): self.display_wolfie() # wolfram integration - def ask_the_wolf(self, query: str, lang: str = None): + def ask_the_wolf(self, query: str, lang: str = None, units: str = None): + units = units or self.system_unit lang = lang or self.lang if lang.startswith("en"): self.log.debug(f"skipping auto translation for wolfram alpha, " @@ -278,7 +283,8 @@ def ask_the_wolf(self, query: str, lang: str = None): self.log.info(f"enabling auto translation for wolfram alpha, " f"{lang} is not supported internally") WolframAlphaSolver.enable_tx = True - return self.wolfie.spoken_answer(query, context={"lang": lang}) + return self.wolfie.spoken_answer(query, + context={"lang": lang, "units": units}) def display_wolfie(self): if not can_use_gui(self.bus): @@ -292,11 +298,12 @@ def display_wolfie(self): return image = res.get("image") or self.wolfie.visual_answer(res["phrase"], - context={"lang": self.lang}) + context={"lang": sess.lang, + "units": sess.system_unit}) if image: self.gui["wolfram_image"] = image # scrollable full result page - self.gui.show_page(join(self.root_dir, "qt5", "wolf"), override_idle=45) + self.gui.show_page("wolf", override_idle=45) def stop_session(self, sess): if sess.session_id in self.session_results: From 50c4ffe60df3ce81679d79faebc65758be14bf87 Mon Sep 17 00:00:00 2001 From: miro Date: Sun, 21 Apr 2024 03:52:21 +0100 Subject: [PATCH 3/7] feat/units_from_session --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index fff01f5..0ead123 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ ovos-translate-server-plugin ovos-config>=0.0.12 ovos-utils~=0.0, >=0.0.38 -ovos_workshop~=0.0, >=0.0.15 +ovos_workshop~=0.0, >=0.0.16a25 ovos-plugin-manager \ No newline at end of file From c1efdd484eda8510889a08b1fbf72880207477e9 Mon Sep 17 00:00:00 2001 From: miro Date: Thu, 25 Apr 2024 03:13:24 +0100 Subject: [PATCH 4/7] drop tts_prefs from sessionfix units --- __init__.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/__init__.py b/__init__.py index 13744d2..0cf6c59 100644 --- a/__init__.py +++ b/__init__.py @@ -51,7 +51,7 @@ def get_image(self, query: str, units: str = None): class WolframAlphaSolver(QuestionSolver): priority = 25 - enable_cache = True + enable_cache = False enable_tx = True def __init__(self, config=None): @@ -274,6 +274,9 @@ def CQS_action(self, phrase: str, data: dict): # wolfram integration def ask_the_wolf(self, query: str, lang: str = None, units: str = None): units = units or self.system_unit + if units != "metric": + units = "nonmetric" # what wolfram api expects + lang = lang or self.lang if lang.startswith("en"): self.log.debug(f"skipping auto translation for wolfram alpha, " @@ -315,7 +318,12 @@ def stop_session(self, sess): d = WolframAlphaSkill(bus=FakeBus(), skill_id="fake.wolf") - print(d.ask_the_wolf("what is the speed of light")) + print(d.ask_the_wolf("what is the speed of light", units="nonmetric")) # SI units regardless + # The speed of light has a value of about 300 million meters per second + print(d.ask_the_wolf("how tall is the eiffel tower", units="metric")) + print(d.ask_the_wolf("how tall is the eiffel tower", units="nonmetric")) + # The total height of the Eiffel Tower is 330 meters + # The total height of the Eiffel Tower is about 1083 feet exit() From 96f66813cd7c03dd1f509442c2572b4005f11d4e Mon Sep 17 00:00:00 2001 From: miro Date: Fri, 26 Apr 2024 00:33:44 +0100 Subject: [PATCH 5/7] fix display --- __init__.py | 35 +++++++++++------------------------ 1 file changed, 11 insertions(+), 24 deletions(-) diff --git a/__init__.py b/__init__.py index 0cf6c59..630069d 100644 --- a/__init__.py +++ b/__init__.py @@ -13,7 +13,7 @@ import tempfile from os.path import join, isfile - +from typing import Optional import requests from ovos_backend_client.api import WolframAlphaApi as _WA from ovos_bus_client import Message @@ -21,14 +21,13 @@ from ovos_config import Configuration from ovos_plugin_manager.templates.solvers import QuestionSolver from ovos_utils import classproperty -from ovos_utils.gui import can_use_gui from ovos_utils.process_utils import RuntimeRequirements from ovos_workshop.decorators import intent_handler from ovos_workshop.skills.common_query_skill import CommonQuerySkill, CQSMatchLevel class WolframAlphaApi(_WA): - def get_image(self, query: str, units: str = None): + def get_image(self, query: str, units: Optional[str] = None): """ query assured to be in self.default_lang return path/url to a single image to acompany spoken_answer @@ -269,10 +268,17 @@ def CQS_match_query_phrase(self, phrase: str): def CQS_action(self, phrase: str, data: dict): """ If selected show gui """ - self.display_wolfie() + # generate image for the query after skill was selected for speed + image = self.wolfie.visual_answer(phrase, context=data) + if image: + self.gui["wolfram_image"] = image + # scrollable full result page + self.gui.show_page("wolf", override_idle=45) # wolfram integration - def ask_the_wolf(self, query: str, lang: str = None, units: str = None): + def ask_the_wolf(self, query: str, + lang: Optional[str] = None, + units: Optional[str] = None): units = units or self.system_unit if units != "metric": units = "nonmetric" # what wolfram api expects @@ -289,25 +295,6 @@ def ask_the_wolf(self, query: str, lang: str = None, units: str = None): return self.wolfie.spoken_answer(query, context={"lang": lang, "units": units}) - def display_wolfie(self): - if not can_use_gui(self.bus): - return - - # generate image for the last query this session made - # only after skill was selected for speed - sess = SessionManager.get() - res = self.session_results.get(sess.session_id) - if not res or not res["spoken_response"]: - return - - image = res.get("image") or self.wolfie.visual_answer(res["phrase"], - context={"lang": sess.lang, - "units": sess.system_unit}) - if image: - self.gui["wolfram_image"] = image - # scrollable full result page - self.gui.show_page("wolf", override_idle=45) - def stop_session(self, sess): if sess.session_id in self.session_results: self.session_results.pop(sess.session_id) From f448f05c21aa9ecf186598489b67d5d2dd302205 Mon Sep 17 00:00:00 2001 From: miro Date: Fri, 26 Apr 2024 00:35:59 +0100 Subject: [PATCH 6/7] render logo for attribution --- __init__.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/__init__.py b/__init__.py index 630069d..72c39b7 100644 --- a/__init__.py +++ b/__init__.py @@ -270,10 +270,9 @@ def CQS_action(self, phrase: str, data: dict): """ If selected show gui """ # generate image for the query after skill was selected for speed image = self.wolfie.visual_answer(phrase, context=data) - if image: - self.gui["wolfram_image"] = image - # scrollable full result page - self.gui.show_page("wolf", override_idle=45) + self.gui["wolfram_image"] = image or f"{self.root_dir}/res/logo.png" + # scrollable full result page + self.gui.show_page("wolf", override_idle=45) # wolfram integration def ask_the_wolf(self, query: str, From dbc71696ecfcacedb6ec9c84a30d6175a6b691d1 Mon Sep 17 00:00:00 2001 From: miro Date: Fri, 26 Apr 2024 00:38:10 +0100 Subject: [PATCH 7/7] render logo for attribution --- logo.png => res/logo.png | Bin setup.py | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename logo.png => res/logo.png (100%) diff --git a/logo.png b/res/logo.png similarity index 100% rename from logo.png rename to res/logo.png diff --git a/setup.py b/setup.py index 4f02069..04fddc5 100755 --- a/setup.py +++ b/setup.py @@ -31,7 +31,7 @@ def get_requirements(requirements_filename: str): def find_resource_files(): - resource_base_dirs = ("locale", "qt5") + resource_base_dirs = ("locale", "qt5", "res") base_dir = path.dirname(__file__) package_data = ["*.json"] for res in resource_base_dirs: