Prompt generator strategy imports.
Functions¶
get_lazy_dir¶
get_lazy_dir(module_globals: dict[str, Any], exports: Mapping[str, LazyExport]) → list[str]Return package attributes and unresolved public exports.
| Parameter | Type | Description |
|---|---|---|
module_globals | dict[str, Any] | The package globals. |
exports | Mapping[str, LazyExport] | Public names and their implementation locations. |
Returns:
list[str]— list[str]: Sorted package attribute names.
resolve_lazy_export¶
resolve_lazy_export(name: str, module_name: str, module_globals: dict[str, Any], exports: Mapping[str, LazyExport]) → AnyResolve and cache one package export.
| Parameter | Type | Description |
|---|---|---|
name | str | Public attribute requested from the package. |
module_name | str | Package name used in an AttributeError. |
module_globals | dict[str, Any] | Package globals where the resolved value is cached. |
exports | Mapping[str, LazyExport] | Public names and their implementation locations. |
Returns:
Any— The resolved public value.
Raises:
AttributeError— Ifnameis not a declared lazy export.
AnecdoctorContext¶
Bases: PromptGeneratorStrategyContext
Context specific to Anecdoctor prompt generation.
Contains all parameters needed for executing Anecdoctor prompt generation, including the evaluation data, language settings, and conversation ID.
AnecdoctorGenerator¶
Bases: PromptGeneratorStrategy[AnecdoctorContext, AnecdoctorResult], Identifiable
Implementation of the Anecdoctor prompt generation strategy.
The Anecdoctor generator creates misinformation content by either:
Using few-shot examples directly (default mode when processing_model is not provided)
First extracting a knowledge graph from examples, then using it (when processing_model is provided)
This generator is designed to test a model’s susceptibility to generating false or misleading content when provided with examples in ClaimsReview format. The generator can optionally use a processing model to extract a knowledge graph representation of the examples before generating the final content.
The generation flow consists of:
(Optional) Extract knowledge graph from evaluation data using processing model
Format a system prompt based on language and content type
Send formatted examples (or knowledge graph) to target model
Return the generated content as the result
Constructor Parameters:
| Parameter | Type | Description |
|---|---|---|
objective_target | PromptTarget | The chat model to be used for prompt generation. |
processing_model | `PromptTarget | None` |
converter_config | `StrategyConverterConfig | None` |
prompt_normalizer | `PromptNormalizer | None` |
Examples:
Methods:
execute_async¶
execute_async(kwargs: Any = {}) → AnecdoctorResultExecute the prompt generation strategy asynchronously with the provided parameters.
| Parameter | Type | Description |
|---|---|---|
content_type | str | The type of content to generate (e.g., “viral tweet”, “news article”). |
language | str | The language of the content to generate (e.g., “english”, “spanish”). |
evaluation_data | list[str] | The data in ClaimsReview format to use in constructing the prompt. |
memory_labels | `dict[str, str] | None` |
**kwargs | Any | Additional parameters for the generation. Defaults to {}. |
Returns:
AnecdoctorResult— The result of the anecdoctor generation.
AnecdoctorResult¶
Bases: PromptGeneratorStrategyResult
Result of Anecdoctor prompt generation.
Contains the generated content from the misinformation prompt generation.
PromptGeneratorStrategy¶
Bases: Strategy[PromptGeneratorStrategyContextT, PromptGeneratorStrategyResultT], ABC
Base class for all prompt generator strategies. Provides a structure for implementing specific prompt generation strategies.
Constructor Parameters:
| Parameter | Type | Description |
|---|---|---|
context_type | type | Type of the context used by the strategy. |
logger | logging.Logger | Logger instance for logging events. Defaults to logger. |
event_handler | StrategyEventHandler | Event handler for handling strategy events. Defaults to None. |
PromptGeneratorStrategyContext¶
Bases: StrategyContext, ABC
Base class for all prompt generator strategy contexts.
PromptGeneratorStrategyResult¶
Bases: StrategyResult, ABC
Base class for all prompt generator strategy results.