o
    #`^h"d                     @  sD  d dl mZ d dlmZmZmZmZ d dlmZ d dl	Z	ddl
mZ ddlmZmZmZ ddlmZmZmZmZmZmZ dd	lmZmZmZmZ dd
lmZ ddlmZm Z  ddl!m"Z"m#Z# ddl$m%Z% ddl&m'Z' ddl(m)Z) ddgZ*G dd deZ+G dd de Z,G dd dZ-G dd dZ.G dd dZ/G dd dZ0dS )    )annotations)UnionMappingOptionalcast)LiteralN   )_legacy_response)image_edit_paramsimage_generate_paramsimage_create_variation_params)	NOT_GIVENBodyQueryHeadersNotGiven	FileTypes)extract_filesmaybe_transformdeepcopy_minimalasync_maybe_transform)cached_property)SyncAPIResourceAsyncAPIResource)to_streamed_response_wrapper"async_to_streamed_response_wrapper)make_request_options)
ImageModel)ImagesResponseImagesAsyncImagesc                   @     e Zd Zed0ddZed1ddZeeeeeddded		d2dd Zeeeeeeddded!
d3d&d'Zeeeeeeeddded(d4d.d/Z	dS )5r   returnImagesWithRawResponsec                 C     t | S a  
        This property can be used as a prefix for any HTTP method call to return the
        the raw response object instead of the parsed content.

        For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
        )r#   self r(   U/home/air/shanriGPT/back/venv/lib/python3.10/site-packages/openai/resources/images.pywith_raw_response      zImages.with_raw_responseImagesWithStreamingResponsec                 C  r$   z
        An alternative to `.with_raw_response` that doesn't eagerly read the response body.

        For more information, see https://www.github.com/openai/openai-python#with_streaming_response
        )r,   r&   r(   r(   r)   with_streaming_response(      zImages.with_streaming_responseN	modelnresponse_formatsizeuserextra_headersextra_query
extra_bodytimeoutimager   r1   'Union[str, ImageModel, None] | NotGivenr2   Optional[int] | NotGivenr3   /Optional[Literal['url', 'b64_json']] | NotGivenr4   ?Optional[Literal['256x256', '512x512', '1024x1024']] | NotGivenr5   str | NotGivenr6   Headers | Noner7   Query | Noner8   Body | Noner9   'float | httpx.Timeout | None | NotGivenr   c       
      
   C  sl   t ||||||d}tttttf |dggd}ddi|p i }| jdt|tj	|t
|||	|
dtdS )	  
        Creates a variation of a given image.

        Args:
          image: The image to use as the basis for the variation(s). Must be a valid PNG file,
              less than 4MB, and square.

          model: The model to use for image generation. Only `dall-e-2` is supported at this
              time.

          n: The number of images to generate. Must be between 1 and 10. For `dall-e-3`, only
              `n=1` is supported.

          response_format: The format in which the generated images are returned. Must be one of `url` or
              `b64_json`. URLs are only valid for 60 minutes after the image has been
              generated.

          size: The size of the generated images. Must be one of `256x256`, `512x512`, or
              `1024x1024`.

          user: A unique identifier representing your end-user, which can help OpenAI to monitor
              and detect abuse.
              [Learn more](https://platform.openai.com/docs/guides/safety-best-practices/end-user-ids).

          extra_headers: Send extra headers

          extra_query: Add additional query parameters to the request

          extra_body: Add additional JSON properties to the request

          timeout: Override the client-level default timeout for this request, in seconds
        r:   r1   r2   r3   r4   r5   r:   pathsContent-Typemultipart/form-data/images/variationsr6   r7   r8   r9   bodyfilesoptionscast_to)r   r   r   r   strobject_postr   r   ImageCreateVariationParamsr   r   r'   r:   r1   r2   r3   r4   r5   r6   r7   r8   r9   rM   rN   r(   r(   r)   create_variation1   s(   0

zImages.create_variation
maskr1   r2   r3   r4   r5   r6   r7   r8   r9   promptrQ   rX   FileTypes | NotGivenc             
   C  st   t ||||||||d}tttttf |dgdggd}ddi|	p$i }	| jdt|tj	|t
