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.

Refactor/rename Ocr to Extract (#345)

Louis Choquelf4f01b99f0ee
diff --git a/.cursor/rules/pipelex.mdc b/.cursor/rules/pipelex.mdc
index 5dcea3bff..eaac0d687 100644
--- a/.cursor/rules/pipelex.mdc
+++ b/.cursor/rules/pipelex.mdc
@@ -164,7 +164,7 @@ Look at the Pipes we have in order to adapt it. Pipes are organized in two categ
2. **Operators** - For specific tasks:
- `PipeLLM` - Generate Text and Objects (include Vision LLM)
- - `PipeOcr` - Extract text and images from an image or a PDF
+ - `PipeExtract` - Extract text and images from an image or a PDF
- `PipeCompose` - For composing text using Jinja2 templates: supports html, markdown, mermaid, etc.
- `PipeImgGen` - Generate Images
- `PipeFunc` - For running classic python scripts
@@ -355,14 +355,14 @@ prompt_template = "Describe what you see in this image"
## Purpose
-The PipeOcr operator is used to extract text and images from an image or a PDF
+The PipeExtract operator is used to extract text and images from an image or a PDF
## Basic Usage
### Simple Text Extraction
```plx
[pipe.extract_info]
-type = "PipeOcr"
+type = "PipeExtract"
description = "extract the information"
inputs = { document = "PDF" } # or { image = "Image" } if it's an image. This is the only input.
output = "Page"
@@ -371,7 +371,7 @@ output = "Page"
Only one input is allowed and it must either be an `Image` or a `PDF`.
The output concept `Page` is a native concept, with the structure `PageContent`:
-It corresponds to 1 page. Therefore, the PipeOcr is outputing a `ListContent` of `Page`
+It corresponds to 1 page. Therefore, the PipeExtract is outputing a `ListContent` of `Page`
```python
class TextAndImagesContent(StuffContent):
diff --git a/.cursor/rules/pytest.mdc b/.cursor/rules/pytest.mdc
index 53db2a504..89a009295 100644
--- a/.cursor/rules/pytest.mdc
+++ b/.cursor/rules/pytest.mdc
@@ -31,6 +31,7 @@ These rules apply when writing unit tests.
Apply the appropriate markers:
- "llm: uses an LLM to generate text or objects"
- "img_gen: uses an image generation AI"
+- "extract: uses ocr models"
- "inference: uses either an LLM or an image generation AI"
- "gha_disabled: will not be able to run properly on GitHub Actions"
diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md
index 91824da96..e4413335f 100644
--- a/.github/copilot-instructions.md
+++ b/.github/copilot-instructions.md
@@ -285,7 +285,7 @@ Look at the Pipes we have in order to adapt it. Pipes are organized in two categ
2. **Operators** - For specific tasks:
- `PipeLLM` - Generate Text and Objects (include Vision LLM)
- - `PipeOcr` - Extract text and images from an image or a PDF
+ - `PipeExtract` - Extract text and images from an image or a PDF
- `PipeCompose` - For composing text using Jinja2 templates: supports html, markdown, mermaid, etc.
- `PipeImgGen` - Generate Images
- `PipeFunc` - For running classic python scripts
@@ -495,14 +495,14 @@ DO NOT write "$topic" alone in an isolated line.
DO write things like "Write an essay about $topic" to include text into an actual sentence.
-## PipeOcr operator
+## PipeExtract operator
-The PipeOcr operator is used to extract text and images from an image or a PDF
+The PipeExtract operator is used to extract text and images from an image or a PDF
### Simple Text Extraction
```plx
[pipe.extract_info]
-type = "PipeOcr"
+type = "PipeExtract"
description = "extract the information"
inputs = { document = "PDF" } # or { image = "Image" } if it's an image. This is the only input.
output = "Page"
@@ -511,7 +511,7 @@ output = "Page"
Only one input is allowed and it must either be an `Image` or a `PDF`.
The output concept `Page` is a native concept, with the structure `PageContent`:
-It corresponds to 1 page. Therefore, the PipeOcr is outputing a `ListContent` of `Page`
+It corresponds to 1 page. Therefore, the PipeExtract is outputing a `ListContent` of `Page`
```python
class TextAndImagesContent(StuffContent):
@@ -1113,6 +1113,7 @@ NEVER USE unittest.mock or MagicMock. YOU MUST USE pytest-mock instead.
Apply the appropriate markers:
- "llm: uses an LLM to generate text or objects"
- "img_gen: uses an image generation AI"
+- "extract: uses ocr models"
- "inference: uses either an LLM or an image generation AI"
- "gha_disabled: will not be able to run properly on GitHub Actions"
diff --git a/.pipelex/inference/deck/base_deck.toml b/.pipelex/inference/deck/base_deck.toml
index 808f9de31..90dbc838d 100644
--- a/.pipelex/inference/deck/base_deck.toml
+++ b/.pipelex/inference/deck/base_deck.toml
@@ -110,12 +110,12 @@ for_object = "cheap_llm_for_object"
# OCR Presets
####################################################################################################
-[ocr]
+[extract]
choice_default = "base_ocr_mistral"
-[ocr.presets]
-base_ocr_mistral = { ocr_handle = "mistral-ocr", max_nb_images = 100, image_min_size = 50 }
-base_ocr_pypdfium2 = { ocr_handle = "pypdfium2-extract-text", max_nb_images = 100, image_min_size = 50 }
+[extract.presets]
+base_ocr_mistral = { extract_handle = "mistral-ocr", max_nb_images = 100, image_min_size = 50 }
+base_extract_pypdfium2 = { extract_handle = "pypdfium2-extract-text", max_nb_images = 100, image_min_size = 50 }
####################################################################################################
# Image Generation Presets
diff --git a/.pipelex/pipelex.toml b/.pipelex/pipelex.toml
index 788e7dab1..dddcbf095 100644
--- a/.pipelex/pipelex.toml
+++ b/.pipelex/pipelex.toml
@@ -14,7 +14,7 @@ api_key_method = "env"
# OCR config
####################################################################################################
-[cogt.ocr_config]
+[cogt.extract_config]
page_output_text_file_name = "page_text.md"
[pipelex.feature_config]
diff --git a/AGENTS.md b/AGENTS.md
index 91824da96..e2f4adf85 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -285,7 +285,7 @@ Look at the Pipes we have in order to adapt it. Pipes are organized in two categ
2. **Operators** - For specific tasks:
- `PipeLLM` - Generate Text and Objects (include Vision LLM)
- - `PipeOcr` - Extract text and images from an image or a PDF
+ - `PipeExtract` - Extract text and images from an image or a PDF
- `PipeCompose` - For composing text using Jinja2 templates: supports html, markdown, mermaid, etc.
- `PipeImgGen` - Generate Images
- `PipeFunc` - For running classic python scripts
@@ -495,14 +495,14 @@ DO NOT write "$topic" alone in an isolated line.
DO write things like "Write an essay about $topic" to include text into an actual sentence.
-## PipeOcr operator
+## PipeExtract operator
-The PipeOcr operator is used to extract text and images from an image or a PDF
+The PipeExtract operator is used to extract text and images from an image or a PDF
### Simple Text Extraction
```plx
[pipe.extract_info]
-type = "PipeOcr"
+type = "PipeExtract"
description = "extract the information"
inputs = { document = "PDF" } # or { image = "Image" } if it's an image. This is the only input.
output = "Page"
@@ -511,7 +511,7 @@ output = "Page"
Only one input is allowed and it must either be an `Image` or a `PDF`.
The output concept `Page` is a native concept, with the structure `PageContent`:
-It corresponds to 1 page. Therefore, the PipeOcr is outputing a `ListContent` of `Page`
+It corresponds to 1 page. Therefore, the PipeExtract is outputing a `ListContent` of `Page`
```python
class TextAndImagesContent(StuffContent):
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d22ec5c4b..f2bdec807 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -113,7 +113,7 @@
### Changed
- ⚠️ Breaking changes:
- - Renamed `ocr_handle` to `ocr_model` in `PipeOcr` blueprint, so you'll need to update your PLX code accordingly
+ - Renamed `ocr_handle` to `ocr_model` in `PipeExtract` blueprint, so you'll need to update your PLX code accordingly
- Updated .env.example file with slightly modified key names (more standard).
- OCR system now uses InferenceModelSpec with unified model handles
- Renamed `get_llm_deck()` to `get_model_deck()` and updated parameter names from `llm_handle` to `model_handle`
@@ -379,7 +379,7 @@ Simplified input memory:
- Refactored `PipeInput` to use `InputRequirement` and `TypedNamedInputRequirement` classes instead of plain strings for input specifications.
- Updated `WorkingMemoryFactory` to handle `ImplicitMemory` instead of `CompactMemory`.
- Replaced `ExecutePipelineException` with `PipelineInputError` in `execute_pipeline` function.
-- Updated `PipeBatch`, `PipeCondition`, `PipeParallel`, `PipeSequence`, `PipeFunc`, `PipeImgGen`, `PipeCompose`, `PipeLLM`, and `PipeOcr` classes to use `InputRequirement` for input handling.
+- Updated `PipeBatch`, `PipeCondition`, `PipeParallel`, `PipeSequence`, `PipeFunc`, `PipeImgGen`, `PipeCompose`, `PipeLLM`, and `PipeExtract` classes to use `InputRequirement` for input handling.
- Updated `PipeInput` creation in various test files to use `make_from_dict` method.
- Updated `pyproject.toml` to exclude `pypdfium2` version `4.30.1`.
- Updated `Jinja2TemplateCategory` to handle HTML and Markdown templates differently.
@@ -633,7 +633,7 @@ Simplified input memory:
### Tooling Improvements
- Pipeline tracking: restored **visual flowchart generation using Mermaid**
-- Enhanced dry run configuration: added more granular control with `nb_list_items`, `nb_ocr_pages`, and `image_urls`
+- Enhanced dry run configuration: added more granular control with `nb_list_items`, `nb_extract_pages`, and `image_urls`
- New feature flags: better control over pipeline tracking, activity tracking, and reporting
- Improved OCR configuration: handle image file type for Mistral-OCR, added `default_page_views_dpi` setting
- Enhanced LLM configuration: **better prompting for structured generation with automatic schema insertion** for two-step structuring: generate plain text and then structure via Json
@@ -682,7 +682,7 @@ Simplified input memory:
### Highlights
- **Structured Input Specifications**: Pipe inputs are now defined as a dictionary mapping a required variable name to a concept code (`required_variable` -> `concept_code`). This replaces the previous single `input` field and allows for multiple, named inputs, making pipes more powerful and explicit. This is a **breaking change**.
-- **Static Validation for Inference Pipes**: You can now catch configuration and input mistakes in your pipelines *before* running any operations. This static validation checks `PipeLLM`, `PipeOcr`, and `PipeImgGen`. Static validation for controller pipes (PipeSequence, PipeParallel…) will come in a future release.
+- **Static Validation for Inference Pipes**: You can now catch configuration and input mistakes in your pipelines *before* running any operations. This static validation checks `PipeLLM`, `PipeExtract`, and `PipeImgGen`. Static validation for controller pipes (PipeSequence, PipeParallel…) will come in a future release.
- Configure the behavior for different error types using the `static_validation_config` section in your settings. For each error type, choose to `raise`, `log`, or `ignore`.
- **Dry Run Mode for Zero-Cost Pipeline Validation**: A powerful dry-run mode allows you to test entire pipelines without making any actual inference calls. It's fast, costs nothing, works offline, and is perfect for linting and validating pipeline logic.
- The new `dry_run_config` lets you control settings, like disabling Jinja2 rendering during a dry run.
@@ -839,7 +839,7 @@ is_reporting_enabled = true
## [v0.2.1] - 2025-05-22
-- Added `OcrWorkerAbstract` and `MistralOcrWorker`, along with `PipeOcr` for OCR processing of images and PDFs.
+- Added `OcrWorkerAbstract` and `MistralOcrWorker`, along with `PipeExtract` for OCR processing of images and PDFs.
- Introduced `MissionManager` for managing missions, cost reports, and activity tracking.
- Added detection and handling for pipe stack overflow, configurable with `pipe_stack_limit`.
- More possibilities for dependency injection and better class structure.
diff --git a/CLAUDE.md b/CLAUDE.md
index ed646a5fb..97a780d6d 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -285,7 +285,7 @@ Look at the Pipes we have in order to adapt it. Pipes are organized in two categ
2. **Operators** - For specific tasks:
- `PipeLLM` - Generate Text and Objects (include Vision LLM)
- - `PipeOcr` - Extract text and images from an image or a PDF
+ - `PipeExtract` - Extract text and images from an image or a PDF
- `PipeCompose` - For composing text using Jinja2 templates: supports html, markdown, mermaid, etc.
- `PipeImgGen` - Generate Images
- `PipeFunc` - For running classic python scripts
@@ -495,14 +495,14 @@ DO NOT write "$topic" alone in an isolated line.
DO write things like "Write an essay about $topic" to include text into an actual sentence.
-## PipeOcr operator
+## PipeExtract operator
-The PipeOcr operator is used to extract text and images from an image or a PDF
+The PipeExtract operator is used to extract text and images from an image or a PDF
### Simple Text Extraction
```plx
[pipe.extract_info]
-type = "PipeOcr"
+type = "PipeExtract"
description = "extract the information"
inputs = { document = "PDF" } # or { image = "Image" } if it's an image. This is the only input.
output = "Page"
@@ -511,7 +511,7 @@ output = "Page"
Only one input is allowed and it must either be an `Image` or a `PDF`.
The output concept `Page` is a native concept, with the structure `PageContent`:
-It corresponds to 1 page. Therefore, the PipeOcr is outputing a `ListContent` of `Page`
+It corresponds to 1 page. Therefore, the PipeExtract is outputing a `ListContent` of `Page`
```python
class TextAndImagesContent(StuffContent):
diff --git a/Makefile b/Makefile
index 239e2f4f8..1ae3487f4 100644
--- a/Makefile
+++ b/Makefile
@@ -18,7 +18,7 @@ VENV_PYLINT := $(VIRTUAL_ENV)/bin/pylint
UV_MIN_VERSION = $(shell grep -m1 'required-version' pyproject.toml | sed -E 's/.*= *"([^<>=, ]+).*/\1/')
-USUAL_PYTEST_MARKERS := "(dry_runnable or not (inference or llm or img_gen or ocr)) and not (needs_output or pipelex_api)"
+USUAL_PYTEST_MARKERS := "(dry_runnable or not (inference or llm or img_gen or extract)) and not (needs_output or pipelex_api)"
define PRINT_TITLE
$(eval PROJECT_PART := [$(PROJECT_NAME)])
@@ -78,8 +78,10 @@ make tp - Shorthand -> test-with-prints
make test-inference - Run unit tests only for inference (with prints)
make ti - Shorthand -> test-inference
make tip - Shorthand -> test-inference-with-prints (parallelized inference tests)
-make test-ocr - Run unit tests only for ocr (with prints)
-make to - Shorthand -> test-ocr
+make test-llm - Run unit tests only for llm (with prints)
+make tl - Shorthand -> test-llm
+make test-extract - Run unit tests only for extract (with prints)
+make te - Shorthand -> test-extract
make test-img-gen - Run unit tests only for img_gen (with prints)
make test-g - Shorthand -> test-img-gen
@@ -105,7 +107,7 @@ export HELP
format lint pyright mypy pylint \
cleanderived cleanenv cleanlibraries cleanall \
test test-xdist t test-quiet tq test-with-prints tp test-inference ti \
- test-img-gen tg test-ocr to codex-tests gha-tests \
+ test-llm tl test-img-gen tg test-extract te codex-tests gha-tests \
run-all-tests run-manual-trigger-gha-tests run-gha_disabled-tests \
validate v check c cc \
merge-check-ruff-lint merge-check-ruff-format merge-check-mypy merge-check-pyright \
@@ -286,17 +288,17 @@ tp: test-with-prints
test-inference-with-prints: env
$(call PRINT_TITLE,"Unit testing")
@if [ -n "$(TEST)" ]; then \
- $(VENV_PYTEST) --pipe-run-mode live -m "inference and not img_gen" -s -k "$(TEST)" $(if $(filter 1,$(VERBOSE)),-v,$(if $(filter 2,$(VERBOSE)),-vv,$(if $(filter 3,$(VERBOSE)),-vvv,))); \
+ $(VENV_PYTEST) --pipe-run-mode live -m "inference" -s -k "$(TEST)" $(if $(filter 1,$(VERBOSE)),-v,$(if $(filter 2,$(VERBOSE)),-vv,$(if $(filter 3,$(VERBOSE)),-vvv,))); \
else \
- $(VENV_PYTEST) --pipe-run-mode live -m "inference and not img_gen" -s $(if $(filter 1,$(VERBOSE)),-v,$(if $(filter 2,$(VERBOSE)),-vv,$(if $(filter 3,$(VERBOSE)),-vvv,))); \
+ $(VENV_PYTEST) --pipe-run-mode live -m "inference" -s $(if $(filter 1,$(VERBOSE)),-v,$(if $(filter 2,$(VERBOSE)),-vv,$(if $(filter 3,$(VERBOSE)),-vvv,))); \
fi
test-inference-fast: env
$(call PRINT_TITLE,"Unit testing")
@if [ -n "$(TEST)" ]; then \
- $(VENV_PYTEST) -n auto --pipe-run-mode live -m "inference and not img_gen" -s -k "$(TEST)" $(if $(filter 1,$(VERBOSE)),-v,$(if $(filter 2,$(VERBOSE)),-vv,$(if $(filter 3,$(VERBOSE)),-vvv,))); \
+ $(VENV_PYTEST) -n auto --pipe-run-mode live -m "inference" -s -k "$(TEST)" $(if $(filter 1,$(VERBOSE)),-v,$(if $(filter 2,$(VERBOSE)),-vv,$(if $(filter 3,$(VERBOSE)),-vvv,))); \
else \
- $(VENV_PYTEST) -n auto --pipe-run-mode live -m "inference and not img_gen" -s $(if $(filter 1,$(VERBOSE)),-v,$(if $(filter 2,$(VERBOSE)),-vv,$(if $(filter 3,$(VERBOSE)),-vvv,))); \
+ $(VENV_PYTEST) -n auto --pipe-run-mode live -m "inference" -s $(if $(filter 1,$(VERBOSE)),-v,$(if $(filter 2,$(VERBOSE)),-vv,$(if $(filter 3,$(VERBOSE)),-vvv,))); \
fi
tip: test-inference-with-prints
@@ -308,24 +310,35 @@ ti: test-inference-fast
ti-dry: env
$(call PRINT_TITLE,"Unit testing")
@if [ -n "$(TEST)" ]; then \
- $(VENV_PYTEST) --pipe-run-mode dry --exitfirst -m "inference and not img_gen" -s -k "$(TEST)" $(if $(filter 1,$(VERBOSE)),-v,$(if $(filter 2,$(VERBOSE)),-vv,$(if $(filter 3,$(VERBOSE)),-vvv,))); \
+ $(VENV_PYTEST) --pipe-run-mode dry --exitfirst -m "inference" -s -k "$(TEST)" $(if $(filter 1,$(VERBOSE)),-v,$(if $(filter 2,$(VERBOSE)),-vv,$(if $(filter 3,$(VERBOSE)),-vvv,))); \
else \
- $(VENV_PYTEST) --pipe-run-mode dry --exitfirst -m "inference and not img_gen" -s $(if $(filter 1,$(VERBOSE)),-v,$(if $(filter 2,$(VERBOSE)),-vv,$(if $(filter 3,$(VERBOSE)),-vvv,))); \
+ $(VENV_PYTEST) --pipe-run-mode dry --exitfirst -m "inference" -s $(if $(filter 1,$(VERBOSE)),-v,$(if $(filter 2,$(VERBOSE)),-vv,$(if $(filter 3,$(VERBOSE)),-vvv,))); \
fi
-test-ocr: env
- $(call PRINT_TITLE,"Unit testing ocr")
+test-llm: env
+ $(call PRINT_TITLE,"Unit testing LLM")
@if [ -n "$(TEST)" ]; then \
- $(VENV_PYTEST) --pipe-run-mode live --exitfirst -m "ocr" -s -k "$(TEST)" $(if $(filter 1,$(VERBOSE)),-v,$(if $(filter 2,$(VERBOSE)),-vv,$(if $(filter 3,$(VERBOSE)),-vvv,))); \
+ $(VENV_PYTEST) --pipe-run-mode live --exitfirst -m "llm" -s -k "$(TEST)" $(if $(filter 1,$(VERBOSE)),-v,$(if $(filter 2,$(VERBOSE)),-vv,$(if $(filter 3,$(VERBOSE)),-vvv,))); \
else \
- $(VENV_PYTEST) --pipe-run-mode live --exitfirst -m "ocr" -s $(if $(filter 1,$(VERBOSE)),-v,$(if $(filter 2,$(VERBOSE)),-vv,$(if $(filter 3,$(VERBOSE)),-vvv,))); \
+ $(VENV_PYTEST) --pipe-run-mode live --exitfirst -m "llm" -s $(if $(filter 1,$(VERBOSE)),-v,$(if $(filter 2,$(VERBOSE)),-vv,$(if $(filter 3,$(VERBOSE)),-vvv,))); \
fi
-to: test-ocr
- @echo "> done: to = test-ocr"
+tl: test-llm
+ @echo "> done: tl = test-llm"
+
+test-extract: env
+ $(call PRINT_TITLE,"Unit testing Extract")
+ @if [ -n "$(TEST)" ]; then \
+ $(VENV_PYTEST) --pipe-run-mode live --exitfirst -m "extract" -s -k "$(TEST)" $(if $(filter 1,$(VERBOSE)),-v,$(if $(filter 2,$(VERBOSE)),-vv,$(if $(filter 3,$(VERBOSE)),-vvv,))); \
+ else \
+ $(VENV_PYTEST) --pipe-run-mode live --exitfirst -m "extract" -s $(if $(filter 1,$(VERBOSE)),-v,$(if $(filter 2,$(VERBOSE)),-vv,$(if $(filter 3,$(VERBOSE)),-vvv,))); \
+ fi
+
+te: test-extract
+ @echo "> done: te = test-extract"
test-img-gen: env
- $(call PRINT_TITLE,"Unit testing")
+ $(call PRINT_TITLE,"Unit testing Image Generation")
@if [ -n "$(TEST)" ]; then \
$(VENV_PYTEST) --pipe-run-mode live --exitfirst -m "img_gen" -s -k "$(TEST)" $(if $(filter 1,$(VERBOSE)),-v,$(if $(filter 2,$(VERBOSE)),-vv,$(if $(filter 3,$(VERBOSE)),-vvv,))); \
else \
diff --git a/NEW_INFERENCE_BACKEND_CONFIG_SYSTEM.md b/NEW_INFERENCE_BACKEND_CONFIG_SYSTEM.md
index 9005b72f6..4ae4ecd66 100644
--- a/NEW_INFERENCE_BACKEND_CONFIG_SYSTEM.md
+++ b/NEW_INFERENCE_BACKEND_CONFIG_SYSTEM.md
@@ -66,7 +66,7 @@ The **Model Deck** (`ModelDeck`) is the final, unified collection of all configu
- **Common SDKs**: `mistral` (for Mistral OCR models), `pypdfium2` (for local PDF text extraction)
- **Inputs**: `pdf`, `image`
- **Outputs**: `pages` (structured page data with text and images)
-- **Usage**: OCR models are referenced by their `ocr_handle` in `PipeOcr` operations and can use OCR presets for common configurations
+- **Usage**: OCR models are referenced by their `ocr_handle` in `PipeExtract` operations and can use OCR presets for common configurations
Example OCR model configuration:
```toml
diff --git a/docs/pages/build-reliable-ai-workflows-with-pipelex/design_and_run_pipelines.md b/docs/pages/build-reliable-ai-workflows-with-pipelex/design_and_run_pipelines.md
index 8f5f2fc18..265e5b4df 100644
--- a/docs/pages/build-reliable-ai-workflows-with-pipelex/design_and_run_pipelines.md
+++ b/docs/pages/build-reliable-ai-workflows-with-pipelex/design_and_run_pipelines.md
@@ -8,7 +8,7 @@ This guide provides an overview of how to design your pipelines and execute them
A pipeline is composed of pipes. There are two fundamental types of pipes you will use to build your workflows:
-* **[Pipe Operators](pipe-operators/index.md)**: These are the "workers" of your pipeline. They perform concrete actions like calling an LLM (`PipeLLM`), extracting text from a document (`PipeOcr`), or running a Python function (`PipeFunc`). Each operator is a specialized tool designed for a specific task.
+* **[Pipe Operators](pipe-operators/index.md)**: These are the "workers" of your pipeline. They perform concrete actions like calling an LLM (`PipeLLM`), extracting text from a document (`PipeExtract`), or running a Python function (`PipeFunc`). Each operator is a specialized tool designed for a specific task.
* **[Pipe Controllers](pipe-controllers/index.md)**: These are the "managers" of your pipeline. They don't perform tasks themselves but orchestrate the execution flow of other pipes. They define the logic of your workflow, such as running pipes in sequence (`PipeSequence`), in parallel (`PipeParallel`), or based on a condition (`PipeCondition`).
## Designing a Pipeline: Composition in PLX
diff --git a/docs/pages/build-reliable-ai-workflows-with-pipelex/pipe-controllers/PipeSequence.md b/docs/pages/build-reliable-ai-workflows-with-pipelex/pipe-controllers/PipeSequence.md
index a4fa1f118..359947090 100644
--- a/docs/pages/build-reliable-ai-workflows-with-pipelex/pipe-controllers/PipeSequence.md
+++ b/docs/pages/build-reliable-ai-workflows-with-pipelex/pipe-controllers/PipeSequence.md
@@ -41,7 +41,7 @@ Let's imagine a pipeline that first extracts text from an image, then summarizes
```plx
[pipe.extract_text_from_image]
-type = "PipeOcr"
+type = "PipeExtract"
description = "Extract text from an image"
output = "Text"
ocr = "mistral-ocr"
diff --git a/docs/pages/build-reliable-ai-workflows-with-pipelex/pipe-operators/PipeOcr.md b/docs/pages/build-reliable-ai-workflows-with-pipelex/pipe-operators/PipeExtract.md
similarity index 83%
rename from docs/pages/build-reliable-ai-workflows-with-pipelex/pipe-operators/PipeOcr.md
rename to docs/pages/build-reliable-ai-workflows-with-pipelex/pipe-operators/PipeExtract.md
index 7cb532eb9..48b40e377 100644
--- a/docs/pages/build-reliable-ai-workflows-with-pipelex/pipe-operators/PipeOcr.md
+++ b/docs/pages/build-reliable-ai-workflows-with-pipelex/pipe-operators/PipeExtract.md
@@ -1,10 +1,10 @@
-# PipeOcr
+# PipeExtract
-The `PipeOcr` operator performs Optical Character Recognition (OCR) on images and PDF documents. It extracts text, embedded images, and provides full-page renderings.
+The `PipeExtract` operator performs Optical Character Recognition (OCR) on images and PDF documents. It extracts text, embedded images, and provides full-page renderings.
## How it works
-`PipeOcr` takes a single input, which must be either an `Image` or a `Pdf`. It processes the document page by page and produces a list of `PageContent` objects. Each `PageContent` object encapsulates all the information extracted from a single page.
+`PipeExtract` takes a single input, which must be either an `Image` or a `Pdf`. It processes the document page by page and produces a list of `PageContent` objects. Each `PageContent` object encapsulates all the information extracted from a single page.
The output is always a list, even if the input is a single image (in which case the list will contain just one item).
@@ -19,11 +19,11 @@ The `PageContent` object has the following structure:
## Configuration
-`PipeOcr` is configured in your pipeline's `.plx` file.
+`PipeExtract` is configured in your pipeline's `.plx` file.
### OCR Models and Backend System
-PipeOcr uses the unified inference backend system to manage OCR models. This means you can:
+PipeExtract uses the unified inference backend system to manage OCR models. This means you can:
- Use different OCR providers (Mistral OCR, local PDF extraction via internal backend, etc.)
- Configure OCR models through the same backend system as LLMs and image generation models
@@ -40,7 +40,7 @@ OCR presets are defined in your model deck configuration and can include paramet
| Parameter | Type | Description | Required |
| --------------------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------- | -------- |
-| `type` | string | The type of the pipe: `PipeOcr` | Yes |
+| `type` | string | The type of the pipe: `PipeExtract` | Yes |
| `description` | string | A description of the OCR operation. | Yes |
| `inputs` | Fixed | The value is either of concept `Image` or `Pdf`. | Yes |
| `output` | string | The output concept produced by the OCR operation. | Yes |
@@ -63,7 +63,7 @@ description = "A list of pages extracted from a document by OCR"
refines = "Page"
[pipe.extract_text_from_document]
-type = "PipeOcr"
+type = "PipeExtract"
description = "Extract text from a scanned document"
inputs = { document = "ScannedDocument" }
output = "Page"
@@ -71,6 +71,6 @@ page_views = true
page_views_dpi = 200
```
-The output of the PipeOcr must be exactly the native `Page` concept.
+The output of the PipeExtract must be exactly the native `Page` concept.
To use this pipe, you would first need to load a PDF into the `ScannedDocument` concept. After the pipe runs, the `ExtractedPages` concept will contain a list of `PageContent` objects, where each object has the extracted text and a 200 DPI image of the corresponding page.
diff --git a/docs/pages/build-reliable-ai-workflows-with-pipelex/pipe-operators/index.md b/docs/pages/build-reliable-ai-workflows-with-pipelex/pipe-operators/index.md
index 7172bc539..8a131c38a 100644
--- a/docs/pages/build-reliable-ai-workflows-with-pipelex/pipe-operators/index.md
+++ b/docs/pages/build-reliable-ai-workflows-with-pipelex/pipe-operators/index.md
@@ -9,7 +9,7 @@ Each operator specializes in a specific kind of action, from interacting with La
Here are the primary pipe operators available in Pipelex:
- [**`PipeLLM`**](./PipeLLM.md): The core operator for all interactions with Large Language Models (LLMs), including text generation, structured data extraction, and vision tasks.
-- [**`PipeOcr`**](./PipeOcr.md): Performs Optical Character Recognition (OCR) on images and PDF documents to extract text and embedded images.
+- [**`PipeExtract`**](./PipeExtract.md): Performs Optical Character Recognition (OCR) on images and PDF documents to extract text and embedded images.
- [**`PipeImgGen`**](./PipeImgGen.md): Generates images from a text prompt using models like GPT Image, Flux, or other image generation models.
- [**`PipeFunc`**](./PipeFunc.md): An escape hatch that allows you to execute any custom Python function, giving you maximum flexibility.
- [**`PipeCompose`**](./PipeCompose.md): Renders a Jinja2 template using data from the working memory, perfect for creating formatted reports or complex prompts.
@@ -19,7 +19,7 @@ Here are the primary pipe operators available in Pipelex:
Pipelex provides the following pipe operators:
- `PipeLLM`: For LLM-based text generation and processing
-- `PipeOcr`: For optical character recognition and document processing
+- `PipeExtract`: For optical character recognition and document processing
- `PipeFunc`: For executing custom functions
- `PipeImgGen`: For AI-powered image generation
@@ -42,7 +42,7 @@ Core operator for LLM-based text generation and processing.
- Sub-pipe handling
- Pipeline composition
-## PipeOcr
+## PipeExtract
Processes images and PDFs using Optical Character Recognition.
diff --git a/docs/pages/configuration/config-pipeline-validation/dry-run-config.md b/docs/pages/configuration/config-pipeline-validation/dry-run-config.md
index 435245640..892180aa0 100644
--- a/docs/pages/configuration/config-pipeline-validation/dry-run-config.md
+++ b/docs/pages/configuration/config-pipeline-validation/dry-run-config.md
@@ -9,7 +9,7 @@ class DryRunConfig(ConfigModel):
apply_to_jinja2_rendering: bool
text_gen_truncate_length: int
nb_list_items: int
- nb_ocr_pages: int
+ nb_extract_pages: int
image_urls: List[str]
allowed_to_fail_pipes: List[str] = Field(default_factory=list)
```
@@ -19,7 +19,7 @@ class DryRunConfig(ConfigModel):
- `apply_to_jinja2_rendering`: When true, simulates Jinja2 template rendering during dry runs
- `text_gen_truncate_length`: Maximum length of generated text during dry runs
- `nb_list_items`: Number of items to generate for list content during dry runs
-- `nb_ocr_pages`: Number of pages to simulate for OCR operations during dry runs
+- `nb_extract_pages`: Number of pages to simulate for OCR operations during dry runs
- `image_urls`: List of image URLs to use for dry run testing (must be non-empty)
- `allowed_to_fail_pipes`: List of pipe names that are allowed to fail during dry runs (optional)
@@ -30,7 +30,7 @@ class DryRunConfig(ConfigModel):
apply_to_jinja2_rendering = true
text_gen_truncate_length = 100
nb_list_items = 3
-nb_ocr_pages = 2
+nb_extract_pages = 2
image_urls = ["https://example.com/image1.jpg", "https://example.com/image2.jpg"]
allowed_to_fail_pipes = ["optional_pipe", "experimental_pipe"]
```
diff --git a/docs/pages/configuration/config-technical/cogt-config.md b/docs/pages/configuration/config-technical/cogt-config.md
index 8896096ab..6351d5b78 100644
--- a/docs/pages/configuration/config-technical/cogt-config.md
+++ b/docs/pages/configuration/config-technical/cogt-config.md
@@ -10,7 +10,7 @@ The Cogt configuration manages all cognitive tools in Pipelex, including LLM (La
[cogt.inference_manager_config]
[cogt.llm_config]
[cogt.img_gen_config]
-[cogt.ocr_config]
+[cogt.extract_config]
```
## Inference Manager Configuration
@@ -21,7 +21,7 @@ Controls automatic setup of various cognitive tools:
[cogt.inference_manager_config]
is_auto_setup_preset_llm = true
is_auto_setup_preset_img_gen = true
-is_auto_setup_preset_ocr = true
+is_auto_setup_preset_extract = true
```
## LLM Configuration
@@ -105,7 +105,7 @@ Image generation jobs support these parameters:
Configuration for Optical Character Recognition:
```toml
-[cogt.ocr_config]
+[cogt.extract_config]
page_output_text_file_name = "page_text.md"
default_page_views_dpi = 72
@@ -169,7 +169,7 @@ All model types support the same routing, aliasing, and preset systems.
[cogt.inference_manager_config]
is_auto_setup_preset_llm = true
is_auto_setup_preset_img_gen = true
-is_auto_setup_preset_ocr = true
+is_auto_setup_preset_extract = true
[cogt.llm_config]
default_max_images = 100
@@ -197,6 +197,6 @@ is_raw = false
output_format = "jpg"
seed = "auto"
-[cogt.ocr_config]
+[cogt.extract_config]
page_output_text_file_name = "page_text.md"
```
diff --git a/docs/pages/configuration/config-technical/inference-backend-config.md b/docs/pages/configuration/config-technical/inference-backend-config.md
index b87dca5a4..8ff6ca750 100644
--- a/docs/pages/configuration/config-technical/inference-backend-config.md
+++ b/docs/pages/configuration/config-technical/inference-backend-config.md
@@ -370,15 +370,6 @@ smart_llm = [
"gemini-2.5-pro",
]
-# OCR aliases
-best-ocr = "mistral-ocr"
-local-ocr = "pypdfium2-extract-text"
-
-# Image generation aliases
-base-img-gen = "flux-pro/v1.1"
-best-img-gen = "flux-pro/v1.1-ultra"
-fast-img-gen = "fast-lightning-sdxl"
-
# Aliases can also define fallback chains
llm_to_engineer = { llm_handle = "smart_llm", temperature = 0.2 }
```
@@ -403,10 +394,10 @@ llm_to_reason = { llm_handle = "base-claude", temperature = 1 }
OCR presets combine OCR model selection with optimized parameters:
```toml
-[ocr.presets]
+[extract.presets]
# General purpose OCR
base_ocr_mistral = { ocr_handle = "mistral-ocr", max_nb_images = 100, image_min_size = 50 }
-base_ocr_pypdfium2 = { ocr_handle = "pypdfium2-extract-text", max_nb_images = 100, image_min_size = 50 }
+base_extract_pypdfium2 = { extract_handle = "pypdfium2-extract-text", max_nb_images = 100, image_min_size = 50 }
```
### Image Generation Presets
@@ -430,7 +421,7 @@ Set default models for different types of AI operations:
for_text = "cheap_llm_for_text"
for_object = "cheap_llm_for_object"
-[ocr]
+[extract]
choice_default = "base_ocr_mistral"
[img_gen]
@@ -448,8 +439,8 @@ Use `.pipelex/inference/deck/overrides.toml` for project-specific customizations
[llm.presets]
llm_to_extract_invoice = { llm_handle = "gpt-4o-mini", temperature = 0.2 }
-[ocr.presets]
-my_custom_ocr = { ocr_handle = "mistral-ocr", max_nb_images = 5 }
+[extract.presets]
+my_custom_extract = { ocr_handle = "mistral-ocr", max_nb_images = 5 }
[img_gen.presets]
my_custom_img_gen = { img_gen_handle = "flux-dev", quality = "medium" }
@@ -457,7 +448,7 @@ my_custom_img_gen = { img_gen_handle = "flux-dev", quality = "medium" }
# Add custom aliases
[aliases]
my_custom_llm = "claude-3-sonnet"
-my_custom_ocr = "pypdfium2-extract-text"
+my_custom_extract = "pypdfium2-extract-text"
my_custom_img_gen = "base-img-gen"
```
diff --git a/docs/pages/cookbook-examples/simple-ocr.md b/docs/pages/cookbook-examples/simple-ocr.md
index c2844f100..f606cffb2 100644
--- a/docs/pages/cookbook-examples/simple-ocr.md
+++ b/docs/pages/cookbook-examples/simple-ocr.md
@@ -6,11 +6,11 @@ This is a fundamental building block for many document processing workflows.
## Get the code
-[**➡️ View on GitHub: examples/simple_ocr.py**](https://github.com/Pipelex/pipelex-cookbook/blob/main/examples/simple_ocr.py)
+[**➡️ View on GitHub: examples/simple_extract.py**](https://github.com/Pipelex/pipelex-cookbook/blob/main/examples/simple_ocr.py)
## The Pipeline Explained
-The core of this example is a simple function that creates a "working memory" from a PDF and then executes a pre-defined pipeline called `ocr_page_contents_from_pdf`.
+The core of this example is a simple function that creates a "working memory" from a PDF and then executes a pre-defined pipeline called `extract_page_contents_from_pdf`.
```python
async def simple_ocr(pdf_url: str):
@@ -20,7 +20,7 @@ async def simple_ocr(pdf_url: str):
name="pdf",
)
pipe_output = await execute_pipeline(
- pipe_code="ocr_page_contents_from_pdf",
+ pipe_code="extract_page_contents_from_pdf",
working_memory=working_memory,
)
page_content_list: ListContent[PageContent] = pipe_output.main_stuff_as_list(item_type=PageContent)
diff --git a/mkdocs.yml b/mkdocs.yml
index 35885f573..0f76fd2da 100644
--- a/mkdocs.yml
+++ b/mkdocs.yml
@@ -113,7 +113,7 @@ nav:
- Pipe Operators:
- Overview: pages/build-reliable-ai-workflows-with-pipelex/pipe-operators/index.md
- PipeLLM: pages/build-reliable-ai-workflows-with-pipelex/pipe-operators/PipeLLM.md
- - PipeOcr: pages/build-reliable-ai-workflows-with-pipelex/pipe-operators/PipeOcr.md
+ - PipeExtract: pages/build-reliable-ai-workflows-with-pipelex/pipe-operators/PipeExtract.md
- PipeImgGen: pages/build-reliable-ai-workflows-with-pipelex/pipe-operators/PipeImgGen.md
- PipeCompose: pages/build-reliable-ai-workflows-with-pipelex/pipe-operators/PipeCompose.md
- PipeFunc: pages/build-reliable-ai-workflows-with-pipelex/pipe-operators/PipeFunc.md
diff --git a/pipelex/cogt/config_cogt.py b/pipelex/cogt/config_cogt.py
index adcaed1c1..b673644a2 100644
--- a/pipelex/cogt/config_cogt.py
+++ b/pipelex/cogt/config_cogt.py
@@ -5,7 +5,7 @@ from pipelex.tools.config.config_model import ConfigModel
from pipelex.tools.misc.file_utils import find_files_in_dir
-class OcrConfig(ConfigModel):
+class ExtractConfig(ConfigModel):
page_output_text_file_name: str
default_page_views_dpi: int
@@ -36,7 +36,7 @@ class LLMConfig(ConfigModel):
class InferenceManagerConfig(ConfigModel):
is_auto_setup_preset_llm: bool
is_auto_setup_preset_img_gen: bool
- is_auto_setup_preset_ocr: bool
+ is_auto_setup_preset_extract: bool
class InferenceConfig(ConfigModel):
@@ -72,4 +72,4 @@ class Cogt(ConfigModel):
inference_manager_config: InferenceManagerConfig
llm_config: LLMConfig
img_gen_config: ImgGenConfig
- ocr_config: OcrConfig
+ extract_config: ExtractConfig
diff --git a/pipelex/cogt/content_generation/assignment_models.py b/pipelex/cogt/content_generation/assignment_models.py
index efd3da823..8ac28f038 100644
--- a/pipelex/cogt/content_generation/assignment_models.py
+++ b/pipelex/cogt/content_generation/assignment_models.py
@@ -4,14 +4,14 @@ from pydantic import BaseModel
from typing_extensions import override
from pipelex.cogt.exceptions import LLMAssignmentError
+from pipelex.cogt.extract.extract_input import ExtractInput
+from pipelex.cogt.extract.extract_job_components import ExtractJobConfig, ExtractJobParams
from pipelex.cogt.img_gen.img_gen_job_components import ImgGenJobConfig, ImgGenJobParams
from pipelex.cogt.img_gen.img_gen_prompt import ImgGenPrompt
from pipelex.cogt.llm.llm_job_components import LLMJobParams
from pipelex.cogt.llm.llm_prompt import LLMPrompt
from pipelex.cogt.llm.llm_prompt_factory_abstract import LLMPromptFactoryAbstract
from pipelex.cogt.llm.llm_setting import LLMSetting
-from pipelex.cogt.ocr.ocr_input import OcrInput
-from pipelex.cogt.ocr.ocr_job_components import OcrJobConfig, OcrJobParams
from pipelex.hub import get_class_registry
from pipelex.pipeline.job_metadata import JobMetadata
from pipelex.tools.templating.jinja2_template_category import Jinja2TemplateCategory
@@ -134,9 +134,9 @@ class Jinja2Assignment(BaseModel):
template_category: Jinja2TemplateCategory = Jinja2TemplateCategory.LLM_PROMPT
-class OcrAssignment(BaseModel):
+class ExtractAssignment(BaseModel):
job_metadata: JobMetadata
- ocr_handle: str
- ocr_input: OcrInput
- ocr_job_params: OcrJobParams
- ocr_job_config: OcrJobConfig
+ extract_handle: str
+ extract_input: ExtractInput
+ extract_job_params: ExtractJobParams
+ extract_job_config: ExtractJobConfig
diff --git a/pipelex/cogt/content_generation/content_generator.py b/pipelex/cogt/content_generation/content_generator.py
index e8248a7f7..6d8509e5a 100644
--- a/pipelex/cogt/content_generation/content_generator.py
+++ b/pipelex/cogt/content_generation/content_generator.py
@@ -4,19 +4,22 @@ from typing_extensions import override
from pipelex import log
from pipelex.cogt.content_generation.assignment_models import (
+ ExtractAssignment,
ImgGenAssignment,
Jinja2Assignment,
LLMAssignment,
LLMAssignmentFactory,
ObjectAssignment,
- OcrAssignment,
TextThenObjectAssignment,
)
from pipelex.cogt.content_generation.content_generator_protocol import ContentGeneratorProtocol, update_job_metadata
+from pipelex.cogt.content_generation.extract_generate import extract_gen_pages
from pipelex.cogt.content_generation.img_gen_generate import img_gen_image_list, img_gen_single_image
from pipelex.cogt.content_generation.jinja2_generate import jinja2_gen_text
from pipelex.cogt.content_generation.llm_generate import llm_gen_object, llm_gen_object_list, llm_gen_text
-from pipelex.cogt.content_generation.ocr_generate import ocr_gen_extract_pages
+from pipelex.cogt.extract.extract_input import ExtractInput
+from pipelex.cogt.extract.extract_job_components import ExtractJobConfig, ExtractJobParams
+from pipelex.cogt.extract.extract_output import ExtractOutput
from pipelex.cogt.image.generated_image import GeneratedImage
from pipelex.cogt.img_gen.img_gen_job_components import ImgGenJobConfig, ImgGenJobParams
from pipelex.cogt.img_gen.img_gen_prompt import ImgGenPrompt
@@ -24,9 +27,6 @@ from pipelex.cogt.llm.llm_prompt import LLMPrompt
from pipelex.cogt.llm.llm_prompt_factory_abstract import LLMPromptFactoryAbstract
from pipelex.cogt.llm.llm_prompt_template import LLMPromptTemplate
from pipelex.cogt.llm.llm_setting import LLMSetting
-from pipelex.cogt.ocr.ocr_input import OcrInput
-from pipelex.cogt.ocr.ocr_job_components import OcrJobConfig, OcrJobParams
-from pipelex.cogt.ocr.ocr_output import OcrOutput
from pipelex.config import get_config
from pipelex.pipeline.job_metadata import JobMetadata
from pipelex.tools.templating.jinja2_template_category import Jinja2TemplateCategory
@@ -261,19 +261,19 @@ class ContentGenerator(ContentGeneratorProtocol):
return await jinja2_gen_text(jinja2_assignment=jinja2_assignment)
@override
- async def make_ocr_extract_pages(
+ async def make_extract_pages(
self,
job_metadata: JobMetadata,
- ocr_input: OcrInput,
- ocr_handle: str,
- ocr_job_params: OcrJobParams | None = None,
- ocr_job_config: OcrJobConfig | None = None,
- ) -> OcrOutput:
- ocr_assignment = OcrAssignment(
+ extract_input: ExtractInput,
+ extract_handle: str,
+ extract_job_params: ExtractJobParams | None = None,
+ extract_job_config: ExtractJobConfig | None = None,
+ ) -> ExtractOutput:
+ extract_assignment = ExtractAssignment(
job_metadata=job_metadata,
- ocr_input=ocr_input,
- ocr_handle=ocr_handle,
- ocr_job_params=ocr_job_params or OcrJobParams.make_default_ocr_job_params(),
- ocr_job_config=ocr_job_config or OcrJobConfig(),
+ extract_input=extract_input,
+ extract_handle=extract_handle,
+ extract_job_params=extract_job_params or ExtractJobParams.make_default_extract_job_params(),
+ extract_job_config=extract_job_config or ExtractJobConfig(),
)
- return await ocr_gen_extract_pages(ocr_assignment=ocr_assignment)
+ return await extract_gen_pages(extract_assignment=extract_assignment)
diff --git a/pipelex/cogt/content_generation/content_generator_dry.py b/pipelex/cogt/content_generation/content_generator_dry.py
index baa3fb44b..2a66b9154 100644
--- a/pipelex/cogt/content_generation/content_generator_dry.py
+++ b/pipelex/cogt/content_generation/content_generator_dry.py
@@ -5,15 +5,15 @@ from typing_extensions import override
from pipelex import log
from pipelex.cogt.content_generation.content_generator_protocol import ContentGeneratorProtocol, update_job_metadata
+from pipelex.cogt.extract.extract_input import ExtractInput
+from pipelex.cogt.extract.extract_job_components import ExtractJobConfig, ExtractJobParams
+from pipelex.cogt.extract.extract_output import ExtractedImageFromPage, ExtractOutput, Page
from pipelex.cogt.image.generated_image import GeneratedImage
from pipelex.cogt.img_gen.img_gen_job_components import ImgGenJobConfig, ImgGenJobParams
from pipelex.cogt.img_gen.img_gen_prompt import ImgGenPrompt
from pipelex.cogt.llm.llm_prompt import LLMPrompt
from pipelex.cogt.llm.llm_prompt_factory_abstract import LLMPromptFactoryAbstract
from pipelex.cogt.llm.llm_setting import LLMSetting
-from pipelex.cogt.ocr.ocr_input import OcrInput
-from pipelex.cogt.ocr.ocr_job_components import OcrJobConfig, OcrJobParams
-from pipelex.cogt.ocr.ocr_output import ExtractedImageFromPage, OcrOutput, Page
from pipelex.config import get_config
from pipelex.pipeline.job_metadata import JobMetadata
from pipelex.tools.templating.jinja2_template_category import Jinja2TemplateCategory
@@ -195,27 +195,27 @@ class ContentGeneratorDry(ContentGeneratorProtocol):
)
@override
- async def make_ocr_extract_pages(
+ async def make_extract_pages(
self,
job_metadata: JobMetadata,
- ocr_input: OcrInput,
- ocr_handle: str,
- ocr_job_params: OcrJobParams | None = None,
- ocr_job_config: OcrJobConfig | None = None,
- ) -> OcrOutput:
- func_name = "make_ocr_extract_pages"
+ extract_input: ExtractInput,
+ extract_handle: str,
+ extract_job_params: ExtractJobParams | None = None,
+ extract_job_config: ExtractJobConfig | None = None,
+ ) -> ExtractOutput:
+ func_name = "make_extract_pages"
log.dev(f"🤡 DRY RUN: {self.__class__.__name__}.{func_name}")
- if ocr_input.image_uri:
- ocr_image_as_page = Page(
+ if extract_input.image_uri:
+ image_as_page = Page(
text="DRY RUN: OCR text",
extracted_images=[],
page_view=None,
)
- ocr_output = OcrOutput(
- pages={1: ocr_image_as_page},
+ extract_output = ExtractOutput(
+ pages={1: image_as_page},
)
else:
- nb_pages = get_config().pipelex.dry_run_config.nb_ocr_pages
+ nb_pages = get_config().pipelex.dry_run_config.nb_extract_pages
pages = {
page_index: Page(
text="DRY RUN: OCR text",
@@ -228,5 +228,5 @@ class ContentGeneratorDry(ContentGeneratorProtocol):
)
for page_index in range(1, nb_pages + 1)
}
- ocr_output = OcrOutput(pages=pages)
- return ocr_output
+ extract_output = ExtractOutput(pages=pages)
+ return extract_output
diff --git a/pipelex/cogt/content_generation/content_generator_protocol.py b/pipelex/cogt/content_generation/content_generator_protocol.py
index 936d3a3ac..5112cbc8e 100644
--- a/pipelex/cogt/content_generation/content_generator_protocol.py
+++ b/pipelex/cogt/content_generation/content_generator_protocol.py
@@ -2,15 +2,15 @@ from collections.abc import Awaitable, Callable, Coroutine
from functools import wraps
from typing import Any, ParamSpec, Protocol, TypeVar
+from pipelex.cogt.extract.extract_input import ExtractInput
+from pipelex.cogt.extract.extract_job_components import ExtractJobConfig, ExtractJobParams
+from pipelex.cogt.extract.extract_output import ExtractOutput
from pipelex.cogt.image.generated_image import GeneratedImage
from pipelex.cogt.img_gen.img_gen_job_components import ImgGenJobConfig, ImgGenJobParams
from pipelex.cogt.img_gen.img_gen_prompt import ImgGenPrompt
from pipelex.cogt.llm.llm_prompt import LLMPrompt
from pipelex.cogt.llm.llm_prompt_factory_abstract import LLMPromptFactoryAbstract
from pipelex.cogt.llm.llm_setting import LLMSetting
-from pipelex.cogt.ocr.ocr_input import OcrInput
-from pipelex.cogt.ocr.ocr_job_components import OcrJobConfig, OcrJobParams
-from pipelex.cogt.ocr.ocr_output import OcrOutput
from pipelex.pipeline.job_metadata import JobMetadata
from pipelex.tools.templating.jinja2_template_category import Jinja2TemplateCategory
from pipelex.tools.templating.templating_models import PromptingStyle
@@ -118,11 +118,11 @@ class ContentGeneratorProtocol(Protocol):
template_category: Jinja2TemplateCategory = Jinja2TemplateCategory.LLM_PROMPT,
) -> str: ...
- async def make_ocr_extract_pages(
+ async def make_extract_pages(
self,
job_metadata: JobMetadata,
- ocr_input: OcrInput,
- ocr_handle: str,
- ocr_job_params: OcrJobParams,
- ocr_job_config: OcrJobConfig,
- ) -> OcrOutput: ...
+ extract_input: ExtractInput,
+ extract_handle: str,
+ extract_job_params: ExtractJobParams,
+ extract_job_config: ExtractJobConfig,
+ ) -> ExtractOutput: ...
diff --git a/pipelex/cogt/content_generation/extract_generate.py b/pipelex/cogt/content_generation/extract_generate.py
new file mode 100644
index 000000000..43364c7c2
--- /dev/null
+++ b/pipelex/cogt/content_generation/extract_generate.py
@@ -0,0 +1,15 @@
+from pipelex.cogt.content_generation.assignment_models import ExtractAssignment
+from pipelex.cogt.extract.extract_job_factory import ExtractJobFactory
+from pipelex.cogt.extract.extract_output import ExtractOutput
+from pipelex.hub import get_extract_worker
+
+
+async def extract_gen_pages(extract_assignment: ExtractAssignment) -> ExtractOutput:
+ extract_worker = get_extract_worker(extract_handle=extract_assignment.extract_handle)
+ extract_job = ExtractJobFactory.make_extract_job(
+ extract_input=extract_assignment.extract_input,
+ extract_job_params=extract_assignment.extract_job_params,
+ extract_job_config=extract_assignment.extract_job_config,
+ job_metadata=extract_assignment.job_metadata,
+ )
+ return await extract_worker.extract_pages(extract_job=extract_job)
diff --git a/pipelex/cogt/content_generation/ocr_generate.py b/pipelex/cogt/content_generation/ocr_generate.py
deleted file mode 100644
index 66254b7fd..000000000
--- a/pipelex/cogt/content_generation/ocr_generate.py
+++ /dev/null
@@ -1,15 +0,0 @@
-from pipelex.cogt.content_generation.assignment_models import OcrAssignment
-from pipelex.cogt.ocr.ocr_job_factory import OcrJobFactory
-from pipelex.cogt.ocr.ocr_output import OcrOutput
-from pipelex.hub import get_ocr_worker
-
-
-async def ocr_gen_extract_pages(ocr_assignment: OcrAssignment) -> OcrOutput:
- ocr_worker = get_ocr_worker(ocr_handle=ocr_assignment.ocr_handle)
- ocr_job = OcrJobFactory.make_ocr_job(
- ocr_input=ocr_assignment.ocr_input,
- ocr_job_params=ocr_assignment.ocr_job_params,
- ocr_job_config=ocr_assignment.ocr_job_config,
- job_metadata=ocr_assignment.job_metadata,
- )
- return await ocr_worker.ocr_extract_pages(ocr_job=ocr_job)
diff --git a/pipelex/cogt/exceptions.py b/pipelex/cogt/exceptions.py
index 075930c73..22d99b0f4 100644
--- a/pipelex/cogt/exceptions.py
+++ b/pipelex/cogt/exceptions.py
@@ -34,7 +34,7 @@ class LLMChoiceNotFoundError(CogtError):
pass
-class OcrChoiceNotFoundError(CogtError):
+class ExtractChoiceNotFoundError(CogtError):
pass
diff --git a/pipelex/cogt/ocr/__init__.py b/pipelex/cogt/extract/__init__.py
similarity index 100%
rename from pipelex/cogt/ocr/__init__.py
rename to pipelex/cogt/extract/__init__.py
diff --git a/pipelex/cogt/ocr/ocr_input.py b/pipelex/cogt/extract/extract_input.py
similarity index 84%
rename from pipelex/cogt/ocr/ocr_input.py
rename to pipelex/cogt/extract/extract_input.py
index a364aa014..97b4d9a88 100644
--- a/pipelex/cogt/ocr/ocr_input.py
+++ b/pipelex/cogt/extract/extract_input.py
@@ -5,11 +5,11 @@ from pipelex.tools.typing.validation_utils import has_exactly_one_among_attribut
from pipelex.types import Self
-class OcrInputError(CogtError):
+class ExtractInputError(CogtError):
pass
-class OcrInput(BaseModel):
+class ExtractInput(BaseModel):
image_uri: str | None = None
pdf_uri: str | None = None
@@ -17,5 +17,5 @@ class OcrInput(BaseModel):
def validate_at_exactly_one_input(self) -> Self:
if not has_exactly_one_among_attributes_from_list(self, attributes_list=["image_uri", "pdf_uri"]):
msg = "Exactly one of 'image_uri' or 'pdf_uri' must be provided"
- raise OcrInputError(msg)
+ raise ExtractInputError(msg)
return self
diff --git a/pipelex/cogt/extract/extract_job.py b/pipelex/cogt/extract/extract_job.py
new file mode 100644
index 000000000..0ec341e58
--- /dev/null
+++ b/pipelex/cogt/extract/extract_job.py
@@ -0,0 +1,28 @@
+from datetime import datetime
+
+from typing_extensions import override
+
+from pipelex.cogt.extract.extract_input import ExtractInput
+from pipelex.cogt.extract.extract_job_components import ExtractJobConfig, ExtractJobParams, ExtractJobReport
+from pipelex.cogt.inference.inference_job_abstract import InferenceJobAbstract
+
+
+class ExtractJob(InferenceJobAbstract):
+ extract_input: ExtractInput
+ job_params: ExtractJobParams
+ job_config: ExtractJobConfig
+ job_report: ExtractJobReport = ExtractJobReport()
+
+ @override
+ def validate_before_execution(self):
+ pass
+
+ def extract_job_before_start(self):
+ # Reset metadata
+ self.job_metadata.started_at = datetime.now()
+
+ # Reset outputs
+ self.job_report = ExtractJobReport()
+
+ def extract_job_after_complete(self):
+ self.job_metadata.completed_at = datetime.now()
diff --git a/pipelex/cogt/ocr/ocr_job_components.py b/pipelex/cogt/extract/extract_job_components.py
similarity index 77%
rename from pipelex/cogt/ocr/ocr_job_components.py
rename to pipelex/cogt/extract/extract_job_components.py
index e07317231..5bc9bc558 100644
--- a/pipelex/cogt/ocr/ocr_job_components.py
+++ b/pipelex/cogt/extract/extract_job_components.py
@@ -3,7 +3,7 @@ from pydantic import BaseModel
from pipelex.tools.config.config_model import ConfigModel
-class OcrJobParams(BaseModel):
+class ExtractJobParams(BaseModel):
should_include_images: bool
max_nb_images: int | None
image_min_size: int | None
@@ -12,8 +12,8 @@ class OcrJobParams(BaseModel):
page_views_dpi: int | None
@classmethod
- def make_default_ocr_job_params(cls) -> "OcrJobParams":
- return OcrJobParams(
+ def make_default_extract_job_params(cls) -> "ExtractJobParams":
+ return ExtractJobParams(
should_caption_images=False,
max_nb_images=None,
image_min_size=None,
@@ -23,7 +23,7 @@ class OcrJobParams(BaseModel):
)
-class OcrJobConfig(ConfigModel):
+class ExtractJobConfig(ConfigModel):
pass
@@ -32,5 +32,5 @@ class OcrJobConfig(ConfigModel):
########################################################################
-class OcrJobReport(ConfigModel):
+class ExtractJobReport(ConfigModel):
pass
diff --git a/pipelex/cogt/extract/extract_job_factory.py b/pipelex/cogt/extract/extract_job_factory.py
new file mode 100644
index 000000000..23d06e6d4
--- /dev/null
+++ b/pipelex/cogt/extract/extract_job_factory.py
@@ -0,0 +1,30 @@
+from pipelex.cogt.extract.extract_input import ExtractInput
+from pipelex.cogt.extract.extract_job import ExtractJob
+from pipelex.cogt.extract.extract_job_components import ExtractJobConfig, ExtractJobParams, ExtractJobReport
+from pipelex.pipeline.job_metadata import JobCategory, JobMetadata
+
+
+class ExtractJobFactory:
+ @classmethod
+ def make_extract_job(
+ cls,
+ extract_input: ExtractInput,
+ extract_job_params: ExtractJobParams | None = None,
+ extract_job_config: ExtractJobConfig | None = None,
+ job_metadata: JobMetadata | None = None,
+ ) -> ExtractJob:
+ # TODO: manage the param default through the config
+ job_metadata = job_metadata or JobMetadata(
+ job_category=JobCategory.EXTRACT_JOB,
+ )
+ job_params = extract_job_params or ExtractJobParams.make_default_extract_job_params()
+ job_config = extract_job_config or ExtractJobConfig()
+ job_report = ExtractJobReport()
+
+ return ExtractJob(
+ job_metadata=job_metadata,
+ extract_input=extract_input,
+ job_params=job_params,
+ job_config=job_config,
+ job_report=job_report,
+ )
diff --git a/pipelex/cogt/ocr/ocr_output.py b/pipelex/cogt/extract/extract_output.py
similarity index 98%
rename from pipelex/cogt/ocr/ocr_output.py
rename to pipelex/cogt/extract/extract_output.py
index 186e5600c..de6ce3fd9 100644
--- a/pipelex/cogt/ocr/ocr_output.py
+++ b/pipelex/cogt/extract/extract_output.py
@@ -44,7 +44,7 @@ class Page(CustomBaseModel):
page_view.save_to_directory(directory=directory)
-class OcrOutput(CustomBaseModel):
+class ExtractOutput(CustomBaseModel):
pages: dict[int, Page]
@property
diff --git a/pipelex/cogt/ocr/ocr_setting.py b/pipelex/cogt/extract/extract_setting.py
similarity index 51%
rename from pipelex/cogt/ocr/ocr_setting.py
rename to pipelex/cogt/extract/extract_setting.py
index 9ec34a603..0b887e8be 100644
--- a/pipelex/cogt/ocr/ocr_setting.py
+++ b/pipelex/cogt/extract/extract_setting.py
@@ -5,13 +5,13 @@ from pydantic import Field
from pipelex.tools.config.config_model import ConfigModel
-class OcrSetting(ConfigModel):
- ocr_handle: str
+class ExtractSetting(ConfigModel):
+ extract_handle: str
max_nb_images: int | None = Field(default=None, ge=0)
image_min_size: int | None = Field(default=None, ge=0)
def desc(self) -> str:
- return f"OcrSetting(ocr_handle={self.ocr_handle}, max_nb_images={self.max_nb_images}, image_min_size={self.image_min_size})"
+ return f"OcrSetting(extract_handle={self.extract_handle}, max_nb_images={self.max_nb_images}, image_min_size={self.image_min_size})"
-OcrChoice = Union[OcrSetting, str]
+ExtractChoice = Union[ExtractSetting, str]
diff --git a/pipelex/cogt/ocr/ocr_worker_abstract.py b/pipelex/cogt/extract/extract_worker_abstract.py
similarity index 64%
rename from pipelex/cogt/ocr/ocr_worker_abstract.py
rename to pipelex/cogt/extract/extract_worker_abstract.py
index e80464a5d..b9aafb3ed 100644
--- a/pipelex/cogt/ocr/ocr_worker_abstract.py
+++ b/pipelex/cogt/extract/extract_worker_abstract.py
@@ -4,15 +4,15 @@ from typing import Any
from typing_extensions import override
from pipelex import log
+from pipelex.cogt.extract.extract_job import ExtractJob
+from pipelex.cogt.extract.extract_output import ExtractOutput
from pipelex.cogt.inference.inference_worker_abstract import InferenceWorkerAbstract
from pipelex.cogt.model_backends.model_spec import InferenceModelSpec
-from pipelex.cogt.ocr.ocr_job import OcrJob
-from pipelex.cogt.ocr.ocr_output import OcrOutput
from pipelex.pipeline.job_metadata import UnitJobId
from pipelex.reporting.reporting_protocol import ReportingProtocol
-class OcrWorkerAbstract(InferenceWorkerAbstract):
+class ExtractWorkerAbstract(InferenceWorkerAbstract):
def __init__(
self,
extra_config: dict[str, Any],
@@ -32,42 +32,42 @@ class OcrWorkerAbstract(InferenceWorkerAbstract):
def desc(self) -> str:
return f"OCR-Worker:{self.inference_model.tag}"
- def _check_can_perform_job(self, ocr_job: OcrJob):
+ def _check_can_perform_job(self, extract_job: ExtractJob):
# This can be overridden by subclasses for specific checks
pass
- async def ocr_extract_pages(
+ async def extract_pages(
self,
- ocr_job: OcrJob,
- ) -> OcrOutput:
- log.debug(f"OCR Worker ocr_extract_pages:\n{self.inference_model.desc}")
+ extract_job: ExtractJob,
+ ) -> ExtractOutput:
+ log.debug(f"Extract Worker extract_pages:\n{self.inference_model.desc}")
# Verify that the job is valid
- ocr_job.validate_before_execution()
+ extract_job.validate_before_execution()
# Verify feasibility
- self._check_can_perform_job(ocr_job=ocr_job)
+ self._check_can_perform_job(extract_job=extract_job)
# TODO: check can generate object (where it will be appropriate)
# metadata
- ocr_job.job_metadata.unit_job_id = UnitJobId.OCR_EXTRACT_PAGES
+ extract_job.job_metadata.unit_job_id = UnitJobId.EXTRACT_PAGES
# Prepare job
- ocr_job.ocr_job_before_start()
+ extract_job.extract_job_before_start()
# Execute job
- result = await self._ocr_extract_pages(ocr_job=ocr_job)
+ result = await self._extract_pages(extract_job=extract_job)
# Report job
- ocr_job.ocr_job_after_complete()
+ extract_job.extract_job_after_complete()
if self.reporting_delegate:
- self.reporting_delegate.report_inference_job(inference_job=ocr_job)
+ self.reporting_delegate.report_inference_job(inference_job=extract_job)
return result
@abstractmethod
- async def _ocr_extract_pages(
+ async def _extract_pages(
self,
- ocr_job: OcrJob,
- ) -> OcrOutput:
+ extract_job: ExtractJob,
+ ) -> ExtractOutput:
pass
diff --git a/pipelex/cogt/ocr/ocr_worker_factory.py b/pipelex/cogt/extract/extract_worker_factory.py
similarity index 72%
rename from pipelex/cogt/ocr/ocr_worker_factory.py
rename to pipelex/cogt/extract/extract_worker_factory.py
index d66c563b1..22ffefa04 100644
--- a/pipelex/cogt/ocr/ocr_worker_factory.py
+++ b/pipelex/cogt/extract/extract_worker_factory.py
@@ -1,26 +1,26 @@
+import importlib.util
+
from pipelex.cogt.exceptions import MissingDependencyError
+from pipelex.cogt.extract.extract_worker_abstract import ExtractWorkerAbstract
from pipelex.cogt.model_backends.model_spec import InferenceModelSpec
-from pipelex.cogt.ocr.ocr_worker_abstract import OcrWorkerAbstract
from pipelex.hub import get_models_manager, get_plugin_manager
from pipelex.plugins.plugin_sdk_registry import Plugin
from pipelex.reporting.reporting_protocol import ReportingProtocol
-class OcrWorkerFactory:
- def make_ocr_worker(
+class ExtractWorkerFactory:
+ def make_extract_worker(
self,
inference_model: InferenceModelSpec,
reporting_delegate: ReportingProtocol | None = None,
- ) -> OcrWorkerAbstract:
+ ) -> ExtractWorkerAbstract:
plugin = Plugin.make_for_inference_model(inference_model=inference_model)
backend = get_models_manager().get_required_inference_backend(inference_model.backend_name)
plugin_sdk_registry = get_plugin_manager().plugin_sdk_registry
- ocr_worker: OcrWorkerAbstract
+ extract_worker: ExtractWorkerAbstract
match plugin.sdk:
case "mistral":
- try:
- import mistralai # noqa: PLC0415,F401
- except ImportError as exc:
+ if importlib.util.find_spec("mistralai") is None:
lib_name = "mistralai"
lib_extra_name = "mistral"
msg = "The mistralai SDK is required to use Mistral OCR models through the mistralai client."
@@ -28,18 +28,18 @@ class OcrWorkerFactory:
lib_name,
lib_extra_name,
msg,
- ) from exc
+ )
+ from pipelex.plugins.mistral.mistral_extract_worker import MistralExtractWorker # noqa: PLC0415
from pipelex.plugins.mistral.mistral_factory import MistralFactory # noqa: PLC0415
- from pipelex.plugins.mistral.mistral_ocr_worker import MistralOcrWorker # noqa: PLC0415
- ocr_sdk_instance = plugin_sdk_registry.get_sdk_instance(plugin=plugin) or plugin_sdk_registry.set_sdk_instance(
+ extract_sdk_instance = plugin_sdk_registry.get_sdk_instance(plugin=plugin) or plugin_sdk_registry.set_sdk_instance(
plugin=plugin,
sdk_instance=MistralFactory.make_mistral_client(backend=backend),
)
- ocr_worker = MistralOcrWorker(
- sdk_instance=ocr_sdk_instance,
+ extract_worker = MistralExtractWorker(
+ sdk_instance=extract_sdk_instance,
extra_config=backend.extra_config,
inference_model=inference_model,
reporting_delegate=reporting_delegate,
@@ -47,7 +47,7 @@ class OcrWorkerFactory:
case "pypdfium2":
from pipelex.plugins.pypdfium2.pypdfium2_worker import Pypdfium2Worker # noqa: PLC0415
- ocr_worker = Pypdfium2Worker(
+ extract_worker = Pypdfium2Worker(
extra_config=backend.extra_config,
inference_model=inference_model,
reporting_delegate=reporting_delegate,
@@ -56,4 +56,4 @@ class OcrWorkerFactory:
msg = f"Plugin '{plugin}' is not supported"
raise NotImplementedError(msg)
- return ocr_worker
+ return extract_worker
diff --git a/pipelex/cogt/inference/inference_manager.py b/pipelex/cogt/inference/inference_manager.py
index b3f96b475..89c98136c 100644
--- a/pipelex/cogt/inference/inference_manager.py
+++ b/pipelex/cogt/inference/inference_manager.py
@@ -2,6 +2,8 @@ from typing_extensions import override
from pipelex import log
from pipelex.cogt.exceptions import InferenceManagerWorkerSetupError
+from pipelex.cogt.extract.extract_worker_abstract import ExtractWorkerAbstract
+from pipelex.cogt.extract.extract_worker_factory import ExtractWorkerFactory
from pipelex.cogt.img_gen.img_gen_worker_abstract import ImgGenWorkerAbstract
from pipelex.cogt.img_gen.img_gen_worker_factory import ImgGenWorkerFactory
from pipelex.cogt.inference.inference_manager_protocol import InferenceManagerProtocol
@@ -9,33 +11,32 @@ from pipelex.cogt.llm.llm_worker_abstract import LLMWorkerAbstract
from pipelex.cogt.llm.llm_worker_factory import LLMWorkerFactory
from pipelex.cogt.llm.llm_worker_internal_abstract import LLMWorkerInternalAbstract
from pipelex.cogt.model_backends.model_spec import InferenceModelSpec
-from pipelex.cogt.ocr.ocr_worker_abstract import OcrWorkerAbstract
-from pipelex.cogt.ocr.ocr_worker_factory import OcrWorkerFactory
from pipelex.config import get_config
from pipelex.hub import get_models_manager, get_report_delegate
class InferenceManager(InferenceManagerProtocol):
def __init__(self):
+ # TODO: we don't need instances of the factories, we can just use them via class methods
self.img_gen_worker_factory = ImgGenWorkerFactory()
- self.ocr_worker_factory = OcrWorkerFactory()
+ self.extract_worker_factory = ExtractWorkerFactory()
self.llm_workers: dict[str, LLMWorkerAbstract] = {}
self.img_gen_workers: dict[str, ImgGenWorkerAbstract] = {}
- self.ocr_workers: dict[str, OcrWorkerAbstract] = {}
+ self.extract_workers: dict[str, ExtractWorkerAbstract] = {}
@override
def teardown(self):
self.img_gen_worker_factory = ImgGenWorkerFactory()
- self.ocr_worker_factory = OcrWorkerFactory()
+ self.extract_worker_factory = ExtractWorkerFactory()
for llm_worker in self.llm_workers.values():
llm_worker.teardown()
self.llm_workers = {}
for img_gen_worker in self.img_gen_workers.values():
img_gen_worker.teardown()
self.img_gen_workers = {}
- for ocr_worker in self.ocr_workers.values():
- ocr_worker.teardown()
- self.ocr_workers = {}
+ for extract_worker in self.extract_workers.values():
+ extract_worker.teardown()
+ self.extract_workers = {}
log.verbose("InferenceManager teardown done")
def print_workers(self):
@@ -48,9 +49,9 @@ class InferenceManager(InferenceManagerProtocol):
log.debug(f" {handle}:")
log.debug(img_gen_worker_async.desc)
log.debug("OCR Workers:")
- for handle, ocr_worker_async in self.ocr_workers.items():
+ for handle, extract_worker_async in self.extract_workers.items():
log.debug(f" {handle}:")
- log.debug(ocr_worker_async.desc)
+ log.debug(extract_worker_async.desc)
####################################################################################################
# Setup LLM Workers
@@ -119,31 +120,31 @@ class InferenceManager(InferenceManagerProtocol):
return img_gen_worker
####################################################################################################
- # Manage OCR Workers
+ # Manage Extract Workers
####################################################################################################
- def _setup_one_ocr_worker(
+ def _setup_one_extract_worker(
self,
inference_model: InferenceModelSpec,
- model_handle: str,
- ) -> OcrWorkerAbstract:
- ocr_worker = self.ocr_worker_factory.make_ocr_worker(
+ extract_handle: str,
+ ) -> ExtractWorkerAbstract:
+ extract_worker = self.extract_worker_factory.make_extract_worker(
inference_model=inference_model,
reporting_delegate=get_report_delegate(),
)
- self.ocr_workers[model_handle] = ocr_worker
- return ocr_worker
+ self.extract_workers[extract_handle] = extract_worker
+ return extract_worker
@override
- def get_ocr_worker(self, model_handle: str) -> OcrWorkerAbstract:
- if ocr_worker := self.ocr_workers.get(model_handle):
- return ocr_worker
- if not get_config().cogt.inference_manager_config.is_auto_setup_preset_ocr:
- msg = f"Found no OCR worker for '{model_handle}', set it up or enable cogt.inference_manager_config.is_auto_setup_preset_ocr"
+ def get_extract_worker(self, extract_handle: str) -> ExtractWorkerAbstract:
+ if extract_worker := self.extract_workers.get(extract_handle):
+ return extract_worker
+ if not get_config().cogt.inference_manager_config.is_auto_setup_preset_extract:
+ msg = f"Found no Extract worker for '{extract_handle}', set it up or enable cogt.inference_manager_config.is_auto_setup_preset_extract"
raise InferenceManagerWorkerSetupError(msg)
- inference_model = get_models_manager().get_inference_model(model_handle=model_handle)
- return self._setup_one_ocr_worker(
+ inference_model = get_models_manager().get_inference_model(model_handle=extract_handle)
+ return self._setup_one_extract_worker(
inference_model=inference_model,
- model_handle=model_handle,
+ extract_handle=extract_handle,
)
diff --git a/pipelex/cogt/inference/inference_manager_protocol.py b/pipelex/cogt/inference/inference_manager_protocol.py
index e6ea5d4c8..0472d8278 100644
--- a/pipelex/cogt/inference/inference_manager_protocol.py
+++ b/pipelex/cogt/inference/inference_manager_protocol.py
@@ -1,8 +1,8 @@
from typing import Protocol
+from pipelex.cogt.extract.extract_worker_abstract import ExtractWorkerAbstract
from pipelex.cogt.img_gen.img_gen_worker_abstract import ImgGenWorkerAbstract
from pipelex.cogt.llm.llm_worker_abstract import LLMWorkerAbstract
-from pipelex.cogt.ocr.ocr_worker_abstract import OcrWorkerAbstract
class InferenceManagerProtocol(Protocol):
@@ -32,7 +32,7 @@ class InferenceManagerProtocol(Protocol):
def get_img_gen_worker(self, img_gen_handle: str) -> ImgGenWorkerAbstract: ...
####################################################################################################
- # OCR Workers
+ # Extract Workers
####################################################################################################
- def get_ocr_worker(self, model_handle: str) -> OcrWorkerAbstract: ...
+ def get_extract_worker(self, extract_handle: str) -> ExtractWorkerAbstract: ...
diff --git a/pipelex/cogt/models/model_deck.py b/pipelex/cogt/models/model_deck.py
index 93e780771..7085bbb6c 100644
--- a/pipelex/cogt/models/model_deck.py
+++ b/pipelex/cogt/models/model_deck.py
@@ -4,18 +4,18 @@ from pydantic import Field, field_validator, model_validator
from pipelex import log
from pipelex.cogt.exceptions import (
+ ExtractChoiceNotFoundError,
ImgGenChoiceNotFoundError,
LLMChoiceNotFoundError,
LLMHandleNotFoundError,
LLMSettingsValidationError,
ModelDeckValidatonError,
- OcrChoiceNotFoundError,
)
+from pipelex.cogt.extract.extract_setting import ExtractChoice, ExtractSetting
from pipelex.cogt.img_gen.img_gen_setting import ImgGenChoice, ImgGenSetting
from pipelex.cogt.llm.llm_setting import LLMChoice, LLMSetting, LLMSettingChoices, LLMSettingChoicesDefaults
from pipelex.cogt.model_backends.model_constraints import ModelConstraints
from pipelex.cogt.model_backends.model_spec import InferenceModelSpec
-from pipelex.cogt.ocr.ocr_setting import OcrChoice, OcrSetting
from pipelex.tools.config.config_model import ConfigModel
from pipelex.tools.exceptions import ConfigValidationError
from pipelex.types import Self
@@ -34,9 +34,9 @@ class LLMDeckBlueprint(ConfigModel):
)
-class OCRDeckBlueprint(ConfigModel):
- presets: dict[str, OcrSetting] = Field(default_factory=dict)
- choice_default: OcrChoice
+class ExtractDeckBlueprint(ConfigModel):
+ presets: dict[str, ExtractSetting] = Field(default_factory=dict)
+ choice_default: ExtractChoice
class ImgGenDeckBlueprint(ConfigModel):
@@ -48,7 +48,7 @@ class ModelDeckBlueprint(ConfigModel):
aliases: dict[str, Waterfall] = Field(default_factory=dict)
llm: LLMDeckBlueprint
- ocr: OCRDeckBlueprint
+ extract: ExtractDeckBlueprint
img_gen: ImgGenDeckBlueprint
@@ -63,8 +63,8 @@ class ModelDeck(ConfigModel):
for_object=None,
)
- ocr_presets: dict[str, OcrSetting] = Field(default_factory=dict)
- ocr_choice_default: OcrChoice
+ extract_presets: dict[str, ExtractSetting] = Field(default_factory=dict)
+ extract_choice_default: ExtractChoice
img_gen_presets: dict[str, ImgGenSetting] = Field(default_factory=dict)
img_gen_choice_default: ImgGenChoice
@@ -91,16 +91,16 @@ class ModelDeck(ConfigModel):
msg = f"LLM choice '{llm_choice}' not found in deck"
raise LLMChoiceNotFoundError(msg)
- def get_ocr_setting(self, ocr_choice: OcrChoice) -> OcrSetting:
- if isinstance(ocr_choice, OcrSetting):
- return ocr_choice
- # it's a string, so either an ocr preset id or an ocr handle
- if ocr_preset := self.ocr_presets.get(ocr_choice):
- return ocr_preset
- if self.is_handle_defined(model_handle=ocr_choice):
- return OcrSetting(ocr_handle=ocr_choice)
- msg = f"OCR choice '{ocr_choice}' not found in deck"
- raise OcrChoiceNotFoundError(msg)
+ def get_extract_setting(self, extract_choice: ExtractChoice) -> ExtractSetting:
+ if isinstance(extract_choice, ExtractSetting):
+ return extract_choice
+ # it's a string, so either an extract preset id or an extract handle
+ if extract_preset := self.extract_presets.get(extract_choice):
+ return extract_preset
+ if self.is_handle_defined(model_handle=extract_choice):
+ return ExtractSetting(extract_handle=extract_choice)
+ msg = f"Extract choice '{extract_choice}' not found in deck"
+ raise ExtractChoiceNotFoundError(msg)
def get_img_gen_setting(self, img_gen_choice: ImgGenChoice) -> ImgGenSetting:
if isinstance(img_gen_choice, ImgGenSetting):
diff --git a/pipelex/cogt/models/model_deck_check.py b/pipelex/cogt/models/model_deck_check.py
index 4faf808aa..d45ffc3f1 100644
--- a/pipelex/cogt/models/model_deck_check.py
+++ b/pipelex/cogt/models/model_deck_check.py
@@ -1,7 +1,7 @@
-from pipelex.cogt.exceptions import ImgGenChoiceNotFoundError, LLMChoiceNotFoundError, OcrChoiceNotFoundError
+from pipelex.cogt.exceptions import ExtractChoiceNotFoundError, ImgGenChoiceNotFoundError, LLMChoiceNotFoundError
+from pipelex.cogt.extract.extract_setting import ExtractChoice, ExtractSetting
from pipelex.cogt.img_gen.img_gen_setting import ImgGenChoice, ImgGenSetting
from pipelex.cogt.llm.llm_setting import LLMChoice, LLMSetting
-from pipelex.cogt.ocr.ocr_setting import OcrChoice, OcrSetting
from pipelex.hub import get_model_deck
@@ -9,29 +9,29 @@ def check_llm_choice_with_deck(llm_choice: LLMChoice):
if isinstance(llm_choice, LLMSetting):
return
- llm_deck = get_model_deck()
+ model_deck = get_model_deck()
- if llm_choice in llm_deck.llm_presets or llm_deck.is_handle_defined(model_handle=llm_choice):
+ if llm_choice in model_deck.llm_presets or model_deck.is_handle_defined(model_handle=llm_choice):
return
msg = f"LLM choice '{llm_choice}' not found in deck"
raise LLMChoiceNotFoundError(msg)
-def check_ocr_choice_with_deck(ocr_choice: OcrChoice):
- if isinstance(ocr_choice, OcrSetting):
+def check_extract_choice_with_deck(extract_choice: ExtractChoice):
+ if isinstance(extract_choice, ExtractSetting):
return
- ocr_deck = get_model_deck()
- if ocr_choice in ocr_deck.ocr_presets or ocr_deck.is_handle_defined(model_handle=ocr_choice):
+ model_deck = get_model_deck()
+ if extract_choice in model_deck.extract_presets or model_deck.is_handle_defined(model_handle=extract_choice):
return
- msg = f"OCR choice '{ocr_choice}' not found in deck"
- raise OcrChoiceNotFoundError(msg)
+ msg = f"OCR choice '{extract_choice}' not found in deck"
+ raise ExtractChoiceNotFoundError(msg)
def check_img_gen_choice_with_deck(img_gen_choice: ImgGenChoice):
if isinstance(img_gen_choice, ImgGenSetting):
return
- img_gen_deck = get_model_deck()
- if img_gen_choice in img_gen_deck.img_gen_presets or img_gen_deck.is_handle_defined(model_handle=img_gen_choice):
+ model_deck = get_model_deck()
+ if img_gen_choice in model_deck.img_gen_presets or model_deck.is_handle_defined(model_handle=img_gen_choice):
return
msg = f"Image generation choice '{img_gen_choice}' not found in deck"
raise ImgGenChoiceNotFoundError(msg)
diff --git a/pipelex/cogt/models/model_manager.py b/pipelex/cogt/models/model_manager.py
index 37f5dbaa2..e237868e6 100644
--- a/pipelex/cogt/models/model_manager.py
+++ b/pipelex/cogt/models/model_manager.py
@@ -127,8 +127,8 @@ class ModelManager(ModelManagerAbstract):
llm_presets=model_deck_blueprint.llm.presets,
llm_choice_defaults=model_deck_blueprint.llm.choice_defaults,
llm_choice_overrides=model_deck_blueprint.llm.choice_overrides,
- ocr_presets=model_deck_blueprint.ocr.presets,
- ocr_choice_default=model_deck_blueprint.ocr.choice_default,
+ extract_presets=model_deck_blueprint.extract.presets,
+ extract_choice_default=model_deck_blueprint.extract.choice_default,
img_gen_presets=model_deck_blueprint.img_gen.presets,
img_gen_choice_default=model_deck_blueprint.img_gen.choice_default,
)
diff --git a/pipelex/cogt/ocr/ocr_job.py b/pipelex/cogt/ocr/ocr_job.py
deleted file mode 100644
index 3047498bf..000000000
--- a/pipelex/cogt/ocr/ocr_job.py
+++ /dev/null
@@ -1,28 +0,0 @@
-from datetime import datetime
-
-from typing_extensions import override
-
-from pipelex.cogt.inference.inference_job_abstract import InferenceJobAbstract
-from pipelex.cogt.ocr.ocr_input import OcrInput
-from pipelex.cogt.ocr.ocr_job_components import OcrJobConfig, OcrJobParams, OcrJobReport
-
-
-class OcrJob(InferenceJobAbstract):
- ocr_input: OcrInput
- job_params: OcrJobParams
- job_config: OcrJobConfig
- job_report: OcrJobReport = OcrJobReport()
-
- @override
- def validate_before_execution(self):
- pass
-
- def ocr_job_before_start(self):
- # Reset metadata
- self.job_metadata.started_at = datetime.now()
-
- # Reset outputs
- self.job_report = OcrJobReport()
-
- def ocr_job_after_complete(self):
- self.job_metadata.completed_at = datetime.now()
diff --git a/pipelex/cogt/ocr/ocr_job_factory.py b/pipelex/cogt/ocr/ocr_job_factory.py
deleted file mode 100644
index c89601f4c..000000000
--- a/pipelex/cogt/ocr/ocr_job_factory.py
+++ /dev/null
@@ -1,31 +0,0 @@
-from pipelex.cogt.ocr.ocr_input import OcrInput
-from pipelex.cogt.ocr.ocr_job import OcrJob
-from pipelex.cogt.ocr.ocr_job_components import OcrJobConfig, OcrJobParams, OcrJobReport
-from pipelex.pipeline.job_metadata import JobCategory, JobMetadata
-
-
-class OcrJobFactory:
- @classmethod
- def make_ocr_job(
- cls,
- ocr_input: OcrInput,
- ocr_job_params: OcrJobParams | None = None,
- ocr_job_config: OcrJobConfig | None = None,
- job_metadata: JobMetadata | None = None,
- ) -> OcrJob:
- # TODO: manage the param default through the config
- # ocr_config = get_config().cogt.ocr_config
- job_metadata = job_metadata or JobMetadata(
- job_category=JobCategory.OCR_JOB,
- )
- job_params = ocr_job_params or OcrJobParams.make_default_ocr_job_params()
- job_config = ocr_job_config or OcrJobConfig()
- job_report = OcrJobReport()
-
- return OcrJob(
- job_metadata=job_metadata,
- ocr_input=ocr_input,
- job_params=job_params,
- job_config=job_config,
- job_report=job_report,
- )
diff --git a/pipelex/config.py b/pipelex/config.py
index 96d062275..9a2402519 100644
--- a/pipelex/config.py
+++ b/pipelex/config.py
@@ -49,7 +49,7 @@ class DryRunConfig(ConfigModel):
apply_to_jinja2_rendering: bool
text_gen_truncate_length: int
nb_list_items: int
- nb_ocr_pages: int
+ nb_extract_pages: int
image_urls: list[str]
allowed_to_fail_pipes: list[str] = Field(default_factory=list)
diff --git a/pipelex/config_template/inference/deck/base_deck.toml b/pipelex/config_template/inference/deck/base_deck.toml
index c262d6cfb..90dbc838d 100644
--- a/pipelex/config_template/inference/deck/base_deck.toml
+++ b/pipelex/config_template/inference/deck/base_deck.toml
@@ -17,8 +17,10 @@ best-gemini = "gemini-2.5-pro"
best-mistral = "mistral-medium"
best-grok = "grok-3"
+cheap-gpt = "gpt-4o-mini"
cheap_llm_for_text = "gpt-4o-mini"
cheap_llm_for_object = "gpt-4o-mini"
+cheap_llm_for_vision = "gemini-2.5-flash-lite"
base_llm_for_text = "gpt-4o-mini"
base_llm_for_object = "gpt-4o-mini"
@@ -53,6 +55,8 @@ cheap_llm_to_structure = { llm_handle = "cheap_llm_for_object", temperature = 0.
llm_for_testing_gen_text = { llm_handle = "base_llm_for_text", temperature = 0.5 }
llm_for_testing_gen_object = { llm_handle = "base_llm_for_object", temperature = 0.5 }
+llm_for_testing_vision = { llm_handle = "cheap_llm_for_vision", temperature = 0.5 }
+llm_for_testing_vision_structured = { llm_handle = "cheap-gpt", temperature = 0.5 }
####################################################################################################
# LLM Presets — Specific skills
@@ -106,12 +110,12 @@ for_object = "cheap_llm_for_object"
# OCR Presets
####################################################################################################
-[ocr]
+[extract]
choice_default = "base_ocr_mistral"
-[ocr.presets]
-base_ocr_mistral = { ocr_handle = "mistral-ocr", max_nb_images = 100, image_min_size = 50 }
-base_ocr_pypdfium2 = { ocr_handle = "pypdfium2-extract-text", max_nb_images = 100, image_min_size = 50 }
+[extract.presets]
+base_ocr_mistral = { extract_handle = "mistral-ocr", max_nb_images = 100, image_min_size = 50 }
+base_extract_pypdfium2 = { extract_handle = "pypdfium2-extract-text", max_nb_images = 100, image_min_size = 50 }
####################################################################################################
# Image Generation Presets
diff --git a/pipelex/config_template/pipelex.toml b/pipelex/config_template/pipelex.toml
index 788e7dab1..dddcbf095 100644
--- a/pipelex/config_template/pipelex.toml
+++ b/pipelex/config_template/pipelex.toml
@@ -14,7 +14,7 @@ api_key_method = "env"
# OCR config
####################################################################################################
-[cogt.ocr_config]
+[cogt.extract_config]
page_output_text_file_name = "page_text.md"
[pipelex.feature_config]
diff --git a/pipelex/core/bundles/pipelex_bundle_blueprint.py b/pipelex/core/bundles/pipelex_bundle_blueprint.py
index 2c2cf9c26..c0a8af155 100644
--- a/pipelex/core/bundles/pipelex_bundle_blueprint.py
+++ b/pipelex/core/bundles/pipelex_bundle_blueprint.py
@@ -9,17 +9,17 @@ from pipelex.pipe_controllers.condition.pipe_condition_blueprint import PipeCond
from pipelex.pipe_controllers.parallel.pipe_parallel_blueprint import PipeParallelBlueprint
from pipelex.pipe_controllers.sequence.pipe_sequence_blueprint import PipeSequenceBlueprint
from pipelex.pipe_operators.compose.pipe_compose_blueprint import PipeComposeBlueprint
+from pipelex.pipe_operators.extract.pipe_extract_blueprint import PipeExtractBlueprint
from pipelex.pipe_operators.func.pipe_func_blueprint import PipeFuncBlueprint
from pipelex.pipe_operators.img_gen.pipe_img_gen_blueprint import PipeImgGenBlueprint
from pipelex.pipe_operators.llm.pipe_llm_blueprint import PipeLLMBlueprint
-from pipelex.pipe_operators.ocr.pipe_ocr_blueprint import PipeOcrBlueprint
PipeBlueprintUnion = Annotated[
PipeFuncBlueprint
| PipeImgGenBlueprint
| PipeComposeBlueprint
| PipeLLMBlueprint
- | PipeOcrBlueprint
+ | PipeExtractBlueprint
| PipeBatchBlueprint
| PipeConditionBlueprint
| PipeParallelBlueprint
diff --git a/pipelex/core/concepts/concept_factory.py b/pipelex/core/concepts/concept_factory.py
index f48fd2694..94639d2b9 100644
--- a/pipelex/core/concepts/concept_factory.py
+++ b/pipelex/core/concepts/concept_factory.py
@@ -69,7 +69,7 @@ class ConceptFactory:
)
@classmethod
- def make_native_concept_from_enum(cls, native_concept_code: NativeConceptCode) -> Concept:
+ def make_native_concept(cls, native_concept_code: NativeConceptCode) -> Concept:
structure_class_name = native_concept_code.structure_class_name
match native_concept_code:
case NativeConceptCode.DYNAMIC:
@@ -138,7 +138,7 @@ class ConceptFactory:
@classmethod
def make_all_native_concepts(cls) -> list[Concept]:
- return [cls.make_native_concept_from_enum(native_concept_code=native_concept) for native_concept in NativeConceptCode.values_list()]
+ return [cls.make_native_concept(native_concept_code=native_concept) for native_concept in NativeConceptCode.values_list()]
@classmethod
def make_domain_and_concept_code_from_concept_string_or_code(
diff --git a/pipelex/core/pipes/pipe_blueprint.py b/pipelex/core/pipes/pipe_blueprint.py
index 1f71639b3..a825fad06 100644
--- a/pipelex/core/pipes/pipe_blueprint.py
+++ b/pipelex/core/pipes/pipe_blueprint.py
@@ -40,7 +40,7 @@ class AllowedPipeTypes(StrEnum):
PIPE_IMG_GEN = "PipeImgGen"
PIPE_COMPOSE = "PipeCompose"
PIPE_LLM = "PipeLLM"
- PIPE_OCR = "PipeOcr"
+ PIPE_OCR = "PipeExtract"
# Pipe Controller
PIPE_BATCH = "PipeBatch"
PIPE_CONDITION = "PipeCondition"
diff --git a/pipelex/core/registry_models.py b/pipelex/core/registry_models.py
index f3aeba5cf..73a5eeb4f 100644
--- a/pipelex/core/registry_models.py
+++ b/pipelex/core/registry_models.py
@@ -24,14 +24,14 @@ from pipelex.pipe_controllers.sequence.pipe_sequence import PipeSequence
from pipelex.pipe_controllers.sequence.pipe_sequence_factory import PipeSequenceFactory
from pipelex.pipe_operators.compose.pipe_compose import PipeCompose
from pipelex.pipe_operators.compose.pipe_compose_factory import PipeComposeFactory
+from pipelex.pipe_operators.extract.pipe_extract import PipeExtract
+from pipelex.pipe_operators.extract.pipe_extract_factory import PipeExtractFactory
from pipelex.pipe_operators.func.pipe_func import PipeFunc
from pipelex.pipe_operators.func.pipe_func_factory import PipeFuncFactory
from pipelex.pipe_operators.img_gen.pipe_img_gen import PipeImgGen
from pipelex.pipe_operators.img_gen.pipe_img_gen_factory import PipeImgGenFactory
from pipelex.pipe_operators.llm.pipe_llm import PipeLLM
from pipelex.pipe_operators.llm.pipe_llm_factory import PipeLLMFactory
-from pipelex.pipe_operators.ocr.pipe_ocr import PipeOcr
-from pipelex.pipe_operators.ocr.pipe_ocr_factory import PipeOcrFactory
from pipelex.tools.registry_models import ModelType, RegistryModels
@@ -43,7 +43,7 @@ class PipelexRegistryModels(RegistryModels):
PipeImgGen,
PipeCompose,
PipeLLM,
- PipeOcr,
+ PipeExtract,
]
PIPE_OPERATORS_FACTORY: ClassVar[list[PipeFactoryProtocol[Any, Any]]] = [
@@ -51,7 +51,7 @@ class PipelexRegistryModels(RegistryModels):
PipeImgGenFactory,
PipeComposeFactory,
PipeLLMFactory,
- PipeOcrFactory,
+ PipeExtractFactory,
]
PIPE_CONTROLLERS: ClassVar[list[PipeAbstractType]] = [
diff --git a/pipelex/core/stuffs/image_content.py b/pipelex/core/stuffs/image_content.py
index 4c67919c0..288f187ba 100644
--- a/pipelex/core/stuffs/image_content.py
+++ b/pipelex/core/stuffs/image_content.py
@@ -6,7 +6,7 @@ from PIL import Image
from typing_extensions import override
from yattag import Doc
-from pipelex.cogt.ocr.ocr_output import ExtractedImage
+from pipelex.cogt.extract.extract_output import ExtractedImage
from pipelex.core.stuffs.stuff_content import StuffContent
from pipelex.tools.misc.base_64_utils import save_base64_to_binary_file
from pipelex.tools.misc.file_utils import ensure_directory_exists, get_incremental_file_path, save_text_to_path
diff --git a/pipelex/core/stuffs/stuff_factory.py b/pipelex/core/stuffs/stuff_factory.py
index 000674e53..c11ba9d3c 100644
--- a/pipelex/core/stuffs/stuff_factory.py
+++ b/pipelex/core/stuffs/stuff_factory.py
@@ -41,7 +41,7 @@ class StuffFactory:
@classmethod
def make_from_str(cls, str_value: str, name: str) -> Stuff:
return cls.make_stuff(
- concept=ConceptFactory.make_native_concept_from_enum(native_concept_code=NativeConceptCode.TEXT),
+ concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.TEXT),
content=TextContent(text=str_value),
name=name,
)
@@ -214,7 +214,7 @@ class StuffFactory:
elif isinstance(stuff_content_or_data, str):
str_stuff: str = stuff_content_or_data
return StuffFactory.make_stuff(
- concept=ConceptFactory.make_native_concept_from_enum(native_concept_code=NativeConceptCode.TEXT),
+ concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.TEXT),
content=TextContent(text=str_stuff),
name=name,
)
@@ -227,7 +227,7 @@ class StuffFactory:
raise StuffFactoryError(msg)
content_value = stuff_content_dict["content"]
if NativeConceptCode.get_validated_native_concept_string(concept_string_or_code=concept_code):
- concept = ConceptFactory.make_native_concept_from_enum(native_concept_code=NativeConceptCode(concept_code))
+ concept = ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode(concept_code))
content = StuffContentFactory.make_stuff_content_from_concept_with_fallback(
concept=concept,
value=content_value,
diff --git a/pipelex/hub.py b/pipelex/hub.py
index 3fb2f5d2f..ca260fd39 100644
--- a/pipelex/hub.py
+++ b/pipelex/hub.py
@@ -6,12 +6,12 @@ from pipelex import log
from pipelex.cogt.content_generation.content_generator_protocol import (
ContentGeneratorProtocol,
)
+from pipelex.cogt.extract.extract_worker_abstract import ExtractWorkerAbstract
from pipelex.cogt.img_gen.img_gen_worker_abstract import ImgGenWorkerAbstract
from pipelex.cogt.inference.inference_manager_protocol import InferenceManagerProtocol
from pipelex.cogt.llm.llm_worker_abstract import LLMWorkerAbstract
from pipelex.cogt.models.model_deck import ModelDeck
from pipelex.cogt.models.model_manager_abstract import ModelManagerAbstract
-from pipelex.cogt.ocr.ocr_worker_abstract import OcrWorkerAbstract
from pipelex.core.concepts.concept import Concept
from pipelex.core.concepts.concept_library_abstract import ConceptLibraryAbstract
from pipelex.core.concepts.concept_native import NativeConceptCode
@@ -371,10 +371,10 @@ def get_img_gen_worker(
return get_inference_manager().get_img_gen_worker(img_gen_handle=img_gen_handle)
-def get_ocr_worker(
- ocr_handle: str,
-) -> OcrWorkerAbstract:
- return get_inference_manager().get_ocr_worker(model_handle=ocr_handle)
+def get_extract_worker(
+ extract_handle: str,
+) -> ExtractWorkerAbstract:
+ return get_inference_manager().get_extract_worker(extract_handle=extract_handle)
def get_report_delegate() -> ReportingProtocol:
diff --git a/pipelex/libraries/pipelines/builder/builder.plx b/pipelex/libraries/pipelines/builder/builder.plx
index 8a276aefa..fcbf42cd7 100644
--- a/pipelex/libraries/pipelines/builder/builder.plx
+++ b/pipelex/libraries/pipelines/builder/builder.plx
@@ -80,7 +80,7 @@ Available pipe operators:
- PipeImgGen: A pipe that uses an AI model to generate an image.
VERY IMPORTANT: IF YOU DECIDE TO CREATE A PipeImgGen, YOU ALSO HAVE TO CREATE A PIPELLM THAT WILL WRITE THE PROMPT, AND THAT NEEDS TO PRECEED THE PIPEIMGEN, based on the necessary elements.
That means that in the MAIN pipeline, the prompt MUST NOT be considered as an input. It should be the output of a step that generates the prompt.
-- PipeOcr: A pipe that uses an OCR technology to extract text from an image or a pdf.
+- PipeExtract: A pipe that uses an OCR technology to extract text from an image or a pdf.
VERY IMPORTANT: THE INPUT OF THE PIPEOCR MUST BE either an image or a pdf or a concept which refines one of them.
@@ -101,7 +101,7 @@ inputs = { plan_draft = "PlanDraft", brief = "UserBrief" }
output = "ConceptDrafts"
llm = "llm_to_engineer"
prompt_template = """
-We are working on writing an AI pipeleine to fulfill this brief:
+We are working on writing an AI pipeline to fulfill this brief:
@brief
We have already written a plan for the pipeline. It's built using pipes, each with its own inputs (one or more) and output (single).
@@ -206,7 +206,7 @@ Available pipe operators:
- PipeImgGen: A pipe that uses an AI model to generate an image.
VERY IMPORTANT: IF YOU DECIDE TO CREATE A PipeImgGen, YOU ALSO HAVE TO CREATE A PIPELLM THAT WILL WRITE THE PROMPT, AND THAT NEEDS TO PRECEED THE PIPEIMGEN, based on the necessary elements.
That means that in the MAIN pipeline, the prompt MUST NOT be considered as an input. It should be the output of a step that generates the prompt.
-- PipeOcr: A pipe that extracts text from an image or a pdf. PipeOcr must have a exactly one input which must be either an `Image` or a `PDF`.
+- PipeExtract: A pipe that extracts text from an image or a pdf. PipeExtract must have a exactly one input which must be either an `Image` or a `PDF`.
Be smart about splitting the workflow into steps (sequence or parallel):
- You can use an LLM to extract or analyze several things at the same time, they can be output as a single concept which will be structured with attributes etc.
diff --git a/pipelex/libraries/pipelines/builder/builder.py b/pipelex/libraries/pipelines/builder/builder.py
index 91872c516..f98296e3d 100644
--- a/pipelex/libraries/pipelines/builder/builder.py
+++ b/pipelex/libraries/pipelines/builder/builder.py
@@ -34,10 +34,10 @@ from pipelex.libraries.pipelines.builder.concept.concept_spec import ConceptSpec
from pipelex.libraries.pipelines.builder.pipe.pipe_batch_spec import PipeBatchSpec
from pipelex.libraries.pipelines.builder.pipe.pipe_compose_spec import PipeComposeSpec
from pipelex.libraries.pipelines.builder.pipe.pipe_condition_spec import PipeConditionSpec
+from pipelex.libraries.pipelines.builder.pipe.pipe_extract_spec import PipeExtractSpec
from pipelex.libraries.pipelines.builder.pipe.pipe_func_spec import PipeFuncSpec
from pipelex.libraries.pipelines.builder.pipe.pipe_img_spec import PipeImgGenSpec
from pipelex.libraries.pipelines.builder.pipe.pipe_llm_spec import PipeLLMSpec
-from pipelex.libraries.pipelines.builder.pipe.pipe_ocr_spec import PipeOcrSpec
from pipelex.libraries.pipelines.builder.pipe.pipe_parallel_spec import PipeParallelSpec
from pipelex.libraries.pipelines.builder.pipe.pipe_sequence_spec import PipeSequenceSpec
from pipelex.libraries.pipelines.builder.pipe.pipe_signature import PipeSpec
@@ -58,7 +58,7 @@ PipeSpecUnion = Annotated[
| PipeImgGenSpec
| PipeComposeSpec
| PipeLLMSpec
- | PipeOcrSpec
+ | PipeExtractSpec
| PipeBatchSpec
| PipeConditionSpec
| PipeParallelSpec
@@ -172,7 +172,7 @@ def _convert_pipe_spec(pipe_spec: PipeSpecUnion) -> PipeSpecUnion:
"PipeImgGen": PipeImgGenSpec,
"PipeCompose": PipeComposeSpec,
"PipeLLM": PipeLLMSpec,
- "PipeOcr": PipeOcrSpec,
+ "PipeExtract": PipeExtractSpec,
"PipeBatch": PipeBatchSpec,
"PipeCondition": PipeConditionSpec,
"PipeParallel": PipeParallelSpec,
@@ -296,7 +296,7 @@ async def validate_bundle_spec(pipelex_bundle_spec: PipelexBundleSpec):
"PipeImgGen": PipeImgGenSpec,
"PipeCompose": PipeComposeSpec,
"PipeLLM": PipeLLMSpec,
- "PipeOcr": PipeOcrSpec,
+ "PipeExtract": PipeExtractSpec,
"PipeBatch": PipeBatchSpec,
"PipeCondition": PipeConditionSpec,
"PipeParallel": PipeParallelSpec,
diff --git a/pipelex/libraries/pipelines/builder/builder_errors.py b/pipelex/libraries/pipelines/builder/builder_errors.py
index 3c45746f8..c37deb293 100644
--- a/pipelex/libraries/pipelines/builder/builder_errors.py
+++ b/pipelex/libraries/pipelines/builder/builder_errors.py
@@ -11,10 +11,10 @@ from pipelex.libraries.pipelines.builder.concept.concept_spec import ConceptSpec
from pipelex.libraries.pipelines.builder.pipe.pipe_batch_spec import PipeBatchSpec
from pipelex.libraries.pipelines.builder.pipe.pipe_compose_spec import PipeComposeSpec
from pipelex.libraries.pipelines.builder.pipe.pipe_condition_spec import PipeConditionSpec
+from pipelex.libraries.pipelines.builder.pipe.pipe_extract_spec import PipeExtractSpec
from pipelex.libraries.pipelines.builder.pipe.pipe_func_spec import PipeFuncSpec
from pipelex.libraries.pipelines.builder.pipe.pipe_img_spec import PipeImgGenSpec
from pipelex.libraries.pipelines.builder.pipe.pipe_llm_spec import PipeLLMSpec
-from pipelex.libraries.pipelines.builder.pipe.pipe_ocr_spec import PipeOcrSpec
from pipelex.libraries.pipelines.builder.pipe.pipe_parallel_spec import PipeParallelSpec
from pipelex.libraries.pipelines.builder.pipe.pipe_sequence_spec import PipeSequenceSpec
from pipelex.types import Self
@@ -25,7 +25,7 @@ PipeSpecUnion = (
| PipeImgGenSpec
| PipeComposeSpec
| PipeLLMSpec
- | PipeOcrSpec
+ | PipeExtractSpec
| PipeBatchSpec
| PipeConditionSpec
| PipeParallelSpec
@@ -94,7 +94,7 @@ class PipeFailure(StructuredContent):
| PipeImgGenSpec
| PipeComposeSpec
| PipeLLMSpec
- | PipeOcrSpec
+ | PipeExtractSpec
| PipeBatchSpec
| PipeConditionSpec
| PipeParallelSpec
diff --git a/pipelex/libraries/pipelines/builder/flow.py b/pipelex/libraries/pipelines/builder/flow.py
index ce54c296c..7e866599b 100644
--- a/pipelex/libraries/pipelines/builder/flow.py
+++ b/pipelex/libraries/pipelines/builder/flow.py
@@ -19,7 +19,7 @@ class Flow(StructuredContent):
implementation details. It shows:
- Domain and description
- Pipe controllers (sequence, parallel, condition, batch) with their full structure
- - Pipe operators (LLM, func, img_gen, compose, ocr) as signatures only
+ - Pipe operators (LLM, Func, ImgGgen, Compose, Extract) as signatures only
This representation is useful for understanding the overall workflow and
dependencies without getting into implementation specifics.
diff --git a/pipelex/libraries/pipelines/builder/pipe/pipe_design.plx b/pipelex/libraries/pipelines/builder/pipe/pipe_design.plx
index 231ace7a9..2bdf8624d 100644
--- a/pipelex/libraries/pipelines/builder/pipe/pipe_design.plx
+++ b/pipelex/libraries/pipelines/builder/pipe/pipe_design.plx
@@ -5,16 +5,16 @@ description = "Build and process pipes."
PipeSignature = "A pipe contract which says what the pipe does, not how it does it: code (the pipe code in snake_case), type, description, inputs, output."
PipeSpec = "A structured spec for a pipe (union)."
# Pipe controllers
-PipeBatchSpec = "A structured spec for a pipe batch."
-PipeConditionSpec = "A structured spec for a pipe condition."
-PipeParallelSpec = "A structured spec for a pipe parallel."
-PipeSequenceSpec = "A structured spec for a pipe sequence."
+PipeBatchSpec = "A structured spec for a PipeBatch."
+PipeConditionSpec = "A structured spec for a PipeCondition."
+PipeParallelSpec = "A structured spec for a PipeParallel."
+PipeSequenceSpec = "A structured spec for a PipeSequence."
# Pipe operators
-PipeFuncSpec = "A structured spec for a pipe func."
-PipeImgGenSpec = "A structured spec for a pipe img gen."
-# PipeComposeSpec = "A structured spec for a pipe jinja2."
-PipeLLMSpec = "A structured spec for a pipe llm."
-PipeOcrSpec = "A structured spec for a pipe ocr."
+PipeFuncSpec = "A structured spec for a PipeFunc."
+PipeImgGenSpec = "A structured spec for a PipeImgGen."
+PipeComposeSpec = "A structured spec for a pipe jinja2."
+PipeLLMSpec = "A structured spec for a PipeLLM."
+PipeExtractSpec = "A structured spec for a PipeExtract."
PipeFailure = "Details of a single pipe failure during dry run."
[pipe]
@@ -32,7 +32,7 @@ PipeSequence = "detail_pipe_sequence"
PipeParallel = "detail_pipe_parallel"
PipeCondition = "detail_pipe_condition"
PipeLLM = "detail_pipe_llm"
-PipeOcr = "detail_pipe_ocr"
+PipeExtract = "detail_pipe_extract"
PipeImgGen = "detail_pipe_img_gen"
# ────────────────────────────────────────────────────────────────────────────────
@@ -124,19 +124,19 @@ Here are the concepts you can use for inputs/outputs:
@concept_specs
"""
-[pipe.detail_pipe_ocr]
+[pipe.detail_pipe_extract]
type = "PipeLLM"
-description = "Build a PipeOcrSpec from the signature."
+description = "Build a PipeExtractSpec from the signature."
inputs = { plan_draft = "PlanDraft", pipe_signature = "PipeSignature", concept_specs = "concept.ConceptSpec" }
-output = "PipeOcrSpec"
+output = "PipeExtractSpec"
llm = "llm_to_engineer"
prompt_template = """
-Your job is to design a PipeOcrSpec to extract text from an image or a pdf.
+Your job is to design a PipeExtractSpec to extract text from an image or a pdf.
-This PipeOcr is part of a larger pipeline:
+This PipeExtract is part of a larger pipeline:
@plan_draft
-You will specifically generate the PipeOcr related to this signature:
+You will specifically generate the PipeExtract related to this signature:
@pipe_signature
Here are the concepts you can use for inputs/outputs:
diff --git a/pipelex/libraries/pipelines/builder/pipe/pipe_ocr_spec.py b/pipelex/libraries/pipelines/builder/pipe/pipe_extract_spec.py
similarity index 52%
rename from pipelex/libraries/pipelines/builder/pipe/pipe_ocr_spec.py
rename to pipelex/libraries/pipelines/builder/pipe/pipe_extract_spec.py
index 5ede44b4a..09fc7237b 100644
--- a/pipelex/libraries/pipelines/builder/pipe/pipe_ocr_spec.py
+++ b/pipelex/libraries/pipelines/builder/pipe/pipe_extract_spec.py
@@ -6,36 +6,36 @@ from typing_extensions import override
from pipelex.exceptions import PipeDefinitionError
from pipelex.libraries.pipelines.builder.pipe.pipe_signature import PipeSpec
-from pipelex.pipe_operators.ocr.pipe_ocr_blueprint import PipeOcrBlueprint
+from pipelex.pipe_operators.extract.pipe_extract_blueprint import PipeExtractBlueprint
from pipelex.types import StrEnum
if TYPE_CHECKING:
- from pipelex.cogt.ocr.ocr_setting import OcrChoice
+ from pipelex.cogt.extract.extract_setting import ExtractChoice
-class AvailableOcr(StrEnum):
+class AvailableExtractModel(StrEnum):
BASE_OCR_MISTRAL = "base_ocr_mistral"
- # BASE_OCR_PYPDFIUM2 = "base_ocr_pypdfium2"
+ # BASE_EXTRACT_PYPDFIUM2 = "base_extract_pypdfium2"
-class OcrSkill(StrEnum):
+class ExtractSkill(StrEnum):
EXTRACT_TEXT_FROM_VISUALS = "extract_text_from_visuals"
EXTARCT_TEXT_FROM_PDF = "extract_text_from_pdf"
@property
- def ocr_recommendation(self) -> AvailableOcr:
+ def model_recommendation(self) -> AvailableExtractModel:
match self:
- case OcrSkill.EXTRACT_TEXT_FROM_VISUALS:
- return AvailableOcr.BASE_OCR_MISTRAL
- case OcrSkill.EXTARCT_TEXT_FROM_PDF:
+ case ExtractSkill.EXTRACT_TEXT_FROM_VISUALS:
+ return AvailableExtractModel.BASE_OCR_MISTRAL
+ case ExtractSkill.EXTARCT_TEXT_FROM_PDF:
# TODO: Debug the BaseOcrPypdfium2
- return AvailableOcr.BASE_OCR_MISTRAL
+ return AvailableExtractModel.BASE_OCR_MISTRAL
-class PipeOcrSpec(PipeSpec):
+class PipeExtractSpec(PipeSpec):
"""Spec for OCR (Optical Character Recognition) pipe operations in the Pipelex framework.
- PipeOcr enables text extraction from images and documents using OCR technology.
+ PipeExtract enables text extraction from images and documents using OCR technology.
Supports various OCR platforms and output configurations including image detection,
caption generation, and page rendering.
@@ -43,48 +43,48 @@ class PipeOcrSpec(PipeSpec):
- inputs dict must have exactly one input entry, and the value must be either `Image` or `PDF`.
"""
- type: SkipJsonSchema[Literal["PipeOcr"]] = "PipeOcr"
+ type: SkipJsonSchema[Literal["PipeExtract"]] = "PipeExtract"
category: SkipJsonSchema[Literal["PipeOperator"]] = "PipeOperator"
- ocr: OcrSkill | str = Field(description="Use one of the recommended OCR choices")
- page_images: bool | None = Field(default=None, description="Whether to include detected images in the OCR output.")
+ extract_skill: ExtractSkill | str = Field(description="Select the most adequate extraction model skill according to the task to be performed.")
+ page_images: bool | None = Field(default=None, description="Whether to include detected images in the Extract output.")
page_image_captions: bool | None = Field(default=None, description="Whether to generate captions for detected images using AI.")
page_views: bool | None = Field(default=None, description="Whether to include rendered page views in the output.")
- @field_validator("ocr", mode="before")
+ @field_validator("extract_skill", mode="before")
@classmethod
- def validate_ocr(cls, ocr_value: str) -> OcrSkill:
- return OcrSkill(ocr_value)
+ def validate_extract_skill(cls, extract_skill_value: str) -> ExtractSkill:
+ return ExtractSkill(extract_skill_value)
@field_validator("inputs", mode="before")
@classmethod
- def validate_ocr_inputs(cls, inputs_value: dict[str, str] | None) -> dict[str, str] | None:
+ def validate_extract_inputs(cls, inputs_value: dict[str, str] | None) -> dict[str, str] | None:
if inputs_value is None:
- msg = "PipeOcr must have exactly one input which must be either`Image` or `PDF`."
+ msg = "PipeExtract must have exactly one input which must be either`Image` or `PDF`."
raise PipeDefinitionError(msg)
if len(inputs_value) != 1:
- msg = "PipeOcr must have exactly one input which must be either`Image` or `PDF`."
+ msg = "PipeExtract must have exactly one input which must be either`Image` or `PDF`."
raise PipeDefinitionError(msg)
return inputs_value
@override
- def to_blueprint(self) -> PipeOcrBlueprint:
+ def to_blueprint(self) -> PipeExtractBlueprint:
base_blueprint = super().to_blueprint()
- # create ocr choice as a str
- ocr: OcrChoice
- if isinstance(self.ocr, OcrSkill):
- ocr = self.ocr.ocr_recommendation.value
+ # create extract choice as a str
+ extract_model_choice: ExtractChoice
+ if isinstance(self.extract_skill, ExtractSkill):
+ extract_model_choice = self.extract_skill.model_recommendation.value
else:
- ocr = OcrSkill(self.ocr).ocr_recommendation.value
+ extract_model_choice = ExtractSkill(self.extract_skill).model_recommendation.value
- return PipeOcrBlueprint(
+ return PipeExtractBlueprint(
source=None,
description=base_blueprint.description,
inputs=base_blueprint.inputs,
output=base_blueprint.output,
type=self.type,
category=self.category,
- ocr=ocr,
+ ocr=extract_model_choice,
page_images=self.page_images,
page_image_captions=self.page_image_captions,
page_views=self.page_views,
diff --git a/pipelex/libraries/pipelines/builder/pipe/pipe_img_spec.py b/pipelex/libraries/pipelines/builder/pipe/pipe_img_spec.py
index 35531eb00..fe6dadad6 100644
--- a/pipelex/libraries/pipelines/builder/pipe/pipe_img_spec.py
+++ b/pipelex/libraries/pipelines/builder/pipe/pipe_img_spec.py
@@ -8,12 +8,28 @@ from pipelex.pipe_operators.img_gen.pipe_img_gen_blueprint import PipeImgGenBlue
from pipelex.types import StrEnum
-class RecommendedImgGen(StrEnum):
+class AvailableImgGen(StrEnum):
BASE_IMG_GEN = "base_img_gen"
FAST_IMG_GEN = "fast_img_gen"
HIGH_QUALITY_IMG_GEN = "high_quality_img_gen"
+class ImgGenSkill(StrEnum):
+ GEN_IMAGE = "gen_image"
+ GEN_IMAGE_FAST = "gen_image_fast"
+ GEN_IMAGE_HIGH_QUALITY = "gen_image_high_quality"
+
+ @property
+ def model_recommendation(self) -> AvailableImgGen:
+ match self:
+ case ImgGenSkill.GEN_IMAGE:
+ return AvailableImgGen.BASE_IMG_GEN
+ case ImgGenSkill.GEN_IMAGE_FAST:
+ return AvailableImgGen.FAST_IMG_GEN
+ case ImgGenSkill.GEN_IMAGE_HIGH_QUALITY:
+ return AvailableImgGen.HIGH_QUALITY_IMG_GEN
+
+
class PipeImgGenSpec(PipeSpec):
"""Specs for image generation pipe operations in the Pipelex framework.
@@ -24,16 +40,16 @@ class PipeImgGenSpec(PipeSpec):
type: Literal["PipeImgGen"] = "PipeImgGen"
category: Literal["PipeOperator"] = "PipeOperator"
- img_gen: RecommendedImgGen | None = None
+ img_gen_skill: ImgGenSkill | None = None
nb_output: int | None = Field(default=None, ge=1)
- @field_validator("img_gen", mode="before")
+ @field_validator("img_gen_skill", mode="before")
@classmethod
- def validate_img_gen(cls, img_gen_value: str | None) -> RecommendedImgGen | None:
- if img_gen_value is None:
+ def validate_img_gen_skill(cls, img_gen_skill_value: str | None) -> ImgGenSkill | None:
+ if img_gen_skill_value is None:
return None
else:
- return RecommendedImgGen(img_gen_value)
+ return ImgGenSkill(img_gen_skill_value)
@override
def to_blueprint(self) -> PipeImgGenBlueprint:
@@ -47,7 +63,7 @@ class PipeImgGenSpec(PipeSpec):
category=self.category,
img_gen_prompt=None,
img_gen_prompt_var_name=None,
- img_gen=self.img_gen,
+ img_gen=self.img_gen_skill.model_recommendation if self.img_gen_skill else None,
aspect_ratio=None,
background=None,
output_format=None,
diff --git a/pipelex/libraries/pipelines/builder/pipe/pipe_llm_spec.py b/pipelex/libraries/pipelines/builder/pipe/pipe_llm_spec.py
index 29b14aedd..40a40f484 100644
--- a/pipelex/libraries/pipelines/builder/pipe/pipe_llm_spec.py
+++ b/pipelex/libraries/pipelines/builder/pipe/pipe_llm_spec.py
@@ -83,7 +83,7 @@ class PipeLLMSpec(PipeSpec):
type: SkipJsonSchema[Literal["PipeLLM"]] = "PipeLLM"
category: SkipJsonSchema[Literal["PipeOperator"]] = "PipeOperator"
- llm: LLMSkill | str = Field(description="The required skill of the LLM according to the task to be performed.")
+ llm: LLMSkill | str = Field(description="Select the most adequate LLM model skill according to the task to be performed.")
temperature: float | None = Field(default=None, ge=0, le=1)
system_prompt: str | None = Field(default=None, description="A system-level prompt to guide the LLM's behavior, style and skills.")
prompt_template: str | None = Field(
diff --git a/pipelex/libraries/pipelines/documents.plx b/pipelex/libraries/pipelines/documents.plx
index 1b6ac1adf..8fee29f27 100644
--- a/pipelex/libraries/pipelines/documents.plx
+++ b/pipelex/libraries/pipelines/documents.plx
@@ -7,19 +7,19 @@ description = "The domain of documents that can comprise pages, text, images, et
TextAndImagesContent = "A content that comprises text and images where the text can include local links to the images"
[pipe]
-# PipeOcr requires to have a single input
+# PipeExtract requires to have a single input
# It can be named however you want
# but it must be either an image or a pdf or a concept which refines one of them
-[pipe.ocr_page_contents_from_pdf]
-type = "PipeOcr"
+[pipe.extract_page_contents_from_pdf]
+type = "PipeExtract"
description = "Extract page contents from a PDF document"
inputs = { document = "PDF" }
output = "Page"
page_images = true
page_views = false
-[pipe.ocr_page_contents_and_views_from_pdf]
-type = "PipeOcr"
+[pipe.extract_page_contents_and_views_from_pdf]
+type = "PipeExtract"
description = "Extract page contents from a PDF document as well as full page views"
inputs = { document = "PDF" }
output = "Page"
diff --git a/pipelex/pipe_controllers/condition/pipe_condition.py b/pipelex/pipe_controllers/condition/pipe_condition.py
index 6b211ba84..3f68f4a78 100644
--- a/pipelex/pipe_controllers/condition/pipe_condition.py
+++ b/pipelex/pipe_controllers/condition/pipe_condition.py
@@ -156,7 +156,7 @@ class PipeCondition(PipeController):
# so we'll use a generic placeholder that will be validated later
needed_inputs.add_requirement(
variable_name=var_name,
- concept=ConceptFactory.make_native_concept_from_enum(
+ concept=ConceptFactory.make_native_concept(
native_concept_code=NativeConceptCode.ANYTHING,
),
)
diff --git a/pipelex/pipe_operators/compose/pipe_compose.py b/pipelex/pipe_operators/compose/pipe_compose.py
index 5d3f2fdd5..9c30d3013 100644
--- a/pipelex/pipe_operators/compose/pipe_compose.py
+++ b/pipelex/pipe_operators/compose/pipe_compose.py
@@ -41,7 +41,7 @@ class PipeCompose(PipeOperator[PipeComposeOutput]):
model_config = ConfigDict(extra="forbid", strict=False)
adhoc_pipe_code: ClassVar[str] = "jinja2_render"
- output: Concept = ConceptFactory.make_native_concept_from_enum(
+ output: Concept = ConceptFactory.make_native_concept(
native_concept_code=NativeConceptCode.TEXT,
)
diff --git a/pipelex/pipe_operators/ocr/__init__.py b/pipelex/pipe_operators/extract/__init__.py
similarity index 100%
rename from pipelex/pipe_operators/ocr/__init__.py
rename to pipelex/pipe_operators/extract/__init__.py
diff --git a/pipelex/pipe_operators/ocr/pipe_ocr.py b/pipelex/pipe_operators/extract/pipe_extract.py
similarity index 82%
rename from pipelex/pipe_operators/ocr/pipe_ocr.py
rename to pipelex/pipe_operators/extract/pipe_extract.py
index 35953832b..32fc4c87f 100644
--- a/pipelex/pipe_operators/ocr/pipe_ocr.py
+++ b/pipelex/pipe_operators/extract/pipe_extract.py
@@ -6,10 +6,10 @@ from typing_extensions import override
from pipelex import log
from pipelex.cogt.content_generation.content_generator_dry import ContentGeneratorDry
from pipelex.cogt.content_generation.content_generator_protocol import ContentGeneratorProtocol
-from pipelex.cogt.models.model_deck_check import check_ocr_choice_with_deck
-from pipelex.cogt.ocr.ocr_input import OcrInput
-from pipelex.cogt.ocr.ocr_job_components import OcrJobConfig, OcrJobParams
-from pipelex.cogt.ocr.ocr_setting import OcrChoice, OcrSetting
+from pipelex.cogt.extract.extract_input import ExtractInput
+from pipelex.cogt.extract.extract_job_components import ExtractJobConfig, ExtractJobParams
+from pipelex.cogt.extract.extract_setting import ExtractChoice, ExtractSetting
+from pipelex.cogt.models.model_deck_check import check_extract_choice_with_deck
from pipelex.config import StaticValidationReaction, get_config
from pipelex.core.concepts.concept_native import NativeConceptCode
from pipelex.core.memory.working_memory import WorkingMemory
@@ -39,13 +39,13 @@ from pipelex.tools.pdf.pypdfium2_renderer import pypdfium2_renderer
from pipelex.types import Self
-class PipeOcrOutput(PipeOutput):
+class PipeExtractOutput(PipeOutput):
pass
-class PipeOcr(PipeOperator[PipeOcrOutput]):
- type: Literal["PipeOcr"] = "PipeOcr"
- ocr_choice: OcrChoice | None
+class PipeExtract(PipeOperator[PipeExtractOutput]):
+ type: Literal["PipeExtract"] = "PipeExtract"
+ extract_choice: ExtractChoice | None
should_caption_images: bool
should_include_images: bool
should_include_page_views: bool
@@ -62,8 +62,8 @@ class PipeOcr(PipeOperator[PipeOcrOutput]):
@override
def validate_with_libraries(self):
self._validate_inputs()
- if self.ocr_choice:
- check_ocr_choice_with_deck(ocr_choice=self.ocr_choice)
+ if self.extract_choice:
+ check_extract_choice_with_deck(extract_choice=self.extract_choice)
@override
def required_variables(self) -> set[str]:
@@ -72,7 +72,7 @@ class PipeOcr(PipeOperator[PipeOcrOutput]):
@override
def validate_output(self):
if self.output != get_native_concept(native_concept=NativeConceptCode.PAGE):
- msg = f"PipeOcr output should be a Page concept, but is {self.output.concept_string}"
+ msg = f"PipeExtract output should be a Page concept, but is {self.output.concept_string}"
raise PipeDefinitionError(msg)
def _validate_inputs(self):
@@ -136,7 +136,7 @@ class PipeOcr(PipeOperator[PipeOcrOutput]):
pipe_code=self.code,
variable_names=[input_name],
provided_concept_code=requirement.concept.code,
- explanation="For PipeOcr you must provide either a pdf or an image or a concept that refines one of them",
+ explanation="For PipeExtract you must provide either a pdf or an image or a concept that refines one of them",
)
match reactions.get(StaticValidationErrorType.INADEQUATE_INPUT_CONCEPT, default_reaction):
case StaticValidationReaction.IGNORE:
@@ -158,7 +158,7 @@ class PipeOcr(PipeOperator[PipeOcrOutput]):
pipe_run_params: PipeRunParams,
output_name: str | None = None,
content_generator: ContentGeneratorProtocol | None = None,
- ) -> PipeOcrOutput:
+ ) -> PipeExtractOutput:
content_generator = content_generator or get_content_generator()
image_uri: str | None = None
@@ -170,30 +170,30 @@ class PipeOcr(PipeOperator[PipeOcrOutput]):
pdf_stuff = working_memory.get_stuff_as_pdf(name=self.pdf_stuff_name)
pdf_uri = pdf_stuff.url
else:
- msg = "PipeOcr should have a non-None image_stuff_name or pdf_stuff_name"
+ msg = "PipeExtract should have a non-None image_stuff_name or pdf_stuff_name"
raise PipeDefinitionError(msg)
- ocr_choice: OcrChoice = self.ocr_choice or get_model_deck().ocr_choice_default
- ocr_setting: OcrSetting = get_model_deck().get_ocr_setting(ocr_choice=ocr_choice)
+ extract_choice: ExtractChoice = self.extract_choice or get_model_deck().extract_choice_default
+ extract_setting: ExtractSetting = get_model_deck().get_extract_setting(extract_choice=extract_choice)
- ocr_job_params = OcrJobParams(
+ extract_job_params = ExtractJobParams(
should_include_images=self.should_include_images,
should_caption_images=self.should_caption_images,
should_include_page_views=self.should_include_page_views,
page_views_dpi=self.page_views_dpi,
- max_nb_images=ocr_setting.max_nb_images,
- image_min_size=ocr_setting.image_min_size,
+ max_nb_images=extract_setting.max_nb_images,
+ image_min_size=extract_setting.image_min_size,
)
- ocr_input = OcrInput(
+ extract_input = ExtractInput(
image_uri=image_uri,
pdf_uri=pdf_uri,
)
- ocr_output = await content_generator.make_ocr_extract_pages(
- ocr_input=ocr_input,
- ocr_handle=ocr_setting.ocr_handle,
+ extract_output = await content_generator.make_extract_pages(
+ extract_input=extract_input,
+ extract_handle=extract_setting.extract_handle,
job_metadata=job_metadata,
- ocr_job_params=ocr_job_params,
- ocr_job_config=OcrJobConfig(),
+ extract_job_params=extract_job_params,
+ extract_job_config=ExtractJobConfig(),
)
# Build the output stuff, which is a list of page contents
@@ -202,15 +202,15 @@ class PipeOcr(PipeOperator[PipeOcrOutput]):
log.debug(f"should_include_page_views: {self.should_include_page_views}, pdf_uri: {pdf_uri}, image_uri: {image_uri}")
if pdf_uri:
page_view_contents.extend(
- ImageContent.make_from_extracted_image(extracted_image=page.page_view) for page in ocr_output.pages.values() if page.page_view
+ ImageContent.make_from_extracted_image(extracted_image=page.page_view) for page in extract_output.pages.values() if page.page_view
)
log.debug(f"page_view_contents: {page_view_contents}")
needs_to_generate_page_views: bool
if len(page_view_contents) == 0:
log.debug("No page views found in the OCR output")
needs_to_generate_page_views = True
- elif len(page_view_contents) < len(ocr_output.pages):
- log.warning(f"Only {len(page_view_contents)} page found in the OCR output, but {len(ocr_output.pages)} pages")
+ elif len(page_view_contents) < len(extract_output.pages):
+ log.warning(f"Only {len(page_view_contents)} page found in the OCR output, but {len(extract_output.pages)} pages")
needs_to_generate_page_views = True
else:
log.debug("All page views found in the OCR output")
@@ -223,7 +223,7 @@ class PipeOcr(PipeOperator[PipeOcrOutput]):
page_view_contents = [ImageContent(url=image_uri)]
page_contents: list[PageContent] = []
- for page_index, page in ocr_output.pages.items():
+ for page_index, page in extract_output.pages.items():
images = [ImageContent.make_from_extracted_image(extracted_image=img) for img in page.extracted_images]
log.debug(f"images: {images}, page_view_contents: {page_view_contents}, index: {page_index}")
page_view = page_view_contents[page_index - 1] if self.should_include_page_views else None
@@ -250,7 +250,7 @@ class PipeOcr(PipeOperator[PipeOcrOutput]):
name=output_name,
)
- return PipeOcrOutput(
+ return PipeExtractOutput(
working_memory=working_memory,
pipeline_run_id=job_metadata.pipeline_run_id,
)
@@ -262,10 +262,10 @@ class PipeOcr(PipeOperator[PipeOcrOutput]):
working_memory: WorkingMemory,
pipe_run_params: PipeRunParams,
output_name: str | None = None,
- ) -> PipeOcrOutput:
- log.debug(f"PipeOcr: dry run operator pipe: {self.code}")
+ ) -> PipeExtractOutput:
+ log.debug(f"PipeExtract: dry run operator pipe: {self.code}")
if pipe_run_params.run_mode != PipeRunMode.DRY:
- msg = f"Running pipe '{self.code}' (PipeOcr) _dry_run_operator_pipe() in non-dry mode is not allowed."
+ msg = f"Running pipe '{self.code}' (PipeExtract) _dry_run_operator_pipe() in non-dry mode is not allowed."
raise PipeDefinitionError(msg)
content_generator_dry = ContentGeneratorDry()
diff --git a/pipelex/pipe_operators/ocr/pipe_ocr_blueprint.py b/pipelex/pipe_operators/extract/pipe_extract_blueprint.py
similarity index 60%
rename from pipelex/pipe_operators/ocr/pipe_ocr_blueprint.py
rename to pipelex/pipe_operators/extract/pipe_extract_blueprint.py
index b09179f33..557e6e3a7 100644
--- a/pipelex/pipe_operators/ocr/pipe_ocr_blueprint.py
+++ b/pipelex/pipe_operators/extract/pipe_extract_blueprint.py
@@ -1,13 +1,13 @@
from typing import Literal
-from pipelex.cogt.ocr.ocr_setting import OcrChoice
+from pipelex.cogt.extract.extract_setting import ExtractChoice
from pipelex.core.pipes.pipe_blueprint import PipeBlueprint
-class PipeOcrBlueprint(PipeBlueprint):
- type: Literal["PipeOcr"] = "PipeOcr"
+class PipeExtractBlueprint(PipeBlueprint):
+ type: Literal["PipeExtract"] = "PipeExtract"
category: Literal["PipeOperator"] = "PipeOperator"
- ocr: OcrChoice | None = None
+ ocr: ExtractChoice | None = None
page_images: bool | None = None
page_image_captions: bool | None = None
page_views: bool | None = None
diff --git a/pipelex/pipe_operators/ocr/pipe_ocr_factory.py b/pipelex/pipe_operators/extract/pipe_extract_factory.py
similarity index 80%
rename from pipelex/pipe_operators/ocr/pipe_ocr_factory.py
rename to pipelex/pipe_operators/extract/pipe_extract_factory.py
index 93fd66bb6..8a13b0e93 100644
--- a/pipelex/pipe_operators/ocr/pipe_ocr_factory.py
+++ b/pipelex/pipe_operators/extract/pipe_extract_factory.py
@@ -5,27 +5,27 @@ from pipelex.core.concepts.concept_factory import ConceptFactory
from pipelex.core.pipes.input_requirements_factory import InputRequirementsFactory
from pipelex.core.pipes.pipe_factory import PipeFactoryProtocol
from pipelex.hub import get_required_concept
-from pipelex.pipe_operators.ocr.pipe_ocr import PipeOcr
-from pipelex.pipe_operators.ocr.pipe_ocr_blueprint import PipeOcrBlueprint
+from pipelex.pipe_operators.extract.pipe_extract import PipeExtract
+from pipelex.pipe_operators.extract.pipe_extract_blueprint import PipeExtractBlueprint
-class PipeOcrFactory(PipeFactoryProtocol[PipeOcrBlueprint, PipeOcr]):
+class PipeExtractFactory(PipeFactoryProtocol[PipeExtractBlueprint, PipeExtract]):
@classmethod
@override
def make_from_blueprint(
cls,
domain: str,
pipe_code: str,
- blueprint: PipeOcrBlueprint,
+ blueprint: PipeExtractBlueprint,
concept_codes_from_the_same_domain: list[str] | None = None,
- ) -> PipeOcr:
+ ) -> PipeExtract:
output_domain_and_code = ConceptFactory.make_domain_and_concept_code_from_concept_string_or_code(
domain=domain,
concept_string_or_code=blueprint.output,
concept_codes_from_the_same_domain=concept_codes_from_the_same_domain,
)
- return PipeOcr(
+ return PipeExtract(
domain=domain,
code=pipe_code,
description=blueprint.description,
@@ -40,9 +40,9 @@ class PipeOcrFactory(PipeFactoryProtocol[PipeOcrBlueprint, PipeOcr]):
blueprint=blueprint.inputs or {},
concept_codes_from_the_same_domain=concept_codes_from_the_same_domain,
),
- ocr_choice=blueprint.ocr,
+ extract_choice=blueprint.ocr,
should_include_images=blueprint.page_images or False,
should_caption_images=blueprint.page_image_captions or False,
should_include_page_views=blueprint.page_views or False,
- page_views_dpi=blueprint.page_views_dpi or get_config().cogt.ocr_config.default_page_views_dpi,
+ page_views_dpi=blueprint.page_views_dpi or get_config().cogt.extract_config.default_page_views_dpi,
)
diff --git a/pipelex/pipe_operators/img_gen/pipe_img_gen.py b/pipelex/pipe_operators/img_gen/pipe_img_gen.py
index 6be720126..607f4f763 100644
--- a/pipelex/pipe_operators/img_gen/pipe_img_gen.py
+++ b/pipelex/pipe_operators/img_gen/pipe_img_gen.py
@@ -121,7 +121,7 @@ class PipeImgGen(PipeOperator[PipeImgGenOutput]):
if self.img_gen_prompt:
needed_inputs.add_requirement(
variable_name="img_gen_prompt",
- concept=ConceptFactory.make_native_concept_from_enum(
+ concept=ConceptFactory.make_native_concept(
native_concept_code=NativeConceptCode.TEXT,
),
)
@@ -185,7 +185,7 @@ class PipeImgGen(PipeOperator[PipeImgGenOutput]):
input_name, requirement = self.inputs.items[0]
if concept_library.is_compatible(
tested_concept=requirement.concept,
- wanted_concept=ConceptFactory.make_native_concept_from_enum(native_concept_code=NativeConceptCode.TEXT),
+ wanted_concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.TEXT),
):
self.img_gen_prompt_var_name = input_name
else:
diff --git a/pipelex/pipe_operators/img_gen/pipe_img_gen_blueprint.py b/pipelex/pipe_operators/img_gen/pipe_img_gen_blueprint.py
index 938ce84d4..df804e232 100644
--- a/pipelex/pipe_operators/img_gen/pipe_img_gen_blueprint.py
+++ b/pipelex/pipe_operators/img_gen/pipe_img_gen_blueprint.py
@@ -13,7 +13,6 @@ class PipeImgGenBlueprint(PipeBlueprint):
img_gen_prompt: str | None = None
img_gen_prompt_var_name: str | None = None
- # New ImgGenChoice pattern (like LLM)
img_gen: ImgGenChoice | None = None
# One-time settings (not in ImgGenSetting)
diff --git a/pipelex/pipelex.toml b/pipelex/pipelex.toml
index 309149c25..19cbc73da 100644
--- a/pipelex/pipelex.toml
+++ b/pipelex/pipelex.toml
@@ -83,7 +83,7 @@ inference_config_path = ".pipelex/inference"
[cogt.inference_manager_config]
is_auto_setup_preset_llm = true
is_auto_setup_preset_img_gen = true
-is_auto_setup_preset_ocr = true
+is_auto_setup_preset_extract = true
[cogt.llm_config]
default_max_images = 100
@@ -126,7 +126,7 @@ sdxl_lightning_map_quality_to_steps = { "low" = 2, "medium" = 4, "high" = 8 }
# OCR config
####################################################################################################
-[cogt.ocr_config]
+[cogt.extract_config]
page_output_text_file_name = "page_text.md"
default_page_views_dpi = 72
@@ -206,7 +206,7 @@ pipe_stack_limit = 20
apply_to_jinja2_rendering = false
text_gen_truncate_length = 256
nb_list_items = 3
-nb_ocr_pages = 4
+nb_extract_pages = 4
allowed_to_fail_pipes = [
"infinite_loop_1", # Loop but only for testing purposes
"fix_failing_pipes_once", # Loop but its normal
diff --git a/pipelex/pipeline/job_metadata.py b/pipelex/pipeline/job_metadata.py
index 60b214c3e..86e58b2b2 100644
--- a/pipelex/pipeline/job_metadata.py
+++ b/pipelex/pipeline/job_metadata.py
@@ -10,16 +10,15 @@ class JobCategory(StrEnum):
MOCK_JOB = "mock_job"
LLM_JOB = "llm_job"
IMG_GEN_JOB = "img_gen_job"
- PROMPTING_JOB = "prompting_job"
JINJA2_JOB = "jinja2_job"
- OCR_JOB = "ocr_job"
+ EXTRACT_JOB = "extract_job"
class UnitJobId(StrEnum):
LLM_GEN_TEXT = "llm_gen_text"
LLM_GEN_OBJECT = "llm_gen_object"
IMG_GEN_TEXT_TO_IMAGE = "img_gen_text_to_image"
- OCR_EXTRACT_PAGES = "ocr_extract_pages"
+ EXTRACT_PAGES = "extract_pages"
class JobMetadata(BaseModel):
diff --git a/pipelex/plugins/mistral/mistral_ocr_worker.py b/pipelex/plugins/mistral/mistral_extract_worker.py
similarity index 67%
rename from pipelex/plugins/mistral/mistral_ocr_worker.py
rename to pipelex/plugins/mistral/mistral_extract_worker.py
index 6a1c43b0c..e7d88e751 100644
--- a/pipelex/plugins/mistral/mistral_ocr_worker.py
+++ b/pipelex/plugins/mistral/mistral_extract_worker.py
@@ -5,20 +5,19 @@ from typing_extensions import override
from pipelex import log
from pipelex.cogt.exceptions import OcrCapabilityError, SdkTypeError
+from pipelex.cogt.extract.extract_input import ExtractInputError
+from pipelex.cogt.extract.extract_job import ExtractJob
+from pipelex.cogt.extract.extract_output import ExtractOutput
+from pipelex.cogt.extract.extract_worker_abstract import ExtractWorkerAbstract
from pipelex.cogt.model_backends.model_spec import InferenceModelSpec
-from pipelex.cogt.ocr.ocr_input import OcrInputError
-from pipelex.cogt.ocr.ocr_job import OcrJob
-from pipelex.cogt.ocr.ocr_output import OcrOutput
-from pipelex.cogt.ocr.ocr_worker_abstract import OcrWorkerAbstract
from pipelex.plugins.mistral.mistral_factory import MistralFactory
-from pipelex.plugins.mistral.mistral_utils import upload_file_for_ocr
from pipelex.reporting.reporting_protocol import ReportingProtocol
from pipelex.tools.misc.base_64_utils import load_binary_as_base64_async
from pipelex.tools.misc.filetype_utils import detect_file_type_from_base64
from pipelex.tools.misc.path_utils import clarify_path_or_url
-class MistralOcrWorker(OcrWorkerAbstract):
+class MistralExtractWorker(ExtractWorkerAbstract):
def __init__(
self,
sdk_instance: Any,
@@ -39,34 +38,34 @@ class MistralOcrWorker(OcrWorkerAbstract):
self.mistral_client: Mistral = sdk_instance
@override
- async def _ocr_extract_pages(
+ async def _extract_pages(
self,
- ocr_job: OcrJob,
- ) -> OcrOutput:
+ extract_job: ExtractJob,
+ ) -> ExtractOutput:
# TODO: report usage
- if image_uri := ocr_job.ocr_input.image_uri:
- ocr_output = await self._make_ocr_output_from_image(
+ if image_uri := extract_job.extract_input.image_uri:
+ extract_output = await self._make_extract_output_from_image(
image_uri=image_uri,
- should_caption_image=ocr_job.job_params.should_caption_images,
+ should_caption_image=extract_job.job_params.should_caption_images,
)
- elif pdf_uri := ocr_job.ocr_input.pdf_uri:
- ocr_output = await self._make_ocr_output_from_pdf(
+ elif pdf_uri := extract_job.extract_input.pdf_uri:
+ extract_output = await self._make_extract_output_from_pdf(
pdf_uri=pdf_uri,
- should_include_images=ocr_job.job_params.should_include_images,
- should_caption_images=ocr_job.job_params.should_caption_images,
- should_include_page_views=ocr_job.job_params.should_include_page_views,
+ should_include_images=extract_job.job_params.should_include_images,
+ should_caption_images=extract_job.job_params.should_caption_images,
+ should_include_page_views=extract_job.job_params.should_include_page_views,
)
else:
- msg = "No image nor PDF URI provided in OcrJob"
- raise OcrInputError(msg)
- return ocr_output
+ msg = "No image nor PDF URI provided in ExtractJob"
+ raise ExtractInputError(msg)
+ return extract_output
- async def _make_ocr_output_from_image(
+ async def _make_extract_output_from_image(
self,
image_uri: str,
should_caption_image: bool = False,
- ) -> OcrOutput:
+ ) -> ExtractOutput:
if should_caption_image:
msg = "Captioning is not implemented for Mistral OCR."
raise NotImplementedError(msg)
@@ -80,13 +79,13 @@ class MistralOcrWorker(OcrWorkerAbstract):
image_path=image_path,
)
- async def _make_ocr_output_from_pdf(
+ async def _make_extract_output_from_pdf(
self,
pdf_uri: str,
should_include_images: bool,
should_caption_images: bool,
should_include_page_views: bool,
- ) -> OcrOutput:
+ ) -> ExtractOutput:
if should_caption_images:
msg = "Captioning is not implemented for Mistral OCR."
raise OcrCapabilityError(msg)
@@ -97,58 +96,58 @@ class MistralOcrWorker(OcrWorkerAbstract):
# the caller will be responsible to get the page views using other solution if needed
# raise OcrCapabilityError("Page views are not implemented for Mistral OCR.")
pdf_path, pdf_url = clarify_path_or_url(path_or_uri=pdf_uri)
- ocr_output: OcrOutput
+ extract_output: ExtractOutput
if pdf_url:
- ocr_output = await self.extract_from_pdf_url(
+ extract_output = await self.extract_from_pdf_url(
pdf_url=pdf_url,
should_include_images=should_include_images,
)
else: # pdf_path must be provided based on validation
assert pdf_path is not None
- ocr_output = await self.extract_from_pdf_file(
+ extract_output = await self.extract_from_pdf_file(
pdf_path=pdf_path,
should_include_images=should_include_images,
)
- return ocr_output
+ return extract_output
async def extract_from_image_url(
self,
image_url: str,
- ) -> OcrOutput:
- ocr_response = await self.mistral_client.ocr.process_async(
+ ) -> ExtractOutput:
+ extract_response = await self.mistral_client.ocr.process_async(
model=self.inference_model.model_id,
document={
"type": "image_url",
"image_url": image_url,
},
)
- return await MistralFactory.make_ocr_output_from_mistral_response(
- mistral_ocr_response=ocr_response,
+ return await MistralFactory.make_extract_output_from_mistral_response(
+ mistral_extract_response=extract_response,
)
async def extract_from_image_file(
self,
image_path: str,
- ) -> OcrOutput:
+ ) -> ExtractOutput:
b64 = await load_binary_as_base64_async(path=image_path)
file_type = detect_file_type_from_base64(b64=b64)
mime_type = file_type.mime
- ocr_response = await self.mistral_client.ocr.process_async(
+ extract_response = await self.mistral_client.ocr.process_async(
model=self.inference_model.model_id,
document={"type": "image_url", "image_url": f"data:{mime_type};base64,{b64.decode('utf-8')}"},
)
- return await MistralFactory.make_ocr_output_from_mistral_response(
- mistral_ocr_response=ocr_response,
+ return await MistralFactory.make_extract_output_from_mistral_response(
+ mistral_extract_response=extract_response,
)
async def extract_from_pdf_url(
self,
pdf_url: str,
should_include_images: bool = False,
- ) -> OcrOutput:
- ocr_response = await self.mistral_client.ocr.process_async(
+ ) -> ExtractOutput:
+ extract_response = await self.mistral_client.ocr.process_async(
model=self.inference_model.model_id,
document={
"type": "document_url",
@@ -157,8 +156,8 @@ class MistralOcrWorker(OcrWorkerAbstract):
include_image_base64=should_include_images,
)
- return await MistralFactory.make_ocr_output_from_mistral_response(
- mistral_ocr_response=ocr_response,
+ return await MistralFactory.make_extract_output_from_mistral_response(
+ mistral_extract_response=extract_response,
should_include_images=should_include_images,
)
@@ -166,9 +165,9 @@ class MistralOcrWorker(OcrWorkerAbstract):
self,
pdf_path: str,
should_include_images: bool = False,
- ) -> OcrOutput:
+ ) -> ExtractOutput:
# Upload the file
- uploaded_file_id = await upload_file_for_ocr(
+ uploaded_file_id = await MistralFactory.upload_file_to_mistral_for_ocr(
mistral_client=self.mistral_client,
file_path=pdf_path,
)
diff --git a/pipelex/plugins/mistral/mistral_factory.py b/pipelex/plugins/mistral/mistral_factory.py
index e08322db4..d4d542ff4 100644
--- a/pipelex/plugins/mistral/mistral_factory.py
+++ b/pipelex/plugins/mistral/mistral_factory.py
@@ -1,4 +1,8 @@
-from mistralai import Mistral, OCRImageObject, OCRResponse
+import os
+
+import aiofiles
+import mistralai
+from mistralai import Mistral
from mistralai.models import (
ContentChunk,
ImageURLChunk,
@@ -18,10 +22,10 @@ from openai.types.chat import (
)
from pipelex.cogt.exceptions import PromptImageFormatError
+from pipelex.cogt.extract.extract_output import ExtractedImageFromPage, ExtractOutput, Page
from pipelex.cogt.image.prompt_image import PromptImage, PromptImageBase64, PromptImagePath, PromptImageUrl
from pipelex.cogt.llm.llm_job import LLMJob
from pipelex.cogt.model_backends.backend import InferenceBackend
-from pipelex.cogt.ocr.ocr_output import ExtractedImageFromPage, OcrOutput, Page
from pipelex.cogt.usage.token_category import NbTokensByCategoryDict, TokenCategory
from pipelex.plugins.openai.openai_factory import OpenAIFactory
from pipelex.tools.misc.base_64_utils import load_binary_as_base64
@@ -111,32 +115,31 @@ class MistralFactory:
return nb_tokens_by_category
@classmethod
- async def make_ocr_output_from_mistral_response(
+ async def make_extract_output_from_mistral_response(
cls,
- mistral_ocr_response: OCRResponse,
+ mistral_extract_response: mistralai.OCRResponse,
should_include_images: bool = False,
- # export_dir: Optional[str] = None,
- ) -> OcrOutput:
+ ) -> ExtractOutput:
pages: dict[int, Page] = {}
- for ocr_response_page in mistral_ocr_response.pages:
+ for response_page in mistral_extract_response.pages:
page = Page(
- text=ocr_response_page.markdown,
+ text=response_page.markdown,
extracted_images=[],
)
if should_include_images:
- for mistral_ocr_image_obj in ocr_response_page.images:
+ for mistral_ocr_image_obj in response_page.images:
extracted_image = cls.make_extracted_image_from_page_from_mistral_ocr_image_obj(mistral_ocr_image_obj)
page.extracted_images.append(extracted_image)
- pages[ocr_response_page.index] = page
+ pages[response_page.index] = page
- return OcrOutput(
+ return ExtractOutput(
pages=pages,
)
@classmethod
def make_extracted_image_from_page_from_mistral_ocr_image_obj(
cls,
- mistral_ocr_image_obj: OCRImageObject,
+ mistral_ocr_image_obj: mistralai.OCRImageObject,
) -> ExtractedImageFromPage:
return ExtractedImageFromPage(
image_id=mistral_ocr_image_obj.id,
@@ -146,3 +149,31 @@ class MistralFactory:
bottom_right_y=mistral_ocr_image_obj.bottom_right_y,
base_64=mistral_ocr_image_obj.image_base64 if mistral_ocr_image_obj.image_base64 else None,
)
+
+ #########################################################
+ # Utils
+ #########################################################
+ @classmethod
+ async def upload_file_to_mistral_for_ocr(
+ cls,
+ mistral_client: Mistral,
+ file_path: str,
+ ) -> str:
+ """Upload a local file to Mistral.
+
+ Args:
+ file_path: Path to the local file to upload
+ mistral_client: Mistral client
+
+ Returns:
+ ID of the uploaded file
+
+ """
+ async with aiofiles.open(file_path, "rb") as file: # pyright: ignore[reportUnknownMemberType]
+ file_content = await file.read()
+
+ uploaded_file = await mistral_client.files.upload_async(
+ file={"file_name": os.path.basename(file_path), "content": file_content},
+ purpose="ocr",
+ )
+ return uploaded_file.id
diff --git a/pipelex/plugins/mistral/mistral_utils.py b/pipelex/plugins/mistral/mistral_utils.py
deleted file mode 100644
index d09e37c01..000000000
--- a/pipelex/plugins/mistral/mistral_utils.py
+++ /dev/null
@@ -1,28 +0,0 @@
-import os
-
-import aiofiles
-from mistralai import Mistral
-
-
-async def upload_file_for_ocr(
- mistral_client: Mistral,
- file_path: str,
-) -> str:
- """Upload a local file to Mistral.
-
- Args:
- file_path: Path to the local file to upload
- mistral_client: Mistral client
-
- Returns:
- ID of the uploaded file
-
- """
- async with aiofiles.open(file_path, "rb") as file: # pyright: ignore[reportUnknownMemberType]
- file_content = await file.read()
-
- uploaded_file = await mistral_client.files.upload_async(
- file={"file_name": os.path.basename(file_path), "content": file_content},
- purpose="ocr",
- )
- return uploaded_file.id
diff --git a/pipelex/plugins/pypdfium2/pypdfium2_worker.py b/pipelex/plugins/pypdfium2/pypdfium2_worker.py
index 388178efa..9d4ff1faa 100644
--- a/pipelex/plugins/pypdfium2/pypdfium2_worker.py
+++ b/pipelex/plugins/pypdfium2/pypdfium2_worker.py
@@ -2,17 +2,17 @@ from typing import Any
from typing_extensions import override
+from pipelex.cogt.extract.extract_input import ExtractInputError
+from pipelex.cogt.extract.extract_job import ExtractJob
+from pipelex.cogt.extract.extract_output import ExtractOutput, Page
+from pipelex.cogt.extract.extract_worker_abstract import ExtractWorkerAbstract
from pipelex.cogt.model_backends.model_spec import InferenceModelSpec
-from pipelex.cogt.ocr.ocr_input import OcrInputError
-from pipelex.cogt.ocr.ocr_job import OcrJob
-from pipelex.cogt.ocr.ocr_output import OcrOutput, Page
-from pipelex.cogt.ocr.ocr_worker_abstract import OcrWorkerAbstract
from pipelex.reporting.reporting_protocol import ReportingProtocol
from pipelex.tools.misc.path_utils import clarify_path_or_url
from pipelex.tools.pdf.pypdfium2_renderer import pypdfium2_renderer
-class Pypdfium2Worker(OcrWorkerAbstract):
+class Pypdfium2Worker(ExtractWorkerAbstract):
def __init__(
self,
extra_config: dict[str, Any],
@@ -22,55 +22,55 @@ class Pypdfium2Worker(OcrWorkerAbstract):
super().__init__(extra_config=extra_config, inference_model=inference_model, reporting_delegate=reporting_delegate)
@override
- async def _ocr_extract_pages(
+ async def _extract_pages(
self,
- ocr_job: OcrJob,
- ) -> OcrOutput:
- if ocr_job.ocr_input.image_uri:
+ extract_job: ExtractJob,
+ ) -> ExtractOutput:
+ if extract_job.extract_input.image_uri:
msg = "Pypdfium2 only extracts text from PDFs, not images"
raise NotImplementedError(msg)
- if pdf_uri := ocr_job.ocr_input.pdf_uri:
+ if pdf_uri := extract_job.extract_input.pdf_uri:
pdf_path, pdf_url = clarify_path_or_url(path_or_uri=pdf_uri)
- ocr_output: OcrOutput
+ extract_output: ExtractOutput
if pdf_url:
- ocr_output = await self.extract_from_pdf_url(
+ extract_output = await self.extract_from_pdf_url(
pdf_url=pdf_url,
)
else: # pdf_path must be provided based on validation
assert pdf_path is not None # Type narrowing for mypy
- ocr_output = await self.extract_from_pdf_file(
+ extract_output = await self.extract_from_pdf_file(
pdf_path=pdf_path,
)
else:
- msg = "No PDF URI provided in OcrJob"
- raise OcrInputError(msg)
- return ocr_output
+ msg = "No PDF URI provided in ExtractJob"
+ raise ExtractInputError(msg)
+ return extract_output
async def extract_from_pdf_url(
self,
pdf_url: str,
- ) -> OcrOutput:
+ ) -> ExtractOutput:
page_texts = await pypdfium2_renderer.get_text_from_pdf_pages_from_uri(pdf_uri=pdf_url)
pages: dict[int, Page] = {}
for page_index, page_text in enumerate(page_texts):
pages[page_index + 1] = Page(
text=page_text,
)
- return OcrOutput(
+ return ExtractOutput(
pages=pages,
)
async def extract_from_pdf_file(
self,
pdf_path: str,
- ) -> OcrOutput:
+ ) -> ExtractOutput:
page_texts = await pypdfium2_renderer.get_text_from_pdf_pages(pdf_input=pdf_path)
pages: dict[int, Page] = {}
for page_index, page_text in enumerate(page_texts):
pages[page_index + 1] = Page(
text=page_text,
)
- return OcrOutput(
+ return ExtractOutput(
pages=pages,
)
diff --git a/pyproject.toml b/pyproject.toml
index d76f87d12..b54926cb7 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -210,7 +210,7 @@ strictSetInference = true
typeCheckingMode = "strict"
[tool.pytest.ini_options]
-addopts = "--import-mode=importlib -ra -m 'not (inference or llm or img_gen or ocr or needs_output or pipelex_api)'"
+addopts = "--import-mode=importlib -ra -m 'not (inference or llm or img_gen or extract or needs_output or pipelex_api)'"
asyncio_default_fixture_loop_scope = "session"
filterwarnings = [
"ignore:Support for class-based `config` is deprecated:DeprecationWarning",
@@ -220,7 +220,7 @@ markers = [
"inference: slow and costly due to inference calls",
"llm: slow and costly due to llm inference calls",
"img_gen: slow and costly due to image generation inference calls",
- "ocr: slow and costly due to ocr inference calls",
+ "extract: slow and costly due to doc extraction inference calls",
"gha_disabled: tests that should not run in GitHub Actions",
"codex_disabled: tests that should not run in Codex",
"dry_runnable: tests that can be run in dry-run mode",
diff --git a/tests/integration/pipelex/client/test_client.py b/tests/integration/pipelex/client/test_client.py
index c049103ce..24bd36665 100644
--- a/tests/integration/pipelex/client/test_client.py
+++ b/tests/integration/pipelex/client/test_client.py
@@ -29,7 +29,7 @@ class TestPipelexApiClient:
pipe_code="retrieve_excerpts",
memory=[
StuffFactory.make_stuff(
- concept=ConceptFactory.make_native_concept_from_enum(native_concept_code=NativeConceptCode.TEXT),
+ concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.TEXT),
name="text",
content=TextContent(
text="""
diff --git a/tests/integration/pipelex/cogt/test_content_generator.py b/tests/integration/pipelex/cogt/test_content_generator.py
index 29b1c89e5..422e2e44d 100644
--- a/tests/integration/pipelex/cogt/test_content_generator.py
+++ b/tests/integration/pipelex/cogt/test_content_generator.py
@@ -3,13 +3,13 @@ from pytest import FixtureRequest
from pipelex import pretty_print
from pipelex.cogt.exceptions import LLMHandleNotFoundError
+from pipelex.cogt.extract.extract_input import ExtractInput
+from pipelex.cogt.extract.extract_job_components import ExtractJobConfig, ExtractJobParams
+from pipelex.cogt.extract.extract_output import ExtractOutput
from pipelex.cogt.image.generated_image import GeneratedImage
from pipelex.cogt.img_gen.img_gen_prompt import ImgGenPrompt
from pipelex.cogt.llm.llm_prompt import LLMPrompt
from pipelex.cogt.llm.llm_setting import LLMSetting
-from pipelex.cogt.ocr.ocr_input import OcrInput
-from pipelex.cogt.ocr.ocr_job_components import OcrJobConfig, OcrJobParams
-from pipelex.cogt.ocr.ocr_output import OcrOutput
from pipelex.hub import get_content_generator, get_model_deck
from pipelex.pipeline.job_metadata import JobMetadata
from tests.cases import ImageTestCases, PDFTestCases
@@ -127,31 +127,31 @@ class TestContentGenerator:
assert isinstance(jinja2_text, str)
assert jinja2_text == "The answer is: elementary, my dear Watson"
- @pytest.mark.ocr
+ @pytest.mark.extract
@pytest.mark.inference
- async def test_make_ocr_extract_pages_from_image(self, ocr_handle_from_image: str, request: FixtureRequest):
- ocr_output = await get_content_generator().make_ocr_extract_pages(
+ async def test_make_extract_pages_from_image(self, extract_handle_from_image: str, request: FixtureRequest):
+ extract_output = await get_content_generator().make_extract_pages(
job_metadata=JobMetadata(job_name=request.node.originalname), # pyright: ignore[reportUnknownMemberType,reportUnknownArgumentType]
- ocr_handle=ocr_handle_from_image,
- ocr_input=OcrInput(image_uri=ImageTestCases.IMAGE_FILE_PATH_PNG),
- ocr_job_params=OcrJobParams.make_default_ocr_job_params(),
- ocr_job_config=OcrJobConfig(),
+ extract_handle=extract_handle_from_image,
+ extract_input=ExtractInput(image_uri=ImageTestCases.IMAGE_FILE_PATH_PNG),
+ extract_job_params=ExtractJobParams.make_default_extract_job_params(),
+ extract_job_config=ExtractJobConfig(),
)
- pretty_print(ocr_output, title="ocr_extract_pages")
- assert isinstance(ocr_output, OcrOutput)
+ pretty_print(extract_output, title="extract_pages")
+ assert isinstance(extract_output, ExtractOutput)
- @pytest.mark.ocr
+ @pytest.mark.extract
@pytest.mark.inference
- async def test_make_ocr_extract_pages_from_pdf(self, ocr_handle: str, request: FixtureRequest):
- ocr_output = await get_content_generator().make_ocr_extract_pages(
+ async def test_make_extract_pages_from_pdf(self, extract_handle: str, request: FixtureRequest):
+ extract_output = await get_content_generator().make_extract_pages(
job_metadata=JobMetadata(job_name=request.node.originalname), # pyright: ignore[reportUnknownMemberType,reportUnknownArgumentType]
- ocr_handle=ocr_handle,
- ocr_input=OcrInput(pdf_uri=PDFTestCases.PDF_FILE_PATH_1),
- ocr_job_params=OcrJobParams.make_default_ocr_job_params(),
- ocr_job_config=OcrJobConfig(),
+ extract_handle=extract_handle,
+ extract_input=ExtractInput(pdf_uri=PDFTestCases.PDF_FILE_PATH_1),
+ extract_job_params=ExtractJobParams.make_default_extract_job_params(),
+ extract_job_config=ExtractJobConfig(),
)
- pretty_print(ocr_output, title="ocr_extract_pages")
- assert isinstance(ocr_output, OcrOutput)
+ pretty_print(extract_output, title="extract_pages")
+ assert isinstance(extract_output, ExtractOutput)
@pytest.mark.llm
@pytest.mark.inference
diff --git a/tests/integration/pipelex/cogt/test_ocr.py b/tests/integration/pipelex/cogt/test_ocr.py
index 3818558ff..3fb307e60 100644
--- a/tests/integration/pipelex/cogt/test_ocr.py
+++ b/tests/integration/pipelex/cogt/test_ocr.py
@@ -1,64 +1,64 @@
import pytest
from pipelex import pretty_print
-from pipelex.cogt.ocr.ocr_input import OcrInput
-from pipelex.cogt.ocr.ocr_job_components import OcrJobParams
-from pipelex.cogt.ocr.ocr_job_factory import OcrJobFactory
+from pipelex.cogt.extract.extract_input import ExtractInput
+from pipelex.cogt.extract.extract_job_components import ExtractJobParams
+from pipelex.cogt.extract.extract_job_factory import ExtractJobFactory
from pipelex.config import get_config
-from pipelex.hub import get_ocr_worker
+from pipelex.hub import get_extract_worker
from pipelex.tools.misc.file_utils import get_incremental_directory_path
from tests.cases import ImageTestCases, PDFTestCases
@pytest.mark.inference
@pytest.mark.asyncio(loop_scope="class")
-class TestOcr:
+class TestExtract:
@pytest.mark.parametrize("file_path", PDFTestCases.DOCUMENT_FILE_PATHS)
- async def test_ocr_pdf_path(self, ocr_handle: str, file_path: str):
- ocr_worker = get_ocr_worker(ocr_handle=ocr_handle)
- ocr_job = OcrJobFactory.make_ocr_job(
- ocr_input=OcrInput(pdf_uri=file_path),
+ async def test_extract_pdf_path(self, extract_handle: str, file_path: str):
+ extract_worker = get_extract_worker(extract_handle=extract_handle)
+ extract_job = ExtractJobFactory.make_extract_job(
+ extract_input=ExtractInput(pdf_uri=file_path),
)
- ocr_output = await ocr_worker.ocr_extract_pages(ocr_job=ocr_job)
- pretty_print(ocr_output, title="OCR Output")
+ extract_output = await extract_worker.extract_pages(extract_job=extract_job)
+ pretty_print(extract_output, title="Extract Output")
- assert ocr_output.pages
+ assert extract_output.pages
@pytest.mark.parametrize("url", PDFTestCases.DOCUMENT_URLS)
- async def test_ocr_pdf_url(self, ocr_handle: str, url: str):
- ocr_worker = get_ocr_worker(ocr_handle=ocr_handle)
- ocr_job = OcrJobFactory.make_ocr_job(
- ocr_input=OcrInput(pdf_uri=url),
+ async def test_extract_pdf_url(self, extract_handle: str, url: str):
+ extract_worker = get_extract_worker(extract_handle=extract_handle)
+ extract_job = ExtractJobFactory.make_extract_job(
+ extract_input=ExtractInput(pdf_uri=url),
)
- ocr_output = await ocr_worker.ocr_extract_pages(ocr_job=ocr_job)
- pretty_print(ocr_output, title="OCR Output")
- assert ocr_output.pages
+ extract_output = await extract_worker.extract_pages(extract_job=extract_job)
+ pretty_print(extract_output, title="OCR Output")
+ assert extract_output.pages
@pytest.mark.parametrize("file_path", ImageTestCases.IMAGE_FILE_PATHS)
- async def test_ocr_image_file(self, ocr_handle_from_image: str, file_path: str):
- ocr_worker = get_ocr_worker(ocr_handle=ocr_handle_from_image)
- ocr_job = OcrJobFactory.make_ocr_job(
- ocr_input=OcrInput(image_uri=file_path),
+ async def test_extract_image_file(self, extract_handle_from_image: str, file_path: str):
+ extract_worker = get_extract_worker(extract_handle=extract_handle_from_image)
+ extract_job = ExtractJobFactory.make_extract_job(
+ extract_input=ExtractInput(image_uri=file_path),
)
- ocr_output = await ocr_worker.ocr_extract_pages(ocr_job=ocr_job)
- pretty_print(ocr_output, title="OCR Output")
- assert ocr_output.pages
+ extract_output = await extract_worker.extract_pages(extract_job=extract_job)
+ pretty_print(extract_output, title="OCR Output")
+ assert extract_output.pages
@pytest.mark.parametrize("url", ImageTestCases.IMAGE_URLS)
- async def test_ocr_image_url(self, ocr_handle_from_image: str, url: str):
- ocr_worker = get_ocr_worker(ocr_handle=ocr_handle_from_image)
- ocr_job = OcrJobFactory.make_ocr_job(
- ocr_input=OcrInput(image_uri=url),
+ async def test_extract_image_url(self, extract_handle_from_image: str, url: str):
+ extract_worker = get_extract_worker(extract_handle=extract_handle_from_image)
+ extract_job = ExtractJobFactory.make_extract_job(
+ extract_input=ExtractInput(image_uri=url),
)
- ocr_output = await ocr_worker.ocr_extract_pages(ocr_job=ocr_job)
- pretty_print(ocr_output, title="OCR Output")
- assert ocr_output.pages
+ extract_output = await extract_worker.extract_pages(extract_job=extract_job)
+ pretty_print(extract_output, title="OCR Output")
+ assert extract_output.pages
@pytest.mark.parametrize("file_path", PDFTestCases.DOCUMENT_FILE_PATHS)
- async def test_ocr_image_save(self, ocr_handle_from_image: str, file_path: str):
- ocr_worker = get_ocr_worker(ocr_handle=ocr_handle_from_image)
- ocr_job_params = OcrJobParams(
+ async def test_extract_image_save(self, extract_handle_from_image: str, file_path: str):
+ extract_worker = get_extract_worker(extract_handle=extract_handle_from_image)
+ extract_job_params = ExtractJobParams(
should_include_images=True,
should_caption_images=False,
should_include_page_views=False,
@@ -66,17 +66,17 @@ class TestOcr:
max_nb_images=None,
image_min_size=None,
)
- ocr_job = OcrJobFactory.make_ocr_job(
- ocr_input=OcrInput(pdf_uri=file_path),
- ocr_job_params=ocr_job_params,
+ extract_job = ExtractJobFactory.make_extract_job(
+ extract_input=ExtractInput(pdf_uri=file_path),
+ extract_job_params=extract_job_params,
)
- ocr_output = await ocr_worker.ocr_extract_pages(ocr_job=ocr_job)
- pretty_print(ocr_output, title="OCR Output")
+ extract_output = await extract_worker.extract_pages(extract_job=extract_job)
+ pretty_print(extract_output, title="OCR Output")
directory = get_incremental_directory_path(
base_path="results/test_ocr_image_save",
- base_name="ocr_output",
+ base_name="extract_output",
)
- ocr_output.save_to_directory(
+ extract_output.save_to_directory(
directory=directory,
- page_text_file_name=get_config().cogt.ocr_config.page_output_text_file_name,
+ page_text_file_name=get_config().cogt.extract_config.page_output_text_file_name,
)
diff --git a/tests/integration/pipelex/cogt/test_setup_inference_workers.py b/tests/integration/pipelex/cogt/test_setup_inference_workers.py
index 697dc1731..820e7dbe2 100644
--- a/tests/integration/pipelex/cogt/test_setup_inference_workers.py
+++ b/tests/integration/pipelex/cogt/test_setup_inference_workers.py
@@ -13,6 +13,6 @@ class TestSetupInferenceWorkers:
if isinstance(llm_worker, LLMWorkerInternalAbstract):
assert inference_model == llm_worker.inference_model
case ModelType.TEXT_EXTRACTOR:
- _ = inference_manager.get_ocr_worker(model_handle=model_handle)
+ _ = inference_manager.get_extract_worker(extract_handle=model_handle)
case ModelType.IMG_GEN:
_ = inference_manager.get_img_gen_worker(img_gen_handle=model_handle)
diff --git a/tests/integration/pipelex/conftest.py b/tests/integration/pipelex/conftest.py
index 365655418..dea6ff5ce 100644
--- a/tests/integration/pipelex/conftest.py
+++ b/tests/integration/pipelex/conftest.py
@@ -210,7 +210,7 @@ def img_gen_handle(request: pytest.FixtureRequest) -> str:
"mistral-ocr",
],
)
-def ocr_handle(request: pytest.FixtureRequest) -> str:
+def extract_handle(request: pytest.FixtureRequest) -> str:
assert isinstance(request.param, str)
return request.param
@@ -220,7 +220,7 @@ def ocr_handle(request: pytest.FixtureRequest) -> str:
"mistral-ocr",
],
)
-def ocr_handle_from_image(request: pytest.FixtureRequest) -> str:
+def extract_handle_from_image(request: pytest.FixtureRequest) -> str:
assert isinstance(request.param, str)
return request.param
@@ -230,7 +230,7 @@ def ocr_handle_from_image(request: pytest.FixtureRequest) -> str:
"base_ocr_mistral",
],
)
-def ocr_choice_for_pdf(request: pytest.FixtureRequest) -> str:
+def extract_choice_for_pdf(request: pytest.FixtureRequest) -> str:
assert isinstance(request.param, str)
return request.param
@@ -240,6 +240,6 @@ def ocr_choice_for_pdf(request: pytest.FixtureRequest) -> str:
"base_ocr_mistral",
],
)
-def ocr_choice_for_image(request: pytest.FixtureRequest) -> str:
+def extract_choice_for_image(request: pytest.FixtureRequest) -> str:
assert isinstance(request.param, str)
return request.param
diff --git a/tests/integration/pipelex/pipes/controller/pipe_batch/test_pipe_batch_simple.py b/tests/integration/pipelex/pipes/controller/pipe_batch/test_pipe_batch_simple.py
index e95b932ca..137d430ec 100644
--- a/tests/integration/pipelex/pipes/controller/pipe_batch/test_pipe_batch_simple.py
+++ b/tests/integration/pipelex/pipes/controller/pipe_batch/test_pipe_batch_simple.py
@@ -74,7 +74,7 @@ class TestPipeBatchSimple:
]
text_list_stuff = StuffFactory.make_stuff(
- concept=ConceptFactory.make_native_concept_from_enum(native_concept_code=NativeConceptCode.TEXT),
+ concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.TEXT),
content=ListContent[StuffContent](items=cast("list[StuffContent]", text_items)),
name="text_list",
)
diff --git a/tests/integration/pipelex/pipes/controller/pipe_condition/test_pipe_condition_simple.py b/tests/integration/pipelex/pipes/controller/pipe_condition/test_pipe_condition_simple.py
index a0d29fd34..52a54ac56 100644
--- a/tests/integration/pipelex/pipes/controller/pipe_condition/test_pipe_condition_simple.py
+++ b/tests/integration/pipelex/pipes/controller/pipe_condition/test_pipe_condition_simple.py
@@ -46,7 +46,7 @@ class TestPipeConditionSimple:
blueprint=pipe_condition_blueprint,
)
input_text_stuff = StuffFactory.make_stuff(
- concept=ConceptFactory.make_native_concept_from_enum(native_concept_code=NativeConceptCode.TEXT),
+ concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.TEXT),
content=TextContent(text="hello world"), # 11 characters
name="input_text",
)
@@ -118,7 +118,7 @@ class TestPipeConditionSimple:
# Create test data - short text input (<= 5 characters)
input_text_stuff = StuffFactory.make_stuff(
- concept=ConceptFactory.make_native_concept_from_enum(native_concept_code=NativeConceptCode.TEXT),
+ concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.TEXT),
content=TextContent(text="hi"), # 2 characters
name="input_text",
)
diff --git a/tests/integration/pipelex/pipes/controller/pipe_parallel/test_pipe_parallel_simple.py b/tests/integration/pipelex/pipes/controller/pipe_parallel/test_pipe_parallel_simple.py
index 69323565c..26dda49ad 100644
--- a/tests/integration/pipelex/pipes/controller/pipe_parallel/test_pipe_parallel_simple.py
+++ b/tests/integration/pipelex/pipes/controller/pipe_parallel/test_pipe_parallel_simple.py
@@ -46,7 +46,7 @@ class TestPipeParallelSimple:
# Create test data
input_text_stuff = StuffFactory.make_stuff(
- concept=ConceptFactory.make_native_concept_from_enum(native_concept_code=NativeConceptCode.TEXT),
+ concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.TEXT),
content=TextContent(text="The weather is beautiful today. I love sunny days and outdoor activities."),
name="input_text",
)
@@ -161,7 +161,7 @@ class TestPipeParallelSimple:
)
# Create test data - shorter text
input_text_stuff = StuffFactory.make_stuff(
- concept=ConceptFactory.make_native_concept_from_enum(native_concept_code=NativeConceptCode.TEXT),
+ concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.TEXT),
content=TextContent(text="Hello world"),
name="input_text",
)
diff --git a/tests/integration/pipelex/pipes/controller/pipe_sequence/test_pipe_sequence_simple.py b/tests/integration/pipelex/pipes/controller/pipe_sequence/test_pipe_sequence_simple.py
index 356a1f791..0b6e8cb95 100644
--- a/tests/integration/pipelex/pipes/controller/pipe_sequence/test_pipe_sequence_simple.py
+++ b/tests/integration/pipelex/pipes/controller/pipe_sequence/test_pipe_sequence_simple.py
@@ -60,7 +60,7 @@ class TestPipeSequenceSimple:
# Create test data - single text input
input_text_stuff = StuffFactory.make_stuff(
- concept=ConceptFactory.make_native_concept_from_enum(native_concept_code=NativeConceptCode.TEXT),
+ concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.TEXT),
content=TextContent(text="hello world"),
name="input_text",
)
diff --git a/tests/integration/pipelex/pipes/operator/pipe_ocr/__init__.py b/tests/integration/pipelex/pipes/operator/pipe_extract/__init__.py
similarity index 100%
rename from tests/integration/pipelex/pipes/operator/pipe_ocr/__init__.py
rename to tests/integration/pipelex/pipes/operator/pipe_extract/__init__.py
diff --git a/tests/integration/pipelex/pipes/operator/pipe_ocr/test_pipe_ocr.py b/tests/integration/pipelex/pipes/operator/pipe_extract/test_pipe_extract.py
similarity index 70%
rename from tests/integration/pipelex/pipes/operator/pipe_ocr/test_pipe_ocr.py
rename to tests/integration/pipelex/pipes/operator/pipe_extract/test_pipe_extract.py
index ac7c09f4c..3aa86f0de 100644
--- a/tests/integration/pipelex/pipes/operator/pipe_ocr/test_pipe_ocr.py
+++ b/tests/integration/pipelex/pipes/operator/pipe_extract/test_pipe_extract.py
@@ -8,19 +8,19 @@ from pipelex.core.memory.working_memory_factory import WorkingMemoryFactory
from pipelex.core.pipes.input_requirement_blueprint import InputRequirementBlueprint
from pipelex.core.stuffs.page_content import PageContent
from pipelex.hub import get_concept_library, get_pipe_router
-from pipelex.pipe_operators.ocr.pipe_ocr_blueprint import PipeOcrBlueprint
-from pipelex.pipe_operators.ocr.pipe_ocr_factory import PipeOcrFactory
+from pipelex.pipe_operators.extract.pipe_extract_blueprint import PipeExtractBlueprint
+from pipelex.pipe_operators.extract.pipe_extract_factory import PipeExtractFactory
from pipelex.pipe_run.pipe_job_factory import PipeJobFactory
from pipelex.pipe_run.pipe_run_params import PipeRunMode
from pipelex.pipe_run.pipe_run_params_factory import PipeRunParamsFactory
-from tests.integration.pipelex.test_data import PipeOcrTestCases
+from tests.integration.pipelex.test_data import PipeExtractTestCases
@pytest.mark.dry_runnable
@pytest.mark.inference
@pytest.mark.asyncio(loop_scope="class")
-class TestPipeOCR:
+class TestPipeExtract:
@pytest.fixture(scope="class", autouse=True)
def setup(self):
concept_library = get_concept_library()
@@ -37,14 +37,14 @@ class TestPipeOCR:
concept_library.teardown()
@pytest.mark.usefixtures("setup")
- @pytest.mark.parametrize("image_url", PipeOcrTestCases.PIPE_OCR_IMAGE_TEST_CASES)
- async def test_pipe_ocr_image(
+ @pytest.mark.parametrize("image_url", PipeExtractTestCases.PIPE_OCR_IMAGE_TEST_CASES)
+ async def test_pipe_extract_image(
self,
- ocr_choice_for_image: str,
+ extract_choice_for_image: str,
pipe_run_mode: PipeRunMode,
image_url: str,
):
- pipe_ocr_blueprint = PipeOcrBlueprint(
+ pipe_extract_blueprint = PipeExtractBlueprint(
description="OCR test for image processing",
inputs={"page_scan": InputRequirementBlueprint(concept=NativeConceptCode.IMAGE)},
output=NativeConceptCode.TEXT_AND_IMAGES,
@@ -52,14 +52,14 @@ class TestPipeOCR:
page_image_captions=False,
page_views=True,
page_views_dpi=72,
- ocr=ocr_choice_for_image,
+ ocr=extract_choice_for_image,
)
pipe_job = PipeJobFactory.make_pipe_job(
- pipe=PipeOcrFactory.make_from_blueprint(
+ pipe=PipeExtractFactory.make_from_blueprint(
domain="generic",
pipe_code="adhoc_for_test_pipe_ocr_image",
- blueprint=pipe_ocr_blueprint,
+ blueprint=pipe_extract_blueprint,
),
pipe_run_params=PipeRunParamsFactory.make_run_params(pipe_run_mode=pipe_run_mode),
working_memory=WorkingMemoryFactory.make_from_image(
@@ -67,26 +67,26 @@ class TestPipeOCR:
name="page_scan",
),
)
- pipe_ocr_output = await get_pipe_router().run(
+ pipe_extract_output = await get_pipe_router().run(
pipe_job=pipe_job,
)
- ocr_text = pipe_ocr_output.main_stuff_as_list(item_type=PageContent)
- pretty_print(ocr_text, title="ocr_text")
+ list_result = pipe_extract_output.main_stuff_as_list(item_type=PageContent)
+ pretty_print(list_result, title="list_result")
- @pytest.mark.parametrize("pdf_url", PipeOcrTestCases.PIPE_OCR_PDF_TEST_CASES)
+ @pytest.mark.parametrize("pdf_url", PipeExtractTestCases.PIPE_OCR_PDF_TEST_CASES)
async def test_pipe_ocr_pdf(
self,
- ocr_choice_for_pdf: str,
+ extract_choice_for_pdf: str,
pipe_run_mode: PipeRunMode,
pdf_url: str,
):
input_name = "arbitrary_name"
- pipe_ocr_blueprint = PipeOcrBlueprint(
+ pipe_ocr_blueprint = PipeExtractBlueprint(
description="OCR test for PDF processing",
inputs={input_name: InputRequirementBlueprint(concept=NativeConceptCode.PDF)},
output=NativeConceptCode.TEXT_AND_IMAGES,
- ocr=ocr_choice_for_pdf,
+ ocr=extract_choice_for_pdf,
page_images=True,
page_image_captions=False,
page_views=True,
@@ -94,7 +94,7 @@ class TestPipeOCR:
)
pipe_job = PipeJobFactory.make_pipe_job(
- pipe=PipeOcrFactory.make_from_blueprint(
+ pipe=PipeExtractFactory.make_from_blueprint(
domain="generic",
pipe_code="adhoc_for_test_pipe_ocr_pdf",
blueprint=pipe_ocr_blueprint,
@@ -105,8 +105,8 @@ class TestPipeOCR:
name=input_name,
),
)
- pipe_ocr_output = await get_pipe_router().run(
+ pipe_extract_output = await get_pipe_router().run(
pipe_job=pipe_job,
)
- ocr_text = pipe_ocr_output.main_stuff_as_list(item_type=PageContent)
- pretty_print(ocr_text, title="ocr_text")
+ extracted_text = pipe_extract_output.main_stuff_as_list(item_type=PageContent)
+ pretty_print(extracted_text, title="extracted_text")
diff --git a/tests/integration/pipelex/pipes/operator/pipe_func/test_pipe_func.py b/tests/integration/pipelex/pipes/operator/pipe_func/test_pipe_func.py
index 832cdad0c..f92b3e72f 100644
--- a/tests/integration/pipelex/pipes/operator/pipe_func/test_pipe_func.py
+++ b/tests/integration/pipelex/pipes/operator/pipe_func/test_pipe_func.py
@@ -45,7 +45,7 @@ if __name__ == "__main__":
# Create stuff with the source code
source_text_stuff = StuffFactory.make_stuff(
name="source_text",
- concept=ConceptFactory.make_native_concept_from_enum(native_concept_code=NativeConceptCode.TEXT),
+ concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.TEXT),
content=TextContent(text=sample_code),
)
diff --git a/tests/integration/pipelex/pipes/test_image_inputs.py b/tests/integration/pipelex/pipes/test_image_inputs.py
index b6e9e2f71..226d0cc16 100644
--- a/tests/integration/pipelex/pipes/test_image_inputs.py
+++ b/tests/integration/pipelex/pipes/test_image_inputs.py
@@ -67,7 +67,7 @@ class TestImageInputs:
# Create stuff from page content
stuff = StuffFactory.make_stuff(
- concept=ConceptFactory.make_native_concept_from_enum(native_concept_code=NativeConceptCode.PAGE),
+ concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.PAGE),
content=page_content,
name="page",
)
diff --git a/tests/integration/pipelex/pipes/test_pipe_running_variants.py b/tests/integration/pipelex/pipes/test_pipe_running_variants.py
index c649d934c..d42458d3f 100644
--- a/tests/integration/pipelex/pipes/test_pipe_running_variants.py
+++ b/tests/integration/pipelex/pipes/test_pipe_running_variants.py
@@ -19,7 +19,7 @@ from tests.integration.pipelex.test_data import PipeTestCases
@pytest.mark.dry_runnable
@pytest.mark.llm
@pytest.mark.inference
@pytest.mark.asyncio(loop_scope="class")
class TestPipeRunningVariants:
diff --git a/tests/integration/pipelex/test_data.py b/tests/integration/pipelex/test_data.py
index 4b797b45d..a115b250d 100644
--- a/tests/integration/pipelex/test_data.py
+++ b/tests/integration/pipelex/test_data.py
@@ -48,17 +48,17 @@ class PipeTestCases:
# Create simple Stuff objects
SIMPLE_STUFF_TEXT = StuffFactory.make_stuff(
name="text",
- concept=ConceptFactory.make_native_concept_from_enum(native_concept_code=NativeConceptCode.TEXT),
+ concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.TEXT),
content=TextContent(text="Describe a t-shirt in 2 sentences"),
)
SIMPLE_STUFF_IMAGE = StuffFactory.make_stuff(
name="image",
- concept=ConceptFactory.make_native_concept_from_enum(native_concept_code=NativeConceptCode.IMAGE),
+ concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.IMAGE),
content=ImageContent(url=URL_IMG_FASHION_PHOTO_1),
)
SIMPLE_STUFF_PDF = StuffFactory.make_stuff(
name="document",
- concept=ConceptFactory.make_native_concept_from_enum(native_concept_code=NativeConceptCode.PDF),
+ concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.PDF),
content=PDFContent(url=PDFTestCases.DOCUMENT_URLS[0]),
)
COMPLEX_STUFF = StuffFactory.make_stuff(
@@ -74,7 +74,7 @@ class PipeTestCases:
STUFF_CONTENT_WITH_IMAGE_ATTRIBUTE_1 = SomeContentWithImageAttribute(image_attribute=ImageContent(url=URL_IMG_FASHION_PHOTO_1))
STUFF_WITH_IMAGE_ATTRIBUTE = StuffFactory.make_stuff(
- concept=ConceptFactory.make_native_concept_from_enum(native_concept_code=NativeConceptCode.IMAGE),
+ concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.IMAGE),
content=STUFF_CONTENT_WITH_IMAGE_ATTRIBUTE_1,
name="stuff_with_image",
)
@@ -83,7 +83,7 @@ class PipeTestCases:
sub_object=STUFF_CONTENT_WITH_IMAGE_ATTRIBUTE_1,
)
STUFF_WITH_IMAGE_ATTRIBUTE_IN_SUB_OBJECT = StuffFactory.make_stuff(
- concept=ConceptFactory.make_native_concept_from_enum(native_concept_code=NativeConceptCode.IMAGE),
+ concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.IMAGE),
content=STUFF_CONTENT_WITH_IMAGE_ATTRIBUTE_IN_SUB_OBJECT,
name="stuff_with_image_in_sub_object",
)
@@ -154,7 +154,7 @@ class PipeTestCases:
(
"Extract page contents from PDF",
SIMPLE_STUFF_PDF,
- "ocr_page_contents_from_pdf",
+ "extract_page_contents_from_pdf",
),
]
FAILURE_PIPES: ClassVar[list[tuple[str, type[Exception], str]]] = [
@@ -174,7 +174,7 @@ class LibraryTestCases:
]
-class PipeOcrTestCases:
+class PipeExtractTestCases:
PIPE_OCR_IMAGE_TEST_CASES: ClassVar[list[str]] = [
ImageTestCases.IMAGE_FILE_PATH_PNG,
ImageTestCases.IMAGE_URL_PNG,
diff --git a/tests/unit/pipelex/client/test_api_serialization.py b/tests/unit/pipelex/client/test_api_serialization.py
index 5873596d4..aa944220d 100644
--- a/tests/unit/pipelex/client/test_api_serialization.py
+++ b/tests/unit/pipelex/client/test_api_serialization.py
@@ -73,7 +73,7 @@ class TestApiSerialization:
@pytest.fixture
def text_content_memory(self) -> WorkingMemory:
stuff = StuffFactory.make_stuff(
- concept=ConceptFactory.make_native_concept_from_enum(native_concept_code=NativeConceptCode.TEXT),
+ concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.TEXT),
name="sample_text",
content=TextContent(text="Sample text content"),
)
@@ -83,7 +83,7 @@ class TestApiSerialization:
def number_content_memory(self) -> WorkingMemory:
number_content = NumberContent(number=3.14159)
stuff = StuffFactory.make_stuff(
- concept=ConceptFactory.make_native_concept_from_enum(native_concept_code=NativeConceptCode.NUMBER),
+ concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.NUMBER),
name="pi_value",
content=number_content,
)
diff --git a/tests/unit/pipelex/cogt/models/test_model_deck.py b/tests/unit/pipelex/cogt/models/test_model_deck.py
index 0def83c41..d10085b40 100644
--- a/tests/unit/pipelex/cogt/models/test_model_deck.py
+++ b/tests/unit/pipelex/cogt/models/test_model_deck.py
@@ -34,8 +34,8 @@ class TestModelDeckGetOptionalInferenceModel:
for_text=LLMSetting(llm_handle="default_text", temperature=0.7, max_tokens=1000),
for_object=LLMSetting(llm_handle="default_object", temperature=0.1, max_tokens=1000),
),
- ocr_presets={},
- ocr_choice_default="base_ocr_mistral",
+ extract_presets={},
+ extract_choice_default="base_ocr_mistral",
img_gen_presets={},
img_gen_choice_default="base_img_gen",
)
diff --git a/tests/unit/pipelex/core/concepts/concept/test_concept.py b/tests/unit/pipelex/core/concepts/concept/test_concept.py
index 9608e6daf..507fcf731 100644
--- a/tests/unit/pipelex/core/concepts/concept/test_concept.py
+++ b/tests/unit/pipelex/core/concepts/concept/test_concept.py
@@ -128,7 +128,7 @@ class TestConcept:
valid_definition = "Lorem Ipsum"
for native_concept_code in NativeConceptCode.values_list():
- native_concept = ConceptFactory.make_native_concept_from_enum(native_concept_code=native_concept_code)
+ native_concept = ConceptFactory.make_native_concept(native_concept_code=native_concept_code)
assert Concept.is_native_concept(native_concept) is True
assert (
@@ -315,11 +315,11 @@ class TestConcept:
concept_codes_from_the_same_domain=["Code1"],
)
- concept_5 = ConceptFactory.make_native_concept_from_enum(
+ concept_5 = ConceptFactory.make_native_concept(
native_concept_code=NativeConceptCode.PAGE,
)
- concept_6 = ConceptFactory.make_native_concept_from_enum(
+ concept_6 = ConceptFactory.make_native_concept(
native_concept_code=NativeConceptCode.IMAGE,
)
diff --git a/tests/unit/pipelex/core/concepts/concept_library/test_concept_library.py b/tests/unit/pipelex/core/concepts/concept_library/test_concept_library.py
index 85bc3a468..011b12c87 100644
--- a/tests/unit/pipelex/core/concepts/concept_library/test_concept_library.py
+++ b/tests/unit/pipelex/core/concepts/concept_library/test_concept_library.py
@@ -7,7 +7,7 @@ from pipelex.hub import get_concept_library
class TestConceptLibrary:
def test_is_image_concept(self):
concept_library = get_concept_library()
- native_image_concept = ConceptFactory.make_native_concept_from_enum(native_concept_code=NativeConceptCode.IMAGE)
+ native_image_concept = ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.IMAGE)
concept_1 = ConceptFactory.make_from_blueprint(
domain="test",
diff --git a/tests/unit/pipelex/core/memory/test_working_memory.py b/tests/unit/pipelex/core/memory/test_working_memory.py
index 3c1ce3e5c..d62bd4aa7 100644
--- a/tests/unit/pipelex/core/memory/test_working_memory.py
+++ b/tests/unit/pipelex/core/memory/test_working_memory.py
@@ -86,19 +86,19 @@ class TestWorkingMemory:
def multiple_stuff_memory(self) -> WorkingMemory:
"""Create WorkingMemory with multiple stuff items."""
text_stuff = StuffFactory.make_stuff(
- concept=ConceptFactory.make_native_concept_from_enum(native_concept_code=NativeConceptCode.TEXT),
+ concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.TEXT),
name="question",
content=TextContent(text="What are the aerodynamic features?"),
)
document_stuff = StuffFactory.make_stuff(
- concept=ConceptFactory.make_native_concept_from_enum(native_concept_code=NativeConceptCode.TEXT),
+ concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.TEXT),
name="document",
content=TextContent(text=TestWorkingMemoryData.SAMPLE_TEXT),
)
image_stuff = StuffFactory.make_stuff(
- concept=ConceptFactory.make_native_concept_from_enum(native_concept_code=NativeConceptCode.IMAGE),
+ concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.IMAGE),
name="diagram",
content=ImageContent(url=TestWorkingMemoryData.SAMPLE_IMAGE_URL),
)
@@ -109,13 +109,13 @@ class TestWorkingMemory:
def memory_with_aliases(self) -> WorkingMemory:
"""Create WorkingMemory with aliases."""
text_stuff = StuffFactory.make_stuff(
- concept=ConceptFactory.make_native_concept_from_enum(native_concept_code=NativeConceptCode.TEXT),
+ concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.TEXT),
name="primary_text",
content=TextContent(text="Primary content"),
)
secondary_stuff = StuffFactory.make_stuff(
- concept=ConceptFactory.make_native_concept_from_enum(native_concept_code=NativeConceptCode.TEXT),
+ concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.TEXT),
name="secondary_text",
content=TextContent(text="Secondary content"),
)
@@ -156,7 +156,7 @@ class TestWorkingMemory:
)
stuff = StuffFactory.make_stuff(
- concept=ConceptFactory.make_native_concept_from_enum(native_concept_code=NativeConceptCode.TEXT_AND_IMAGES),
+ concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.TEXT_AND_IMAGES),
name="project_overview",
content=text_and_images_content,
)
@@ -187,7 +187,7 @@ class TestWorkingMemory:
number_content = NumberContent(number=3.14159)
stuff = StuffFactory.make_stuff(
- concept=ConceptFactory.make_native_concept_from_enum(native_concept_code=NativeConceptCode.NUMBER),
+ concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.NUMBER),
name="pi_value",
content=number_content,
)
diff --git a/tests/unit/pipelex/core/stuffs/test_stuff_content_factory.py b/tests/unit/pipelex/core/stuffs/test_stuff_content_factory.py
index 402a3aa66..40395c9f4 100644
--- a/tests/unit/pipelex/core/stuffs/test_stuff_content_factory.py
+++ b/tests/unit/pipelex/core/stuffs/test_stuff_content_factory.py
@@ -92,7 +92,7 @@ class TestStuffContentFactory:
def test_make_stuffcontent_from_concept_code_required_text_content(self):
"""Test required method with native.Text concept (should work)."""
result = StuffContentFactory.make_stuff_content_from_concept_required(
- concept=ConceptFactory.make_native_concept_from_enum(native_concept_code=NativeConceptCode.TEXT),
+ concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.TEXT),
value="Test text content",
)
@@ -102,7 +102,7 @@ class TestStuffContentFactory:
def test_make_stuffcontent_from_concept_code_required_implicit_concept(self):
"""Test required method with implicit concept (should create TextContent)."""
result = StuffContentFactory.make_stuff_content_from_concept_required(
- concept=ConceptFactory.make_native_concept_from_enum(native_concept_code=NativeConceptCode.TEXT),
+ concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.TEXT),
value="Test content for implicit concept",
)
@@ -112,7 +112,7 @@ class TestStuffContentFactory:
def test_make_stuffcontent_from_concept_code_with_fallback_text_success(self):
"""Test fallback method with native.Text concept."""
result = StuffContentFactory.make_stuff_content_from_concept_with_fallback(
- concept=ConceptFactory.make_native_concept_from_enum(native_concept_code=NativeConceptCode.TEXT),
+ concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.TEXT),
value="Test text content",
)
@@ -122,7 +122,7 @@ class TestStuffContentFactory:
def test_make_stuffcontent_from_concept_code_with_fallback_implicit_string(self):
"""Test fallback method with implicit concept and string value."""
result = StuffContentFactory.make_stuff_content_from_concept_with_fallback(
- concept=ConceptFactory.make_native_concept_from_enum(native_concept_code=NativeConceptCode.TEXT),
+ concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.TEXT),
value="Fallback text content",
)
@@ -132,7 +132,7 @@ class TestStuffContentFactory:
def test_make_stuffcontent_from_concept_code_with_fallback_implicit_dict(self):
"""Test fallback method with implicit concept and dict value."""
result = StuffContentFactory.make_stuff_content_from_concept_with_fallback(
- concept=ConceptFactory.make_native_concept_from_enum(native_concept_code=NativeConceptCode.TEXT),
+ concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.TEXT),
value={"text": "Dict fallback content"},
)
@@ -150,7 +150,7 @@ class TestStuffContentFactory:
if test_name.startswith("text_"):
# Test native.Text concept with required method
result = StuffContentFactory.make_stuff_content_from_concept_required(
- concept=ConceptFactory.make_native_concept_from_enum(native_concept_code=NativeConceptCode.TEXT),
+ concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.TEXT),
value=content,
)
assert isinstance(result, TextContent)
@@ -168,7 +168,7 @@ class TestStuffContentFactory:
# The dict will be passed through model_validate which should fail for TextContent
try:
result_required = StuffContentFactory.make_stuff_content_from_concept_required(
- concept=ConceptFactory.make_native_concept_from_enum(native_concept_code=NativeConceptCode.TEXT),
+ concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.TEXT),
value=content,
)
# If it succeeds, it should be TextContent (due to implicit concept)
@@ -180,7 +180,7 @@ class TestStuffContentFactory:
# Test fallback method - same behavior expected
try:
result_fallback = StuffContentFactory.make_stuff_content_from_concept_with_fallback(
- concept=ConceptFactory.make_native_concept_from_enum(native_concept_code=NativeConceptCode.TEXT),
+ concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.TEXT),
value=content,
)
# If it succeeds, it should be TextContent (due to implicit concept)
@@ -193,13 +193,13 @@ class TestStuffContentFactory:
# Both methods should work and return TextContent due to implicit concept creation
result_required = StuffContentFactory.make_stuff_content_from_concept_required(
- concept=ConceptFactory.make_native_concept_from_enum(native_concept_code=NativeConceptCode.TEXT),
+ concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.TEXT),
value=content,
)
assert isinstance(result_required, TextContent)
result_fallback = StuffContentFactory.make_stuff_content_from_concept_with_fallback(
- concept=ConceptFactory.make_native_concept_from_enum(native_concept_code=NativeConceptCode.TEXT),
+ concept=ConceptFactory.make_native_concept(native_concept_code=NativeConceptCode.TEXT),
value=content,
)
assert isinstance(result_fallback, TextContent)
diff --git a/tests/unit/pipelex/core/stuffs/test_stuff_factory_make_stuff_from_content.py b/tests/unit/pipelex/core/stuffs/test_stuff_factory_make_stuff_from_content.py
index 98e740f7a..deb9125c2 100644
--- a/tests/unit/pipelex/core/stuffs/test_stuff_factory_make_stuff_from_content.py
+++ b/tests/unit/pipelex/core/stuffs/test_stuff_factory_make_stuff_from_content.py
@@ -187,7 +187,7 @@ class TestMakeStuffFromStuffContentUsingSearchDomains:
"""Test string input creates TextContent with TEXT concept."""
mock_concept = mocker.Mock()
mock_concept_factory = mocker.patch("pipelex.core.stuffs.stuff_factory.ConceptFactory")
- mock_concept_factory.make_native_concept_from_enum.return_value = mock_concept
+ mock_concept_factory.make_native_concept.return_value = mock_concept
mock_stuff = mocker.Mock(spec=Stuff)
mocker.patch.object(StuffFactory, "make_stuff", return_value=mock_stuff)
@@ -199,13 +199,13 @@ class TestMakeStuffFromStuffContentUsingSearchDomains:
)
assert result == mock_stuff
- mock_concept_factory.make_native_concept_from_enum.assert_called_once_with(native_concept_code=NativeConceptCode.TEXT)
+ mock_concept_factory.make_native_concept.assert_called_once_with(native_concept_code=NativeConceptCode.TEXT)
def test_dict_with_native_concept(self, mocker: MockerFixture):
"""Test dictionary with native concept."""
mock_concept = mocker.Mock()
mock_concept_factory = mocker.patch("pipelex.core.stuffs.stuff_factory.ConceptFactory")
- mock_concept_factory.make_native_concept_from_enum.return_value = mock_concept
+ mock_concept_factory.make_native_concept.return_value = mock_concept
mock_content = mocker.Mock(spec=StuffContent)
mock_content_factory = mocker.patch("pipelex.core.stuffs.stuff_factory.StuffContentFactory")
@@ -222,7 +222,7 @@ class TestMakeStuffFromStuffContentUsingSearchDomains:
)
assert result == mock_stuff
- mock_concept_factory.make_native_concept_from_enum.assert_called_once()
+ mock_concept_factory.make_native_concept.assert_called_once()
mock_content_factory.make_stuff_content_from_concept_with_fallback.assert_called_once()
def test_dict_with_custom_concept_and_stuffcontent_value(self, mocker: MockerFixture):
diff --git a/tests/unit/pipelex/core/test_data/__init__.py b/tests/unit/pipelex/core/test_data/__init__.py
index ce1be450e..71f8cdb1d 100644
--- a/tests/unit/pipelex/core/test_data/__init__.py
+++ b/tests/unit/pipelex/core/test_data/__init__.py
@@ -13,10 +13,10 @@ from .pipes.controllers.condition.pipe_condition import PIPE_CONDITION_TEST_CASE
from .pipes.controllers.parallel.pipe_parallel import PIPE_PARALLEL_TEST_CASES
from .pipes.controllers.sequence.pipe_sequence import PIPE_SEQUENCE_TEST_CASES
from .pipes.operators.compose.pipe_compose import PIPE_COMPOSE_TEST_CASES
+from .pipes.operators.extract.pipe_ocr import PIPE_OCR_TEST_CASES
from .pipes.operators.func.pipe_func import PIPE_FUNC_TEST_CASES
from .pipes.operators.img_gen.pipe_img_gen import PIPE_IMG_GEN_TEST_CASES
from .pipes.operators.llm.pipe_llm import PIPE_LLM_TEST_CASES
-from .pipes.operators.ocr.pipe_ocr import PIPE_OCR_TEST_CASES
class InterpreterTestCases:
diff --git a/tests/unit/pipelex/core/test_data/pipes/operators/extract/__init__.py b/tests/unit/pipelex/core/test_data/pipes/operators/extract/__init__.py
new file mode 100644
index 000000000..3119a2416
--- /dev/null
+++ b/tests/unit/pipelex/core/test_data/pipes/operators/extract/__init__.py
@@ -0,0 +1 @@
+"""PipeExtract test data for PipelexInterpreter tests."""
diff --git a/tests/unit/pipelex/core/test_data/pipes/operators/ocr/pipe_ocr.py b/tests/unit/pipelex/core/test_data/pipes/operators/extract/pipe_ocr.py
similarity index 67%
rename from tests/unit/pipelex/core/test_data/pipes/operators/ocr/pipe_ocr.py
rename to tests/unit/pipelex/core/test_data/pipes/operators/extract/pipe_ocr.py
index 08f52d728..927d12442 100644
--- a/tests/unit/pipelex/core/test_data/pipes/operators/ocr/pipe_ocr.py
+++ b/tests/unit/pipelex/core/test_data/pipes/operators/extract/pipe_ocr.py
@@ -1,6 +1,6 @@
from pipelex.core.bundles.pipelex_bundle_blueprint import PipelexBundleBlueprint
from pipelex.core.concepts.concept_native import NativeConceptCode
-from pipelex.pipe_operators.ocr.pipe_ocr_blueprint import PipeOcrBlueprint
+from pipelex.pipe_operators.extract.pipe_extract_blueprint import PipeExtractBlueprint
PIPE_OCR = (
"pipe_ocr",
@@ -8,26 +8,26 @@ PIPE_OCR = (
description = "Domain with OCR pipe"
[pipe.extract_text]
-type = "PipeOcr"
+type = "PipeExtract"
description = "Extract text from document"
output = "Page"
-ocr = "base_ocr_pypdfium2"
+ocr = "base_extract_pypdfium2"
""",
PipelexBundleBlueprint(
domain="test_pipes",
description="Domain with OCR pipe",
pipe={
- "extract_text": PipeOcrBlueprint(
- type="PipeOcr",
+ "extract_text": PipeExtractBlueprint(
+ type="PipeExtract",
description="Extract text from document",
output=NativeConceptCode.PAGE,
- ocr="base_ocr_pypdfium2",
+ ocr="base_extract_pypdfium2",
),
},
),
)
-# Export all PipeOcr test cases
+# Export all PipeExtract test cases
PIPE_OCR_TEST_CASES = [
PIPE_OCR,
]
diff --git a/tests/unit/pipelex/core/test_data/pipes/operators/ocr/__init__.py b/tests/unit/pipelex/core/test_data/pipes/operators/ocr/__init__.py
deleted file mode 100644
index a5ef8b7a3..000000000
--- a/tests/unit/pipelex/core/test_data/pipes/operators/ocr/__init__.py
+++ /dev/null
@@ -1 +0,0 @@
-"""PipeOcr test data for PipelexInterpreter tests."""
diff --git a/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operator/pipe_img/test_data.py b/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operator/pipe_img/test_data.py
index 49fac4933..16e933abb 100644
--- a/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operator/pipe_img/test_data.py
+++ b/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operator/pipe_img/test_data.py
@@ -1,7 +1,7 @@
from typing import ClassVar
from pipelex.core.pipes.input_requirement_blueprint import InputRequirementBlueprint
-from pipelex.libraries.pipelines.builder.pipe.pipe_img_spec import PipeImgGenSpec, RecommendedImgGen
+from pipelex.libraries.pipelines.builder.pipe.pipe_img_spec import ImgGenSkill, PipeImgGenSpec
from pipelex.pipe_operators.img_gen.pipe_img_gen_blueprint import PipeImgGenBlueprint
@@ -39,7 +39,7 @@ class PipeImgGenTestCases:
description="Generate image with options",
inputs={"description": "Text"},
output="Image",
- img_gen=RecommendedImgGen.BASE_IMG_GEN,
+ img_gen_skill=ImgGenSkill.GEN_IMAGE,
nb_output=3,
),
PipeImgGenBlueprint(
@@ -49,7 +49,7 @@ class PipeImgGenTestCases:
type="PipeImgGen",
category="PipeOperator",
img_gen_prompt=None,
- img_gen=RecommendedImgGen.BASE_IMG_GEN,
+ img_gen=ImgGenSkill.GEN_IMAGE.model_recommendation,
aspect_ratio=None,
background=None,
output_format=None,
diff --git a/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operator/pipe_ocr/test_data.py b/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operator/pipe_ocr/test_data.py
index 15e0ebafe..5f31980e0 100644
--- a/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operator/pipe_ocr/test_data.py
+++ b/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operator/pipe_ocr/test_data.py
@@ -1,26 +1,26 @@
from typing import ClassVar
from pipelex.core.pipes.input_requirement_blueprint import InputRequirementBlueprint
-from pipelex.libraries.pipelines.builder.pipe.pipe_ocr_spec import PipeOcrSpec
-from pipelex.pipe_operators.ocr.pipe_ocr_blueprint import PipeOcrBlueprint
+from pipelex.libraries.pipelines.builder.pipe.pipe_extract_spec import PipeExtractSpec
+from pipelex.pipe_operators.extract.pipe_extract_blueprint import PipeExtractBlueprint
-class PipeOcrTestCases:
+class PipeExtractTestCases:
SIMPLE_OCR = (
"simple_ocr",
- PipeOcrSpec(
+ PipeExtractSpec(
pipe_code="ocr_extractor",
description="Extract text from image",
inputs={"image": "Image"},
output="ExtractedText",
- ocr="extract_text_from_visuals",
+ extract_skill="extract_text_from_visuals",
),
- PipeOcrBlueprint(
+ PipeExtractBlueprint(
source=None,
description="Extract text from image",
inputs={"image": InputRequirementBlueprint(concept="Image")},
output="ExtractedText",
- type="PipeOcr",
+ type="PipeExtract",
category="PipeOperator",
ocr="base_ocr_mistral",
),
@@ -28,22 +28,22 @@ class PipeOcrTestCases:
OCR_WITH_OPTIONS = (
"ocr_with_options",
- PipeOcrSpec(
+ PipeExtractSpec(
pipe_code="advanced_ocr",
description="OCR with page options",
inputs={"document": "PDF"},
output="PageContent",
- ocr="extract_text_from_pdf",
+ extract_skill="extract_text_from_pdf",
page_images=True,
page_image_captions=True,
page_views=True,
),
- PipeOcrBlueprint(
+ PipeExtractBlueprint(
source=None,
description="OCR with page options",
inputs={"document": InputRequirementBlueprint(concept="PDF")},
output="PageContent",
- type="PipeOcr",
+ type="PipeExtract",
category="PipeOperator",
ocr="base_ocr_mistral",
page_images=True,
@@ -53,7 +53,7 @@ class PipeOcrTestCases:
),
)
- TEST_CASES: ClassVar[list[tuple[str, PipeOcrSpec, PipeOcrBlueprint]]] = [
+ TEST_CASES: ClassVar[list[tuple[str, PipeExtractSpec, PipeExtractBlueprint]]] = [
SIMPLE_OCR,
OCR_WITH_OPTIONS,
]
diff --git a/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operator/pipe_ocr/test_pipe_ocr.py b/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operator/pipe_ocr/test_pipe_extract.py
similarity index 51%
rename from tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operator/pipe_ocr/test_pipe_ocr.py
rename to tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operator/pipe_ocr/test_pipe_extract.py
index f3fad9ef8..c97fb00d2 100644
--- a/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operator/pipe_ocr/test_pipe_ocr.py
+++ b/tests/unit/pipelex/libraries/pipelines/builder/pipe/pipe_operator/pipe_ocr/test_pipe_extract.py
@@ -1,21 +1,21 @@
import pytest
from pipelex import log
-from pipelex.libraries.pipelines.builder.pipe.pipe_ocr_spec import PipeOcrSpec
-from pipelex.pipe_operators.ocr.pipe_ocr_blueprint import PipeOcrBlueprint
-from tests.unit.pipelex.libraries.pipelines.builder.pipe.pipe_operator.pipe_ocr.test_data import PipeOcrTestCases
+from pipelex.libraries.pipelines.builder.pipe.pipe_extract_spec import PipeExtractSpec
+from pipelex.pipe_operators.extract.pipe_extract_blueprint import PipeExtractBlueprint
+from tests.unit.pipelex.libraries.pipelines.builder.pipe.pipe_operator.pipe_ocr.test_data import PipeExtractTestCases
-class TestPipeOcrBlueprintConversion:
+class TestPipeExtractBlueprintConversion:
@pytest.mark.parametrize(
("test_name", "pipe_spec", "expected_blueprint"),
- PipeOcrTestCases.TEST_CASES,
+ PipeExtractTestCases.TEST_CASES,
)
def test_pipe_ocr_spec_to_blueprint(
self,
test_name: str,
- pipe_spec: PipeOcrSpec,
- expected_blueprint: PipeOcrBlueprint,
+ pipe_spec: PipeExtractSpec,
+ expected_blueprint: PipeExtractBlueprint,
):
log.verbose(f"Testing {test_name}")
result = pipe_spec.to_blueprint()