deepset-ai / deepset-ai/haystack
More robust `default_from_dict`, `default_to_dict` that handle Secrets, StreamingCallbackT, Tool, Toolset automatically
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 26.6k
- Forks
- 3.2k
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 194
Description
Is your feature request related to a problem? Please describe.
When users create a custom component that accepts a Secret (an API key etc) in the init, they need to define from_dict and to_dict methods. In contrast, simpler custom components can directly use the default implementations default_from_dict and default_to_dict methods, making the implementation much more compact.
Describe the solution you'd like
We should provide more robust versions of default_from_dict, default_to_dict that automatically handle the (de-)serialization of components that have a Secret in the init.
Secrets can be a first example. Later, in a separate issue/PR, other functionality could follow, for example serialize_callable or serialize_tools_or_toolset.
If all three were covered by the default_from_dict and default_to_dict, the OpenAIChatGenerator for example wouldn't need a custom implementation of from_dict and to_dict.
self.document_store.to_dict(), is another example
In addition, it would be a great simplification for users if the @component decorator automatically adds to_dict and from_dict, which internally call component_from_dict, component_to_dict
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading default_from_dict, default_to_dict, component_from_dict, and component_to_dict, then compare the custom OpenAIChatGenerator serialization mentioned in the issue. Trace how Secret, StreamingCallbackT, Tool, Toolset, and document_store are currently handled. Done means default serialization covers the requested component values and the @component decorator can supply matching methods without custom implementations.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100