Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /farhan0167_otto-m8 /lib /otto_backend /engine /blocks.py
| from typing import List, Union | |
| from pydantic import BaseModel, ValidationError, Field, field_validator, model_validator | |
| from implementations.base import BaseImplementation | |
| class Block(BaseModel, extra = 'forbid', arbitrary_types_allowed = True): | |
| name: str | |
| block_type: str = 'simple_block' | |
| connections: list[str] = Field(description="List of connections to other blocks in the model", default=[]) | |
| run_config: dict = Field(description="Configuration for the run", default=None) | |
| implementation: Union[BaseImplementation, None] = Field(description="The implementation of the block", default=None) | |
| def validate_block_type(cls, v): | |
| """ | |
| Ensures that block_type is equal to the lowercase version of the name of the class. | |
| This is useful for ensuring that the block_type of a model is consistent with its class name. | |
| """ | |
| if cls.__name__.lower().startswith(v): | |
| return v | |
| raise ValueError(f"{cls.__name__} must have block_type '{cls.__name__.lower()}'") | |
| class StartBlock(Block): | |
| name: str = 'start' | |
| block_type: str = 'start_node' | |
| class InputBlock(Block): | |
| custom_name: str = 'user_input' | |
| block_type: str = 'input' | |
| payload: Union[str, None] = None | |
| # The input type of the block determines the type of the input in the run config that will be passed to a model. | |
| input_type: str = 'text' | |
| process_metadata: dict = {} | |
| class OutputBlock(Block): | |
| custom_name: str | |
| block_type: str = 'output' | |
| class ProcessBlock(Block): | |
| custom_name: str | |
| block_type: str = 'process' | |
| process_metadata: dict = {} | |
| class WorkflowTemplate(BaseModel, extra='forbid'): | |
| workflow_name: str | |
| input: List[InputBlock] | |
| process: List[ProcessBlock] | |
| output: List[OutputBlock] | |
| version: float = 1.0 | |
| def validate_connections(cls, values): | |
| """ | |
| Validate that all connections in the model reference valid block names. | |
| The connections are validated by checking that each connection is in the set of all block names. | |
| If a connection is not in the set of block names, a ValueError is raised. | |
| """ | |
| all_block_names = { | |
| f"input.{block['name']}" for block in values.get('input', []) | |
| }.union({ | |
| f"output.{block['name']}" for block in values.get('output', []) | |
| }).union({ | |
| f"process.{block['name']}" for block in values.get('process', []) | |
| }) | |
| # Validate that connections reference valid block names | |
| for block_list in ['input', 'output', 'process']: | |
| for block in values.get(block_list, []): | |
| for connection in block.get('connections', []): | |
| if connection not in all_block_names: | |
| raise ValueError(f"Block '{block_list}.{block['name']}' has an invalid connection to '{connection}'") | |
| return values | |
Xet Storage Details
- Size:
- 3.04 kB
- Xet hash:
- 4329b18e9be968cb64a4f9ea29e2e701d3dadd97337f572724638efb0c8748a9
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.