|	|
||dtd	S )
  
        Creates an edited or extended image given an original image and a prompt.

        Args:
          image: The image to edit. Must be a valid PNG file, less than 4MB, and square. If mask
              is not provided, image must have transparency, which will be used as the mask.

          prompt: A text description of the desired image(s). The maximum length is 1000
              characters.

          mask: An additional image whose fully transparent areas (e.g. where alpha is zero)
              indicate where `image` should be edited. Must be a valid PNG file, less than
              4MB, and have the same dimensions as `image`.

          model: The model to use for image generation. Only `dall-e-2` is supported at this
              time.

          n: The number of images to generate. Must be between 1 and 10.

          response_format: The format in which the generated images are returned. Must be one of `url` or
              `b64_json`. URLs are only valid for 60 minutes after the image has been
              generated.

          size: The size of the generated images. Must be one of `256x256`, `512x512`, or
              `1024x1024`.

          user: A unique identifier representing your end-user, which can help OpenAI to monitor
              and detect abuse.
              [Learn more](https://platform.openai.com/docs/guides/safety-best-practices/end-user-ids).

          extra_headers: Send extra headers

          extra_query: Add additional query parameters to the request

          extra_body: Add additional JSON properties to the request

          timeout: Override the client-level default timeout for this request, in seconds
        r:   rY   rX   r1   r2   r3   r4   r5   r:   rX   rF   rH   rI   /images/editsrK   rL   )r   r   r   r   rQ   rR   rS   r   r
   ImageEditParamsr   r   r'   r:   rY   rX   r1   r2   r3   r4   r5   r6   r7   r8   r9   rM   rN   r(   r(   r)   editz   s,   8"
zImages.editr1   r2   qualityr3   r4   styler5   r6   r7   r8   r9   rb   $Literal['standard', 'hd'] | NotGivenYOptional[Literal['256x256', '512x512', '1024x1024', '1792x1024', '1024x1792']] | NotGivenrc   0Optional[Literal['vivid', 'natural']] | NotGivenc                C  s8   | j dt||||||||dtjt|	|
||dtdS )  
        Creates an image given a prompt.

        Args:
          prompt: A text description of the desired image(s). The maximum length is 1000
              characters for `dall-e-2` and 4000 characters for `dall-e-3`.

          model: The model to use for image generation.

          n: The number of images to generate. Must be between 1 and 10. For `dall-e-3`, only
              `n=1` is supported.

          quality: The quality of the image that will be generated. `hd` creates images with finer
              details and greater consistency across the image. This param is only supported
              for `dall-e-3`.

          response_format: The format in which the generated images are returned. Must be one of `url` or
              `b64_json`. URLs are only valid for 60 minutes after the image has been
              generated.

          size: The size of the generated images. Must be one of `256x256`, `512x512`, or
              `1024x1024` for `dall-e-2`. Must be one of `1024x1024`, `1792x1024`, or
              `1024x1792` for `dall-e-3` models.

          style: The style of the generated images. Must be one of `vivid` or `natural`. Vivid
              causes the model to lean towards generating hyper-real and dramatic images.
              Natural causes the model to produce more natural, less hyper-real looking
              images. This param is only supported for `dall-e-3`.

          user: A unique identifier representing your end-user, which can help OpenAI to monitor
              and detect abuse.
              [Learn more](https://platform.openai.com/docs/guides/safety-best-practices/end-user-ids).

          extra_headers: Send extra headers

          extra_query: Add additional query parameters to the request

          extra_body: Add additional JSON properties to the request

          timeout: Override the client-level default timeout for this request, in seconds
        /images/generationsrY   r1   r2   rb   r3   r4   rc   r5   rK   rM   rO   rP   )rS   r   r   ImageGenerateParamsr   r   r'   rY   r1   r2   rb   r3   r4   rc   r5   r6   r7   r8   r9   r(   r(   r)   generate   s&   ;
