Build AI methods with your coding agent, then run them anywhere: as an MCP for chatbots, as a webapp for people, or via API for your software.
Refactor/plugin management (#129)
Louis Choquel11ee87d715fe
diff --git a/docs/pages/advanced-customization/index.md b/docs/pages/advanced-customization/index.mdindex a30846b36..33fb3e03c 100644--- a/docs/pages/advanced-customization/index.md+++ b/docs/pages/advanced-customization/index.md@@ -16,7 +16,6 @@ from pipelex import Pipelexpipelex = Pipelex(template_provider=MyTemplateProvider(),llm_model_provider=MyLLMProvider(),- plugin_manager=MyPluginManager(),inference_manager=MyInferenceManager(),pipeline_tracker=MyPipelineTracker(),activity_manager=MyActivityManager(),@@ -38,7 +37,6 @@ from pipelex.hub import PipelexHubhub = PipelexHub()hub.set_template_provider(MyTemplateProvider())hub.set_llm_models_provider(MyLLMProvider())-hub.set_plugin_manager(MyPluginManager())# ... and so on for other components```@@ -88,54 +86,45 @@ Pipelex supports injection of the following components:- Default: `LLMModelLibrary`- [Details](llm-model-provider-injection.md)-3. **Plugin Manager** (`PluginManager`)-- - Protocol: `PluginManagerProtocol`- - Default: `PluginManager`- - [Details](plugin-manager-injection.md)--4. **Inference Manager** (`InferenceManager`)+3. **Inference Manager** (`InferenceManager`)- Protocol: `InferenceManagerProtocol`- Default: `InferenceManager`- [Details](inference-manager-injection.md)-5. **Reporting Delegate** (`ReportingManager`)+4. **Reporting Delegate** (`ReportingManager`)- Protocol: `ReportingProtocol`- Default: `ReportingManager` or `ReportingNoOp` if disabled- [Details](reporting-delegate-injection.md)-6. **Pipeline Tracker** (`PipelineTracker`)+5. **Pipeline Tracker** (`PipelineTracker`)- Protocol: `PipelineTrackerProtocol`- Default: `PipelineTracker` or `PipelineTrackerNoOp` if disabled- [Details](pipeline-tracker-injection.md)-7. **Activity Manager** (`ActivityManager`)+6. **Activity Manager** (`ActivityManager`)- Protocol: `ActivityManagerProtocol`- Default: `ActivityManager` or `ActivityManagerNoOp` if disabled- [Details](activity-manager-injection.md)-8. **Secrets Provider** (`EnvSecretsProvider`)+7. **Secrets Provider** (`EnvSecretsProvider`)- Protocol: `SecretsProviderProtocol`- Default: `EnvSecretsProvider`- [Details](secrets-provider-injection.md)-9. **Content Generator** (`ContentGenerator`)+8. **Content Generator** (`ContentGenerator`)- Protocol: `ContentGeneratorProtocol`- Default: `ContentGenerator`- [Details](content-generator-injection.md)-10. **Pipe Router** (`PipeRouter`)+9. **Pipe Router** (`PipeRouter`)- Protocol: `PipeRouterProtocol`- Default: `PipeRouter`- [Details](pipe-router-injection.md)-## Best Practices--⚠️ Under constructiondiff --git a/pipelex/cogt/exceptions.py b/pipelex/cogt/exceptions.pyindex eec64b48e..6e4388f9d 100644--- a/pipelex/cogt/exceptions.py+++ b/pipelex/cogt/exceptions.py@@ -23,6 +23,10 @@ class SdkTypeError(CogtError):pass+class SdkRegistryError(CogtError):+ pass++class LLMWorkerError(CogtError):pass@@ -128,5 +132,9 @@ class MissingDependencyError(CogtError):super().__init__(error_msg)+class MissingPluginError(CogtError):+ pass++class OcrCapabilityError(CogtError):passdiff --git a/pipelex/cogt/imgg/imgg_worker_factory.py b/pipelex/cogt/imgg/imgg_worker_factory.pyindex f9a822a98..29bc8b72b 100644--- a/pipelex/cogt/imgg/imgg_worker_factory.py+++ b/pipelex/cogt/imgg/imgg_worker_factory.py@@ -5,9 +5,9 @@ from pipelex.cogt.imgg.imgg_engine import ImggEnginefrom pipelex.cogt.imgg.imgg_platform import ImggPlatformfrom pipelex.cogt.imgg.imgg_worker_abstract import ImggWorkerAbstractfrom pipelex.cogt.llm.llm_models.llm_platform import LLMPlatform-from pipelex.cogt.plugin_manager import PluginHandlefrom pipelex.hub import get_plugin_manager, get_secretfrom pipelex.plugins.openai.openai_imgg_worker import OpenAIImggWorker+from pipelex.plugins.plugin_sdk_registry import PluginSdkHandlefrom pipelex.reporting.reporting_protocol import ReportingProtocolfrom pipelex.tools.secrets.secrets_errors import SecretNotFoundError@@ -22,8 +22,8 @@ class ImggWorkerFactory:imgg_engine: ImggEngine,reporting_delegate: Optional[ReportingProtocol] = None,) -> ImggWorkerAbstract:- imgg_sdk_handle = PluginHandle.get_for_imgg_engine(imgg_platform=imgg_engine.imgg_platform)- plugin_manager = get_plugin_manager()+ imgg_sdk_handle = PluginSdkHandle.get_for_imgg_engine(imgg_platform=imgg_engine.imgg_platform)+ plugin_sdk_registry = get_plugin_manager().plugin_sdk_registryimgg_worker: ImggWorkerAbstractmatch imgg_engine.imgg_platform:case ImggPlatform.FAL_AI:@@ -41,7 +41,9 @@ class ImggWorkerFactory:from pipelex.plugins.fal.fal_imgg_worker import FalImggWorker- imgg_sdk_instance = plugin_manager.get_imgg_sdk_instance(imgg_sdk_handle=imgg_sdk_handle) or plugin_manager.set_imgg_sdk_instance(+ imgg_sdk_instance = plugin_sdk_registry.get_imgg_sdk_instance(+ imgg_sdk_handle=imgg_sdk_handle+ ) or plugin_sdk_registry.set_imgg_sdk_instance(imgg_sdk_handle=imgg_sdk_handle,imgg_sdk_instance=FalAsyncClient(key=fal_api_key),)@@ -54,7 +56,9 @@ class ImggWorkerFactory:case ImggPlatform.OPENAI:from pipelex.plugins.openai.openai_factory import OpenAIFactory- imgg_sdk_instance = plugin_manager.get_llm_sdk_instance(llm_sdk_handle=imgg_sdk_handle) or plugin_manager.set_llm_sdk_instance(+ imgg_sdk_instance = plugin_sdk_registry.get_llm_sdk_instance(+ llm_sdk_handle=imgg_sdk_handle+ ) or plugin_sdk_registry.set_llm_sdk_instance(llm_sdk_handle=imgg_sdk_handle,llm_sdk_instance=OpenAIFactory.make_openai_client(llm_platform=LLMPlatform.OPENAI),)diff --git a/pipelex/cogt/inference/inference_manager.py b/pipelex/cogt/inference/inference_manager.pyindex 39c79b0da..26e36fbea 100644--- a/pipelex/cogt/inference/inference_manager.py+++ b/pipelex/cogt/inference/inference_manager.py@@ -1,4 +1,4 @@-from typing import Dict, Optional+from typing import Dict, Typefrom typing_extensions import override@@ -12,6 +12,7 @@ from pipelex.cogt.llm.llm_models.llm_engine_blueprint import LLMEngineBlueprintfrom pipelex.cogt.llm.llm_models.llm_engine_factory import LLMEngineFactoryfrom pipelex.cogt.llm.llm_worker_abstract import LLMWorkerAbstractfrom pipelex.cogt.llm.llm_worker_factory import LLMWorkerFactory+from pipelex.cogt.llm.llm_worker_internal_abstract import LLMWorkerInternalAbstractfrom pipelex.cogt.ocr.ocr_engine_factory import OcrEngineFactoryfrom pipelex.cogt.ocr.ocr_worker_abstract import OcrWorkerAbstractfrom pipelex.cogt.ocr.ocr_worker_factory import OcrWorkerFactory@@ -31,10 +32,16 @@ class InferenceManager(InferenceManagerProtocol):def teardown(self):self.imgg_worker_factory = ImggWorkerFactory()self.ocr_worker_factory = OcrWorkerFactory()- self.llm_workers.clear()- self.imgg_workers.clear()- self.ocr_workers.clear()- log.verbose("InferenceManagerAsync reset")+ for llm_worker in self.llm_workers.values():+ llm_worker.teardown()+ self.llm_workers = {}+ for imgg_worker in self.imgg_workers.values():+ imgg_worker.teardown()+ self.imgg_workers = {}+ for ocr_worker in self.ocr_workers.values():+ ocr_worker.teardown()+ self.ocr_workers = {}+ log.verbose("InferenceManager teardown done")def print_workers(self):log.debug("LLM Workers:")@@ -60,15 +67,15 @@ class InferenceManager(InferenceManagerProtocol):llm_handle_to_llm_engine_blueprint = get_llm_deck().llm_handleslog.verbose(f"{len(llm_handle_to_llm_engine_blueprint)} LLM engine_cards found")for llm_handle, llm_engine_blueprint in llm_handle_to_llm_engine_blueprint.items():- self._setup_one_llm_worker(llm_engine_blueprint=llm_engine_blueprint, llm_handle=llm_handle)+ self._setup_one_internal_llm_worker(llm_engine_blueprint=llm_engine_blueprint, llm_handle=llm_handle)log.verbose(f"Setup LLM worker for '{llm_handle}' on {llm_engine_blueprint.llm_platform_choice}")log.debug("Done setting up LLM Workers (async)")- def _setup_one_llm_worker(+ def _setup_one_internal_llm_worker(self,llm_engine_blueprint: LLMEngineBlueprint,llm_handle: str,- ) -> LLMWorkerAbstract:+ ) -> LLMWorkerInternalAbstract:llm_engine = LLMEngineFactory.make_llm_engine(llm_engine_blueprint=llm_engine_blueprint)llm_worker = LLMWorkerFactory.make_llm_worker(llm_engine=llm_engine,@@ -78,11 +85,7 @@ class InferenceManager(InferenceManagerProtocol):return llm_worker@override- def get_llm_worker(- self,- llm_handle: str,- specific_llm_engine_blueprint: Optional[LLMEngineBlueprint] = None,- ) -> LLMWorkerAbstract:+ def get_llm_worker(self, llm_handle: str) -> LLMWorkerAbstract:if llm_worker := self.llm_workers.get(llm_handle):return llm_workerif not get_config().cogt.inference_manager_config.is_auto_setup_preset_llm:@@ -90,15 +93,26 @@ class InferenceManager(InferenceManagerProtocol):f"No LLM worker for '{llm_handle}', set it up or enable cogt.inference_manager_config.is_auto_setup_preset_llm")- if not specific_llm_engine_blueprint:- specific_llm_engine_blueprint = get_llm_deck().get_llm_engine_blueprint(llm_handle=llm_handle)- llm_worker = self._setup_one_llm_worker(- llm_engine_blueprint=specific_llm_engine_blueprint,+ llm_engine_blueprint = get_llm_deck().get_llm_engine_blueprint(llm_handle=llm_handle)+ llm_worker = self._setup_one_internal_llm_worker(+ llm_engine_blueprint=llm_engine_blueprint,llm_handle=llm_handle,)return llm_worker+ @override+ def set_llm_worker_from_external_plugin(+ self,+ llm_handle: str,+ llm_worker_class: Type[LLMWorkerAbstract],+ should_warn_if_already_registered: bool = True,+ ):+ if llm_handle in self.llm_workers:+ if should_warn_if_already_registered:+ log.warning(f"LLM worker for '{llm_handle}' already registered, skipping")+ self.llm_workers[llm_handle] = llm_worker_class(reporting_delegate=get_report_delegate())+##################################################################################################### Manage IMGG Workers####################################################################################################diff --git a/pipelex/cogt/inference/inference_manager_protocol.py b/pipelex/cogt/inference/inference_manager_protocol.pyindex a03631506..3a9a598a7 100644--- a/pipelex/cogt/inference/inference_manager_protocol.py+++ b/pipelex/cogt/inference/inference_manager_protocol.py@@ -1,7 +1,6 @@-from typing import Optional, Protocol+from typing import Protocol, Typefrom pipelex.cogt.imgg.imgg_worker_abstract import ImggWorkerAbstract-from pipelex.cogt.llm.llm_models.llm_engine_blueprint import LLMEngineBlueprintfrom pipelex.cogt.llm.llm_worker_abstract import LLMWorkerAbstractfrom pipelex.cogt.ocr.ocr_worker_abstract import OcrWorkerAbstract@@ -20,11 +19,14 @@ class InferenceManagerProtocol(Protocol):def setup_llm_workers(self): ...- def get_llm_worker(+ def get_llm_worker(self, llm_handle: str) -> LLMWorkerAbstract: ...++ def set_llm_worker_from_external_plugin(self,llm_handle: str,- specific_llm_engine_blueprint: Optional[LLMEngineBlueprint] = None,- ) -> LLMWorkerAbstract: ...+ llm_worker_class: Type[LLMWorkerAbstract],+ should_warn_if_already_registered: bool = True,+ ): ...##################################################################################################### IMG Generation Workersdiff --git a/pipelex/cogt/inference/inference_worker_abstract.py b/pipelex/cogt/inference/inference_worker_abstract.pyindex 989be63a4..22f4510d4 100644--- a/pipelex/cogt/inference/inference_worker_abstract.py+++ b/pipelex/cogt/inference/inference_worker_abstract.py@@ -11,6 +11,12 @@ class InferenceWorkerAbstract(ABC):):self.reporting_delegate = reporting_delegate+ def setup(self):+ pass++ def teardown(self):+ pass+@property@abstractmethoddef desc(self) -> str:diff --git a/pipelex/cogt/llm/llm_models/llm_deck.py b/pipelex/cogt/llm/llm_models/llm_deck.pyindex dfe9c3265..1a2a8ff91 100644--- a/pipelex/cogt/llm/llm_models/llm_deck.py+++ b/pipelex/cogt/llm/llm_models/llm_deck.py@@ -42,17 +42,14 @@ class LLMDeck(LLMDeckAbstract, ConfigModel):@overridedef get_llm_setting(self, llm_setting_or_preset_id: LLMSettingOrPresetId) -> LLMSetting:- the_llm_setting: LLMSetting- if isinstance(llm_setting_or_preset_id, str):+ if isinstance(llm_setting_or_preset_id, LLMSetting):+ return llm_setting_or_preset_id+ else:# it's a preset idthe_llm_preset = self.llm_presets.get(llm_setting_or_preset_id)if not the_llm_preset:raise LLMPresetNotFoundError(f"LLM preset '{llm_setting_or_preset_id}' not found in deck")- the_llm_setting = the_llm_preset- else:- # it's an explict setting- the_llm_setting = llm_setting_or_preset_id- return the_llm_setting+ return the_llm_preset@overridedef get_llm_setting_for_text(self, override: Optional[LLMSettingChoices] = None) -> LLMSetting:@@ -139,6 +136,19 @@ class LLMDeck(LLMDeckAbstract, ConfigModel):)return llm_model+ @override+ def find_optional_llm_model(self, llm_handle: str) -> Optional[LLMModel]:+ llm_models_provider = get_llm_models_provider()+ llm_engine_blueprint = self.llm_handles.get(llm_handle)+ if not llm_engine_blueprint:+ return None+ llm_model = llm_models_provider.get_optional_llm_model(+ llm_name=llm_engine_blueprint.llm_name,+ llm_version=llm_engine_blueprint.llm_version,+ llm_platform_choice=llm_engine_blueprint.llm_platform_choice,+ )+ return llm_model+@override@classmethoddef final_validate(cls, deck: Self):@@ -215,11 +225,11 @@ class LLMDeck(LLMDeckAbstract, ConfigModel):value.for_object_list_direct = Nonereturn value- def add_llm_handle_to_llm_engine_blueprint(self, llm_handle: str, llm_engine_default: str):- if llm_handle in self.llm_handles:- raise ConfigValidationError(f"LLM engine blueprint for '{llm_handle}' is already defined in llm_handle_to_llm_engine_blueprint")+ def add_llm_name_as_handle_with_defaults(self, llm_name: str):+ if llm_name in self.llm_handles:+ raise ConfigValidationError(f"LLM engine blueprint for '{llm_name}' is already defined in llm deck's llm_handles")# TODO: sort the defaults by llm family- self.llm_handles[llm_handle] = LLMEngineBlueprint(llm_name=llm_engine_default)+ self.llm_handles[llm_name] = LLMEngineBlueprint(llm_name=llm_name)def validate_llm_presets(self) -> Self:for llm_preset_id, llm_setting in self.llm_presets.items():diff --git a/pipelex/cogt/llm/llm_models/llm_deck_abstract.py b/pipelex/cogt/llm/llm_models/llm_deck_abstract.pyindex 971d64dd2..40c90d7dc 100644--- a/pipelex/cogt/llm/llm_models/llm_deck_abstract.py+++ b/pipelex/cogt/llm/llm_models/llm_deck_abstract.py@@ -1,5 +1,5 @@from abc import ABC, abstractmethod-from typing import Dict, Optional+from typing import Dict, List, Optionalfrom pydantic import Fieldfrom typing_extensions import Self@@ -11,6 +11,7 @@ from pipelex.cogt.llm.llm_models.llm_setting import LLMSetting, LLMSettingChoiceclass LLMDeckAbstract(ABC):llm_handles: Dict[str, LLMEngineBlueprint] = Field(default_factory=dict)+ llm_external_handles: List[str] = Field(default_factory=list)llm_presets: Dict[str, LLMSetting] = Field(default_factory=dict)llm_choice_defaults: LLMSettingChoicesllm_choice_overrides: LLMSettingChoices = LLMSettingChoices(@@ -57,6 +58,10 @@ class LLMDeckAbstract(ABC):def find_llm_model(self, llm_handle: str) -> LLMModel:pass+ @abstractmethod+ def find_optional_llm_model(self, llm_handle: str) -> Optional[LLMModel]:+ pass+@classmethod@abstractmethoddef final_validate(cls, deck: Self):diff --git a/pipelex/cogt/llm/llm_models/llm_engine.py b/pipelex/cogt/llm/llm_models/llm_engine.pyindex 92be8cf9b..383614ce2 100644--- a/pipelex/cogt/llm/llm_models/llm_engine.py+++ b/pipelex/cogt/llm/llm_models/llm_engine.py@@ -31,7 +31,7 @@ platform llm id: '{self.llm_id}'"""@propertydef tag(self) -> str:- return f"{self.llm_platform} - {self.llm_model.llm_name} - {self.llm_model.version}"+ return f"{self.llm_platform}:{self.llm_model.llm_name}:{self.llm_model.version}:id-[{self.llm_id}]"@propertydef is_gen_object_supported(self) -> bool:diff --git a/pipelex/cogt/llm/llm_models/llm_engine_factory.py b/pipelex/cogt/llm/llm_models/llm_engine_factory.pyindex 08c12f524..a23cc6ff5 100644--- a/pipelex/cogt/llm/llm_models/llm_engine_factory.py+++ b/pipelex/cogt/llm/llm_models/llm_engine_factory.py@@ -15,7 +15,7 @@ class LLMEngineFactory:Create an instance of LLMEngine based on the parameters provided through the LLMEngineCard.Args:- llm_engine_blueprint: LLMEngineCard+ llm_engine_blueprint: LLMEngineBlueprint"""llm_platform_choice = llm_engine_blueprint.llm_platform_choicediff --git a/pipelex/cogt/llm/llm_models/llm_model_library.py b/pipelex/cogt/llm/llm_models/llm_model_library.pyindex ebb0573cd..cefefcc78 100644--- a/pipelex/cogt/llm/llm_models/llm_model_library.py+++ b/pipelex/cogt/llm/llm_models/llm_model_library.py@@ -1,5 +1,5 @@import os-from typing import Any, Dict, List+from typing import Any, Dict, List, Optionalfrom pydantic import Field, RootModelfrom typing_extensions import override@@ -84,12 +84,25 @@ class LLMModelLibrary(LLMModelProviderAbstract, RootModel[LLMModelLibraryRoot]):llm_version: str,llm_platform_choice: LLMPlatformChoice,) -> LLMModel:+ llm_model = self.get_optional_llm_model(llm_name=llm_name, llm_version=llm_version, llm_platform_choice=llm_platform_choice)+ if not llm_model:+ raise LLMModelProviderError(f"Model '{llm_name}' version '{llm_version}' not found")+ else:+ return llm_model++ @override+ def get_optional_llm_model(+ self,+ llm_name: str,+ llm_version: str,+ llm_platform_choice: LLMPlatformChoice,+ ) -> Optional[LLMModel]:if llm_version == LATEST_VERSION_NAME:- return self._get_llm_model_latest_version(llm_name=llm_name, llm_platform_choice=llm_platform_choice)+ return self._get_optional_llm_model_latest_version(llm_name=llm_name, llm_platform_choice=llm_platform_choice)found_llm_models = [llm_model for llm_model in self.root if llm_model.llm_name == llm_name and llm_model.version == llm_version]if not found_llm_models:- raise LLMModelProviderError(f"Model '{llm_name}' version '{llm_version}' not found")+ return Noneif len(found_llm_models) > 1:raise LLMModelProviderError(f"Model '{llm_name}' version '{llm_version}' has multiple instances in the library")llm_model = found_llm_models[0]@@ -100,14 +113,14 @@ class LLMModelLibrary(LLMModelProviderAbstract, RootModel[LLMModelLibraryRoot]):raise LLMModelPlatformError(f"Missing llm id for LLM model {llm_model.name_and_version}'s chosen platform='{llm_platform}'")return llm_model- def _get_llm_model_latest_version(+ def _get_optional_llm_model_latest_version(self,llm_name: str,llm_platform_choice: LLMPlatformChoice,- ) -> LLMModel:+ ) -> Optional[LLMModel]:found_llm_models = [llm_model for llm_model in self.root if llm_model.llm_name == llm_name]if not found_llm_models:- raise LLMModelProviderError(f"Could not find model named '{llm_name}'")+ return Noneelif len(found_llm_models) == 1:# only one so it is the latest we've gotllm_model = found_llm_models[0]@@ -124,3 +137,16 @@ class LLMModelLibrary(LLMModelProviderAbstract, RootModel[LLMModelLibraryRoot]):assert llm_platform_choice == DEFAULT_PLATFORM_INDICATORllm_model = max(found_llm_models, key=lambda m: m.version)return llm_model++ def _get_llm_model_latest_version(+ self,+ llm_name: str,+ llm_platform_choice: LLMPlatformChoice,+ ) -> LLMModel:+ llm_model_latest_version = self.get_optional_llm_model(+ llm_name=llm_name, llm_version=LATEST_VERSION_NAME, llm_platform_choice=llm_platform_choice+ )+ if llm_model_latest_version is not None:+ return llm_model_latest_version+ else:+ raise LLMModelProviderError(f"Could not find model named '{llm_name}'")diff --git a/pipelex/cogt/llm/llm_models/llm_model_provider_abstract.py b/pipelex/cogt/llm/llm_models/llm_model_provider_abstract.pyindex 33c4d152f..4e0562154 100644--- a/pipelex/cogt/llm/llm_models/llm_model_provider_abstract.py+++ b/pipelex/cogt/llm/llm_models/llm_model_provider_abstract.py@@ -1,6 +1,8 @@from abc import ABC, abstractmethodfrom typing import List+from mistralai import Optional+from pipelex.cogt.llm.llm_models.llm_model import LLMModelfrom pipelex.cogt.llm.llm_models.llm_platform import LLMPlatformChoice@@ -24,6 +26,15 @@ class LLMModelProviderAbstract(ABC):) -> LLMModel:pass+ @abstractmethod+ def get_optional_llm_model(+ self,+ llm_name: str,+ llm_version: str,+ llm_platform_choice: LLMPlatformChoice,+ ) -> Optional[LLMModel]:+ pass+@abstractmethoddef setup(self):passdiff --git a/pipelex/cogt/llm/llm_worker_abstract.py b/pipelex/cogt/llm/llm_worker_abstract.pyindex 1de792eca..2c4028e38 100644--- a/pipelex/cogt/llm/llm_worker_abstract.py+++ b/pipelex/cogt/llm/llm_worker_abstract.py@@ -1,15 +1,11 @@from abc import ABC, abstractmethodfrom typing import Optional, Type-from instructor.exceptions import InstructorRetryExceptionfrom typing_extensions import overridefrom pipelex import log-from pipelex.cogt.exceptions import LLMCapabilityError, LLMCompletionErrorfrom pipelex.cogt.inference.inference_worker_abstract import InferenceWorkerAbstractfrom pipelex.cogt.llm.llm_job import LLMJob-from pipelex.cogt.llm.llm_models.llm_engine import LLMEngine-from pipelex.cogt.llm.structured_output import StructureMethodfrom pipelex.pipeline.job_metadata import UnitJobIdfrom pipelex.reporting.reporting_protocol import ReportingProtocolfrom pipelex.tools.typing.pydantic_utils import BaseModelTypeVar@@ -18,21 +14,15 @@ from pipelex.tools.typing.pydantic_utils import BaseModelTypeVarclass LLMWorkerAbstract(InferenceWorkerAbstract, ABC):def __init__(self,- llm_engine: LLMEngine,- structure_method: Optional[StructureMethod],reporting_delegate: Optional[ReportingProtocol] = None,):"""Initialize the LLMWorker.Args:- llm_engine (LLMEngine): The LLM engine to be used by the worker.- structure_method (Optional[StructureMethod]): The structure method to be used by the worker.reporting_delegate (Optional[ReportingProtocol]): An optional report delegate for reporting unit jobs."""InferenceWorkerAbstract.__init__(self, reporting_delegate=reporting_delegate)- self.llm_engine = llm_engine- self.structure_method = structure_method########################################################## Instance methods@@ -41,55 +31,52 @@ class LLMWorkerAbstract(InferenceWorkerAbstract, ABC):@property@overridedef desc(self) -> str:- return f"LLM Worker using:\n{self.llm_engine.desc}"+ return "LLM Worker • if you're using an external plugin, override this method to describe your llm worker"- def _check_can_perform_job(self, llm_job: LLMJob):- # This can be overridden by subclasses for specific checks- self._check_vision_support(llm_job=llm_job)-- def _check_vision_support(self, llm_job: LLMJob):- if llm_job.llm_prompt.user_images:- if not self.llm_engine.llm_model.is_vision_supported:- raise LLMCapabilityError(f"LLM Engine '{self.llm_engine.tag}' does not support vision.")-- nb_images = len(llm_job.llm_prompt.user_images)- max_prompt_images = self.llm_engine.llm_model.max_prompt_images or 5000- if nb_images > max_prompt_images:- raise LLMCapabilityError(f"LLM Engine '{self.llm_engine.tag}' does not accept that many images: {nb_images}.")+ @property+ @abstractmethod+ def is_gen_object_supported(self) -> bool:+ return False- async def gen_text(+ async def _before_job(self,llm_job: LLMJob,- ) -> str:- log.debug("LLM Worker gen_text")- log.verbose(f"\n{self.llm_engine.desc}")- log.verbose(llm_job.params_desc)-+ ):# Verify that the job is validllm_job.validate_before_execution()# Verify feasibilityself._check_can_perform_job(llm_job=llm_job)- # TODO: Fix printing prompts that contain image bytes- # log.verbose(llm_job.llm_prompt.desc, title="llm_prompt")+ async def _after_job(+ self,+ llm_job: LLMJob,+ ):+ # Report job+ llm_job.llm_job_after_complete()+ if self.reporting_delegate:+ self.reporting_delegate.report_inference_job(inference_job=llm_job)++ def _check_can_perform_job(self, llm_job: LLMJob):+ # This can be overridden by subclasses for specific checks+ pass++ async def gen_text(+ self,+ llm_job: LLMJob,+ ) -> str:+ log.debug("LLM Worker gen_text")+ log.verbose(llm_job.params_desc)+ log.verbose(llm_job.llm_prompt.desc, title="llm_prompt")# metadatallm_job.job_metadata.unit_job_id = UnitJobId.LLM_GEN_TEXT- # Prepare job- llm_job.llm_job_before_start(llm_engine=self.llm_engine)+ await self._before_job(llm_job=llm_job)result = await self._gen_text(llm_job=llm_job)- # Cleanup result (Instructor adds the client's response as a _raw_response attribute, we don't want to pass it along)- if hasattr(result, "_raw_response"):- delattr(result, "_raw_response")-- # Report job- llm_job.llm_job_after_complete()- if self.reporting_delegate:- self.reporting_delegate.report_inference_job(inference_job=llm_job)+ await self._after_job(llm_job=llm_job)return result@@ -106,44 +93,22 @@ class LLMWorkerAbstract(InferenceWorkerAbstract, ABC):schema: Type[BaseModelTypeVar],) -> BaseModelTypeVar:log.debug("LLM Worker gen_object")- log.verbose(f"\n{self.llm_engine.desc}")log.verbose(llm_job.params_desc)-- # Verify that the job is valid- llm_job.validate_before_execution()-- # Verify feasibility- if not self.llm_engine.is_gen_object_supported:- raise LLMCapabilityError(f"LLM Engine '{self.llm_engine.tag}' does not support object generation.")- self._check_can_perform_job(llm_job=llm_job)-- # TODO: Fix printing prompts that contain image bytes- # log.verbose(llm_job.llm_prompt.desc, title="llm_prompt")+ log.verbose(llm_job.llm_prompt.desc, title="llm_prompt")# metadatallm_job.job_metadata.unit_job_id = UnitJobId.LLM_GEN_OBJECT- # Prepare job- llm_job.llm_job_before_start(llm_engine=self.llm_engine)+ await self._before_job(llm_job=llm_job)# Execute job- try:- result = await self._gen_object(llm_job=llm_job, schema=schema)- except InstructorRetryException as exc:- raise LLMCompletionError(- f"""Instructor failed to generate object: {schema} after retry with llm '{self.llm_engine.tag}'- Reason: {exc}- LLMPrompt: {llm_job.llm_prompt.desc}"""- ) from exc+ result = await self._gen_object(llm_job=llm_job, schema=schema)# Cleanup resultif hasattr(result, "_raw_response"):delattr(result, "_raw_response")- # Report job- llm_job.llm_job_after_complete()- if self.reporting_delegate:- self.reporting_delegate.report_inference_job(inference_job=llm_job)+ await self._after_job(llm_job=llm_job)return resultdiff --git a/pipelex/cogt/llm/llm_worker_factory.py b/pipelex/cogt/llm/llm_worker_factory.pyindex 21ccb3edd..55ef8d4a9 100644--- a/pipelex/cogt/llm/llm_worker_factory.py+++ b/pipelex/cogt/llm/llm_worker_factory.py@@ -3,11 +3,11 @@ from typing import Optionalfrom pipelex.cogt.exceptions import MissingDependencyErrorfrom pipelex.cogt.llm.llm_models.llm_engine import LLMEnginefrom pipelex.cogt.llm.llm_models.llm_platform import LLMPlatform-from pipelex.cogt.llm.llm_worker_abstract import LLMWorkerAbstract+from pipelex.cogt.llm.llm_worker_internal_abstract import LLMWorkerInternalAbstractfrom pipelex.cogt.llm.structured_output import StructureMethod-from pipelex.cogt.plugin_manager import PluginHandlefrom pipelex.config import get_configfrom pipelex.hub import get_plugin_manager+from pipelex.plugins.plugin_sdk_registry import PluginSdkHandlefrom pipelex.reporting.reporting_protocol import ReportingProtocol@@ -16,10 +16,10 @@ class LLMWorkerFactory:def make_llm_worker(llm_engine: LLMEngine,reporting_delegate: Optional[ReportingProtocol] = None,- ) -> LLMWorkerAbstract:- llm_sdk_handle = PluginHandle.get_for_llm_platform(llm_platform=llm_engine.llm_platform)- plugin_manager = get_plugin_manager()- llm_worker: LLMWorkerAbstract+ ) -> LLMWorkerInternalAbstract:+ llm_sdk_handle = PluginSdkHandle.get_for_llm_platform(llm_platform=llm_engine.llm_platform)+ plugin_sdk_registry = get_plugin_manager().plugin_sdk_registry+ llm_worker: LLMWorkerInternalAbstractmatch llm_engine.llm_platform:case LLMPlatform.OPENAI | LLMPlatform.AZURE_OPENAI | LLMPlatform.PERPLEXITY | LLMPlatform.XAI:from pipelex.plugins.openai.openai_factory import OpenAIFactory@@ -30,7 +30,9 @@ class LLMWorkerFactory:from pipelex.plugins.openai.openai_llm_worker import OpenAILLMWorker- llm_sdk_instance = plugin_manager.get_llm_sdk_instance(llm_sdk_handle=llm_sdk_handle) or plugin_manager.set_llm_sdk_instance(+ llm_sdk_instance = plugin_sdk_registry.get_llm_sdk_instance(+ llm_sdk_handle=llm_sdk_handle+ ) or plugin_sdk_registry.set_llm_sdk_instance(llm_sdk_handle=llm_sdk_handle,llm_sdk_instance=OpenAIFactory.make_openai_client(llm_platform=llm_engine.llm_platform),)@@ -50,7 +52,9 @@ class LLMWorkerFactory:from pipelex.plugins.openai.openai_factory import OpenAIFactoryfrom pipelex.plugins.openai.openai_llm_worker import OpenAILLMWorker- llm_sdk_instance = plugin_manager.get_llm_sdk_instance(llm_sdk_handle=llm_sdk_handle) or plugin_manager.set_llm_sdk_instance(+ llm_sdk_instance = plugin_sdk_registry.get_llm_sdk_instance(+ llm_sdk_handle=llm_sdk_handle+ ) or plugin_sdk_registry.set_llm_sdk_instance(llm_sdk_handle=llm_sdk_handle,llm_sdk_instance=OpenAIFactory.make_openai_client(llm_platform=llm_engine.llm_platform),)@@ -65,7 +69,9 @@ class LLMWorkerFactory:from pipelex.plugins.openai.openai_factory import OpenAIFactoryfrom pipelex.plugins.openai.openai_llm_worker import OpenAILLMWorker- llm_sdk_instance = plugin_manager.get_llm_sdk_instance(llm_sdk_handle=llm_sdk_handle) or plugin_manager.set_llm_sdk_instance(+ llm_sdk_instance = plugin_sdk_registry.get_llm_sdk_instance(+ llm_sdk_handle=llm_sdk_handle+ ) or plugin_sdk_registry.set_llm_sdk_instance(llm_sdk_handle=llm_sdk_handle,llm_sdk_instance=OpenAIFactory.make_openai_client(llm_platform=llm_engine.llm_platform),)@@ -93,7 +99,9 @@ class LLMWorkerFactory:from pipelex.plugins.anthropic.anthropic_factory import AnthropicFactoryfrom pipelex.plugins.anthropic.anthropic_llm_worker import AnthropicLLMWorker- llm_sdk_instance = plugin_manager.get_llm_sdk_instance(llm_sdk_handle=llm_sdk_handle) or plugin_manager.set_llm_sdk_instance(+ llm_sdk_instance = plugin_sdk_registry.get_llm_sdk_instance(+ llm_sdk_handle=llm_sdk_handle+ ) or plugin_sdk_registry.set_llm_sdk_instance(llm_sdk_handle=llm_sdk_handle,llm_sdk_instance=AnthropicFactory.make_anthropic_client(llm_platform=llm_engine.llm_platform),)@@ -121,7 +129,9 @@ class LLMWorkerFactory:from pipelex.plugins.mistral.mistral_factory import MistralFactoryfrom pipelex.plugins.mistral.mistral_llm_worker import MistralLLMWorker- llm_sdk_instance = plugin_manager.get_llm_sdk_instance(llm_sdk_handle=llm_sdk_handle) or plugin_manager.set_llm_sdk_instance(+ llm_sdk_instance = plugin_sdk_registry.get_llm_sdk_instance(+ llm_sdk_handle=llm_sdk_handle+ ) or plugin_sdk_registry.set_llm_sdk_instance(llm_sdk_handle=llm_sdk_handle,llm_sdk_instance=MistralFactory.make_mistral_client(),)@@ -144,7 +154,9 @@ class LLMWorkerFactory:from pipelex.plugins.bedrock.bedrock_factory import BedrockFactoryfrom pipelex.plugins.bedrock.bedrock_llm_worker import BedrockLLMWorker- llm_sdk_instance = plugin_manager.get_llm_sdk_instance(llm_sdk_handle=llm_sdk_handle) or plugin_manager.set_llm_sdk_instance(+ llm_sdk_instance = plugin_sdk_registry.get_llm_sdk_instance(+ llm_sdk_handle=llm_sdk_handle+ ) or plugin_sdk_registry.set_llm_sdk_instance(llm_sdk_handle=llm_sdk_handle,llm_sdk_instance=BedrockFactory.make_bedrock_client(),)diff --git a/pipelex/cogt/llm/llm_worker_internal_abstract.py b/pipelex/cogt/llm/llm_worker_internal_abstract.pynew file mode 100644index 000000000..afc435c1d--- /dev/null+++ b/pipelex/cogt/llm/llm_worker_internal_abstract.py@@ -0,0 +1,67 @@+from typing import Optional++from typing_extensions import override++from pipelex.cogt.exceptions import LLMCapabilityError+from pipelex.cogt.llm.llm_job import LLMJob+from pipelex.cogt.llm.llm_models.llm_engine import LLMEngine+from pipelex.cogt.llm.llm_worker_abstract import LLMWorkerAbstract+from pipelex.cogt.llm.structured_output import StructureMethod+from pipelex.reporting.reporting_protocol import ReportingProtocol+++class LLMWorkerInternalAbstract(LLMWorkerAbstract):+ def __init__(+ self,+ llm_engine: LLMEngine,+ structure_method: Optional[StructureMethod] = None,+ reporting_delegate: Optional[ReportingProtocol] = None,+ ):+ """+ Initialize the LLMWorker.++ Args:+ llm_engine (LLMEngine): The LLM engine to be used by the worker.+ structure_method (Optional[StructureMethod]): The structure method to be used by the worker.+ reporting_delegate (Optional[ReportingProtocol]): An optional report delegate for reporting unit jobs.+ """+ LLMWorkerAbstract.__init__(self, reporting_delegate=reporting_delegate)+ self.llm_engine = llm_engine+ self.structure_method = structure_method++ #########################################################+ # Instance methods+ #########################################################++ @property+ @override+ def desc(self) -> str:+ return f"LLM-Worker:{self.llm_engine.tag}"++ @property+ @override+ def is_gen_object_supported(self) -> bool:+ return self.llm_engine.is_gen_object_supported++ @override+ async def _before_job(+ self,+ llm_job: LLMJob,+ ):+ await super()._before_job(llm_job=llm_job)+ llm_job.llm_job_before_start(llm_engine=self.llm_engine)++ @override+ def _check_can_perform_job(self, llm_job: LLMJob):+ # This can be overridden by subclasses for specific checks+ self._check_vision_support(llm_job=llm_job)++ def _check_vision_support(self, llm_job: LLMJob):+ if llm_job.llm_prompt.user_images:+ if not self.llm_engine.llm_model.is_vision_supported:+ raise LLMCapabilityError(f"LLM Engine '{self.llm_engine.tag}' does not support vision.")++ nb_images = len(llm_job.llm_prompt.user_images)+ max_prompt_images = self.llm_engine.llm_model.max_prompt_images or 5000+ if nb_images > max_prompt_images:+ raise LLMCapabilityError(f"LLM Engine '{self.llm_engine.tag}' does not accept that many images: {nb_images}.")diff --git a/pipelex/cogt/ocr/ocr_worker_factory.py b/pipelex/cogt/ocr/ocr_worker_factory.pyindex d004c3d35..4c96a1602 100644--- a/pipelex/cogt/ocr/ocr_worker_factory.py+++ b/pipelex/cogt/ocr/ocr_worker_factory.py@@ -4,8 +4,8 @@ from pipelex.cogt.exceptions import MissingDependencyErrorfrom pipelex.cogt.ocr.ocr_engine import OcrEnginefrom pipelex.cogt.ocr.ocr_platform import OcrPlatformfrom pipelex.cogt.ocr.ocr_worker_abstract import OcrWorkerAbstract-from pipelex.cogt.plugin_manager import PluginHandlefrom pipelex.hub import get_plugin_manager+from pipelex.plugins.plugin_sdk_registry import PluginSdkHandlefrom pipelex.reporting.reporting_protocol import ReportingProtocol@@ -15,8 +15,8 @@ class OcrWorkerFactory:ocr_engine: OcrEngine,reporting_delegate: Optional[ReportingProtocol] = None,) -> OcrWorkerAbstract:- ocr_sdk_handle = PluginHandle.get_for_ocr_engine(ocr_platform=ocr_engine.ocr_platform)- plugin_manager = get_plugin_manager()+ ocr_sdk_handle = PluginSdkHandle.get_for_ocr_engine(ocr_platform=ocr_engine.ocr_platform)+ plugin_sdk_registry = get_plugin_manager().plugin_sdk_registryocr_worker: OcrWorkerAbstractmatch ocr_engine.ocr_platform:case OcrPlatform.MISTRAL:@@ -32,7 +32,9 @@ class OcrWorkerFactory:from pipelex.plugins.mistral.mistral_factory import MistralFactoryfrom pipelex.plugins.mistral.mistral_ocr_worker import MistralOcrWorker- ocr_sdk_instance = plugin_manager.get_ocr_sdk_instance(ocr_sdk_handle=ocr_sdk_handle) or plugin_manager.set_ocr_sdk_instance(+ ocr_sdk_instance = plugin_sdk_registry.get_ocr_sdk_instance(+ ocr_sdk_handle=ocr_sdk_handle+ ) or plugin_sdk_registry.set_ocr_sdk_instance(ocr_sdk_handle=ocr_sdk_handle,ocr_sdk_instance=MistralFactory.make_mistral_client(),)diff --git a/pipelex/config.py b/pipelex/config.pyindex 87005e265..5a50fc298 100644--- a/pipelex/config.py+++ b/pipelex/config.py@@ -9,7 +9,6 @@ from pipelex.exceptions import PipelexConfigError, StaticValidationErrorTypefrom pipelex.hub import get_required_configfrom pipelex.libraries.library_config import LibraryConfigfrom pipelex.pipeline.track.tracker_config import TrackerConfig-from pipelex.plugins.plugins_config import PluginsConfigfrom pipelex.tools.aws.aws_config import AwsConfigfrom pipelex.tools.config.models import ConfigModel, ConfigRootfrom pipelex.tools.log.log_config import LogConfig@@ -114,7 +113,6 @@ class Pipelex(ConfigModel):class PipelexConfig(ConfigRoot):session_id: str = shortuuid.uuid()cogt: Cogt- plugins: PluginsConfigpipelex: Pipelexdiff --git a/pipelex/core/pipe_input_details.py b/pipelex/core/pipe_input_details.pyindex 94e0ccd4b..6e5bc96a0 100644--- a/pipelex/core/pipe_input_details.py+++ b/pipelex/core/pipe_input_details.py@@ -23,13 +23,13 @@ class PipeInputDetails(RootModel[PipeInputDetailsRoot]):# in case of sub-attribute, the variable name is the object name, before the 1st dottransformed_key: str = required_input.split(".", 1)[0]if transformed_key != required_input:- log.warning(f"Sub-attribute {required_input} detected, using {transformed_key} as variable name")+ log.verbose(f"Sub-attribute {required_input} detected, using {transformed_key} as variable name")# Validate concept_codeconcept_code = ConceptCodeFactory.make_concept_code_from_str(concept_str=concept_str)if transformed_key in transformed_dict and transformed_dict[transformed_key] != concept_code:- log.warning(+ log.verbose(f"Variable {transformed_key} already exists with a different concept code: {transformed_dict[transformed_key]} -> {concept_str}")transformed_dict[transformed_key] = concept_codediff --git a/pipelex/core/pipe_input_spec.py b/pipelex/core/pipe_input_spec.pyindex 00466df5b..faab24c88 100644--- a/pipelex/core/pipe_input_spec.py+++ b/pipelex/core/pipe_input_spec.py@@ -29,13 +29,13 @@ class PipeInputSpec(RootModel[PipeInputSpecRoot]):# in case of sub-attribute, the variable name is the object name, before the 1st dottransformed_key: str = required_input.split(".", 1)[0]if transformed_key != required_input:- log.warning(f"Sub-attribute {required_input} detected, using {transformed_key} as variable name")+ log.verbose(f"Sub-attribute {required_input} detected, using {transformed_key} as variable name")# Validate concept_codeconcept_code = ConceptCodeFactory.make_concept_code_from_str(concept_str=concept_str)if transformed_key in transformed_dict and transformed_dict[transformed_key] != concept_code:- log.warning(+ log.verbose(f"Variable {transformed_key} already exists with a different concept code: {transformed_dict[transformed_key]} -> {concept_str}")transformed_dict[transformed_key] = concept_codediff --git a/pipelex/hub.py b/pipelex/hub.pyindex 780c19f23..552a38211 100644--- a/pipelex/hub.py+++ b/pipelex/hub.py@@ -10,13 +10,11 @@ from pipelex.cogt.content_generation.content_generator_protocol import (from pipelex.cogt.imgg.imgg_worker_abstract import ImggWorkerAbstractfrom pipelex.cogt.inference.inference_manager_protocol import InferenceManagerProtocolfrom pipelex.cogt.llm.llm_models.llm_deck_abstract import LLMDeckAbstract-from pipelex.cogt.llm.llm_models.llm_engine_blueprint import LLMEngineBlueprintfrom pipelex.cogt.llm.llm_models.llm_model_provider_abstract import (LLMModelProviderAbstract,)from pipelex.cogt.llm.llm_worker_abstract import LLMWorkerAbstractfrom pipelex.cogt.ocr.ocr_worker_abstract import OcrWorkerAbstract-from pipelex.cogt.plugin_manager import PluginManagerfrom pipelex.core.concept import Conceptfrom pipelex.core.concept_provider_abstract import ConceptProviderAbstractfrom pipelex.core.domain import Domain@@ -28,6 +26,7 @@ from pipelex.pipeline.activity.activity_manager_protocol import ActivityManagerPfrom pipelex.pipeline.pipeline import Pipelinefrom pipelex.pipeline.pipeline_manager_abstract import PipelineManagerAbstractfrom pipelex.pipeline.track.pipeline_tracker_protocol import PipelineTrackerProtocol+from pipelex.plugins.plugin_manager import PluginManagerfrom pipelex.reporting.reporting_protocol import ReportingProtocolfrom pipelex.tools.config.manager import config_managerfrom pipelex.tools.config.models import ConfigRoot@@ -229,7 +228,7 @@ class PipelexHub:def get_plugin_manager(self) -> PluginManager:if self._plugin_manager is None:- raise RuntimeError("SdkManager is not initialized")+ raise RuntimeError("PluginManager2 is not initialized")return self._plugin_managerdef get_inference_manager(self) -> InferenceManagerProtocol:@@ -348,12 +347,8 @@ def get_inference_manager() -> InferenceManagerProtocol:def get_llm_worker(llm_handle: str,- specific_llm_engine_blueprint: Optional[LLMEngineBlueprint] = None,) -> LLMWorkerAbstract:- return get_inference_manager().get_llm_worker(- llm_handle=llm_handle,- specific_llm_engine_blueprint=specific_llm_engine_blueprint,- )+ return get_inference_manager().get_llm_worker(llm_handle=llm_handle)def get_imgg_worker(diff --git a/pipelex/libraries/library_config.py b/pipelex/libraries/library_config.pyindex 03736eaa2..e8b201e13 100644--- a/pipelex/libraries/library_config.py+++ b/pipelex/libraries/library_config.py@@ -20,6 +20,8 @@ class LibraryConfig(ConfigModel):exported_llm_deck_path: ClassVar[str] = f"{exported_library_root}/llm_deck"internal_templates_path: ClassVar[str] = f"{internal_library_root}/templates"exported_templates_path: ClassVar[str] = f"{exported_library_root}/templates"+ internal_plugins_path: ClassVar[str] = f"{internal_library_root}/plugins"+ exported_plugins_path: ClassVar[str] = f"{exported_library_root}/plugins"@classmethoddef get_llm_deck_paths(cls) -> List[str]:@@ -31,6 +33,10 @@ class LibraryConfig(ConfigModel):def get_templates_paths(cls) -> List[str]:return [str(path) for path in find_files_in_dir(dir_path=cls.exported_templates_path, pattern="*.toml", is_recursive=True)]+ @classmethod+ def get_plugin_config_path(cls) -> str:+ return f"{cls.exported_plugins_path}/plugin_config.toml"+@classmethoddef export_libraries(cls, overwrite: bool = False) -> None:"""Duplicate pipelex libraries files in the client project, preserving directory structure."""@@ -84,3 +90,11 @@ class LibraryConfig(ConfigModel):target_dir=cls.exported_templates_path,overwrite=overwrite,)++ # plugins+ copy_folder_from_package(+ package_name=cls.package_name,+ folder_path_in_package=cls.internal_plugins_path,+ target_dir=cls.exported_plugins_path,+ overwrite=overwrite,+ )diff --git a/pipelex/libraries/llm_deck/base_llm_deck.toml b/pipelex/libraries/llm_deck/base_llm_deck.tomlindex 205f962f7..f64fbba24 100644--- a/pipelex/libraries/llm_deck/base_llm_deck.toml+++ b/pipelex/libraries/llm_deck/base_llm_deck.toml@@ -1,10 +1,14 @@+# LLM Deck base####################################################################################################-# LLM Deck base+# LLM Handles####################################################################################################-# Match a llm_handle with a complete blueprint (llm_name, llm_version and llm_platform_choice).+llm_external_handles = []++# Match a llm_handle with either just and llm_name+# or a complete blueprint including llm_version (defaulting to "latest") and llm_platform_choice (defaulting to "default").[llm_handles]gpt-4o-2024-08-06 = { llm_name = "gpt-4o", llm_version = "2024-08-06" }best-claude = "claude-4-opus"@@ -12,6 +16,7 @@ best-gemini = "gemini-2.5-pro"best-mistral = "mistral-large"best-grok = "grok-3"+##################################################################################################### LLM Presets####################################################################################################diff --git a/pipelex/libraries/plugins/plugin_config.toml b/pipelex/libraries/plugins/plugin_config.tomlnew file mode 100644index 000000000..e3c86138b--- /dev/null+++ b/pipelex/libraries/plugins/plugin_config.toml@@ -0,0 +1,39 @@++####################################################################################################+# Plugins config+####################################################################################################++[openai_config]+image_output_compression = 100+api_key_method = "env"++[azure_openai_config]+api_key_method = "env"++# TODO: handle multiple azure openai accounts with different resource groups and account names for various llm model++[perplexity_config]+api_key_method = "env"++[xai_config]+api_key_method = "env"++[vertexai_config]+api_key_method = "env"++[mistral_config]+api_key_method = "env"++[bedrock_config]+client_method = "aioboto3"++[anthropic_config]+claude_4_reduced_tokens_limit = 8192 # use "unlimited" to enable the full 32/64K tokens Opus/Sonet but it raises streaming/timeout issues+api_key_method = "env"++[custom_endpoint_config]+api_key_method = "env"++[fal_config]+flux_map_quality_to_steps = { "low" = 14, "medium" = 28, "high" = 56 }+sdxl_lightning_map_quality_to_steps = { "low" = 2, "medium" = 4, "high" = 8 }diff --git a/pipelex/pipe_operators/pipe_llm.py b/pipelex/pipe_operators/pipe_llm.pyindex 4879e0ccc..228729a19 100644--- a/pipelex/pipe_operators/pipe_llm.py+++ b/pipelex/pipe_operators/pipe_llm.py@@ -265,9 +265,9 @@ class PipeLLM(PipeOperator):else:log.verbose(f"{self.class_name} generate a single '{output_concept_code}' (class '{output_concept.structure_class_name}')")- if not self.pipe_llm_prompt.prompting_style:- llm_deck = get_llm_deck()- llm_model = llm_deck.find_llm_model(llm_handle=self.llm_setting_main.llm_handle)+ if not self.pipe_llm_prompt.prompting_style and (+ llm_model := get_llm_deck().find_optional_llm_model(llm_handle=self.llm_setting_main.llm_handle)+ ):llm_family = llm_model.llm_familyif self.llm_setting_main.prompting_target:log.dev(f"prompting_target for '{self.llm_setting_main.llm_handle}' from setting: {self.llm_setting_main}")diff --git a/pipelex/pipelex.py b/pipelex/pipelex.pyindex a6aff6f10..569fcd1bc 100644--- a/pipelex/pipelex.py+++ b/pipelex/pipelex.py@@ -17,7 +17,6 @@ from pipelex.cogt.content_generation.content_generator_protocol import (from pipelex.cogt.inference.inference_manager import InferenceManagerfrom pipelex.cogt.llm.llm_models.llm_model import LATEST_VERSION_NAMEfrom pipelex.cogt.llm.llm_models.llm_model_library import LLMModelLibrary-from pipelex.cogt.plugin_manager import PluginManagerfrom pipelex.config import PipelexConfig, get_configfrom pipelex.core.registry_models import PipelexRegistryModelsfrom pipelex.exceptions import PipelexConfigError, PipelexSetupError@@ -36,6 +35,7 @@ from pipelex.pipeline.track.pipeline_tracker_protocol import (PipelineTrackerNoOp,PipelineTrackerProtocol,)+from pipelex.plugins.plugin_manager import PluginManagerfrom pipelex.reporting.reporting_manager import ReportingManagerfrom pipelex.reporting.reporting_protocol import ReportingNoOp, ReportingProtocolfrom pipelex.test_extras.registry_test_models import PipelexTestModels@@ -64,7 +64,6 @@ class Pipelex:class_registry: Optional[ClassRegistryAbstract] = None,template_provider: Optional[TemplateLibrary] = None,llm_model_provider: Optional[LLMModelLibrary] = None,- plugin_manager: Optional[PluginManager] = None,inference_manager: Optional[InferenceManager] = None,pipeline_manager: Optional[PipelineManager] = None,pipeline_tracker: Optional[PipelineTracker] = None,@@ -92,7 +91,6 @@ class Pipelex:class_registry: Optional[ClassRegistryAbstract] = None,template_provider: Optional[TemplateLibrary] = None,llm_model_provider: Optional[LLMModelLibrary] = None,- plugin_manager: Optional[PluginManager] = None,inference_manager: Optional[InferenceManager] = None,pipeline_manager: Optional[PipelineManager] = None,pipeline_tracker: Optional[PipelineTracker] = None,@@ -131,10 +129,10 @@ class Pipelex:self.kajson_manager = KajsonManager(class_registry=self.class_registry)# cogt+ self.plugin_manager = PluginManager()+ self.pipelex_hub.set_plugin_manager(self.plugin_manager)self.llm_model_provider = llm_model_provider or LLMModelLibrary()self.pipelex_hub.set_llm_models_provider(self.llm_model_provider)- self.plugin_manager = plugin_manager or PluginManager()- self.pipelex_hub.set_plugin_manager(self.plugin_manager)self.inference_manager = inference_manager or InferenceManager()self.pipelex_hub.set_inference_manager(self.inference_manager)@@ -187,6 +185,7 @@ class Pipelex:self.pipelex_hub.set_secrets_provider(secrets_provider or EnvSecretsProvider())self.pipelex_hub.set_storage_provider(storage_provider)# cogt+ self.plugin_manager.setup()self.pipelex_hub.set_content_generator(content_generator or ContentGenerator())self.reporting_delegate.setup()self.class_registry.register_classes(PipelexRegistryModels.get_all_models())@@ -213,9 +212,8 @@ class Pipelex:llm_deck = self.library_manager.load_deck()for llm_model in self.llm_model_provider.get_all_llm_models():if llm_model.version == LATEST_VERSION_NAME:- llm_deck.add_llm_handle_to_llm_engine_blueprint(- llm_handle=llm_model.llm_name,- llm_engine_default=llm_model.llm_name,+ llm_deck.add_llm_name_as_handle_with_defaults(+ llm_name=llm_model.llm_name,)llm_deck.validate_llm_presets()self.library_manager.load_libraries()@@ -241,6 +239,7 @@ class Pipelex:self.inference_manager.teardown()self.reporting_delegate.teardown()self.llm_model_provider.teardown()+ self.plugin_manager.teardown()# toolsself.kajson_manager.teardown()@@ -262,6 +261,10 @@ class Pipelex:log.info(f"Pipelex {PACKAGE_VERSION} initialized.")return pipelex_instance+ @classmethod+ def get_optional_instance(cls) -> Optional[Self]:+ return cls._pipelex_instance+@classmethoddef get_instance(cls) -> Self:if cls._pipelex_instance is None:diff --git a/pipelex/pipelex.toml b/pipelex/pipelex.tomlindex 978485b4f..d05c1f703 100644--- a/pipelex/pipelex.toml+++ b/pipelex/pipelex.toml@@ -128,47 +128,6 @@ ocr_handles = ["mistral/mistral-ocr-latest"]page_output_text_file_name = "page_text.md"default_page_views_dpi = 72-####################################################################################################-# Plugins config-####################################################################################################--[plugins]--[plugins.openai_config]-image_output_compression = 100-api_key_method = "env"--[plugins.azure_openai_config]-api_key_method = "env"--# TODO: handle multiple azure openai accounts with different resource groups and account names for various llm model--[plugins.perplexity_config]-api_key_method = "env"--[plugins.xai_config]-api_key_method = "env"--[plugins.vertexai_config]-api_key_method = "env"--[plugins.mistral_config]-api_key_method = "env"--[plugins.bedrock_config]-client_method = "aioboto3"--[plugins.anthropic_config]-claude_4_reduced_tokens_limit = 8192 # use "unlimited" to enable the full 32/64K tokens Opus/Sonet but it raises streaming/timeout issues-api_key_method = "env"--[plugins.custom_endpoint_config]-api_key_method = "env"--[plugins.fal_config]-flux_map_quality_to_steps = { "low" = 14, "medium" = 28, "high" = 56 }-sdxl_lightning_map_quality_to_steps = { "low" = 2, "medium" = 4, "high" = 8 }-##################################################################################################### Pipelex prompting config####################################################################################################@@ -250,4 +209,3 @@ image_urls = ["https://storage.googleapis.com/public_test_files_7fa6_4277_9ab/fashion/fashion_photo_1.jpg","https://storage.googleapis.com/public_test_files_7fa6_4277_9ab/fashion/fashion_photo_2.png",]-diff --git a/pipelex/pipelex_template.toml b/pipelex/pipelex_template.tomlindex cc535db55..287a71269 100644--- a/pipelex/pipelex_template.toml+++ b/pipelex/pipelex_template.toml@@ -1,5 +1,5 @@[pipelex.aws_config]-api_key_method = "env"+api_key_method = "env"# The possible values are "env" and "secret_provider".# "env" means means that the env var are stored in your .env file.# "secret_provider" means that the env var are stored in your Secret Manager (See the doc for injecting a secret provider).@@ -9,39 +9,6 @@ api_key_method = "env"# This overrrides the defaults set for any llm handle"gpt-4o-mini" = "openai"-[plugins]--[plugins.openai_config]-image_output_compression = 100-api_key_method = "env"--[plugins.azure_openai_config]-api_key_method = "env"--# TODO: handle multiple azure openai accounts with different resource groups and account names for various llm model--[plugins.perplexity_config]-api_key_method = "env"--[plugins.xai_config]-api_key_method = "env"--[plugins.vertexai_config]-api_key_method = "env"--[plugins.mistral_config]-api_key_method = "env"--[plugins.bedrock_config]-client_method = "aioboto3"--[plugins.anthropic_config]-claude_4_reduced_tokens_limit = 8192 # use "unlimited" to enable the full 32/64K tokens Opus/Sonet but it raises streaming/timeout issues-api_key_method = "env"--[plugins.custom_endpoint_config]-api_key_method = "env"-##################################################################################################### OCR config####################################################################################################diff --git a/pipelex/plugins/anthropic/anthropic_factory.py b/pipelex/plugins/anthropic/anthropic_factory.pyindex 4c318c7f5..6e44689dd 100644--- a/pipelex/plugins/anthropic/anthropic_factory.py+++ b/pipelex/plugins/anthropic/anthropic_factory.py@@ -25,7 +25,7 @@ from pipelex.cogt.llm.llm_job import LLMJobfrom pipelex.cogt.llm.llm_models.llm_platform import LLMPlatformfrom pipelex.cogt.llm.token_category import NbTokensByCategoryDict, TokenCategoryfrom pipelex.config import get_config-from pipelex.hub import get_secrets_provider+from pipelex.hub import get_plugin_manager, get_secrets_providerfrom pipelex.tools.misc.base_64_utils import (load_binary_as_base64_async,)@@ -43,7 +43,7 @@ class AnthropicFactory:# TODO: also support Anthropic with VertexAImatch llm_platform:case LLMPlatform.ANTHROPIC:- anthropic_config = get_config().plugins.anthropic_config+ anthropic_config = get_plugin_manager().plugin_configs.anthropic_configapi_key = anthropic_config.get_api_key(secrets_provider=get_secrets_provider())return AsyncAnthropic(api_key=api_key)case LLMPlatform.BEDROCK_ANTHROPIC:diff --git a/pipelex/plugins/anthropic/anthropic_llm_worker.py b/pipelex/plugins/anthropic/anthropic_llm_worker.pyindex 85aa8b63a..97aa88dd1 100644--- a/pipelex/plugins/anthropic/anthropic_llm_worker.py+++ b/pipelex/plugins/anthropic/anthropic_llm_worker.py@@ -9,15 +9,15 @@ from pipelex.cogt.exceptions import LLMCompletionError, LLMEngineParameterError,from pipelex.cogt.llm.llm_job import LLMJobfrom pipelex.cogt.llm.llm_models.llm_engine import LLMEnginefrom pipelex.cogt.llm.llm_models.llm_platform import LLMPlatform-from pipelex.cogt.llm.llm_worker_abstract import LLMWorkerAbstract+from pipelex.cogt.llm.llm_worker_internal_abstract import LLMWorkerInternalAbstractfrom pipelex.cogt.llm.structured_output import StructureMethod-from pipelex.config import get_config+from pipelex.hub import get_plugin_managerfrom pipelex.plugins.anthropic.anthropic_factory import AnthropicFactoryfrom pipelex.reporting.reporting_protocol import ReportingProtocolfrom pipelex.tools.typing.pydantic_utils import BaseModelTypeVar-class AnthropicLLMWorker(LLMWorkerAbstract):+class AnthropicLLMWorker(LLMWorkerInternalAbstract):def __init__(self,sdk_instance: Any,@@ -25,7 +25,7 @@ class AnthropicLLMWorker(LLMWorkerAbstract):structure_method: Optional[StructureMethod] = None,reporting_delegate: Optional[ReportingProtocol] = None,):- LLMWorkerAbstract.__init__(+ LLMWorkerInternalAbstract.__init__(self,llm_engine=llm_engine,structure_method=structure_method,@@ -63,7 +63,7 @@ class AnthropicLLMWorker(LLMWorkerAbstract):# TODO: implement streaming behind the scenes to avoid timeout/streaming errors with Claude 4 and high tokensdef _adapt_max_tokens(self, max_tokens: Optional[int]) -> int:max_tokens = max_tokens or self.default_max_tokens- if claude_4_tokens_limit := get_config().plugins.anthropic_config.claude_4_tokens_limit:+ if claude_4_tokens_limit := get_plugin_manager().plugin_configs.anthropic_config.claude_4_tokens_limit:if max_tokens > claude_4_tokens_limit:max_tokens = claude_4_tokens_limitlog.warning(f"Max tokens is greater than the claude 4 reduced tokens limit, reducing to {max_tokens}")diff --git a/pipelex/plugins/bedrock/bedrock_factory.py b/pipelex/plugins/bedrock/bedrock_factory.pyindex b12dca2bd..513a2c458 100644--- a/pipelex/plugins/bedrock/bedrock_factory.py+++ b/pipelex/plugins/bedrock/bedrock_factory.py@@ -2,8 +2,7 @@ from pipelex import logfrom pipelex.cogt.exceptions import LLMCapabilityError, PromptImageFormatErrorfrom pipelex.cogt.image.prompt_image import PromptImageBytesfrom pipelex.cogt.llm.llm_job import LLMJob-from pipelex.config import get_config-from pipelex.hub import get_secrets_provider+from pipelex.hub import get_plugin_manager, get_secrets_providerfrom pipelex.plugins.bedrock.bedrock_client_protocol import BedrockClientProtocolfrom pipelex.plugins.bedrock.bedrock_config import BedrockClientMethodfrom pipelex.plugins.bedrock.bedrock_message import BedrockContentItem, BedrockImage, BedrockMessage, BedrockSource, ImageFormat@@ -16,7 +15,7 @@ class BedrockFactory:@classmethoddef make_bedrock_client(cls) -> BedrockClientProtocol:- bedrock_config = get_config().plugins.bedrock_config+ bedrock_config = get_plugin_manager().plugin_configs.bedrock_configaws_region = bedrock_config.configure(secrets_provider=get_secrets_provider())client_method = bedrock_config.client_methodbedrock_async_client: BedrockClientProtocoldiff --git a/pipelex/plugins/bedrock/bedrock_llm_worker.py b/pipelex/plugins/bedrock/bedrock_llm_worker.pyindex 95f4ec264..87e479573 100644--- a/pipelex/plugins/bedrock/bedrock_llm_worker.py+++ b/pipelex/plugins/bedrock/bedrock_llm_worker.py@@ -6,7 +6,7 @@ from pipelex import logfrom pipelex.cogt.exceptions import LLMCapabilityError, LLMEngineParameterError, SdkTypeErrorfrom pipelex.cogt.llm.llm_job import LLMJobfrom pipelex.cogt.llm.llm_models.llm_engine import LLMEngine-from pipelex.cogt.llm.llm_worker_abstract import LLMWorkerAbstract+from pipelex.cogt.llm.llm_worker_internal_abstract import LLMWorkerInternalAbstractfrom pipelex.cogt.llm.structured_output import StructureMethodfrom pipelex.plugins.bedrock.bedrock_client_protocol import BedrockClientProtocolfrom pipelex.plugins.bedrock.bedrock_factory import BedrockFactory@@ -14,7 +14,7 @@ from pipelex.reporting.reporting_protocol import ReportingProtocolfrom pipelex.tools.typing.pydantic_utils import BaseModelTypeVar-class BedrockLLMWorker(LLMWorkerAbstract):+class BedrockLLMWorker(LLMWorkerInternalAbstract):def __init__(self,sdk_instance: Any,@@ -22,7 +22,7 @@ class BedrockLLMWorker(LLMWorkerAbstract):structure_method: Optional[StructureMethod] = None,reporting_delegate: Optional[ReportingProtocol] = None,):- LLMWorkerAbstract.__init__(+ LLMWorkerInternalAbstract.__init__(self,llm_engine=llm_engine,structure_method=structure_method,diff --git a/pipelex/plugins/fal/fal_factory.py b/pipelex/plugins/fal/fal_factory.pyindex b4a2f08b3..88d47dc11 100644--- a/pipelex/plugins/fal/fal_factory.py+++ b/pipelex/plugins/fal/fal_factory.py@@ -7,7 +7,7 @@ from pipelex.cogt.imgg.imgg_engine import ImggEnginefrom pipelex.cogt.imgg.imgg_handle import ImggHandlefrom pipelex.cogt.imgg.imgg_job import ImggJobfrom pipelex.cogt.imgg.imgg_job_components import AspectRatio, OutputFormat, Quality-from pipelex.config import get_config+from pipelex.hub import get_plugin_managerclass FalFactory:@@ -17,12 +17,12 @@ class FalFactory:@classmethoddef make_nb_steps_from_quality_for_flux_pro(cls, quality: Quality) -> int:- flux_map_quality_to_steps = get_config().plugins.fal_config.flux_map_quality_to_steps+ flux_map_quality_to_steps = get_plugin_manager().plugin_configs.fal_config.flux_map_quality_to_stepsreturn flux_map_quality_to_steps[quality.value]@classmethoddef make_nb_steps_from_quality_for_sdxl_lightning(cls, quality: Quality) -> int:- sdxl_lightning_map_quality_to_steps = get_config().plugins.fal_config.sdxl_lightning_map_quality_to_steps+ sdxl_lightning_map_quality_to_steps = get_plugin_manager().plugin_configs.fal_config.sdxl_lightning_map_quality_to_stepsreturn sdxl_lightning_map_quality_to_steps[quality.value]@classmethoddiff --git a/pipelex/plugins/mistral/mistral_factory.py b/pipelex/plugins/mistral/mistral_factory.pyindex 9115bb15e..2d00aa6b7 100644--- a/pipelex/plugins/mistral/mistral_factory.py+++ b/pipelex/plugins/mistral/mistral_factory.py@@ -24,8 +24,7 @@ from pipelex.cogt.image.prompt_image import PromptImage, PromptImageBytes, Prompfrom pipelex.cogt.llm.llm_job import LLMJobfrom pipelex.cogt.llm.token_category import NbTokensByCategoryDict, TokenCategoryfrom pipelex.cogt.ocr.ocr_output import ExtractedImageFromPage, OcrOutput, Page-from pipelex.config import get_config-from pipelex.hub import get_secrets_provider+from pipelex.hub import get_plugin_manager, get_secrets_providerfrom pipelex.plugins.openai.openai_factory import OpenAIFactoryfrom pipelex.tools.misc.base_64_utils import encode_to_base64, load_binary_as_base64@@ -38,7 +37,7 @@ class MistralFactory:@classmethoddef make_mistral_client(cls) -> Mistral:return Mistral(- api_key=get_config().plugins.mistral_config.api_key(secrets_provider=get_secrets_provider()),+ api_key=get_plugin_manager().plugin_configs.mistral_config.api_key(secrets_provider=get_secrets_provider()),)#########################################################diff --git a/pipelex/plugins/mistral/mistral_llm_worker.py b/pipelex/plugins/mistral/mistral_llm_worker.pyindex 433b531fc..5cbb1965d 100644--- a/pipelex/plugins/mistral/mistral_llm_worker.py+++ b/pipelex/plugins/mistral/mistral_llm_worker.py@@ -9,14 +9,14 @@ from pipelex import logfrom pipelex.cogt.exceptions import LLMCompletionError, LLMEngineParameterError, SdkTypeErrorfrom pipelex.cogt.llm.llm_job import LLMJobfrom pipelex.cogt.llm.llm_models.llm_engine import LLMEngine-from pipelex.cogt.llm.llm_worker_abstract import LLMWorkerAbstract+from pipelex.cogt.llm.llm_worker_internal_abstract import LLMWorkerInternalAbstractfrom pipelex.cogt.llm.structured_output import StructureMethodfrom pipelex.plugins.mistral.mistral_factory import MistralFactoryfrom pipelex.reporting.reporting_protocol import ReportingProtocolfrom pipelex.tools.typing.pydantic_utils import BaseModelTypeVar-class MistralLLMWorker(LLMWorkerAbstract):+class MistralLLMWorker(LLMWorkerInternalAbstract):def __init__(self,sdk_instance: Any,@@ -24,7 +24,12 @@ class MistralLLMWorker(LLMWorkerAbstract):structure_method: Optional[StructureMethod] = None,reporting_delegate: Optional[ReportingProtocol] = None,):- super().__init__(llm_engine=llm_engine, structure_method=structure_method, reporting_delegate=reporting_delegate)+ LLMWorkerInternalAbstract.__init__(+ self,+ llm_engine=llm_engine,+ structure_method=structure_method,+ reporting_delegate=reporting_delegate,+ )if not isinstance(sdk_instance, Mistral):raise SdkTypeError(f"Provided LLM sdk_instance for {self.__class__.__name__} is not of type Mistral: it's a '{type(sdk_instance)}'")diff --git a/pipelex/plugins/openai/custom_endpoint_config.py b/pipelex/plugins/openai/custom_endpoint_config.pyindex 8c371d010..2564ee6fa 100644--- a/pipelex/plugins/openai/custom_endpoint_config.py+++ b/pipelex/plugins/openai/custom_endpoint_config.py@@ -3,15 +3,15 @@ from typing import Optional, Tuplefrom pydantic import Fieldfrom pipelex import log-from pipelex.cogt.exceptions import CogtErrorfrom pipelex.tools.config.models import ConfigModelfrom pipelex.tools.environment import EnvVarNotFoundError, get_required_env+from pipelex.tools.exceptions import CredentialsErrorfrom pipelex.tools.secrets.secrets_errors import SecretNotFoundErrorfrom pipelex.tools.secrets.secrets_provider_abstract import SecretsProviderAbstractfrom pipelex.types import StrEnum-class CustomEndpointCredentialsError(CogtError):+class CustomEndpointCredentialsError(CredentialsError):passdiff --git a/pipelex/plugins/openai/openai_config.py b/pipelex/plugins/openai/openai_config.pyindex 901f38206..c79804502 100644--- a/pipelex/plugins/openai/openai_config.py+++ b/pipelex/plugins/openai/openai_config.py@@ -1,15 +1,15 @@from pydantic import Fieldfrom pipelex import log-from pipelex.cogt.exceptions import CogtErrorfrom pipelex.tools.config.models import ConfigModelfrom pipelex.tools.environment import EnvVarNotFoundError, get_required_env+from pipelex.tools.exceptions import CredentialsErrorfrom pipelex.tools.secrets.secrets_errors import SecretNotFoundErrorfrom pipelex.tools.secrets.secrets_provider_abstract import SecretsProviderAbstractfrom pipelex.types import StrEnum-class OpenAICredentialsError(CogtError):+class OpenAICredentialsError(CredentialsError):passdiff --git a/pipelex/plugins/openai/openai_factory.py b/pipelex/plugins/openai/openai_factory.pyindex 0cb832f8b..bf0e2a555 100644--- a/pipelex/plugins/openai/openai_factory.py+++ b/pipelex/plugins/openai/openai_factory.py@@ -19,8 +19,7 @@ from pipelex.cogt.llm.llm_job import LLMJobfrom pipelex.cogt.llm.llm_models.llm_engine import LLMEnginefrom pipelex.cogt.llm.llm_models.llm_platform import LLMPlatformfrom pipelex.cogt.llm.token_category import NbTokensByCategoryDict, TokenCategory-from pipelex.config import get_config-from pipelex.hub import get_secrets_provider+from pipelex.hub import get_plugin_manager, get_secrets_providerfrom pipelex.tools.misc.base_64_utils import load_binary_as_base64@@ -31,7 +30,7 @@ class OpenAIFactory:api_key: Optional[str] = Nonematch llm_platform:case LLMPlatform.AZURE_OPENAI:- azure_openai_config = get_config().plugins.azure_openai_config+ azure_openai_config = get_plugin_manager().plugin_configs.azure_openai_configendpoint, api_version, api_key = azure_openai_config.configure(secrets_provider=get_secrets_provider())log.verbose(f"Making AsyncAzureOpenAI client with endpoint: {endpoint}, api_version: {api_version}")@@ -41,7 +40,7 @@ class OpenAIFactory:api_version=api_version,)case LLMPlatform.PERPLEXITY:- perplexity_config = get_config().plugins.perplexity_config+ perplexity_config = get_plugin_manager().plugin_configs.perplexity_configendpoint, api_key = perplexity_config.configure(secrets_provider=get_secrets_provider())log.verbose(f"Making perplexity AsyncOpenAI client with endpoint: {endpoint}")@@ -50,11 +49,11 @@ class OpenAIFactory:base_url=endpoint,)case LLMPlatform.OPENAI:- openai_config = get_config().plugins.openai_config+ openai_config = get_plugin_manager().plugin_configs.openai_configapi_key = openai_config.get_api_key(secrets_provider=get_secrets_provider())the_client = openai.AsyncOpenAI(api_key=api_key)case LLMPlatform.VERTEXAI:- vertexai_config = get_config().plugins.vertexai_config+ vertexai_config = get_plugin_manager().plugin_configs.vertexai_configendpoint, api_key = vertexai_config.configure(secrets_provider=get_secrets_provider())log.verbose(f"Making vertex AsyncOpenAI client with endpoint: {endpoint}")@@ -63,7 +62,7 @@ class OpenAIFactory:base_url=endpoint,)case LLMPlatform.XAI:- xai_config = get_config().plugins.xai_config+ xai_config = get_plugin_manager().plugin_configs.xai_configendpoint, api_key = xai_config.configure(secrets_provider=get_secrets_provider())log.verbose(f"Making Xai AsyncOpenAI client with endpoint: {endpoint}")@@ -72,7 +71,7 @@ class OpenAIFactory:base_url=endpoint,)case LLMPlatform.CUSTOM_LLM:- custom_endpoint_config = get_config().plugins.custom_endpoint_config+ custom_endpoint_config = get_plugin_manager().plugin_configs.custom_endpoint_configbase_url, api_key = custom_endpoint_config.configure(secrets_provider=get_secrets_provider())log.verbose(f"Making custom AsyncOpenAI client with base_url: {base_url}")diff --git a/pipelex/plugins/openai/openai_imgg_worker.py b/pipelex/plugins/openai/openai_imgg_worker.pyindex b68aa7c82..6ac84f67f 100644--- a/pipelex/plugins/openai/openai_imgg_worker.py+++ b/pipelex/plugins/openai/openai_imgg_worker.py@@ -11,7 +11,7 @@ from pipelex.cogt.imgg.imgg_engine import ImggEnginefrom pipelex.cogt.imgg.imgg_job import ImggJobfrom pipelex.cogt.imgg.imgg_job_components import Qualityfrom pipelex.cogt.imgg.imgg_worker_abstract import ImggWorkerAbstract-from pipelex.config import get_config+from pipelex.hub import get_plugin_managerfrom pipelex.plugins.openai.openai_imgg_factory import OpenAIImggFactoryfrom pipelex.reporting.reporting_protocol import ReportingProtocolfrom pipelex.tools.misc.base_64_utils import save_base64_to_binary_file@@ -54,7 +54,7 @@ class OpenAIImggWorker(ImggWorkerAbstract):moderation = OpenAIImggFactory.moderation_for_gpt_image_1(is_moderated=imgg_job.job_params.is_moderated)background = OpenAIImggFactory.background_for_gpt_image_1(background=imgg_job.job_params.background)quality = OpenAIImggFactory.quality_for_gpt_image_1(quality=imgg_job.job_params.quality or Quality.LOW)- output_compression = get_config().plugins.openai_config.image_output_compression+ output_compression = get_plugin_manager().plugin_configs.openai_config.image_output_compressionresult = await self.openai_client.images.generate(prompt=imgg_job.imgg_prompt.positive_text,model=self.imgg_engine.imgg_model_name,diff --git a/pipelex/plugins/openai/openai_llm_worker.py b/pipelex/plugins/openai/openai_llm_worker.pyindex c0305ebbf..525cd17e9 100644--- a/pipelex/plugins/openai/openai_llm_worker.py+++ b/pipelex/plugins/openai/openai_llm_worker.py@@ -11,14 +11,14 @@ from pipelex.cogt.exceptions import LLMCompletionError, LLMEngineParameterError,from pipelex.cogt.llm.llm_job import LLMJobfrom pipelex.cogt.llm.llm_models.llm_engine import LLMEnginefrom pipelex.cogt.llm.llm_models.llm_family import LLMFamily-from pipelex.cogt.llm.llm_worker_abstract import LLMWorkerAbstract+from pipelex.cogt.llm.llm_worker_internal_abstract import LLMWorkerInternalAbstractfrom pipelex.cogt.llm.structured_output import StructureMethodfrom pipelex.plugins.openai.openai_factory import OpenAIFactoryfrom pipelex.reporting.reporting_protocol import ReportingProtocolfrom pipelex.tools.typing.pydantic_utils import BaseModelTypeVar-class OpenAILLMWorker(LLMWorkerAbstract):+class OpenAILLMWorker(LLMWorkerInternalAbstract):def __init__(self,sdk_instance: Any,@@ -26,7 +26,12 @@ class OpenAILLMWorker(LLMWorkerAbstract):structure_method: Optional[StructureMethod],reporting_delegate: Optional[ReportingProtocol] = None,):- super().__init__(llm_engine=llm_engine, structure_method=structure_method, reporting_delegate=reporting_delegate)+ LLMWorkerInternalAbstract.__init__(+ self,+ llm_engine=llm_engine,+ structure_method=structure_method,+ reporting_delegate=reporting_delegate,+ )if not isinstance(sdk_instance, openai.AsyncOpenAI):raise SdkTypeError(diff --git a/pipelex/plugins/openai/perplexity_config.py b/pipelex/plugins/openai/perplexity_config.pyindex 9f7665474..3fd06d0e0 100644--- a/pipelex/plugins/openai/perplexity_config.py+++ b/pipelex/plugins/openai/perplexity_config.py@@ -3,15 +3,15 @@ from typing import Tuplefrom pydantic import Fieldfrom pipelex import log-from pipelex.cogt.exceptions import CogtErrorfrom pipelex.tools.config.models import ConfigModelfrom pipelex.tools.environment import EnvVarNotFoundError, get_required_env+from pipelex.tools.exceptions import CredentialsErrorfrom pipelex.tools.secrets.secrets_errors import SecretNotFoundErrorfrom pipelex.tools.secrets.secrets_provider_abstract import SecretsProviderAbstractfrom pipelex.types import StrEnum-class PerplexityCredentialsError(CogtError):+class PerplexityCredentialsError(CredentialsError):passdiff --git a/pipelex/plugins/openai/vertexai_config.py b/pipelex/plugins/openai/vertexai_config.pyindex 861fa8bd1..92b4e5bce 100644--- a/pipelex/plugins/openai/vertexai_config.py+++ b/pipelex/plugins/openai/vertexai_config.py@@ -3,16 +3,17 @@ from typing import Any, Dict, Tuplefrom pydantic import Fieldfrom pipelex import log-from pipelex.cogt.exceptions import CogtError, MissingDependencyError+from pipelex.cogt.exceptions import MissingDependencyErrorfrom pipelex.tools.config.models import ConfigModelfrom pipelex.tools.environment import EnvVarNotFoundError, get_required_env+from pipelex.tools.exceptions import CredentialsErrorfrom pipelex.tools.misc.json_utils import load_json_dict_from_pathfrom pipelex.tools.secrets.secrets_errors import SecretNotFoundErrorfrom pipelex.tools.secrets.secrets_provider_abstract import SecretsProviderAbstractfrom pipelex.types import StrEnum-class VertexAICredentialsError(CogtError):+class VertexAICredentialsError(CredentialsError):passdiff --git a/pipelex/plugins/openai/xai_config.py b/pipelex/plugins/openai/xai_config.pyindex 45b49a2e4..1719e8d9e 100644--- a/pipelex/plugins/openai/xai_config.py+++ b/pipelex/plugins/openai/xai_config.py@@ -3,15 +3,15 @@ from typing import Tuplefrom pydantic import Fieldfrom pipelex import log-from pipelex.cogt.exceptions import CogtErrorfrom pipelex.tools.config.models import ConfigModelfrom pipelex.tools.environment import EnvVarNotFoundError, get_required_env+from pipelex.tools.exceptions import CredentialsErrorfrom pipelex.tools.secrets.secrets_errors import SecretNotFoundErrorfrom pipelex.tools.secrets.secrets_provider_abstract import SecretsProviderAbstractfrom pipelex.types import StrEnum-class XaiCredentialsError(CogtError):+class XaiCredentialsError(CredentialsError):passdiff --git a/pipelex/plugins/plugin_manager.py b/pipelex/plugins/plugin_manager.pynew file mode 100644index 000000000..9c14cb73d--- /dev/null+++ b/pipelex/plugins/plugin_manager.py@@ -0,0 +1,27 @@+from typing import Optional++from pipelex.libraries.library_config import LibraryConfig+from pipelex.plugins.plugin_sdk_registry import PluginSdkRegistry+from pipelex.plugins.plugins_config import PluginConfig+from pipelex.tools.misc.toml_utils import load_toml_from_path+++class PluginManager:+ def __init__(self):+ self._plugin_configs: Optional[PluginConfig] = None+ self.plugin_sdk_registry = PluginSdkRegistry()++ @property+ def plugin_configs(self) -> PluginConfig:+ if self._plugin_configs is None:+ raise RuntimeError("Plugin configs not loaded")+ return self._plugin_configs++ def setup(self):+ plugin_config_path = LibraryConfig.get_plugin_config_path()+ plugin_config_dict = load_toml_from_path(path=plugin_config_path)+ self._plugin_configs = PluginConfig.model_validate(plugin_config_dict)++ def teardown(self):+ self._plugin_configs = None+ self.plugin_sdk_registry.teardown()diff --git a/pipelex/cogt/plugin_manager.py b/pipelex/plugins/plugin_sdk_registry.pysimilarity index 53%rename from pipelex/cogt/plugin_manager.pyrename to pipelex/plugins/plugin_sdk_registry.pyindex 85955cbf4..59619aa32 100644--- a/pipelex/cogt/plugin_manager.py+++ b/pipelex/plugins/plugin_sdk_registry.py@@ -8,7 +8,7 @@ from pipelex.cogt.ocr.ocr_platform import OcrPlatformfrom pipelex.types import StrEnum-class PluginHandle(StrEnum):+class PluginSdkHandle(StrEnum):OPENAI_SDK = "openai_sdk"AZURE_OPENAI_SDK = "azure_openai_sdk"ANTHROPIC_SDK = "anthropic_sdk"@@ -22,70 +22,73 @@ class PluginHandle(StrEnum):FAL_SDK = "fal_sdk"@staticmethod- def get_for_llm_platform(llm_platform: LLMPlatform) -> "PluginHandle":+ def get_for_llm_platform(llm_platform: LLMPlatform) -> "PluginSdkHandle":match llm_platform:case LLMPlatform.OPENAI:- return PluginHandle.OPENAI_SDK+ return PluginSdkHandle.OPENAI_SDKcase LLMPlatform.AZURE_OPENAI:- return PluginHandle.AZURE_OPENAI_SDK+ return PluginSdkHandle.AZURE_OPENAI_SDKcase LLMPlatform.ANTHROPIC:- return PluginHandle.ANTHROPIC_SDK+ return PluginSdkHandle.ANTHROPIC_SDKcase LLMPlatform.MISTRAL:- return PluginHandle.MISTRAL_SDK+ return PluginSdkHandle.MISTRAL_SDKcase LLMPlatform.BEDROCK:- return PluginHandle.BEDROCK_SDK+ return PluginSdkHandle.BEDROCK_SDKcase LLMPlatform.BEDROCK_ANTHROPIC:- return PluginHandle.BEDROCK_ANTHROPIC_SDK+ return PluginSdkHandle.BEDROCK_ANTHROPIC_SDKcase LLMPlatform.PERPLEXITY:- return PluginHandle.PERPLEXITY_OPENAI_SDK+ return PluginSdkHandle.PERPLEXITY_OPENAI_SDKcase LLMPlatform.VERTEXAI:- return PluginHandle.VERTEXAI_OPENAI_SDK+ return PluginSdkHandle.VERTEXAI_OPENAI_SDKcase LLMPlatform.XAI:- return PluginHandle.XAI_OPENAI_SDK+ return PluginSdkHandle.XAI_OPENAI_SDKcase LLMPlatform.CUSTOM_LLM:- return PluginHandle.CUSTOM_LLM_OPENAI_SDK+ return PluginSdkHandle.CUSTOM_LLM_OPENAI_SDK@staticmethod- def get_for_ocr_engine(ocr_platform: OcrPlatform) -> "PluginHandle":+ def get_for_ocr_engine(ocr_platform: OcrPlatform) -> "PluginSdkHandle":match ocr_platform:case OcrPlatform.MISTRAL:- return PluginHandle.MISTRAL_SDK+ return PluginSdkHandle.MISTRAL_SDK@staticmethod- def get_for_imgg_engine(imgg_platform: ImggPlatform) -> "PluginHandle":+ def get_for_imgg_engine(imgg_platform: ImggPlatform) -> "PluginSdkHandle":match imgg_platform:case ImggPlatform.FAL_AI:- return PluginHandle.FAL_SDK+ return PluginSdkHandle.FAL_SDKcase ImggPlatform.OPENAI:- return PluginHandle.OPENAI_SDK+ return PluginSdkHandle.OPENAI_SDK-PluginManagerRoot = Dict[str, Any]+PluginSdkRegistryRoot = Dict[str, Any]-class PluginManager(RootModel[PluginManagerRoot]):- root: PluginManagerRoot = Field(default_factory=dict)+class PluginSdkRegistry(RootModel[PluginSdkRegistryRoot]):+ root: PluginSdkRegistryRoot = Field(default_factory=dict)- def reset(self):- self.root.clear()+ def teardown(self):+ for llm_sdk_instance in self.root.values():+ if hasattr(llm_sdk_instance, "teardown"):+ llm_sdk_instance.teardown()+ self.root = {}- def get_llm_sdk_instance(self, llm_sdk_handle: PluginHandle) -> Optional[Any]:+ def get_llm_sdk_instance(self, llm_sdk_handle: PluginSdkHandle) -> Optional[Any]:return self.root.get(llm_sdk_handle)- def set_llm_sdk_instance(self, llm_sdk_handle: PluginHandle, llm_sdk_instance: Any) -> Any:+ def set_llm_sdk_instance(self, llm_sdk_handle: PluginSdkHandle, llm_sdk_instance: Any) -> Any:self.root[llm_sdk_handle] = llm_sdk_instancereturn llm_sdk_instance- def get_ocr_sdk_instance(self, ocr_sdk_handle: PluginHandle) -> Optional[Any]:+ def get_ocr_sdk_instance(self, ocr_sdk_handle: PluginSdkHandle) -> Optional[Any]:return self.root.get(ocr_sdk_handle)- def set_ocr_sdk_instance(self, ocr_sdk_handle: PluginHandle, ocr_sdk_instance: Any) -> Any:+ def set_ocr_sdk_instance(self, ocr_sdk_handle: PluginSdkHandle, ocr_sdk_instance: Any) -> Any:self.root[ocr_sdk_handle] = ocr_sdk_instancereturn ocr_sdk_instance- def get_imgg_sdk_instance(self, imgg_sdk_handle: PluginHandle) -> Optional[Any]:+ def get_imgg_sdk_instance(self, imgg_sdk_handle: PluginSdkHandle) -> Optional[Any]:return self.root.get(imgg_sdk_handle)- def set_imgg_sdk_instance(self, imgg_sdk_handle: PluginHandle, imgg_sdk_instance: Any) -> Any:+ def set_imgg_sdk_instance(self, imgg_sdk_handle: PluginSdkHandle, imgg_sdk_instance: Any) -> Any:self.root[imgg_sdk_handle] = imgg_sdk_instancereturn imgg_sdk_instancediff --git a/pipelex/plugins/plugins_config.py b/pipelex/plugins/plugins_config.pyindex ac5dc7d47..cd11b970f 100644--- a/pipelex/plugins/plugins_config.py+++ b/pipelex/plugins/plugins_config.py@@ -11,7 +11,7 @@ from pipelex.plugins.openai.xai_config import XaiConfigfrom pipelex.tools.config.models import ConfigModel-class PluginsConfig(ConfigModel):+class PluginConfig(ConfigModel):anthropic_config: AnthropicConfigazure_openai_config: AzureOpenAIConfigbedrock_config: BedrockConfigdiff --git a/pipelex/plugins/specific_llm/specific_llm_config.py b/pipelex/plugins/specific_llm/specific_llm_config.pynew file mode 100644index 000000000..3eff2f16a--- /dev/null+++ b/pipelex/plugins/specific_llm/specific_llm_config.py@@ -0,0 +1,7 @@+from typing import Dict++from pipelex.tools.config.models import ConfigModel+++class SpecificLLMConfig(ConfigModel):+ llm_worker_classes: Dict[str, str]diff --git a/pipelex/tools/aws/aws_config.py b/pipelex/tools/aws/aws_config.pyindex 6f5fce9f2..1dbda8abb 100644--- a/pipelex/tools/aws/aws_config.py+++ b/pipelex/tools/aws/aws_config.py@@ -6,12 +6,12 @@ from pipelex import logfrom pipelex.hub import get_secretfrom pipelex.tools.config.models import ConfigModelfrom pipelex.tools.environment import EnvVarNotFoundError, get_required_env-from pipelex.tools.exceptions import ToolException+from pipelex.tools.exceptions import CredentialsErrorfrom pipelex.tools.secrets.secrets_errors import SecretNotFoundErrorfrom pipelex.types import StrEnum-class AwsCredentialsError(ToolException):+class AwsCredentialsError(CredentialsError):passdiff --git a/pipelex/tools/exceptions.py b/pipelex/tools/exceptions.pyindex 054477cfc..20eef6a10 100644--- a/pipelex/tools/exceptions.py+++ b/pipelex/tools/exceptions.py@@ -14,6 +14,10 @@ class ToolException(RootException):pass+class CredentialsError(RootException):+ pass++class TracebackMessageErrorMode(StrEnum):ERROR = "error"EXCEPTION = "exception"diff --git a/pipelex/tools/typing/pydantic_utils.py b/pipelex/tools/typing/pydantic_utils.pyindex ff269e7f7..d4115b02d 100644--- a/pipelex/tools/typing/pydantic_utils.py+++ b/pipelex/tools/typing/pydantic_utils.py@@ -26,7 +26,9 @@ def format_pydantic_validation_error(exc: ValidationError) -> str:extra_fields = [f"{'.'.join(map(str, err['loc']))}: {err['input']}" for err in exc.errors() if err["type"] == "extra_forbidden"]type_errors = [f"{'.'.join(map(str, err['loc']))}: expected {err['type']}" for err in exc.errors() if err["type"] == "type_error"]value_errors = [f"{'.'.join(map(str, err['loc']))}: {err['msg']}" for err in exc.errors() if err["type"] == "value_error"]- enum_errors = [f"{'.'.join(map(str, err['loc']))}: invalid enum value" for err in exc.errors() if err["type"] == "enum"]+ enum_errors = [+ f"{'.'.join(map(str, err['loc']))}: invalid enum value '{err.get('input', 'unknown')}'" for err in exc.errors() if err["type"] == "enum"+ ]model_type_errors: List[str] = []for err in exc.errors():if err["type"] == "model_type":diff --git a/pyproject.toml b/pyproject.tomlindex c1f3697f4..6e57ffae7 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -1,6 +1,6 @@[project]name = "pipelex"-version = "0.4.8"+version = "0.4.9"description = "Pipelex is an open-source dev tool based on a simple declarative language that lets you define replicable, structured, composable LLM pipelines."authors = [{ name = "Evotis S.A.S.", email = "[email protected]" }]maintainers = [{ name = "Pipelex staff", email = "[email protected]" }]diff --git a/tests/integration/pipelex/cogt/test_llm_engines.py b/tests/integration/pipelex/cogt/test_llm_engines.pyindex b304f2cff..a388ddf58 100644--- a/tests/integration/pipelex/cogt/test_llm_engines.py+++ b/tests/integration/pipelex/cogt/test_llm_engines.py@@ -22,13 +22,12 @@ class TestLLMEngines:generated_text = await llm_worker.gen_text(llm_job=llm_job)assert generated_textpretty_print(generated_text)- llm_model = llm_worker.llm_engine.llm_model- if llm_model.is_gen_object_supported:+ if llm_worker.is_gen_object_supported:generated_object = await llm_worker.gen_object(llm_job=llm_job, schema=Person)assert generated_objectpretty_print(generated_object)else:- log.info(f"No object generation supported for this model: '{llm_model.name_and_version_and_platform}'")+ log.info(f"No object generation supported for this worker: '{llm_worker.desc}'")async def test_one_llm_engine(self, llm_job_params: LLMJobParams, llm_handle: str):inference_manager = get_inference_manager()@@ -44,7 +43,6 @@ class TestLLMEngines:log.info(f"Testing {llm_id} on {llm_platform}")llm_models_provider = get_llm_models_provider()llm_models = llm_models_provider.get_all_llm_models()- llm_worker_factory = LLMWorkerFactory()count = 0for llm_model in llm_models:platform_llm_id = llm_model.platform_llm_id.get(llm_platform)@@ -55,7 +53,7 @@ class TestLLMEngines:llm_platform=llm_platform,llm_model=llm_model,)- llm_worker = llm_worker_factory.make_llm_worker(+ llm_worker = LLMWorkerFactory.make_llm_worker(llm_engine=llm_engine,reporting_delegate=get_report_delegate(),)@@ -73,16 +71,15 @@ class TestLLMEngines:pytest.fail(f"No llm_engines found for llm_id '{llm_id}' on platform '{llm_platform}'")async def test_llm_engines_from_one_family(self, llm_job_params: LLMJobParams, llm_family: LLMFamily):- inference_manager = get_inference_manager()llm_handle_to_llm_engine_blueprint = get_llm_deck().llm_handlescount = 0- for llm_handle, llm_engine_blueprint in llm_handle_to_llm_engine_blueprint.items():+ for _, llm_engine_blueprint in llm_handle_to_llm_engine_blueprint.items():llm_engine = LLMEngineFactory.make_llm_engine(llm_engine_blueprint=llm_engine_blueprint)if llm_engine.llm_model.llm_family != llm_family:continue- llm_worker = inference_manager.get_llm_worker(- llm_handle=llm_handle,- specific_llm_engine_blueprint=llm_engine_blueprint,+ llm_worker = LLMWorkerFactory.make_llm_worker(+ llm_engine=llm_engine,+ reporting_delegate=get_report_delegate(),)llm_job = LLMJobFactory.make_llm_job_from_prompt_contents(system_text=None,@@ -95,15 +92,14 @@ class TestLLMEngines:log.info(f"Tested {count} llm_engines for family {llm_family}")async def test_llm_engines_from_one_creator(self, llm_job_params: LLMJobParams, llm_creator: LLMCreator):- inference_manager = get_inference_manager()llm_handle_to_llm_engine_blueprint = get_llm_deck().llm_handles- for llm_handle, llm_engine_blueprint in llm_handle_to_llm_engine_blueprint.items():+ for _, llm_engine_blueprint in llm_handle_to_llm_engine_blueprint.items():llm_engine = LLMEngineFactory.make_llm_engine(llm_engine_blueprint=llm_engine_blueprint)if llm_engine.llm_model.llm_family.creator != llm_creator:continue- llm_worker = inference_manager.get_llm_worker(- llm_handle=llm_handle,- specific_llm_engine_blueprint=llm_engine_blueprint,+ llm_worker = LLMWorkerFactory.make_llm_worker(+ llm_engine=llm_engine,+ reporting_delegate=get_report_delegate(),)llm_job = LLMJobFactory.make_llm_job_from_prompt_contents(system_text=None,@@ -115,7 +111,6 @@ class TestLLMEngines:async def test_llm_engines_from_one_platform(self, llm_job_params: LLMJobParams, llm_platform: LLMPlatform):llm_models_provider = get_llm_models_provider()llm_models = llm_models_provider.get_all_llm_models()- llm_worker_factory = LLMWorkerFactory()for llm_model in llm_models:if llm_platform not in llm_model.enabled_platforms:continue@@ -123,7 +118,7 @@ class TestLLMEngines:llm_platform=llm_platform,llm_model=llm_model,)- llm_worker = llm_worker_factory.make_llm_worker(+ llm_worker = LLMWorkerFactory.make_llm_worker(llm_engine=llm_engine,reporting_delegate=get_report_delegate(),)diff --git a/tests/integration/pipelex/cogt/test_llm_gen_object.py b/tests/integration/pipelex/cogt/test_llm_gen_object.pyindex 5fb151c35..05005e319 100644--- a/tests/integration/pipelex/cogt/test_llm_gen_object.py+++ b/tests/integration/pipelex/cogt/test_llm_gen_object.py@@ -31,8 +31,8 @@ class TestLLMGenObject:@pytest.mark.parametrize("user_text, expected_instance", LLMTestCases.SINGLE_OBJECT)async def test_gen_object_async_using_handle(self, llm_job_params: LLMJobParams, llm_handle: str, user_text: str, expected_instance: BaseModel):llm_worker = get_llm_worker(llm_handle=llm_handle)- if not llm_worker.llm_engine.is_gen_object_supported:- pytest.skip(f"LLM '{llm_handle}' does not support object generation")+ if not llm_worker.is_gen_object_supported:+ pytest.skip(f"LLM worker '{llm_worker.desc}' does not support object generation")llm_job = LLMJobFactory.make_llm_job_from_prompt_contents(user_text=user_text,llm_job_params=llm_job_params,@@ -46,8 +46,8 @@ class TestLLMGenObject:@pytest.mark.parametrize("user_text, expected_instance", LLMTestCases.SINGLE_OBJECT)async def test_gen_object_async_using_llm_preset(self, llm_preset_id: str, user_text: str, expected_instance: BaseModel):llm_worker, llm_job = get_async_worker_and_job(llm_preset_id=llm_preset_id, user_text=user_text)- if not llm_worker.llm_engine.is_gen_object_supported:- pytest.skip(f"LLM '{llm_worker.llm_engine.tag}' does not support object generation")+ if not llm_worker.is_gen_object_supported:+ pytest.skip(f"'{llm_worker.desc}' does not support object generation")expected_class = expected_instance.__class__output = await llm_worker.gen_object(llm_job=llm_job, schema=expected_class)pretty_print(output)@@ -59,8 +59,8 @@ class TestLLMGenObject:self, llm_job_params: LLMJobParams, llm_handle: str, case_tuples: List[Tuple[str, BaseModel]]):llm_worker = get_llm_worker(llm_handle=llm_handle)- if not llm_worker.llm_engine.is_gen_object_supported:- pytest.skip(f"LLM '{llm_handle}' does not support object generation")+ if not llm_worker.is_gen_object_supported:+ pytest.skip(f"'{llm_worker.desc}' does not support object generation")tasks: List[asyncio.Task[BaseModel]] = []for case_tuple in case_tuples:user_text, expected_instance = case_tuple@@ -83,8 +83,8 @@ class TestLLMGenObject:@pytest.mark.parametrize("case_tuples", LLMTestCases.MULTIPLE_OBJECTS)async def test_gen_object_async_multiple_using_llm_preset(self, llm_preset_id: str, case_tuples: List[Tuple[str, BaseModel]]):llm_worker, llm_job = get_async_worker_and_job(llm_preset_id=llm_preset_id, user_text=case_tuples[0][0])- if not llm_worker.llm_engine.is_gen_object_supported:- pytest.skip(f"LLM '{llm_worker.llm_engine.tag}' does not support object generation")+ if not llm_worker.is_gen_object_supported:+ pytest.skip(f"'{llm_worker.desc}' does not support object generation")tasks: List[asyncio.Task[BaseModel]] = []for case_tuple in case_tuples:user_text, expected_instance = case_tuplediff --git a/tests/integration/pipelex/cogt/test_llm_gen_text.py b/tests/integration/pipelex/cogt/test_llm_gen_text.pyindex 66f9f231a..fc42fd90f 100644--- a/tests/integration/pipelex/cogt/test_llm_gen_text.py+++ b/tests/integration/pipelex/cogt/test_llm_gen_text.py@@ -1,17 +1,20 @@import asyncio-from typing import List+from typing import List, Tupleimport pytestfrom pipelex import log, pretty_print+from pipelex.cogt.llm.llm_job import LLMJobfrom pipelex.cogt.llm.llm_job_components import LLMJobParamsfrom pipelex.cogt.llm.llm_job_factory import LLMJobFactoryfrom pipelex.cogt.llm.llm_models.llm_family import LLMFamily+from pipelex.cogt.llm.llm_worker_abstract import LLMWorkerAbstract+from pipelex.cogt.llm.llm_worker_internal_abstract import LLMWorkerInternalAbstractfrom pipelex.hub import get_llm_deck, get_llm_worker, get_report_delegatefrom tests.integration.pipelex.cogt.test_data import LLMTestCases-def get_async_worker_and_job(llm_preset_id: str, user_text: str):+def get_worker_and_job(llm_preset_id: str, user_text: str) -> Tuple[LLMWorkerAbstract, LLMJob]:llm_setting = get_llm_deck().get_llm_setting(llm_setting_or_preset_id=llm_preset_id)pretty_print(llm_setting, title=llm_preset_id)pretty_print(user_text)@@ -43,14 +46,14 @@ class TestLLMGenText:@pytest.mark.parametrize("topic, prompt_text", LLMTestCases.SINGLE_TEXT)async def test_gen_text_async_using_llm_preset(self, llm_preset_id: str, topic: str, prompt_text: str):- llm_worker, llm_job = get_async_worker_and_job(llm_preset_id=llm_preset_id, user_text=prompt_text)+ llm_worker, llm_job = get_worker_and_job(llm_preset_id=llm_preset_id, user_text=prompt_text)generated_text = await llm_worker.gen_text(llm_job=llm_job)assert generated_textpretty_print(generated_text)@pytest.mark.parametrize("topic, prompt_text", LLMTestCases.SINGLE_TEXT)async def test_gen_text_async_multiple_using_llm_preset(self, llm_preset_id: str, topic: str, prompt_text: str):- llm_worker, llm_job = get_async_worker_and_job(llm_preset_id=llm_preset_id, user_text=prompt_text)+ llm_worker, llm_job = get_worker_and_job(llm_preset_id=llm_preset_id, user_text=prompt_text)job_params_base = llm_job.job_paramsmax_tokens = 30temperature = 0.1@@ -60,8 +63,8 @@ class TestLLMGenText:temperature += 0.2if temperature > 1:break- if llm_worker.llm_engine.llm_model.llm_family == LLMFamily.O_SERIES:- log.warning("LLMFamily.O1, forcing temprature to 1, setting minimum tokens to avoid empty output")+ if isinstance(llm_worker, LLMWorkerInternalAbstract) and llm_worker.llm_engine.llm_model.llm_family == LLMFamily.O_SERIES:+ log.warning("LLMFamily O_series, forcing temprature to 1, setting minimum tokens to avoid empty output")completion_max_tokens = max(max_tokens, 2000)llm_job.job_params = job_params_base.model_copy(update={"max_tokens": completion_max_tokens, "temperature": 1})else:diff --git a/tests/integration/pipelex/plugins/test_external_plugin.py b/tests/integration/pipelex/plugins/test_external_plugin.pynew file mode 100644index 000000000..e7cd67003--- /dev/null+++ b/tests/integration/pipelex/plugins/test_external_plugin.py@@ -0,0 +1,113 @@+from typing import Type++import pytest+from polyfactory.factories.pydantic_factory import ModelFactory+from typing_extensions import override++from pipelex import log, pretty_print+from pipelex.cogt.llm.llm_job import LLMJob+from pipelex.cogt.llm.llm_job_components import LLMJobParams+from pipelex.cogt.llm.llm_job_factory import LLMJobFactory+from pipelex.cogt.llm.llm_models.llm_setting import LLMSetting, LLMSettingChoices+from pipelex.cogt.llm.llm_worker_abstract import LLMWorkerAbstract+from pipelex.cogt.llm.token_category import NbTokensByCategoryDict, TokenCategory+from pipelex.core.concept_native import NativeConcept+from pipelex.hub import get_inference_manager, get_pipe_router, get_report_delegate+from pipelex.pipe_operators.pipe_llm import PipeLLM, PipeLLMOutput+from pipelex.pipe_operators.pipe_llm_prompt import PipeLLMPrompt+from pipelex.pipe_works.pipe_job_factory import PipeJobFactory+from pipelex.tools.typing.pydantic_utils import BaseModelTypeVar+from tests.integration.pipelex.cogt.test_data import LLMTestConstants, Person+from tests.integration.pipelex.test_data import PipeTestCases++EXTERNAL_PLUGIN_NAME = "mock_external_llm"+++class MockExternalLLMWorker(LLMWorkerAbstract):+ @property+ @override+ def is_gen_object_supported(self) -> bool:+ return True++ @override+ async def _gen_text(+ self,+ llm_job: LLMJob,+ ) -> str:+ response_text = f"This is a mock LLM response from '{self.__class__}'"++ if llm_tokens_usage := llm_job.job_report.llm_tokens_usage:+ nb_tokens_by_category: NbTokensByCategoryDict = {+ TokenCategory.INPUT: 100,+ TokenCategory.OUTPUT: 100,+ }+ llm_tokens_usage.nb_tokens_by_category = nb_tokens_by_category+ return response_text++ @override+ async def _gen_object(+ self,+ llm_job: LLMJob,+ schema: Type[BaseModelTypeVar],+ ) -> BaseModelTypeVar:+ class ObjectFactory(ModelFactory[schema]): # type: ignore+ __model__ = schema+ __use_examples__ = True++ obj = ObjectFactory.build()+ return obj++[email protected](loop_scope="class")+class TestExternalPlugin:+ async def test_external_llm_worker(self):+ llm_worker = MockExternalLLMWorker(reporting_delegate=get_report_delegate())+ llm_job = LLMJobFactory.make_llm_job_from_prompt_contents(+ system_text=None,+ user_text=LLMTestConstants.USER_TEXT_SHORT,+ llm_job_params=LLMJobParams(+ temperature=0.5,+ max_tokens=None,+ seed=None,+ ),+ )+ generated_text = await llm_worker.gen_text(llm_job=llm_job)+ assert generated_text+ pretty_print(generated_text)+ generated_object = await llm_worker.gen_object(llm_job=llm_job, schema=Person)+ assert generated_object+ pretty_print(generated_object)++ async def test_pipe_llm_with_external_llm_handle(self):+ llm_handle = EXTERNAL_PLUGIN_NAME+ get_inference_manager().set_llm_worker_from_external_plugin(+ llm_handle=llm_handle,+ llm_worker_class=MockExternalLLMWorker,+ )+ pipe_job = PipeJobFactory.make_pipe_job(+ pipe=PipeLLM(+ code="adhoc_for_test_pipe_llm_with_external_llm_handle",+ domain="generic",+ output_concept_code=NativeConcept.TEXT.code,+ pipe_llm_prompt=PipeLLMPrompt(+ code="adhoc_for_test_pipe_llm_with_external_llm_handle",+ domain="generic",+ system_prompt=PipeTestCases.SYSTEM_PROMPT,+ user_text=PipeTestCases.USER_PROMPT,+ ),+ llm_choices=LLMSettingChoices.make_completed_with_defaults(+ for_text=LLMSetting(+ llm_handle=llm_handle,+ temperature=0.5,+ max_tokens=None,+ ),+ ),+ ),+ )+ pipe_llm_output: PipeLLMOutput = await get_pipe_router().run_pipe_job(+ pipe_job=pipe_job,+ )++ log.verbose(pipe_llm_output, title="stuff")+ llm_generated_text = pipe_llm_output.main_stuff_as_text+ pretty_print(llm_generated_text, title="llm_generated_text")diff --git a/tests/integration/pipelex/plugins/test_openai.py b/tests/integration/pipelex/plugins/test_openai.pyindex a85e485fa..21d04cd9e 100644--- a/tests/integration/pipelex/plugins/test_openai.py+++ b/tests/integration/pipelex/plugins/test_openai.py@@ -3,8 +3,7 @@ import pytestfrom pipelex import pretty_printfrom pipelex.cogt.exceptions import LLMSDKErrorfrom pipelex.cogt.llm.llm_models.llm_platform import LLMPlatform-from pipelex.config import get_config-from pipelex.hub import get_secrets_provider+from pipelex.hub import get_plugin_manager, get_secrets_providerfrom pipelex.plugins.openai.openai_llms import openai_list_available_models@@ -14,7 +13,7 @@ from pipelex.plugins.openai.openai_llms import openai_list_available_models@pytest.mark.asyncio(loop_scope="class")class TestOpenAI:async def test_openai_api_key(self):- openai_config = get_config().plugins.openai_config+ openai_config = get_plugin_manager().plugin_configs.openai_configassert openai_config.get_api_key(secrets_provider=get_secrets_provider())# pytest -k test_openai_list_available_models -s -vvdiff --git a/tests/integration/pipelex/test_data.py b/tests/integration/pipelex/test_data.pyindex 77e2ec745..3daf1136c 100644--- a/tests/integration/pipelex/test_data.py+++ b/tests/integration/pipelex/test_data.py@@ -2,7 +2,13 @@ from typing import ClassVar, List, Optional, Tuple, Typefrom pipelex.core.pipe_run_params import PipeOutputMultiplicityfrom pipelex.core.stuff import Stuff-from pipelex.core.stuff_content import ImageContent, ListContent, PDFContent, StructuredContent, TextContent+from pipelex.core.stuff_content import (+ ImageContent,+ ListContent,+ PDFContent,+ StructuredContent,+ TextContent,+)from pipelex.core.stuff_factory import StuffBlueprint, StuffFactoryfrom pipelex.exceptions import PipeStackOverflowErrorfrom tests.cases import ImageTestCases, PDFTestCases@@ -83,8 +89,14 @@ class PipeTestCases:)STUFFS_IMAGE_ATTRIBUTES: ClassVar[List[Tuple[Stuff, List[str]]]] = [ # stuff, attribute_paths(STUFF_WITH_IMAGE_ATTRIBUTE, ["stuff_with_image.image_attribute"]),- (STUFF_WITH_IMAGE_ATTRIBUTE_IN_SUB_OBJECT, ["stuff_with_image_in_sub_object.image_attribute"]),- (STUFF_WITH_IMAGE_ATTRIBUTE_IN_SUB_OBJECT, ["stuff_with_image_in_sub_object.sub_object.image_attribute"]),+ (+ STUFF_WITH_IMAGE_ATTRIBUTE_IN_SUB_OBJECT,+ ["stuff_with_image_in_sub_object.image_attribute"],+ ),+ (+ STUFF_WITH_IMAGE_ATTRIBUTE_IN_SUB_OBJECT,+ ["stuff_with_image_in_sub_object.sub_object.image_attribute"],+ ),(STUFF_WITH_IMAGE_ATTRIBUTE_IN_SUB_OBJECT,[@@ -93,7 +105,11 @@ class PipeTestCases:],),]- TRICKY_QUESTION_BLUEPRINT = StuffBlueprint(stuff_name="question", concept_code="answer.Question", content=USER_TEXT_TRICKY_2)+ TRICKY_QUESTION_BLUEPRINT = StuffBlueprint(+ stuff_name="question",+ concept_code="answer.Question",+ content=USER_TEXT_TRICKY_2,+ )BLUEPRINT_AND_PIPE: ClassVar[List[Tuple[str, StuffBlueprint, str]]] = [ # topic, blueprint, pipe("Tricky question conclude",