Skip to content

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.

In PipeSpec, made inputs required, can be empty but not None Fixed choice of model to llm = "llm_to_engineer"

Louis Choquela05b13a8fd37
diff --git a/pipelex/libraries/pipelines/builder/builder.plx b/pipelex/libraries/pipelines/builder/builder.plx
index 993e16703..b1562f705 100644
--- a/pipelex/libraries/pipelines/builder/builder.plx
+++ b/pipelex/libraries/pipelines/builder/builder.plx
@@ -36,6 +36,7 @@ type = "PipeLLM"
description = "Turn the brief into a DomainInformation object."
inputs = { brief = "UserBrief" }
output = "DomainInformation"
+llm = "llm_to_engineer"
prompt_template = """
Name and define the domain of this process:
@brief
diff --git a/pipelex/libraries/pipelines/builder/builder.py b/pipelex/libraries/pipelines/builder/builder.py
index c57f5f3e9..38d48245c 100644
--- a/pipelex/libraries/pipelines/builder/builder.py
+++ b/pipelex/libraries/pipelines/builder/builder.py
@@ -302,6 +302,18 @@ async def validate_bundle_spec(pipelex_bundle_spec: PipelexBundleSpec):
dry_run_result = await dry_run_pipes(pipes=pipes, raise_on_failure=False)
library_manager.remove_from_blueprint(blueprint=pipelex_bundle_blueprint)
+ pipe_type_to_spec_class = {
+ "PipeFunc": PipeFuncSpec,
+ "PipeImgGen": PipeImgGenSpec,
+ "PipeCompose": PipeComposeSpec,
+ "PipeLLM": PipeLLMSpec,
+ "PipeOcr": PipeOcrSpec,
+ "PipeBatch": PipeBatchSpec,
+ "PipeCondition": PipeConditionSpec,
+ "PipeParallel": PipeParallelSpec,
+ "PipeSequence": PipeSequenceSpec,
+ }
+
dry_run_pipe_failures: list[PipeFailure] = []
for pipe_code, dry_run_output in dry_run_result.items():
if dry_run_output.status.is_failure:
@@ -312,33 +324,33 @@ async def validate_bundle_spec(pipelex_bundle_spec: PipelexBundleSpec):
msg = f"Pipe '{pipe_code}' not found in bundle spec but we recorded a dry run failure for it"
raise PipelexBundleUnexpectedError(message=msg)
- failing_pipe_spec = pipelex_bundle_spec.pipe[pipe_code]
- pipe_spec_type_name = failing_pipe_spec.type
- pipe_spec_class_name = pipe_spec_type_name + "Spec"
- spec_class = get_class_registry().get_class(name=pipe_spec_class_name)
+ pipe_spec = pipelex_bundle_spec.pipe[pipe_code]
+ spec_class = pipe_type_to_spec_class.get(pipe_spec.type)
if not spec_class:
- msg = f"Unknown pipe spec class: {pipe_spec_class_name}"
- raise PipelexBundleUnexpectedError(message=msg)
- pipe_spec = spec_class.model_validate(obj=failing_pipe_spec.model_dump(serialize_as_any=True))
- dry_run_pipe_failures.append(
- PipeFailure(
- pipe_spec=pipe_spec,
- error_message=dry_run_output.error_message or "",
- ),
+ msg = f"Unknown pipe type: {pipe_spec.type}"
+ raise ValidateDryRunError(msg)
+ pipe_spec = spec_class(**pipe_spec.model_dump(serialize_as_any=True))
+ pipe_failure = PipeFailure(
+ pipe_spec=pipe_spec,
+ error_message=dry_run_output.error_message or "",
)
+ dry_run_pipe_failures.append(pipe_failure)
if dry_run_pipe_failures:
raise PipelexBundleError(message="Pipes failed during dry run", pipe_failures=dry_run_pipe_failures)
-async def reconstruct_bundle_with_pipe_fixes(working_memory: WorkingMemory) -> PipelexBundleSpec:
+async def reconstruct_bundle_with_pipe_fixes_from_memory(working_memory: WorkingMemory) -> PipelexBundleSpec:
pipelex_bundle_spec = working_memory.get_stuff_as(name="pipelex_bundle_spec", content_type=PipelexBundleSpec)
fixed_pipes_list = cast("ListContent[PipeSpecUnion]", working_memory.get_stuff(name="fixed_pipes").content)
+ return await reconstruct_bundle_with_pipe_fixes(pipelex_bundle_spec=pipelex_bundle_spec, fixed_pipes=fixed_pipes_list.items)
+
+async def reconstruct_bundle_with_pipe_fixes(pipelex_bundle_spec: PipelexBundleSpec, fixed_pipes: list[PipeSpecUnion]) -> PipelexBundleSpec:
if not pipelex_bundle_spec.pipe:
msg = "No pipes section found in bundle spec"
raise PipeBuilderError(msg)
- for fixed_pipe_blueprint in fixed_pipes_list.items:
+ for fixed_pipe_blueprint in fixed_pipes:
pipe_code = fixed_pipe_blueprint.the_pipe_code
pipelex_bundle_spec.pipe[pipe_code] = fixed_pipe_blueprint
diff --git a/pipelex/libraries/pipelines/builder/builder_loop.py b/pipelex/libraries/pipelines/builder/builder_loop.py
index c32a7c420..2c586a9cc 100644
--- a/pipelex/libraries/pipelines/builder/builder_loop.py
+++ b/pipelex/libraries/pipelines/builder/builder_loop.py
@@ -1,7 +1,13 @@
from pipelex import pretty_print
from pipelex.client.protocol import ImplicitMemory
from pipelex.language.plx_factory import PlxFactory
-from pipelex.libraries.pipelines.builder.builder import PipelexBundleSpec, validate_bundle_spec
+from pipelex.libraries.pipelines.builder.builder import (
+ PipelexBundleError,
+ PipelexBundleSpec,
+ PipeSpecUnion,
+ reconstruct_bundle_with_pipe_fixes,
+ validate_bundle_spec,
+)
from pipelex.pipeline.execute import execute_pipeline
from pipelex.tools.misc.file_utils import save_text_to_path
@@ -20,6 +26,16 @@ class BuilderLoop:
plx_content = PlxFactory.make_plx_content(blueprint=pipelex_bundle_spec.to_blueprint())
save_text_to_path(text=plx_content, path="results/generated_pipeline_1st_iteration.plx")
- await validate_bundle_spec(pipelex_bundle_spec=pipelex_bundle_spec)
+ try:
+ await validate_bundle_spec(pipelex_bundle_spec=pipelex_bundle_spec)
+ except PipelexBundleError as exc:
+ pretty_print(exc, title="Pipelex Bundle Error")
+
+ fixed_pipes: list[PipeSpecUnion] = []
+ # TODO: fixe the pipes)
+ pipelex_bundle_spec = await reconstruct_bundle_with_pipe_fixes(pipelex_bundle_spec=pipelex_bundle_spec, fixed_pipes=fixed_pipes)
+ # pretty_print(pipelex_bundle_spec, title="Pipelex Bundle Spec • 2nd iteration")
+ # plx_content = PlxFactory.make_plx_content(blueprint=pipelex_bundle_spec.to_blueprint())
+ # save_text_to_path(text=plx_content, path="results/generated_pipeline_2nd_iteration.plx")
return pipelex_bundle_spec
diff --git a/pipelex/libraries/pipelines/builder/pipe/pipe_design.plx b/pipelex/libraries/pipelines/builder/pipe/pipe_design.plx
index 096fc539b..92f3dc2ab 100644
--- a/pipelex/libraries/pipelines/builder/pipe/pipe_design.plx
+++ b/pipelex/libraries/pipelines/builder/pipe/pipe_design.plx
@@ -133,6 +133,7 @@ type = "PipeLLM"
description = "Build a PipeImgGenSpec from the signature."
inputs = { plan_draft = "PlanDraft", pipe_signature = "PipeSignature", concept_specs = "concept.ConceptSpec" }
output = "PipeImgGenSpec"
+llm = "llm_to_engineer"
prompt_template = """
Your job is to design a PipeImgGenSpec to generate an image from a text prompt.
@@ -150,6 +151,7 @@ type = "PipeLLM"
description = "Build a PipeComposeSpec from the signature."
inputs = { plan_draft = "PlanDraft", pipe_signature = "PipeSignature", concept_specs = "concept.ConceptSpec" }
output = "PipeComposeSpec"
+llm = "llm_to_engineer"
prompt_template = """
Your job is to design a PipeComposeSpec to render a jinja2 template.
diff --git a/pipelex/libraries/pipelines/builder/pipe/pipe_signature.py b/pipelex/libraries/pipelines/builder/pipe/pipe_signature.py
index da7c2303e..423255469 100644
--- a/pipelex/libraries/pipelines/builder/pipe/pipe_signature.py
+++ b/pipelex/libraries/pipelines/builder/pipe/pipe_signature.py
@@ -40,7 +40,7 @@ class PipeSpec(StructuredContent):
description=f"Pipe category. It is defined with type `Any` but validated at runtime and it must be one of: {AllowedPipeCategories}"
)
definition: str | None = Field(description="Natural language description of what the pipe does.")
- inputs: dict[str, str] | None = Field(
+ inputs: dict[str, str] = Field(
description=("Input concept specifications. The keys are input names in snake_case. Each value must be a ConceptCode in PascalCase"),
)
output: str = Field(description="Output concept code in PascalCase format!! Very important")
@@ -79,8 +79,10 @@ class PipeSpec(StructuredContent):
return pipe_code
def to_blueprint(self) -> PipeBlueprint:
- converted_inputs: dict[str, str | InputRequirementBlueprint] | None = None
- if self.inputs is not None:
+ converted_inputs: dict[str, str | InputRequirementBlueprint] | None
+ if not self.inputs:
+ converted_inputs = None
+ else:
converted_inputs = {}
for input_name, concept_code in self.inputs.items():
converted_inputs[input_name] = InputRequirementBlueprint(concept=concept_code)
diff --git a/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operators/pipe_func/test_data.py b/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operators/pipe_func/test_data.py
index b36e3f526..32a365675 100644
--- a/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operators/pipe_func/test_data.py
+++ b/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operators/pipe_func/test_data.py
@@ -31,7 +31,7 @@ class PipeFuncTestCases:
PipeFuncSpec(
the_pipe_code="generator_func",
definition="Generate data",
- inputs=None,
+ inputs={},
output="GeneratedData",
function_name="generate_data",
),
diff --git a/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operators/pipe_img/test_data.py b/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operators/pipe_img/test_data.py
index ae4aebb48..8405376dd 100644
--- a/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operators/pipe_img/test_data.py
+++ b/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operators/pipe_img/test_data.py
@@ -13,7 +13,7 @@ class PipeImgGenTestCases:
PipeImgGenSpec(
the_pipe_code="img_generator",
definition="Generate an image",
- inputs=None,
+ inputs={},
output="GeneratedImage",
),
PipeImgGenBlueprint(
diff --git a/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operators/pipe_llm/test_data.py b/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operators/pipe_llm/test_data.py
index 681918225..c0bc716ba 100644
--- a/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operators/pipe_llm/test_data.py
+++ b/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operators/pipe_llm/test_data.py
@@ -34,7 +34,7 @@ class PipeLLMTestCases:
PipeLLMSpec(
the_pipe_code="generate_pipe",
definition="Generate without inputs",
- inputs=None,
+ inputs={},
output="Text",
llm="llm_for_creative_writing",
prompt_template="Generate something interesting",
@@ -54,7 +54,7 @@ class PipeLLMTestCases:
PipeLLMSpec(
the_pipe_code="generate",
definition="Generate with preset",
- inputs=None,
+ inputs={},
output="Text",
prompt_template="Generate text",
llm="llm_to_reason",
@@ -74,7 +74,7 @@ class PipeLLMTestCases:
PipeLLMSpec(
the_pipe_code="generate",
definition="Generate with settings",
- inputs=None,
+ inputs={},
output="Text",
prompt_template="Generate text",
llm="llm_cheap_for_easy_questions",
@@ -122,7 +122,7 @@ class PipeLLMTestCases:
PipeLLMSpec(
the_pipe_code="generate_items",
definition="Generate multiple items",
- inputs=None,
+ inputs={},
output="Item",
prompt_template="Generate items",
multiple_output=True,
@@ -145,7 +145,7 @@ class PipeLLMTestCases:
PipeLLMSpec(
the_pipe_code="generate_items",
definition="Generate exactly 5 items",
- inputs=None,
+ inputs={},
output="Item",
prompt_template="Generate items",
nb_output=5,
diff --git a/tests/unit/pipelex/libraries/pipelines/builder/pipe/test_data_pipe.py b/tests/unit/pipelex/libraries/pipelines/builder/pipe/test_data_pipe.py
index 8ce6104db..38f1f43ec 100644
--- a/tests/unit/pipelex/libraries/pipelines/builder/pipe/test_data_pipe.py
+++ b/tests/unit/pipelex/libraries/pipelines/builder/pipe/test_data_pipe.py
@@ -55,7 +55,7 @@ class PipeBlueprintTestCases:
type="PipeFunc",
category="PipeOperator",
definition="Pipe without inputs",
- inputs=None,
+ inputs={},
output="GeneratedData",
),
PipeBlueprint(