File tree Expand file tree Collapse file tree 1 file changed +5
-1
lines changed
Expand file tree Collapse file tree 1 file changed +5
-1
lines changed Original file line number Diff line number Diff line change 3434dictionaries containing only such values. Anything else (objects, functions, etc) will raise an exception at init
3535time. If there's the need for such values, consider serializing them to a string.
3636
37- _(TODO explain how to use classes and functions in init. In the meantime see `test/components/test_accumulate.py`)_
37+ If you need to accept classes or callables, accept either a string import path or the callable itself. Resolve strings
38+ to objects in `__init__`, and serialize objects back to importable strings in `to_dict()` so that `from_dict()` can load
39+ them (for example, store `"module_path.symbol_name"` and load it via `importlib`). This keeps init parameters JSON
40+ serializable for pipeline save/load. See `haystack.testing.sample_components.accumulate.Accumulate` for a reference
41+ implementation.
3842
3943The `__init__` must be extremely lightweight, because it's a frequent operation during the construction and
4044validation of the pipeline. If a component has some heavy state to initialize (models, backends, etc...) refer to
You can’t perform that action at this time.
0 commit comments