pyrit.chat_message_normalizer.GenericSystemSquash#

class GenericSystemSquash[source]#

Bases: ChatMessageNormalizer[list[ChatMessage]]

__init__()#

Methods

__init__()

combine_system_user_message(system_message, ...)

Combines the system message with the user message.

normalize(messages)

Returns the first system message combined with the first user message.

squash_system_message(messages, squash_function)

Combines the system message into the first user request.

static combine_system_user_message(system_message: ChatMessage, user_message: ChatMessage, msg_type: Literal['system', 'user', 'assistant'] = 'user') ChatMessage[source]#

Combines the system message with the user message.

Parameters:
  • system_message (str) – The system message.

  • user_message (str) – The user message.

  • msg_type (ChatMessageRole, optional) – The message type. Defaults to “user”.

Returns:

The combined message.

Return type:

ChatMessage

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

Returns the first system message combined with the first user message.

The format of the result uses generic instruction tags.

Parameters:

messages (list[ChatMessage]) – The list of messages to normalize.

Returns:

The normalized list of messages.

Return type:

list[ChatMessage]