From cb348b5bfe0f7466b962fe62bb0f7320e74a1cc6 Mon Sep 17 00:00:00 2001 From: Jason Date: Fri, 17 May 2024 10:48:54 -0700 Subject: [PATCH] allow serialize_to_str to work with non ascii when dumping via json.dumps --- autogen/function_utils.py | 2 +- test/test_function_utils.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/autogen/function_utils.py b/autogen/function_utils.py index dd225fd4719..6b9b6f5b129 100644 --- a/autogen/function_utils.py +++ b/autogen/function_utils.py @@ -353,4 +353,4 @@ def serialize_to_str(x: Any) -> str: elif isinstance(x, BaseModel): return model_dump_json(x) else: - return json.dumps(x) + return json.dumps(x, ensure_ascii=False) diff --git a/test/test_function_utils.py b/test/test_function_utils.py index adddbf32e26..0475044b49f 100644 --- a/test/test_function_utils.py +++ b/test/test_function_utils.py @@ -391,6 +391,10 @@ async def f( assert actual[1] == "EUR" +def test_serialize_to_str_with_nonascii() -> None: + assert serialize_to_str("中文") == "中文" + + def test_serialize_to_json() -> None: assert serialize_to_str("abc") == "abc" assert serialize_to_str(123) == "123"