
    gVa                       U d dl mZ d dlZd dlZd dlZd dlZd dlmZmZ d dl	m
Z
 d dlZd dlZddl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 dd
lmZmZmZmZmZ ddl 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Z0dZ1 ejd                  e3      Z4de5d<    G d de&      Z6 G d de'      Z7 G d d      Z8 G d d      Z9 G d d      Z: G d d       Z;y)!    )annotationsN)Listoverload)Path   )_legacy_response   )Parts
AsyncPartsPartsWithRawResponseAsyncPartsWithRawResponsePartsWithStreamingResponseAsyncPartsWithStreamingResponse)FilePurposeupload_create_paramsupload_complete_params)	NOT_GIVENBodyQueryHeadersNotGiven)maybe_transformasync_maybe_transform)cached_property)SyncAPIResourceAsyncAPIResource)to_streamed_response_wrapper"async_to_streamed_response_wrapper)make_request_options)Upload)r   UploadsAsyncUploadsi   zlogging.Loggerlogc                  v   e Zd Zedd       Zedd       Zedd       Zedded	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Z	eded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Z	ddded		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd
Z	ddded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ
ddded	 	 	 	 	 	 	 	 	 	 	 ddZeddded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZy)r!   c                ,    t        | j                        S N)r
   _clientselfs    U/var/www/openai/venv/lib/python3.12/site-packages/openai/resources/uploads/uploads.pypartszUploads.parts/   s    T\\""    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
        )UploadsWithRawResponser(   s    r*   with_raw_responsezUploads.with_raw_response3   s     &d++r,   c                    t        |       S 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
        )UploadsWithStreamingResponser(   s    r*   with_streaming_responsezUploads.with_streaming_response=   s     ,D11r,   Nbytes	part_sizemd5c                    yzESplits a file into multiple 64MB parts and uploads them sequentially.N r)   file	mime_typepurposer6   r7   r8   s          r*   upload_file_chunkedzUploads.upload_file_chunkedF       r,   r7   r8   c                    yzPSplits an in-memory file into multiple 64MB parts and uploads them sequentially.Nr;   r)   r=   filenamer6   r>   r?   r7   r8   s           r*   r@   zUploads.upload_file_chunkedS   rA   r,   rF   r6   r7   r8   c               >   t        |t        j                        r|t        d      |Pt        d      t        |t              st	        |      }|s|j
                  }||j                         j                  }| j                  ||||      }g }	|t        }t        |t        j                        rt        j                  |      }
nt        j                  |      }
	 	 |
j                  |      }|snn| j                  j                  |j                  |      }t         j#                  d|j                  |j                         |	j%                  |j                         	 | j+                  |j                  |	|      S # t&        $ r |
j)                           w xY w)"  Splits the given file into multiple parts and uploads them sequentially.

        ```py
        from pathlib import Path

        client.uploads.upload_file(
            file=Path("my-paper.pdf"),
            mime_type="pdf",
            purpose="assistants",
        )
        ```
        9The `filename` argument must be given for in-memory files6The `bytes` argument must be given for in-memory filesr6   rF   r>   r?   	upload_iddataUploaded part %s for upload %srN   part_idsr8   )
isinstancebuiltinsr6   	TypeErrorr   namestatst_sizecreateDEFAULT_PART_SIZEioBytesIOFileIOreadr+   idr#   infoappend	Exceptionclosecomplete)r)   r=   r>   r?   rF   r6   r7   r8   uploadrR   bufrO   parts                r*   r@   zUploads.upload_file_chunkeda   sh   . dHNN+ [\\} XYYdD)Dz99}		++	  
 !)IdHNN+*,**T*:C))D/C	xx	*zz((6994(H9477FIIN(   }}vyy8}MM	  	IIK	s   BF Fextra_headersextra_query
extra_bodytimeoutc          
         | j                  dt        ||||dt        j                        t	        ||||      t
              S )  
        Creates an intermediate
        [Upload](https://platform.openai.com/docs/api-reference/uploads/object) object
        that you can add
        [Parts](https://platform.openai.com/docs/api-reference/uploads/part-object) to.
        Currently, an Upload can accept at most 8 GB in total and expires after an hour
        after you create it.

        Once you complete the Upload, we will create a
        [File](https://platform.openai.com/docs/api-reference/files/object) object that
        contains all the parts you uploaded. This File is usable in the rest of our
        platform as a regular File object.

        For certain `purpose`s, the correct `mime_type` must be specified. Please refer
        to documentation for the supported MIME types for your use case:

        - [Assistants](https://platform.openai.com/docs/assistants/tools/file-search#supported-files)

        For guidance on the proper filename extensions for each purpose, please follow
        the documentation on
        [creating a File](https://platform.openai.com/docs/api-reference/files/create).

        Args:
          bytes: The number of bytes in the file you are uploading.

          filename: The name of the file to upload.

          mime_type: The MIME type of the file.

              This must fall within the supported MIME types for your file purpose. See the
              supported MIME types for assistants and vision.

          purpose: The intended purpose of the uploaded file.

              See the
              [documentation on File purposes](https://platform.openai.com/docs/api-reference/files/create#files-create-purpose).

          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
        /uploadsrL   rh   bodyoptionscast_to)_postr   r   UploadCreateParamsr   r    	r)   r6   rF   r>   r?   ri   rj   rk   rl   s	            r*   rY   zUploads.create   s\    v zz " (!*&	 %77 )+Q[el   
 	
r,   c          	     t    |st        d|      | j                  d| dt        ||||      t              S ){  Cancels the Upload.

        No Parts may be added after an Upload is cancelled.

        Args:
          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
        8Expected a non-empty value for `upload_id` but received 	/uploads//cancelrh   rr   rs   
ValueErrorrt   r   r    r)   rN   ri   rj   rk   rl   s         r*   cancelzUploads.cancel   sV    0 WXaWdeffzz	{'*(+Q[el   
 	
r,   r8   ri   rj   rk   rl   c          
         |st        d|      | j                  d| dt        ||dt        j                        t        ||||      t              S )L  
        Completes the
        [Upload](https://platform.openai.com/docs/api-reference/uploads/object).

        Within the returned Upload object, there is a nested
        [File](https://platform.openai.com/docs/api-reference/files/object) object that
        is ready to use in the rest of the platform.

        You can specify the order of the Parts by passing in an ordered list of the Part
        IDs.

        The number of bytes uploaded upon completion must match the number of bytes
        initially specified when creating the Upload object. No Parts may be added after
        an Upload is completed.

        Args:
          part_ids: The ordered list of Part IDs.

          md5: The optional md5 checksum for the file contents to verify if the bytes uploaded
              matches what you expect.

          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
        ry   rz   	/completerR   r8   rh   rp   )r~   rt   r   r   UploadCompleteParamsr   r    r)   rN   rR   r8   ri   rj   rk   rl   s           r*   rd   zUploads.complete  sw    T WXaWdeffzz	{),  ( ';; )+Q[el   
 	
r,   )returnr
   )r   r/   )r   r3   r=   zos.PathLike[str]r>   strr?   r   r6   
int | Noner7   r   r8   str | NotGivenr   r    r=   r6   rF   r   r6   intr>   r   r?   r   r7   r   r8   r   r   r    r=   zos.PathLike[str] | bytesr>   r   r?   r   rF   z
str | Noner6   r   r7   r   r8   r   r   r    r6   r   rF   r   r>   r   r?   r   ri   Headers | Nonerj   Query | Nonerk   Body | Nonerl   'float | httpx.Timeout | None | NotGivenr   r    rN   r   ri   r   rj   r   rk   r   rl   r   r   r    rN   r   rR   z	List[str]r8   r   ri   r   rj   r   rk   r   rl   r   r   r    __name__
__module____qualname__r   r+   r0   r4   r   r   r@   rY   r   rd   r;   r,   r*   r!   r!   .   s   # # , , 2 2  ! $'
T 
T 	
T
 
T 
T 
T 
T 

T 
T  !%'_ _ 	_
 _ _ _ _ _ 
_ _&  $  $'FN 'FN 	FN
 FN FN FN FN FN 
FNb )-$("&;DJ
 J
 	J

 J
 J
 &J
 "J
  J
 9J
 
J
d )-$("&;D 
 
 & 
 " 
   
 9 
 
 
N ( )-$("&;D9
9
 	9

 9
 &9
 "9
  9
 99
 
9
r,   c                  v   e Zd Zedd       Zedd       Zedd       Zedded	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Z	eded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Z	ddded		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd
Z	ddded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ
ddded	 	 	 	 	 	 	 	 	 	 	 ddZeddded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZy)r"   c                ,    t        | j                        S r&   )r   r'   r(   s    r*   r+   zAsyncUploads.partsT  s    $,,''r,   c                    t        |       S r.   )AsyncUploadsWithRawResponser(   s    r*   r0   zAsyncUploads.with_raw_responseX  s     +400r,   c                    t        |       S r2   )!AsyncUploadsWithStreamingResponser(   s    r*   r4   z$AsyncUploads.with_streaming_responseb  s     166r,   Nr5   c                  K   ywr:   r;   r<   s          r*   r@   z AsyncUploads.upload_file_chunkedk          rB   c                  K   ywrD   r;   rE   s           r*   r@   z AsyncUploads.upload_file_chunkedx  r   r   rG   c               p  K   t        |t        j                        r|t        d      |nt        d      t        |t        j
                        st	        j
                  |      }|s|j                  }|$|j                          d{   }|j                  }| j                  ||||       d{   }	g }
