camel.extractors package#
Submodules#
camel.extractors.base module#
- class camel.extractors.base.BaseExtractor(pipeline: List[List[BaseExtractorStrategy]], cache_templates: bool = True, max_cache_size: int = 1000, extraction_timeout: float = 30.0, batch_size: int = 10, monitoring_interval: float = 5.0, cpu_threshold: float = 80.0, memory_threshold: float = 85.0, **kwargs)[source]#
Bases:
object
Base class for response extractors with a fixed strategy pipeline.
This extractor: - Uses a fixed multi-stage pipeline of extraction strategies. - Tries each strategy in order within a stage until one succeeds. - Feeds the output of one stage into the next for processing. - Supports async execution for efficient processing. - Provides batch processing and resource monitoring options.
- async cleanup() None [source]#
Clean up extractor resources.
This method handles cleanup of resources and resets the extractor state. It ensures: 1. All resources are properly released 2. Template cache is cleared 3. Parallel processing resources are shutdown 4. State is reset to initial 5. Cleanup happens even if errors occur
- Raises:
RuntimeError β If cleanup fails (after resetting initialization state).
- async extract(response: str) str | None [source]#
Extracts a normalized, comparable part of the LLM response using the fixed multi-stage strategy pipeline.
- Parameters:
response (str) β The raw response text.
- Returns:
Extracted data if successful, otherwise None.
- Return type:
Optional[str]
- Raises:
ValueError β If response is empty or invalid.
RuntimeError β If extractor is not initialized.
Module contents#
- class camel.extractors.BaseExtractor(pipeline: List[List[BaseExtractorStrategy]], cache_templates: bool = True, max_cache_size: int = 1000, extraction_timeout: float = 30.0, batch_size: int = 10, monitoring_interval: float = 5.0, cpu_threshold: float = 80.0, memory_threshold: float = 85.0, **kwargs)[source]#
Bases:
object
Base class for response extractors with a fixed strategy pipeline.
This extractor: - Uses a fixed multi-stage pipeline of extraction strategies. - Tries each strategy in order within a stage until one succeeds. - Feeds the output of one stage into the next for processing. - Supports async execution for efficient processing. - Provides batch processing and resource monitoring options.
- async cleanup() None [source]#
Clean up extractor resources.
This method handles cleanup of resources and resets the extractor state. It ensures: 1. All resources are properly released 2. Template cache is cleared 3. Parallel processing resources are shutdown 4. State is reset to initial 5. Cleanup happens even if errors occur
- Raises:
RuntimeError β If cleanup fails (after resetting initialization state).
- async extract(response: str) str | None [source]#
Extracts a normalized, comparable part of the LLM response using the fixed multi-stage strategy pipeline.
- Parameters:
response (str) β The raw response text.
- Returns:
Extracted data if successful, otherwise None.
- Return type:
Optional[str]
- Raises:
ValueError β If response is empty or invalid.
RuntimeError β If extractor is not initialized.
- class camel.extractors.BaseExtractorStrategy[source]#
Bases:
ABC
Abstract base class for extraction strategies.
- class camel.extractors.BoxedStrategy[source]#
Bases:
BaseExtractorStrategy
Extracts content from \boxed{} environments.
- class camel.extractors.PythonDictStrategy[source]#
Bases:
BaseExtractorStrategy
Extracts and normalizes Python dictionaries.
- class camel.extractors.PythonListStrategy[source]#
Bases:
BaseExtractorStrategy
Extracts and normalizes Python lists.
- class camel.extractors.PythonSetStrategy[source]#
Bases:
BaseExtractorStrategy
Extracts and normalizes Python sets.
- class camel.extractors.PythonTupleStrategy[source]#
Bases:
BaseExtractorStrategy
Extracts and normalizes Python tuples.