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.

async setup() None[source]#

Set up the extractor with necessary resources.

This method: 1. Initializes template cache if enabled 2. Sets up any parallel processing resources 3. Validates extraction patterns

Raises:

RuntimeError – If initialization fails

class camel.extractors.base.BaseExtractorStrategy[source]#

Bases: ABC

Abstract base class for extraction strategies.

abstract async extract(text: str) str | None[source]#

Asynchronously extracts relevant parts from text.

Parameters:

text (str) – The input text to process.

Returns:

Extracted str if successful, otherwise None.

Return type:

Optional[str]

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.

async setup() None[source]#

Set up the extractor with necessary resources.

This method: 1. Initializes template cache if enabled 2. Sets up any parallel processing resources 3. Validates extraction patterns

Raises:

RuntimeError – If initialization fails

class camel.extractors.BaseExtractorStrategy[source]#

Bases: ABC

Abstract base class for extraction strategies.

abstract async extract(text: str) str | None[source]#

Asynchronously extracts relevant parts from text.

Parameters:

text (str) – The input text to process.

Returns:

Extracted str if successful, otherwise None.

Return type:

Optional[str]

class camel.extractors.BoxedStrategy[source]#

Bases: BaseExtractorStrategy

Extracts content from \boxed{} environments.

async extract(text: str) str | None[source]#

Extract content from \boxed{} environments.

Parameters:

text (str) – The input text to process.

Returns:

Content inside \boxed{} if found, else None.

Return type:

Optional[str]

class camel.extractors.PythonDictStrategy[source]#

Bases: BaseExtractorStrategy

Extracts and normalizes Python dictionaries.

async extract(text: str) str | None[source]#

Extract and normalize a Python dictionary.

Parameters:

text (str) – The input text to process.

Returns:

Normalized dictionary as a string, else None.

Return type:

Optional[str]

class camel.extractors.PythonListStrategy[source]#

Bases: BaseExtractorStrategy

Extracts and normalizes Python lists.

async extract(text: str) str | None[source]#

Extract and normalize a Python list.

Parameters:

text (str) – The input text to process.

Returns:

Normalized list as a string if found, else None.

Return type:

Optional[str]

class camel.extractors.PythonSetStrategy[source]#

Bases: BaseExtractorStrategy

Extracts and normalizes Python sets.

async extract(text: str) str | None[source]#

Extract and normalize a Python set.

Parameters:

text (str) – The input text to process.

Returns:

Normalized set as a string if found, else None.

Return type:

Optional[str]

class camel.extractors.PythonTupleStrategy[source]#

Bases: BaseExtractorStrategy

Extracts and normalizes Python tuples.

async extract(text: str) str | None[source]#

Extract and normalize a Python tuple.

Parameters:

text (str) – The input text to process.

Returns:

Normalized tuple as a string if found, else None.

Return type:

Optional[str]