Shaper
The Shaper component is best described as PromptNode's helper. It makes it possible to use the full potential of PromptNode and integrate it with Haystack.
Input | Depends on the function used |
Output | Depends on the function used |
Classes | Shaper |
Usage
To initialize the Shaper, specify the function to use for modifying your variables. In this example, the node takes the value query
, and creates a list that contains this value as many times as it takes to match the length of the documents
list. This list is passed down the pipeline under the key questions
.
from haystack.nodes import Shaper
mapper = Shaper(
func="expand_value_to_list"
value="query",
target_list=[Documents],
output=questions
)
components:
- name: mapper
type: Shaper
params:
func: expand_value_to_list
inputs:
value: query
target_list: documents
outputs:
- questions
Functions
When initializing Shaper, you specify the function you want it to invoke. The supported functions are:
-
rename
Renames values without changing them.
Example:- name: shaper type: Shaper params: func: rename inputs: value: query output: [question]
-
current_datetime
Outputs the current time and/or date.
Example:- name: shaper type: Shaper params: func: current_datetime params: format: "%H:%M:%S %d/%m/%y" outputs: - date_time
-
value_to_list
Changes a value into a list. The value is repeated in the list to match the length of the list. For example, if you set the list length to five, the value is repeated in this list five times.
Example:- name:QuestionsShaper type: Shaper params: func: value_to_list inputs: value: query outputs: - questions params: target_list: [5]
-
join_lists
Joins multiple lists into a single list. -
join_strings
Takes a list of strings and changes it into a list that contains a single string. The new list contains all the original strings separated by the specified delimiter. -
join_documents
Takes a list of documents and changes it into a list containing a single document. The new list contains all the original documents separated by the specified delimiter. You can use thepattern
parameter to control how each document is represented. -
join_documents_and_scores
Takes a list of documents containing scores in their metadata and changes them into a list containing a single document. The resulting document contains both the content of the original -
format_string
Replaces values in a string. -
format_document
Changes a document into a string. You can control how the document is represented using thepattern
parameter. -
format_answer
Changes an answer into a single string. You can control how the answer is represented using thepattern
parameter. -
join_documents_to_string
Takes a list of documents and changes them into a single string. The resulting string is the joined results of all original documents separated by the delimiter you specify. You can control how each document is represented using thepattern
parameter. -
string_to_answer
Transforms a string into an answer. You can populate the answer's document IDs by extracting document references from the string. -
parse_references
Parses an answer string for document references and returns the document ids of the referenced documents. -
answers_to_strings
Extracts the content field of Answers and returns a list of strings. -
strings_to_documents
Changes a list of strings into a list of documents. -
documents_to_strings
Extracts thecontent
field of each document you pass to it and puts it in a list of strings. Each item in this list is the content of thecontent
field of one document.
In a pipeline, after performing a function, Shaper passes the new or modified values further down the pipeline.
Updated about 1 year ago