fix: fix chatbot response

This commit is contained in:
Mikołaj Gawron 2024-05-07 23:14:14 +02:00
parent ca27a16a40
commit f552440de7
5 changed files with 9 additions and 2 deletions

View File

@ -1,5 +1,5 @@
{
"name_query": [
"ask_name": [
"jak masz na imię",
"jak się nazywasz",
"twoje imię",

View File

@ -1,5 +1,5 @@
{
"ask_name": [
"name_response": [
"Witaj, nazywam się Dia.",
"Cześć! Jestem Dia.",
"Hej, jestem Dia.",

View File

@ -27,6 +27,7 @@ def main():
intent = nlp.analyze(user_input)
response = generator.generate(intent)
print(Fore.CYAN + "Bot: " + response)

View File

@ -8,6 +8,11 @@ class ResponseGenerator:
def __init__(self, config: Config):
with config.responses_path.open('r', encoding='utf-8') as file:
self.responses: Dict[str, list] = json.load(file)
self.intent_to_response_key = {
"ask_name": "name_response",
"unknown": "unknown"
}
def generate(self, response_key: str) -> str:
response_key = self.intent_to_response_key.get(response_key, "unknown")
return random.choice(self.responses.get(response_key, ["Przepraszam, nie rozumiem. Możesz to powtórzyć?"]))

View File

@ -18,3 +18,4 @@ class NaturalLanguageProcessor:
if any(phrase in lower_text for phrase in phrases):
return intent
return "unknown"