pyrit.models.SeedPrompt#
- class SeedPrompt(value: str, value_sha256: str | None = None, data_type: ~typing.Literal['text', 'image_path', 'audio_path', 'video_path', 'url', 'error'] | None = None, id: ~uuid.UUID | None = <factory>, name: str | None = None, dataset_name: str | None = None, harm_categories: ~typing.Sequence[str] | None = <factory>, description: str | None = None, authors: ~typing.Sequence[str] | None = <factory>, groups: ~typing.Sequence[str] | None = <factory>, source: str | None = None, date_added: ~datetime.datetime | None = <factory>, added_by: str | None = None, metadata: ~typing.Dict[str, str | int] | None = <factory>, parameters: ~typing.Sequence[str] | None = <factory>, prompt_group_id: ~uuid.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__(value: str, value_sha256: str | None = None, data_type: ~typing.Literal['text', 'image_path', 'audio_path', 'video_path', 'url', 'error'] | None = None, id: ~uuid.UUID | None = <factory>, name: str | None = None, dataset_name: str | None = None, harm_categories: ~typing.Sequence[str] | None = <factory>, description: str | None = None, authors: ~typing.Sequence[str] | None = <factory>, groups: ~typing.Sequence[str] | None = <factory>, source: str | None = None, date_added: ~datetime.datetime | None = <factory>, added_by: str | None = None, metadata: ~typing.Dict[str, str | int] | None = <factory>, parameters: ~typing.Sequence[str] | None = <factory>, prompt_group_id: ~uuid.UUID | None = None, prompt_group_alias: str | None = None, sequence: int | None = 0) None #
Methods
__init__
(value[, value_sha256, data_type, ...])from_yaml_file
(file)Creates a new object from a YAML file.
from_yaml_with_required_parameters
(...[, ...])Load a SeedPrompt from a YAML file and validate that it contains specific parameters.
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.13/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.13/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.13/x64/lib/python3.11/site-packages'), 'pyrit_path': PosixPath('/opt/hostedtoolcache/Python/3.11.13/x64/lib/python3.11/site-packages/pyrit')}#
- classmethod from_yaml_with_required_parameters(template_path: str | Path, required_parameters: list[str], error_message: str | None = None) SeedPrompt [source]#
Load a SeedPrompt from a YAML file and validate that it contains specific parameters.
- Parameters:
template_path – Path to the YAML file containing the template.
required_parameters – List of parameter names that must exist in the template.
error_message – Custom error message if validation fails. If None, a default message is used.
- Returns:
The loaded and validated seed prompt.
- Return type:
- Raises:
ValueError – If the template doesn’t contain all required parameters.
- 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.