Skip to content

Commit 0769b4b

Browse files
authored
Merge pull request #932 from parea-ai/safe-serialize-obj
safe serialize obj
2 parents 701ffba + 6c106c6 commit 0769b4b

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

parea/utils/universal_encoder.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,19 @@ def default(self, obj: Any):
110110
return str(obj)
111111
elif isinstance(obj, Decimal):
112112
return float(obj)
113-
elif callable(obj):
114-
return f"<callable {obj.__name__}>"
115-
elif isinstance(obj, bytes):
116-
return obj.decode(errors="ignore")
117113
elif is_numpy_instance(obj):
118114
return obj.tolist()
119115
elif is_pandas_instance(obj):
120116
return obj.to_dict(orient="records")
121117
elif dspy_response := self.handle_dspy_response(obj):
122118
return dspy_response
119+
elif callable(obj):
120+
try:
121+
return f"<callable {obj.__name__}>"
122+
except AttributeError:
123+
return str(obj)
124+
elif isinstance(obj, bytes):
125+
return obj.decode(errors="ignore")
123126
else:
124127
return super().default(obj)
125128

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ build-backend = "poetry.core.masonry.api"
66
[tool.poetry]
77
name = "parea-ai"
88
packages = [{ include = "parea" }]
9-
version = "0.2.173"
9+
version = "0.2.174"
1010
description = "Parea python sdk"
1111
readme = "README.md"
1212
authors = ["joel-parea-ai <[email protected]>"]

0 commit comments

Comments
 (0)