Skip to content

yednapg/trying-gpt-for-codeday-discord

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This is a fork of OpenAI's GPT-3 Discord Bot that has been modified to have unlimited memory. I utilized David Shapiro's code with some modifications to achieve this, all credit for this goes to David and others who have done this before me. His code is available here: https://github.com/daveshap/LongtermChatExternalSources

The bot takes your input and its output and creates embeddings with the 'embedding-ada-002' model and saves them as logs, each time you message the bot a search returns similar topics from your logs, these memories are summarized and a new embedding is created called notes. Each message you send creates a prompt that is sent to GPT-3, the prompt consists of your original prompt to the bot, a sample conversation, your memory notes, the last five messages in chat and your current message. The bot performs very well, able to recall memories of conversations past, it will timestamp them and this also gives the bot additional capabilities like knowing the current time and date.

In addition to long term memory the bot has been brought out from threads and will talk in regular text channels and does not need / commands. The bot will talk in every channel that it has permission to talk in, including threads, so be mindful of where you put your bot and what permissions it has. All permissions can be modified inside the Discord app. Also, all moderation has been turned off and removed from the code, be careful.

This bot uses the OpenAI Python Library and discord.py.

Features

  • The model will generate a reply when it's tagged in any thread or text channel it has access to
  • The past 5 messages and any history relating to the topic will be passed to GPT-3 with every message
  • you can customize the bot instructions by modifying config.yaml
  • you can change the model, the hardcoded value is text-davinci-003, the bot also uses 'embeddings-ada-002' for saving its memory
    response = openai.ChatCompletion.create(
        model="gpt-3.5-turbo",  # The name of the OpenAI chatbot model to use
        messages=message_log,   # The conversation history up to this point, as a list of dictionaries
        max_tokens=3800,        # The maximum number of tokens (words or subwords) in the generated response
        stop=None,              # The stopping sequence for the generated response, if any (not used here)
        temperature=0.7,        # The "creativity" of the generated response (higher temperature = more creative)
    )

Setup

  1. Copy .env.example to .env and start filling in the values as detailed below (make sure .env is .env and not .env.txt)
  2. Go to https://beta.openai.com/account/api-keys, create a new API key, and fill in OPENAI_API_KEY
  3. Create your own Discord application at https://discord.com/developers/applications
  4. Go to the Bot tab and click "Add Bot"
    • Click "Reset Token" and fill in DISCORD_BOT_TOKEN
    • Disable "Public Bot" unless you want your bot to be visible to everyone
    • Enable "Message Content Intent" under "Privileged Gateway Intents"
  5. Go to the OAuth2 tab, copy your "Client ID", and fill in DISCORD_CLIENT_ID
  6. Copy the ID the server you want to allow your bot to be used in by right clicking the server icon and clicking "Copy ID". Fill in ALLOWED_SERVER_IDS. If you want to allow multiple servers, separate the IDs by "," like server_id_1,server_id_2
  7. Create folders inside the src directory for each of the following: chat_logs , memories , notes (I need to add this into the code but just haven't gotten to it.)
  8. Install dependencies and run the bot
    pip install -r requirements.txt
    python -m src.main
    
    You should see an invite URL in the console. Copy and paste it into your browser to add the bot to your server.

Deploy

I am using fly.io to deploy this bot for free.

FAQ

Why isn't my bot responding to commands?

Ensure that the channels your bots have access to allow the bot to have these permissions.

  • Send Messages
  • Send Messages in Threads
  • Create Public Threads
  • Manage Messages (only for moderation to delete blocked messages)
  • Manage Threads
  • Read Message History
  • Use Application Commands

About

Discord Bot written for CodeDay Discord Server

Resources

License

Stars

Watchers

Forks

Languages

  • Python 97.4%
  • C 1.7%
  • Cython 0.5%
  • C++ 0.3%
  • Fortran 0.1%
  • PowerShell 0.0%