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.

Done rename PipeJinja2

Louis Choquel4c64d95f0be5
diff --git a/pipelex/core/pipes/pipe_blueprint.py b/pipelex/core/pipes/pipe_blueprint.py
index c83e162d9..fc3dbe731 100644
--- a/pipelex/core/pipes/pipe_blueprint.py
+++ b/pipelex/core/pipes/pipe_blueprint.py
@@ -22,7 +22,7 @@ class AllowedPipeTypes(StrEnum):
# Pipe Operators
PIPE_FUNC = "PipeFunc"
PIPE_IMG_GEN = "PipeImgGen"
- PIPE_JINJA2 = "PipeCompose"
+ PIPE_COMPOSE = "PipeCompose"
PIPE_LLM = "PipeLLM"
PIPE_OCR = "PipeOcr"
# Pipe Controller
diff --git a/pipelex/pipe_controllers/condition/pipe_condition.py b/pipelex/pipe_controllers/condition/pipe_condition.py
index a4ee5ce46..7905e8c35 100644
--- a/pipelex/pipe_controllers/condition/pipe_condition.py
+++ b/pipelex/pipe_controllers/condition/pipe_condition.py
@@ -1,4 +1,4 @@
-from typing import TYPE_CHECKING, Literal, cast
+from typing import Literal
import shortuuid
from pydantic import field_validator, model_validator
@@ -28,7 +28,6 @@ from pipelex.exceptions import (
from pipelex.hub import get_pipe_router, get_pipeline_tracker, get_required_pipe
from pipelex.pipe_controllers.condition.pipe_condition_details import PipeConditionDetails, PipeConditionPipeMap
from pipelex.pipe_controllers.pipe_controller import PipeController
-from pipelex.pipe_operators.compose.pipe_compose import PipeComposeOutput
from pipelex.pipe_operators.compose.pipe_compose_blueprint import PipeComposeBlueprint
from pipelex.pipe_operators.compose.pipe_compose_factory import PipeComposeFactory
from pipelex.pipe_works.pipe_job_factory import PipeJobFactory
@@ -36,9 +35,6 @@ from pipelex.pipeline.job_metadata import JobCategory, JobMetadata
from pipelex.tools.typing.validation_utils import has_exactly_one_among_attributes_from_list
from pipelex.types import Self
-if TYPE_CHECKING:
- from pipelex.pipe_operators.compose.pipe_compose import PipeComposeOutput
-
class PipeCondition(PipeController):
type: Literal["PipeCondition"] = "PipeCondition"
@@ -130,13 +126,14 @@ class PipeCondition(PipeController):
@override
def required_variables(self) -> set[str]:
required_variables: set[str] = set()
+ # TODO: use jinja2 directly without going though a pipe
# Variables from the expression/expression_template
- pipe_jinja2 = PipeComposeFactory.make_pipe_compose_from_template_str(
+ pipe_compose = PipeComposeFactory.make_pipe_compose_from_template_str(
domain=self.domain,
template_str=self.applied_expression_template,
inputs=self.inputs,
)
- required_variables.update(pipe_jinja2.required_variables())
+ required_variables.update(pipe_compose.required_variables())
# Variables from the pipe_map
for pipe_code in self.pipe_dependencies():
@@ -165,13 +162,13 @@ class PipeCondition(PipeController):
needed_inputs = PipeInputSpecFactory.make_empty()
# 1. Add the variables from the expression/expression_template
- pipe_jinja2 = PipeComposeFactory.make_pipe_compose_from_template_str(
+ pipe_compose = PipeComposeFactory.make_pipe_compose_from_template_str(
domain=self.domain,
template_str=self.applied_expression_template,
inputs=self.inputs,
)
- for var_name in pipe_jinja2.required_variables():
+ for var_name in pipe_compose.required_variables():
if not var_name.startswith("_"): # exclude internal variables starting with `_`
# We don't know the concept code from just the variable name,
# so we'll use a generic placeholder that will be validated later
@@ -285,7 +282,7 @@ class PipeCondition(PipeController):
multiplicity=requirement.multiplicity,
)
- pipe_jinja2_blueprint = PipeComposeBlueprint(
+ pipe_compose_blueprint = PipeComposeBlueprint(
definition="Jinja2 template for pipe condition evaluation",
jinja2=self.applied_expression_template,
inputs=inputs_blueprint,
@@ -293,10 +290,10 @@ class PipeCondition(PipeController):
)
# TODO: use jinja2 directly without going though a pipe
- pipe_jinja2 = PipeComposeFactory.make_from_blueprint(
+ pipe_compose = PipeComposeFactory.make_from_blueprint(
domain=self.domain,
pipe_code="evaluation_for_pipe_condition",
- blueprint=pipe_jinja2_blueprint,
+ blueprint=pipe_compose_blueprint,
)
jinja2_job_metadata = job_metadata.copy_with_update(
updated_metadata=JobMetadata(
@@ -304,23 +301,13 @@ class PipeCondition(PipeController):
),
)
log.debug(f"Jinja2 expression: {self.applied_expression_template}")
- # evaluated_expression = (
- # await pipe_jinja2.run_pipe(
- # job_metadata=jinja2_job_metadata,
- # working_memory=working_memory,
- # pipe_run_params=pipe_run_params,
- # )
- # ).rendered_text.strip()
- # TODO: restore the possibility above, without need to explicitly cast the output
- pipe_jinja2_output = cast(
- "PipeComposeOutput",
- await pipe_jinja2.run_pipe(
+ evaluated_expression = (
+ await pipe_compose.run_pipe(
job_metadata=jinja2_job_metadata,
working_memory=working_memory,
pipe_run_params=pipe_run_params,
- ),
- )
- evaluated_expression = pipe_jinja2_output.rendered_text.strip()
+ )
+ ).main_stuff_as_str.strip()
if not evaluated_expression or evaluated_expression == "None":
error_msg = f"Conditional expression returned an empty string in pipe {self.code}:"
@@ -356,7 +343,7 @@ class PipeCondition(PipeController):
evaluated_expression=evaluated_expression,
chosen_pipe_code=chosen_pipe_code,
)
- required_variables = pipe_jinja2.required_variables()
+ required_variables = pipe_compose.required_variables()
log.debug(required_variables, title=f"Required variables for PipeCondition '{self.code}'")
required_stuff_names = {required_variable for required_variable in required_variables if not required_variable.startswith("_")}
try:
@@ -426,13 +413,13 @@ class PipeCondition(PipeController):
# 2. Validate that the expression template is valid
try:
- pipe_jinja2 = PipeComposeFactory.make_pipe_compose_from_template_str(
+ pipe_compose = PipeComposeFactory.make_pipe_compose_from_template_str(
domain=self.domain,
template_str=self.applied_expression_template,
inputs=self.inputs,
)
# Get required variables to validate the template syntax
- required_variables = pipe_jinja2.required_variables()
+ required_variables = pipe_compose.required_variables()
log.debug(f"Expression template is valid, requires variables: {required_variables}")
except Exception as exc:
log.error(f"Dry run failed: invalid expression template: {exc}")
diff --git a/pipelex/pipe_operators/compose/pipe_compose.py b/pipelex/pipe_operators/compose/pipe_compose.py
index 2b974e922..7d5399fe6 100644
--- a/pipelex/pipe_operators/compose/pipe_compose.py
+++ b/pipelex/pipe_operators/compose/pipe_compose.py
@@ -33,9 +33,7 @@ from pipelex.types import Self
class PipeComposeOutput(PipeOutput):
- @property
- def rendered_text(self) -> str:
- return self.main_stuff_as_text.text
+ pass
class PipeCompose(PipeOperator[PipeComposeOutput]):
diff --git a/pipelex/pipe_operators/compose/pipe_compose_factory.py b/pipelex/pipe_operators/compose/pipe_compose_factory.py
index 691d18009..4dc329138 100644
--- a/pipelex/pipe_operators/compose/pipe_compose_factory.py
+++ b/pipelex/pipe_operators/compose/pipe_compose_factory.py
@@ -76,16 +76,17 @@ class PipeComposeFactory(PipeFactoryProtocol[PipeComposeBlueprint, PipeCompose])
)
return PipeCompose(
domain=domain,
- code="adhoc_pipe_jinja2_from_template_str",
+ code="adhoc_pipe_compose_from_template_str",
jinja2=preprocessed_template,
inputs=inputs or PipeInputSpecFactory.make_empty(),
)
- if template_name:
+ elif template_name:
return PipeCompose(
domain=domain,
- code="adhoc_pipe_jinja2_from_template_name",
+ code="adhoc_pipe_compose_from_template_name",
jinja2_name=template_name,
inputs=inputs or PipeInputSpecFactory.make_empty(),
)
- msg = "Either template_str or template_name must be provided to make_pipe_jinja2_from_template_str"
- raise PipeDefinitionError(msg)
+ else:
+ msg = "Could not make a PipeCompose because neither template_str nor template_name were provided"
+ raise PipeDefinitionError(msg)
diff --git a/tests/integration/pipelex/pipes/test_pipe_jinja2.py b/tests/integration/pipelex/pipes/test_pipe_compose.py
similarity index 73%
rename from tests/integration/pipelex/pipes/test_pipe_jinja2.py
rename to tests/integration/pipelex/pipes/test_pipe_compose.py
index 28ba3d5b4..7e34aa303 100644
--- a/tests/integration/pipelex/pipes/test_pipe_jinja2.py
+++ b/tests/integration/pipelex/pipes/test_pipe_compose.py
@@ -20,39 +20,39 @@ from tests.cases import JINJA2TestCases
@pytest.mark.asyncio(loop_scope="class")
class TestPipeCompose:
@pytest.mark.parametrize("jinja2", JINJA2TestCases.JINJA2_FOR_ANY)
- async def test_pipe_jinja2_for_any(
+ async def test_pipe_compose_for_any(
self,
pipe_run_mode: PipeRunMode,
jinja2: str,
):
- pipe_jinja2_blueprint = PipeComposeBlueprint(
+ pipe_compose_blueprint = PipeComposeBlueprint(
definition="Jinja2 test for any context",
jinja2=jinja2,
output=NativeConceptEnum.TEXT,
- extra_context={"place_holder": "[some text from test_pipe_jinja2_for_any]"},
+ extra_context={"place_holder": "[some text from test_pipe_compose_for_any]"},
)
pipe_job = PipeJobFactory.make_pipe_job(
pipe=PipeComposeFactory.make_from_blueprint(
domain="generic",
- pipe_code="adhoc_for_test_pipe_jinja2_for_any",
- blueprint=pipe_jinja2_blueprint,
+ pipe_code="adhoc_for_test_pipe_compose_for_any",
+ blueprint=pipe_compose_blueprint,
),
pipe_run_params=PipeRunParamsFactory.make_run_params(pipe_run_mode=pipe_run_mode),
)
- pipe_jinja2_output = cast(PipeComposeOutput, await get_pipe_router().run(pipe_job=pipe_job))
- rendered_text = pipe_jinja2_output.rendered_text
+ pipe_compose_output = cast(PipeComposeOutput, await get_pipe_router().run(pipe_job=pipe_job))
+ rendered_text = pipe_compose_output.main_stuff_as_str
pretty_print(rendered_text)
@pytest.mark.parametrize("jinja2", JINJA2TestCases.JINJA2_FOR_STUFF)
- async def test_pipe_jinja2_for_stuff(
+ async def test_pipe_compose_for_stuff(
self,
pipe_run_mode: PipeRunMode,
jinja2: str,
):
- working_memory = WorkingMemoryFactory.make_from_text(text="[some text from test_pipe_jinja2_for_stuff]", name="place_holder")
+ working_memory = WorkingMemoryFactory.make_from_text(text="[some text from test_pipe_compose_for_stuff]", name="place_holder")
- pipe_jinja2_blueprint = PipeComposeBlueprint(
+ pipe_compose_blueprint = PipeComposeBlueprint(
definition="Jinja2 test for stuff context",
jinja2=jinja2,
prompting_style=PromptingStyle(tag_style=TagStyle.TICKS, text_format=TextFormat.MARKDOWN),
@@ -62,12 +62,12 @@ class TestPipeCompose:
pipe_job = PipeJobFactory.make_pipe_job(
pipe=PipeComposeFactory.make_from_blueprint(
domain="generic",
- pipe_code="adhoc_for_test_pipe_jinja2",
- blueprint=pipe_jinja2_blueprint,
+ pipe_code="adhoc_for_test_pipe_compose",
+ blueprint=pipe_compose_blueprint,
),
pipe_run_params=PipeRunParamsFactory.make_run_params(pipe_run_mode=pipe_run_mode),
working_memory=working_memory,
)
- pipe_jinja2_output = cast(PipeComposeOutput, await get_pipe_router().run(pipe_job=pipe_job))
- rendered_text = pipe_jinja2_output.rendered_text
+ pipe_compose_output = cast(PipeComposeOutput, await get_pipe_router().run(pipe_job=pipe_job))
+ rendered_text = pipe_compose_output.main_stuff_as_str
pretty_print(rendered_text)
diff --git a/tests/unit/pipelex/core/test_data/__init__.py b/tests/unit/pipelex/core/test_data/__init__.py
index 1df3bcca0..ac9101a9f 100644
--- a/tests/unit/pipelex/core/test_data/__init__.py
+++ b/tests/unit/pipelex/core/test_data/__init__.py
@@ -14,7 +14,7 @@ from .pipes.controllers.parallel.pipe_parallel import PIPE_PARALLEL_TEST_CASES
from .pipes.controllers.sequence.pipe_sequence import PIPE_SEQUENCE_TEST_CASES
from .pipes.operators.func.pipe_func import PIPE_FUNC_TEST_CASES
from .pipes.operators.img_gen.pipe_img_gen import PIPE_IMG_GEN_TEST_CASES
-from .pipes.operators.jinja2.pipe_jinja2 import PIPE_JINJA2_TEST_CASES
+from .pipes.operators.compose.pipe_compose import PIPE_COMPOSE_TEST_CASES
from .pipes.operators.llm.pipe_llm import PIPE_LLM_TEST_CASES
from .pipes.operators.ocr.pipe_ocr import PIPE_OCR_TEST_CASES
@@ -35,7 +35,7 @@ class InterpreterTestCases:
*PIPE_OCR_TEST_CASES,
*PIPE_FUNC_TEST_CASES,
*PIPE_IMG_GEN_TEST_CASES,
- *PIPE_JINJA2_TEST_CASES,
+ *PIPE_COMPOSE_TEST_CASES,
# Pipe controller tests
*PIPE_SEQUENCE_TEST_CASES,
*PIPE_CONDITION_TEST_CASES,
diff --git a/tests/unit/pipelex/core/test_data/pipes/operators/jinja2/__init__.py b/tests/unit/pipelex/core/test_data/pipes/operators/compose/__init__.py
similarity index 100%
rename from tests/unit/pipelex/core/test_data/pipes/operators/jinja2/__init__.py
rename to tests/unit/pipelex/core/test_data/pipes/operators/compose/__init__.py
diff --git a/tests/unit/pipelex/core/test_data/pipes/operators/jinja2/pipe_jinja2.py b/tests/unit/pipelex/core/test_data/pipes/operators/compose/pipe_compose.py
similarity index 92%
rename from tests/unit/pipelex/core/test_data/pipes/operators/jinja2/pipe_jinja2.py
rename to tests/unit/pipelex/core/test_data/pipes/operators/compose/pipe_compose.py
index 407e54dda..a097edae4 100644
--- a/tests/unit/pipelex/core/test_data/pipes/operators/jinja2/pipe_jinja2.py
+++ b/tests/unit/pipelex/core/test_data/pipes/operators/compose/pipe_compose.py
@@ -3,8 +3,8 @@ from pipelex.core.concepts.concept_native import NativeConceptEnum
from pipelex.pipe_operators.compose.pipe_compose_blueprint import PipeComposeBlueprint
from pipelex.tools.templating.jinja2_template_category import Jinja2TemplateCategory
-PIPE_JINJA2 = (
- "pipe_jinja2",
+PIPE_COMPOSE = (
+ "pipe_compose",
"""domain = "test_pipes"
definition = "Domain with template processing pipe"
@@ -31,6 +31,6 @@ template_category = "markdown"
)
# Export all PipeCompose test cases
-PIPE_JINJA2_TEST_CASES = [
- PIPE_JINJA2,
+PIPE_COMPOSE_TEST_CASES = [
+ PIPE_COMPOSE,
]
diff --git a/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operators/pipe_jinja2/test_pipe_jinja2.py b/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operators/pipe_jinja2/test_pipe_jinja2.py
index 421b52d87..cf72ba612 100644
--- a/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operators/pipe_jinja2/test_pipe_jinja2.py
+++ b/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operators/pipe_jinja2/test_pipe_jinja2.py
@@ -11,7 +11,7 @@ class TestPipeComposeBlueprintConversion:
"test_name,pipe_spec,expected_blueprint",
PipeComposeTestCases.TEST_CASES,
)
- def test_pipe_jinja2_spec_to_blueprint(
+ def test_pipe_compose_spec_to_blueprint(
self,
test_name: str,
pipe_spec: PipeComposeSpec,