HarlanBOT is a Python module designed for creating AI-based chatbots. This module utilizes various natural language processing (NLP) and deep learning technologies to enable the bot to learn from registered conversation samples and provide relevant responses based on user input.
- Easy Customization: Easily add, modify, or remove intents and responses in the JSON file.
- Train the ChatBot: Train the chatbot using data from a JSON file containing intents and responses.
- Real-time Interaction: The chatbot can respond in real-time based on user input.
Follow the steps below to install and set up HarlanBOT:
-
Install the package:
pip install harlanbot
This requires the modified
tflearn
package for compatibility with the AI:pip install git+https://github.com/harlansr/tflearn.git@master
-
Create a Python script:
from harlanbot import ChatBot bot = ChatBot()
Run this code for the first time to create the
files/intents.json
file. You can also customize the file name as needed by passing a custom path.from harlanbot import ChatBot bot = ChatBot(files="custom_file_name")
This example will create a file named
custom_file_name/intents.json
. -
Edit the
intents.json
file:intents.json
is the file required to train the bot. To tailor the chatbot to your needs, edit the contents of theintents.json
file.
{
"intents": {
"main": [
{
"tag": "greeting",
"patterns": [
"hello",
"who are you"
],
"responses": [
"Hello, I'm your assistant",
"Hi, I'm your assistant"
]
},
{
"tag": "goodbye",
"patterns": [
"bye",
"I need to go"
],
"responses": [
"Okay, have a nice day",
"See you again"
]
}
]
}
}
Name | Description |
---|---|
tag | An identifier that should be unique across all intents. |
patterns | Sample input texts; the more patterns, the better the model. |
responses | Output responses when matching input patterns. Can be filled with multiple responses, which will be displayed randomly. |
After customizing the intents.json
file, when you run:
bot.train()
This will train the AI according to the data in intents.json
. Alternatively, you can train the model everytime code running by modify the code like this:
from harlanbot import ChatBot
bot = ChatBot(train=True)
Name | Description |
---|---|
train() | Manually train the chatbot with provided data |
load() | Load the trained data model |
ask() | Ask a question to the AI and get an answer |
run_loop() | Run the chatbot in a loop to facilitate continuous Q&A |
Name | Type | Default | Description |
---|---|---|---|
train | boolean | False | Run training when initiated |
accuracy | float | 0.8 | Accuracy of the response, recommended value is 0.9 |
files | string | "files" | Directory name to store the data |
message_default | string | "Sorry, I don't understand" | Message to display when the accuracy is below the defined threshold |
Name | Type | Default | Description |
---|---|---|---|
message | string | The message that you want to ask the bot | |
need_accuracy | boolean | False | Whether to include the accuracy value with the response |
Name | Type | Default | Description |
---|---|---|---|
need_accuracy | boolean | False | Whether to include the accuracy value with the response |
from harlanbot import ChatBot
bot = ChatBot(True, 0.9) # Set to False if you don't want the bot to train every time
answer = bot.ask("Hello, nice to meet you")
print(answer)
If you'd like to contribute to this project, please follow these steps:
- Fork the GitHub repository
- Create a new branch (
git checkout -b new-feature
) - Make the necessary changes
- Commit the changes (
git commit -am 'Add new feature'
) - Push the branch (
git push origin new-feature
) - Create a Pull Request