o
    ۷i                     @   sv   d Z ddlmZ ddlmZ ddlmZmZmZ G dd de	eZ
G dd deZG d	d
 d
eZG dd deZdS )z
OpenAI-compatible protocol definitions for image generation.

This module provides Pydantic models that follow the OpenAI DALL-E API specification
for text-to-image generation, with vllm-omni specific extensions.
    )Enum)Any)	BaseModelFieldfield_validatorc                   @   s   e Zd ZdZdZdZdS )ResponseFormatzImage response formatb64_jsonurlN)__name__
__module____qualname____doc__B64_JSONURL r   r   b/home/ubuntu/vllm_env/lib/python3.10/site-packages/vllm_omni/entrypoints/openai/protocol/images.pyr      s    r   c                   @   s  e Zd ZU dZedddZeed< edddZedB ed	< ed
d
dddZ	e
ed< edddZedB ed< eejddZeed< edddZedB ed< ededd Zededd ZedddZedB ed< edd
dddZe
dB ed< edddd dZedB ed!< edddd"dZedB ed#< edd$dZe
dB ed%< edd&dZedB ed'< edd(dZeeef dB ed)< ed*d+dZedB ed,< ed*d-dZ edB ed.< dS )/ImageGenerationRequestz
    OpenAI DALL-E compatible image generation request.

    Follows the OpenAI Images API specification with vllm-omni extensions
    for advanced diffusion parameters.
    .z(Text description of the desired image(s)descriptionpromptNzBModel to use (optional, uses server's configured model if omitted)defaultr   model   
   zNumber of images to generate)r   geler   nz[Image dimensions in WIDTHxHEIGHT format (e.g., '1024x1024', uses model defaults if omitted)sizezFormat of the returned imageresponse_formatzUser identifier for trackinguserc                 C   s*   |du rdS t |trd|vrtd|S )zValidate size parameter.

        Accepts any string in 'WIDTHxHEIGHT' format (e.g., '1024x1024', '512x768').
        No restrictions on specific dimensions - models can handle arbitrary sizes.
        Nxz9size must be in format 'WIDTHxHEIGHT' (e.g., '1024x1024'))
isinstancestr
ValueErrorclsvr   r   r   validate_size/   s
   z$ImageGenerationRequest.validate_sizec                 C   s$   |dur|t jkrtd| |S )z6Validate response format - only b64_json is supported.Nz3Only 'b64_json' response format is supported, got: )r   r   r$   r%   r   r   r   validate_response_format>   s   z/ImageGenerationRequest.validate_response_formatz*Text describing what to avoid in the imagenegative_prompt   zINumber of diffusion sampling steps (uses model defaults if not specified)num_inference_stepsg        g      4@zEClassifier-free guidance scale (uses model defaults if not specified)guidance_scalezJTrue CFG scale (model-specific parameter, may be ignored if not supported)true_cfg_scalezRandom seed for reproducibilityseedz\Device for the seeded torch.Generator (e.g. 'cpu', 'cuda'). Defaults to the runner's device.generator_devicezOptional LoRA adapter for this request. Expected shape: {name/path/scale/int_id}. Field names are flexible (e.g. name|lora_name|adapter, path|lora_path|local_path, scale|lora_scale, int_id|lora_int_id).loraFzEnable VAE slicingvae_use_slicingzEnable VAE tilingvae_use_tiling)!r
   r   r   r   r   r   r#   __annotations__r   r   intr   r   r   r   r    r   classmethodr(   r)   r*   r,   r-   floatr.   r/   r0   r1   dictr   r2   boolr3   r   r   r   r   r      sd   
 r   c                   @   sZ   e Zd ZU dZedddZedB ed< edddZedB ed< edddZ	edB ed	< dS )
	ImageDatazSingle generated image dataNzBase64-encoded PNG imager   r   zImage URL (not implemented)r	   z2Revised prompt (OpenAI compatibility, always null)revised_prompt)
r
   r   r   r   r   r   r#   r4   r	   r;   r   r   r   r   r:   q   s
   
 r:   c                   @   sf   e Zd ZU dZedddZeed< edddZe	e
 ed< edd	dZeed
< edddZeed< dS )ImageGenerationResponsezj
    OpenAI DALL-E compatible image generation response.

    Returns generated images with metadata.
    .z/Unix timestamp of when the generation completedr   createdzArray of generated imagesdataNz)The output format of the image generationoutput_formatzThe size of the image generatedr   )r
   r   r   r   r   r=   r5   r4   r>   listr:   r?   r#   r   r   r   r   r   r<   y   s   
 r<   N)r   enumr   typingr   pydanticr   r   r   r#   r   r   r:   r<   r   r   r   r   <module>   s   Z