base.py


Overview

The base.py file provides foundational abstract base classes and utilities for defining and managing components and their parameters within the InfiniFlow system. It standardizes how component parameters are represented, validated, updated, and serialized, as well as how components themselves are initialized, invoked, and interact with a processing graph or canvas.

This file is key for enabling a modular and extensible architecture where components and their configurations can be dynamically managed, validated, and executed with controlled concurrency and error handling.


Classes and Key Functionality

ComponentParamBase (Abstract Base Class)

ComponentParamBase serves as the base class for all parameter objects associated with components. It encapsulates parameter data, validation logic, serialization, and update mechanisms.

Initialization and Properties

Methods

Usage Example

class MyComponentParams(ComponentParamBase):
    def check(self):
        self.check_string(self.description, "Description")
        self.check_positive_integer(self.max_retries, "Max retries")

params = MyComponentParams().set_name("MyParams")
params.update({"description": "Example", "max_retries": 3})
params.validate()
print(params.as_dict())

ComponentBase (Abstract Base Class)

ComponentBase defines the interface and base behavior for components in the system. Components represent functional units that process inputs and produce outputs within a canvas/graph.

Initialization

Attributes

Key Methods

Usage Example

class MyComponent(ComponentBase):
    component_name = "MyComponent"

    async def _invoke(self, **kwargs):
        # Example processing logic
        input_val = self.get_input_value("input_key")
        result = input_val * 2  # Some processing
        self.set_output("result", result)

# Usage
component = MyComponent(canvas, "comp1", params)
output = component.invoke(input_key=5)
print(output["result"])  # Expected: 10

Important Implementation Details and Algorithms


Interactions with Other System Parts


Mermaid Class Diagram

classDiagram
    class ComponentParamBase {
        - message_history_window_size: int
        - inputs: dict
        - outputs: dict
        - description: str
        - max_retries: int
        - delay_after_error: float
        - exception_method
        - exception_default_value
        - exception_goto
        - debug_inputs: dict
        + set_name(name: str)
        + check()
        + as_dict() dict
        + update(conf: dict, allow_redundant: bool) ComponentParamBase
        + extract_not_builtin() dict
        + validate()
        + check_string(param, descr)
        + check_positive_integer(param, descr)
        + check_boolean(param, descr)
        + check_and_change_lower(param, valid_list, descr)
        + _greater_equal_than(value, limit) bool
        + _less_equal_than(value, limit) bool
        + _range(value, ranges) bool
        + _in(value, list) bool
        + _not_in(value, list) bool
        + _warn_deprecated_param(param_name, descr)
        + _warn_to_deprecate_param(param_name, descr, new_param) bool
    }

    class ComponentBase {
        - component_name: str
        - thread_limiter: trio.CapacityLimiter
        - variable_ref_patt: str
        - _canvas
        - _id
        - _param: ComponentParamBase
        + __init__(canvas, id, param: ComponentParamBase)
        + invoke(**kwargs) dict
        + _invoke(**kwargs)
        + output(var_nm: str) Any
        + set_output(key: str, value: Any)
        + error() Any
        + reset(only_output: bool)
        + get_input(key: str) Any
        + get_input_values() dict
        + get_input_elements_from_text(txt: str) dict
        + get_input_elements() dict
        + get_input_form() dict
        + set_input_value(key: str, value: Any)
        + get_input_value(key: str) Any
        + get_component_name(cpn_id) str
        + get_param(name)
        + debug(**kwargs)
        + get_parent()
        + get_upstream() list
        + get_downstream() list
        + string_format(content: str, kv: dict) str
        + exception_handler() dict
        + get_exception_default_value()
        + set_exception_default_value()
        + thoughts()
    }

    ComponentBase --> ComponentParamBase : uses >

Summary

base.py defines the core abstractions for component parameters and components within InfiniFlow, providing:

This file is foundational for building reliable, extensible, and maintainable components that can be orchestrated in complex workflows.


If you need further details on specific methods or example integrations, feel free to ask!