Skip to content

Eggdrop TCL Script allowing communication with open AI over http

License

Notifications You must be signed in to change notification settings

pajus1337/Eggdrop_openAi_Connection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Eggdrop OpenAI Chat Bot + API Server in Python

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.

Screenshot

SparkBuddy Screenshot

Prerequisites

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

Setup

aiConnection.tcl

  1. Make sure you have the Tcl interpreter installed on your system.
  2. 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.

OpenAIChatAPI.py

  1. Make sure you have Python installed on your system.
  2. Install the required Python packages by running the following command:
    pip install flask openai
  3. Set your OpenAI API key in the `OpenAIChatAPI.py` script. Replace `'API_Key'` with your actual OpenAI API key.
  4. 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}"
        }
      ]
    }
        
  5. Save the `OpenAIChatAPI.py` and `prompts.json` files in the same directory.
  6. To start the API server, run the following command in the terminal:
    python OpenAIChatAPI.py
    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).
  7. Optionally, you can enable or disable logging for debugging purposes by modifying the logging.basicConfig line in the script.

Usage

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.

Configuration

Both scripts provide configuration options that you can modify:

aiConnection.tcl

  • 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.

OpenAIChatAPI.py

  • openai.api_key: Set your OpenAI API key.
  • isOnlyLan: Set to True to allow connections only via the local network, or False 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. :-)

License

This project is licensed under the MIT License. Feel free to modify and adapt the code according to your requirements.

Acknowledgments

This project utilizes the OpenAI Chat API. Make sure to review and comply with OpenAI's usage guidelines and policies.

About

Eggdrop TCL Script allowing communication with open AI over http

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published