Skip to content

Commit 1298875

Browse files
jtoyJasonsonichi
authored
allow serialize_to_str to work with non ascii when dumping via json.dumps (microsoft#2714)
Co-authored-by: Jason <[email protected]> Co-authored-by: Chi Wang <[email protected]>
1 parent c0812f9 commit 1298875

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

autogen/function_utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -353,4 +353,4 @@ def serialize_to_str(x: Any) -> str:
353353
elif isinstance(x, BaseModel):
354354
return model_dump_json(x)
355355
else:
356-
return json.dumps(x)
356+
return json.dumps(x, ensure_ascii=False)

test/test_function_utils.py

+4
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,10 @@ async def f(
391391
assert actual[1] == "EUR"
392392

393393

394+
def test_serialize_to_str_with_nonascii() -> None:
395+
assert serialize_to_str("中文") == "中文"
396+
397+
394398
def test_serialize_to_json() -> None:
395399
assert serialize_to_str("abc") == "abc"
396400
assert serialize_to_str(123) == "123"

0 commit comments

Comments
 (0)