|
| 1 | +--- |
| 2 | +title: Batch Run |
| 3 | +slug: /batch-run |
| 4 | +--- |
| 5 | + |
| 6 | +import Icon from "@site/src/components/icon"; |
| 7 | +import Tabs from '@theme/Tabs'; |
| 8 | +import TabItem from '@theme/TabItem'; |
| 9 | +import PartialParams from '@site/docs/_partial-hidden-params.mdx'; |
| 10 | +import PartialDevModeWindows from '@site/docs/_partial-dev-mode-windows.mdx'; |
| 11 | + |
| 12 | +The **Batch Run** component runs a language model over _each row of one text column_ in a [`DataFrame`](/data-types#dataframe), and then returns a new `DataFrame` with the original text and an LLM response. |
| 13 | +The output contains the following columns: |
| 14 | + |
| 15 | +* `text_input`: The original text from the input `DataFrame` |
| 16 | +* `model_response`: The model's response for each input |
| 17 | +* `batch_index`: The 0-indexed processing order for all rows in the `DataFrame` |
| 18 | +* `metadata` (optional): Additional information about the processing |
| 19 | + |
| 20 | +### Use the Batch Run component in a flow |
| 21 | + |
| 22 | +If you pass the **Batch Run** output to a [**Parser** component](/parser), you can use variables in the parsing template to reference these keys, such as `{text_input}` and `{model_response}`. |
| 23 | +This is demonstrated in the following example. |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | +1. Connect any language model component to a **Batch Run** component's **Language model** port. |
| 28 | + |
| 29 | +2. Connect `DataFrame` output from another component to the **Batch Run** component's **DataFrame** input. |
| 30 | +For example, you could connect a **Read File** component with a CSV file. |
| 31 | + |
| 32 | +3. In the **Batch Run** component's **Column Name** field, enter the name of the column in the incoming `DataFrame` that contains the text to process. |
| 33 | +For example, if you want to extract text from a `name` column in a CSV file, enter `name` in the **Column Name** field. |
| 34 | + |
| 35 | +4. Connect the **Batch Run** component's **Batch Results** output to a **Parser** component's **DataFrame** input. |
| 36 | + |
| 37 | +5. Optional: In the **Batch Run** [component's header menu](/concepts-components#component-menus), click <Icon name="SlidersHorizontal" aria-hidden="true"/> **Controls**, enable the **System Message** parameter, click **Close**, and then enter an instruction for how you want the LLM to process each cell extracted from the file. |
| 38 | +For example, `Create a business card for each name.` |
| 39 | + |
| 40 | +6. In the **Parser** component's **Template** field, enter a template for processing the **Batch Run** component's new `DataFrame` columns (`text_input`, `model_response`, and `batch_index`): |
| 41 | + |
| 42 | + For example, this template uses three columns from the resulting, post-batch `DataFrame`: |
| 43 | + |
| 44 | + ```text |
| 45 | + record_number: {batch_index}, name: {text_input}, summary: {model_response} |
| 46 | + ``` |
| 47 | + |
| 48 | +7. To test the processing, click the **Parser** component, click <Icon name="Play" aria-hidden="true" /> **Run component**, and then click <Icon name="TextSearch" aria-hidden="true" /> **Inspect output** to view the final `DataFrame`. |
| 49 | + |
| 50 | + You can also connect a **Chat Output** component to the **Parser** component if you want to see the output in the **Playground**. |
| 51 | + |
| 52 | +### Batch Run parameters |
| 53 | + |
| 54 | +<PartialParams /> |
| 55 | + |
| 56 | +| Name | Type | Description | |
| 57 | +|------|------|-------------| |
| 58 | +| model | HandleInput | Input parameter. Connect the 'Language Model' output from a language model component. Required. | |
| 59 | +| system_message | MultilineInput | Input parameter. A multi-line system instruction for all rows in the DataFrame. | |
| 60 | +| df | DataFrameInput | Input parameter. The DataFrame whose column is treated as text messages, as specified by 'column_name'. Required. | |
| 61 | +| column_name | MessageTextInput | Input parameter. The name of the DataFrame column to treat as text messages. If empty, all columns are formatted in TOML. | |
| 62 | +| output_column_name | MessageTextInput | Input parameter. Name of the column where the model's response is stored. Default=`model_response`. | |
| 63 | +| enable_metadata | BoolInput | Input parameter. If `True`, add metadata to the output DataFrame. | |
| 64 | +| batch_results | DataFrame | Output parameter. A DataFrame with all original columns plus the model's response column. | |
| 65 | + |
0 commit comments