Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a significant bug where the history pruning function could trim away the system prompt #32

Merged
merged 2 commits into from
Sep 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading