Skip to content

Commit

Permalink
chore: Refactor make_history_start_with_user_message method (#32)
Browse files Browse the repository at this point in the history
Fix the method to not trim the first entry if it is a "system" role
  • Loading branch information
efunneko authored Sep 5, 2024
1 parent 8c9434f commit 3c9b8ba
Showing 1 changed file with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,20 @@ def clear_history_but_keep_depth(self, session_id: str, depth: int, history):

def make_history_start_with_user_message(self, session_id, history):
if session_id in history:
while (
history[session_id]["messages"]
and history[session_id]["messages"][0]["role"] != "user"
):
history[session_id]["messages"].pop(0)
messages = history[session_id]["messages"]
if messages:
if messages[0]["role"] == "system":
# Start from the second message if the first is "system"
start_index = 1
else:
# Start from the first message otherwise
start_index = 0

while (
start_index < len(messages)
and messages[start_index]["role"] != "user"
):
messages.pop(start_index)

def handle_timer_event(self, timer_data):
if timer_data["timer_id"] == "history_cleanup":
Expand Down

0 comments on commit 3c9b8ba

Please sign in to comment.