fix(prompt): preserve non-ASCII characters in tool specs serialization (#19942)

Use json.dumps with ensure_ascii=False to avoid converting Chinese
descriptions into Unicode escape sequences.

This makes logs easier to read and significantly improves LLM tool
selection accuracy (from ~48% to ~67%) by preserving the original
natural language context.
This commit is contained in:
Leo Wang
2025-12-15 01:12:14 +08:00
committed by GitHub
parent 1c62be4406
commit a1bde74e97

View File

@@ -345,7 +345,7 @@ async def chat_completion_tools_handler(
sources = []
specs = [tool["spec"] for tool in tools.values()]
tools_specs = json.dumps(specs)
tools_specs = json.dumps(specs, ensure_ascii=False)
if request.app.state.config.TOOLS_FUNCTION_CALLING_PROMPT_TEMPLATE != "":
template = request.app.state.config.TOOLS_FUNCTION_CALLING_PROMPT_TEMPLATE