-
Notifications
You must be signed in to change notification settings - Fork 3k
feat: Add utility method to auto deserialize pipeline inputs #12093
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
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ba804fe
Auto deserialization of dataclasses in pipeline.run
sjrl ca78fb7
refactoring
sjrl 453e7ee
Add support for pydantic models and dataclasses
sjrl bb11947
Merge branch 'main' of github.com:deepset-ai/haystack into auto-deser…
sjrl 799364b
improvements
sjrl 5fd5248
PR comments
sjrl 8cf82ef
expand tests
sjrl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
releasenotes/notes/coerce-pipeline-inputs-utility-d38e32c0ca3b76cd.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| --- | ||
| features: | ||
| - | | ||
| Added the ``coerce_pipeline_inputs`` utility function (importable from ``haystack``). | ||
| It deserializes serialized Haystack objects in pipeline input data based on the pipeline's input | ||
| socket types: for every provided value whose socket type involves a class exposing ``from_dict`` | ||
| (such as ``ChatMessage`` or ``Document``), plain dictionaries are converted into instances of that | ||
| class. Socket types of the form ``T``, ``list[T]``, and optionals/unions of those are supported, | ||
| and both the nested (``{"component_name": {"input_name": value}}``) and flat | ||
| (``{"input_name": value}``) input formats are accepted. This removes the need for API layers to | ||
| guess which pipeline inputs contain serialized ``ChatMessage`` objects before calling | ||
| ``Pipeline.run``: | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| from haystack import coerce_pipeline_inputs | ||
|
|
||
| inputs = coerce_pipeline_inputs(pipeline, serialized_inputs) | ||
| result = pipeline.run(inputs) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I may be wrong, but
Tool.from_dict()mutates nested fields in this dictionary, so passingvaluedirectly modifies the caller’s payload. Maybe adeepcopy(value)would fix this? (not sure it's valuable though)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.
Hmm for now I'd leave it up to the caller to the deepcopy and if need be we can open an issue in Haystack about if designing
from_dictto not mutate in place. Although I believe that was a design choice to often deserialize in place.