
    i                    j   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d0dZd1dZddd2dZed3d            Zed4d            Zd5dZd6d Z d7d#Z!ed3d$            Z"ed4d%            Z"d5d&Z"d6d'Z#d7d(Z$d8d,Z%d9d/Z&dS ):    )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                j    t          | t          j                  pt          | t          j                  S N)
isinstanceioIOBaseosPathLiker   s    T/home/piyush/.hermes/hermes-agent/venv/lib/python3.11/site-packages/openai/_files.pyis_base64_file_inputr$      s%    c29%%EC)E)EE    TypeGuard[FileContent]c                    t          | t                    pHt          | t                    p3t          | t          j                  pt          | t
          j                  S r   )r   bytestupler   r   r    r!   r"   s    r#   is_file_contentr*      sI    3v*S%"8"8vJsBI<V<VvZdehjljuZvZvr%   )keyr+   
str | NoneNonec                   t          |           s1|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+   prefixs      r#   assert_is_file_contentr3   #   s    3 14-s----Ff^aFfFfFf  u  u]abe]f]f  u  u  u
 
	 r%   filesc                    d S r    r4   s    r#   to_httpx_filesr8   +   s    ),r%   r   r   c                    d S r   r6   r7   s    r#   r8   r8   /   s    >Acr%   RequestFiles | NoneHttpxRequestFiles | Nonec                    | d S t          |           rd |                                 D             } n<t          |           rd | D             } n t          dt	          |            d          | S )Nc                4    i | ]\  }}|t          |          S r6   _transform_file.0r+   files      r#   
<dictcomp>z"to_httpx_files.<locals>.<dictcomp>8   s&    KKK	Tod++KKKr%   c                6    g | ]\  }}|t          |          fS r6   r>   r@   s      r#   
<listcomp>z"to_httpx_files.<locals>.<listcomp>:   s)    EEE)#t#t,,-EEEr%   zUnexpected file type input z, expected mapping or sequence)r   itemsr   	TypeErrorr1   r7   s    r#   r8   r8   3   s    }tE cKKU[[]]KKK	u		 cEEuEEEad5kkaaabbbLr%   rB   r
   r   c                B   t          |           rKt          | t          j                  r/t	          j        |           }|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_contentrG   rB   paths     r#   r?   r?   A   s    t dBK(( 	2<%%DIt0011$ @Q*4733?d122h???
Z
[
[[r%   r   r   c                    t          | t          j                  r&t          j        |                                           S | S r   )r   r    r!   rK   rL   rN   rB   s    r#   rO   rO   O   s7    $$$ /|D!!,,...Kr%   c                
   K   d S r   r6   r7   s    r#   async_to_httpx_filesrU   U   s      58Sr%   c                
   K   d S r   r6   r7   s    r#   rU   rU   Y   s      JM#r%   c                   K   | d S t          |           r%d |                                 D              d {V } n1t          |           rd | D              d {V } nt          d          | S )Nc                D   K   i | ]\  }}|t          |           d {V S r   _async_transform_filer@   s      r#   rC   z(async_to_httpx_files.<locals>.<dictcomp>b   s=      WWWIC1$77777777WWWr%   c                F   K   g | ]\  }}|t          |           d {V fS r   rY   r@   s      r#   rE   z(async_to_httpx_files.<locals>.<listcomp>d   s@      QQQic4#24888888889QQQr%   zFUnexpected file type input {type(files)}, expected mapping or sequence)r   rF   r   rG   r7   s    r#   rU   rU   ]   s      }tE bWWWWWWWWWWW	u		 bQQ5QQQQQQQQQ`aaaLr%   c                ^  K   t          |           rQt          | t          j                  r5t	          j        |           }|j        |                                 d {V fS | S t          |           r.| d         t          | d                    d {V g| dd          R S t          d          rI   )r*   r   r    r!   anyiorL   rM   rN   r   async_read_file_contentrG   rP   s     r#   rZ   rZ   k   s      t dBK(( 	8:d##DIT__%6%666666677$ LQ6tAw????????K$qrr(KKK
Z
[
[[r%   c                   K   t          | t          j                  r,t          j        |                                            d {V S | S r   )r   r    r!   r]   rL   rN   rS   s    r#   r^   r^   y   sM      $$$ 3Z%%00222222222Kr%   itempathsSequence[Sequence[str]]c                $    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)r`   ra   s     r#   deepcopy_with_pathsrf      s    "  eQ///r%   indexintc                4   |s| S t          |           ri }|D ]D}t          |          k     r/|                    |         g                               |           E|s| S t	          |           }|                                D ]&\  }}||v rt          ||         |dz             ||<   't          t          |          S t          |           rGfd|D             st          t          |           S t          t          fd| D                       S | S )Nr	   c                R    g | ]#}t          |          k     |         d k    !|$S )z<array>)len)rA   rQ   rg   s     r#   rE   z(_deepcopy_with_paths.<locals>.<listcomp>   s8    ```T1B1BtE{V_G_G_tG_G_G_r%   c                8    g | ]}t          |d z             S )r	   rd   )rA   entryarray_pathsrg   s     r#   rE   z(_deepcopy_with_paths.<locals>.<listcomp>   s+    ___QV-e[%!)LL___r%   )
r   rk   
setdefaultappenddictrF   re   r   r   r   )	r`   ra   rg   key_to_pathsrQ   resultr+   subpathsrn   s	     `     @r#   re   re      sR    $  79 	F 	FDs4yy  ''UR88??EEE  	Kd)//11 	U 	UMCf}}26#;%RS)TTsBt}} a```````  	"D>>!B_____Z^___```Kr%   )r   r   r   r   )r   r   r   r&   )r   r   r+   r,   r   r-   )r4   r-   r   r-   )r4   r   r   r   )r4   r:   r   r;   )rB   r
   r   r   )rB   r   r   r   )r`   r   ra   rb   r   r   )r`   r   ra   rb   rg   rh   r   r   )'
__future__r   r   r    rK   typingr   r   r   typing_extensionsr   r   r]   _typesr
   r   r   r   r   r   r   _utilsr   r   r   r   r   r   r$   r*   r3   r8   r?   rO   rU   rZ   r^   rf   re   r6   r%   r#   <module>rz      sg   " " " " " " 				 				  + + + + + + + + + + 0 0 0 0 0 0 0 0                   Q P P P P P P P P P P P P PWT]]F F F F    >B       
 , , , 
 , 
 A A A 
 A   \ \ \ \    
 8 8 8 
 8 
 M M M 
 M   \ \ \ \   0 0 0 0(     r%   