o
    ØRWj�  ã                   @  sH  d dl mZ d dlZd dlZd dlZd dlmZmZmZ d dl	m
Z
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mZmZ e
dƒZd;dd„Zd<dd„Zddœd=dd„Zed>dd„ƒZed?dd„ƒZd@d d„ZdAd$d%„Z dBd(d)„Z!ed>d*d+„ƒZ"ed?d,d+„ƒZ"d@d-d+„Z"dAd.d/„Z#dBd0d1„Z$dCd5d6„Z%dDd9d:„Z&dS )Eé    )ÚannotationsN)ÚSequenceÚcastÚoverload)ÚTypeVarÚ	TypeGuardé   )Ú	FileTypesÚFileContentÚRequestFilesÚHttpxFileTypesÚBase64FileInputÚHttpxFileContentÚHttpxRequestFiles)Úis_listÚ
is_mappingÚ
is_tuple_tÚis_mapping_tÚis_sequence_tÚ_TÚobjÚobjectÚreturnúTypeGuard[Base64FileInput]c                 C  s   t | tjƒpt | tjƒS ©N)Ú
isinstanceÚioÚIOBaseÚosÚPathLike©r   © r!   ú\/home/esfera/Documents/content_generation/venv/lib/python3.10/site-packages/openai/_files.pyÚis_base64_file_input   s   r#   ú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'   )Úkeyr(   ú
str | NoneÚNonec                C  sF   t | ƒs!|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/   Úfilesc                 C  ó   d S r   r!   ©r0   r!   r!   r"   Úto_httpx_files+   ó   r3   r   r   c                 C  r1   r   r!   r2   r!   r!   r"   r3   /   r4   úRequestFiles | NoneúHttpxRequestFiles | Nonec                 C  sX   | d u rd S t | ƒrdd„ |  ¡ D ƒ} | S t| ƒr"dd„ | D ƒ} | S tdt| ƒ› d�ƒ‚)Nc                 S  s   i | ]	\}}|t |ƒ“qS r!   ©Ú_transform_file©Ú.0r(   Úfiler!   r!   r"   Ú
<dictcomp>8   s    z"to_httpx_files.<locals>.<dictcomp>c                 S  s   g | ]
\}}|t |ƒf‘qS r!   r7   r9   r!   r!   r"   Ú
<listcomp>:   ó    z"to_httpx_files.<locals>.<listcomp>úUnexpected file type input ú, expected mapping or sequence©r   Úitemsr   Ú	TypeErrorr-   r2   r!   r!   r"   r3   3   s   ûþr;   r	   r   c                 C  sb   t | ƒrt| tjƒrt | ¡}|j| ¡ fS | S t| ƒr-| d t	| d ƒg| dd … ¢R S t
dƒ‚©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_contentrC   ©r;   Úpathr!   r!   r"   r8   A   s   
"r8   r
   r   c                 C  s   t | tjƒrt | ¡ ¡ S | S r   )r   r   r   rF   rG   rI   ©r;   r!   r!   r"   rJ   O   s   rJ   c                 Ã  ó   �d S r   r!   r2   r!   r!   r"   Úasync_to_httpx_filesU   ó   €rO   c                 Ã  rN   r   r!   r2   r!   r!   r"   rO   Y   rP   c                 Ã  sf   �| d u rd S t | ƒrdd„ |  ¡ D ƒI d H } | S t| ƒr)dd„ | D ƒI d H } | S tdt| ƒ› d�ƒ‚)Nc                 Ó  s"   �i | ]\}}|t |ƒI d H “qS r   ©Ú_async_transform_filer9   r!   r!   r"   r<   b   s   €  z(async_to_httpx_files.<locals>.<dictcomp>c                 Ó  s$   �g | ]\}}|t |ƒI d H f‘qS r   rQ   r9   r!   r!   r"   r=   d   s   €" z(async_to_httpx_files.<locals>.<listcomp>r?   r@   rA   r2   r!   r!   r"   rO   ]   s   €ûþc                 Ã  sp   �t | ƒrt| tjƒrt | ¡}|j| ¡ I d H fS | S t| ƒr4| d t	| d ƒI d H g| dd … ¢R S t
dƒ‚rD   )r'   r   r   r   ÚanyiorG   rH   rI   r   Úasync_read_file_contentrC   rK   r!   r!   r"   rR   k   s   €
(rR   c                 Ã  s&   �t | tjƒrt | ¡ ¡ I d H S | S r   )r   r   r   rS   rG   rI   rM   r!   r!   r"   rT   y   s   €rT   ÚitemÚpathsúSequence[Sequence[str]]c                 C  s   t | |dƒS )aP  Copy only the containers along the given paths.

    Used to guard against mutation by extract_files without copying the entire structure.
    Only dicts and lists that lie on a path are copied; everything else
    is returned by reference.

    For example, given paths=[["foo", "files", "file"]] and the structure:
        {
            "foo": {
                "bar": {"baz": {}},
                "files": {"file": <content>}
            }
        }
    The root dict, "foo", and "files" are copied (they lie on the path).
    "bar" and "baz" are returned by reference (off the path).
    r   ©Ú_deepcopy_with_paths)rU   rV   r!   r!   r"   Údeepcopy_with_paths€   s   rZ   ÚindexÚintc                   sÒ   |s| S t | ƒrFi }|D ]}ˆt|ƒk r| |ˆ g ¡ |¡ q|s$| S t| ƒ}| ¡ D ]\}}||v r@t|| |ˆd ƒ||< q,tt|ƒS t	| ƒrg‡fdd„|D ƒ‰ ˆ sZtt| ƒS tt‡ ‡fdd„| D ƒƒS | S )Nr   c                   s(   g | ]}ˆ t |ƒk r|ˆ  d kr|‘qS )z<array>)Úlen)r:   rL   )r[   r!   r"   r=   §   s   ( z(_deepcopy_with_paths.<locals>.<listcomp>c                   s   g | ]
}t |ˆ ˆd  ƒ‘qS )r   rX   )r:   Úentry©Úarray_pathsr[   r!   r"   r=   ¬   r>   )
r   r]   Ú
setdefaultÚappendÚdictrB   rY   r   r   r   )rU   rV   r[   Úkey_to_pathsrL   Úresultr(   Úsubpathsr!   r_   r"   rY   ”   s,   €€

rY   )r   r   r   r   )r   r   r   r$   )r   r   r(   r)   r   r*   )r0   r*   r   r*   )r0   r   r   r   )r0   r5   r   r6   )r;   r	   r   r   )r;   r
   r   r   )rU   r   rV   rW   r   r   )rU   r   rV   rW   r[   r\   r   r   )'Ú
__future__r   r   r   rF   Útypingr   r   r   Útyping_extensionsr   r   rS   Ú_typesr	   r
   r   r   r   r   r   Ú_utilsr   r   r   r   r   r   r#   r'   r/   r3   r8   rJ   rO   rR   rT   rZ   rY   r!   r!   r!   r"   Ú<module>   s:    $	