zImages.generate)r"   r#   )r"   r,   r:   r   r1   r;   r2   r<   r3   r=   r4   r>   r5   r?   r6   r@   r7   rA   r8   rB   r9   rC   r"   r   r:   r   rY   rQ   rX   rZ   r1   r;   r2   r<   r3   r=   r4   r>   r5   r?   r6   r@   r7   rA   r8   rB   r9   rC   r"   r   rY   rQ   r1   r;   r2   r<   rb   rd   r3   r=   r4   re   rc   rf   r5   r?   r6   r@   r7   rA   r8   rB   r9   rC   r"   r   
__name__
__module____qualname__r   r*   r.   r   rV   r`   rm   r(   r(   r(   r)   r      L    	NWc                   @  r!   )5r    r"   AsyncImagesWithRawResponsec                 C  r$   r%   )rv   r&   r(   r(   r)   r*     r+   zAsyncImages.with_raw_response AsyncImagesWithStreamingResponsec                 C  r$   r-   )rw   r&   r(   r(   r)   r.   )  r/   z#AsyncImages.with_streaming_responseNr0   r:   r   r1   r;   r2   r<   r3   r=   r4   r>   r5   r?   r6   r@   r7   rA   r8   rB   r9   rC   r   c       
      
     sz   t ||||||d}tttttf |dggd}ddi|p!i }| jdt|tj	I dH |t
|||	|
dtd	I dH S )
rD   rE   r:   rF   rH   rI   rJ   NrK   rL   )r   r   r   r   rQ   rR   rS   r   r   rT   r   r   rU   r(   r(   r)   rV   2  s*   0
zAsyncImages.create_variationrW   rY   rQ   rX   rZ   c             
     s   t ||||||||d}tttttf |dgdggd}ddi|	p%i }	| jdt|tj	I dH |t
|	|
||d	td
I dH S )r[   r\   r:   rX   rF   rH   rI   r]   NrK   rL   )r   r   r   r   rQ   rR   rS   r   r
   r^   r   r   r_   r(   r(   r)   r`   {  s.   8"zAsyncImages.editra   rb   rd   re   rc   rf   c                  sF   | j dt||||||||dtjI dH t|	|
||dtdI dH S )rg   rh   ri   NrK   rj   )rS   r   r   rk   r   r   rl   r(   r(   r)   rm     s(   ;
zAsyncImages.generate)r"   rv   )r"   rw   rn   ro   rp   rq   r(   r(   r(   r)   r      ru   c                   @     e Zd ZdddZdS )	r#   imagesr   r"   Nonec                 C  4   || _ t|j| _t|j| _t|j| _d S N)_imagesr	   to_raw_response_wrapperrV   r`   rm   r'   ry   r(   r(   r)   __init__      
zImagesWithRawResponse.__init__Nry   r   r"   rz   rr   rs   rt   r   r(   r(   r(   r)   r#         r#   c                   @  rx   )	rv   ry   r    r"   rz   c                 C  r{   r|   )r}   r	   async_to_raw_response_wrapperrV   r`   rm   r   r(   r(   r)   r   /  r   z#AsyncImagesWithRawResponse.__init__Nry   r    r"   rz   r   r(   r(   r(   r)   rv   .  r   rv   c                   @  rx   )	r,   ry   r   r"   rz   c                 C  .   || _ t|j| _t|j| _t|j| _d S r|   )r}   r   rV   r`   rm   r   r(   r(   r)   r   >     
z$ImagesWithStreamingResponse.__init__Nr   r   r(   r(   r(   r)   r,   =  r   r,   c                   @  rx   )	rw   ry   r    r"   rz   c                 C  r   r|   )r}   r   rV   r`   rm   r   r(   r(   r)   r   M  r   z)AsyncImagesWithStreamingResponse.__init__Nr   r   r(   r(   r(   r)   rw   L  r   rw   )1
__future__r   typingr   r   r   r   typing_extensionsr   httpx r	   typesr
   r   r   _typesr   r   r   r   r   r   _utilsr   r   r   r   _compatr   	_resourcer   r   	_responser   r   _base_clientr   types.image_modelr   types.images_responser   __all__r   r    r#   rv   r,   rw   r(   r(   r(   r)   <module>   s2        