mirror of
https://github.com/deepset-ai/haystack.git
synced 2026-01-08 13:06:29 +00:00
Sync Haystack API reference on Docusaurus (#10266)
Co-authored-by: vblagoje <458335+vblagoje@users.noreply.github.com>
This commit is contained in:
parent
20f464706f
commit
d7f32fd9cb
@ -79,26 +79,30 @@ from haystack.dataclasses import ByteStream
|
||||
from haystack.components.routers import ConditionalRouter
|
||||
|
||||
routes = [
|
||||
{
|
||||
"condition": "{{streams|length > 2}}",
|
||||
"output": "{{streams}}",
|
||||
"output_name": "enough_streams",
|
||||
"output_type": list[ByteStream],
|
||||
{"condition": "{{count > 5}}",
|
||||
"output": "Processing many items",
|
||||
"output_name": "many_items",
|
||||
"output_type": str,
|
||||
},
|
||||
{
|
||||
"condition": "{{streams|length <= 2}}",
|
||||
"output": "{{streams}}",
|
||||
"output_name": "insufficient_streams",
|
||||
"output_type": list[ByteStream],
|
||||
{"condition": "{{count <= 5}}",
|
||||
"output": "Processing few items",
|
||||
"output_name": "few_items",
|
||||
"output_type": str,
|
||||
},
|
||||
]
|
||||
|
||||
pipe = Pipeline()
|
||||
pipe.add_component("router", router)
|
||||
...
|
||||
pipe.connect("router.enough_streams", "some_component_a.streams")
|
||||
pipe.connect("router.insufficient_streams", "some_component_b.streams_or_some_other_input")
|
||||
...
|
||||
pipe.add_component("router", ConditionalRouter(routes))
|
||||
|
||||
# Run with count > 5
|
||||
result = pipe.run({"router": {"count": 10}})
|
||||
print(result)
|
||||
# >> {'router': {'many_items': 'Processing many items'}}
|
||||
|
||||
# Run with count <= 5
|
||||
result = pipe.run({"router": {"count": 3}})
|
||||
print(result)
|
||||
# >> {'router': {'few_items': 'Processing few items'}}
|
||||
```
|
||||
|
||||
<a id="conditional_router.ConditionalRouter.__init__"></a>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user