pyrit.models.DataTypeSerializer#
- class DataTypeSerializer[source]#
Bases:
ABCAbstract base class for data type normalizers.
Responsible for reading and saving multi-modal data types to local disk or Azure Storage Account.
- __init__()#
Methods
__init__()Returns True if the data is stored on disk.
get_data_filename([file_name])Generates or retrieves a unique filename for the data file.
get_extension(file_path)Get the file extension from the file path.
get_mime_type(file_path)Get the MIME type of the file path.
Reads the data from the storage.
Reads the data from the storage.
save_b64_image(data[, output_filename])Saves the base64 encoded image to storage.
save_data(data[, output_filename])Saves the data to storage.
save_formatted_audio(data[, num_channels, ...])Saves the PCM16 of other specially formatted audio data to storage.
Attributes
- data_type: Literal['text', 'image_path', 'audio_path', 'video_path', 'url', 'reasoning', 'error', 'function_call', 'tool_call', 'function_call_output']#
- async get_data_filename(file_name: str | None = None) Path | str[source]#
Generates or retrieves a unique filename for the data file.
- async read_data() bytes[source]#
Reads the data from the storage.
- Returns:
The data read from storage.
- Return type:
- async save_b64_image(data: str, output_filename: str = None) None[source]#
Saves the base64 encoded image to storage.
- Parameters:
data – string with base64 data
output_filename (optional, str) – filename to store image as. Defaults to UUID if not provided
- async save_data(data: bytes, output_filename: str | None = None) None[source]#
Saves the data to storage.
- Parameters:
data – bytes: The data to be saved.
output_filename (optional, str) – filename to store data as. Defaults to UUID if not provided
- async save_formatted_audio(data: bytes, num_channels: int = 1, sample_width: int = 2, sample_rate: int = 16000, output_filename: str | None = None) None[source]#
Saves the PCM16 of other specially formatted audio data to storage.
- Parameters:
data – bytes with audio data
output_filename (optional, str) – filename to store audio as. Defaults to UUID if not provided
num_channels (optional, int) – number of channels in audio data. Defaults to 1
sample_width (optional, int) – sample width in bytes. Defaults to 2
sample_rate (optional, int) – sample rate in Hz. Defaults to 16000