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.
Add missing inputs
Louis Choquelf3db3c432cb2
diff --git a/pipelex/core/pipe_library.py b/pipelex/core/pipe_library.pyindex 8eeeff5ff..ad05d4770 100644--- a/pipelex/core/pipe_library.py+++ b/pipelex/core/pipe_library.py@@ -46,6 +46,13 @@ class PipeLibrary(RootModel[PipeLibraryRoot], PipeProviderAbstract):raise PipeLibraryError(f"Pipe '{name}' already exists in the library")self.root[pipe.code] = pipe+ def add_or_update_pipe(self, pipe: PipeAbstract):+ name = pipe.code+ pipe.inputs.set_default_domain(domain=pipe.domain)+ if pipe.output_concept_code and "." not in pipe.output_concept_code:+ pipe.output_concept_code = f"{pipe.domain}.{pipe.output_concept_code}"+ self.root[name] = pipe+@overridedef get_optional_pipe(self, pipe_code: str) -> Optional[PipeAbstract]:return self.root.get(pipe_code)diff --git a/pipelex/create/build_blueprint.py b/pipelex/create/build_blueprint.pyindex 4e64d0a14..32722b91e 100644--- a/pipelex/create/build_blueprint.py+++ b/pipelex/create/build_blueprint.py@@ -5,11 +5,14 @@ from typing import Optionalimport typer-from pipelex import pretty_print+from pipelex import log, pretty_printfrom pipelex.create.helpers import get_support_filefrom pipelex.create.pipeline_toml import save_pipeline_blueprint_toml_to_path-from pipelex.create.validate_blueprint import validate_blueprint+from pipelex.create.validate_blueprint import load_pipes_from_generated_blueprint, validate_loaded_blueprint+from pipelex.exceptions import PipelexCLIError, StaticValidationError, StaticValidationErrorType+from pipelex.hub import get_library_manager, get_required_pipefrom pipelex.libraries.pipeline_blueprint import PipelineBlueprint+from pipelex.pipe_controllers.pipe_controller import PipeControllerfrom pipelex.pipeline.execute import execute_pipelinefrom pipelex.tools.misc.file_utils import save_text_to_pathfrom pipelex.tools.misc.json_utils import save_as_json_to_path@@ -46,7 +49,32 @@ async def do_build_blueprint(save_as_json_to_path(object_to_save=blueprint, path=json_path)draft_path = output_path.replace(Path(output_path).suffix, "_draft.md")save_text_to_path(text=pipeline_draft, path=draft_path)- typer.echo(f"✅ Blueprint saved to '{output_path}'")+ log.info(f"✅ Blueprint saved to '{output_path}'")++ load_pipes_from_generated_blueprint(blueprint=blueprint)+ log.info("✅ Pipes loaded from blueprint")if validate:- await validate_blueprint(blueprint=blueprint)+ try:+ await validate_loaded_blueprint(blueprint=blueprint)+ except StaticValidationError as static_validation_error:+ match static_validation_error.error_type:+ case StaticValidationErrorType.MISSING_INPUT_VARIABLE:+ pipe_code = static_validation_error.pipe_code+ if not pipe_code:+ raise PipelexCLIError(f"No pipe code found for static validation error: {static_validation_error}")+ pipe = get_required_pipe(pipe_code=pipe_code)+ if isinstance(pipe, PipeController):+ log.error(f"❌ Validation failed:\n{static_validation_error}")+ log.error(f"❌ Missing input variable: {static_validation_error.variable_names}")+ log.error(f"❌ Provided concept code: {static_validation_error.provided_concept_code}")+ log.error(f"❌ File path: {static_validation_error.file_path}")+ case _:+ raise static_validation_error+++# def recap_inputs_for_controller_pipes(blueprint: PipelineBlueprint) -> None:+# pipe_codes = list(blueprint.pipe.keys())+# for pipe_code in pipe_codes:+# pipe = get_required_pipe(pipe_code=pipe_code)+# if isinstance(pipe, PipeController):diff --git a/pipelex/create/validate_blueprint.py b/pipelex/create/validate_blueprint.pyindex d9247d51d..6917dd8a7 100644--- a/pipelex/create/validate_blueprint.py+++ b/pipelex/create/validate_blueprint.py@@ -3,33 +3,70 @@ from __future__ import annotationsfrom typing import Any, Dict, castfrom pipelex import log-from pipelex.exceptions import PipeDefinitionError, PipelexCLIError-from pipelex.hub import get_library_manager+from pipelex.exceptions import PipeDefinitionError, PipelexCLIError, StaticValidationError, StaticValidationErrorType+from pipelex.hub import get_library_manager, get_required_pipefrom pipelex.libraries.library_manager import LibraryManagerfrom pipelex.libraries.pipeline_blueprint import PipelineBlueprint+from pipelex.pipe_controllers.pipe_controller import PipeControllerfrom pipelex.pipe_works.pipe_dry import dry_run_pipe_codesasync def validate_blueprint(blueprint: PipelineBlueprint) -> None:# Load pipes from the blueprint+ log.dev("Loading pipes from blueprint")try:- _load_pipes_from_generated_blueprint(blueprint=blueprint)+ load_pipes_from_generated_blueprint(blueprint=blueprint, updates_allowed=True)except PipeDefinitionError as exc:raise PipelexCLIError(f"Failed to load pipes from blueprint for domain '{blueprint.desc}': {exc}") from exc+ # try:+ # await validate_loaded_blueprint(blueprint=blueprint)+ # except StaticValidationError as exc:+ # # raise PipelexCLIError(f"Validation failed:\n{exc}") from exc+ # log.error(f"❌ Validation failed:\n{exc}")++ try:+ await validate_loaded_blueprint(blueprint=blueprint)+ except StaticValidationError as static_validation_error:+ match static_validation_error.error_type:+ case StaticValidationErrorType.MISSING_INPUT_VARIABLE:+ pipe_code = static_validation_error.pipe_code+ if not pipe_code:+ raise PipelexCLIError(f"No pipe code found for static validation error: {static_validation_error}")+ pipe = get_required_pipe(pipe_code=pipe_code)+ if isinstance(pipe, PipeController):+ # log.error(f"❌ Validation failed:\n{static_validation_error}")+ # log.error(f"❌ Missing input variable: {static_validation_error.variable_names}")+ variable_names = static_validation_error.variable_names+ required_concept_codes = static_validation_error.required_concept_codes+ if not variable_names:+ raise PipelexCLIError(f"No variable names found for static validation error: {static_validation_error}")+ if not required_concept_codes:+ raise PipelexCLIError(f"No required concept codes found for static validation error: {static_validation_error}")+ log.error(f"❌ Missing: {variable_names} / concepts: {required_concept_codes}")+ for variable_name, concept_code in zip(variable_names, required_concept_codes):+ if "inputs" not in blueprint.pipe[pipe_code]:+ blueprint.pipe[pipe_code]["inputs"] = {}+ blueprint.pipe[pipe_code]["inputs"][variable_name] = concept_code+ log.info(f"✅ Added: {variable_name} / {concept_code}")+ await validate_blueprint(blueprint=blueprint)+ case _:+ raise static_validation_error+ log.info("✅ Validation passed")+++async def validate_loaded_blueprint(blueprint: PipelineBlueprint) -> None:# Run validation- log.info("Validating pipes ----------------------")- log.info("Validating libraries ----------------------")+ log.dev("Validating blueprint")get_library_manager().validate_libraries()generated_pipe_codes = list(blueprint.pipe.keys())if not generated_pipe_codes:raise PipelexCLIError("No pipe found in blueprint to validate")- log.info(f"Dry running pipes: {generated_pipe_codes}")await dry_run_pipe_codes(pipe_codes=generated_pipe_codes)log.info(f"✅ All pipes validated successfully: {generated_pipe_codes}")-def _load_pipes_from_generated_blueprint(blueprint: PipelineBlueprint) -> None:+def load_pipes_from_generated_blueprint(blueprint: PipelineBlueprint, updates_allowed: bool = False) -> None:"""Instantiate and register all pipes from a generated PipelineBlueprint.This constructs the appropriate typed PipeBlueprint for each pipe entry and@@ -61,4 +98,7 @@ def _load_pipes_from_generated_blueprint(blueprint: PipelineBlueprint) -> None:pipe_code=pipe_code,pipe_blueprint=pipe_blueprint,)- library_manager.pipe_library.add_new_pipe(pipe=pipe)+ if updates_allowed:+ library_manager.pipe_library.add_or_update_pipe(pipe=pipe)+ else:+ library_manager.pipe_library.add_new_pipe(pipe=pipe)diff --git a/pipelex/exceptions.py b/pipelex/exceptions.pyindex 90d70824c..9c9da0009 100644--- a/pipelex/exceptions.py+++ b/pipelex/exceptions.py@@ -25,6 +25,7 @@ class StaticValidationError(Exception):domain_code: str,pipe_code: Optional[str] = None,variable_names: Optional[List[str]] = None,+ required_concept_codes: Optional[List[str]] = None,provided_concept_code: Optional[str] = None,file_path: Optional[str] = None,explanation: Optional[str] = None,@@ -33,6 +34,7 @@ class StaticValidationError(Exception):self.domain_code = domain_codeself.pipe_code = pipe_codeself.variable_names = variable_names+ self.required_concept_codes = required_concept_codesself.provided_concept_code = provided_concept_codeself.file_path = file_pathself.explanation = explanation@@ -44,6 +46,8 @@ class StaticValidationError(Exception):msg += f" • pipe='{self.pipe_code}'"if self.variable_names:msg += f" • variable='{self.variable_names}'"+ if self.required_concept_codes:+ msg += f" • required_concept_codes='{self.required_concept_codes}'"if self.provided_concept_code:msg += f" • provided_concept_code='{self.provided_concept_code}'"if self.file_path:diff --git a/pipelex/pipe_controllers/pipe_sequence.py b/pipelex/pipe_controllers/pipe_sequence.pyindex 752efbfb7..e6a8f85a4 100644--- a/pipelex/pipe_controllers/pipe_sequence.py+++ b/pipelex/pipe_controllers/pipe_sequence.py@@ -102,6 +102,7 @@ class PipeSequence(PipeController):domain_code=self.domain,pipe_code=self.code,variable_names=[named_input_requirement.variable_name],+ required_concept_codes=[named_input_requirement.concept_code],)match reactions.get(StaticValidationErrorType.MISSING_INPUT_VARIABLE, default_reaction):case StaticValidationReaction.IGNORE: