fix: fix chatbot response
This commit is contained in:
parent
ca27a16a40
commit
f552440de7
@ -1,5 +1,5 @@
|
||||
{
|
||||
"name_query": [
|
||||
"ask_name": [
|
||||
"jak masz na imię",
|
||||
"jak się nazywasz",
|
||||
"twoje imię",
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"ask_name": [
|
||||
"name_response": [
|
||||
"Witaj, nazywam się Dia.",
|
||||
"Cześć! Jestem Dia.",
|
||||
"Hej, jestem Dia.",
|
||||
|
@ -27,6 +27,7 @@ def main():
|
||||
|
||||
intent = nlp.analyze(user_input)
|
||||
response = generator.generate(intent)
|
||||
|
||||
print(Fore.CYAN + "Bot: " + response)
|
||||
|
||||
|
||||
|
@ -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ć?"]))
|
||||
|
@ -18,3 +18,4 @@ class NaturalLanguageProcessor:
|
||||
if any(phrase in lower_text for phrase in phrases):
|
||||
return intent
|
||||
return "unknown"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user