mirror of
https://github.com/deepset-ai/haystack.git
synced 2026-01-20 11:07:05 +00:00
* Update documentation and remove unused assets. Enhanced the 'agents' and 'components' sections with clearer descriptions and examples. Removed obsolete images and updated links for better navigation. Adjusted formatting for consistency across various documentation pages. * remove dependency * address comments * delete more empty pages * broken link * unduplicate headings * alphabetical components nav
48 lines
2.0 KiB
Plaintext
48 lines
2.0 KiB
Plaintext
---
|
|
title: "StringJoiner"
|
|
id: stringjoiner
|
|
slug: "/stringjoiner"
|
|
description: "Component to join strings from different components into a list of strings."
|
|
---
|
|
|
|
# StringJoiner
|
|
|
|
Component to join strings from different components into a list of strings.
|
|
|
|
| | |
|
|
| --- | --- |
|
|
| **Most common position in a pipeline** | After at least two other components to join their strings |
|
|
| **Mandatory run variables** | “strings”: Multiple strings from connected components. |
|
|
| **Output variables** | “strings”: A list of merged strings |
|
|
| **API reference** | [Joiners](/reference/joiners-api) |
|
|
| **GitHub link** | https://github.com/deepset-ai/haystack/blob/main/haystack/components/joiners/string_joiner.py |
|
|
|
|
## Overview
|
|
|
|
The `StringJoiner` component collects multiple string outputs from various pipeline components and combines them into a single list. This is useful when you need to merge several strings from different parts of a pipeline into a unified output.
|
|
|
|
## Usage
|
|
|
|
```python
|
|
from haystack.components.joiners import StringJoiner
|
|
from haystack.components.builders import PromptBuilder
|
|
from haystack.core.pipeline import Pipeline
|
|
|
|
string_1 = "What's Natural Language Processing?"
|
|
string_2 = "What is life?"
|
|
|
|
pipeline = Pipeline()
|
|
pipeline.add_component("prompt_builder_1", PromptBuilder("Builder 1: {{query}}"))
|
|
pipeline.add_component("prompt_builder_2", PromptBuilder("Builder 2: {{query}}"))
|
|
pipeline.add_component("string_joiner", StringJoiner())
|
|
|
|
pipeline.connect("prompt_builder_1.prompt", "string_joiner.strings")
|
|
pipeline.connect("prompt_builder_2.prompt", "string_joiner.strings")
|
|
|
|
result = pipeline.run(data={
|
|
"prompt_builder_1": {"query": string_1},
|
|
"prompt_builder_2": {"query": string_2}
|
|
})
|
|
|
|
print(result)
|
|
``` |