a
    !f                     @  sT  d dl mZ d dlZd dlZd dlZd dlmZ d dlmZ d dl	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	d
ddZddddddddZedddddZedddddZdddddZddddd Zd!d"dd#d$Zedddd%d&Zedddd'd&Zdddd(d&Zdddd)d*Zd!d"dd+d,ZdS )-    )annotationsN)overload)	TypeGuard   )	FileTypesFileContentRequestFilesHttpxFileTypesHttpxFileContentHttpxRequestFiles)
is_tuple_tis_mapping_tis_sequence_tobjectzTypeGuard[FileContent])objreturnc                 C  s,   t | tp*t | tp*t | tjp*t | tjS N)
isinstancebytestupleioIOBaseosPathLike)r    r   N/var/www/html/python-backend/venv/lib/python3.9/site-packages/openai/_files.pyis_file_content   s    *r   )keyz
str | NoneNone)r   r   r   c                C  sF   t | sB|d urd| dn
d| d}t| dt|  dd d S )NzExpected entry at ``zExpected file input `zF to be bytes, an io.IOBase instance, PathLike or a tuple but received zL instead. See https://github.com/openai/openai-python/tree/main#file-uploads)r   RuntimeErrortype)r   r   prefixr   r   r   assert_is_file_content   s     r#   )filesr   c                 C  s   d S r   r   r$   r   r   r   to_httpx_files$   s    r&   r   r   c                 C  s   d S r   r   r%   r   r   r   r&   )   s    zRequestFiles | NonezHttpxRequestFiles | Nonec                 C  sX   | d u rd S t | r(dd |  D } n,t| r@dd | D } ntdt|  d| S )Nc                 S  s   i | ]\}}|t |qS r   _transform_file.0r   filer   r   r   
<dictcomp>3       z"to_httpx_files.<locals>.<dictcomp>c                 S  s   g | ]\}}|t |fqS r   r'   r)   r   r   r   
<listcomp>5   r-   z"to_httpx_files.<locals>.<listcomp>zUnexpected file type input z, expected mapping or sequence)r   itemsr   	TypeErrorr!   r%   r   r   r   r&   .   s    r   r	   )r+   r   c                 C  sf   t | r0t| tjr,t| }|j| fS | S t| rZ| d t	| d g| dd  R S t
dd S Nr   r      zCExpected file types input to be a FileContent type or to be a tuple)r   r   r   r   pathlibPathname
read_bytesr   _read_file_contentr0   r+   pathr   r   r   r(   <   s    
"r(   r   r
   c                 C  s   t | tjrt|  S | S r   )r   r   r   r3   r4   r6   r+   r   r   r   r7   J   s    r7   c                   s   d S r   r   r%   r   r   r   async_to_httpx_filesP   s    r;   c                   s   d S r   r   r%   r   r   r   r;   U   s    c                   sX   | d u rd S t | r.dd |  D I d H } n&t| rLdd | D I d H } ntd| S )Nc                   s    i | ]\}}|t |I d H qS r   _async_transform_filer)   r   r   r   r,   _   r-   z(async_to_httpx_files.<locals>.<dictcomp>c                   s"   g | ]\}}|t |I d H fqS r   r<   r)   r   r   r   r.   a   r-   z(async_to_httpx_files.<locals>.<listcomp>zFUnexpected file type input {type(files)}, expected mapping or sequence)r   r/   r   r0   r%   r   r   r   r;   Z   s    c                   sr   t | r6t| tjr2t| }|j| I d H fS | S t| rf| d t	| d I d H g| dd  R S t
dd S r1   )r   r   r   r   anyior4   r5   r6   r   _async_read_file_contentr0   r8   r   r   r   r=   h   s    
(r=   c                   s$   t | tjr t|  I d H S | S r   )r   r   r   r>   r4   r6   r:   r   r   r   r?   v   s    r?   )
__future__r   r   r   r3   typingr   Ztyping_extensionsr   r>   _typesr   r   r   r	   r
   r   _utilsr   r   r   r   r#   r&   r(   r7   r;   r=   r?   r   r   r   r   <module>   s0    