I am currently working on a chatbot for buying/selling items and I need this project for my resume. Looking forward into some help.
I have a JSON file that includes patterns and responses:
{"intents": [
{"tag": "greetings",
"patterns": ["hallo"],
"responses": ["Hallo!", "Guten Tag!"]
}
]
}
My Python script so far looks like this:
import json
import random
with open('Python\intents.json') as file:
data = json.load(file)
What I want is:
If I give an input, it should search in all tags (I want to expand the intents data later) and if input is found in patterns of one of those tags, it should print a random line of its responses. For example, if input is "hallo" which is a greeting, the script should know it is a greeting and if its found in the tag, it should print its responses. In this case "Hallo" or "Guten Tag"
This method works, but like I mentioned I want the script to know what kind of input it is whether it is a greeting, a question, etc.
for i in data['intents']:
if i['tag'] == 'greetings':
if inp in i['patterns']:
print(i['responses'][0])
break
Thanks in advance.