Create your own custom chatbot
Project description
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
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.
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
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 Distribution
Built Distribution
File details
Details for the file harlanbot-0.1.2.tar.gz
.
File metadata
- Download URL: harlanbot-0.1.2.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
0e171a05a9ac3aeb531b71a9c6648cead4a236d22d16affc3d096b6f59975fb8
|
|
MD5 |
baab10628864debe968cdefe8f281247
|
|
BLAKE2b-256 |
219eddcc6c9f38271d37d5e77ff52116c38342a7cdfe0b4e0ce68aaac7b0ea3e
|
File details
Details for the file harlanbot-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: harlanbot-0.1.2-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
d87b69e1d22a5828c1a76c5f0e9f9a1f0b64ed9e3dd7376c2f230d547f45da67
|
|
MD5 |
c22340db5716114febbcda59e5d55e8a
|
|
BLAKE2b-256 |
d16306c18751165e83958e6a2b9f9144b79301bf507edc5ab69532efb83982b2
|