Skip to content

Commit

Permalink
linter
Browse files Browse the repository at this point in the history
  • Loading branch information
masci committed Jun 4, 2024
1 parent 99c20db commit 18871bd
Showing 1 changed file with 36 additions and 34 deletions.
70 changes: 36 additions & 34 deletions haystack_experimental/components/wrappers/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,49 +9,50 @@

@component
class PipelineWrapper:
def __init__(self, pipeline: Pipeline) -> None:
"""
PipelineWrapper wraps a pipeline into a single component.
"""
PipelineWrapper wraps a pipeline into a single component.
This component has the same inputs as the wrapped pipeline. The wrapped pipeline might have
a component expecting multiple inputs like this:
This component has the same inputs as the wrapped pipeline. The wrapped pipeline might have
a component expecting multiple inputs like this:
```python
{
'llm': {
'prompt': {'type': ..., 'is_mandatory': True},
'generation_kwargs': {'type': ..., 'is_mandatory': False, 'default_value': None}
}
```python
{
'llm': {
'prompt': {'type': ..., 'is_mandatory': True},
'generation_kwargs': {'type': ..., 'is_mandatory': False, 'default_value': None}
}
```
}
```
In turn, this wrapper components would have nested inputs:
In turn, this wrapper components would have nested inputs:
```python
{
"this_component": {
'llm': {
'prompt': {'type': ..., 'is_mandatory': True},
'generation_kwargs': {'type': ..., 'is_mandatory': False, 'default_value': None}
}
}
```python
{
"this_component": {
'llm': {
'prompt': {'type': ..., 'is_mandatory': True},
'generation_kwargs': {'type': ..., 'is_mandatory': False, 'default_value': None}
}
}
````
}
````
This component would be difficult to connect, so we wrap the data we send to the pipeline and
the return value of the pipeline using this convention:
This component would be difficult to connect, so we wrap the data we send to the pipeline and
the return value of the pipeline using this convention:
<this component input> -> <wrapped_component_name>:<wrapped_input_name>
<this component input> -> <wrapped_component_name>:<wrapped_input_name>
the inputs of this component would then be:
the inputs of this component would then be:
```python
{
'llm:prompt': {...},
'llm.generation_kwargs': {...}
}
```
"""
```python
{
'llm:prompt': {...},
'llm.generation_kwargs': {...}
}
```
"""

def __init__(self, pipeline: Pipeline) -> None:
self._pipeline_instance = pipeline
self.pipeline = pipeline.to_dict()

Expand All @@ -73,6 +74,7 @@ def __init__(self, pipeline: Pipeline) -> None:
def run(self, **kwargs):
"""
Before running the wrapped pipeline, we unwrap `kwargs`, so we can invoke the underlying pipeline.
For example, if the following is passed as `kwargs` (note the "wrapping convention" of the input):
```python
Expand All @@ -94,7 +96,7 @@ def run(self, **kwargs):
ret = self._pipeline_instance.run(data=dict(unwrapped_data))

# Wrap the return value of the pipeline run
wrapped_ret = dict()
wrapped_ret = {}
for k, v in ret.items():
component_name = k
for output_name, ret_value in v.items():
Expand Down

0 comments on commit 18871bd

Please sign in to comment.