Interface and example code for using openAI's python AI, including original completion interface, image interface and chat interface. An example Discord chatGPT bot is provided.
OPENAI_API_KEY needs to be set appropriate
application: discordbot.py
./discordbot.py --help
usage: discordbot.py [-h] [-f DIRECTORY] [-m MODEL]
Interface to chatGPT discord-bot
optional arguments:
-h, --help show this help message and exit
-f DIRECTORY, --directory DIRECTORY
Directory to store chats (default: discord_chats)
-m MODEL, --model MODEL
Select the model to use (default: gpt-3.5-turbo)
- Have a conversation in any channel on your server; currently discord-bot is not restricted to particular channels
- To start a new conversation, use .clear, .new, .reset, .newconv
- To report the current system role, use .role, .system, .sysrole, .system_role
- To change the system role and start a new conversation, use .role , or alias
- To save the current conversation use .save, .store, .record
- Conversations are stored as JSON objects in the discord_chats directory
- Conversations are named using the time the conversation is stored
- The log directory can be specified as a command parameter when discordbot.py is run
- Use .report to show the complete conversation as a JSON object
Firstly you need to create the bot
- Go to the Discord Developer Portal website: https://discord.com/developers/applications
- Click the "New Application" button in the top right corner.
- Enter a name for your application and click "Create".
- Enter bot name, description etc. If you want an app icon, use ChatGPT_bot_icon.png (created with Midjourney)
- On the left-hand side of the screen, click "Bot".
- Click the "Add Bot" button (you may need to go through 2FA to do this)
- Customize your bot by giving it a name and profile picture.
- Under the "Token" section, click "Copy" to copy the bot token.
- This token should be stored in DISCORD_CHATGPT_BOT_TOKEN
Additionally, you need to allow the bot access to your Discord via OAuth2
- In the application in the Discord Developer Portal, go to OAuth2 -> URL Generator
- Select the following scopes: bot, applications.commands
- In the Bot Permissions window, select all Text Permissions
- Copy the Generated URL and go to that address and accept the permissions to allow your bot to be used on you discord server
application: slackbot.py
- Go to https://api.slack.com/, and select Create an app
- Select from scratch, select name and workspace, then create the app
- Select a Bot
- Add scopes: chat.write, commands, chat:write.customize, channels.join
- Get App Credentials from Basic Information
- Get SLACK_BOT_TOKEN from OAuth & Permissions tab in OAuth Tokens for Your Workspace section
- Also see https://slack.dev/bolt-python/tutorial/getting-started
- Basic Information -> App Token section. Generate Token and scopes. Add connections:write
- Use this token as SLACK_APP_TOKEN
- Go to socket mode and Enable Socket Mode
- Ensure Allow users to send Slash commands and messages from the messages tab is enabled in App Home->Show Tabs
- You can now add the app to your Slack (OAuth Tokens for Your Workspace -> Reinstall to Workspace )
- Slash command entries need to be added for the bot on https://api.slack.com/
- Add /new, /report, /chats, /save
Not sure this is relevant yet, but to enable Events
- Ensure Event Subscriptions->Enable Events is on
- Subscribe to bot events: app_mention, message.channels, message.im
- If you make a change to bot (such as permission), reinstall the bot using Apple-R (on Mac)
-
Refactor code into more of a helper library model so code can be reused
-
Option to display previous chats, or restart previous chats
-
Open viewer for images
-
Auto-summarize at end of chat
-
Add slash command support - see https://stackoverflow.com/questions/71165431/how-do-i-make-a-working-slash-command-in-discord-py
- Looks like its better to have a tree to attach commands too rather than using the command.Bot approach
- Need to use a GUILD_ID - don't understand that yet
-
Discord front-end
- Use .commands to do operations like start/stop conversations, change temperature, regenerate responses etc.
- Allow multiple threads for multiple chats
- .commands to change behavior to different models (like images)
- The bot will respond on any channel in the server; it would be better it is monitor specific channels
- There is only one global conversation; there should be unique conversations to each channel (or possibly thread)
-
Slack front-end
- Basic implementation