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.
85 lines
2.9 KiB
85 lines
2.9 KiB
## Module/Class Name: TaskInput
|
|
|
|
The `TaskInput` class is designed to handle the input parameters for a task. It is an abstract class that serves as the base model for input data manipulation.
|
|
|
|
### Overview and Introduction
|
|
The `TaskInput` class is an essential component of the `swarms.structs` library, allowing users to define and pass input parameters to tasks. It is crucial for ensuring the correct and structured input to various tasks and processes within the library.
|
|
|
|
### Class Definition
|
|
|
|
#### TaskInput Class:
|
|
- Parameters:
|
|
- `__root__` (Any): The input parameters for the task. Any value is allowed.
|
|
|
|
### Disclaimer:
|
|
It is important to note that the `TaskInput` class extends the `BaseModel` from the `pydantic` library. This means that it inherits all the properties and methods of the `BaseModel`.
|
|
|
|
### Functionality and Usage
|
|
The `TaskInput` class encapsulates the input parameters in a structured format. It allows for easy validation and manipulation of input data.
|
|
|
|
#### Usage Example 1: Using TaskInput for Debugging
|
|
```python
|
|
from pydantic import BaseModel, Field
|
|
|
|
from swarms.structs import TaskInput
|
|
|
|
|
|
class DebugInput(TaskInput):
|
|
debug: bool
|
|
|
|
|
|
# Creating an instance of DebugInput
|
|
debug_params = DebugInput(__root__={"debug": True})
|
|
|
|
# Accessing the input parameters
|
|
print(debug_params.debug) # Output: True
|
|
```
|
|
|
|
#### Usage Example 2: Using TaskInput for Task Modes
|
|
```python
|
|
from pydantic import BaseModel, Field
|
|
|
|
from swarms.structs import TaskInput
|
|
|
|
|
|
class ModeInput(TaskInput):
|
|
mode: str
|
|
|
|
|
|
# Creating an instance of ModeInput
|
|
mode_params = ModeInput(__root__={"mode": "benchmarks"})
|
|
|
|
# Accessing the input parameters
|
|
print(mode_params.mode) # Output: benchmarks
|
|
```
|
|
|
|
#### Usage Example 3: Using TaskInput with Arbitrary Parameters
|
|
```python
|
|
from pydantic import BaseModel, Field
|
|
|
|
from swarms.structs import TaskInput
|
|
|
|
|
|
class ArbitraryInput(TaskInput):
|
|
message: str
|
|
quantity: int
|
|
|
|
|
|
# Creating an instance of ArbitraryInput
|
|
arbitrary_params = ArbitraryInput(__root__={"message": "Hello, world!", "quantity": 5})
|
|
|
|
# Accessing the input parameters
|
|
print(arbitrary_params.message) # Output: Hello, world!
|
|
print(arbitrary_params.quantity) # Output: 5
|
|
```
|
|
|
|
### Additional Information and Tips
|
|
- The `TaskInput` class can be extended to create custom input models with specific parameters tailored to individual tasks.
|
|
- The `Field` class from `pydantic` can be used to specify metadata and constraints for the input parameters.
|
|
|
|
### References and Resources
|
|
- Official `pydantic` Documentation: [https://pydantic-docs.helpmanual.io/](https://pydantic-docs.helpmanual.io/)
|
|
- Additional resources on data modelling with `pydantic`: [https://www.tiangolo.com/blog/2021/02/16/real-python-tutorial-modern-fastapi-pydantic/](https://www.tiangolo.com/blog/2021/02/16/real-python-tutorial-modern-fastapi-pydantic/)
|
|
|
|
This documentation presents the `TaskInput` class, its usage, and practical examples for creating and handling input parameters within the `swarms.structs` library.
|