Skip to content

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.

Feature/concept refines text (#120)

Louis Choquel579bef147431
diff --git a/.cursor/rules/standards.mdc b/.cursor/rules/standards.mdc
index 4f768ea63..19972fed3 100644
--- a/.cursor/rules/standards.mdc
+++ b/.cursor/rules/standards.mdc
@@ -7,6 +7,10 @@ alwaysApply: true
This document outlines the coding standards and quality control procedures that must be followed when contributing to this project.
+## Style
+
+Always use type hints. Use the types with Uppercase first letter for types like Dict[], List[] etc.
+
## Code Quality Checks
### Linting and Type Checking
diff --git a/mkdocs.yml b/mkdocs.yml
index bbb0e67f8..db8593c33 100644
--- a/mkdocs.yml
+++ b/mkdocs.yml
@@ -39,8 +39,8 @@ extra:
link: https://github.com/Pipelex/pipelex
name: Pipelex on GitHub
- icon: fontawesome/brands/python
- link: https://pypi.org/project/kajson/
- name: kajson on PyPI
+ link: https://pypi.org/project/pipelex/
+ name: pipelex on PyPI
- icon: fontawesome/brands/twitter
link: https://x.com/PipelexAI
name: Pipelex on X
diff --git a/pipelex/core/concept_factory.py b/pipelex/core/concept_factory.py
index e078cf885..f59d3d6f9 100644
--- a/pipelex/core/concept_factory.py
+++ b/pipelex/core/concept_factory.py
@@ -72,7 +72,11 @@ class ConceptFactory:
raise ConceptFactoryError(f"Concept '{code}' in domain '{domain_code}' has no definition")
details_dict["definition"] = concept_definition
details_dict["domain"] = domain_code
- details_dict["refines"] = ConceptFactory.make_refines(domain=domain_code, refines=details_dict.pop("refines", []))
+ refines = ConceptFactory.make_refines(domain=domain_code, refines=details_dict.pop("refines", []))
+ if not refines and not details_dict.get("structure"):
+ # No structure? this refines Text
+ refines = [NativeConcept.TEXT.code]
+ details_dict["refines"] = refines
concept_blueprint = ConceptBlueprint.model_validate(details_dict)
the_concept = ConceptFactory.make_concept_from_blueprint(domain=domain_code, code=code, concept_blueprint=concept_blueprint)
return the_concept
@@ -90,19 +94,18 @@ class ConceptFactory:
structure_class_name = code
else:
structure_class_name = TextContent.__name__
- # TODO: why use a dict to create a concept? it makes no sense
- # TODO: don't wall make_concept_code from the factory, the code received here must already be a valid concept code
- concept_dict = {
- "domain": domain_code,
- "code": ConceptCodeFactory.make_concept_code(domain_code, code),
- "definition": definition,
- "structure_class_name": structure_class_name,
- }
+
try:
- the_concept = Concept.model_validate(concept_dict)
+ the_concept = Concept(
+ code=ConceptCodeFactory.make_concept_code(domain_code, code),
+ domain=domain_code,
+ definition=definition,
+ structure_class_name=structure_class_name,
+ refines=[NativeConcept.TEXT.code],
+ )
+ return Concept.model_validate(the_concept)
except ValidationError as e:
raise ConceptFactoryError(f"Error validating concept: {e}") from e
- return the_concept
@classmethod
def make_concept_from_blueprint(
diff --git a/pipelex/core/stuff.py b/pipelex/core/stuff.py
index dbef01262..e5c960052 100644
--- a/pipelex/core/stuff.py
+++ b/pipelex/core/stuff.py
@@ -140,6 +140,11 @@ class Stuff(CustomBaseModel):
"""Get content as TextContent if applicable."""
return self.content_as(TextContent)
+ @property
+ def as_str(self) -> str:
+ """Get content as string if applicable."""
+ return self.as_text.text
+
@property
def as_image(self) -> ImageContent:
"""Get content as ImageContent if applicable."""
diff --git a/pipelex/libraries/llm_deck/base_llm_deck.toml b/pipelex/libraries/llm_deck/base_llm_deck.toml
index cef1161a7..205f962f7 100644
--- a/pipelex/libraries/llm_deck/base_llm_deck.toml
+++ b/pipelex/libraries/llm_deck/base_llm_deck.toml
@@ -21,7 +21,7 @@ best-grok = "grok-3"
####################################################################################################
# LLM Presets — General purpose
-cheap_llm_for_text = { llm_handle = "gpt-4o-mini", temperature = 0.5, max_tokens = 50 }
+cheap_llm_for_text = { llm_handle = "gpt-4o-mini", temperature = 0.5 }
cheap_llm_for_short_text = { llm_handle = "gpt-4o-mini", temperature = 0.5, max_tokens = 50 }
cheap_llm_for_object = { llm_handle = "gpt-4o-mini", temperature = 0.5 }
cheap_llm_to_structure = { llm_handle = "gpt-4o-mini", temperature = 0.1 }
diff --git a/pyproject.toml b/pyproject.toml
index 9e342ef82..b833e63ed 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -24,7 +24,7 @@ dependencies = [
"instructor>=1.8.3",
"jinja2>=3.1.4",
"json2html>=1.3.0",
- "kajson==0.2.0",
+ "kajson==0.2.2",
"markdown>=3.6",
"networkx>=3.4.2",
"openai>=1.60.1",
diff --git a/uv.lock b/uv.lock
index 46e72f85e..315a1cef6 100644
--- a/uv.lock
+++ b/uv.lock
@@ -889,14 +889,14 @@ wheels = [
[[package]]
name = "kajson"
-version = "0.2.0"
+version = "0.2.2"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "pydantic" },
]
-sdist = { url = "https://files.pythonhosted.org/packages/8a/b5/404dda6ea283cba04e408d4447466a14863586f6872f87d70883e32ac48a/kajson-0.2.0.tar.gz", hash = "sha256:1dbe9595ef70a6cb1e3fdfc28fa6f1f3e361bbdfb03b0a4ca525f3f6f6100b92", size = 18178, upload-time = "2025-06-23T09:05:15.665Z" }
+sdist = { url = "https://files.pythonhosted.org/packages/0b/90/997c2bf6c47714e1655ac7cbb718317b815c9155634148625f93faad8520/kajson-0.2.2.tar.gz", hash = "sha256:2a7d71a772d12303b398e1d6ec35fd6213fc0d23861ed860beb201105721a498", size = 19792, upload-time = "2025-06-26T10:56:01.675Z" }
wheels = [
- { url = "https://files.pythonhosted.org/packages/1e/da/8942c19fb6806d29d8769059a2f5f0a19bd9cbaadaaad725dd1aae8efa78/kajson-0.2.0-py3-none-any.whl", hash = "sha256:1221d4d3be54033f97642c4df9a7144d086a49d95f1f2adeb975308e671c5ac9", size = 24219, upload-time = "2025-06-23T09:05:14.193Z" },
+ { url = "https://files.pythonhosted.org/packages/cb/ef/9b4a1bf8b7e9fcff9450be3ed7ce69738cf7c3ef58b057385fac73eb60a1/kajson-0.2.2-py3-none-any.whl", hash = "sha256:5b1b77dab1be2af2904f9872e24e66289adeafdf1017705e1f7e0e87a1fbe6b6", size = 25863, upload-time = "2025-06-26T10:56:00.257Z" },
]
[[package]]
@@ -1619,7 +1619,7 @@ wheels = [
[[package]]
name = "pipelex"
-version = "0.4.4"
+version = "0.4.6"
source = { editable = "." }
dependencies = [
{ name = "aiofiles" },
@@ -1713,7 +1713,7 @@ requires-dist = [
{ name = "instructor", specifier = ">=1.8.3" },
{ name = "jinja2", specifier = ">=3.1.4" },
{ name = "json2html", specifier = ">=1.3.0" },
- { name = "kajson", specifier = "==0.2.0" },
+ { name = "kajson", specifier = "==0.2.2" },
{ name = "markdown", specifier = ">=3.6" },
{ name = "mistralai", marker = "extra == 'mistralai'", specifier = "==1.5.2" },
{ name = "mkdocs", marker = "extra == 'docs'", specifier = "==1.6.1" },