deepset-ai / canals

A component orchestration engine
https://deepset-ai.github.io/canals/
Apache License 2.0
27 stars 3 forks source link

Add component `from_dict` and `to_dict` methods #68

Closed silvanocerza closed 1 year ago

silvanocerza commented 1 year ago

Add from_dict and to_dict to Component interface.

All classes decorated with @components will have a default implementation added.

Given a MyComponent class that accepts a value parameter in __init__ to_dict() will create a dictionary similar to this:

{
        "hash": <id_of_the_instance>,
        "type": "MyComponent",
        "init_parameters": { "value": 100 },
 }

MyComponent.from_dict() will instead return a new instance of MyComponent given the above dictionary.

Trying to call OtherComponent.from_dict() using the above dictionary will fail.