pyrit.models.SeedPrompt#
- class SeedPrompt(*, id: UUID | None = None, value: str, value_sha256: str | None = None, data_type: Literal['text', 'image_path', 'audio_path', 'video_path', 'url', 'error'], name: str | None = None, dataset_name: str | None = None, harm_categories: Sequence[str] | None = None, description: str | None = None, authors: Sequence[str] | None = None, groups: Sequence[str] | None = None, source: str | None = None, date_added: datetime | None = datetime.datetime(2025, 3, 9, 14, 23, 32, 285400), added_by: str | None = None, metadata: Dict[str, str | int] | None = None, parameters: Sequence[str] | None = None, prompt_group_id: UUID | None = None, prompt_group_alias: str | None = None, sequence: int | None = 0)[source]#
Bases:
YamlLoadable
Represents a seed prompt with various attributes and metadata.
- __init__(*, id: UUID | None = None, value: str, value_sha256: str | None = None, data_type: Literal['text', 'image_path', 'audio_path', 'video_path', 'url', 'error'], name: str | None = None, dataset_name: str | None = None, harm_categories: Sequence[str] | None = None, description: str | None = None, authors: Sequence[str] | None = None, groups: Sequence[str] | None = None, source: str | None = None, date_added: datetime | None = datetime.datetime(2025, 3, 9, 14, 23, 32, 285400), added_by: str | None = None, metadata: Dict[str, str | int] | None = None, parameters: Sequence[str] | None = None, prompt_group_id: UUID | None = None, prompt_group_alias: str | None = None, sequence: int | None = 0)[source]#
Methods
__init__
(*[, id, value_sha256, name, ...])from_yaml_file
(file)Creates a new object from a YAML file.
render_template_value
(**kwargs)Renders self.value as a template, applying provided parameters in kwargs
render_template_value_silent
(**kwargs)Renders self.value as a template, applying provided parameters in kwargs. For parameters in the template
This method sets the encoding data for the prompt within metadata dictionary.
This method computes the SHA256 hash value asynchronously.
Attributes
- TEMPLATE_PATHS = {'datasets_path': PosixPath('/opt/hostedtoolcache/Python/3.11.11/x64/lib/python3.11/site-packages/pyrit/datasets'), 'db_data_path': PosixPath('/home/runner/.local/share/dbdata'), 'docs_code_path': PosixPath('/opt/hostedtoolcache/Python/3.11.11/x64/lib/python3.11/site-packages/doc/code'), 'log_path': PosixPath('/home/runner/.local/share/dbdata/logs.txt'), 'pyrit_home_path': PosixPath('/opt/hostedtoolcache/Python/3.11.11/x64/lib/python3.11/site-packages'), 'pyrit_path': PosixPath('/opt/hostedtoolcache/Python/3.11.11/x64/lib/python3.11/site-packages/pyrit')}#
- render_template_value(**kwargs) str [source]#
Renders self.value as a template, applying provided parameters in kwargs
- Parameters:
kwargs – Key-value pairs to replace in the SeedPrompt value.
- Returns:
A new prompt with the parameters applied.
- Raises:
ValueError – If parameters are missing or invalid in the template.
- render_template_value_silent(**kwargs) str [source]#
- Renders self.value as a template, applying provided parameters in kwargs. For parameters in the template
that are not provided as kwargs here, this function will leave them as is instead of raising an error.
- Parameters:
kwargs – Key-value pairs to replace in the SeedPrompt value.
- Returns:
A new prompt with the parameters applied.
- Raises:
ValueError – If parameters are missing or invalid in the template.
- set_encoding_metadata()[source]#
This method sets the encoding data for the prompt within metadata dictionary. For images, this is just the file format. For audio and video, this also includes bitrate (kBits/s as int), samplerate (samples/second as int), bitdepth (as int), filesize (bytes as int), and duration (seconds as int) if the file type is supported by TinyTag. Example suppported file types include: MP3, MP4, M4A, and WAV.
- async set_sha256_value_async()[source]#
This method computes the SHA256 hash value asynchronously. It should be called after prompt value is serialized to text, as file paths used in the value may have changed from local to memory storage paths.
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.