Skip to content

fix: add ensure_ascii=False to json.dumps for correct Unicode output #639

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

Merged
merged 2 commits into from
Jun 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/agents/extensions/models/litellm_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ async def get_response(
logger.debug("Received model response")
else:
logger.debug(
f"LLM resp:\n{json.dumps(response.choices[0].message.model_dump(), indent=2)}\n"
f"""LLM resp:\n{
json.dumps(
response.choices[0].message.model_dump(), indent=2, ensure_ascii=False
)
}\n"""
)

if hasattr(response, "usage"):
Expand Down Expand Up @@ -269,8 +273,8 @@ async def _fetch_response(
else:
logger.debug(
f"Calling Litellm model: {self.model}\n"
f"{json.dumps(converted_messages, indent=2)}\n"
f"Tools:\n{json.dumps(converted_tools, indent=2)}\n"
f"{json.dumps(converted_messages, indent=2, ensure_ascii=False)}\n"
f"Tools:\n{json.dumps(converted_tools, indent=2, ensure_ascii=False)}\n"
f"Stream: {stream}\n"
f"Tool choice: {tool_choice}\n"
f"Response format: {response_format}\n"
Expand Down
6 changes: 3 additions & 3 deletions src/agents/models/openai_chatcompletions.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ async def get_response(
if message is not None:
logger.debug(
"LLM resp:\n%s\n",
json.dumps(message.model_dump(), indent=2),
json.dumps(message.model_dump(), indent=2, ensure_ascii=False),
)
else:
finish_reason = first_choice.finish_reason if first_choice else "-"
Expand Down Expand Up @@ -256,8 +256,8 @@ async def _fetch_response(
logger.debug("Calling LLM")
else:
logger.debug(
f"{json.dumps(converted_messages, indent=2)}\n"
f"Tools:\n{json.dumps(converted_tools, indent=2)}\n"
f"{json.dumps(converted_messages, indent=2, ensure_ascii=False)}\n"
f"Tools:\n{json.dumps(converted_tools, indent=2, ensure_ascii=False)}\n"
f"Stream: {stream}\n"
f"Tool choice: {tool_choice}\n"
f"Response format: {response_format}\n"
Expand Down
12 changes: 9 additions & 3 deletions src/agents/models/openai_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,13 @@ async def get_response(
else:
logger.debug(
"LLM resp:\n"
f"{json.dumps([x.model_dump() for x in response.output], indent=2)}\n"
f"""{
json.dumps(
[x.model_dump() for x in response.output],
indent=2,
ensure_ascii=False,
)
}\n"""
)

usage = (
Expand Down Expand Up @@ -249,8 +255,8 @@ async def _fetch_response(
else:
logger.debug(
f"Calling LLM {self.model} with input:\n"
f"{json.dumps(list_input, indent=2)}\n"
f"Tools:\n{json.dumps(converted_tools.tools, indent=2)}\n"
f"{json.dumps(list_input, indent=2, ensure_ascii=False)}\n"
f"Tools:\n{json.dumps(converted_tools.tools, indent=2, ensure_ascii=False)}\n"
f"Stream: {stream}\n"
f"Tool choice: {tool_choice}\n"
f"Response format: {response_format}\n"
Expand Down