mirror of
https://github.com/deepset-ai/haystack.git
synced 2025-12-16 09:38:07 +00:00
fix: OutputAdapter from_dict with custom_filters None (#8173)
Co-authored-by: Marie-Luise Klaus <marieluise.klaus@deepset.ai>
This commit is contained in:
parent
a4eb88e7ea
commit
ec02817f14
@ -139,8 +139,13 @@ class OutputAdapter:
|
|||||||
"""
|
"""
|
||||||
init_params = data.get("init_parameters", {})
|
init_params = data.get("init_parameters", {})
|
||||||
init_params["output_type"] = deserialize_type(init_params["output_type"])
|
init_params["output_type"] = deserialize_type(init_params["output_type"])
|
||||||
for name, filter_func in init_params.get("custom_filters", {}).items():
|
|
||||||
init_params["custom_filters"][name] = deserialize_callable(filter_func) if filter_func else None
|
custom_filters = init_params.get("custom_filters", {})
|
||||||
|
if custom_filters:
|
||||||
|
init_params["custom_filters"] = {
|
||||||
|
name: deserialize_callable(filter_func) if filter_func else None
|
||||||
|
for name, filter_func in custom_filters.items()
|
||||||
|
}
|
||||||
return default_from_dict(cls, data)
|
return default_from_dict(cls, data)
|
||||||
|
|
||||||
def _extract_variables(self, env: SandboxedEnvironment) -> Set[str]:
|
def _extract_variables(self, env: SandboxedEnvironment) -> Set[str]:
|
||||||
|
|||||||
@ -0,0 +1,4 @@
|
|||||||
|
---
|
||||||
|
fixes:
|
||||||
|
- |
|
||||||
|
Fix Output Adapter from_dict method when custom_filters value is None.
|
||||||
@ -129,6 +129,22 @@ class TestOutputAdapter:
|
|||||||
# invoke the custom filter to check if it is deserialized correctly
|
# invoke the custom filter to check if it is deserialized correctly
|
||||||
assert deserialized_adapter.custom_filters["custom_filter"]("test") == "TEST"
|
assert deserialized_adapter.custom_filters["custom_filter"]("test") == "TEST"
|
||||||
|
|
||||||
|
def test_output_adapter_from_dict_custom_filters_none(self):
|
||||||
|
component = OutputAdapter.from_dict(
|
||||||
|
data={
|
||||||
|
"type": "haystack.components.converters.output_adapter.OutputAdapter",
|
||||||
|
"init_parameters": {
|
||||||
|
"template": "{{ documents[0].content}}",
|
||||||
|
"output_type": "str",
|
||||||
|
"custom_filters": None,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
assert component.template == "{{ documents[0].content}}"
|
||||||
|
assert component.output_type == str
|
||||||
|
assert component.custom_filters == {}
|
||||||
|
|
||||||
def test_output_adapter_in_pipeline(self):
|
def test_output_adapter_in_pipeline(self):
|
||||||
@component
|
@component
|
||||||
class DocumentProducer:
|
class DocumentProducer:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user