|t        }t        |t        j
                        r|j                  d       d{   }|4 d{    	 |j                  |       d{   }|snv| j                  j                  |	j                  |       d{   }t        j!                  d|j                  |	j                         |
j#                  |j                         ddd      d{    nt%        j&                  |      }	 	 |j                  |      }|snv| j                  j                  |	j                  |       d{   }t        j!                  d|j                  |	j                         |
j#                  |j                         	 | j-                  |	j                  |
|       d{   S 7 7 7 7 z7 c7 47 # 1 d{  7  sw Y   LxY w7 # t(        $ r |j+                           w xY w7 Mw)	rI   NrJ   rK   rL   rbrM   rP   rQ   )rS   rT   r6   rU   anyior   rV   rW   rX   rY   rZ   openr^   r+   r_   r#   r`   ra   r[   r\   rb   rc   rd   )r)   r=   r>   r?   rF   r6   r7   r8   rW   re   rR   fdrO   rg   rf   s                  r*   r@   z AsyncUploads.upload_file_chunked  s<    . dHNN+ [\\} XYYdEJJ/zz$'99}!YY[({{	 # 
 
 !)IdEJJ'yy&Br!#!33D!%!2!2VYYT!2!RRDHH=tww		ROODGG,  rr **T"C88I.D!%!2!2VYYT!2!RRDHH=tww		ROODGG,   ]]VYYs]SSSY )
 '3
 S rrr( S  		 Ts   BJ6	I+
(J62I.3<J6/I10
J6:I4;J6>I?I71I?I:AI?J6I=J69?J 8J9AJ "J6&J4'J6.J61J64J67I?:I?=J6?JJJJ6J J11J6rh   c          
        K   | j                  dt        ||||dt        j                         d{   t	        ||||      t
               d{   S 7 $7 w)rn   ro   rL   Nrh   rp   )rt   r   r   ru   r   r    rv   s	            r*   rY   zAsyncUploads.create  su     v ZZ," (!*&	 %77  )+Q[el    
 
 	

s!   /AA
AAAAc          	        K   |st        d|      | j                  d| dt        ||||      t               d{   S 7 w)rx   ry   rz   r{   rh   r|   Nr}   r   s         r*   r   zAsyncUploads.cancel%  sd     0 WXaWdeffZZ	{'*(+Q[el    
 
 	
 
s   =AA Ar   c          
        K   |st        d|      | j                  d| dt        ||dt        j                         d{   t        ||||      t               d{   S 7 $7 w)r   ry   rz   r   r   Nrh   rp   )r~   rt   r   r   r   r   r    r   s           r*   rd   zAsyncUploads.completeG  s     T WXaWdeffZZ	{),, ( ';;  )+Q[el    
 
 	

s$   AA,A(
A,#A*$A,*A,)r   r   )r   r   )r   r   r   r   r   r   r   r   r   r;   r,   r*   r"   r"   S  s   ( ( 1 1 7 7  ! $'
T 
T 	
T
 
T 
T 
T 
T 

T 
T  !%'_ _ 	_
 _ _ _ _ _ 
_ _&  $  $'QT 'QT 	QT
 QT QT QT QT QT 
QTx )-$("&;DJ
 J
 	J

 J
 J
 &J
 "J
  J
 9J
 
J
d )-$("&;D 
 
 & 
 " 
   
 9 
 
 
N ( )-$("&;D9
9
 	9

 9
 &9
 "9
  9
 99
 
9
r,   c                  &    e Zd ZddZedd       Zy)r/   c                    || _         t        j                  |j                        | _        t        j                  |j                        | _        t        j                  |j
                        | _        y r&   )_uploadsr   to_raw_response_wrapperrY   r   rd   r)   uploadss     r*   __init__zUploadsWithRawResponse.__init__  sZ    &>>NN
 '>>NN
 )@@
r,   c                @    t        | j                  j                        S r&   )r   r   r+   r(   s    r*   r+   zUploadsWithRawResponse.parts  s    #DMM$7$788r,   Nr   r!   r   None)r   r   r   r   r   r   r   r+   r;   r,   r*   r/   r/     s    
 9 9r,   r/   c                  &    e Zd ZddZedd       Zy)r   c                    || _         t        j                  |j                        | _        t        j                  |j                        | _        t        j                  |j
                        | _        y r&   )r   r   async_to_raw_response_wrapperrY   r   rd   r   s     r*   r   z$AsyncUploadsWithRawResponse.__init__  sZ    &DDNN
 'DDNN
 )FF
