Fix: truncate message issue. (#5765)

### What problem does this PR solve?

Close #5761

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
Kevin Hu 2025-03-07 16:33:25 +08:00 committed by GitHub
parent 3418984848
commit 64c6cc4cf3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -70,7 +70,7 @@ def message_fit_in(msg, max_length=4000):
if c < max_length: if c < max_length:
return c, msg return c, msg
msg_ = [m for m in msg[:-1] if m["role"] == "system"] msg_ = [m for m in msg if m["role"] == "system"]
if len(msg) > 1: if len(msg) > 1:
msg_.append(msg[-1]) msg_.append(msg[-1])
msg = msg_ msg = msg_