o
    #`^hm                     @  sp  d dl mZ d dlZd dlZd dlmZ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.m/Z/ ddl0mZ ddgZ1G dd deZ2G dd deZ3G dd dZ4G dd dZ5G dd dZ6G dd dZ7dS )    )annotationsN)Mappingcast   )_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)SyncPage	AsyncPage)AsyncPaginatormake_request_options)
FileObject)FileDeleted)r   Files
AsyncFilesc                   @     e Zd Zed4ddZed5ddZddded	d6ddZddded	d7ddZedddedd8d d!Z	ddded	d9d#d$Z
ddded	d:d&d'Zed(ddded	d;d)d*Zd+d,d-d<d2d3ZdS )=r#   returnFilesWithRawResponsec                 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,   T/home/air/shanriGPT/back/venv/lib/python3.10/site-packages/openai/resources/files.pywith_raw_response+      zFiles.with_raw_responseFilesWithStreamingResponsec                 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
        )r0   r*   r,   r,   r-   with_streaming_response5      zFiles.with_streaming_responseNextra_headersextra_query
extra_bodytimeoutfiler   purposer   r5   Headers | Noner6   Query | Noner7   Body | Noner8   'float | httpx.Timeout | None | NotGivenr!   c          	   
   C  sd   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 100 GB.

        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 100 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.

              Use "assistants" for
              [Assistants](https://platform.openai.com/docs/api-reference/assistants) and
              [Message](https://platform.openai.com/docs/api-reference/messages) files,
              "vision" for Assistants image file inputs, "batch" for
              [Batch API](https://platform.openai.com/docs/guides/batch), and "fine-tune" for
              [Fine-tuning](https://platform.openai.com/docs/api-reference/fine-tuning).

          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
        r9   r:   r9   pathsContent-Typemultipart/form-data/filesr4   bodyfilesoptionscast_to)r   r   r   r   strobject_postr   r	   FileCreateParamsr    r!   	r+   r9   r:   r5   r6   r7   r8   rG   rH   r,   r,   r-   create>   s    8
zFiles.createfile_idrK   c                C  4   |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/r4   rI   rJ   
ValueError_getr    r!   r+   rQ   r5   r6   r7   r8   r,   r,   r-   retrieve      zFiles.retriever:   r5   r6   r7   r8   str | NotGivenSyncPage[FileObject]c                C  0   | j dtt t||||td|itjdtdS a  
        Returns a list of files that belong to the user's organization.

        Args:
          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
        rE   r:   )r5   r6   r7   r8   query)pagerI   model)_get_api_listr   r!   r    r   r   FileListParamsr+   r:   r5   r6   r7   r8   r,   r,   r-   list      z
Files.listr"   c                C  rR   )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
        rT   rU   r4   rV   rX   _deleter    r"   rZ   r,   r,   r-   delete   r\   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
        rT   Acceptapplication/binaryrU   /contentr4   rV   rX   rY   r    r   HttpxBinaryResponseContentrZ   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 )ro   rT   rU   rr   r4   rV   rX   rY   r    rK   rZ   r,   r,   r-   retrieve_content  s   
zFiles.retrieve_content      @  poll_intervalmax_wait_secondsidr|   floatr}   c                C  sl   h d}t   }| |}|j|vr4| | | |}t   | |kr/td| d| d|j|vs|S )EWaits for the given file to be processed, default timeout is 30 mins.>   errordeleted	processedGiving up on waiting for file  to finish processing after 	 seconds.timer[   status_sleepRuntimeErrorr+   r~   r|   r}   TERMINAL_STATESstartr9   r,   r,   r-   wait_for_processing7  s   




	zFiles.wait_for_processing)r&   r'   )r&   r0   r9   r   r:   r   r5   r;   r6   r<   r7   r=   r8   r>   r&   r!   rQ   rK   r5   r;   r6   r<   r7   r=   r8   r>   r&   r!   )r:   r^   r5   r;   r6   r<   r7   r=   r8   r>   r&   r_   rQ   rK   r5   r;   r6   r<   r7   r=   r8   r>   r&   r"   rQ   rK   r5   r;   r6   r<   r7   r=   r8   r>   r&   rn   rQ   rK   r5   r;   r6   r<   r7   r=   r8   r>   r&   rK   r~   rK   r|   r   r}   r   r&   r!   __name__
