Browse Source

Fix truncation calculation

Kumi 1 year ago
parent
commit
48f13fcf7f
1 changed files with 2 additions and 4 deletions
  1. 2 4
      src/gptbot/classes/bot.py

+ 2 - 4
src/gptbot/classes/bot.py

@@ -921,7 +921,7 @@ class GPTBot:
 
         chat_messages = [{"role": "system", "content": system_message}]
 
-        last_messages = [event] + last_messages
+        last_messages = last_messages + [event]
 
         for message in last_messages:
             if isinstance(message, (RoomMessageNotice, RoomMessageText)):
@@ -953,7 +953,7 @@ class GPTBot:
 
         # Truncate messages to fit within the token limit
         truncated_messages = self._truncate(
-            chat_messages, self.max_tokens - 1, system_message=system_message
+            chat_messages[1:], self.max_tokens - 1, system_message=system_message
         )
 
         try:
@@ -978,8 +978,6 @@ class GPTBot:
 
             self.logger.log(f"Sending response to room {room.room_id}...")
 
-            # Convert markdown to HTML
-
             message = await self.send_message(room, response)
 
         else: