o
    +ifXj                     @  sl  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 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gZ0G dd deZ1G dd deZ2G dd dZ3G dd dZ4G dd dZ5G dd dZ6dS )    )annotationsN)Mappingcast)Literal   )_legacy_response)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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 N)r'   self r,   O/var/www/html/corbot_env/lib/python3.10/site-packages/openai/resources/files.pywith_raw_response+      zFiles.with_raw_responseFilesWithStreamingResponsec                 C  r(   r)   )r0   r*   r,   r,   r-   with_streaming_response/   r/   zFiles.with_streaming_responseNextra_headersextra_query
extra_bodytimeoutfiler   purpose5Literal['assistants', 'batch', 'fine-tune', 'vision']r3   Headers | Noner4   Query | Noner5   Body | Noner6   'float | httpx.Timeout | None | NotGivenr!   c          	   
   C  sh   t ||d}tttttf |dggd}|r 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
        r7   r8   r7   pathsContent-Typemultipart/form-data/filesr2   bodyfilesoptionscast_to)r   r   r   r   strobject_postr   r	   FileCreateParamsr    r!   	r+   r7   r8   r3   r4   r5   r6   rF   rG   r,   r,   r-   create3   s"   8
zFiles.createfile_idrJ   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/r2   rH   rI   
ValueError_getr    r!   r+   rP   r3   r4   r5   r6   r,   r,   r-   retrieve      zFiles.retriever8   r3   r4   r5   r6   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
        rD   r8   )r3   r4   r5   r6   query)pagerH   model)_get_api_listr   r!   r    r   r   FileListParamsr+   r8   r3   r4   r5   r6   r,   r,   r-   list      z
Files.listr"   c                C  rQ   )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
        rS   rT   r2   rU   rW   _deleter    r"   rY   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
        rS   Acceptapplication/binaryrT   /contentr2   rU   rW   rX   r    r   HttpxBinaryResponseContentrY   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 )rn   rS   rT   rq   r2   rU   rW   rX   r    rJ   rY   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.timerZ   status_sleepRuntimeErrorr+   r}   r{   r|   TERMINAL_STATESstartr7   r,   r,   r-   wait_for_processing-  s   




	zFiles.wait_for_processing)r&   r'   )r&   r0   r7   r   r8   r9   r3   r:   r4   r;   r5   r<   r6   r=   r&   r!   rP   rJ   r3   r:   r4   r;   r5   r<   r6   r=   r&   r!   )r8   r]   r3   r:   r4   r;   r5   r<   r6   r=   r&   r^   rP   rJ   r3   r:   r4   r;   r5   r<   r6   r=   r&   r"   rP   rJ   r3   r:   r4   r;   r5   r<   r6   r=   r&   rm   rP   rJ   r3   r:   r4   r;   r5   r<   r6   r=   r&   rJ   r}   rJ   r{   r~   r|   r~   r&   r!   __name__
__module____qualname__r   r.   r1   r
   rO   rZ   rg   rl   rt   typing_extensions
deprecatedrw   r   r,   r,   r,   r-   r#   *   P    
T$,'"%c                   @  r%   )=r$   r&   AsyncFilesWithRawResponsec                 C  r(   r)   )r   r*   r,   r,   r-   r.   F  r/   zAsyncFiles.with_raw_responseAsyncFilesWithStreamingResponsec                 C  r(   r)   )r   r*   r,   r,   r-   r1   J  r/   z"AsyncFiles.with_streaming_responseNr2   r7   r   r8   r9   r3   r:   r4   r;   r5   r<   r6   r=   r!   c          	   
     sv   t ||d}tttttf |dggd}|r!ddi|pi }| jdt|tj	I dH |t
||||dtd	I dH S )
r>   r?   r7   r@   rB   rC   rD   Nr2   rE   )r   r   r   r   rJ   rK   rL   r   r	   rM   r    r!   rN   r,   r,   r-   rO   N  s$   8zAsyncFiles.createrP   rJ   c                  <   |s
t d|| jd| t||||dtdI dH S )rR   rS   rT   r2   rU   NrV   rY   r,   r,   r-   rZ        zAsyncFiles.retriever\   r]   1AsyncPaginator[FileObject, AsyncPage[FileObject]]c                C  r_   r`   )rd   r   r!   r    r   r   re   rf   r,   r,   r-   rg     rh   zAsyncFiles.listr"   c                  r   )ri   rS   rT   r2   rU   Nrj   rY   r,   r,   r-   rl     r   zAsyncFiles.deleterm   c                  sP   |s
t d|ddi|pi }| jd| dt||||dtjdI dH S )	rn   rS   ro   rp   rT   rq   r2   rU   Nrr   rY   r,   r,   r-   rt     s   
zAsyncFiles.contentru   c                  s>   |s
t d|| jd| dt||||dtdI dH S )rn   rS   rT   rq   r2   rU   Nrv   rY   r,   r,   r-   rw   &  s   
zAsyncFiles.retrieve_contentrx   ry   rz   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   H  s   

	zAsyncFiles.wait_for_processing)r&   r   )r&   r   r   r   )r8   r]   r3   r:   r4   r;   r5   r<   r6   r=   r&   r   r   r   r   r   r   r,   r,   r,   r-   r$   E  r   c                   @     e Zd ZdddZdS )	r'   rG   r#   r&   Nonec                 C  ^   || _ t|j| _t|j| _t|j| _t|j| _t|j| _t|j| _d S r)   )	_filesr   to_raw_response_wrapperrO   rZ   rg   rl   rt   rw   r+   rG   r,   r,   r-   __init__a  (   zFilesWithRawResponse.__init__NrG   r#   r&   r   r   r   r   r   r,   r,   r,   r-   r'   `      r'   c                   @  r   )	r   rG   r$   r&   r   c                 C  r   r)   )	r   r   async_to_raw_response_wrapperrO   rZ   rg   rl   rt   rw   r   r,   r,   r-   r   {  r   z"AsyncFilesWithRawResponse.__init__NrG   r$   r&   r   r   r,   r,   r,   r-   r   z  r   r   c                   @  r   )	r0   rG   r#   r&   r   c                 C  T   || _ t|j| _t|j| _t|j| _t|j| _t|jt| _t|j	| _	d S r)   )
r   r   rO   rZ   rg   rl   r   rt   r   rw   r   r,   r,   r-   r     *   z#FilesWithStreamingResponse.__init__Nr   r   r,   r,   r,   r-   r0     r   r0   c                   @  r   )	r   rG   r$   r&   r   c                 C  r   r)   )
r   r   rO   rZ   rg   rl   r   rt   r   rw   r   r,   r,   r-   r     r   z(AsyncFilesWithStreamingResponse.__init__Nr   r   r,   r,   r,   r-   r     r   r   )7
__future__r   r   r   typingr   r   r   httpx r   typesr   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"   __all__r#   r$   r'   r   r0   r   r,   r,   r,   r-   <module>   s8         