Skip to content

Commit

Permalink
Disable gpt to support threads
Browse files Browse the repository at this point in the history
Threads require python 3.8, gpt requires python 3.7
  • Loading branch information
nfaltermeier committed Oct 15, 2021
1 parent beb8143 commit 5735d68
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.env
.vscode
checkpoint
disabled_checkpoint
secret-scholars-bot-config.json

# Created by https://www.toptal.com/developers/gitignore/api/windows,python
Expand Down
8 changes: 3 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
# Based off of https://github.com/minimaxir/gpt-2-cloud-run/blob/master/Dockerfile
FROM python:3.7-slim-buster
FROM python:3.8-slim-buster

RUN apt-get -y update && apt-get -y install gcc
RUN apt-get -y update && apt-get -y install git

WORKDIR /code

COPY checkpoint checkpoint

RUN pip3 --no-cache-dir install -U tensorflow==1.15.5 gpt-2-simple discord.py python-dotenv
RUN pip3 --no-cache-dir install -U git+https://github.com/Rapptz/discord.py python-dotenv

RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

Expand Down
39 changes: 24 additions & 15 deletions src/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from dotenv import load_dotenv
import logging
from datetime import datetime, timezone
import gptlib
# import gptlib
import donut
import config
import asyncio
Expand All @@ -23,6 +23,13 @@ def allowed_channel(channel):
async def on_ready():
logging.info(f'{datetime.now(timezone.utc)} We have logged in as {client.user}')

# API says this is called for thread creation and joining a thread...
@client.event
async def on_thread_join(thread):
global joined_threads
logging.info(f'{datetime.now(timezone.utc)} Joined thread {thread.name}')
await thread.join()

@client.event
async def on_message(message):
global total_generated
Expand All @@ -39,20 +46,22 @@ async def on_message(message):
await message.delete()
await bot_response.delete()
else:
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()
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()
Expand Down
5 changes: 5 additions & 0 deletions src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,15 @@ 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': [],
Expand Down

0 comments on commit 5735d68

Please sign in to comment.