Skip to content

Commit

Permalink
Fully remove gpt code
Browse files Browse the repository at this point in the history
  • Loading branch information
nfaltermeier committed Apr 7, 2022
1 parent 5735d68 commit 9770620
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 107 deletions.
11 changes: 1 addition & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# About
A discord bot to produce gpt-2 messages on command. The bot can be prompted by including a text after the command name in the discord message.
A discord bot that doesn't do all that much at the moment.

Designed to be ran in a Docker container. I would recomend removing the `.env` file from the image before pushing the image anywhere.

Expand All @@ -11,24 +11,15 @@ DISCORD_TOKEN=<discord bot token>
`secret-scholars-bot-config.json`
```
{
"allowed-channels": [
"<channel name 1>"
],
"checkpoints": {
"<command name>": "<checkpoint model name>"
},
"donut-ids": [
<integer discord id 1>
],
"strict-donuts": false
}
```
Command names must be prefixed with a `$` when used in discord for the bot to recognize the command.

## Build

Put the model(s) in a new folder named `checkpoint`.

Run
```sh
docker build -t secret-scholars-bot .
Expand Down
29 changes: 3 additions & 26 deletions src/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,18 @@
from dotenv import load_dotenv
import logging
from datetime import datetime, timezone
# import gptlib
import donut
import config
import asyncio

logging.basicConfig(level=logging.INFO)

total_generated = 0

conf = config.read_or_create_config()

client = discord.Client()
intents = discord.Intents.default()
intents.message_content = True

def allowed_channel(channel):
return channel in conf['allowed-channels']
client = discord.Client(intents=intents)

@client.event
async def on_ready():
Expand All @@ -32,8 +29,6 @@ async def on_thread_join(thread):

@client.event
async def on_message(message):
global total_generated

if message.author == client.user:
return

Expand All @@ -45,24 +40,6 @@ async def on_message(message):
logging.info(f'{datetime.now(timezone.utc)} Attempting to delete hello messages')
await message.delete()
await bot_response.delete()
else:
return
if conf['gpt-enabled']:
for cmd in conf['checkpoints'].keys():
if message.content.startswith(f'${cmd}'):
if allowed_channel(message.channel.name):
run_name = conf['checkpoints'][cmd]
prefix = message.content[len(cmd) + 2:]
logging.info(f'{datetime.now(timezone.utc)} Generating message with prefix "{prefix}" for model "{run_name}". Previously generated count: {total_generated}')
total_generated += 1
await gptlib.generate(run_name, prefix, message.channel.send)
else:
bot_response = await message.channel.send('Please use the right channel :slight_smile:')
await asyncio.sleep(300)
logging.info(f'{datetime.now(timezone.utc)} Attempting to delete messages in incorrect channel')
await message.delete()
await bot_response.delete()


load_dotenv()
client.run(os.getenv('DISCORD_TOKEN'))
15 changes: 0 additions & 15 deletions src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@ def read_or_create_config():
with open(filename, 'r') as f:
conf = json.load(f)

if not 'checkpoints' in conf:
conf['checkpoints'] = {}
elif not type(conf['checkpoints']) is dict:
raise Exception('config file key \'checkpoints\' should be an object command name keys and checkpoint names as values')
if not 'allowed-channels' in conf:
conf['allowed-channels'] = []
elif not type(conf['allowed-channels']) is list:
raise Exception('config file key \'allowed-channels\' should be an array with channel name values')
if not 'donut-ids' in conf:
conf['donut-ids'] = []
elif not type(conf['donut-ids']) is list:
Expand All @@ -27,17 +19,10 @@ def read_or_create_config():
conf['strict-donuts'] = false
elif not type(conf['strict-donuts']) is bool:
raise Exception('config file key \'strict-donuts\' should be an bool to delete messages from donut users that block the bot')
if not 'gpt-enabled' in conf:
conf['gpt-enabled'] = false
elif not type(conf['gpt-enabled']) is bool:
raise Exception('config file key \'gpt-enabled\' should be an bool for whether or not to enable gpt message generation')
return conf
else:
with open(filename, 'w') as f:
conf = {
'gpt-enabled': True,
'checkpoints': {},
'allowed-channels': [],
'donut-ids': [],
'strict-donuts': False
}
Expand Down
56 changes: 0 additions & 56 deletions src/gptlib.py

This file was deleted.

0 comments on commit 9770620

Please sign in to comment.