From ad7c341ccab5e113be0eab026e8ee6c00c8106e3 Mon Sep 17 00:00:00 2001 From: Joel Alexander Date: Thu, 13 Jun 2024 09:17:32 -0400 Subject: [PATCH 1/2] safe serialize obj --- parea/cookbook/langchain/trace_langchain_simple.py | 3 +-- parea/utils/universal_encoder.py | 11 +++++++---- pyproject.toml | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/parea/cookbook/langchain/trace_langchain_simple.py b/parea/cookbook/langchain/trace_langchain_simple.py index f6377fd8..2dd250b6 100644 --- a/parea/cookbook/langchain/trace_langchain_simple.py +++ b/parea/cookbook/langchain/trace_langchain_simple.py @@ -1,4 +1,3 @@ -import asyncio import os from dotenv import load_dotenv @@ -35,4 +34,4 @@ async def amain(): if __name__ == "__main__": print(main()) - print(asyncio.run(amain())) + # print(asyncio.run(amain())) diff --git a/parea/utils/universal_encoder.py b/parea/utils/universal_encoder.py index 9628a72b..c7c242be 100644 --- a/parea/utils/universal_encoder.py +++ b/parea/utils/universal_encoder.py @@ -110,16 +110,19 @@ def default(self, obj: Any): return str(obj) elif isinstance(obj, Decimal): return float(obj) - elif callable(obj): - return f"" - elif isinstance(obj, bytes): - return obj.decode(errors="ignore") elif is_numpy_instance(obj): return obj.tolist() elif is_pandas_instance(obj): return obj.to_dict(orient="records") elif dspy_response := self.handle_dspy_response(obj): return dspy_response + elif callable(obj): + try: + return f"" + except AttributeError: + return str(obj) + elif isinstance(obj, bytes): + return obj.decode(errors="ignore") else: return super().default(obj) diff --git a/pyproject.toml b/pyproject.toml index 23ad232f..abb0743d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "parea-ai" packages = [{ include = "parea" }] -version = "0.2.173" +version = "0.2.174" description = "Parea python sdk" readme = "README.md" authors = ["joel-parea-ai "] From 6c106c608266f3263e50f5ec961b0f08b47ff892 Mon Sep 17 00:00:00 2001 From: Joel Alexander Date: Thu, 13 Jun 2024 09:18:20 -0400 Subject: [PATCH 2/2] safe serialize obj --- parea/cookbook/langchain/trace_langchain_simple.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/parea/cookbook/langchain/trace_langchain_simple.py b/parea/cookbook/langchain/trace_langchain_simple.py index 2dd250b6..f6377fd8 100644 --- a/parea/cookbook/langchain/trace_langchain_simple.py +++ b/parea/cookbook/langchain/trace_langchain_simple.py @@ -1,3 +1,4 @@ +import asyncio import os from dotenv import load_dotenv @@ -34,4 +35,4 @@ async def amain(): if __name__ == "__main__": print(main()) - # print(asyncio.run(amain())) + print(asyncio.run(amain()))