A framework to create chatbots in the easiest way
Project description
Baker
Bot-Maker Baker! Is a framework to create chatbots with Python in the easiest and simplest route, train your chatbot by texting or adding data in XML, JSON or YAML files.
Installation
You can install Baker with pip
pip install baker-python
Usage
Using Baker is very easy, all you have to do is to create a YAML, JSON or XML file first. However, files should have been defined in a specific format:
For XML files
<responses>
<Hello>
<response>Hello!</response>
<response>Hi there!</response>
</Hello>
</responses>
The Hello
tag is defining that if the user will write Hello
to the chatbot the chatbot will return one of the responses in the response
tag.
For JSON files
{
"Hello": [
"Hi",
"Heyy",
"Hello"
]
}
Same goes with JSON files. Even if the response is only one, it must be in a list []. Here, if user inputs Hello
then the response must be random in the list.
For YAML files
Hello:
- Hello!
- Hi there!
How are you:
- I am fine
- I am doing good, thanks for asking
Same process is with the YAML files with a bit different syntax and nothing else.
To train the chatbot, the Trainer
class is used:
bot = Trainer('database.yaml')
user_input = input("You: ")
response = bot.get_response(user_input)
print("Bot:", response)
# Train the bot with a new response
new_response = input("New response: ")
bot.train_response(user_input, new_response)
print("Bot has been trained with the new response!")
Note :- The keyword must be already created in the file or else the trainer will not be able to train because the trainer will not find the keyword in the file. For example if you want to train the chatbot for responses of Hello
then Hello
should be at least created in the data file.
To parse the chatbot use the Parser
class:
def test_chatbot(bot):
while True:
user_input = input("You: ")
if user_input.lower() == "exit":
print("Testing session ended.")
break
response = bot.get_response(user_input)
print("Bot:", response)
bot = Parser('database.json')
test_chatbot(bot)
The above code will run the chatbot, but there is anther simpler way to run the chatbot with it's specified name which is to use the Chatbot
class:
trainer = Trainer('database.json')
parser = Parser('database.json')
my_chatbot = Chatbot("MyChatbot")
my_chatbot.interactive_session(trainer, parser)
Keep training your chatbot by texting or adding words in the database and then run it!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file baker_python-1-py3-none-any.whl
.
File metadata
- Download URL: baker_python-1-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b020af8c6019817a13ce78a4797533dd5bdaa474f07e8d03f20f5c8f0c5dfc02 |
|
MD5 | fb24cfcc2715ed151f61120481cf6e29 |
|
BLAKE2b-256 | 5a662166718f9d04f56ed2c0731576ad894480e207f94f7eef00cb13931e8049 |