U
    hv                     @  s|  d dl m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	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"m#Z#m$Z$m%Z%m&Z& ddl'm(Z(m)Z) ddl*m+Z+m,Z, ddl-m.Z. ddl/m0Z0 ddl1mZ ddgZ2G dd deZ3G dd deZ4G dd dZ5G dd dZ6G dd dZ7G dd dZ8dS )    )annotationsN)Mappingcast)Literal   )_legacy_response)FilePurposefile_list_paramsfile_create_params)	NOT_GIVENBodyQueryHeadersNotGiven	FileTypes)extract_filesmaybe_transformdeepcopy_minimalasync_maybe_transform)cached_property)SyncAPIResourceAsyncAPIResource)StreamedBinaryAPIResponseAsyncStreamedBinaryAPIResponseto_streamed_response_wrapper"async_to_streamed_response_wrapper#to_custom_streamed_response_wrapper)async_to_custom_streamed_response_wrapper)SyncCursorPageAsyncCursorPage)AsyncPaginatormake_request_options)
FileObject)FileDeleted)r   Files
AsyncFilesc                   @  sB  e Zd ZeddddZeddddZeddded	d
ddddddddddZdddeddddddddddZeeeedddeddddddddddd	d d!Z	dddeddddddd"dd#d$Z
dddeddddddd%dd&d'Zed(dddeddddddddd)d*Zd+d,d-dd.d.dd/d0d1ZdS )2r$   FilesWithRawResponsereturnc                 C  s   t | S a  
        This property can be used as a prefix for any HTTP method call to return
        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,   :/tmp/pip-unpacked-wheel-dms8d3uv/openai/resources/files.pywith_raw_response$   s    zFiles.with_raw_responseFilesWithStreamingResponsec                 C  s   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
        )r/   r*   r,   r,   r-   with_streaming_response.   s    zFiles.with_streaming_responseNexpires_afterextra_headersextra_query
