This project implements a eggdrop chat bot that uses the OpenAI API to generate responses based on user input. It consists of two scripts: aiConnection.tcl
and OpenAIChatAPI.py
.
Before running the scripts, make sure you have the following:
- For
aiConnection.tcl
: - Tcl interpreter
- Packages:
http
,tls
,json
- For
OpenAIChatAPI.py
: - Python 3.x
- Required packages:
flask
,openai
,json
,logging
- Make sure you have the Tcl interpreter installed on your system.
- Install the required packages by running the following commands:
tclsh tcl::pkg::install http tls json
Script should be added to the Eggdrop configuration file (eggdrop.conf). Here's an example:
# Add the following line to your eggdrop.conf file
source scripts/aiConnection.tcl
After adding the script, it is recommended to restart your Eggdrop bot using the ".restart" command to ensure the changes take effect.
- Make sure you have Python installed on your system.
- Install the required Python packages by running the following command:
pip install flask openai
- Set your OpenAI API key in the `OpenAIChatAPI.py` script. Replace `'API_Key'` with your actual OpenAI API key.
- Create a file named `prompts.json` and populate it with the following content:
{ "scenario1": [ { "role": "system", "content": "Edit the content here" }, { "role": "user", "content": "{message}" } ] }
- Save the `OpenAIChatAPI.py` and `prompts.json` files in the same directory.
- To start the API server, run the following command in the terminal:
The server will start running on either `http://127.0.0.1:5000` (for LAN-only access) or `http://0.0.0.0:5000` (for access from the internet).
python OpenAIChatAPI.py
- Optionally, you can enable or disable logging for debugging purposes by modifying the
logging.basicConfig
line in the script.
Once you have completed the setup, you can interact with the chatbot through the Eggdrop bot. The bot will listen for messages starting with its nickname and forward them to the OpenAI Chat API server. The server will generate a response and send it back to the bot, which will then display the response in the channel or send it as a private message.
To use the chatbot, simply address a message to the bot's nickname, followed by your question or statement. For example, if the bot's nickname is "SparkBuddy", you can send a message like:
SparkBuddy: How are you?
The bot will process the message, send it to the OpenAI Chat API server, and display or send the generated response.
The `prompts.json` file contains the conversation prompts used by the chatbot. You can customize the prompts by editing the content of the `scenario1` section in the file. The `{message}` placeholder in the user role content will be replaced with the user's message during runtime.
It is important to note that the OpenAI Chat API requires an active internet connection to function properly. Ensure that your server has internet access for the chatbot to work as expected.
Feel free to customize the chatbot behavior by modifying the `OpenAIChatAPI.py` script, adjusting parameters such as temperature and max tokens, or modifying the conversation prompts.
Both scripts provide configuration options that you can modify:
respond_to_private_messages
: Set to 1 to enable responding to private messages, or 0 to disable.respond_to_channel_questions
: Set to 1 to enable responding to channel questions, or 0 to disable.reply_delay
: Time delay in milliseconds before sending a reply.
openai.api_key
: Set your OpenAI API key.isOnlyLan
: Set toTrue
to allow connections only via the local network, orFalse
to allow connections via the internet.temperature
: Adjust the temperature parameter for controlling the creativity of the responses.max_tokens
: Adjust the maximum number of tokens in the generated response.
Feel free to modify these configuration options to customize the behavior of the chat bot according to your needs. :-)
This project is licensed under the MIT License. Feel free to modify and adapt the code according to your requirements.
This project utilizes the OpenAI Chat API. Make sure to review and comply with OpenAI's usage guidelines and policies.