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.
Moved and renamed code related to ConceptFactory
Louis Choquelea743cc87379
diff --git a/pipelex/core/concepts/concept_factory.py b/pipelex/core/concepts/concept_factory.pyindex b80758831..ef37afd99 100644--- a/pipelex/core/concepts/concept_factory.py+++ b/pipelex/core/concepts/concept_factory.py@@ -60,10 +60,6 @@ class ConceptFactory:structure_class_name=TextContent.__name__,)- @classmethod- def construct_concept_string_with_domain(cls, domain: str, concept_code: str) -> str:- return f"{domain}.{concept_code}"-@classmethoddef make(cls, concept_code: str, domain: str, definition: str, structure_class_name: str, refines: str | None = None) -> Concept:return Concept(@@ -104,6 +100,25 @@ class ConceptFactory:return DomainAndConceptCode(domain=domain, concept_code=concept_string_or_code)return DomainAndConceptCode(domain=SpecialDomain.IMPLICIT, concept_code=concept_string_or_code)+ @classmethod+ def make_concept_string_with_domain(cls, domain: str, concept_code: str) -> str:+ return f"{domain}.{concept_code}"++ @classmethod+ def make_concept_string_with_domain_from_concept_string_or_code(+ cls, domain: str, concept_sring_or_code: str, concept_codes_from_the_same_domain: list[str] | None = None+ ) -> str:+ input_domain_and_code = cls.make_domain_and_concept_code_from_concept_string_or_code(+ domain=domain,+ concept_string_or_code=concept_sring_or_code,+ concept_codes_from_the_same_domain=concept_codes_from_the_same_domain,+ )++ return cls.make_concept_string_with_domain(+ domain=input_domain_and_code.domain,+ concept_code=input_domain_and_code.concept_code,+ )+@classmethoddef make_refine(cls, refine: str) -> str:if not NativeConceptManager.is_native_concept(concept_string_or_code=refine):diff --git a/pipelex/core/concepts/concept_library.py b/pipelex/core/concepts/concept_library.pyindex 2904820f7..10b016681 100644--- a/pipelex/core/concepts/concept_library.py+++ b/pipelex/core/concepts/concept_library.py@@ -123,7 +123,7 @@ class ConceptLibrary(RootModel[ConceptLibraryRoot], ConceptProviderAbstract):ConceptBlueprint.validate_concept_code(concept_code=concept_code)for domain in search_domains:if found_concept := self.get_required_concept(- concept_string=ConceptFactory.construct_concept_string_with_domain(domain=domain, concept_code=concept_code),+ concept_string=ConceptFactory.make_concept_string_with_domain(domain=domain, concept_code=concept_code),):return found_conceptdiff --git a/pipelex/core/pipes/pipe_input_factory.py b/pipelex/core/pipes/pipe_input_factory.pyindex 351f4006f..7f4f8123e 100644--- a/pipelex/core/pipes/pipe_input_factory.py+++ b/pipelex/core/pipes/pipe_input_factory.py@@ -2,7 +2,7 @@ from pipelex.core.concepts.concept_blueprint import ConceptBlueprintfrom pipelex.core.concepts.concept_factory import ConceptFactoryfrom pipelex.core.pipes.pipe_input import InputRequirement, PipeInputSpecfrom pipelex.core.pipes.pipe_input_blueprint import InputRequirementBlueprint-from pipelex.hub import get_concept_provider+from pipelex.hub import get_required_conceptclass PipeInputSpecFactory:@@ -22,21 +22,16 @@ class PipeInputSpecFactory:if isinstance(input_requirement_blueprint, str):input_requirement_blueprint = InputRequirementBlueprint(concept=input_requirement_blueprint)- concept_string = input_requirement_blueprint.concept- ConceptBlueprint.validate_concept_string_or_code(concept_string_or_code=concept_string)- input_domain_and_code = ConceptFactory.make_domain_and_concept_code_from_concept_string_or_code(+ concept_string_or_code = input_requirement_blueprint.concept+ ConceptBlueprint.validate_concept_string_or_code(concept_string_or_code=concept_string_or_code)+ concept_string_with_domain = ConceptFactory.make_concept_string_with_domain_from_concept_string_or_code(domain=domain,- concept_string_or_code=concept_string,+ concept_sring_or_code=concept_string_or_code,concept_codes_from_the_same_domain=concept_codes_from_the_same_domain,)inputs[var_name] = InputRequirement(- concept=get_concept_provider().get_required_concept(- concept_string=ConceptFactory.construct_concept_string_with_domain(- domain=input_domain_and_code.domain,- concept_code=input_domain_and_code.concept_code,- ),- ),+ concept=get_required_concept(concept_string=concept_string_with_domain),multiplicity=input_requirement_blueprint.multiplicity,)return PipeInputSpec(root=inputs)diff --git a/pipelex/libraries/library_manager.py b/pipelex/libraries/library_manager.pyindex 5bdf0a9fa..165894425 100644--- a/pipelex/libraries/library_manager.py+++ b/pipelex/libraries/library_manager.py@@ -180,7 +180,7 @@ class LibraryManager(LibraryManagerAbstract):# Remove concepts (they may depend on domain)if blueprint.concept is not None:concept_codes_to_remove = [- ConceptFactory.construct_concept_string_with_domain(domain=blueprint.domain, concept_code=concept_code)+ ConceptFactory.make_concept_string_with_domain(domain=blueprint.domain, concept_code=concept_code)for concept_code in blueprint.concept]self.concept_library.remove_concepts_by_codes(concept_codes=concept_codes_to_remove)diff --git a/pipelex/pipe_controllers/batch/pipe_batch_factory.py b/pipelex/pipe_controllers/batch/pipe_batch_factory.pyindex 469bccaea..699aed0b6 100644--- a/pipelex/pipe_controllers/batch/pipe_batch_factory.py+++ b/pipelex/pipe_controllers/batch/pipe_batch_factory.py@@ -34,7 +34,7 @@ class PipeBatchFactory(PipeFactoryProtocol[PipeBatchBlueprint, PipeBatch]):concept_codes_from_the_same_domain=concept_codes_from_the_same_domain,),output=get_concept_provider().get_required_concept(- concept_string=ConceptFactory.construct_concept_string_with_domain(+ concept_string=ConceptFactory.make_concept_string_with_domain(domain=output_domain_and_code.domain,concept_code=output_domain_and_code.concept_code,),diff --git a/pipelex/pipe_controllers/condition/pipe_condition_factory.py b/pipelex/pipe_controllers/condition/pipe_condition_factory.pyindex 215c7c978..8f4382eb5 100644--- a/pipelex/pipe_controllers/condition/pipe_condition_factory.py+++ b/pipelex/pipe_controllers/condition/pipe_condition_factory.py@@ -40,7 +40,7 @@ class PipeConditionFactory(PipeFactoryProtocol[PipeConditionBlueprint, PipeCondiconcept_codes_from_the_same_domain=concept_codes_from_the_same_domain,),output=get_concept_provider().get_required_concept(- concept_string=ConceptFactory.construct_concept_string_with_domain(+ concept_string=ConceptFactory.make_concept_string_with_domain(domain=output_domain_and_code.domain,concept_code=output_domain_and_code.concept_code,),diff --git a/pipelex/pipe_controllers/parallel/pipe_parallel_factory.py b/pipelex/pipe_controllers/parallel/pipe_parallel_factory.pyindex b43fa0423..af35e31d2 100644--- a/pipelex/pipe_controllers/parallel/pipe_parallel_factory.py+++ b/pipelex/pipe_controllers/parallel/pipe_parallel_factory.py@@ -46,7 +46,7 @@ class PipeParallelFactory(PipeFactoryProtocol[PipeParallelBlueprint, PipeParalleconcept_codes_from_the_same_domain=concept_codes_from_the_same_domain,)combined_output = get_required_concept(- concept_string=ConceptFactory.construct_concept_string_with_domain(+ concept_string=ConceptFactory.make_concept_string_with_domain(domain=combined_output_domain_and_code.domain,concept_code=combined_output_domain_and_code.concept_code,),@@ -69,7 +69,7 @@ class PipeParallelFactory(PipeFactoryProtocol[PipeParallelBlueprint, PipeParalleconcept_codes_from_the_same_domain=concept_codes_from_the_same_domain,),output=get_required_concept(- concept_string=ConceptFactory.construct_concept_string_with_domain(+ concept_string=ConceptFactory.make_concept_string_with_domain(domain=output_domain_and_code.domain,concept_code=output_domain_and_code.concept_code,),diff --git a/pipelex/pipe_controllers/sequence/pipe_sequence_factory.py b/pipelex/pipe_controllers/sequence/pipe_sequence_factory.pyindex a91d084cd..dc3d42644 100644--- a/pipelex/pipe_controllers/sequence/pipe_sequence_factory.py+++ b/pipelex/pipe_controllers/sequence/pipe_sequence_factory.py@@ -34,7 +34,7 @@ class PipeSequenceFactory(PipeFactoryProtocol[PipeSequenceBlueprint, PipeSequencconcept_codes_from_the_same_domain=concept_codes_from_the_same_domain,),output=get_concept_provider().get_required_concept(- concept_string=ConceptFactory.construct_concept_string_with_domain(+ concept_string=ConceptFactory.make_concept_string_with_domain(domain=output_domain_and_code.domain,concept_code=output_domain_and_code.concept_code,),diff --git a/pipelex/pipe_operators/compose/pipe_compose_factory.py b/pipelex/pipe_operators/compose/pipe_compose_factory.pyindex 4dc329138..0b739c018 100644--- a/pipelex/pipe_operators/compose/pipe_compose_factory.py+++ b/pipelex/pipe_operators/compose/pipe_compose_factory.py@@ -48,7 +48,7 @@ class PipeComposeFactory(PipeFactoryProtocol[PipeComposeBlueprint, PipeCompose])concept_codes_from_the_same_domain=concept_codes_from_the_same_domain,),output=get_concept_provider().get_required_concept(- concept_string=ConceptFactory.construct_concept_string_with_domain(+ concept_string=ConceptFactory.make_concept_string_with_domain(domain=output_domain_and_code.domain,concept_code=output_domain_and_code.concept_code,),diff --git a/pipelex/pipe_operators/func/pipe_func_factory.py b/pipelex/pipe_operators/func/pipe_func_factory.pyindex 685423dc6..792a539e1 100644--- a/pipelex/pipe_operators/func/pipe_func_factory.py+++ b/pipelex/pipe_operators/func/pipe_func_factory.py@@ -33,7 +33,7 @@ class PipeFuncFactory(PipeFactoryProtocol[PipeFuncBlueprint, PipeFunc]):concept_codes_from_the_same_domain=concept_codes_from_the_same_domain,),output=get_concept_provider().get_required_concept(- concept_string=ConceptFactory.construct_concept_string_with_domain(+ concept_string=ConceptFactory.make_concept_string_with_domain(domain=output_domain_and_code.domain,concept_code=output_domain_and_code.concept_code,),diff --git a/pipelex/pipe_operators/img_gen/pipe_img_gen_factory.py b/pipelex/pipe_operators/img_gen/pipe_img_gen_factory.pyindex de36dde65..6c36f3829 100644--- a/pipelex/pipe_operators/img_gen/pipe_img_gen_factory.py+++ b/pipelex/pipe_operators/img_gen/pipe_img_gen_factory.py@@ -33,7 +33,7 @@ class PipeImgGenFactory(PipeFactoryProtocol[PipeImgGenBlueprint, PipeImgGen]):concept_codes_from_the_same_domain=concept_codes_from_the_same_domain,),output=get_concept_provider().get_required_concept(- concept_string=ConceptFactory.construct_concept_string_with_domain(+ concept_string=ConceptFactory.make_concept_string_with_domain(domain=output_domain_and_code.domain,concept_code=output_domain_and_code.concept_code,),diff --git a/pipelex/pipe_operators/llm/pipe_llm.py b/pipelex/pipe_operators/llm/pipe_llm.pyindex 3204c4503..e7478f5fe 100644--- a/pipelex/pipe_operators/llm/pipe_llm.py+++ b/pipelex/pipe_operators/llm/pipe_llm.py@@ -248,7 +248,7 @@ class PipeLLM(PipeOperator[PipeLLMOutput]):output_concept_code = SpecialDomain.NATIVE + "." + NativeConceptEnum.TEXTelse:output_concept = get_concept_provider().get_required_concept(- concept_string=ConceptFactory.construct_concept_string_with_domain(domain=self.domain, concept_code=output_concept_code),+ concept_string=ConceptFactory.make_concept_string_with_domain(domain=self.domain, concept_code=output_concept_code),)multiplicity_resolution = output_multiplicity_to_apply(diff --git a/pipelex/pipe_operators/llm/pipe_llm_factory.py b/pipelex/pipe_operators/llm/pipe_llm_factory.pyindex 60410525b..b6334debd 100644--- a/pipelex/pipe_operators/llm/pipe_llm_factory.py+++ b/pipelex/pipe_operators/llm/pipe_llm_factory.py@@ -85,7 +85,7 @@ class PipeLLMFactory(PipeFactoryProtocol[PipeLLMBlueprint, PipeLLM]):concept_codes_from_the_same_domain=concept_codes_from_the_same_domain,)concept = get_concept_provider().get_required_concept(- concept_string=ConceptFactory.construct_concept_string_with_domain(+ concept_string=ConceptFactory.make_concept_string_with_domain(domain=domain_and_code.domain,concept_code=domain_and_code.concept_code,),@@ -132,7 +132,7 @@ class PipeLLMFactory(PipeFactoryProtocol[PipeLLMBlueprint, PipeLLM]):concept_codes_from_the_same_domain=concept_codes_from_the_same_domain,),output=get_concept_provider().get_required_concept(- concept_string=ConceptFactory.construct_concept_string_with_domain(domain=output_concept_domain, concept_code=output_concept_code),+ concept_string=ConceptFactory.make_concept_string_with_domain(domain=output_concept_domain, concept_code=output_concept_code),),llm_prompt_spec=llm_prompt_spec,llm_choices=llm_choices,diff --git a/pipelex/pipe_operators/ocr/pipe_ocr_factory.py b/pipelex/pipe_operators/ocr/pipe_ocr_factory.pyindex 65fd09980..0a2c26579 100644--- a/pipelex/pipe_operators/ocr/pipe_ocr_factory.py+++ b/pipelex/pipe_operators/ocr/pipe_ocr_factory.py@@ -30,7 +30,7 @@ class PipeOcrFactory(PipeFactoryProtocol[PipeOcrBlueprint, PipeOcr]):code=pipe_code,definition=blueprint.definition,output=get_concept_provider().get_required_concept(- concept_string=ConceptFactory.construct_concept_string_with_domain(+ concept_string=ConceptFactory.make_concept_string_with_domain(domain=output_domain_and_code.domain,concept_code=output_domain_and_code.concept_code,),diff --git a/tests/integration/pipelex/pipes/controller/pipe_parallel/test_pipe_parallel_validation.py b/tests/integration/pipelex/pipes/controller/pipe_parallel/test_pipe_parallel_validation.pyindex 1c521b07d..dc8f9c07f 100644--- a/tests/integration/pipelex/pipes/controller/pipe_parallel/test_pipe_parallel_validation.py+++ b/tests/integration/pipelex/pipes/controller/pipe_parallel/test_pipe_parallel_validation.py@@ -36,7 +36,7 @@ class TestPipeParallelValidation:"context": InputRequirementBlueprint(concept=concept_2.concept_string),},definition="Analysis pipe for document processing",- output=ConceptFactory.construct_concept_string_with_domain(domain=domain, concept_code=concept_3.code),+ output=ConceptFactory.make_concept_string_with_domain(domain=domain, concept_code=concept_3.code),prompt_template="Analyze this document: \n@context\n@document",)@@ -61,7 +61,7 @@ class TestPipeParallelValidation:"document": InputRequirementBlueprint(concept=concept_1.code),"context": InputRequirementBlueprint(concept=concept_2.code),},- output=ConceptFactory.construct_concept_string_with_domain(domain=domain, concept_code=concept_3.code),+ output=ConceptFactory.make_concept_string_with_domain(domain=domain, concept_code=concept_3.code),parallels=[SubPipeBlueprint(pipe=real_pipe.code, result="analysis_result")],add_each_output=True,combined_output=None,@@ -105,7 +105,7 @@ class TestPipeParallelValidation:pipe_parallel_blueprint = PipeParallelBlueprint(definition="Basic parallel pipe for testing",inputs={"input_var": InputRequirementBlueprint(concept=concept_1.concept_string)},- output=ConceptFactory.construct_concept_string_with_domain(domain=domain, concept_code=concept_3.code),+ output=ConceptFactory.make_concept_string_with_domain(domain=domain, concept_code=concept_3.code),parallels=[SubPipeBlueprint(pipe="test_pipe_1", result="result_1")],add_each_output=True,combined_output=None,@@ -152,7 +152,7 @@ class TestPipeParallelValidation:"document": InputRequirementBlueprint(concept=concept_1.concept_string),"context": InputRequirementBlueprint(concept=concept_2.concept_string),},- output=ConceptFactory.construct_concept_string_with_domain(domain=domain, concept_code=concept_3.code),+ output=ConceptFactory.make_concept_string_with_domain(domain=domain, concept_code=concept_3.code),parallels=[], # No sub-pipes to avoid dependency issuesadd_each_output=True,combined_output=None,diff --git a/tests/unit/pipelex/core/concepts/concept/test_concept.py b/tests/unit/pipelex/core/concepts/concept/test_concept.pyindex de683c378..0c0cb8979 100644--- a/tests/unit/pipelex/core/concepts/concept/test_concept.py+++ b/tests/unit/pipelex/core/concepts/concept/test_concept.py@@ -204,7 +204,7 @@ class TestConcept:"""Test construct_concept_string_with_domain method."""valid_domain = "valid_domain"assert (- ConceptFactory.construct_concept_string_with_domain(domain=valid_domain, concept_code=NativeConceptEnum.TEXT)+ ConceptFactory.make_concept_string_with_domain(domain=valid_domain, concept_code=NativeConceptEnum.TEXT)== f"{valid_domain}.{NativeConceptEnum.TEXT}")