HarlanBOT
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.
Features
- 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.
Installation
Follow the steps below to install and set up HarlanBOT:
Installation Steps
-
Install the package:
pip install harlanbot
This requires the modified
tflearnpackage 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.jsonfile. 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.jsonfile:intents.jsonis the file required to train the bot. To tailor the chatbot to your needs, edit the contents of theintents.jsonfile.
Usage
Example intents.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"
]
}
]
}
}
Explanation:
| 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. |
Training the ChatBot
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)
Documentation
Functions
| 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 |
Class ChatBot( train, accuracy, files, message_default )
| 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 |
Function ask( message, need_accuracy )
| 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 |
Function run_loop( need_accuracy )
| Name | Type | Default | Description |
|---|---|---|---|
| need_accuracy | boolean | False | Whether to include the accuracy value with the response |
Example Code
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)
Contributing
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
Metadata
Release files for harlanbot 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| harlanbot-0.1.2.tar.gz | 6.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| harlanbot-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.7 kB
Release files / harlanbot-0.1.2.tar.gz
| Download URL | harlanbot-0.1.2.tar.gz |
|---|---|
| Size | 6.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0e171a05a9ac3aeb531b71a9c6648cead4a236d22d16affc3d096b6f59975fb8
|
|
BLAKE2b-256 checksum How to use checksums |
219eddcc6c9f38271d37d5e77ff52116c38342a7cdfe0b4e0ce68aaac7b0ea3e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.10.6
|
Release files / harlanbot-0.1.2-py3-none-any.whl
| Download URL | harlanbot-0.1.2-py3-none-any.whl |
|---|---|
| Size | 6.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d87b69e1d22a5828c1a76c5f0e9f9a1f0b64ed9e3dd7376c2f230d547f45da67
|
|
BLAKE2b-256 checksum How to use checksums |
d16306c18751165e83958e6a2b9f9144b79301bf507edc5ab69532efb83982b2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.10.6
|