-
Notifications
You must be signed in to change notification settings - Fork 3
fix: serialize nested BaseModel values in dict inputs (v0.5.7) #159
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -33,6 +33,17 @@ def __init__(self, client: "VLMRunProtocol") -> None: | |||||
| self._client = client | ||||||
| self._requestor = APIRequestor(client) | ||||||
|
|
||||||
| @staticmethod | ||||||
| def _serialize_value(value: Any) -> Any: | ||||||
| """Recursively serialize a value, converting BaseModel instances to dicts.""" | ||||||
| if isinstance(value, BaseModel): | ||||||
| return value.model_dump(exclude_none=True) | ||||||
| elif isinstance(value, dict): | ||||||
| return {k: Agent._serialize_value(v) for k, v in value.items()} | ||||||
| elif isinstance(value, list): | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current implementation only handles lists. It would be more robust to also handle other sequence types like tuples, which might also contain
Suggested change
|
||||||
| return [Agent._serialize_value(item) for item in value] | ||||||
| return value | ||||||
|
|
||||||
| def _process_inputs( | ||||||
| self, inputs: Union[dict[str, Any], BaseModel, None] | ||||||
| ) -> Optional[dict[str, Any]]: | ||||||
|
|
@@ -53,6 +64,7 @@ def _process_inputs( | |||||
| DeprecationWarning, | ||||||
| stacklevel=3, | ||||||
| ) | ||||||
| return {k: self._serialize_value(v) for k, v in inputs.items()} | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For consistency with how
Suggested change
|
||||||
| return inputs | ||||||
|
|
||||||
| def get( | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| __version__ = "0.5.6" | ||
| __version__ = "0.5.7" |
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.
To improve maintainability and reduce code duplication, consider defining the
MockClientclass once at theTestAgentProcessInputsclass level or as a pytest fixture. It is repeated in every test method within this test class (e.g.,test_process_inputs_with_dict,test_process_inputs_with_basemodel, etc.), including the newly added tests.