r,   c                @    t        | j                  j                        S r&   )r   r   r+   r(   s    r*   r+   z!AsyncUploadsWithRawResponse.parts  s    ()<)<==r,   Nr   r"   r   r   )r   r   r   r;   r,   r*   r   r     s    
 > >r,   r   c                  &    e Zd ZddZedd       Zy)r3   c                    || _         t        |j                        | _        t        |j                        | _        t        |j                        | _        y r&   )r   r   rY   r   rd   r   s     r*   r   z%UploadsWithStreamingResponse.__init__  sH    2NN
 3NN
 5
r,   c                @    t        | j                  j                        S r&   )r   r   r+   r(   s    r*   r+   z"UploadsWithStreamingResponse.parts  s    )$--*=*=>>r,   Nr   )r   r   r   r;   r,   r*   r3   r3     s    
 ? ?r,   r3   c                  &    e Zd ZddZedd       Zy)r   c                    || _         t        |j                        | _        t        |j                        | _        t        |j                        | _        y r&   )r   r   rY   r   rd   r   s     r*   r   z*AsyncUploadsWithStreamingResponse.__init__  sH    8NN
 9NN
 ;
r,   c                @    t        | j                  j                        S r&   )r   r   r+   r(   s    r*   r+   z'AsyncUploadsWithStreamingResponse.parts  s    .t}}/B/BCCr,   Nr   )r   r   r   r;   r,   r*   r   r     s    
 D Dr,   r   )<
__future__r   r[   osloggingrT   typingr   r   pathlibr   r   httpx r   r+   r
   r   r   r   r   r   typesr   r   r   _typesr   r   r   r   r   _utilsr   r   _compatr   	_resourcer   r   	_responser   r   _base_clientr   types.uploadr    types.file_purpose__all__rZ   	getLoggerr   r#   __annotations__r!   r"   r/   r   r3   r   r;   r,   r*   <module>r      s    # 	 	   !       O N ? ? ' : Y 0 " -n
% % 'g''1^ 1b
o b
J	m
# m
`	9 9&> >&? ?&D Dr,   