Removed old intent process for RESTAPI and started working on wikipedia skill
This commit is contained in:
parent
6e28b7076e
commit
1695cd2903
@ -2,11 +2,12 @@ import flask
|
|||||||
import lingua_franca
|
import lingua_franca
|
||||||
from flask import Flask, request, jsonify, Response
|
from flask import Flask, request, jsonify, Response
|
||||||
|
|
||||||
from jarvis.ia import process
|
|
||||||
from jarvis.skills import intent_manager
|
from jarvis.skills import intent_manager
|
||||||
|
from jarvis.skills.entertainement.jokes import JokesSkill
|
||||||
from jarvis.skills.entertainement.spotify import SpotifySkill
|
from jarvis.skills.entertainement.spotify import SpotifySkill
|
||||||
|
from jarvis.skills.research.wikipedia import WikipediaSkill
|
||||||
from jarvis.utils import languages_utils
|
from jarvis.utils import languages_utils
|
||||||
from utils import config_utils, flask_utils, intents_utils, utils
|
from utils import config_utils, flask_utils, utils
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
@ -18,21 +19,7 @@ def process_request():
|
|||||||
if 'sentence' not in data or not data['sentence']:
|
if 'sentence' not in data or not data['sentence']:
|
||||||
flask.abort(Response('You must provide a \'sentence\' parameter (not empty aswell)!'))
|
flask.abort(Response('You must provide a \'sentence\' parameter (not empty aswell)!'))
|
||||||
|
|
||||||
sentence = data['sentence']
|
return {}
|
||||||
tag_for_request = process.get_tag_for_sentence(sentence)
|
|
||||||
|
|
||||||
print("SENTENCE : " + sentence + " /// TAG : " + tag_for_request)
|
|
||||||
|
|
||||||
# stop here if the sentence isn't understood
|
|
||||||
if tag_for_request == 'dont_understand':
|
|
||||||
return jsonify("I didn't get that.")
|
|
||||||
|
|
||||||
path_of_intent = intents_utils.get_path(tag_for_request)
|
|
||||||
path_of_intent = path_of_intent.split('/skills/')[1].replace('/', '.')
|
|
||||||
path_of_intent = "skills." + path_of_intent + "intent"
|
|
||||||
|
|
||||||
method = utils.import_method_from_string(path_of_intent, tag_for_request)
|
|
||||||
return jsonify(method())
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
@ -41,17 +28,19 @@ if __name__ == '__main__':
|
|||||||
lingua_franca.load_language(lang=languages_utils.get_language().split("-")[0])
|
lingua_franca.load_language(lang=languages_utils.get_language().split("-")[0])
|
||||||
|
|
||||||
# Tests
|
# Tests
|
||||||
# WikipediaSkill().register()
|
WikipediaSkill().register()
|
||||||
# JokesSkill().register()
|
JokesSkill().register()
|
||||||
SpotifySkill().register()
|
SpotifySkill().register()
|
||||||
|
|
||||||
intent_manager.process_handlers()
|
intent_manager.process_handlers()
|
||||||
|
|
||||||
# intent_manager.recognise("cherche sur wikipedia Elon Musk") # TO CHECK
|
intent_manager.recognise("cherche sur wikipédia Elon Musk") # TO CHECK
|
||||||
|
intent_manager.recognise("c'est qui Elon Musk") # TO CHECK
|
||||||
|
intent_manager.recognise("cherche Elon Musk sur wikipédia") # TO CHECK
|
||||||
# intent_manager.recognise("raconte moi une blague") # WORKING
|
# intent_manager.recognise("raconte moi une blague") # WORKING
|
||||||
# intent_manager.recognise("joue le morceau crazy crazy nights de KISS sur spotify") # WORKING
|
# intent_manager.recognise("joue le morceau crazy crazy nights de KISS sur spotify") # WORKING
|
||||||
# intent_manager.recognise("coupe la musique") # WORKING
|
# intent_manager.recognise("coupe la musique") # WORKING
|
||||||
intent_manager.recognise("c'est quoi le nom de cette chanson ?")
|
# intent_manager.recognise("c'est quoi le nom de cette chanson ?") # WORKING
|
||||||
|
|
||||||
# start the flask server
|
# start the flask server
|
||||||
app.config['JSON_AS_ASCII'] = False
|
app.config['JSON_AS_ASCII'] = False
|
||||||
|
@ -35,9 +35,9 @@ class SpotifySkill(Skill, metaclass=SkillRegistering):
|
|||||||
song_name = current_playback['item']['name']
|
song_name = current_playback['item']['name']
|
||||||
artist = current_playback['item']['artists'][0]['name']
|
artist = current_playback['item']['artists'][0]['name']
|
||||||
|
|
||||||
print(song_name + " from " + artist)
|
print("[INFO INTENT] - Current playback : " + song_name + " from " + artist + " on Spotify")
|
||||||
|
else:
|
||||||
print("[INFO INTENT] - Current playback : music for Spotify")
|
print("Nothing is playing")
|
||||||
|
|
||||||
|
|
||||||
def create_skill():
|
def create_skill():
|
||||||
|
@ -1,15 +1,14 @@
|
|||||||
from adapt.intent import IntentBuilder
|
|
||||||
|
|
||||||
from jarvis.skills import Skill, SkillRegistering
|
from jarvis.skills import Skill, SkillRegistering
|
||||||
from jarvis.skills.decorators import intent_handler
|
from jarvis.skills.decorators import intent_file_handler
|
||||||
|
|
||||||
|
|
||||||
class WikipediaSkill(Skill, metaclass=SkillRegistering):
|
class WikipediaSkill(Skill, metaclass=SkillRegistering):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__("WikipediaSkill")
|
super().__init__("WikipediaSkill")
|
||||||
|
|
||||||
@intent_handler(IntentBuilder("WikipediaQueryIntent").require("Wikipedia").require("ArticleTitle"))
|
@intent_file_handler("search.wikipedia.intent", "WikipediaQueryIntent")
|
||||||
def handle_wikipedia_query_intent(self, data):
|
def handle_wikipedia_query_intent(self, data):
|
||||||
|
print(data)
|
||||||
print("Handle Wikipedia Query Intent Method")
|
print("Handle Wikipedia Query Intent Method")
|
||||||
|
|
||||||
|
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
Chercher {query} sur wikipédia
|
||||||
|
C'est qui {query}
|
||||||
|
Donne moi plus d'infos sur {query}
|
||||||
|
C'est quoi {query}
|
||||||
|
Cherche sur wikipédia {query}
|
||||||
|
Cherche {query} sur wikipédia
|
Reference in New Issue
Block a user