Skip to content

Commit

Permalink
Merge branch 'refs/heads/main' into feat/ready_made_supercomponents
Browse files Browse the repository at this point in the history
# Conflicts:
#	haystack_experimental/core/super_component/super_component.py
  • Loading branch information
mathislucka committed Feb 7, 2025
2 parents eac0142 + 4aa3bf7 commit 4f71375
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions haystack_experimental/core/super_component/super_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from typing import Any, Dict, List, Optional, Tuple

from haystack import Pipeline, component
from haystack.core.serialization import default_from_dict, default_to_dict
from haystack.core.serialization import default_from_dict, default_to_dict, generate_qualified_class_name

from haystack_experimental.core.super_component.utils import _delegate_default, is_compatible

Expand All @@ -21,14 +21,14 @@ class SuperComponent:
"""
A class for creating super components that wrap around a Pipeline.
This wrapper allows for remapping of input and output socket names between the wrapped
This component allows for remapping of input and output socket names between the wrapped
pipeline and the external interface. It handles type checking and verification of all
mappings.
:param pipeline: The pipeline wrapped by the component
:param input_mapping: Mapping from wrapper input names to lists of pipeline socket paths
:param input_mapping: Mapping from component input names to lists of pipeline socket paths
in format "component_name.socket_name"
:param output_mapping: Mapping from pipeline socket paths to wrapper output names
:param output_mapping: Mapping from pipeline socket paths to component output names
:raises InvalidMappingError: If any input or output mappings are invalid or if type
conflicts are detected
:raises ValueError: If no pipeline is provided
Expand Down Expand Up @@ -63,18 +63,23 @@ def warm_up(self) -> None:

def to_dict(self) -> Dict[str, Any]:
"""
Convert the pipeline wrapper to a dictionary representation.
Convert the SuperComponent to a dictionary representation.
:return: Dictionary containing serialized pipeline wrapper data
Must be overwritten for custom component implementations that inherit from SuperComponent.
:return: Dictionary containing serialized super component data
"""
return self._to_super_component_dict()


@classmethod
def from_dict(cls, data: Dict[str, Any]) -> "SuperComponent":
"""
Create a pipeline wrapper instance from a dictionary representation.
Create the SuperComponent instance from a dictionary representation.
Must be overwritten for custom component implementations that inherit from SuperComponent.
:param data: Dictionary containing serialized pipeline wrapper data
:param data: Dictionary containing serialized super component data
:return: New PipelineWrapper instance
"""
pipeline = Pipeline.from_dict(data["init_parameters"]["pipeline"])
Expand Down Expand Up @@ -416,5 +421,5 @@ def _to_super_component_dict(self) -> Dict[str, Any]:
pipeline=serialized_pipeline,
input_mapping=self.input_mapping, output_mapping=self.output_mapping
)
serialized["type"] = "haystack_experimental.core.super_component.super_component.SuperComponent"
serialized["type"] = generate_qualified_class_name(SuperComponent)
return serialized

0 comments on commit 4f71375

Please sign in to comment.