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 lint
thomashebrard851bccf25971
diff --git a/pipelex/client/protocol.py b/pipelex/client/protocol.pyindex 59784c953..f56d536b4 100644--- a/pipelex/client/protocol.py+++ b/pipelex/client/protocol.py@@ -25,14 +25,15 @@ from pipelex.types import StrEnum# - 2.3: {"concept": str, "content": StuffContent}# - 2.4: {"concept": str, "content": Sequence[StuffContent]}# - 2.5: {"concept": str, "content": dict[str, Any]}-# - 2.6: {"concept": str, "content": Sequence[dict[str, Any]]}-# - 2.7: DictStuff {"concept": str, "content": Any}+# - 2.6: {"concept": str, "content": Sequence[dict[str, Any]}+# Note: Case 2 formats can be provided as plain dict or DictStuff instanceStuffContentOrData = (str # Case 1.1| Sequence[str] # Case 1.2| StuffContent # Case 1.3 (also covers Case 1.5 as ListContent is a StuffContent)| Sequence[StuffContent] # Case 1.4 (covariant - accepts list[TextContent], etc.)- | dict[str, Any] # Case 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7 (both plain dicts and DictStuff format)+ | dict[str, Any] # Case 2.1-2.7 - plain dicts with {"concept": str, "content": Any} structure+ | DictStuff # Case 2.7 - DictStuff instances (same structure as dict but as Pydantic model))PipelineInputs = dict[str, StuffContentOrData] # Can include both dict and StuffContentdiff --git a/pipelex/core/stuffs/stuff.py b/pipelex/core/stuffs/stuff.pyindex 9cadb8b5a..f32ccaa71 100644--- a/pipelex/core/stuffs/stuff.py+++ b/pipelex/core/stuffs/stuff.py@@ -202,4 +202,4 @@ class DictStuff(CustomBaseModel):model_config = ConfigDict(extra="forbid", strict=True)concept: str- content: dict[str, Any]+ content: Anydiff --git a/pipelex/core/stuffs/stuff_factory.py b/pipelex/core/stuffs/stuff_factory.pyindex 0834619f4..85a9d2c90 100644--- a/pipelex/core/stuffs/stuff_factory.py+++ b/pipelex/core/stuffs/stuff_factory.py@@ -11,7 +11,7 @@ from pipelex.core.concepts.concept_library import ConceptLibraryConceptNotFoundEfrom pipelex.core.concepts.concept_native import NativeConceptCodefrom pipelex.core.stuffs.list_content import ListContentfrom pipelex.core.stuffs.structured_content import StructuredContent-from pipelex.core.stuffs.stuff import Stuff+from pipelex.core.stuffs.stuff import DictStuff, Stufffrom pipelex.core.stuffs.stuff_content import StuffContentfrom pipelex.core.stuffs.text_content import TextContentfrom pipelex.exceptions import PipelexException@@ -140,7 +140,7 @@ class StuffFactory:Note: StructuredContent (1.3) and ListContent (1.5) are separate cases at the same level.Both inherit from StuffContent but handle different content types.- Case 2: Dict with 'concept' AND 'content' keys+ Case 2: Dict with 'concept' AND 'content' keys (can be plain dict or DictStuff instance)2.1/2.1b: {"concept": "Text"/"native.Text", "content": str} → TextContent with Text concept2.1c: {"concept": "domain.Concept", "content": str} → TextContent with that concept (if compatible)2.2/2.2b: {"concept": "...", "content": list[str]} → ListContent[TextContent]@@ -148,8 +148,6 @@ class StuffFactory:2.4: {"concept": "...", "content": list[StuffContent]} → ListContent[StuffContent]2.5: {"concept": "...", "content": dict} → Create StuffContent from dict2.6: {"concept": "...", "content": list[dict]} → ListContent[StuffContent] from dicts- 2.7: DictStuff (full stuff dict with stuff_code, stuff_name, concept, content) → Create Stuff from all fields- Note: If both stuff_name in dict and name argument are provided, they must match exactly"""concept_library = get_concept_library()@@ -315,6 +313,10 @@ class StuffFactory:raise StuffFactoryError(msg)# ==================== CASE 2: Dict with 'concept' AND 'content' keys ====================+ # Convert DictStuff instance to plain dict if needed+ if isinstance(stuff_content_or_data, DictStuff):+ stuff_content_or_data = stuff_content_or_data.model_dump()+if not isinstance(stuff_content_or_data, dict):msg = f"Unexpected type for stuff_content_or_data: {type(stuff_content_or_data)}.Type should be {StuffContentOrData}."raise StuffFactoryError(msg)@@ -328,55 +330,7 @@ class StuffFactory:msg = f"Trying to create a Stuff '{name}' from a dict that should represent a StuffContentOrData but does not have a 'content' key."raise StuffFactoryError(msg)- # Case 2.7: DictStuff - full stuff dict with stuff_code, stuff_name, concept, content- if "stuff_code" in stuff_content_or_data:- # This is a DictStuff - it has all the fields of a Stuff- if len(stuff_content_or_data) not in (3, 4): # 3 if no stuff_name, 4 if stuff_name present- msg = (- f"Trying to create a Stuff '{name}' from a DictStuff but it does not have the correct keys. "- "Expected keys: 'stuff_code', 'concept', 'content', and optionally 'stuff_name'."- )- raise StuffFactoryError(msg)-- concept_string = stuff_content_or_data.concept- content = stuff_content_or_data.content-- # Get the concept from the library- try:- concept = concept_library.get_required_concept_from_concept_string_or_code(- concept_string_or_code=concept_string, search_domains=search_domains- )- except ConceptLibraryConceptNotFoundError as exc:- msg = f"Trying to create a Stuff from a DictStuff but the concept of name '{concept_string}' is not found in the library"- raise StuffFactoryError(msg) from exc-- # Handle content based on type (similar to Case 2.5 for dict content)- if isinstance(content, dict):- the_class = get_class_registry().get_class(name=concept.structure_class_name)- if the_class is None:- msg = (- f"Trying to create a Stuff from a DictStuff but the concept of name '{concept_string}' is not compatible with a dict content"- )- raise StuffFactoryError(msg)-- return cls.make_stuff(- name=name,- concept=concept,- content=the_class.model_validate(obj=content),- )- else:- # Content might be other types (str, list, etc.) - handle recursively- stuff_content = StuffContentFactory.make_stuff_content_from_concept_with_fallback(- concept=concept,- value=content,- )- return cls.make_stuff(- name=name,- concept=concept,- content=stuff_content,- )-- # ReducedDictStuff - only concept and content+ # All Case 2 variants - dict with concept and contentif len(stuff_content_or_data) != 2:msg = (f"Trying to create a Stuff '{name}' from a dict that should represent a StuffContentOrData but does not have "diff --git a/tests/unit/core/stuffs/data.py b/tests/unit/core/stuffs/data.pyindex aa7a6da22..cde07771e 100644--- a/tests/unit/core/stuffs/data.py+++ b/tests/unit/core/stuffs/data.py@@ -5,7 +5,7 @@ from pipelex.core.concepts.concept_factory import ConceptFactoryfrom pipelex.core.concepts.concept_native import NativeConceptCodefrom pipelex.core.stuffs.list_content import ListContentfrom pipelex.core.stuffs.structured_content import StructuredContent-from pipelex.core.stuffs.stuff import Stuff+from pipelex.core.stuffs.stuff import DictStuff, Stufffrom pipelex.core.stuffs.text_content import TextContent@@ -367,85 +367,104 @@ TEST_CASES: list[tuple[str, StuffContentOrData, str | None, str, Stuff]] = [),),),- # Case 2.7: DictStuff with all fields (stuff_code, stuff_name, concept, content)- # Note: name argument must match stuff_name in dict if both are provided+ # Case 2.7: DictStuff instance with simple dict content(- "case-2.7-dict-stuff-with-stuff-name",- {- "stuff_code": "custom_code",- "stuff_name": "custom_name",- "concept": "test_domain.MyConcept",- "content": {- "arg1": "something",- "arg2": 1,- "arg3": {"arg4": "something else"},+ "case-2.7-dictstuff-instance-simple",+ DictStuff(+ concept="test_domain.MyConcept",+ content={+ "arg1": "from DictStuff",+ "arg2": 999,+ "arg3": {"arg4": "nested in DictStuff"},},- },- "custom_name", # Must match the stuff_name in the dict- "ignored_code",+ ),+ "stuff_name",+ "stuff_code",Stuff(- stuff_code="custom_code",- stuff_name="custom_name",+ 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=MyConcept(arg1="something", arg2=1, arg3=MySubClass(arg4="something else")),+ content=MyConcept(arg1="from DictStuff", arg2=999, arg3=MySubClass(arg4="nested in DictStuff")),),),- # Case 2.7a: DictStuff with stuff_name, but name argument is None+ # Case 2.8: DictStuff instance with native concept(- "case-2.7a-dict-stuff-with-stuff-name-no-arg",- {- "stuff_code": "custom_code_a",- "stuff_name": "custom_name_a",- "concept": "test_domain.MyConcept",- "content": {- "arg1": "something",- "arg2": 1,- "arg3": {"arg4": "something else"},- },- },- None, # name argument is None, so dict's stuff_name is used- "ignored_code",+ "case-2.8-dictstuff-instance-native",+ DictStuff(+ concept="Text",+ content={"text": "Hello from DictStuff"},+ ),+ "stuff_name",+ "stuff_code",Stuff(- stuff_code="custom_code_a",- stuff_name="custom_name_a",+ stuff_name="stuff_name",+ stuff_code="stuff_code",+ concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.TEXT),+ content=TextContent(text="Hello from DictStuff"),+ ),+ ),+ # Case 2.9: DictStuff instance with list of dicts+ (+ "case-2.9-dictstuff-instance-list-dicts",+ DictStuff(+ concept="test_domain.MyConcept",+ content=[+ {+ "arg1": "item1",+ "arg2": 10,+ "arg3": {"arg4": "sub1"},+ },+ {+ "arg1": "item2",+ "arg2": 20,+ "arg3": {"arg4": "sub2"},+ },+ ],+ ),+ "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=MyConcept(arg1="something", arg2=1, arg3=MySubClass(arg4="something else")),+ content=ListContent(+ items=[+ MyConcept(arg1="item1", arg2=10, arg3=MySubClass(arg4="sub1")),+ MyConcept(arg1="item2", arg2=20, arg3=MySubClass(arg4="sub2")),+ ]+ ),),),- # Case 2.7b: DictStuff without stuff_name (only 3 keys)+ # Case 2.10: DictStuff instance with list of strings (Text concept)(- "case-2.7b-dict-stuff-without-stuff-name",- {- "stuff_code": "custom_code_2",- "concept": "test_domain.MyConcept",- "content": {- "arg1": "arg1_value",- "arg2": 42,- "arg3": {"arg4": "arg4_value"},- },- },- "fallback_name",- "ignored_code",+ "case-2.10-dictstuff-instance-list-strings",+ DictStuff(+ concept="Text",+ content=["text1", "text2", "text3"],+ ),+ "stuff_name",+ "stuff_code",Stuff(- stuff_code="custom_code_2",- stuff_name="fallback_name",- concept=ConceptFactory.make(- concept_code="MyConcept",- domain="test_domain",- description="Test concept for unit tests",- structure_class_name="MyConcept",+ 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"),+ ]),- content=MyConcept(arg1="arg1_value", arg2=42, arg3=MySubClass(arg4="arg4_value")),),),]@@ -656,67 +675,4 @@ ERROR_TEST_CASES: list[tuple[str, StuffContentOrData, str | None, str, list[str]Exception,"not compatible",),- # DictStuff with wrong number of keys - should fail- (- "error-dict-stuff-wrong-keys",- {- "stuff_code": "code",- "concept": "Text",- "content": "text",- "extra": "key",- "another": "key",- },- "stuff_name",- "stuff_code",- None,- Exception,- "correct keys",- ),- # DictStuff with missing concept - should fail- (- "error-dict-stuff-missing-concept",- {- "stuff_code": "code",- "stuff_name": "name",- "content": {"field": "value"},- },- "stuff_name",- "stuff_code",- None,- Exception,- "'concept' key",- ),- # DictStuff with concept not found - should fail- (- "error-dict-stuff-concept-not-found",- {- "stuff_code": "code",- "concept": "NonExistentConcept",- "content": {"field": "value"},- },- "stuff_name",- "stuff_code",- None,- Exception,- "not found",- ),- # DictStuff with mismatched stuff_name - should fail- (- "error-dict-stuff-name-mismatch",- {- "stuff_code": "code",- "stuff_name": "name_in_dict",- "concept": "test_domain.MyConcept",- "content": {- "arg1": "arg1",- "arg2": 1,- "arg3": {"arg4": "arg4"},- },- },- "different_name", # Does not match "name_in_dict"- "stuff_code",- ["test_domain"],- Exception,- "does not match",- ),]diff --git a/tests/unit/core/stuffs/test_stuff_factory_implicit_memory.py b/tests/unit/core/stuffs/test_stuff_factory_implicit_memory.pyindex ddd228013..9383f27d8 100644--- a/tests/unit/core/stuffs/test_stuff_factory_implicit_memory.py+++ b/tests/unit/core/stuffs/test_stuff_factory_implicit_memory.py@@ -75,14 +75,13 @@ class TestStuffFactoryImplicitMemory:- StuffContent object - custom (1.3 / 1.3a)- ListContent of StuffContent objects (1.3b, formerly 1.5)- List of StuffContent objects (1.4)- - Case 2: Dict with 'concept' AND 'content' keys+ - Case 2: Dict with 'concept' AND 'content' keys (plain dict or DictStuff)- 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)- - DictStuff with all fields (2.7)"""@pytest.mark.parametrize(