Skip to content

Commit 579bef1

Browse files
authored
Feature/concept refines text (Pipelex#120)
1 parent 29de36c commit 579bef1

7 files changed

Lines changed: 32 additions & 20 deletions

File tree

.cursor/rules/standards.mdc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ alwaysApply: true
77

88
This document outlines the coding standards and quality control procedures that must be followed when contributing to this project.
99

10+
## Style
11+
12+
Always use type hints. Use the types with Uppercase first letter for types like Dict[], List[] etc.
13+
1014
## Code Quality Checks
1115

1216
### Linting and Type Checking

mkdocs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ extra:
3939
link: https://github.com/Pipelex/pipelex
4040
name: Pipelex on GitHub
4141
- icon: fontawesome/brands/python
42-
link: https://pypi.org/project/kajson/
43-
name: kajson on PyPI
42+
link: https://pypi.org/project/pipelex/
43+
name: pipelex on PyPI
4444
- icon: fontawesome/brands/twitter
4545
link: https://x.com/PipelexAI
4646
name: Pipelex on X

pipelex/core/concept_factory.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@ def make_from_details_dict(
7272
raise ConceptFactoryError(f"Concept '{code}' in domain '{domain_code}' has no definition")
7373
details_dict["definition"] = concept_definition
7474
details_dict["domain"] = domain_code
75-
details_dict["refines"] = ConceptFactory.make_refines(domain=domain_code, refines=details_dict.pop("refines", []))
75+
refines = ConceptFactory.make_refines(domain=domain_code, refines=details_dict.pop("refines", []))
76+
if not refines and not details_dict.get("structure"):
77+
# No structure? this refines Text
78+
refines = [NativeConcept.TEXT.code]
79+
details_dict["refines"] = refines
7680
concept_blueprint = ConceptBlueprint.model_validate(details_dict)
7781
the_concept = ConceptFactory.make_concept_from_blueprint(domain=domain_code, code=code, concept_blueprint=concept_blueprint)
7882
return the_concept
@@ -90,19 +94,18 @@ def make_concept_from_definition(
9094
structure_class_name = code
9195
else:
9296
structure_class_name = TextContent.__name__
93-
# TODO: why use a dict to create a concept? it makes no sense
94-
# TODO: don't wall make_concept_code from the factory, the code received here must already be a valid concept code
95-
concept_dict = {
96-
"domain": domain_code,
97-
"code": ConceptCodeFactory.make_concept_code(domain_code, code),
98-
"definition": definition,
99-
"structure_class_name": structure_class_name,
100-
}
97+
10198
try:
102-
the_concept = Concept.model_validate(concept_dict)
99+
the_concept = Concept(
100+
code=ConceptCodeFactory.make_concept_code(domain_code, code),
101+
domain=domain_code,
102+
definition=definition,
103+
structure_class_name=structure_class_name,
104+
refines=[NativeConcept.TEXT.code],
105+
)
106+
return Concept.model_validate(the_concept)
103107
except ValidationError as e:
104108
raise ConceptFactoryError(f"Error validating concept: {e}") from e
105-
return the_concept
106109

107110
@classmethod
108111
def make_concept_from_blueprint(

pipelex/core/stuff.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ def as_text(self) -> TextContent:
140140
"""Get content as TextContent if applicable."""
141141
return self.content_as(TextContent)
142142

143+
@property
144+
def as_str(self) -> str:
145+
"""Get content as string if applicable."""
146+
return self.as_text.text
147+
143148
@property
144149
def as_image(self) -> ImageContent:
145150
"""Get content as ImageContent if applicable."""

pipelex/libraries/llm_deck/base_llm_deck.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ best-grok = "grok-3"
2121
####################################################################################################
2222
# LLM Presets — General purpose
2323

24-
cheap_llm_for_text = { llm_handle = "gpt-4o-mini", temperature = 0.5, max_tokens = 50 }
24+
cheap_llm_for_text = { llm_handle = "gpt-4o-mini", temperature = 0.5 }
2525
cheap_llm_for_short_text = { llm_handle = "gpt-4o-mini", temperature = 0.5, max_tokens = 50 }
2626
cheap_llm_for_object = { llm_handle = "gpt-4o-mini", temperature = 0.5 }
2727
cheap_llm_to_structure = { llm_handle = "gpt-4o-mini", temperature = 0.1 }

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ dependencies = [
2424
"instructor>=1.8.3",
2525
"jinja2>=3.1.4",
2626
"json2html>=1.3.0",
27-
"kajson==0.2.0",
27+
"kajson==0.2.2",
2828
"markdown>=3.6",
2929
"networkx>=3.4.2",
3030
"openai>=1.60.1",

uv.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)