This repository has been archived on 2023-06-09. You can view files and clone it, but cannot push or open issues or pull requests.
jarvis-server/utils/intents_utils.py
Mathieu B 8131b046b2 Base
2021-07-26 18:23:32 +02:00

51 lines
1.2 KiB
Python

import json
import os
import random
import intents.intents
def get_patterns(intent_tag):
if exists(intent_tag):
patterns = get_lang_for_intent(intent_tag).get(intent_tag).get('patterns')
return patterns
else:
return {}
def get_responses(intent_tag):
if exists(intent_tag):
responses = get_lang_for_intent(intent_tag).get(intent_tag).get('responses')
return responses
else:
return {}
def get_response(intent_tag):
if exists(intent_tag):
responses = get_responses(intent_tag)
return random.choice(responses)
def get_lang_for_intent(intent_tag):
language = "fr-fr" # TODO: use config value
# first we check the intent
if exists(intent_tag):
lang_path = str(intents.intents.get_all_intents().get(intent_tag))
lang_path = lang_path + 'lang/' + language + '.json'
if os.path.exists(lang_path):
lang_file = open(lang_path)
json_lang = json.load(lang_file)
return json_lang
else:
return {}
def exists(intent_tag):
if intent_tag in intents.intents.get_all_intents():
return True
else:
return False