pyrit.prompt_normalizer.PromptNormalizer#

class PromptNormalizer(start_token: str = '⟪', end_token: str = '⟫')[source]#

Bases: ABC

__init__(start_token: str = '⟪', end_token: str = '⟫') None[source]#

Initializes the PromptNormalizer.

start_token and end_token are used to delineate which part of a prompt is converted.

Methods

__init__([start_token, end_token])

Initializes the PromptNormalizer.

convert_values(converter_configurations, ...)

send_prompt_async(*, seed_prompt_group, target)

Sends a single request to a target.

send_prompt_batch_to_target_async(*, ...[, ...])

Sends a batch of prompts to the target asynchronously.

async convert_values(converter_configurations: list[PromptConverterConfiguration], request_response: PromptRequestResponse)[source]#
async send_prompt_async(*, seed_prompt_group: SeedPromptGroup, target: PromptTarget, conversation_id: str = None, request_converter_configurations: list[PromptConverterConfiguration] = [], response_converter_configurations: list[PromptConverterConfiguration] = [], sequence: int = -1, labels: dict[str, str] | None = None, orchestrator_identifier: dict[str, str] | None = None) PromptRequestResponse[source]#

Sends a single request to a target.

Parameters:
  • seed_prompt_group (SeedPromptGroup) – The seed prompt group to be sent.

  • target (PromptTarget) – The target to which the prompt is sent.

  • conversation_id (str, optional) – The ID of the conversation. Defaults to None.

  • request_converter_configurations (list[PromptConverterConfiguration], optional) – Configurations for converting the request. Defaults to an empty list.

  • response_converter_configurations (list[PromptConverterConfiguration], optional) – Configurations for converting the response. Defaults to an empty list.

  • sequence (int, optional) – The sequence number of the request. Defaults to -1.

  • labels (Optional[dict[str, str]], optional) – Labels associated with the request. Defaults to None.

  • orchestrator_identifier (Optional[dict[str, str]], optional) – Identifier for the orchestrator. Defaults to None.

  • Raises

  • Exception – If an error occurs during the request processing.

Returns:

The response received from the target.

Return type:

PromptRequestResponse

async send_prompt_batch_to_target_async(*, requests: list[NormalizerRequest], target: PromptTarget, labels: dict[str, str] | None = None, orchestrator_identifier: dict[str, str] | None = None, batch_size: int = 10) list[PromptRequestResponse][source]#

Sends a batch of prompts to the target asynchronously.

Parameters:
  • requests (list[NormalizerRequest]) – A list of NormalizerRequest objects to be sent.

  • target (PromptTarget) – The target to which the prompts are sent.

  • labels (Optional[dict[str, str]], optional) – A dictionary of labels to be included with the request. Defaults to None.

  • orchestrator_identifier (Optional[dict[str, str]], optional) – A dictionary identifying the orchestrator. Defaults to None.

  • batch_size (int, optional) – The number of prompts to include in each batch. Defaults to 10.

Returns:

A list of PromptRequestResponse objects representing the responses

received for each prompt.

Return type:

list[PromptRequestResponse]