Respondent Prompt Modifiers

class afterimage.WithContextRespondentPromptModifier(prompt_template: str | None = None)[source]

Bases: BaseRespondentPromptModifierCallback

Modifies respondent prompt by adding context.

Parameters:

prompt_template – Custom prompt template. If None, uses default_respondent_prompt_with_context. If it contains {prompt} and/or {context}, they will be replaced by the respondent prompt and the context, respectively.

async agenerate(respondent_prompt: str, context: str, instruction: str) GeneratedResponsePrompt[source]

Generates a modified respondent prompt by injecting context and instructions asynchronously.

generate(respondent_prompt: str, context: str, instruction: str) GeneratedResponsePrompt[source]

Generates a modified respondent prompt by injecting context and instructions.

Parameters:
  • respondent_prompt – The original prompt for the respondent

  • context – Additional context to be included

  • instruction – The instruction associated with the prompt

Returns:

GeneratedResponsePrompt containing the modified prompt and context

class afterimage.WithRAGRespondentPromptModifier(retriever: ContextRetriever, prompt_template: str | None = None)[source]

Bases: WithContextRespondentPromptModifier

Modifies respondent prompt by adding relevant context using a retrieval strategy.

Parameters:
  • retriever – Strategy for retrieving relevant context

  • prompt_template – Custom prompt template. If None, uses default_rag_respondent_prompt_with_context.

augment_context(instruction: str, current_context: str) str[source]

Augment existing context with relevant information using the retriever.

Parameters:
  • instruction – The current instruction/question

  • current_context – Any existing context

Returns:

Combined context from both sources

Return type:

str

async augment_context_async(instruction: str, current_context: str) str[source]

Async RAG augmentation; prefers retriever.aget_context when defined.