-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementing base class for logic and pipelines
- Loading branch information
1 parent
e005b74
commit 555a64f
Showing
2 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
from ..schemas.df_config import Config | ||
from typing import Union, Optional | ||
from pandasai.responses.context import Context | ||
from ..helpers.logger import Logger | ||
from pandasai.responses.response_parser import ResponseParser | ||
from abc import ABC, abstractmethod | ||
|
||
|
||
class BaseLogic(ABC): | ||
""" | ||
Logic units for pipeline. | ||
""" | ||
|
||
def __init__(self, input_): | ||
self.input_ = input_ | ||
|
||
@abstractmethod | ||
def call(self, input_): | ||
""" | ||
This method will return output according to | ||
Implementation.""" | ||
pass | ||
|
||
|
||
class PromptRequestLogic(BaseLogic): | ||
""" | ||
Logic units for pipeline. | ||
""" | ||
|
||
def __init__(self, input_): | ||
self.input_ = input_ | ||
super().__init__(input_) | ||
|
||
def call(self): | ||
""" | ||
This method will return output according to | ||
implementation. | ||
""" | ||
pass | ||
|
||
|
||
class Pipeline: | ||
""" | ||
Base Pipeline class to be extended for other pipelines. | ||
""" | ||
|
||
_config: Config = None | ||
_logger: Logger | ||
_logics: list(BaseLogic) | ||
|
||
def __init__( | ||
self, | ||
config: Union[Config, dict] = None, | ||
context: Optional[Context] = None, | ||
logics: Optional(list(PromptRequestLogic)) = None, | ||
): | ||
""" | ||
Intialize the pipeline with given context and configuration | ||
parameters. | ||
Args : | ||
context (Context) : Context is required for ResponseParsers. | ||
config (dict) : The configuration to pipeline. | ||
""" | ||
|
||
if isinstance(config, dict): | ||
config = Config(**config) | ||
|
||
self._config = config | ||
|
||
self._logger = Logger( | ||
save_logs=self._config.save_logs, verbose=self._config.verbose | ||
) | ||
if not context: | ||
context = Context(self._config, self.logger, self.engine) | ||
|
||
if self._config.response_parser: | ||
self._response_parser = self._config.response_parser(context) | ||
else: | ||
self._response_parser = ResponseParser(context) | ||
|
||
@abstractmethod | ||
def execute(self): | ||
""" | ||
This functions is responsible to loop through logic and | ||
Implementation. | ||
""" | ||
pass |