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.
Improve builder CLI
Louis Choquel4efbcb5e6011
diff --git a/pipelex/cli/commands/build_cmd.py b/pipelex/cli/commands/build_cmd.pyindex 66e70c02a..617dc0339 100644--- a/pipelex/cli/commands/build_cmd.py+++ b/pipelex/cli/commands/build_cmd.py@@ -9,6 +9,7 @@ from pipelex.hub import get_report_delegatefrom pipelex.libraries.pipelines.builder.builder import PipelexBundleSpecfrom pipelex.pipelex import Pipelexfrom pipelex.pipeline.execute import execute_pipeline+from pipelex.tools.misc.file_utils import ensure_directory_for_file_path, save_text_to_pathfrom pipelex.tools.plx.plx_utils import make_plx_contentbuild_app = typer.Typer(help="Build artifacts like pipelines", no_args_is_help=True)@@ -30,9 +31,13 @@ def build_pipe_cmd(typer.Argument(help="Brief description of what the pipeline should do"),],output_path: Annotated[- str | None,- typer.Option("--output", "-o", help="Path to save the generated PLX file (use --output='' to skip saving)"),+ str,+ typer.Option("--output", "-o", help="Path to save the generated PLX file"),] = "./results/generated_pipeline.plx",+ no_output: Annotated[+ bool,+ typer.Option("--no-output", help="Skip saving the pipeline to file"),+ ] = False,) -> None:Pipelex.make(relative_config_folder_path="../../../pipelex/libraries", from_file=True)typer.echo("=" * 70)@@ -40,6 +45,15 @@ def build_pipe_cmd(typer.echo("")async def run_pipeline():+ if not no_output:+ if not output_path:+ typer.echo(typer.style("\n⚠️ Cannot save a pipeline to an empty file name", fg=typer.colors.RED))+ raise typer.Exit(1)++ ensure_directory_for_file_path(file_path=output_path)+ else:+ typer.echo(typer.style("\n⚠️ Pipeline will not be saved to file (--no-output specified)", fg=typer.colors.YELLOW))+pipe_output = await execute_pipeline(pipe_code="pipe_builder",input_memory={"brief": brief},@@ -48,13 +62,12 @@ def build_pipe_cmd(pipelex_bundle_spec = pipe_output.working_memory.get_stuff_as(name="pipelex_bundle_spec", content_type=PipelexBundleSpec)plx_content = make_plx_content(blueprint=pipelex_bundle_spec.to_blueprint())- # Save to file unless explicitly disabled with empty string- if output_path and output_path != "":- with open(output_path, "w") as f:- f.write(plx_content)+ # Save to file unless explicitly disabled with --no-output+ if not no_output:+ save_text_to_path(text=plx_content, path=output_path)typer.echo(typer.style(f"\n✅ Pipeline saved to: {output_path}", fg=typer.colors.GREEN))- elif output_path == "":- typer.echo(typer.style("\n⚠️ Pipeline not saved to file (--output='' specified)", fg=typer.colors.YELLOW))+ else:+ typer.echo(typer.style("\n⚠️ Pipeline not saved to file (--no-output specified)", fg=typer.colors.YELLOW))start_time = time.time()asyncio.run(run_pipeline())diff --git a/pipelex/cli/commands/your-pipe.plx b/pipelex/cli/commands/your-pipe.plxdeleted file mode 100644index e69de29bb..000000000diff --git a/pipelex/tools/misc/file_utils.py b/pipelex/tools/misc/file_utils.pyindex 2aa7e5a09..d5fe8e29a 100644--- a/pipelex/tools/misc/file_utils.py+++ b/pipelex/tools/misc/file_utils.py@@ -251,6 +251,15 @@ def ensure_path(path: str) -> bool:return True+def ensure_directory_for_file_path(file_path: str) -> None:+ """Ensures a directory exists for the specified file path.++ Args:+ file_path (str): The path to the file.+ """+ ensure_directory_exists(os.path.dirname(file_path))++def path_exists(path_str: str) -> bool:"""Checks if a file or directory exists at the specified path.diff --git a/pipelex/tools/plx/plx_utils.py b/pipelex/tools/plx/plx_utils.pyindex 13c82ec5b..dada4481c 100644--- a/pipelex/tools/plx/plx_utils.py+++ b/pipelex/tools/plx/plx_utils.py@@ -31,11 +31,6 @@ PIPE_FIELD_ORDERING: FieldOrdering = ["definition","inputs","output",- # "jinja2",- # "jinja2_name",- # "prompting_style",- # "template_category",- # "extra_context",]STRUCTURE_FIELD_ORDERING: FieldOrdering = ["type", "definition", "choices", "required"]@@ -143,6 +138,7 @@ def _convert_mapping_to_table(mapping: Mapping[str, Any], field_ordering: FieldOreturn tbl+# TODO: replace this by a proper toml formatter utilitydef _add_spaces_to_inline_tables(toml_string: str) -> str:"""Add spaces inside inline table curly braces.diff --git a/tests/unit/pipelex/core/test_data/__init__.py b/tests/unit/pipelex/core/test_data/__init__.pyindex 995f06715..458c87257 100644--- a/tests/unit/pipelex/core/test_data/__init__.py+++ b/tests/unit/pipelex/core/test_data/__init__.py@@ -40,9 +40,9 @@ class InterpreterTestCases:*PIPE_SEQUENCE_TEST_CASES,*PIPE_CONDITION_TEST_CASES,*PIPE_PARALLEL_TEST_CASES,- # *PIPE_BATCH_TEST_CASES,- # # Complex tests- # *COMPLEX_TEST_CASES,+ *PIPE_BATCH_TEST_CASES,+ # Complex tests+ *COMPLEX_TEST_CASES,]# Error test cases