Skip to content

Commit

Permalink
make a property
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl authored Aug 22, 2023
1 parent 276a075 commit f836e54
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
class WolframAlphaSkill(CommonQuerySkill):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.wolfie = None
# continuous dialog, "tell me more"
self.idx = 0
self.last_query = None
Expand Down Expand Up @@ -53,14 +52,19 @@ def __init__(self, *args, **kwargs):
'Scrabble score', # spammy
'Other notable uses' # spammy
]

@property
def wolfie(self):
# property to allow api key changes in config
try:
self.wolfie = WolframAlphaSolver({
return WolframAlphaSolver({
"units": self.config_core['system_unit'],
"appid": self.settings.get("api_key")
})
except Exception as err:
self.log.error("WolframAlphaSkill failed to initialize: %s", err)

return None

@classproperty
def runtime_requirements(self):
return RuntimeRequirements(internet_before_load=True,
Expand All @@ -85,12 +89,12 @@ def handle_search(self, message: Message):

@intent_handler(IntentBuilder("WolfieMore").require("More").
require("WolfieKnows"))
def handle_tell_more(self, _):
def handle_tell_more(self, message: Message):
""" Follow up query handler, "tell me more"."""
self.speak_result()

# common query integration
def CQS_match_query_phrase(self, phrase):
def CQS_match_query_phrase(self, phrase: str):
self.log.debug("WolframAlpha query: " + phrase)
if self.wolfie is None:
self.log.error("WolframAlphaSkill not initialized, no response")
Expand All @@ -102,12 +106,12 @@ def CQS_match_query_phrase(self, phrase):
return (phrase, CQSMatchLevel.GENERAL, response,
{'query': phrase, 'answer': response})

def CQS_action(self, phrase, data):
def CQS_action(self, phrase: str, data: dict):
""" If selected show gui """
self.display_wolfie()

# wolfram integration
def ask_the_wolf(self, query):
def ask_the_wolf(self, query: str):
# context for follow up questions
self.set_context("WolfieKnows", query)
results = self.wolfie.long_answer(query,
Expand Down

0 comments on commit f836e54

Please sign in to comment.