This change remove `BaseComponent`'s: - run_raw - run_batch_raw - run_document - run_batch_document - is_document - is_batch Each component is expected to support multiple types of inputs and a single type of output. Since we want the component to work out-of-the-box with both standardized and customized use cases, supporting multiple types of inputs are expected. At the same time, to reduce the complexity of understanding how to use a component, we restrict a component to only have a single output type. To accommodate these changes, we also refactor some components to remove their run_raw, run_batch_raw... methods, and to decide the common output interface for those components. Tests are updated accordingly. Commit changes: * Add kwargs to vector store's query * Simplify the BaseComponent * Update tests * Remove support for Python 3.8 and 3.9 * Bump version 0.3.0 * Fix github PR caching still use old environment after bumping version --------- Co-authored-by: ian <ian@cinnamon.is>
36 lines
959 B
Python
36 lines
959 B
Python
from abc import abstractmethod
|
|
|
|
from theflow.base import Compose
|
|
|
|
|
|
class BaseComponent(Compose):
|
|
"""A component is a class that can be used to compose a pipeline
|
|
|
|
Benefits of component:
|
|
- Auto caching, logging
|
|
- Allow deployment
|
|
|
|
For each component, the spirit is:
|
|
- Tolerate multiple input types, e.g. str, Document, List[str], List[Document]
|
|
- Enforce single output type. Hence, the output type of a component should be
|
|
as generic as possible.
|
|
"""
|
|
|
|
inflow = None
|
|
|
|
def flow(self):
|
|
if self.inflow is None:
|
|
raise ValueError("No inflow provided.")
|
|
|
|
if not isinstance(self.inflow, BaseComponent):
|
|
raise ValueError(
|
|
f"inflow must be a BaseComponent, found {type(self.inflow)}"
|
|
)
|
|
|
|
return self.__call__(self.inflow.flow())
|
|
|
|
@abstractmethod
|
|
def run(self, *args, **kwargs):
|
|
"""Run the component."""
|
|
...
|