diff --git a/src/gptbot/classes/ai/openai.py b/src/gptbot/classes/ai/openai.py index d3b5b71..e7cdb19 100644 --- a/src/gptbot/classes/ai/openai.py +++ b/src/gptbot/classes/ai/openai.py @@ -173,6 +173,8 @@ class OpenAI(BaseAI): ) -> List[Any]: chat_messages = [] + self.logger.log(f"Incoming messages: {messages}", "debug") + for message in messages: if isinstance(message, (RoomMessageNotice, RoomMessageText)): role = ( @@ -390,6 +392,8 @@ class OpenAI(BaseAI): ) chat_messages.append({"role": "system", "content": message_body}) + self.logger.log(f"Prepared messages: {chat_messages}", "debug") + # Truncate messages to fit within the token limit self._truncate( messages=chat_messages, @@ -450,6 +454,8 @@ class OpenAI(BaseAI): total_tokens = len(system_message) + 1 truncated_messages = [] + self.logger.log(f"Messages: {messages}", "debug") + for message in [messages[0]] + list(reversed(messages[1:])): content = ( message["content"] diff --git a/src/gptbot/classes/bot.py b/src/gptbot/classes/bot.py index c186c6e..9a1eb67 100644 --- a/src/gptbot/classes/bot.py +++ b/src/gptbot/classes/bot.py @@ -1103,6 +1103,7 @@ class GPTBot: last_messages = await self._last_n_messages( room.room_id, self.chat_api.max_messages ) + self.logger.log(f"Last messages: {last_messages}", "debug") except Exception as e: self.logger.log(f"Error getting last messages: {e}", "error") await self.send_message( @@ -1113,7 +1114,7 @@ class GPTBot: system_message = self.get_system_message(room) chat_messages = await self.chat_api.prepare_messages( - last_messages, system_message + event, last_messages, system_message ) # Check for a model override @@ -1158,6 +1159,11 @@ class GPTBot: await self.send_message( room, "Something went wrong generating audio file.", True ) + + if self.debug: + await self.send_message( + room, f"Error: {e}\n\n```\n{traceback.format_exc()}\n```", True + ) await self.send_message(room, response)