-
Notifications
You must be signed in to change notification settings - Fork 2k
fix: improve json serialization by allowing non-ascii characters #605
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
Conversation
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Previously accepted JSON objects directly, which was less robust. Now serialize arguments to JSON strings using `_safe_json_serialize`, ensuring stability and handling non-ASCII characters correctly.
I don't know if ensure_ascii is the problem. Ideally even if Chinese character is encoded in dumps(), once you loads() it should restore back to the correct characters. |
The input to the LLM is a JSON string. I think setting ensure_ascii=False would help the LLM handle non-ASCII responses better. |
Assuming this is useful for logging purposes (regarding json.loads not needing this). |
-- 50b09bb by Yuan Chai <350365422@qq.com>: fix: improve json serialization by allowing non-ascii characters -- c66977a by Yuan Chai <350365422@qq.com>: fix: serialize function call arguments to JSON string Previously accepted JSON objects directly, which was less robust. Now serialize arguments to JSON strings using `_safe_json_serialize`, ensuring stability and handling non-ASCII characters correctly. COPYBARA_INTEGRATE_REVIEW=#605 from nauyiahc:fix_non_ascii_char a52513c PiperOrigin-RevId: 764396496
merged by copybara: c4cd180 |
-- 50b09bb by Yuan Chai <350365422@qq.com>: fix: improve json serialization by allowing non-ascii characters -- c66977a by Yuan Chai <350365422@qq.com>: fix: serialize function call arguments to JSON string Previously accepted JSON objects directly, which was less robust. Now serialize arguments to JSON strings using `_safe_json_serialize`, ensuring stability and handling non-ASCII characters correctly. COPYBARA_INTEGRATE_REVIEW=google#605 from nauyiahc:fix_non_ascii_char a52513c PiperOrigin-RevId: 764396496
-- 50b09bb by Yuan Chai <350365422@qq.com>: fix: improve json serialization by allowing non-ascii characters -- c66977a by Yuan Chai <350365422@qq.com>: fix: serialize function call arguments to JSON string Previously accepted JSON objects directly, which was less robust. Now serialize arguments to JSON strings using `_safe_json_serialize`, ensuring stability and handling non-ASCII characters correctly. COPYBARA_INTEGRATE_REVIEW=google#605 from nauyiahc:fix_non_ascii_char a52513c PiperOrigin-RevId: 764396496
-- 50b09bb by Yuan Chai <350365422@qq.com>: fix: improve json serialization by allowing non-ascii characters -- c66977a by Yuan Chai <350365422@qq.com>: fix: serialize function call arguments to JSON string Previously accepted JSON objects directly, which was less robust. Now serialize arguments to JSON strings using `_safe_json_serialize`, ensuring stability and handling non-ASCII characters correctly. COPYBARA_INTEGRATE_REVIEW=google#605 from nauyiahc:fix_non_ascii_char a52513c PiperOrigin-RevId: 764396496
Updated _safe_json_serialize to use json.dumps(obj, ensure_ascii=False). This allows non-ASCII characters to be preserved in JSON output, improving readability and compatibility for internationalization.
Addresses Non-ASCII characters (for example, Chinese characters) in tool responses are escaped before being sent to the LLM. #472
The
Function
class'sarguments
field accepts a JSON string instead of a raw JSON object. This change ensures stability and handles non-ASCII characters correctly, making the arguments more robust and easier to serialize.