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.
finish implicit memory
thomashebrard1dcfa6d10284
diff --git a/pipelex/core/concepts/concept.py b/pipelex/core/concepts/concept.pyindex f3ce38e1d..ed99e6f6a 100644--- a/pipelex/core/concepts/concept.py+++ b/pipelex/core/concepts/concept.py@@ -69,6 +69,11 @@ class Concept(BaseModel):return Trueif concept_1.structure_class_name == concept_2.structure_class_name:return True++ # If concept_1 refines concept_2, they are strictly compatible+ if concept_1.refines is not None and concept_1.refines == concept_2.concept_string:+ return True+if concept_1.refines is None and concept_2.refines is None:concept_1_class = KajsonManager.get_class_registry().get_class(name=concept_1.structure_class_name)concept_2_class = KajsonManager.get_class_registry().get_class(name=concept_2.structure_class_name)@@ -92,6 +97,8 @@ class Concept(BaseModel):@classmethoddef is_valid_structure_class(cls, structure_class_name: str) -> bool:+ # TODO: DO NOT use the KajsonManager here. Pipelex needs to be instantiated to use the get_class_registry.+ # And when we go through KajsonManager, no error raises if pipelex is not instantiated.# We get_class_registry directly from KajsonManager instead of pipelex hub to avoid circular importif KajsonManager.get_class_registry().has_subclass(name=structure_class_name, base_class=StuffContent):return Truediff --git a/pipelex/core/concepts/concept_factory.py b/pipelex/core/concepts/concept_factory.pyindex c9817c97e..eb08432e6 100644--- a/pipelex/core/concepts/concept_factory.py+++ b/pipelex/core/concepts/concept_factory.py@@ -161,7 +161,6 @@ class ConceptFactory:return DomainAndConceptCode(domain=parts[0], concept_code=parts[1])if NativeConceptCode.get_validated_native_concept_string(concept_string_or_code=concept_string_or_code):return DomainAndConceptCode(domain=SpecialDomain.NATIVE, concept_code=concept_string_or_code)-if (concept_codes_from_the_same_domain and concept_string_or_code in concept_codes_from_the_same_domain): # Is a concept code from the same domaindiff --git a/pipelex/core/concepts/concept_library.py b/pipelex/core/concepts/concept_library.pyindex 9ae9b2da4..b04165782 100644--- a/pipelex/core/concepts/concept_library.py+++ b/pipelex/core/concepts/concept_library.py@@ -66,10 +66,10 @@ class ConceptLibrary(RootModel[ConceptLibraryRoot], ConceptLibraryAbstract):self.add_new_concept(concept=concept)@override- def remove_concepts_by_codes(self, concept_codes: list[str]) -> None:- for concept_code in concept_codes:- if concept_code in self.root:- del self.root[concept_code]+ def remove_concepts_by_concept_strings(self, concept_strings: list[str]) -> None:+ for concept_string in concept_strings:+ if concept_string in self.root:+ del self.root[concept_string]@overridedef is_compatible(self, tested_concept: Concept, wanted_concept: Concept, strict: bool = False) -> bool:@@ -130,22 +130,31 @@ class ConceptLibrary(RootModel[ConceptLibraryRoot], ConceptLibraryAbstract):elif NativeConceptCode.is_native_concept(concept_code=concept_string_or_code):return self.get_native_concept(native_concept=NativeConceptCode(concept_string_or_code))else:- if search_domains is None:- msg = f"Concept '{concept_string_or_code}' not found in the library and no search domains were provided"- raise ConceptLibraryConceptNotFoundError(msg)found_concepts: list[Concept] = []- for domain in search_domains:- if found_concept := self.get_required_concept(- concept_string=ConceptFactory.make_concept_string_with_domain(domain=domain, concept_code=concept_string_or_code),- ):- found_concepts.append(found_concept)- if len(found_concepts) == 0:- msg = f"Concept '{concept_string_or_code}' not found in the library and no search domains were provided"- raise ConceptLibraryConceptNotFoundError(msg)- if len(found_concepts) > 1:- msg = f"Multiple concepts found for '{concept_string_or_code}': {found_concepts}. Please specify the domain."- raise ConceptLibraryConceptNotFoundError(msg)- return found_concepts[0]+ if search_domains is None:+ for concept in self.root.values():+ if concept_string_or_code == concept.code:+ found_concepts.append(concept)+ if len(found_concepts) == 0:+ msg = f"Concept '{concept_string_or_code}' not found in the library and no search domains were provided"+ raise ConceptLibraryConceptNotFoundError(msg)+ if len(found_concepts) > 1:+ msg = f"Multiple concepts found for '{concept_string_or_code}': {found_concepts}. Please specify the domain."+ raise ConceptLibraryConceptNotFoundError(msg)+ return found_concepts[0]+ else:+ for domain in search_domains:+ if found_concept := self.get_required_concept(+ concept_string=ConceptFactory.make_concept_string_with_domain(domain=domain, concept_code=concept_string_or_code),+ ):+ found_concepts.append(found_concept)+ if len(found_concepts) == 0:+ msg = f"Concept '{concept_string_or_code}' not found in the library and no search domains were provided"+ raise ConceptLibraryConceptNotFoundError(msg)+ if len(found_concepts) > 1:+ msg = f"Multiple concepts found for '{concept_string_or_code}': {found_concepts}. Please specify the domain."+ raise ConceptLibraryConceptNotFoundError(msg)+ return found_concepts[0]@overridedef search_for_concept_in_domains(self, concept_code: str, search_domains: list[str]) -> Concept | None:diff --git a/pipelex/core/concepts/concept_library_abstract.py b/pipelex/core/concepts/concept_library_abstract.pyindex ae2a0ae30..d34b65677 100644--- a/pipelex/core/concepts/concept_library_abstract.py+++ b/pipelex/core/concepts/concept_library_abstract.py@@ -15,7 +15,7 @@ class ConceptLibraryAbstract(ABC):pass@abstractmethod- def remove_concepts_by_codes(self, concept_codes: list[str]) -> None:+ def remove_concepts_by_concept_strings(self, concept_strings: list[str]) -> None:pass@abstractmethoddiff --git a/pipelex/core/stuffs/stuff_factory.py b/pipelex/core/stuffs/stuff_factory.pyindex f87bf7867..048288e42 100644--- a/pipelex/core/stuffs/stuff_factory.py+++ b/pipelex/core/stuffs/stuff_factory.py@@ -161,6 +161,7 @@ class StuffFactory:if issubclass(type(stuff_content_or_data), StuffContent):# Get the concept from the StuffContent class namecontent_class_name = stuff_content_or_data.__class__.__name__+ stuff_content = cast("StuffContent", stuff_content_or_data)# Check if it's a native conceptif "Content" in content_class_name and NativeConceptCode.is_native_concept(concept_code=content_class_name.split("Content")[0]):@@ -169,12 +170,23 @@ class StuffFactory:else:try:# It's a custom StuffContent, try to find the concept- concept = concept_library.get_required_concept(concept_string=content_class_name)+ concept = concept_library.get_required_concept_from_concept_string_or_code(+ concept_string_or_code=content_class_name, search_domains=search_domains+ )except ConceptLibraryConceptNotFoundError as exc:- msg = f"Trying to create a Stuff '{name}' from a custom StuffContent '{content_class_name}' "- "but the concept of name '{content_class_name}' is not found in the library"+ msg = (+ f"Trying to create a Stuff '{name}' from a custom StuffContent '{content_class_name}' "+ f"but the concept of name '{content_class_name}' is not found in the library"+ )raise StuffFactoryError(msg) from exc+ return cls.make_stuff(+ concept=concept,+ content=stuff_content,+ name=name,+ code=code,+ )+# Case 1.2 or 1.4: list → ListContentif isinstance(stuff_content_or_data, list):if len(stuff_content_or_data) == 0:@@ -217,7 +229,9 @@ class StuffFactory:concept = get_native_concept(native_concept=NativeConceptCode(content_class_name.split("Content")[0]))else:try:- concept = concept_library.get_required_concept(concept_string=content_class_name)+ concept = concept_library.get_required_concept_from_concept_string_or_code(+ concept_string_or_code=content_class_name, search_domains=search_domains+ )except ConceptLibraryConceptNotFoundError as exc:msg = f"Trying to create a Stuff '{name}' from a list of StuffContent but""the concept of name '{content_class_name}' is not found in the library"@@ -263,25 +277,26 @@ class StuffFactory:concept_string_or_code=concept_string, search_domains=search_domains)except ConceptLibraryConceptNotFoundError as exc:- msg = f"Trying to create a Stuff '{name}' in the inputs of your pipe, from a dict that should represent a StuffContentOrData "- f"but the concept of name '{concept_string}' is not found in the library"+ msg = (+ f"Trying to create a Stuff '{name}' in the inputs of your pipe, from a dict that should represent a StuffContentOrData "+ f"but the concept of name '{concept_string}' is not found in the library"+ )raise StuffFactoryError(msg) from exc# Case 2.1: content is a stringif isinstance(content, str):- # Check if concept is compatible with Text+ # Check if concept is strictly compatible with Text (refinement = strict compatibility)text_concept = get_native_concept(native_concept=NativeConceptCode.TEXT)- if concept_library.is_compatible(tested_concept=concept, wanted_concept=text_concept):+ if concept_library.is_compatible(tested_concept=concept, wanted_concept=text_concept, strict=True):return cls.make_stuff(concept=concept,content=TextContent(text=content),name=name,code=code,)-msg = (f"Trying to create a Stuff '{name}' in the inputs of your pipe, from a dict that should represent a StuffContentOrData "- f"but the concept of name '{concept_string}' is not compatible with text content"+ f"but the concept of name '{concept_string}' is not compatible with native concept 'native.Text'")raise StuffFactoryError(msg)@@ -338,7 +353,7 @@ class StuffFactory:raise StuffFactoryError(msg)text_concept = get_native_concept(native_concept=NativeConceptCode.TEXT)- if concept_library.is_compatible(tested_concept=concept, wanted_concept=text_concept):+ if concept_library.is_compatible(tested_concept=concept, wanted_concept=text_concept, strict=True):items = [TextContent(text=item) for item in list_content]return cls.make_stuff(concept=concept,diff --git a/pipelex/libraries/library_manager.py b/pipelex/libraries/library_manager.pyindex cc7d844a1..e69b39ecc 100644--- a/pipelex/libraries/library_manager.py+++ b/pipelex/libraries/library_manager.py@@ -174,7 +174,7 @@ class LibraryManager(LibraryManagerAbstract):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)+ self.concept_library.remove_concepts_by_concept_strings(concept_strings=concept_codes_to_remove)self.domain_library.remove_domain_by_code(domain_code=blueprint.domain)diff --git a/tests/unit/core/stuffs/data.py b/tests/unit/core/stuffs/data.pyindex 1195a32e9..62ab66c9a 100644--- a/tests/unit/core/stuffs/data.py+++ b/tests/unit/core/stuffs/data.py@@ -1,9 +1,6 @@-from typing import ClassVar-from pydantic import Fieldfrom pipelex.client.protocol import StuffContentOrData-from pipelex.core.concepts.concept_blueprint import ConceptBlueprintfrom pipelex.core.concepts.concept_factory import ConceptFactoryfrom pipelex.core.concepts.concept_native import NativeConceptCodefrom pipelex.core.stuffs.list_content import ListContent@@ -22,283 +19,282 @@ class MyConcept(StructuredContent):arg3: MySubClass = Field(description="Test argument 3")-class TestData:- CASE: ClassVar[list[tuple[str, StuffContentOrData, str, str, Stuff]]] = [- # Case 1.1: Content is a string- (- "case-1.1-string",- "Lorem Ipsum",- "stuff_name",- "stuff_code",- Stuff(- stuff_name="stuff_name",- stuff_code="stuff_code",- concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.TEXT),- content=TextContent(text="Lorem Ipsum"),+TEST_CASES: list[tuple[str, StuffContentOrData, str, str, Stuff]] = [+ # Case 1.1: Content is a string+ (+ "case-1.1-string",+ "Lorem Ipsum",+ "stuff_name",+ "stuff_code",+ Stuff(+ stuff_name="stuff_name",+ stuff_code="stuff_code",+ concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.TEXT),+ content=TextContent(text="Lorem Ipsum"),+ ),+ ),+ # Case 1.2: Content is a list of strings+ (+ "case-1.2-list-of-strings",+ ["Lorem Ipsum 1", "Lorem Ipsum 2", "Lorem Ipsum 3"],+ "stuff_name",+ "stuff_code",+ Stuff(+ stuff_name="stuff_name",+ stuff_code="stuff_code",+ concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.TEXT),+ content=ListContent(+ items=[+ TextContent(text="Lorem Ipsum 1"),+ TextContent(text="Lorem Ipsum 2"),+ TextContent(text="Lorem Ipsum 3"),+ ]),),- # Case 1.2: Content is a list of strings- (- "case-1.2-list-of-strings",- ["Lorem Ipsum 1", "Lorem Ipsum 2", "Lorem Ipsum 3"],- "stuff_name",- "stuff_code",- Stuff(- stuff_name="stuff_name",- stuff_code="stuff_code",- concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.TEXT),- content=ListContent(- items=[- TextContent(text="Lorem Ipsum 1"),- TextContent(text="Lorem Ipsum 2"),- TextContent(text="Lorem Ipsum 3"),- ]- ),+ ),+ # Case 1.3: Content is a StuffContent object+ (+ "case-1.3-stuff-content-object",+ MyConcept(arg1="arg1", arg2=1, arg3=MySubClass(arg4="arg4")),+ "stuff_name",+ "stuff_code",+ Stuff(+ stuff_code="stuff_code",+ stuff_name="stuff_name",+ concept=ConceptFactory.make(+ concept_code="MyConcept",+ domain="test_domain",+ description="Test concept for unit tests",+ structure_class_name="MyConcept",),+ content=MyConcept(arg1="arg1", arg2=1, arg3=MySubClass(arg4="arg4")),),- # Case 1.3: Content is a StuffContent object- (- "case-1.3-stuff-content-object",+ ),+ # Case 1.4: Content is a list of StuffContent objects+ (+ "case-1.4-list-of-stuff-content-objects",+ [MyConcept(arg1="arg1", arg2=1, arg3=MySubClass(arg4="arg4")),- "stuff_name",- "stuff_code",- Stuff(- stuff_code="stuff_code",- stuff_name="stuff_name",- concept=ConceptFactory.make(- concept_code="MyConcept",- domain="test_domain",- description="Test concept for unit tests",- structure_class_name="MyConcept",- ),- content=MyConcept(arg1="arg1", arg2=1, arg3=MySubClass(arg4="arg4")),+ MyConcept(arg1="arg1_2", arg2=2, arg3=MySubClass(arg4="arg4_2")),+ ],+ "stuff_name",+ "stuff_code",+ Stuff(+ stuff_name="stuff_name",+ stuff_code="stuff_code",+ concept=ConceptFactory.make(+ concept_code="MyConcept",+ domain="test_domain",+ description="Test concept for unit tests",+ structure_class_name="MyConcept",),- ),- # Case 1.4: Content is a list of StuffContent objects- (- "case-1.4-list-of-stuff-content-objects",- [- MyConcept(arg1="arg1", arg2=1, arg3=MySubClass(arg4="arg4")),- MyConcept(arg1="arg1_2", arg2=2, arg3=MySubClass(arg4="arg4_2")),- ],- "stuff_name",- "stuff_code",- Stuff(- stuff_name="stuff_name",- stuff_code="stuff_code",- concept=ConceptFactory.make(- concept_code="MyConcept",- domain="test_domain",- description="Test concept for unit tests",- structure_class_name="MyConcept",- ),- content=ListContent(- items=[- MyConcept(arg1="arg1", arg2=1, arg3=MySubClass(arg4="arg4")),- MyConcept(arg1="arg1_2", arg2=2, arg3=MySubClass(arg4="arg4_2")),- ]- ),+ content=ListContent(+ items=[+ MyConcept(arg1="arg1", arg2=1, arg3=MySubClass(arg4="arg4")),+ MyConcept(arg1="arg1_2", arg2=2, arg3=MySubClass(arg4="arg4_2")),+ ]),),- # Case 2.1: Content is a string- (- "case-2.1-dict-with-string-content",- {"concept": "Text", "content": "my text"},- "stuff_name",- "stuff_code",- Stuff(- stuff_name="stuff_name",- stuff_code="stuff_code",- concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.TEXT),- content=TextContent(text="my text"),- ),+ ),+ # Case 2.1: Content is a string+ (+ "case-2.1-dict-with-string-content",+ {"concept": "Text", "content": "my text"},+ "stuff_name",+ "stuff_code",+ Stuff(+ stuff_name="stuff_name",+ stuff_code="stuff_code",+ concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.TEXT),+ content=TextContent(text="my text"),),- # Case 2.1b: Content is a string with native prefix- (- "case-2.1b-dict-with-string-content-native-prefix",- {"concept": "native.Text", "content": "my text"},- "stuff_name",- "stuff_code",- Stuff(- stuff_code="stuff_code",- stuff_name="stuff_name",- concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.TEXT),- content=TextContent(text="my text"),- ),+ ),+ # Case 2.1b: Content is a string with native prefix+ (+ "case-2.1b-dict-with-string-content-native-prefix",+ {"concept": "native.Text", "content": "my text"},+ "stuff_name",+ "stuff_code",+ Stuff(+ stuff_code="stuff_code",+ stuff_name="stuff_name",+ concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.TEXT),+ content=TextContent(text="my text"),),- # case 2.1c: Content is a string but the concept is not native.Text, but a concept initiable by str- (- "case-2.1c-dict-with-string-content-not-native-text",- {"concept": "test_domain.MyConceptNotNativeText", "content": "my text"},- "stuff_name",- "stuff_code",- Stuff(- stuff_code="stuff_code",- stuff_name="stuff_name",- concept=ConceptFactory.make_from_blueprint(- domain="test_domain",- concept_code="MyConceptNotNativeText",- blueprint=ConceptBlueprint(- description="Test concept for unit tests",- ),- ),- content=TextContent(text="my text"),+ ),+ # case 2.1c: Content is a string but the concept is not native.Text, but a concept that refines Text+ (+ "case-2.1c-dict-with-string-content-not-native-text",+ {"concept": "test_domain.MyConceptNotNativeText", "content": "my text"},+ "stuff_name",+ "stuff_code",+ Stuff(+ stuff_code="stuff_code",+ stuff_name="stuff_name",+ concept=ConceptFactory.make(+ domain="test_domain",+ concept_code="MyConceptNotNativeText",+ description="Test concept for unit tests",+ structure_class_name="MyConceptNotNativeText",+ refines="native.Text",),+ content=TextContent(text="my text"),),- # Case 2.2: Content is a list of strings- (- "case-2.2-dict-with-list-of-strings",- {"concept": "Text", "content": ["text1", "text2", "text3"]},- "stuff_name",- "stuff_code",- Stuff(- stuff_name="stuff_name",- stuff_code="stuff_code",- concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.TEXT),- content=ListContent(- items=[- TextContent(text="text1"),- TextContent(text="text2"),- TextContent(text="text3"),- ]- ),+ ),+ # Case 2.2: Content is a list of strings+ (+ "case-2.2-dict-with-list-of-strings",+ {"concept": "Text", "content": ["text1", "text2", "text3"]},+ "stuff_name",+ "stuff_code",+ Stuff(+ stuff_name="stuff_name",+ stuff_code="stuff_code",+ concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.TEXT),+ content=ListContent(+ items=[+ TextContent(text="text1"),+ TextContent(text="text2"),+ TextContent(text="text3"),+ ]),),- # case 2.2b: Content is a list of strings but the concept is not native.Text, but a concept initiable by str- (- "case-2.2b-dict-with-list-of-strings-not-native-text",- {"concept": "test_domain.MyConceptNotNativeText", "content": ["text1", "text2", "text3"]},- "stuff_name",- "stuff_code",- Stuff(- stuff_code="stuff_code",- stuff_name="stuff_name",- concept=ConceptFactory.make_from_blueprint(- domain="test_domain",- concept_code="MyConceptNotNativeText",- blueprint=ConceptBlueprint(- description="Test concept for unit tests",- ),- ),- content=ListContent(- items=[- TextContent(text="text1"),- TextContent(text="text2"),- TextContent(text="text3"),- ]- ),+ ),+ # case 2.2b: Content is a list of strings but the concept is not native.Text, but a concept that refines Text+ (+ "case-2.2b-dict-with-list-of-strings-not-native-text",+ {"concept": "test_domain.MyConceptNotNativeText", "content": ["text1", "text2", "text3"]},+ "stuff_name",+ "stuff_code",+ Stuff(+ stuff_code="stuff_code",+ stuff_name="stuff_name",+ concept=ConceptFactory.make(+ domain="test_domain",+ concept_code="MyConceptNotNativeText",+ description="Test concept for unit tests",+ structure_class_name="MyConceptNotNativeText",+ refines="native.Text",+ ),+ content=ListContent(+ items=[+ TextContent(text="text1"),+ TextContent(text="text2"),+ TextContent(text="text3"),+ ]),),- # Case 2.3: Content is a StuffContent object- (- "case-2.3-dict-with-stuff-content-object",- {- "concept": "test_domain.MyConcept",- "content": MyConcept(arg1="arg1", arg2=1, arg3=MySubClass(arg4="arg4")),- },- "stuff_name",- "stuff_code",- Stuff(- stuff_code="stuff_code",- stuff_name="stuff_name",- concept=ConceptFactory.make(- concept_code="MyConcept",- domain="test_domain",- description="Test concept for unit tests",- structure_class_name="MyConcept",- ),- content=MyConcept(arg1="arg1", arg2=1, arg3=MySubClass(arg4="arg4")),+ ),+ # Case 2.3: Content is a StuffContent object+ (+ "case-2.3-dict-with-stuff-content-object",+ {+ "concept": "test_domain.MyConcept",+ "content": MyConcept(arg1="arg1", arg2=1, arg3=MySubClass(arg4="arg4")),+ },+ "stuff_name",+ "stuff_code",+ Stuff(+ stuff_code="stuff_code",+ stuff_name="stuff_name",+ concept=ConceptFactory.make(+ concept_code="MyConcept",+ domain="test_domain",+ description="Test concept for unit tests",+ structure_class_name="MyConcept",),+ content=MyConcept(arg1="arg1", arg2=1, arg3=MySubClass(arg4="arg4")),),- # Case 2.4: Content is a list of StuffContent objects- (- "case-2.4-dict-with-list-of-stuff-content-objects",- {- "concept": "test_domain.MyConcept",- "content": [+ ),+ # Case 2.4: Content is a list of StuffContent objects+ (+ "case-2.4-dict-with-list-of-stuff-content-objects",+ {+ "concept": "test_domain.MyConcept",+ "content": [+ MyConcept(arg1="arg1", arg2=1, arg3=MySubClass(arg4="arg4")),+ MyConcept(arg1="arg1_2", arg2=2, arg3=MySubClass(arg4="arg4_2")),+ ],+ },+ "stuff_name",+ "stuff_code",+ Stuff(+ stuff_name="stuff_name",+ stuff_code="stuff_code",+ concept=ConceptFactory.make(+ concept_code="MyConcept",+ domain="test_domain",+ description="Test concept for unit tests",+ structure_class_name="MyConcept",+ ),+ content=ListContent(+ items=[MyConcept(arg1="arg1", arg2=1, arg3=MySubClass(arg4="arg4")),MyConcept(arg1="arg1_2", arg2=2, arg3=MySubClass(arg4="arg4_2")),- ],+ ]+ ),+ ),+ ),+ # Case 2.5: Content is a dict+ (+ "case-2.5-dict-with-dict-content",+ {+ "concept": "test_domain.MyConcept",+ "content": {+ "arg1": "something",+ "arg2": 1,+ "arg3": {"arg4": "something else else"},},- "stuff_name",- "stuff_code",- Stuff(- stuff_name="stuff_name",- stuff_code="stuff_code",- concept=ConceptFactory.make(- concept_code="MyConcept",- domain="test_domain",- description="Test concept for unit tests",- structure_class_name="MyConcept",- ),- content=ListContent(- items=[- MyConcept(arg1="arg1", arg2=1, arg3=MySubClass(arg4="arg4")),- MyConcept(arg1="arg1_2", arg2=2, arg3=MySubClass(arg4="arg4_2")),- ]- ),+ },+ "stuff_name",+ "stuff_code",+ Stuff(+ stuff_code="stuff_code",+ stuff_name="stuff_name",+ concept=ConceptFactory.make(+ concept_code="MyConcept",+ domain="test_domain",+ description="Test concept for unit tests",+ structure_class_name="MyConcept",),+ content=MyConcept(arg1="something", arg2=1, arg3=MySubClass(arg4="something else else")),),- # Case 2.5: Content is a dict- (- "case-2.5-dict-with-dict-content",- {- "concept": "test_domain.MyConcept",- "content": {+ ),+ # Case 2.6: Content is a list of dicts+ (+ "case-2.6-dict-with-list-of-dicts",+ {+ "concept": "test_domain.MyConcept",+ "content": [+ {"arg1": "something","arg2": 1,"arg3": {"arg4": "something else else"},},- },- "stuff_name",- "stuff_code",- Stuff(- stuff_code="stuff_code",- stuff_name="stuff_name",- concept=ConceptFactory.make(- concept_code="MyConcept",- domain="test_domain",- description="Test concept for unit tests",- structure_class_name="MyConcept",- ),- content=MyConcept(arg1="something", arg2=1, arg3=MySubClass(arg4="something else else")),+ {+ "arg1": "something else",+ "arg2": 2,+ "arg3": {"arg4": "something else else else"},+ },+ ],+ },+ "stuff_name",+ "stuff_code",+ Stuff(+ stuff_name="stuff_name",+ stuff_code="stuff_code",+ concept=ConceptFactory.make(+ concept_code="MyConcept",+ domain="test_domain",+ description="Test concept for unit tests",+ structure_class_name="MyConcept",),- ),- # Case 2.6: Content is a list of dicts- (- "case-2.6-dict-with-list-of-dicts",- {- "concept": "test_domain.MyConcept",- "content": [- {- "arg1": "something",- "arg2": 1,- "arg3": {"arg4": "something else else"},- },- {- "arg1": "something else",- "arg2": 2,- "arg3": {"arg4": "something else else else"},- },- ],- },- "stuff_name",- "stuff_code",- Stuff(- stuff_name="stuff_name",- stuff_code="stuff_code",- concept=ConceptFactory.make(- concept_code="MyConcept",- domain="test_domain",- description="Test concept for unit tests",- structure_class_name="MyConcept",- ),- content=ListContent(- items=[- MyConcept(arg1="something", arg2=1, arg3=MySubClass(arg4="something else else")),- MyConcept(arg1="something else", arg2=2, arg3=MySubClass(arg4="something else else else")),- ]- ),+ content=ListContent(+ items=[+ MyConcept(arg1="something", arg2=1, arg3=MySubClass(arg4="something else else")),+ MyConcept(arg1="something else", arg2=2, arg3=MySubClass(arg4="something else else else")),+ ]),),- ]+ ),+]diff --git a/tests/unit/core/stuffs/test_stuff_factory_implicit_memory.py b/tests/unit/core/stuffs/test_stuff_factory_implicit_memory.pyindex f62a835ee..7f3e7219d 100644--- a/tests/unit/core/stuffs/test_stuff_factory_implicit_memory.py+++ b/tests/unit/core/stuffs/test_stuff_factory_implicit_memory.py@@ -1,24 +1,24 @@import os+from typing import Anyimport pytestfrom pipelex import logfrom pipelex.client.protocol import StuffContentOrData-from pipelex.core.concepts.concept_blueprint import ConceptBlueprintfrom pipelex.core.concepts.concept_factory import ConceptFactoryfrom pipelex.core.stuffs.structured_content import StructuredContentfrom pipelex.core.stuffs.stuff import Stufffrom pipelex.core.stuffs.stuff_factory import StuffFactoryfrom pipelex.hub import get_concept_libraryfrom pipelex.system.registries.class_registry_utils import ClassRegistryUtils-from tests.unit.core.stuffs.data import TestData+from tests.unit.core.stuffs.data import TEST_CASES@pytest.fixture(scope="class")def setup_test_concept():# Register the class in the class registryClassRegistryUtils.register_classes_in_file(- file_path=os.path.join(os.path.dirname(__file__), "test_stuff_factory_implicit_memory.py"),+ file_path=os.path.join(os.path.dirname(__file__), "data.py"),base_class=StructuredContent,is_include_imported=False,)@@ -37,51 +37,62 @@ def setup_test_concept():concept_library.add_new_concept(concept=concept)# Create a concept that is not native.Text but initiable by str- concept_not_native_text = ConceptFactory.make_from_blueprint(+ concept_not_native_text = ConceptFactory.make(domain="test_domain",concept_code="MyConceptNotNativeText",- blueprint=ConceptBlueprint(- description="Test concept for unit tests",- ),+ description="Test concept for unit tests",+ structure_class_name="MyConceptNotNativeText",+ refines="native.Text",)concept_library.add_new_concept(concept=concept_not_native_text)yield concept# Cleanup after test- concept_library.remove_concepts_by_codes(concept_codes=["MyConcept", "MyConceptNotNativeText"])+ concept_library.remove_concepts_by_concept_strings(concept_strings=["test_domain.MyConcept", "test_domain.MyConceptNotNativeText"])class TestStuffFactoryImplicitMemory:- """Test Case 1: Direct content without 'concept' key.-- This covers cases where stuff_content_or_data is directly:- - A string (1.1)- - A list of strings (1.2)- - A StuffContent object (1.3)- - A list of StuffContent objects (1.4)+ """Test StuffFactory with implicit memory input formats.++ This covers cases where stuff_content_or_data is:+ - Case 1: Direct content (no 'concept' key)+ - A string (1.1)+ - A list of strings (1.2)+ - A StuffContent object (1.3)+ - A list of StuffContent objects (1.4)+ - Case 2: Dict with 'concept' AND 'content' keys+ - String content (2.1, 2.1b, 2.1c)+ - List of strings (2.2, 2.2b)+ - StuffContent object (2.3)+ - List of StuffContent objects (2.4)+ - Dict content (2.5)+ - List of dicts (2.6)"""@pytest.mark.parametrize(("test_name", "stuff_content_or_data", "stuff_name", "stuff_code", "expected_stuff"),- TestData.CASE,+ TEST_CASES,)- def test_case(+ def test_implicit_memory_case(self,+ setup_test_concept: Any,test_name: str,stuff_content_or_data: StuffContentOrData,stuff_name: str,stuff_code: str,expected_stuff: Stuff,):- log.info(f"Test Case 1: Direct content without concept key. {test_name}")+ log.info(f"Testing case: {test_name}")log.debug(f"setup_test_concept: {setup_test_concept}")+result = StuffFactory.make_stuff_from_stuff_content_or_data(name=stuff_name,code=stuff_code,stuff_content_or_data=stuff_content_or_data,)- assert result == expected_stuff++ assert result == expected_stuff, f"Failed for test case: {test_name}"# class TestStuffFactoryImplicitMemoryEdgeCases:diff --git a/tests/unit/pipelex/core/concepts/concept/test_concept.py b/tests/unit/pipelex/core/concepts/concept/test_concept.pyindex 507fcf731..dcc9306f9 100644--- a/tests/unit/pipelex/core/concepts/concept/test_concept.py+++ b/tests/unit/pipelex/core/concepts/concept/test_concept.py@@ -344,3 +344,21 @@ class TestConcept:# Test same refinesassert Concept.are_concept_compatible(concept_5, concept_6, strict=False) is Trueassert Concept.are_concept_compatible(concept_5, concept_6, strict=True) is False++ def test_concept_refining_text_is_strictly_compatible(self):+ """Test that a concept created with .make() that refines native.Text is strictly compatible with Text."""+ # Create a concept that refines native.Text using ConceptFactory.make()+ concept_not_native_text = ConceptFactory.make(+ domain="test_domain",+ concept_code="MyConceptNotNativeText",+ description="Test concept for unit tests",+ structure_class_name="TextContent",+ refines="native.Text",+ )++ # Get the native Text concept+ text_concept = ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.TEXT)++ # A concept that refines Text should be strictly compatible with Text+ assert Concept.are_concept_compatible(concept_not_native_text, text_concept, strict=True) is True+ assert Concept.are_concept_compatible(concept_not_native_text, text_concept, strict=False) is Truediff --git a/tests/unit/pipelex/core/concepts/test_concept_find_image_field_paths.py b/tests/unit/pipelex/core/concepts/test_concept_find_image_field_paths.pyindex ce04ace92..16822aaff 100644--- a/tests/unit/pipelex/core/concepts/test_concept_find_image_field_paths.py+++ b/tests/unit/pipelex/core/concepts/test_concept_find_image_field_paths.py@@ -75,7 +75,7 @@ def register_test_concepts():# Cleanup: Remove test concepts from libraryconcept_strings = [concept.concept_string for concept in concepts_to_register]- concept_library.remove_concepts_by_codes(concept_strings)+ concept_library.remove_concepts_by_concept_strings(concept_strings)class TestConceptFindImageFieldPaths: