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.
Remove need for specific name "ocr_input"
Louis Choquela8d4ade29074
diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.mdindex b911fe4fd..2d9aff5e6 100644--- a/.github/copilot-instructions.md+++ b/.github/copilot-instructions.md@@ -118,7 +118,7 @@ Always fix any issues reported by these tools before proceeding.- **Pipelines**: `pipelex/libraries/pipelines/`- **Tests**: `tests/` directory- **Documentation**: `docs/` directory- # Pipeline Guide+# Pipeline Guide- Always first write your "plan" in natural langage, then transcribe it in pipelex.- You should ALWAYS RUN the terminal command `make validate` when you are writing a `.plx` file. It will ensure the pipe is runnable. If not, iterate.diff --git a/pipelex/core/pipes/pipe_input.py b/pipelex/core/pipes/pipe_input.pyindex 1aa6b86fe..75bab0438 100644--- a/pipelex/core/pipes/pipe_input.py+++ b/pipelex/core/pipes/pipe_input.py@@ -119,3 +119,7 @@ class PipeInputSpec(RootModel[PipeInputSpecRoot]):),)return the_requirements++ @property+ def nb_inputs(self) -> int:+ return len(self.root)diff --git a/pipelex/pipe_operators/ocr/pipe_ocr.py b/pipelex/pipe_operators/ocr/pipe_ocr.pyindex 41a86f662..b76966156 100644--- a/pipelex/pipe_operators/ocr/pipe_ocr.py+++ b/pipelex/pipe_operators/ocr/pipe_ocr.py@@ -38,9 +38,6 @@ class PipeOcrOutput(PipeOutput):pass-PIPE_OCR_INPUT_NAME = "ocr_input"--class PipeOcr(PipeOperator[PipeOcrOutput]):type: Literal["PipeOcr"] = "PipeOcr"ocr_choice: OcrChoice | None@@ -65,7 +62,7 @@ class PipeOcr(PipeOperator[PipeOcrOutput]):@overridedef required_variables(self) -> set[str]:- return {PIPE_OCR_INPUT_NAME}+ return set(self.inputs.required_names)@overridedef validate_output(self):@@ -79,49 +76,14 @@ class PipeOcr(PipeOperator[PipeOcrOutput]):default_reaction = static_validation_config.default_reactionreactions = static_validation_config.reactions- # check that we have either an image or a pdf in inputs, at most one of them and nothing else- candidate_prompt_var_names: list[str] = []- for input_name, requirement in self.inputs.items:- log.debug(f"{input_name=}")- log.debug(f"{requirement=}")- log.debug(f"Validating input '{input_name}' with concept code '{requirement.concept.code}'")- if concept_provider.is_compatible(- tested_concept=requirement.concept,- wanted_concept=concept_provider.get_native_concept(native_concept=NativeConceptEnum.IMAGE),- strict=True,- ):- self.image_stuff_name = input_name- candidate_prompt_var_names.append(input_name)- elif concept_provider.is_compatible(- tested_concept=requirement.concept,- wanted_concept=concept_provider.get_native_concept(native_concept=NativeConceptEnum.PDF),- strict=True,- ):- self.pdf_stuff_name = input_name- candidate_prompt_var_names.append(input_name)- else:- inadequate_input_concept_error = StaticValidationError(- error_type=StaticValidationErrorType.INADEQUATE_INPUT_CONCEPT,- domain=self.domain,- pipe_code=self.code,- variable_names=[input_name],- provided_concept_code=requirement.concept.code,- explanation="For OCR you must provide either a pdf or an image or a concept that refines one of them",- )- match reactions.get(StaticValidationErrorType.INADEQUATE_INPUT_CONCEPT, default_reaction):- case StaticValidationReaction.IGNORE:- pass- case StaticValidationReaction.LOG:- log.error(inadequate_input_concept_error.desc())- case StaticValidationReaction.RAISE:- raise inadequate_input_concept_error-- if len(candidate_prompt_var_names) > 1:+ # check that we have exactly one input+ nb_inputs = self.inputs.nb_inputs+ if nb_inputs > 1:too_many_candidate_inputs_error = StaticValidationError(error_type=StaticValidationErrorType.TOO_MANY_CANDIDATE_INPUTS,domain=self.domain,pipe_code=self.code,- variable_names=candidate_prompt_var_names,+ variable_names=self.inputs.variables,explanation="Only one image or pdf can be provided for OCR",)match reactions.get(StaticValidationErrorType.TOO_MANY_CANDIDATE_INPUTS, default_reaction):@@ -131,7 +93,7 @@ class PipeOcr(PipeOperator[PipeOcrOutput]):log.error(too_many_candidate_inputs_error.desc())case StaticValidationReaction.RAISE:raise too_many_candidate_inputs_error- elif len(candidate_prompt_var_names) == 0:+ elif nb_inputs < 1:missing_input_var_error = StaticValidationError(error_type=StaticValidationErrorType.MISSING_INPUT_VARIABLE,domain=self.domain,@@ -146,6 +108,40 @@ class PipeOcr(PipeOperator[PipeOcrOutput]):case StaticValidationReaction.RAISE:raise missing_input_var_error+ # get input_name, requirement from single item in inputs+ input_name, requirement = self.inputs.items[0]+ log.debug(f"{input_name=}")+ log.debug(f"{requirement=}")+ log.debug(f"Validating input '{input_name}' with concept code '{requirement.concept.code}'")+ if concept_provider.is_compatible(+ tested_concept=requirement.concept,+ wanted_concept=concept_provider.get_native_concept(native_concept=NativeConceptEnum.IMAGE),+ strict=True,+ ):+ self.image_stuff_name = input_name+ elif concept_provider.is_compatible(+ tested_concept=requirement.concept,+ wanted_concept=concept_provider.get_native_concept(native_concept=NativeConceptEnum.PDF),+ strict=True,+ ):+ self.pdf_stuff_name = input_name+ else:+ inadequate_input_concept_error = StaticValidationError(+ error_type=StaticValidationErrorType.INADEQUATE_INPUT_CONCEPT,+ domain=self.domain,+ pipe_code=self.code,+ variable_names=[input_name],+ provided_concept_code=requirement.concept.code,+ explanation="For OCR you must provide either a pdf or an image or a concept that refines one of them",+ )+ match reactions.get(StaticValidationErrorType.INADEQUATE_INPUT_CONCEPT, default_reaction):+ case StaticValidationReaction.IGNORE:+ pass+ case StaticValidationReaction.LOG:+ log.error(inadequate_input_concept_error.desc())+ case StaticValidationReaction.RAISE:+ raise inadequate_input_concept_error+@overridedef needed_inputs(self, visited_pipes: set[str] | None = None) -> PipeInputSpec:return self.inputsdiff --git a/tests/integration/pipelex/pipes/operator/pipe_ocr/test_pipe_ocr.py b/tests/integration/pipelex/pipes/operator/pipe_ocr/test_pipe_ocr.pyindex c2961ba1b..dfba3613c 100644--- a/tests/integration/pipelex/pipes/operator/pipe_ocr/test_pipe_ocr.py+++ b/tests/integration/pipelex/pipes/operator/pipe_ocr/test_pipe_ocr.py@@ -12,7 +12,6 @@ from pipelex.core.pipes.pipe_run_params import PipeRunModefrom pipelex.core.pipes.pipe_run_params_factory import PipeRunParamsFactoryfrom pipelex.core.stuffs.stuff_content import PageContentfrom pipelex.hub import get_concept_provider, get_pipe_router-from pipelex.pipe_operators.ocr.pipe_ocr import PIPE_OCR_INPUT_NAMEfrom pipelex.pipe_operators.ocr.pipe_ocr_blueprint import PipeOcrBlueprintfrom pipelex.pipe_operators.ocr.pipe_ocr_factory import PipeOcrFactoryfrom pipelex.pipe_works.pipe_job_factory import PipeJobFactory@@ -84,9 +83,10 @@ class TestPipeOCR:pipe_run_mode: PipeRunMode,pdf_url: str,):+ input_name = "arbitrary_name"pipe_ocr_blueprint = PipeOcrBlueprint(definition="OCR test for PDF processing",- inputs={PIPE_OCR_INPUT_NAME: InputRequirementBlueprint(concept=NativeConceptEnum.PDF)},+ inputs={input_name: InputRequirementBlueprint(concept=NativeConceptEnum.PDF)},output=NativeConceptEnum.TEXT_AND_IMAGES,ocr=ocr_choice_for_pdf,page_images=True,@@ -104,7 +104,7 @@ class TestPipeOCR:pipe_run_params=PipeRunParamsFactory.make_run_params(pipe_run_mode=pipe_run_mode),working_memory=WorkingMemoryFactory.make_from_pdf(pdf_url=pdf_url,- name=PIPE_OCR_INPUT_NAME,+ name=input_name,),)pipe_ocr_output = await get_pipe_router().run(diff --git a/tests/integration/pipelex/test_data.py b/tests/integration/pipelex/test_data.pyindex a4f22dc0a..626479b56 100644--- a/tests/integration/pipelex/test_data.py+++ b/tests/integration/pipelex/test_data.py@@ -13,7 +13,6 @@ from pipelex.core.stuffs.stuff_content import ()from pipelex.core.stuffs.stuff_factory import StuffBlueprint, StuffFactoryfrom pipelex.exceptions import PipeStackOverflowError-from pipelex.pipe_operators.ocr.pipe_ocr import PIPE_OCR_INPUT_NAMEfrom tests.cases import ImageTestCases, PDFTestCases@@ -60,7 +59,7 @@ class PipeTestCases:content=ImageContent(url=URL_IMG_FASHION_PHOTO_1),)SIMPLE_STUFF_PDF = StuffFactory.make_stuff(- name=PIPE_OCR_INPUT_NAME,+ name="arbitrary_name",concept=ConceptFactory.make_native_concept(native_concept_data=NATIVE_CONCEPTS_DATA[NativeConceptEnum.PDF]),content=PDFContent(url=PDFTestCases.DOCUMENT_URLS[0]),)