extra_bodytimeoutr   r   *file_create_params.ExpiresAfter | NotGivenHeaders | NoneQuery | NoneBody | None'float | httpx.Timeout | None | NotGivenr"   filepurposer3   r4   r5   r6   r7   r(   c          
   
   C  sf   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 )	  Upload a file that can be used across various endpoints.

        Individual files can be
        up to 512 MB, and the size of all files uploaded by one organization can be up
        to 1 TB.

        The Assistants API supports files up to 2 million tokens and of specific file
        types. See the
        [Assistants Tools guide](https://platform.openai.com/docs/assistants/tools) for
        details.

        The Fine-tuning API only supports `.jsonl` files. The input also has certain
        required formats for fine-tuning
        [chat](https://platform.openai.com/docs/api-reference/fine-tuning/chat-input) or
        [completions](https://platform.openai.com/docs/api-reference/fine-tuning/completions-input)
        models.

        The Batch API only supports `.jsonl` files up to 200 MB in size. The input also
        has a specific required
        [format](https://platform.openai.com/docs/api-reference/batch/request-input).

        Please [contact us](https://help.openai.com/) if you need to increase these
        storage limits.

        Args:
          file: The File object (not file name) to be uploaded.

          purpose: The intended purpose of the uploaded file. One of: - `assistants`: Used in the
              Assistants API - `batch`: Used in the Batch API - `fine-tune`: Used for
              fine-tuning - `vision`: Images used for vision fine-tuning - `user_data`:
              Flexible file type for any purpose - `evals`: Used for eval data sets

          expires_after: The expiration policy for a file. By default, files with `purpose=batch` expire
              after 30 days and all other files are persisted until they are manually deleted.

          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>   r?   r3   r>   pathsContent-Typemultipart/form-data/filesr4   r5   r6   r7   bodyfilesoptionscast_to)r   r   r   r   strobject_postr   r
   FileCreateParamsr!   r"   
r+   r>   r?   r3   r4   r5   r6   r7   rI   rJ   r,   r,   r-   create7   s(    8
   zFiles.createrG   rM   file_idr4   r5   r6   r7   r(   c                C  s4   |st d|| jd| t||||dtdS )^  
        Returns information about a specific file.

        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
        6Expected a non-empty value for `file_id` but received /files/rG   rK   rL   
ValueError_getr!   r"   r+   rT   r4   r5   r6   r7   r,   r,   r-   retrieve   s       zFiles.retrieveafterlimitorderr?   r4   r5   r6   r7   str | NotGivenint | NotGiven#Literal[('asc', 'desc')] | NotGivenzSyncCursorPage[FileObject]	r_   r`   ra   r?   r4   r5   r6   r7   r(   c          	      C  s6   | j dtt t||||t||||dtjdtdS a  Returns a list of files.

        Args:
          after: A cursor for use in pagination.

        `after` is an object ID that defines your place
              in the list. For instance, if you make a list request and receive 100 objects,
              ending with obj_foo, your subsequent call can include after=obj_foo in order to
              fetch the next page of the list.

          limit: A limit on the number of objects to be returned. Limit can range between 1 and
              10,000, and the default is 10,000.

          order: Sort order by the `created_at` timestamp of the objects. `asc` for ascending
              order and `desc` for descending order.

          purpose: Only return files with the given 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
        rF   )r_   r`   ra   r?   )r4   r5   r6   r7   query)pagerK   model)_get_api_listr   r"   r!   r   r	   FileListParams	r+   r_   r`   ra   r?   r4   r5   r6   r7   r,   r,   r-   list   s&    (z
Files.listr#   c                C  s4   |st d|| jd| t||||dtdS )B  
        Delete a file.

        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
        rV   rW   rG   rX   rZ   _deleter!   r#   r\   r,   r,   r-   delete   s       zFiles.delete+_legacy_response.HttpxBinaryResponseContentc                C  sH   |st d|ddi|pi }| jd| dt||||dtjdS )_  
        Returns the contents of the specified file.

        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
        rV   Acceptapplication/binaryrW   /contentrG   rX   rZ   r[   r!   r   ZHttpxBinaryResponseContentr\   r,   r,   r-   content  s    
   zFiles.content.The `.content()` method should be used insteadc                C  s6   |st d|| jd| dt||||dtdS )rs   rV   rW   rv   rG   rX   rZ   r[   r!   rM   r\   r,   r,   r-   retrieve_content&  s    
   zFiles.retrieve_content      @  poll_intervalmax_wait_secondsfloatidr   r   r(   c                C  sf   dddh}t   }| |}|j|krb| | | |}t   | |krtd| d| dq|S )EWaits for the given file to be processed, default timeout is 30 mins.	processederrordeletedGiving up on waiting for file  to finish processing after 	 seconds.timer]   statusZ_sleepRuntimeErrorr+   r   r   r   ZTERMINAL_STATESstartr>   r,   r,   r-   wait_for_processingH  s    




zFiles.wait_for_processing__name__
__module____qualname__r   r.   r1   r   rR   r]   rm   rq   rx   typing_extensions
deprecatedr{   r   r,   r,   r,   r-   r$   #   sV   	 T$"C'"%c                   @  sB  e Zd ZeddddZeddddZeddded	d
ddddddddddZdddeddddddddddZeeeedddeddddddddddd	d d!Z	dddeddddddd"dd#d$Z
dddeddddddd%dd&d'Zed(dddeddddddddd)d*Zd+d,d-dd.d.dd/d0d1ZdS )2r%   AsyncFilesWithRawResponser'   c                 C  s   t | S r)   )r   r*   r,   r,   r-   r.   a  s    zAsyncFiles.with_raw_responseAsyncFilesWithStreamingResponsec                 C  s   t | S r0   )r   r*   r,   r,   r-   r1   k  s    z"AsyncFiles.with_streaming_responseNr2   r   r   r8   r9   r:   r;   r<   r"   r=   c          
   
     sr   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 )
