o
    $iv                     @  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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/m0Z0 ddl1m2Z2 ddl3mZ ddgZ4G dd de Z5G dd de!Z6G dd dZ7G dd dZ8G dd dZ9G dd dZ:dS )    )annotationsN)Mappingcast)Literal   )_legacy_response)FilePurposefile_list_paramsfile_create_params)BodyOmitQueryHeadersNotGiven	FileTypesomit	not_given)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                	   @     e Zd Zed<ddZed=ddZeddded	d>ddZdddedd?ddZ	eeeeddded d@d(d)Z
dddeddAd+d,ZdddeddBd.d/Zed0dddeddCd1d2Zd3d4d5dDd:d;ZdS )Er&   returnFilesWithRawResponsec                 C     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/   V/var/www/html/flask_server/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
        )r3   r-   r/   r/   r0   with_streaming_response.      zFiles.with_streaming_responseNexpires_afterextra_headersextra_query
extra_bodytimeoutfiler   purposer   r8   &file_create_params.ExpiresAfter | Omitr9   Headers | Noner:   Query | Noner;   Body | Noner<   'float | httpx.Timeout | None | NotGivenr$   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>   r8   r=   pathsContent-Typemultipart/form-data/filesr9   r:   r;   r<   bodyfilesoptionscast_to)r   r   r   r   strobject_postr   r
   FileCreateParamsr#   r$   
r.   r=   r>   r8   r9   r:   r;   r<   rM   rN   r/   r/   r0   create7   s"   7
zFiles.createrK   file_idrQ   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/rK   rO   rP   
ValueError_getr#   r$   r.   rW   r9   r:   r;   r<   r/   r/   r0   retrieve      zFiles.retrieveafterlimitorderr>   r9   r:   r;   r<   rd   
str | Omitre   
int | Omitrf   Literal['asc', 'desc'] | OmitSyncCursorPage[FileObject]c          	      C  6   | 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
        rJ   )rd   re   rf   r>   )r9   r:   r;   r<   query)pagerO   model)_get_api_listr    r$   r#   r   r	   FileListParams	r.   rd   re   rf   r>   r9   r:   r;   r<   r/   r/   r0   list   &   (z
Files.listr%   c                C  rX   )g  
        Delete a file and remove it from all vector stores.

        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
        rZ   r[   rK   r\   r^   _deleter#   r%   r`   r/   r/   r0   delete   rb   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
        rZ   Acceptapplication/binaryr[   /contentrK   r\   r^   r_   r#   r   HttpxBinaryResponseContentr`   r/   r/   r0   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 )rz   rZ   r[   r}   rK   r\   r^   r_   r#   rQ   r`   r/   r/   r0   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.timera   status_sleepRuntimeErrorr.   r   r   r   TERMINAL_STATESstartr=   r/   r/   r0   wait_for_processingG  s   




	zFiles.wait_for_processing)r)   r*   )r)   r3   r=   r   r>   r   r8   r?   r9   r@   r:   rA   r;   rB   r<   rC   r)   r$   rW   rQ   r9   r@   r:   rA   r;   rB   r<   rC   r)   r$   )rd   rg   re   rh   rf   ri   r>   rg   r9   r@   r:   rA   r;   rB   r<   rC   r)   rj   rW   rQ   r9   r@   r:   rA   r;   rB   r<   rC   r)   r%   rW   rQ   r9   r@   r:   rA   r;   rB   r<   rC   r)   ry   rW   rQ   r9   r@   r:   rA   r;   rB   r<   rC   r)   rQ   r   rQ   r   r   r   r   r)   r$   __name__
__module____qualname__r   r1   r5   r   r   rV   ra   rs   rx   r   typing_extensions
deprecatedr   r   r/   r/   r/   r0   r&   #   X    	S$C'"%c                	   @  r(   )Er'   r)   AsyncFilesWithRawResponsec                 C  r+   r,   )r   r-   r/   r/   r0   r1   `  r2   zAsyncFiles.with_raw_responseAsyncFilesWithStreamingResponsec                 C  r+   r4   )r   r-   r/   r/   r0   r5   j  r6   z"AsyncFiles.with_streaming_responseNr7   r=   r   r>   r   r8   r?   r9   r@   r:   rA   r;   rB   r<   rC   r$   c          
   
     st   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/   r0   rV   s  s$   7zAsyncFiles.createrK   rW   rQ   c                  <   |s
t d|| jd| t||||dtdI dH S )rY   rZ   r[   rK   r\   Nr]   r`   r/   r/   r0   ra        zAsyncFiles.retrieverc   rd   rg   re   rh   rf   ri   7AsyncPaginator[FileObject, AsyncCursorPage[FileObject]]c          	      C  rk   rl   )rp   r!   r$   r#   r   r	   rq   rr   r/   r/   r0   rs     rt   zAsyncFiles.listr%   c                  r   )ru   rZ   r[   rK   r\   Nrv   r`   r/   r/   r0   rx     r   zAsyncFiles.deletery   c                  sP   |s
t d|ddi|pi }| jd| dt||||dtjdI dH S )	rz   rZ   r{   r|   r[   r}   rK   r\   Nr~   r`   r/   r/   r0   r   ?  s   
zAsyncFiles.contentr   c                  s>   |s
t d|| jd| dt||||dtdI dH S )rz   rZ   r[   r}   rK   r\   Nr   r`   r/   r/   r0   r   a  s   
zAsyncFiles.retrieve_contentr   r   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/   r0   r     s   

	zAsyncFiles.wait_for_processing)r)   r   )r)   r   r   r   )rd   rg   re   rh   rf   ri   r>   rg   r9   r@   r:   rA   r;   rB   r<   rC   r)   r   r   r   r   r   r   r/   r/   r/   r0   r'   _  r   c                   @     e Zd ZdddZdS )	r*   rN   r&   r)   Nonec                 C  ^   || _ t|j| _t|j| _t|j| _t|j| _t|j| _t|j| _d S N)	_filesr   to_raw_response_wrapperrV   ra   rs   rx   r   r   r.   rN   r/   r/   r0   __init__  (   zFilesWithRawResponse.__init__NrN   r&   r)   r   r   r   r   r   r/   r/   r/   r0   r*         r*   c                   @  r   )	r   rN   r'   r)   r   c                 C  r   r   )	r   r   async_to_raw_response_wrapperrV   ra   rs   rx   r   r   r   r/   r/   r0   r     r   z"AsyncFilesWithRawResponse.__init__NrN   r'   r)   r   r   r/   r/   r/   r0   r     r   r   c                   @  r   )	r3   rN   r&   r)   r   c                 C  T   || _ t|j| _t|j| _t|j| _t|j| _t|jt| _t|j	| _	d S r   )
r   r   rV   ra   rs   rx   r   r   r   r   r   r/   r/   r0   r     *   z#FilesWithStreamingResponse.__init__Nr   r   r/   r/   r/   r0   r3     r   r3   c                   @  r   )	r   rN   r'   r)   r   c                 C  r   r   )
r   r   rV   ra   rs   rx   r   r   r   r   r   r/   r/   r0   r     r   z(AsyncFilesWithStreamingResponse.__init__Nr   r   r/   r/   r/   r0   r     r   r   );
__future__r   r   r   typingr   r   r   httpx r   typesr   r	   r
   _typesr   r   r   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   r3   r   r/   r/   r/   r0   <module>   s:   (   >  >