-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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: Enhanced string cleaning for response handling #3442
base: develop
Are you sure you want to change the base?
Conversation
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. |
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.
Hi @aayush4vedi! Welcome to the elizaOS community. Thanks for submitting your first pull request; your efforts are helping us accelerate towards AGI. We'll review it shortly. You are now an elizaOS contributor!
.replace(/\\n/g, " ") // Replace escaped newlines with space | ||
.replace(/\n/g, " ") // Replace actual newlines with space | ||
.replace(/\s+/g, " ") // Replace multiple spaces with single space | ||
.replace(/\\u[\dA-Fa-f]{4}/g, "") // Remove Unicode escape sequences |
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.
won't this prevent the LLMs from responding with emojis inside of the json?
Relates to
Risks
Low
Background
What does this PR do?
This PR improves the
cleanJsonResponse
function to handle additional edge cases in string responses. The enhanced function now properly handles Unicode escape sequences, non-printable characters, and various newline formats while maintaining the original JSON and markdown cleanup functionality.What kind of change is this?
Improvements
I encountered issues with response strings containing various special characters and escape sequences that were causing problems in downstream processing. This update makes the function more robust and reliable for handling real-world API responses.
Changes
\n
)\uXXXX
)Feature Improvement
Documentation changes needed?
Testing
Added test cases: