Replace old joke skill by new one and a few tests in main.py
This commit is contained in:
parent
5d7ff0c15c
commit
a3e1da051b
@ -3,6 +3,7 @@ from flask import Flask, request, jsonify, Response
|
||||
|
||||
from jarvis.ia import process
|
||||
from jarvis.skills import intent_manager
|
||||
from jarvis.skills.entertainement.jokes import JokesSkill
|
||||
from jarvis.skills.research.wikipedia import WikipediaSkill
|
||||
from utils import config_utils, flask_utils, intents_utils, utils
|
||||
|
||||
@ -36,10 +37,12 @@ def process_request():
|
||||
if __name__ == '__main__':
|
||||
# Tests
|
||||
WikipediaSkill().register()
|
||||
JokesSkill().register()
|
||||
|
||||
intent_manager.process_handlers()
|
||||
|
||||
intent_manager.recognise("cherche sur wikipedia Elon Musk")
|
||||
intent_manager.recognise("raconte moi une blague")
|
||||
|
||||
# start the flask server
|
||||
app.config['JSON_AS_ASCII'] = False
|
||||
|
@ -0,0 +1,41 @@
|
||||
import requests
|
||||
from adapt.intent import IntentBuilder
|
||||
|
||||
from jarvis.skills import Skill, SkillRegistering
|
||||
from jarvis.skills.decorators import intent_handler
|
||||
from jarvis.utils import languages_utils, config_utils
|
||||
|
||||
|
||||
def speak_joke():
|
||||
# french jokes
|
||||
if languages_utils.get_language().startswith("fr-"):
|
||||
# please register on www.blagues-api.fr and set a token in your secret
|
||||
response = requests.get('https://www.blagues-api.fr/api/random', headers={
|
||||
'Authorization': 'Bearer ' + config_utils.get_in_secret('JOKES_FRENCH_API_TOKEN')})
|
||||
|
||||
data = response.json()
|
||||
joke = data['joke']
|
||||
answer = data['answer']
|
||||
|
||||
return joke + " /pause:2s/ " + answer
|
||||
|
||||
# english jokes
|
||||
elif languages_utils.get_language().startswith("en-"):
|
||||
response = requests.get('https://v2.jokeapi.dev/joke/Any?type=twopart')
|
||||
data = response.json()
|
||||
|
||||
joke = data['setup']
|
||||
answer = data['delivery']
|
||||
|
||||
return joke + " /pause:2s/ " + answer
|
||||
else:
|
||||
return "I don't know any jokes in your language..."
|
||||
|
||||
|
||||
class JokesSkill(Skill, metaclass=SkillRegistering):
|
||||
def __init__(self):
|
||||
super().__init__("JokesSkill")
|
||||
|
||||
@intent_handler(IntentBuilder("JokingIntent").require("Joke"))
|
||||
def handle_joke(self, data):
|
||||
print(speak_joke())
|
@ -1,10 +0,0 @@
|
||||
{
|
||||
"name": "Jokes",
|
||||
"languages": [
|
||||
"FR-FR",
|
||||
"EN-EN"
|
||||
],
|
||||
"intents": [
|
||||
"tell_me_a_joke"
|
||||
]
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
import requests as requests
|
||||
|
||||
from jarvis.utils import languages_utils, config_utils
|
||||
|
||||
|
||||
def tell_me_a_joke():
|
||||
tag = 'tell_me_a_joke'
|
||||
# response = intents_utils.get_response(tag)
|
||||
|
||||
# french jokes
|
||||
if languages_utils.get_language().startswith("fr-"):
|
||||
|
||||
# please register on www.blagues-api.fr and set a token in your secret
|
||||
response = requests.get(
|
||||
'https://www.blagues-api.fr/api/random',
|
||||
headers={
|
||||
'Authorization': 'Bearer ' + config_utils.get_in_secret('JOKES_FRENCH_API_TOKEN')
|
||||
}
|
||||
)
|
||||
|
||||
data = response.json()
|
||||
joke = data['joke']
|
||||
answer = data['answer']
|
||||
|
||||
return joke + " /pause:2s/ " + answer
|
||||
|
||||
# english jokes
|
||||
elif languages_utils.get_language().startswith("en-"):
|
||||
response = requests.get('https://v2.jokeapi.dev/joke/Any?type=twopart')
|
||||
data = response.json()
|
||||
|
||||
joke = data['setup']
|
||||
answer = data['delivery']
|
||||
|
||||
return joke + " /pause:2s/ " + answer
|
||||
else:
|
||||
return "I don't know any jokes in your language..."
|
@ -1,11 +0,0 @@
|
||||
{
|
||||
"tell_me_a_joke": {
|
||||
"patterns": [
|
||||
"Tell me a joke",
|
||||
"Make me laugh",
|
||||
"Brighten my day"
|
||||
],
|
||||
"responses": [
|
||||
]
|
||||
}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
{
|
||||
"tell_me_a_joke": {
|
||||
"patterns": [
|
||||
"raconte moi-voir une blague",
|
||||
"dis moi une blague",
|
||||
"raconte une blague",
|
||||
"fait moi rire",
|
||||
"donne une bonne blague",
|
||||
"raconte moi une blagounette"
|
||||
],
|
||||
"responses": [
|
||||
]
|
||||
}
|
||||
}
|
2
jarvis/skills/entertainement/jokes/vocab/en-en/Chuck.voc
Normal file
2
jarvis/skills/entertainement/jokes/vocab/en-en/Chuck.voc
Normal file
@ -0,0 +1,2 @@
|
||||
chuck
|
||||
chuck norris
|
5
jarvis/skills/entertainement/jokes/vocab/en-en/Joke.voc
Normal file
5
jarvis/skills/entertainement/jokes/vocab/en-en/Joke.voc
Normal file
@ -0,0 +1,5 @@
|
||||
joke
|
||||
jokes
|
||||
make me laugh
|
||||
brighten my day
|
||||
tell me joke
|
@ -0,0 +1,3 @@
|
||||
neutral
|
||||
non-offensive
|
||||
geeky
|
2
jarvis/skills/entertainement/jokes/vocab/fr-fr/Chuck.voc
Normal file
2
jarvis/skills/entertainement/jokes/vocab/fr-fr/Chuck.voc
Normal file
@ -0,0 +1,2 @@
|
||||
chuck
|
||||
chuck norris
|
5
jarvis/skills/entertainement/jokes/vocab/fr-fr/Joke.voc
Normal file
5
jarvis/skills/entertainement/jokes/vocab/fr-fr/Joke.voc
Normal file
@ -0,0 +1,5 @@
|
||||
blague
|
||||
blagues
|
||||
fais moi rire
|
||||
illumine ma journée
|
||||
raconte moi une blague
|
@ -0,0 +1,3 @@
|
||||
neutre
|
||||
non offensant
|
||||
geek
|
Reference in New Issue
Block a user