replace inefficient use of to_jsonable_python (#545)
This commit is contained in:
parent
b4c7db6a50
commit
697b6e8e05
1 changed files with 11 additions and 17 deletions
|
|
@ -3,7 +3,6 @@
|
|||
from __future__ import annotations as _annotations
|
||||
|
||||
import inspect
|
||||
import json
|
||||
import re
|
||||
from collections.abc import AsyncIterator, Callable, Iterable, Sequence
|
||||
from contextlib import (
|
||||
|
|
@ -551,10 +550,7 @@ def _convert_to_content(
|
|||
return list(chain.from_iterable(_convert_to_content(item) for item in result)) # type: ignore[reportUnknownVariableType]
|
||||
|
||||
if not isinstance(result, str):
|
||||
try:
|
||||
result = json.dumps(pydantic_core.to_jsonable_python(result))
|
||||
except Exception:
|
||||
result = str(result)
|
||||
result = pydantic_core.to_json(result, fallback=str, indent=2).decode()
|
||||
|
||||
return [TextContent(type="text", text=result)]
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue