kotaemon/knowledgehub/base/component.py
Nguyen Trung Duc (john) 0a3fc4b228 Correct the use of abstractmethod (#80)
* Correct abstractmethod usage

* Update interface

* Specify minimal llama-index version [ignore cache]

* Update examples
2023-11-20 11:18:53 +07:00

36 lines
961 B
Python

from abc import abstractmethod
from theflow.base import Function
class BaseComponent(Function):
"""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."""
...