r@   rA   r>   rB   rD   rE   rF   NrG   rH   )r   r   r   r   rM   rN   rO   r   r
   rP   r!   r"   rQ   r,   r,   r-   rR   t  s(    8   zAsyncFiles.createrG   rM   rS   c                  s:   |st d|| jd| t||||dtdI dH S )rU   rV   rW   rG   rX   NrY   r\   r,   r,   r-   r]     s       zAsyncFiles.retriever^   rb   rc   rd   z7AsyncPaginator[FileObject, AsyncCursorPage[FileObject]]re   c          	      C  s6   | j dtt t||||t||||dtjdtdS rf   )rj   r   r"   r!   r   r	   rk   rl   r,   r,   r-   rm     s&    (zAsyncFiles.listr#   c                  s:   |st d|| jd| t||||dtdI dH S )rn   rV   rW   rG   rX   Nro   r\   r,   r,   r-   rq      s       zAsyncFiles.deleterr   c                  sN   |st d|ddi|pi }| jd| dt||||dtjdI dH S )	rs   rV   rt   ru   rW   rv   rG   rX   Nrw   r\   r,   r,   r-   rx   A  s    
   zAsyncFiles.contentry   c                  s<   |st d|| jd| dt||||dtdI dH S )rs   rV   rW   rv   rG   rX   Nrz   r\   r,   r,   r-   r{   c  s    
   zAsyncFiles.retrieve_contentr|   r}   r~   r   r   c                  sx   dddh}t   }| |I dH }|j|krt| |I dH  | |I dH }t   | |kr"td| d| dq"|S )r   r   r   r   Nr   r   r   r   r   r,   r,   r-   r     s    

zAsyncFiles.wait_for_processingr   r,   r,   r,   r-   r%   `  sV   	 T$"C'"%c                   @  s   e Zd ZdddddZdS )r&   r$   NonerJ   r(   c                 C  s^   || _ t|j| _t|j| _t|j| _t|j| _t|j| _t|j| _d S N)	_filesr   Zto_raw_response_wrapperrR   r]   rm   rq   rx   r{   r+   rJ   r,   r,   r-   __init__  s(    zFilesWithRawResponse.__init__Nr   r   r   r   r,   r,   r,   r-   r&     s   r&   c                   @  s   e Zd ZdddddZdS )r   r%   r   r   c                 C  s^   || _ t|j| _t|j| _t|j| _t|j| _t|j| _t|j| _d S r   )	r   r   Zasync_to_raw_response_wrapperrR   r]   rm   rq   rx   r{   r   r,   r,   r-   r     s(    z"AsyncFilesWithRawResponse.__init__Nr   r,   r,   r,   r-   r     s   r   c                   @  s   e Zd ZdddddZdS )r/   r$   r   r   c                 C  sT   || _ t|j| _t|j| _t|j| _t|j| _t|jt| _t|j	| _	d S r   )
r   r   rR   r]   rm   rq   r   rx   r   r{   r   r,   r,   r-   r     s*    z#FilesWithStreamingResponse.__init__Nr   r,   r,   r,   r-   r/     s   r/   c                   @  s   e Zd ZdddddZdS )r   r%   r   r   c                 C  sT   || _ t|j| _t|j| _t|j| _t|j| _t|jt| _t|j	| _	d S r   )
r   r   rR   r]   rm   rq   r   rx   r   r{   r   r,   r,   r-   r     s*    z(AsyncFilesWithStreamingResponse.__init__Nr   r,   r,   r,   r-   r     s   r   )9
__future__r   r   r   typingr   r   r   Zhttpx r   typesr   r	   r
   _typesr   r   r   r   r   r   _utilsr   r   r   r   _compatr   Z	_resourcer   r   	_responser   r   r   r   r   r   Z
paginationr   r   Z_base_clientr    r!   Ztypes.file_objectr"   Ztypes.file_deletedr#   Ztypes.file_purpose__all__r$   r%   r&   r   r/   r   r,   r,   r,   r-   <module>   s8       ?  ?