Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vivek/fix-dynamic-schema-serialization #235

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions examples/examples/simple/core/testing-ameasure.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,14 @@ def example_response(user):
pipeline = pipeline_by_slug


async def measure_func(user):
return example_response(user)
async def measure_func(x=None):
return x


async def example_handler(pipeline_run_test_case):
(runner, test_case) = pipeline_run_test_case
user = User(
id=1,
name="John Doe",
email="john@example.com",
age=30,
)
await runner.ameasure(
measure_func,
user=user
)
result = await runner.ameasure(measure_func, x=test_case)
return result


async def main():
Expand Down
8 changes: 4 additions & 4 deletions examples/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ openai = "1.13.3"
pinecone-client = "^2.2.1"
python = "^3.8.1"
python-dotenv = "^1.0.0"
gentrace-py = {path = "../package/dist/gentrace_py-0.31.5.tar.gz", develop = true}
gentrace-py = {path = "../package/dist/gentrace_py-0.31.6.tar.gz", develop = true}

[tool.poetry.group.lint.dependencies]
black = "^23.3.0"
Expand Down
15 changes: 12 additions & 3 deletions package/gentrace/providers/step_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,25 @@ def __init__(
self.elapsed_time = elapsed_time
self.start_time = start_time
self.end_time = end_time
self.inputs = self._convert_to_dict(copy.deepcopy(inputs))
self.inputs = self._convert_to_dict(inputs)
self.model_params = model_params
self.outputs = self._convert_to_dict(copy.deepcopy(outputs))
self.context = copy.deepcopy(context or {})
self.outputs = self._convert_to_dict(outputs)
self.context = self._convert_to_dict(context or {})

def _convert_to_dict(self, obj: Any) -> Any:
if hasattr(obj, '__dict__'):
# Check for DynamicSchema Gentrace custom types
if hasattr(obj, 'from_openapi_data_oapg'):
# Primitive type
if not hasattr(obj, 'items'):
return obj
obj = {k: self._convert_to_dict(v) for k, v in obj.items()}
return obj

# Check for model_dump first (works for both v1 and v2)
if hasattr(obj, 'model_dump'):
return obj.model_dump()

# Fallback to dict() if model_dump is not available
elif hasattr(obj, 'dict'):
return obj.dict()
Expand Down
Loading