You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
swarms/docs/swarms/structs/stepinput.md

65 lines
3.4 KiB

# Module/Class Name: StepInput
The `StepInput` class is used to define the input parameters for the task step. It is a part of the `BaseModel` and accepts any value. This documentation will provide an overview of the class, its functionality, and usage examples.
## Overview and Introduction
The `StepInput` class is an integral part of the `swarms.structs` library, allowing users to define and pass input parameters for a specific task step. This class provides flexibility by accepting any value, allowing the user to customize the input parameters according to their requirements.
## Class Definition
The `StepInput` class is defined as follows:
```python
class StepInput(BaseModel):
__root__: Any = Field(
...,
description=("Input parameters for the task step. Any value is" " allowed."),
example='{\n"file_to_refactor": "models.py"\n}',
)
```
The `StepInput` class extends the `BaseModel` and contains a single field `__root__` of type `Any` with a description of accepting input parameters for the task step.
## Functionality and Usage
The `StepInput` class is designed to accept any input value, providing flexibility and customization for task-specific parameters. Upon creating an instance of `StepInput`, the user can define and pass input parameters as per their requirements.
### Usage Example 1:
```python
from swarms import StepInput
input_params = {"file_to_refactor": "models.py", "refactor_method": "code"}
step_input = StepInput(__root__=input_params)
```
In this example, we import the `StepInput` class from the `swarms.structs` library and create an instance `step_input` by passing a dictionary of input parameters. The `StepInput` class allows any value to be passed, providing flexibility for customization.
### Usage Example 2:
```python
from swarms import StepInput
input_params = {"input_path": "data.csv", "output_path": "result.csv"}
step_input = StepInput(__root__=input_params)
```
In this example, we again create an instance of `StepInput` by passing a dictionary of input parameters. The `StepInput` class does not restrict the type of input, allowing users to define parameters based on their specific task requirements.
### Usage Example 3:
```python
from swarms import StepInput
file_path = "config.json"
with open(file_path) as f:
input_data = json.load(f)
step_input = StepInput(__root__=input_data)
```
In this example, we read input parameters from a JSON file and create an instance of `StepInput` by passing the loaded JSON data. The `StepInput` class seamlessly accepts input data from various sources, providing versatility to the user.
## Additional Information and Tips
When using the `StepInput` class, ensure that the input parameters are well-defined and align with the requirements of the task step. When passing complex data structures, such as nested dictionaries or JSON objects, ensure that the structure is valid and well-formed.
## References and Resources
- For further information on the `BaseModel` and `Field` classes, refer to the Pydantic documentation: [Pydantic Documentation](https://pydantic-docs.helpmanual.io/)
The `StepInput` class within the `swarms.structs` library is a versatile and essential component for defining task-specific input parameters. Its flexibility in accepting any value and seamless integration with diverse data sources make it a valuable asset for customizing input parameters for task steps.