Skip to content

Commit

Permalink
Additional logging, added name to mention generation, moved to alpine…
Browse files Browse the repository at this point in the history
… for base image
  • Loading branch information
JMaynor committed Sep 12, 2024
1 parent 6bbc070 commit 45f282d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 21 deletions.
4 changes: 2 additions & 2 deletions dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM python:3.12
FROM python:3.12-alpine
RUN python -m pip install --upgrade pip
RUN mkdir /home/dolores
COPY . /home/dolores
WORKDIR /home/dolores
RUN python -m venv /home/dolores/.venv
RUN . /home/dolores/.venv/bin/activate
RUN pip install -r /home/dolores/requirements.txt
CMD python /home/dolores/src/dolores.py
CMD ["python", "/home/dolores/src/dolores.py"]
20 changes: 5 additions & 15 deletions src/dolores.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ async def handle_mention(message):
clean_message = clean_message.replace("@everyone", "everyone")
clean_message = clean_message.replace("@Testie", "Testie")
logger.info(f"Generating reply to following message: {clean_message}")
reply = text_instance.generate_reply(clean_message)
reply = text_instance.generate_reply(message.author.global_name, clean_message)
else:
reply = "Hi"
if reply != "":
Expand Down Expand Up @@ -119,13 +119,11 @@ async def on_command_error(ctx, error):
tries to use a command that does not exist, Dolores will reply with a snarky
comeback. Any other error performs default behavior of logging to syserr.
"""
await ctx.defer()
logger.error(error)
if os.environ["GENERATION_ENABLED"].lower() == "true":
text_instance = generation(bot)
if isinstance(error, (commands.CommandNotFound)):
await ctx.send(text_instance.generate_snarky_comment())
else:
logger.error(error)
else:
await ctx.send("An error occurred. Please try again.")

Expand All @@ -146,18 +144,10 @@ async def on_message(message):
and message.author.id != bot.user.id
and "@everyone" not in message.clean_content
):
# For testing, print out attributes of message
logger.info(f"Message: {message}")
await handle_mention(message)

# Check for if message was posted in news channel and contains a non-media URL
# if (
# os.environ["TEXT_ENABLED"].lower() == "true"
# and message.channel.id == int(os.environ["NEWS_CHANNEL_ID"])
# and "https" in message.clean_content
# and not any(
# excluded in message.clean_content for excluded in summary_exclude_strings
# )
# ):
# await handle_news(message)
return

# Normal command processing
await bot.process_commands(message)
Expand Down
15 changes: 11 additions & 4 deletions src/modules/generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Module contains code that deals with text processing and image generation.
"""

import asyncio
import json
import os
import random
Expand Down Expand Up @@ -30,7 +31,7 @@
json_data = json.load(f)
system_messages = json_data.get("LLM_SYSTEM_MESSAGES", [])
system_messages = [{"role": "system", "content": x} for x in system_messages]
snarky_comments = json_data.get("SNARKY_COMMENTS", [""])
snarky_comments = json_data.get("SNARKY_COMMENTS", ["Whatever"])


class generation(commands.Cog):
Expand All @@ -41,13 +42,14 @@ class generation(commands.Cog):
def __init__(self, bot):
self.bot = bot

def generate_reply(self, message):
def generate_reply(self, person, message):
"""
Generates a reply to a given message. Currently using chatterbot. Intent is to use a proper LLM in the future.
Generates a reply to a given message.
"""
if reply_method == "openai":

# Add the user's message to the message history
message_history.append({"role": "user", "content": message})
message_history.append({"role": "user", "content": message, "name": person})

try:
# Generate a reply using the OpenAI API
Expand Down Expand Up @@ -167,6 +169,11 @@ async def generate_image(self, ctx, *, prompt: str):
logger.error(e)
await ctx.respond(f"Error generating image: {e}.")

# Add a delay to ensure the image is available
# NOTE: Not sure if this is the issue. Image is getting generated, but is
# inconsistently not being posted to Discord.
await asyncio.sleep(1)

try:
embed = discord.Embed()
embed.description = prompt
Expand Down

0 comments on commit 45f282d

Please sign in to comment.