__module____qualname__r   r.   r2   r
   rP   r[   rh   rm   ru   typing_extensions
deprecatedrx   r   r,   r,   r,   r-   r#   *   P    	S$,'"%c                   @  r%   )=r$   r&   AsyncFilesWithRawResponsec                 C  r(   r)   )r   r*   r,   r,   r-   r.   P  r/   zAsyncFiles.with_raw_responseAsyncFilesWithStreamingResponsec                 C  r(   r1   )r   r*   r,   r,   r-   r2   Z  r3   z"AsyncFiles.with_streaming_responseNr4   r9   r   r:   r   r5   r;   r6   r<   r7   r=   r8   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?   r@   r9   rA   rC   rD   rE   Nr4   rF   )r   r   r   r   rK   rL   rM   r   r	   rN   r    r!   rO   r,   r,   r-   rP   c  s"   8zAsyncFiles.createrQ   rK   c                  <   |s
t d|| jd| t||||dtdI dH S )rS   rT   rU   r4   rV   NrW   rZ   r,   r,   r-   r[        zAsyncFiles.retriever]   r^   1AsyncPaginator[FileObject, AsyncPage[FileObject]]c                C  r`   ra   )re   r   r!   r    r   r   rf   rg   r,   r,   r-   rh     ri   zAsyncFiles.listr"   c                  r   )rj   rT   rU   r4   rV   Nrk   rZ   r,   r,   r-   rm     r   zAsyncFiles.deletern   c                  sP   |s
t d|ddi|pi }| jd| dt||||dtjdI dH S )	ro   rT   rp   rq   rU   rr   r4   rV   Nrs   rZ   r,   r,   r-   ru     s   
zAsyncFiles.contentrv   c                  s>   |s
t d|| jd| dt||||dtdI dH S )ro   rT   rU   rr   r4   rV   Nrw   rZ   r,   r,   r-   rx   :  s   
zAsyncFiles.retrieve_contentry   rz   r{   r~   r|   r   r}   c                  s   h d}t   }| |I dH }|j|vr>| |I dH  | |I dH }t   | |kr9td| d| d|j|vs|S )r   >   r   r   r   Nr   r   r   r   r   r,   r,   r-   r   \  s   

	zAsyncFiles.wait_for_processing)r&   r   )r&   r   r   r   )r:   r^   r5   r;   r6   r<   r7   r=   r8   r>   r&   r   r   r   r   r   r   r,   r,   r,   r-   r$   O  r   c                   @     e Zd ZdddZdS )	r'   rH   r#   r&   Nonec                 C  ^   || _ t|j| _t|j| _t|j| _t|j| _t|j| _t|j| _d S N)	_filesr   to_raw_response_wrapperrP   r[   rh   rm   ru   rx   r+   rH   r,   r,   r-   __init__u  (   zFilesWithRawResponse.__init__NrH   r#   r&   r   r   r   r   r   r,   r,   r,   r-   r'   t      r'   c                   @  r   )	r   rH   r$   r&   r   c                 C  r   r   )	r   r   async_to_raw_response_wrapperrP   r[   rh   rm   ru   rx   r   r,   r,   r-   r     r   z"AsyncFilesWithRawResponse.__init__NrH   r$   r&   r   r   r,   r,   r,   r-   r     r   r   c                   @  r   )	r0   rH   r#   r&   r   c                 C  T   || _ t|j| _t|j| _t|j| _t|j| _t|jt| _t|j	| _	d S r   )
r   r   rP   r[   rh   rm   r   ru   r   rx   r   r,   r,   r-   r     *   z#FilesWithStreamingResponse.__init__Nr   r   r,   r,   r,   r-   r0     r   r0   c                   @  r   )	r   rH   r$   r&   r   c                 C  r   r   )
r   r   rP   r[   rh   rm   r   ru   r   rx   r   r,   r,   r-   r     r   z(AsyncFilesWithStreamingResponse.__init__Nr   r   r,   r,   r,   r-   r     r   r   )8
__future__r   r   r   typingr   r   httpx r   typesr   r   r	   _typesr
   r   r   r   r   r   _utilsr   r   r   r   _compatr   	_resourcer   r   	_responser   r   r   r   r   r   
paginationr   r   _base_clientr   r    types.file_objectr!   types.file_deletedr"   types.file_purpose__all__r#   r$   r'   r   r0   r   r,   r,   r,   r-   <module>   s8       '  '