Stopping Callbacks

class afterimage.FixedNumberStoppingCallback(n: int)[source]

Bases: BaseStoppingCallback

Stops after generating a fixed number of samples.

async should_stop(state: GenerationState) bool[source]

Return True if generation should stop.

Parameters:

state – The current state of the generation process.

class afterimage.PersonaUsageStoppingCallback(n_personas: int)[source]

Bases: BaseStoppingCallback

Stops after N unique personas have been utilized.

async should_stop(state: GenerationState) bool[source]

Return True if generation should stop.

Parameters:

state – The current state of the generation process.

class afterimage.ContextCoverageStoppingCallback(provider: DocumentProvider, target_visits: int = 1, coverage_threshold: float = 1.0)[source]

Bases: BaseStoppingCallback

Stops after all (or a percentage of) contexts have been used N times.

async should_stop(state: GenerationState) bool[source]

Return True if generation should stop.

Parameters:

state – The current state of the generation process.

class afterimage.BudgetStoppingCallback(max_prompt_tokens: int | None = None, max_completion_tokens: int | None = None, max_total_tokens: int | None = None)[source]

Bases: BaseStoppingCallback

Stops when token usage exceeds a threshold.

Parameters:
  • max_prompt_tokens – Maximum number of prompt tokens to use.

  • max_completion_tokens – Maximum number of completion tokens to use.

  • max_total_tokens – Maximum number of total tokens to use.

async should_stop(state: GenerationState) bool[source]

Return True if generation should stop.

Parameters:

state – The current state of the generation process.

class afterimage.RateLimitStoppingCallback(max_error_rate: float = 0.5, min_samples: int = 10)[source]

Bases: BaseStoppingCallback

Stops if error rate exceeds a threshold.

async should_stop(state: GenerationState) bool[source]

Return True if generation should stop.

Parameters:

state – The current state of the generation process.