-
Notifications
You must be signed in to change notification settings - Fork 2.4k
fix(dspy): Example.toDict() fails to serialize dspy.History objects #9047
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
Changes from 4 commits
597a7b4
e79dc12
c67ba33
ebb502c
2a82f8d
1d56c29
9ed984c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -193,6 +193,9 @@ def toDict(self): # noqa: N802 | |
| def convert_to_serializable(value): | ||
| if hasattr(value, "toDict"): | ||
| return value.toDict() | ||
| elif hasattr(value, "model_dump"): | ||
|
||
| # Handle Pydantic models (e.g., dspy.History) | ||
| return value.model_dump() | ||
| elif isinstance(value, list): | ||
| return [convert_to_serializable(item) for item in value] | ||
| elif isinstance(value, dict): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot is it possible to call toDict when dict() is called?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 1d56c29. Simplified the code to always use
example.toDict()instead of the conditional(example.toDict() if hasattr(example, "toDict") else dict(example)). Since Example always has thetoDict()method, the conditional was unnecessary. This ensures consistent serialization behavior and makes the code cleaner.