pyrit.models.group_conversation_request_pieces_by_sequence#
- group_conversation_request_pieces_by_sequence(request_pieces: Sequence[PromptRequestPiece]) MutableSequence[PromptRequestResponse] [source]#
Groups prompt request pieces from the same conversation into PromptRequestResponses.
This is done using the sequence number and conversation ID.
- Parameters:
request_pieces (Sequence[PromptRequestPiece]) – A list of PromptRequestPiece objects representing individual request pieces.
- Returns:
- A list of PromptRequestResponse objects representing grouped request
pieces. This is ordered by the sequence number
- Return type:
MutableSequence[PromptRequestResponse]
- Raises:
ValueError – If the conversation ID of any request piece does not match the conversation ID of the first
request piece. –
Example: >>> request_pieces = [ >>> PromptRequestPiece(conversation_id=1, sequence=1, text=”Hello”), >>> PromptRequestPiece(conversation_id=1, sequence=2, text=”How are you?”), >>> PromptRequestPiece(conversation_id=1, sequence=1, text=”Hi”), >>> PromptRequestPiece(conversation_id=1, sequence=2, text=”I’m good, thanks!”) >>> ] >>> grouped_responses = group_conversation_request_pieces(request_pieces) … [ … PromptRequestResponse(request_pieces=[ … PromptRequestPiece(conversation_id=1, sequence=1, text=”Hello”), … PromptRequestPiece(conversation_id=1, sequence=1, text=”Hi”) … ]), … PromptRequestResponse(request_pieces=[ … PromptRequestPiece(conversation_id=1, sequence=2, text=”How are you?”), … PromptRequestPiece(conversation_id=1, sequence=2, text=”I’m good, thanks!”) … ]) … ]