Iterator

The Iterator component is a generic connector that allows users to iterate over an array of data.

#Release Stage

Alpha

#Configuration

To configure an Iterator, you need to specify three pieces of information

NameKeyTypeDescription
Input (required)inputstringThe data you want to iterate over
Components (required)componentsarray[object]Array of components
Output Elements (required)outputElementsobjectOutput of the iterator

#Input

The input data is the data you want to iterate over. For example, if a component named comp-splits outputs an array of text, then we can use "input": "${comp-splits.output.texts}" for the iterator configuration.

#Components

The components array shares exactly the same structure as the component array in the pipeline recipe. You can put multiple components inside the Iterator. The only difference is that the components within the Iterator can use the element of the Iterator as input by using the syntax ${iterator.element}.

#Output Elements

The outputElements is a string-to-string map. You can specify the output of the Iterator, and the Iterator will concatenate all the data into an array. For instance, in the following recipe example, if we configure the output as "outputElements": { "result": "${base64.output.data}"}, the Iterator will collect the ${base64.output.data} data from each iteration and merge them into an array.

#Example Recipe


{
"version": "v1beta",
"trigger": {
"trigger_by_request": {
"request_fields": {
"text": {
"title": "text",
"instill_format": "string"
}
},
"response_fields": {
"out": {
"title": "out",
"value": "${iterator.output.result}"
}
}
}
}
"components": [
{
"id": "comp-splits",
"operator_component": {
"definition_name": "operator-definitions/text",
"task": "TASK_SPLIT_BY_TOKEN",
"input": {
"chunk_token_size": 5,
"model": "gpt-4",
"text": "${trigger.text}"
}
}
},
{
"id": "iterator",
"iterator_component": {
"input": "${comp-splits.output.text_chunks}",
"output_elements": {
"result": "${base64.output.data}"
},
"components": [
{
"id": "base64",
"operator_component": {
"definition_name": "operator-definitions/base64",
"task": "TASK_ENCODE",
"input": {
"data": "${iterator.element}"
}
}
}
]
}
}
]
}

Last updated: 6/18/2024, 11:35:38 AM