pyrit.prompt_target.OpenAISoraTarget#

class OpenAISoraTarget(*, resolution_dimensions: Literal['360x360', '640x360', '480x480', '854x480', '720x720', '1280x720', '1080x1080', '1920x1080'] | None = None, n_seconds: int | None = None, n_variants: int | None = None, api_version: str | None = None, output_filename: str | None = None, **kwargs)[source]#

Bases: OpenAITarget

OpenAI Sora Target class for sending prompts to the OpenAI Sora API.

__init__(*, resolution_dimensions: Literal['360x360', '640x360', '480x480', '854x480', '720x720', '1280x720', '1080x1080', '1920x1080'] | None = None, n_seconds: int | None = None, n_variants: int | None = None, api_version: str | None = None, output_filename: str | None = None, **kwargs)[source]#

Initialize the OpenAI Sora Target.

Parameters:
  • model_name (str, Optional) – The name of the model.

  • endpoint (str, Optional) – The target URL for the OpenAI service.

  • api_key (str, Optional) – The API key for accessing the Azure OpenAI service. Defaults to the OPENAI_SORA_KEY environment variable.

  • headers (str, Optional) – Extra headers of the endpoint (JSON).

  • use_aad_auth (bool, Optional) – When set to True, user authentication is used instead of API Key. DefaultAzureCredential is taken for https://cognitiveservices.azure.com/.default. Please run az login locally to leverage user AuthN.

  • api_version (str, Optional) – The version of the Azure OpenAI API. Defaults to “preview”.

  • max_requests_per_minute (int, Optional) – Number of requests the target can handle per minute before hitting a rate limit. The number of requests sent to the target will be capped at the value provided.

  • httpx_client_kwargs (dict, Optional) – Additional kwargs to be passed to the httpx.AsyncClient() constructor.

  • resolution_dimensions (Literal, Optional) – Resolution dimensions for the video. Defaults to “480x480”, where the first value is width and the second is height.

  • n_seconds (int, Optional) – The duration of the generated video (in seconds). Defaults to 5. Sora API will support duration up to 20s. For 1080p, maximum duration is 10s.

  • n_variants (int, Optional) – The number of generated videos. Defaults to 1. Sora API will support up to 2 variants for resolutions of 720p, but only 1 for resolutions of 1080p.

  • output_filename (str, Optional) – The name of the output file for the generated video. Note: DO NOT SET if using target with PromptSendingOrchestrator. The default filename is {job_id}_{generation_id}.mp4 as returned by the model.

Raises:

ValueError – If video constraints are not met for the specified resolution.

Methods

__init__(*[, resolution_dimensions, ...])

Initialize the OpenAI Sora Target.

check_job_status_async(job_id)

Asynchronously check status of a submitted video generation job using the job_id.

dispose_db_engine()

Dispose DuckDB database engine to release database connections and resources.

download_video_content_async(generation_id)

Asynchronously download the video using the video generation ID.

get_identifier()

is_json_response_supported()

Indicates that this target supports JSON response format.

is_response_format_json(request_piece)

Checks if the response format is JSON and ensures the target supports it.

refresh_auth_headers()

Refresh the authentication headers.

send_prompt_async(**kwargs)

Sends a normalized prompt async to the prompt target.

set_system_prompt(*, system_prompt, ...[, ...])

Sets the system prompt for the prompt target.

Attributes

ADDITIONAL_REQUEST_HEADERS

CHECK_JOB_RETRY_MAX_NUM_ATTEMPTS

DEFAULT_API_VERSION

DEFAULT_N_SECONDS

DEFAULT_N_VARIANTS

DEFAULT_RESOLUTION_DIMENSIONS

model_name_environment_variable

endpoint_environment_variable

api_key_environment_variable

supported_converters

CHECK_JOB_RETRY_MAX_NUM_ATTEMPTS: int = 25#
DEFAULT_API_VERSION: str = 'preview'#
DEFAULT_N_SECONDS: int = 5#
DEFAULT_N_VARIANTS: int = 1#
DEFAULT_RESOLUTION_DIMENSIONS: str = '480x480'#
async check_job_status_async(job_id: str) Response[source]#

Asynchronously check status of a submitted video generation job using the job_id.

Retries a maxium of {self.CHECK_JOB_RETRY_MAX_NUM_ATTEMPTS} times, until the job is complete (succeeded, failed, or cancelled). Also retries upon RateLimitException.

Parameters:

job_id (str) – The ID of the job to check.

Returns:

The response from the API.

Return type:

httpx.Response

Raises:
  • RateLimitException – If the rate limit is exceeded.

  • httpx.HTTPStatusError – If the request fails.

async download_video_content_async(generation_id: str) Response[source]#

Asynchronously download the video using the video generation ID.

Retries if the response status code is not 200. Also retries upon RateLimitException.

Parameters:

generation_id (str) – The ID of the video generation to download.

Returns:

The response from the API.

Return type:

httpx.Response

Raises:
  • RateLimitException – If the rate limit is exceeded.

  • httpx.HTTPStatusError – If the request fails.

is_json_response_supported() bool[source]#

Indicates that this target supports JSON response format.

async send_prompt_async(**kwargs)#

Sends a normalized prompt async to the prompt target.