Skip to content

Commit fe18d7f

Browse files
authored
Feature/storage provider ingestion (Pipelex#118)
1 parent 7f7b3df commit fe18d7f

5 files changed

Lines changed: 51 additions & 7 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Storage Provider Injection
2+
3+
⚠️ Under construction

pipelex/hub.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@
44
from kajson.class_registry_abstract import ClassRegistryAbstract
55

66
from pipelex import log
7-
from pipelex.cogt.content_generation.content_generator_protocol import ContentGeneratorProtocol
7+
from pipelex.cogt.content_generation.content_generator_protocol import (
8+
ContentGeneratorProtocol,
9+
)
810
from pipelex.cogt.imgg.imgg_worker_abstract import ImggWorkerAbstract
911
from pipelex.cogt.inference.inference_manager_protocol import InferenceManagerProtocol
1012
from pipelex.cogt.llm.llm_models.llm_deck_abstract import LLMDeckAbstract
1113
from pipelex.cogt.llm.llm_models.llm_engine_blueprint import LLMEngineBlueprint
12-
from pipelex.cogt.llm.llm_models.llm_model_provider_abstract import LLMModelProviderAbstract
14+
from pipelex.cogt.llm.llm_models.llm_model_provider_abstract import (
15+
LLMModelProviderAbstract,
16+
)
1317
from pipelex.cogt.llm.llm_worker_abstract import LLMWorkerAbstract
1418
from pipelex.cogt.ocr.ocr_worker_abstract import OcrWorkerAbstract
1519
from pipelex.cogt.plugin_manager import PluginManager
@@ -28,6 +32,7 @@
2832
from pipelex.tools.config.manager import config_manager
2933
from pipelex.tools.config.models import ConfigRoot
3034
from pipelex.tools.secrets.secrets_provider_abstract import SecretsProviderAbstract
35+
from pipelex.tools.storage.storage_provider_abstract import StorageProviderAbstract
3136
from pipelex.tools.templating.template_provider_abstract import TemplateProviderAbstract
3237

3338

@@ -46,6 +51,7 @@ def __init__(self):
4651
self._secrets_provider: Optional[SecretsProviderAbstract] = None
4752
self._template_provider: Optional[TemplateProviderAbstract] = None
4853
self._class_registry: Optional[ClassRegistryAbstract] = None
54+
self._storage_provider: Optional[StorageProviderAbstract] = None
4955
# cogt
5056
self._llm_models_provider: Optional[LLMModelProviderAbstract] = None
5157
self._llm_deck_provider: Optional[LLMDeckAbstract] = None
@@ -112,6 +118,9 @@ def reset_config(self) -> None:
112118
def set_secrets_provider(self, secrets_provider: SecretsProviderAbstract):
113119
self._secrets_provider = secrets_provider
114120

121+
def set_storage_provider(self, storage_provider: StorageProviderAbstract | None):
122+
self._storage_provider = storage_provider
123+
115124
def set_template_provider(self, template_provider: TemplateProviderAbstract):
116125
self._template_provider = template_provider
117126

@@ -198,6 +207,11 @@ def get_required_class_registry(self) -> ClassRegistryAbstract:
198207
raise RuntimeError("ClassRegistry is not initialized")
199208
return self._class_registry
200209

210+
def get_storage_provider(self) -> StorageProviderAbstract:
211+
if self._storage_provider is None:
212+
raise RuntimeError("StorageProvider is not initialized")
213+
return self._storage_provider
214+
201215
# cogt
202216

203217
def get_required_llm_models_provider(self) -> LLMModelProviderAbstract:
@@ -297,6 +311,10 @@ def get_secrets_provider() -> SecretsProviderAbstract:
297311
return get_pipelex_hub().get_required_secrets_provider()
298312

299313

314+
def get_storage_provider() -> StorageProviderAbstract:
315+
return get_pipelex_hub().get_storage_provider()
316+
317+
300318
def get_template_provider() -> TemplateProviderAbstract:
301319
return get_pipelex_hub().get_required_template_provider()
302320

@@ -391,7 +409,9 @@ def get_pipe_provider() -> PipeProviderAbstract:
391409
return get_pipelex_hub().get_required_pipe_provider()
392410

393411

394-
def get_pipes_by_domain(excluded_domains: Optional[List[str]] = None) -> Dict[str, List[str]]:
412+
def get_pipes_by_domain(
413+
excluded_domains: Optional[List[str]] = None,
414+
) -> Dict[str, List[str]]:
395415
pipes = get_pipe_provider().get_pipes()
396416
pipes_by_domain: Dict[str, List[str]] = defaultdict(list)
397417
for pipe in pipes:

pipelex/pipelex.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111

1212
from pipelex import log
1313
from pipelex.cogt.content_generation.content_generator import ContentGenerator
14-
from pipelex.cogt.content_generation.content_generator_protocol import ContentGeneratorProtocol
14+
from pipelex.cogt.content_generation.content_generator_protocol import (
15+
ContentGeneratorProtocol,
16+
)
1517
from pipelex.cogt.inference.inference_manager import InferenceManager
1618
from pipelex.cogt.llm.llm_models.llm_model import LATEST_VERSION_NAME
1719
from pipelex.cogt.llm.llm_models.llm_model_library import LLMModelLibrary
@@ -24,10 +26,16 @@
2426
from pipelex.pipe_works.pipe_router import PipeRouter
2527
from pipelex.pipe_works.pipe_router_protocol import PipeRouterProtocol
2628
from pipelex.pipeline.activity.activity_manager import ActivityManager
27-
from pipelex.pipeline.activity.activity_manager_protocol import ActivityManagerNoOp, ActivityManagerProtocol
29+
from pipelex.pipeline.activity.activity_manager_protocol import (
30+
ActivityManagerNoOp,
31+
ActivityManagerProtocol,
32+
)
2833
from pipelex.pipeline.pipeline_manager import PipelineManager
2934
from pipelex.pipeline.track.pipeline_tracker import PipelineTracker
30-
from pipelex.pipeline.track.pipeline_tracker_protocol import PipelineTrackerNoOp, PipelineTrackerProtocol
35+
from pipelex.pipeline.track.pipeline_tracker_protocol import (
36+
PipelineTrackerNoOp,
37+
PipelineTrackerProtocol,
38+
)
3139
from pipelex.reporting.reporting_manager import ReportingManager
3240
from pipelex.reporting.reporting_protocol import ReportingNoOp, ReportingProtocol
3341
from pipelex.test_extras.registry_test_models import PipelexTestModels
@@ -36,6 +44,7 @@
3644
from pipelex.tools.runtime_manager import runtime_manager
3745
from pipelex.tools.secrets.env_secrets_provider import EnvSecretsProvider
3846
from pipelex.tools.secrets.secrets_provider_abstract import SecretsProviderAbstract
47+
from pipelex.tools.storage.storage_provider_abstract import StorageProviderAbstract
3948
from pipelex.tools.templating.template_library import TemplateLibrary
4049
from pipelex.tools.typing.pydantic_utils import format_pydantic_validation_error
4150

@@ -172,10 +181,11 @@ def setup(
172181
content_generator: Optional[ContentGeneratorProtocol] = None,
173182
pipe_router: Optional[PipeRouterProtocol] = None,
174183
structure_classes: Optional[List[Type[Any]]] = None,
184+
storage_provider: Optional[StorageProviderAbstract] = None,
175185
):
176186
# tools
177187
self.pipelex_hub.set_secrets_provider(secrets_provider or EnvSecretsProvider())
178-
188+
self.pipelex_hub.set_storage_provider(storage_provider)
179189
# cogt
180190
self.pipelex_hub.set_content_generator(content_generator or ContentGenerator())
181191
self.reporting_delegate.setup()

pipelex/tools/storage/__init__.py

Whitespace-only changes.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from abc import ABC, abstractmethod
2+
3+
4+
class StorageProviderAbstract(ABC):
5+
@abstractmethod
6+
def load(self, uri: str) -> bytes:
7+
pass
8+
9+
@abstractmethod
10+
def store(self, data: bytes) -> str:
11+
pass

0 commit comments

Comments
 (0)