pyrit.models.Seed#

class Seed(value: str, value_sha256: str | None = None, data_type: ~typing.Literal['text', 'image_path', 'audio_path', 'video_path', 'url', 'reasoning', 'error', 'function_call', 'tool_call', 'function_call_output'] | 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>, prompt_group_id: ~uuid.UUID | None = None, prompt_group_alias: str | None = None)[source]#

Bases: YamlLoadable

Represents seed data 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', 'reasoning', 'error', 'function_call', 'tool_call', 'function_call_output'] | 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>, prompt_group_id: ~uuid.UUID | None = None, prompt_group_alias: str | None = None) None#

Methods

__init__(value[, value_sha256, data_type, ...])

from_yaml_file(file)

Create a new object from a YAML file.

from_yaml_with_required_parameters(...[, ...])

Load a Seed 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.

set_encoding_metadata()

This method sets the encoding data for the prompt within metadata dictionary.

set_sha256_value_async()

This method computes the SHA256 hash value asynchronously.

Attributes

added_by: str | None = None#
authors: Sequence[str] | None#
data_type: Literal['text', 'image_path', 'audio_path', 'video_path', 'url', 'reasoning', 'error', 'function_call', 'tool_call', 'function_call_output'] | None = None#
dataset_name: str | None = None#
date_added: datetime | None#
description: str | None = None#
abstract classmethod from_yaml_with_required_parameters(template_path: str | Path, required_parameters: list[str], error_message: str | None = None) Seed[source]#

Load a Seed 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 of the specific subclass type.

Return type:

Seed

groups: Sequence[str] | None#
harm_categories: Sequence[str] | None#
id: UUID | None#
metadata: Dict[str, str | int] | None#
name: str | None = None#
prompt_group_alias: str | None = None#
prompt_group_id: UUID | None = None#
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.

abstract 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.

source: str | None = None#
value: str#
value_sha256: str | None = None#