pyrit.models.PromptRequestPiece#
- class PromptRequestPiece(*, role: Literal['system', 'user', 'assistant'], original_value: str, original_value_sha256: str | None = None, converted_value: str | None = None, converted_value_sha256: str | None = None, id: str | UUID | None = None, conversation_id: str | None = None, sequence: int = -1, labels: Dict[str, str] | None = None, prompt_metadata: Dict[str, str | int] | None = None, converter_identifiers: List[Dict[str, str]] | None = None, prompt_target_identifier: Dict[str, str] | None = None, orchestrator_identifier: Dict[str, str] | None = None, scorer_identifier: Dict[str, str] | None = None, original_value_data_type: Literal['text', 'image_path', 'audio_path', 'video_path', 'url', 'error'] = 'text', converted_value_data_type: Literal['text', 'image_path', 'audio_path', 'video_path', 'url', 'error'] = 'text', response_error: Literal['blocked', 'none', 'processing', 'empty', 'unknown'] = 'none', originator: Literal['orchestrator', 'converter', 'undefined', 'scorer'] = 'undefined', original_prompt_id: UUID | None = None, timestamp: datetime | None = None, scores: List[Score] | None = None)[source]#
Bases:
object
Represents a piece of a prompt request to a target.
This class represents a single piece of a prompt request that will be sent to a target. Since some targets can handle multiple pieces (e.g., text and images), requests are composed of lists of PromptRequestPiece objects.
- __init__(*, role: Literal['system', 'user', 'assistant'], original_value: str, original_value_sha256: str | None = None, converted_value: str | None = None, converted_value_sha256: str | None = None, id: str | UUID | None = None, conversation_id: str | None = None, sequence: int = -1, labels: Dict[str, str] | None = None, prompt_metadata: Dict[str, str | int] | None = None, converter_identifiers: List[Dict[str, str]] | None = None, prompt_target_identifier: Dict[str, str] | None = None, orchestrator_identifier: Dict[str, str] | None = None, scorer_identifier: Dict[str, str] | None = None, original_value_data_type: Literal['text', 'image_path', 'audio_path', 'video_path', 'url', 'error'] = 'text', converted_value_data_type: Literal['text', 'image_path', 'audio_path', 'video_path', 'url', 'error'] = 'text', response_error: Literal['blocked', 'none', 'processing', 'empty', 'unknown'] = 'none', originator: Literal['orchestrator', 'converter', 'undefined', 'scorer'] = 'undefined', original_prompt_id: UUID | None = None, timestamp: datetime | None = None, scores: List[Score] | None = None)[source]#
Initialize a PromptRequestPiece.
- Parameters:
role – The role of the prompt (system, assistant, user).
original_value – The text of the original prompt. If prompt is an image, it’s a link.
original_value_sha256 – The SHA256 hash of the original prompt data. Defaults to None.
converted_value – The text of the converted prompt. If prompt is an image, it’s a link. Defaults to None.
converted_value_sha256 – The SHA256 hash of the converted prompt data. Defaults to None.
id – The unique identifier for the memory entry. Defaults to None (auto-generated).
conversation_id – The identifier for the conversation which is associated with a single target. Defaults to None.
sequence – The order of the conversation within a conversation_id. Defaults to -1.
labels – The labels associated with the memory entry. Several can be standardized. Defaults to None.
prompt_metadata – The metadata associated with the prompt. This can be specific to any scenarios. Because memory is how components talk with each other, this can be component specific. e.g. the URI from a file uploaded to a blob store, or a document type you want to upload. Defaults to None.
converter_identifiers – The converter identifiers for the prompt. Defaults to None.
prompt_target_identifier – The target identifier for the prompt. Defaults to None.
orchestrator_identifier – The orchestrator identifier for the prompt. Defaults to None.
scorer_identifier – The scorer identifier for the prompt. Defaults to None.
original_value_data_type – The data type of the original prompt (text, image). Defaults to “text”.
converted_value_data_type – The data type of the converted prompt (text, image). Defaults to “text”.
response_error – The response error type. Defaults to “none”.
originator – The originator of the prompt. Defaults to “undefined”.
original_prompt_id – The original prompt id. It is equal to id unless it is a duplicate. Defaults to None.
timestamp – The timestamp of the memory entry. Defaults to None (auto-generated).
scores – The scores associated with the prompt. Defaults to None.
Methods
__init__
(*, role, original_value[, ...])Initialize a PromptRequestPiece.
Check if the prompt request piece has an error.
Check if the prompt request piece is blocked.
This method computes the SHA256 hash values asynchronously.
to_dict
()- async set_sha256_values_async()[source]#
This method computes the SHA256 hash values asynchronously. It should be called after object creation if original_value and converted_value are set.
Note, this method is async due to the blob retrieval. And because of that, we opted to take it out of main and setter functions. The disadvantage is that it must be explicitly called.
- to_chat_message() ChatMessage [source]#
- to_prompt_request_response() PromptRequestResponse [source]#