Skip to content

Commit ad7c341

Browse files
committed
safe serialize obj
1 parent 701ffba commit ad7c341

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

parea/cookbook/langchain/trace_langchain_simple.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import asyncio
21
import os
32

43
from dotenv import load_dotenv
@@ -35,4 +34,4 @@ async def amain():
3534

3635
if __name__ == "__main__":
3736
print(main())
38-
print(asyncio.run(amain()))
37+
# print(asyncio.run(amain()))

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)