a
    _g                      @  sh  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mZ ddlmZmZmZ dd	d
dd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 )0    )annotationsN)overload)	TypeGuard   )	FileTypesFileContentRequestFilesHttpxFileTypesBase64FileInputHttpxFileContentHttpxRequestFiles)
is_tuple_tis_mapping_tis_sequence_tobjectzTypeGuard[Base64FileInput])objreturnc                 C  s   t | tjpt | tjS N)
isinstanceioIOBaseosPathLiker    r   [/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/openai/_files.pyis_base64_file_input   s    r   zTypeGuard[FileContent]c                 C  s,   t | tp*t | tp*t | tjp*t | tjS r   )r   bytestupler   r   r   r   r   r   r   r   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>6       z"to_httpx_files.<locals>.<dictcomp>c                 S  s   g | ]\}}|t |fqS r   r*   r,   r   r   r   
<listcomp>8   r0   z"to_httpx_files.<locals>.<listcomp>zUnexpected file type input z, expected mapping or sequence)r   itemsr   	TypeErrorr$   r(   r   r   r   r)   1   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_contentr3   r.   pathr   r   r   r+   ?   s    
"r+   r   r   c                 C  s   t | tjrt|  S | S r   )r   r   r   r6   r7   r9   r.   r   r   r   r:   M   s    r:   c                   s   d S r   r   r(   r   r   r   async_to_httpx_filesS   s    r>   c                   s   d S r   r   r(   r   r   r   r>   W   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/   `   r0   z(async_to_httpx_files.<locals>.<dictcomp>c                   s"   g | ]\}}|t |I d H fqS r   r?   r,   r   r   r   r1   b   r0   z(async_to_httpx_files.<locals>.<listcomp>zFUnexpected file type input {type(files)}, expected mapping or sequence)r   r2   r   r3   r(   r   r   r   r>   [   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 r4   )r   r   r   r   anyior7   r8   r9   r   _async_read_file_contentr3   r;   r   r   r   r@   i   s    
(r@   c                   s$   t | tjr t|  I d H S | S r   )r   r   r   rA   r7   r9   r=   r   r   r   rB   w   s    rB   )
__future__r   r   r   r6   typingr   Ztyping_extensionsr   rA   _typesr   r   r   r	   r
   r   r   _utilsr   r   r   r   r   r&   r)   r+   r:   r>   r@   rB   r   r   r   r   <module>   s2   $	