Base Classes

class afterimage.base.BaseGenerator[source]

Bases: object

Intended to serve as the base class for all generator classes

async ainitialize(instruction_generator_callback=None)[source]

Initializes the generator by creating the correspondent prompt if it doesn’t exist.

initialize(instruction_generator_callback=None)[source]

Initializes the generator by creating the correspondent prompt if it doesn’t exist.

load_conversations(limit: int | None = None, offset: int | None = None) list[EvaluatedConversationWithContext][source]
log_correspondent_prompt(correspondent_prompt: str | None) None[source]

Log the correspondent prompt in a standardized format.

Parameters:

correspondent_prompt – The correspondent prompt to log, or None if not set.

class afterimage.base.BaseInstructionGeneratorCallback[source]

Bases: object

Intended to serve as the base class for all custom instruction generator callbacks

async acall(original_prompt: str) GeneratedInstructions[source]
async acreate_correspondent_prompt(respondent_prompt: str) str[source]

Create a correspondent prompt based on the respondent prompt asynchronously.

This method can be overridden by subclasses to customize correspondent prompt creation. By default, returns None, which means the conversation generator should handle it.

Parameters:

respondent_prompt – The prompt for the respondent (assistant)

Returns:

The correspondent prompt, or None if the generator should handle it

Return type:

str

async agenerate(original_prompt) GeneratedInstructions[source]
create_correspondent_prompt(respondent_prompt: str) str | None[source]

Create a correspondent prompt based on the respondent prompt.

This method can be overridden by subclasses to customize correspondent prompt creation. By default, returns None, which means the conversation generator should handle it.

Parameters:

respondent_prompt – The prompt for the respondent (assistant)

Returns:

The correspondent prompt, or None if the generator should handle it

Return type:

str

generate(original_prompt) GeneratedInstructions[source]
class afterimage.base.BaseRespondentPromptModifierCallback[source]

Bases: object

Intended to serve as the base class for all custom respondent prompt modifier callbacks

async acall(respondent_prompt: str, context: str, instruction: str) GeneratedResponsePrompt[source]
async agenerate(respondent_prompt, context, instruction) GeneratedResponsePrompt[source]
generate(respondent_prompt, context, instruction) GeneratedResponsePrompt[source]
class afterimage.base.BaseStoppingCallback[source]

Bases: object

Base class for callbacks that decide when to stop generation.

async should_stop(state: GenerationState) bool[source]

Return True if generation should stop.

Parameters:

state – The current state of the generation process.