From be00ef3e50d6503e747e8e2d6e8eece9dfae265e Mon Sep 17 00:00:00 2001 From: William Lane Date: Mon, 20 Mar 2023 10:25:36 -0700 Subject: [PATCH] fix async blocking issue --- Dockerfile | 2 +- app/discord_bot/connect_discord.py | 15 ++++++++------- app/mabel/connect_openai.py | 2 +- run.py | 1 + 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index c50d5be..546f863 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,7 +13,7 @@ ADD . . # Install any needed packages specified in requirements.txt RUN pip install -r requirements.txt -# Make port 80 available to the world outside this container +# Make port 8080 available to the world outside this container EXPOSE 8080 # Run run.py when the container launches diff --git a/app/discord_bot/connect_discord.py b/app/discord_bot/connect_discord.py index d6090c5..a629076 100644 --- a/app/discord_bot/connect_discord.py +++ b/app/discord_bot/connect_discord.py @@ -10,14 +10,15 @@ class MyClient(discord.Client): async def on_ready(self): print('Logged in as: ', self.user) async def on_message(self, message): - if message.author == self.user: + if message.author == client.user: return - message_content=message.content - chat_response=chatgpt_response(message_content) - if "mabel" in message_content.lower() or "Mabel" in message_content.lower(): - print(message_content) - await message.channel.send(f"{chat_response}") - return + if message.content.startswith('!mabel'): + prompt = message.content[7:] + response = await chatgpt_response(prompt) + await message.channel.send(response) + intents=discord.Intents.default() intents.messages=True client=MyClient(intents=intents) + + diff --git a/app/mabel/connect_openai.py b/app/mabel/connect_openai.py index 24d5b17..214d3ae 100644 --- a/app/mabel/connect_openai.py +++ b/app/mabel/connect_openai.py @@ -14,7 +14,7 @@ def load_system_directives(): system_directives = json.load(f) return system_directives -def chatgpt_response(prompt): +async def chatgpt_response(prompt): global DIALOGUE_STACK, SYSTEM_DIRECTIVES SYSTEM_DIRECTIVES = load_system_directives() current_prompt = {"role": "user", "content": prompt} diff --git a/run.py b/run.py index 7e092df..e57844f 100644 --- a/run.py +++ b/run.py @@ -2,4 +2,5 @@ from app.discord_bot.connect_discord import client, discord_token if __name__ == '__main__': print("Starting Discord Bot") + # run the discord bot on port 8080 client.run(discord_token) \ No newline at end of file