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.
Fix prompt fro structuring DIRECT (no preliminary text)
Louis Choquel7d2bad0d8bf7
diff --git a/pipelex/core/pipe_run_params.py b/pipelex/core/pipe_run_params.pyindex da680fe4e..7c93ee3c2 100644--- a/pipelex/core/pipe_run_params.py+++ b/pipelex/core/pipe_run_params.py@@ -111,6 +111,7 @@ class BatchParams(BaseModel):class PipeRunParams(BaseModel):run_mode: PipeRunMode = PipeRunMode.LIVEfinal_stuff_code: Optional[str] = None+ is_with_preliminary_text: Optional[bool] = Noneoutput_multiplicity: Optional[PipeOutputMultiplicity] = Nonedynamic_output_concept_code: Optional[str] = Nonebatch_params: Optional[BatchParams] = None@@ -139,6 +140,7 @@ class PipeRunParams(BaseModel):cls,pipe_run_params: Self,applied_output_multiplicity: Optional[PipeOutputMultiplicity],+ is_with_preliminary_text: Optional[bool] = None,) -> Self:"""Copy the run params the nb_output into the params, and remove the attribute.@@ -152,6 +154,8 @@ class PipeRunParams(BaseModel):elif isinstance(applied_output_multiplicity, int):new_run_params.output_multiplicity = Falsenew_run_params.params[PipeRunParamKey.NB_OUTPUT] = applied_output_multiplicity+ if is_with_preliminary_text is not None:+ new_run_params.is_with_preliminary_text = is_with_preliminary_textreturn new_run_params@propertydiff --git a/pipelex/libraries/llm_deck/base_llm_deck.toml b/pipelex/libraries/llm_deck/base_llm_deck.tomlindex 1c9271aeb..12e3a52dd 100644--- a/pipelex/libraries/llm_deck/base_llm_deck.toml+++ b/pipelex/libraries/llm_deck/base_llm_deck.toml@@ -56,6 +56,7 @@ llm_for_question_and_excerpt_reformulation = { llm_handle = "gpt-4o", temperatur# Engineering skillsllm_to_engineer = { llm_handle = "best-claude", temperature = 0.5 }+llm_to_pipelex = { llm_handle = "gpt-5-mini", temperature = 0.5 }# Image skillsllm_to_write_imgg_prompt = { llm_handle = "best-claude", temperature = 0.2 }diff --git a/pipelex/libraries/pipelines/meta/meta_pipeline.toml b/pipelex/libraries/pipelines/meta/meta_pipeline.tomlindex 1d443e2b7..d8396250e 100644--- a/pipelex/libraries/pipelines/meta/meta_pipeline.toml+++ b/pipelex/libraries/pipelines/meta/meta_pipeline.toml@@ -16,7 +16,7 @@ type = "PipeLLM"definition = "Generate a rough pipeline draft from natural language requirements"inputs = { rules = "Text", requirements = "Text", pipeline_name = "Text" }output = "PipelineDraftText"-llm = "llm_to_engineer"+llm = "llm_to_pipelex"prompt_template = """You are a Pipelex pipeline architect. Build a pipeline draft text showing how we solve the problem.@@ -52,7 +52,7 @@ type = "PipeLLM"definition = "Generate a pipeline blueprint from natural language requirements"inputs = { rules = "Text", requirements = "Text", pipeline_name = "Text" }output = "PipelineLibraryBlueprint"-llm = "llm_to_engineer"+llm = "llm_to_pipelex"# structuring_method = "preliminary_text"prompt_template = """You are a Pipelex pipeline architect. Build a pipeline draft text showing how we solve the problem.diff --git a/pipelex/pipe_operators/pipe_llm.py b/pipelex/pipe_operators/pipe_llm.pyindex 36739516a..62c2294f8 100644--- a/pipelex/pipe_operators/pipe_llm.py+++ b/pipelex/pipe_operators/pipe_llm.py@@ -310,9 +310,13 @@ class PipeLLM(PipeOperator):))+ is_with_preliminary_text = (+ self.structuring_method == StructuringMethod.PRELIMINARY_TEXT+ ) or get_config().pipelex.structure_config.is_default_text_then_structurellm_prompt_run_params = PipeRunParams.copy_by_injecting_multiplicity(pipe_run_params=pipe_run_params,applied_output_multiplicity=applied_output_multiplicity,+ is_with_preliminary_text=is_with_preliminary_text,)# llm_prompt_1: LLMPrompt = (# await self.pipe_llm_prompt.run_pipe(@@ -345,7 +349,8 @@ class PipeLLM(PipeOperator):log.debug(f"PipeLLM generating {fixed_nb_output} output(s)" if fixed_nb_output else "PipeLLM generating a list of output(s)")llm_prompt_2_factory: Optional[LLMPromptFactoryAbstract]- if structuring_method := self.structuring_method:+ if self.structuring_method:+ structuring_method = cast(StructuringMethod, self.structuring_method)log.debug(f"PipeLLM pipe_code is '{self.code}' and structuring_method is '{structuring_method}'")match structuring_method:case StructuringMethod.DIRECT:diff --git a/pipelex/pipe_operators/pipe_llm_prompt.py b/pipelex/pipe_operators/pipe_llm_prompt.pyindex 218bc40c2..7f65b58e4 100644--- a/pipelex/pipe_operators/pipe_llm_prompt.py+++ b/pipelex/pipe_operators/pipe_llm_prompt.py@@ -171,9 +171,15 @@ class PipeLLMPrompt(PipeOperator):# Append output structure prompt if neededif pipe_run_params.dynamic_output_concept_code:- user_text += PipeLLMPrompt.get_output_structure_prompt(output_concept=pipe_run_params.dynamic_output_concept_code)+ user_text += PipeLLMPrompt.get_output_structure_prompt(+ output_concept=pipe_run_params.dynamic_output_concept_code,+ is_with_preliminary_text=pipe_run_params.is_with_preliminary_text or False,+ )else:- user_text += PipeLLMPrompt.get_output_structure_prompt(output_concept=self.output_concept_code)+ user_text += PipeLLMPrompt.get_output_structure_prompt(+ output_concept=self.output_concept_code,+ is_with_preliminary_text=pipe_run_params.is_with_preliminary_text or False,+ )log.verbose(f"User text with {self.output_concept_code=}:\n {user_text}")@@ -231,7 +237,7 @@ class PipeLLMPrompt(PipeOperator):)@staticmethod- def get_output_structure_prompt(output_concept: str) -> str:+ def get_output_structure_prompt(output_concept: str, is_with_preliminary_text: bool) -> str:class_name = Concept.extract_concept_name_from_str(concept_str=output_concept)output_class = get_class_registry().get_class(class_name)if not output_class:@@ -242,14 +248,26 @@ class PipeLLMPrompt(PipeOperator):if not class_structure:return ""- output_structure_prompt = (- f"\n\n---\nRequested output format: The output should be the following class: {class_name}\n"- f"{chr(10).join(class_structure)}\n"- "You do NOT need to output a formatted JSON object, another LLM will take care of that. "- "If you cannot find a value that is Optional, output None for that field."- "However, you MUST clearly output the values for each of these fields in your response.\n---\n"- "DO NOT create information. If the information is not present, output None."- )+ class_structure_str = "\n".join(class_structure)++ # TODO: use proper prompt templating for this+ if is_with_preliminary_text:+ output_structure_prompt = (+ f"\n\n---\nRequested output format: The requested output will be used to define the following class: {class_name}\n"+ f"{class_structure_str}\n"+ "You do NOT need to output a formatted JSON object, another LLM will take care of that. "+ "If you cannot find a value that is Optional, output None for that field. "+ "However, you MUST clearly output the values for each of these fields in your response.\n---\n"+ "DO NOT create information. If the information is not present, output None."+ )+ else:+ output_structure_prompt = (+ f"\n\n---\nRequested output format: The output must conform to the following BaseModel: {class_name}\n"+ f"{class_structure_str}\n"+ "If you cannot find a value that is Optional, output None for that field. "+ "However, you MUST clearly output the values for each of these fields in your response.\n---\n"+ "DO NOT create information. If the information is not present, output None."+ )return output_structure_promptasync def _unravel_text(diff --git a/tests/integration/pipelex/pipes/test_pipe_llm_prompt.py b/tests/integration/pipelex/pipes/test_pipe_llm_prompt.pyindex be5872265..7aa68df24 100644--- a/tests/integration/pipelex/pipes/test_pipe_llm_prompt.py+++ b/tests/integration/pipelex/pipes/test_pipe_llm_prompt.py@@ -49,7 +49,9 @@ class TestPipeLLMPrompt:assert pipe_output.main_stuff is not Noneassert pipe_output.llm_prompt is not Noneassert pipe_output.llm_prompt.user_text is not None- assert pipe_output.llm_prompt.user_text.endswith(PipeLLMPrompt.get_output_structure_prompt(NativeConcept.TEXT.code))+ assert pipe_output.llm_prompt.user_text.endswith(+ PipeLLMPrompt.get_output_structure_prompt(NativeConcept.TEXT.code, is_with_preliminary_text=False)+ )async def test_prompt_with_images(self, pipe_run_mode: PipeRunMode):"""Test prompt with image inputs."""@@ -109,7 +111,7 @@ class TestPipeLLMPrompt:assert pipe_output.main_stuff is not None# Verify output structure is appended- output_structure = pipe_llm_prompt.get_output_structure_prompt(concept_code)+ output_structure = pipe_llm_prompt.get_output_structure_prompt(concept_code, is_with_preliminary_text=False)assert pipe_output.llm_prompt is not Noneassert pipe_output.llm_prompt.user_text is not None