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 masz na imię",
|
||||||
"jak się nazywasz",
|
"jak się nazywasz",
|
||||||
"twoje imię",
|
"twoje imię",
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"ask_name": [
|
"name_response": [
|
||||||
"Witaj, nazywam się Dia.",
|
"Witaj, nazywam się Dia.",
|
||||||
"Cześć! Jestem Dia.",
|
"Cześć! Jestem Dia.",
|
||||||
"Hej, jestem Dia.",
|
"Hej, jestem Dia.",
|
||||||
|
@ -27,6 +27,7 @@ def main():
|
|||||||
|
|
||||||
intent = nlp.analyze(user_input)
|
intent = nlp.analyze(user_input)
|
||||||
response = generator.generate(intent)
|
response = generator.generate(intent)
|
||||||
|
|
||||||
print(Fore.CYAN + "Bot: " + response)
|
print(Fore.CYAN + "Bot: " + response)
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,6 +8,11 @@ class ResponseGenerator:
|
|||||||
def __init__(self, config: Config):
|
def __init__(self, config: Config):
|
||||||
with config.responses_path.open('r', encoding='utf-8') as file:
|
with config.responses_path.open('r', encoding='utf-8') as file:
|
||||||
self.responses: Dict[str, list] = json.load(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:
|
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ć?"]))
|
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):
|
if any(phrase in lower_text for phrase in phrases):
|
||||||
return intent
|
return intent
|
||||||
return "unknown"
|
return "unknown"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user