pyrit.models.Message#
- class Message(message_pieces: Sequence[MessagePiece], *, skip_validation: bool | None = False)[source]#
Bases:
objectRepresents a message in a conversation, for example a prompt or a response to a prompt.
This is a single request to a target. It can contain multiple message pieces.
- Parameters:
message_pieces (Sequence[MessagePiece]) – The list of message pieces.
Methods
__init__(message_pieces, *[, skip_validation])flatten_to_message_pieces(messages)from_prompt(*, prompt, role)from_system_prompt(system_prompt)get_all_values(messages)Return all converted values across the provided messages.
get_piece([n])Return the nth message piece.
get_value([n])Return the converted value of the nth message piece.
Return the converted values of all message pieces.
is_error()Returns True if any of the message pieces have an error response.
Set that the prompt is not in the database.
validate()Validates the request response.
Attributes
Return the conversation ID of the first request piece (they should all be the same).
Return the role of the first request piece (they should all be the same).
Return the sequence of the first request piece (they should all be the same).
- property conversation_id: str#
Return the conversation ID of the first request piece (they should all be the same).
- static flatten_to_message_pieces(messages: Sequence[Message]) MutableSequence[MessagePiece][source]#
- classmethod from_prompt(*, prompt: str, role: Literal['system', 'user', 'assistant', 'tool', 'developer']) Message[source]#
- static get_all_values(messages: Sequence[Message]) list[str][source]#
Return all converted values across the provided messages.
- get_piece(n: int = 0) MessagePiece[source]#
Return the nth message piece.
- property role: Literal['system', 'user', 'assistant', 'tool', 'developer']#
Return the role of the first request piece (they should all be the same).
- property sequence: int#
Return the sequence of the first request piece (they should all be the same).