Added jokes
This commit is contained in:
parent
db13666d57
commit
53da5409b4
Binary file not shown.
0
intents/entertainement/__init__.py
Normal file
0
intents/entertainement/__init__.py
Normal file
0
intents/entertainement/jokes/__init__.py
Normal file
0
intents/entertainement/jokes/__init__.py
Normal file
10
intents/entertainement/jokes/info.json
Normal file
10
intents/entertainement/jokes/info.json
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"name": "Jokes",
|
||||||
|
"languages": [
|
||||||
|
"FR-FR",
|
||||||
|
"EN-EN"
|
||||||
|
],
|
||||||
|
"intents": [
|
||||||
|
"tell_me_a_joke"
|
||||||
|
]
|
||||||
|
}
|
36
intents/entertainement/jokes/intent.py
Normal file
36
intents/entertainement/jokes/intent.py
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
import requests as requests
|
||||||
|
|
||||||
|
from utils import config_utils
|
||||||
|
|
||||||
|
|
||||||
|
def tell_me_a_joke():
|
||||||
|
tag = 'tell_me_a_joke'
|
||||||
|
# response = intents_utils.get_response(tag)
|
||||||
|
|
||||||
|
# french jokes
|
||||||
|
if config_utils.get_in_config("LANGUAGE").startswith("fr-"):
|
||||||
|
# the token used might be revoked at any time, please register on www.blagues-api.fr and replace it
|
||||||
|
response = requests.get(
|
||||||
|
'https://www.blagues-api.fr/api/random',
|
||||||
|
headers={
|
||||||
|
'Authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiNzA4OTcyNzQwOTQ5ODM1ODI2IiwibGltaXQiOjEwMCwia2V5IjoiYmZlUVBSb2xuY2FleHBHc2taRU90VkdKOGxhdWZsZVRSMFJadnR3QXV3c056djdpYlkiLCJjcmVhdGVkX2F0IjoiMjAyMS0wNS0yOVQxNDoyMjo0MCswMDowMCIsImlhdCI6MTYyMjI5ODE2MH0.6VxH_dTdJSddhHoYOtdQl0j9WC3lzXjUujUio5U09Jg'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
data = response.json()
|
||||||
|
joke = data['joke']
|
||||||
|
answer = data['answer']
|
||||||
|
|
||||||
|
return joke + " /pause:2s/ " + answer
|
||||||
|
|
||||||
|
# english jokes
|
||||||
|
elif config_utils.get_in_config("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..."
|
11
intents/entertainement/jokes/lang/en-en.json
Normal file
11
intents/entertainement/jokes/lang/en-en.json
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"tell_me_a_joke": {
|
||||||
|
"patterns": [
|
||||||
|
"Tell me a joke",
|
||||||
|
"Make me laugh",
|
||||||
|
"Brighten my day"
|
||||||
|
],
|
||||||
|
"responses": [
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
14
intents/entertainement/jokes/lang/fr-fr.json
Normal file
14
intents/entertainement/jokes/lang/fr-fr.json
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"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": [
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
@ -3,3 +3,4 @@ Unidecode~=1.2.0
|
|||||||
nltk~=3.6.2
|
nltk~=3.6.2
|
||||||
torch~=1.9.0
|
torch~=1.9.0
|
||||||
numpy~=1.21.1
|
numpy~=1.21.1
|
||||||
|
requests~=2.26.0
|
61
utils/client_utils.py
Normal file
61
utils/client_utils.py
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
import json
|
||||||
|
|
||||||
|
import requests
|
||||||
|
from requests.structures import CaseInsensitiveDict
|
||||||
|
|
||||||
|
from utils import config_utils
|
||||||
|
|
||||||
|
client_url = config_utils.get_in_config("CLIENT_URL")
|
||||||
|
|
||||||
|
|
||||||
|
def ask_for_microphone_output(record_for_seconds, speech_before_input):
|
||||||
|
data = {
|
||||||
|
'record_for_seconds': record_for_seconds,
|
||||||
|
'speech_before_input': speech_before_input
|
||||||
|
}
|
||||||
|
|
||||||
|
call_client_api("POST", "/record", json.dumps(data))
|
||||||
|
|
||||||
|
|
||||||
|
def ask_for_input(listen_for_seconds, speech_before_input):
|
||||||
|
data = {
|
||||||
|
'listen_for_seconds': listen_for_seconds,
|
||||||
|
'speech_before_input': speech_before_input
|
||||||
|
}
|
||||||
|
|
||||||
|
call_client_api("POST", "/input", json.dumps(data))
|
||||||
|
|
||||||
|
|
||||||
|
def speak(speech):
|
||||||
|
data = {
|
||||||
|
'speech': speech
|
||||||
|
}
|
||||||
|
call_client_api("POST", "/speak", data)
|
||||||
|
|
||||||
|
|
||||||
|
def sound(sound_name):
|
||||||
|
data = {
|
||||||
|
'sound_name': sound_name
|
||||||
|
}
|
||||||
|
call_client_api("POST", "/sound", data)
|
||||||
|
|
||||||
|
|
||||||
|
def call_client_api(method, url, json_data=None):
|
||||||
|
if json_data is None:
|
||||||
|
json_data = {}
|
||||||
|
|
||||||
|
try:
|
||||||
|
url_service = client_url + url
|
||||||
|
|
||||||
|
headers = CaseInsensitiveDict()
|
||||||
|
headers["Authorization"] = config_utils.get_in_config("API_KEY")
|
||||||
|
headers["Content-Type"] = "application/json; charset=utf8"
|
||||||
|
|
||||||
|
if method == 'GET':
|
||||||
|
return json.loads(requests.get(url_service, headers=headers).content.decode("utf-8"))
|
||||||
|
elif method == 'POST':
|
||||||
|
json_data = json.dumps(json_data)
|
||||||
|
return json.loads(
|
||||||
|
requests.post(url_service, headers=headers, data=json_data.encode("utf8")).content.decode("utf-8"))
|
||||||
|
except:
|
||||||
|
print("Error when calling the client API")
|
Reference in New Issue
Block a user