Fix truncation calculation

This commit is contained in:
Kumi 2023-11-11 13:32:31 +01:00
parent 0317b2f5aa
commit 48f13fcf7f
Signed by: kumi
GPG key ID: ECBCC9082395383F

View file

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