I built a chatbot using JSON data for input and responses. The Python accepts an input for example "hi". If "hi" is listed in JSON array, it should output its response. In this case "Hi!". But problem is, if I type "hire", it will also print out "Hi!".
This is my Python script:
import json
import random
f = open('/home/anilo/Dokumente/Anilo/Projekte/Chatbot/chatdata.json', encoding='utf-8')
data = json.load(f)
wörter = []
nutzereingabe = input().lower()
for data in data["data"]:
for input in data["input"]:
if input in nutzereingabe:
print(random.choice(data["antwort"]))
And this is my JSON data:
{"data": [
{"tag": "grüßen",
"input": ["hi"],
"antwort": ["Hi!"]
}]}
I am German, so if you are confused with the words:
nutzereingabe = user input
wörter = words
antwort = response
grüßen = greeting