From c4cd1802bf86abb82b0e0fa016a9b2ca9d7917ad Mon Sep 17 00:00:00 2001 From: Yuan Chai <350365422@qq.com> Date: Wed, 28 May 2025 13:37:34 -0700 Subject: [PATCH] Copybara import of the project: -- 50b09bbe9735c889a9c815eddcee6715ebe848da by Yuan Chai <350365422@qq.com>: fix: improve json serialization by allowing non-ascii characters -- c66977ae6ec4edc71a2d633eb09918eb2a226461 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=https://github.com/google/adk-python/pull/605 from nauyiahc:fix_non_ascii_char a52513c5747296b717acee989684324e1b072d34 PiperOrigin-RevId: 764396496 --- src/google/adk/models/lite_llm.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/google/adk/models/lite_llm.py b/src/google/adk/models/lite_llm.py index 07f27f2..0b4531d 100644 --- a/src/google/adk/models/lite_llm.py +++ b/src/google/adk/models/lite_llm.py @@ -136,7 +136,7 @@ def _safe_json_serialize(obj) -> str: try: # Try direct JSON serialization first - return json.dumps(obj) + return json.dumps(obj, ensure_ascii=False) except (TypeError, OverflowError): return str(obj) @@ -186,7 +186,7 @@ def _content_to_message_param( id=part.function_call.id, function=Function( name=part.function_call.name, - arguments=json.dumps(part.function_call.args), + arguments=_safe_json_serialize(part.function_call.args), ), ) )