8000 Make to/from_dict optional by masci · Pull Request #107 · deepset-ai/canals · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Nov 28, 2023. It is now read-only.

Make to/from_dict optional #107

Merged
merged 7 commits into from
Sep 4, 2023
Merged

Make to/from_dict optional #107

merged 7 commits into from
Sep 4, 2023

Conversation

masci
Copy link
Contributor
@masci masci commented Aug 31, 2023

Writing small custom components is very common in teaching material (tutorials, presentations) and might become even more popular depending how the users will receive the new Pipelines in 2.x. Problem is, having to write a to_dict and from_dict every time is cumbersome, even if the implementation is a single line thanks to the default methods provided by canals.

The idea is to remove to_dict and from_dict from the Component protocol and make them optional. We use the default serialization methods we already have when to_dict or from_dict are not present in a component class.

Caveat: when to_dict is not present, we inspect the __init__ signature and see if the init parameters were assigned to an instance variable. If that wasn't the case, we resort to the default value of the parameter. If it doesn't have a default value, we raise an error.

ATM all the components have the serialization methods, so I changed Greet as an example of how this would look like.

@masci masci requested a review from silvanocerza September 3, 2023 07:47
@silvanocerza silvanocerza marked this pull request as ready for review September 4, 2023 10:21
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0