pyrit.chat_message_normalizer.ChatMessageNormalizer#

class ChatMessageNormalizer[source]#

Bases: ABC, Generic[T]

Abstract base class for normalizing chat messages for model or target compatibility.

__init__()#

Methods

__init__()

normalize(messages)

Normalize the list of chat messages into a compatible format for the model or target.

squash_system_message(messages, squash_function)

Combine the system message into the first user request.

abstract normalize(messages: list[ChatMessage]) T[source]#

Normalize the list of chat messages into a compatible format for the model or target.

static squash_system_message(messages: list[ChatMessage], squash_function) list[ChatMessage][source]#

Combine the system message into the first user request.

Parameters:
  • messages – The list of chat messages.

  • squash_function – The function to combine the system message with the user message.

Returns:

The list of chat messages with squashed system messages.

Raises:

ValueError – If the chat message list is empty.