-
Notifications
You must be signed in to change notification settings - Fork 2.4k
fix: final assistant content cannot end with trailing whitespace error from Anthropic
#5967
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. I might just add a
fn trimwhich trims both leading and trailing whitespace of all messages. Would be simpler, and in theory doesn't cause any issues. Only makes messages smaller.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, looked into this a bit and tried out some edge cases. We could get into trouble with messages that contain things like ascii art, tables, charts, or other space-dependent content in user message. So, I'm just going to leave this as trimming only the trailing whitespace on assistant messages
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could limit the trimming to only the very latest assistant message since that appears to be the only one Anthropic cares about per that message. Any thoughts there @alexhancock ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this stops things from crashing so that's good and agree, leading whitespace you can't trim in general. do we know where the issue comes from though? it would be better if we could fix it at the source.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the error is to be believed at face value, it's an assistant message causing the issue.
So that rules out tool responses, the moim, and special/control input from the user/client. So my thought is that the LLM itself is generating a trailing whitespace for some reason? They do get weird sometimes once context gets long enough.
tool call seems likely and fits with what I was seeing