Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while loading pipelines from yaml files #7804

Closed
1 task done
IronD7 opened this issue Jun 5, 2024 · 2 comments
Closed
1 task done

Error while loading pipelines from yaml files #7804

IronD7 opened this issue Jun 5, 2024 · 2 comments

Comments

@IronD7
Copy link

IronD7 commented Jun 5, 2024

Describe the bug
I've tried loading a Pipeline from a yaml file, it fails with an Error. The same pipeline as a String can be deserialized successfully (see To Reproduce section)

Error message

File ~/anaconda3/envs/env/lib/python3.10/site-packages/haystack/core/pipeline/pipeline.py:151, in Pipeline.from_dict(cls, data, callbacks, **kwargs)
135 @classmethod
136 def from_dict(
137 cls: Type[T], data: Dict[str, Any], callbacks: Optional[DeserializationCallbacks] = None, **kwargs
138 ) -> T:
139 """
140 Deserializes the pipeline from a dictionary.
141
(...)
149 Deserialized component.
150 """
--> 151 metadata = data.get("metadata", {})
152 max_loops_allowed = data.get("max_loops_allowed", 100)
153 debug_path = Path(data.get("debug_path", ".haystack_debug/"))

Expected behavior
The pipeline is loaded.

Additional context

To Reproduce
The first call is fine, the second (the string was copied from the yml file) fails

test_pipeline = """
components:
  first_addition:
    init_parameters:
      add: 2
    type: haystack.testing.sample_components.add_value.AddFixedValue
  double:
    init_parameters: {}
    type: haystack.testing.sample_components.double.Double
connections:
- receiver: double.value
  sender: first_addition.result
max_loops_allowed: 100
metadata: {}
"""
pipeline = Pipeline.loads(test_pipeline)
pipeline = Pipeline.loads("test_pipeline_01.yml")

FAQ Check

System:

  • Haystack version (commit or version number): 2.1.0
@IronD7 IronD7 changed the title Errors while loading pipelines from yaml files Error while loading pipelines from yaml files Jun 5, 2024
@anakin87
Copy link
Member

anakin87 commented Jun 5, 2024

Hello!

When loading a Pipeline from YAML, you should use Pipeline.load (instead of Pipeline.loads).

The following code works properly:

from haystack import Pipeline

test_pipeline = """
components:
  first_addition:
    init_parameters:
      add: 2
    type: haystack.testing.sample_components.add_value.AddFixedValue
  double:
    init_parameters: {}
    type: haystack.testing.sample_components.double.Double
connections:
- receiver: double.value
  sender: first_addition.result
max_loops_allowed: 100
metadata: {}
"""

pipeline = Pipeline.loads(test_pipeline)
print(pipeline)


# Save pipeline to YAML file
with open("test_pipeline_01.yaml", "w") as f:
    f.write(test_pipeline)

# Load pipeline from YAML file
with open("test_pipeline_01.yaml", "r") as f:
    pipeline = Pipeline.load(f)
print(pipeline)

Can you close the issue if the problem is solved?

@IronD7
Copy link
Author

IronD7 commented Jun 5, 2024

That works, thanks a lot for the quick response!!

@IronD7 IronD7 closed this as completed Jun 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants