# 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
```bash
pip install baker-python
```
# Usage
## Initial Tasks
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**
```xml
<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**
```json
{
"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**
```yaml
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.
The files can also be empty for example a JSON file can be like this:
```json
{
}
```
## Training
To train the chatbot, use the `Trainer` class. Here is an example of basic training:
```py
import baker.trainer
import baker.bparser
import baker.chatbot
bot = baker.trainer.Trainer('data.json')
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!")
```
from this route the keyword (user's question) 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 created in the data file.
But with this way to train you can train the chatbot as long you want to with custom keywords (no need to define them in the data file) and their infinite responses:
```py
import baker.trainer
trainer = baker.trainer.Trainer('data.json')
trainer.loop_training()
```
The data file can either be empty or it can have keywords, pre-defined keyowrds can be trained too.
# Parsing
To parse the chatbot to run and test it use the `Parser` class:
```py
import baker.bparser
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 = baker.bparser.Parser('data.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:
```py
import baker.trainer
import baker.bparser
import baker.chatbot
trainer = baker.trainer.Trainer('data.json')
parser = baker.bparser.Parser('data.json')
my_chatbot = baker.chatbot.Chatbot("MyChatbot")
my_chatbot.session(trainer, parser)
```
`Parser` class has more functions regarding the data file:
- Exporting responses :
```py
import baker.bparser
response_file_name = "data.json"
parser_instance = baker.bparser.Parser(response_file_name)
parser_instance.export_responses(export_file_name="data2.json")
```
- Reset resposes
```py
baker.bparser.Parser.reset_responses("A_User_Question")
```
- Removing responses:
```py
parser_instance2 = baker.bparser.Parser("data.json")
user_input = "Hello"
response_to_remove = "Heyy"
parser_instance2.remove_response(user_input, response_to_remove)
```
- Count responses:
```py
parser_instance3 = baker.bparser.Parser("data.json")
user_input = "Hello"
count = parser_instance3.count_responses(user_input)
print(f"Number of Responses for '{user_input}': {count}")
```
Keep training your chatbot by texting or adding words in the database and then run it!
Raw data
{
"_id": null,
"home_page": "https://github.com/enginestein/Baker",
"name": "baker-python",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "",
"author": "Arya Praneil Pritesh",
"author_email": "aryapraneil@gmail.com",
"download_url": "",
"platform": null,
"description": "# Baker\r\n\r\n*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. \r\n\r\n# Installation\r\n\r\nYou can install Baker with pip\r\n\r\n```bash\r\npip install baker-python\r\n```\r\n\r\n# Usage\r\n\r\n## Initial Tasks\r\n\r\nUsing 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:\r\n\r\n**For XML files**\r\n\r\n```xml\r\n<responses>\r\n <Hello>\r\n <response>Hello!</response>\r\n <response>Hi there!</response>\r\n </Hello>\r\n</responses>\r\n```\r\n\r\nThe `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.\r\n\r\n**For JSON files**\r\n\r\n```json\r\n{\r\n \"Hello\": [\r\n \"Hi\",\r\n \"Heyy\",\r\n \"Hello\"\r\n ]\r\n\r\n}\r\n```\r\n\r\nSame 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. \r\n\r\n**For YAML files**\r\n\r\n```yaml\r\nHello:\r\n- Hello!\r\n- Hi there!\r\nHow are you:\r\n- I am fine\r\n- I am doing good, thanks for asking\r\n```\r\n\r\nSame process is with the YAML files with a bit different syntax and nothing else.\r\n\r\nThe files can also be empty for example a JSON file can be like this:\r\n\r\n```json\r\n{\r\n\r\n}\r\n```\r\n\r\n## Training\r\n\r\nTo train the chatbot, use the `Trainer` class. Here is an example of basic training:\r\n\r\n```py\r\nimport baker.trainer\r\nimport baker.bparser\r\nimport baker.chatbot\r\n\r\nbot = baker.trainer.Trainer('data.json')\r\n\r\nuser_input = input(\"You: \")\r\nresponse = bot.get_response(user_input)\r\nprint(\"Bot:\", response)\r\n\r\n# Train the bot with a new response\r\nnew_response = input(\"New response: \")\r\nbot.train_response(user_input, new_response)\r\nprint(\"Bot has been trained with the new response!\")\r\n```\r\n\r\nfrom this route the keyword (user's question) 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 created in the data file.\r\n\r\nBut with this way to train you can train the chatbot as long you want to with custom keywords (no need to define them in the data file) and their infinite responses:\r\n\r\n```py\r\nimport baker.trainer\r\n\r\ntrainer = baker.trainer.Trainer('data.json')\r\ntrainer.loop_training()\r\n```\r\n\r\nThe data file can either be empty or it can have keywords, pre-defined keyowrds can be trained too.\r\n\r\n# Parsing\r\n\r\nTo parse the chatbot to run and test it use the `Parser` class:\r\n\r\n```py\r\nimport baker.bparser\r\n\r\ndef test_chatbot(bot):\r\n while True:\r\n user_input = input(\"You: \")\r\n if user_input.lower() == \"exit\":\r\n print(\"Testing session ended.\")\r\n break\r\n response = bot.get_response(user_input)\r\n print(\"Bot:\", response)\r\n\r\nbot = baker.bparser.Parser('data.json')\r\n\r\ntest_chatbot(bot)\r\n```\r\n\r\nThe 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:\r\n\r\n```py\r\nimport baker.trainer\r\nimport baker.bparser\r\nimport baker.chatbot\r\n\r\ntrainer = baker.trainer.Trainer('data.json')\r\nparser = baker.bparser.Parser('data.json')\r\nmy_chatbot = baker.chatbot.Chatbot(\"MyChatbot\")\r\nmy_chatbot.session(trainer, parser)\r\n```\r\n\r\n`Parser` class has more functions regarding the data file:\r\n\r\n- Exporting responses :\r\n\r\n```py\r\nimport baker.bparser\r\n\r\nresponse_file_name = \"data.json\" \r\nparser_instance = baker.bparser.Parser(response_file_name) \r\nparser_instance.export_responses(export_file_name=\"data2.json\")\r\n```\r\n\r\n- Reset resposes\r\n\r\n```py\r\nbaker.bparser.Parser.reset_responses(\"A_User_Question\")\r\n```\r\n\r\n- Removing responses:\r\n\r\n```py\r\nparser_instance2 = baker.bparser.Parser(\"data.json\")\r\n\r\nuser_input = \"Hello\"\r\nresponse_to_remove = \"Heyy\"\r\nparser_instance2.remove_response(user_input, response_to_remove)\r\n```\r\n\r\n- Count responses:\r\n\r\n```py\r\nparser_instance3 = baker.bparser.Parser(\"data.json\")\r\nuser_input = \"Hello\"\r\n\r\ncount = parser_instance3.count_responses(user_input)\r\nprint(f\"Number of Responses for '{user_input}': {count}\")\r\n```\r\n\r\nKeep training your chatbot by texting or adding words in the database and then run it!\r\n",
"bugtrack_url": null,
"license": "GPL-3.0-only",
"summary": "A framework to create chatbots in the easiest way",
"version": "2.0",
"project_urls": {
"Homepage": "https://github.com/enginestein/Baker",
"Source": "https://github.com/enginestein/Baker",
"Tracker": "https://github.com/enginestein/Baker"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "cb8a2634ec7cac3960290864237754b36801b7416ec6548b6f7598180ed48d4e",
"md5": "7f6464c16fb569767da76034589f82f1",
"sha256": "ea3ba5a59a246fadf960ae0754221f293b5a55e5852704365692f3b0e478d21c"
},
"downloads": -1,
"filename": "baker_python-2.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "7f6464c16fb569767da76034589f82f1",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 5412,
"upload_time": "2024-03-16T16:09:41",
"upload_time_iso_8601": "2024-03-16T16:09:41.288351Z",
"url": "https://files.pythonhosted.org/packages/cb/8a/2634ec7cac3960290864237754b36801b7416ec6548b6f7598180ed48d4e/baker_python-2.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-03-16 16:09:41",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "enginestein",
"github_project": "Baker",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"lcname": "baker-python"
}