Source code for pyrit.prompt_normalizer.normalizer_request

# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.

import abc
from dataclasses import dataclass

from pyrit.models.seed_prompt import SeedPromptGroup
from pyrit.prompt_normalizer.prompt_converter_configuration import (
    PromptConverterConfiguration,
)


[docs] @dataclass class NormalizerRequest(abc.ABC): """ Represents a single request sent to normalizer. """ seed_prompt_group: SeedPromptGroup request_converter_configurations: list[PromptConverterConfiguration] response_converter_configurations: list[PromptConverterConfiguration] conversation_id: str
[docs] def __init__( self, *, seed_prompt_group: SeedPromptGroup, request_converter_configurations: list[PromptConverterConfiguration] = [], response_converter_configurations: list[PromptConverterConfiguration] = [], conversation_id: str = None, ): self.seed_prompt_group = seed_prompt_group self.request_converter_configurations = request_converter_configurations self.response_converter_configurations = response_converter_configurations self.conversation_id = conversation_id
[docs] def validate(self): if not self.seed_prompt_group or len(self.seed_prompt_group.prompts) < 1: raise ValueError("Seed prompt group must be provided.") if not self.seed_prompt_group.is_single_request(): raise ValueError("Sequence must be equal for every piece of a single normalizer request.")