Added wolfram-alpha fallback
This commit is contained in:
parent
3c95978fc9
commit
6284b7c2ab
@ -3,7 +3,8 @@ import json
|
|||||||
from adapt.engine import DomainIntentDeterminationEngine
|
from adapt.engine import DomainIntentDeterminationEngine
|
||||||
from padatious import IntentContainer
|
from padatious import IntentContainer
|
||||||
|
|
||||||
from jarvis.utils import utils
|
from jarvis.utils import utils, client_utils
|
||||||
|
from jarvis.utils.fallbacks.wolframalpha import wa_client
|
||||||
|
|
||||||
adapt_engine = DomainIntentDeterminationEngine()
|
adapt_engine = DomainIntentDeterminationEngine()
|
||||||
padatious_intents_container = IntentContainer('intent_cache')
|
padatious_intents_container = IntentContainer('intent_cache')
|
||||||
@ -104,6 +105,14 @@ def recognise(sentence, client_ip=None, client_port=None):
|
|||||||
confidence_padatious = get_confidence(best_intent_padatious)
|
confidence_padatious = get_confidence(best_intent_padatious)
|
||||||
|
|
||||||
if confidence_adapt < 0.2 and confidence_padatious < 0.2:
|
if confidence_adapt < 0.2 and confidence_padatious < 0.2:
|
||||||
|
|
||||||
|
# Wolfram-Alpha Fallback
|
||||||
|
wolfram_response = wa_client.ask(data['utterance'])
|
||||||
|
if wolfram_response is not None:
|
||||||
|
client_utils.speak(wolfram_response, client_ip, client_port)
|
||||||
|
return wolfram_response
|
||||||
|
else:
|
||||||
|
# Nothing found at all
|
||||||
return "I didn't understand..."
|
return "I didn't understand..."
|
||||||
else:
|
else:
|
||||||
return handle_intent(data,
|
return handle_intent(data,
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
from jarvis.skills import Skill, SkillRegistering
|
from jarvis.skills import Skill, SkillRegistering
|
||||||
from jarvis.skills.decorators import intent_file_handler
|
from jarvis.skills.decorators import intent_file_handler
|
||||||
from jarvis.skills.research.wikipedia import wikipedia
|
from jarvis.skills.research.wikipedia import wikipedia
|
||||||
|
from jarvis.utils.fallbacks.wolframalpha import wa_client
|
||||||
|
|
||||||
|
|
||||||
class WikipediaSkill(Skill, metaclass=SkillRegistering):
|
class WikipediaSkill(Skill, metaclass=SkillRegistering):
|
||||||
@ -10,11 +11,11 @@ class WikipediaSkill(Skill, metaclass=SkillRegistering):
|
|||||||
@intent_file_handler("search.wikipedia.intent", "WikipediaQueryIntent")
|
@intent_file_handler("search.wikipedia.intent", "WikipediaQueryIntent")
|
||||||
def handle_wikipedia_query_intent(self, data):
|
def handle_wikipedia_query_intent(self, data):
|
||||||
if 'query' in data:
|
if 'query' in data:
|
||||||
self.speak_dialog_threaded("wikipedia_searching")
|
self.speak(wikipedia.page_summary(query=data['query']))
|
||||||
print("[INTENT RESULT] : " + wikipedia.page_summary(query=data['query']))
|
|
||||||
else:
|
else:
|
||||||
# TODO: fallback to duckduckgo or wolfram alpha
|
wolfram_response = wa_client.ask(data['utterance'])
|
||||||
pass
|
if wolfram_response is not None:
|
||||||
|
self.speak(wolfram_response)
|
||||||
|
|
||||||
|
|
||||||
def create_skill(data):
|
def create_skill(data):
|
||||||
|
0
jarvis/utils/fallbacks/__init__.py
Normal file
0
jarvis/utils/fallbacks/__init__.py
Normal file
22
jarvis/utils/fallbacks/wolframalpha/wa_client.py
Normal file
22
jarvis/utils/fallbacks/wolframalpha/wa_client.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import urllib.parse
|
||||||
|
|
||||||
|
import requests
|
||||||
|
|
||||||
|
from jarvis.utils import config_utils
|
||||||
|
|
||||||
|
|
||||||
|
def ask(sentence):
|
||||||
|
query = urllib.parse.quote_plus(sentence)
|
||||||
|
query_url = f"https://api.wolframalpha.com/v2/query?" \
|
||||||
|
f"appid={config_utils.get_in_secret('WOLFRAM_APP_ID')}" \
|
||||||
|
f"&input={query}" \
|
||||||
|
f"&format=plaintext" \
|
||||||
|
f"&output=json"
|
||||||
|
|
||||||
|
r = requests.get(query_url).json()
|
||||||
|
|
||||||
|
if r['queryresult']['success']:
|
||||||
|
data = r["queryresult"]["pods"][1]["subpods"][0]
|
||||||
|
return data['plaintext']
|
||||||
|
else:
|
||||||
|
return None
|
Reference in New Issue
Block a user