
    	hf1                       d dl mZ d dlZd dlZd dlZd dlZd dlmZmZm	Z	m
Z
mZmZ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 d dlZddlmZmZmZmZ  ed	          Z ed
e	edf                   Z ede
e ef                   Z! edee                   Z" ededef                   Z#erddl$m%Z%m&Z& dxdZ'dydZ(dzd$Z)d{d'Z*d|d)Z+d}d,Z,d~d.Z-dd1Z.dd3Z/dd6Z0dd8Z1dd:Z2dd<Z3dd>Z4d?d@dAddFZ5ddHZ6ddKZ7 edL          Z8 edM          Z9eddO            Z:eddR            Z:eddS            Z:ddUZ:ddWZ;ddYZ<dd[Z=dd]Z>dd_Z?ddaZ@ddcZAddeZBddgZCddkZDddlZEdmdnddpZFddrZGdduZHddwZIdS )    )annotationsN)
TYPE_CHECKINGAnyTupleMappingTypeVarCallableIterableSequencecastoverload)Path)datedatetime)	TypeGuard   )NotGiven	FileTypes
NotGivenOrHeadersLike_T_TupleT.)bound	_MappingT
_SequenceT	CallableT)AzureOpenAIAsyncAzureOpenAItIterable[Iterable[_T]]returnlist[_T]c                    d | D             S )Nc                    g | ]	}|D ]}|
S  r%   ).0sublistitems      a/var/www/html/web-builder-api.evdpl.com/venv/lib/python3.11/site-packages/openai/_utils/_utils.py
<listcomp>zflatten.<locals>.<listcomp>&   s%    666Wg66dD6666    r%   )r   s    r)   flattenr,   %   s    666666r+   queryMapping[str, object]pathsSequence[Sequence[str]]list[tuple[str, FileTypes]]c          	     `    g }|D ](}|                     t          | |dd                     )|S )zRecursively extract files from the given dictionary based on specified paths.

    A path may look like this ['foo', 'files', '<array>', 'data'].

    Note: this mutates the given dictionary.
    r   Nindexflattened_key)extend_extract_items)r-   r/   filespaths       r)   extract_filesr:   )   sE     *,E O O^E4qMMMNNNNLr+   objobjectr9   Sequence[str]r4   intr5   
str | Nonec          	        	          }n# t           $ r t          | t                    rg cY S ddlm} J t          |           rLg }| D ]C} ||rdz   nd           |                    dz   t          t          |          f           D|cY S  ||            t          t          |           fgcY S w xY wdz  t          |           rf	 t                    k    r|                     |          }n| |         }n# t          $ r g cY S w xY w|n	d| dz  t          |	          S t          |           r%|d
k    rg S t          fd| D                       S g S )Nr   )assert_is_file_content[] )key   []r3   z<array>c           	     D    g | ]}t          |dz   nd          S )NrB   r3   )r7   )r&   r(   r5   r4   r9   s     r)   r*   z"_extract_items.<locals>.<listcomp>v   sV         :G:S-$"6"6Y]	    r+   )
IndexError
isinstancer   _filesrA   is_listappendr   r   is_dictlenpopKeyErrorr7   r,   )	r;   r9   r4   r5   rD   rA   r8   entryr(   s	    ```     r)   r7   r7   <   s<   75k 7 7 7c8$$ 	III 	433333 (((3<< 	13E M M&&u-2_-$2F2F]_````md2DE4J4JKLLLLLLLs6666Y 4 456666'7* 
QJEs|| $

	D		e##wws||3x 	 	 	 III		
  MMZZZZ'M'	
 
 
 	
 
 
)I         

 

 
	
 Is-    !B>A#B>%B>=B>1D DDNotGivenOr[_T]TypeGuard[_T]c                .    t          | t                     S NrJ   r   r;   s    r)   is_givenrY      s    #x((((r+   TypeGuard[tuple[object, ...]]c                ,    t          | t                    S rV   rJ   tuplerX   s    r)   is_tupler^          c5!!!r+   _TupleT | objectTypeGuard[_TupleT]c                ,    t          | t                    S rV   r\   rX   s    r)   
is_tuple_trc      r_   r+   TypeGuard[Sequence[object]]c                ,    t          | t                    S rV   rJ   r   rX   s    r)   is_sequencerg          c8$$$r+   _SequenceT | objectTypeGuard[_SequenceT]c                ,    t          | t                    S rV   rf   rX   s    r)   is_sequence_trl      rh   r+   TypeGuard[Mapping[str, object]]c                ,    t          | t                    S rV   rJ   r   rX   s    r)   
is_mappingrp          c7###r+   _MappingT | objectTypeGuard[_MappingT]c                ,    t          | t                    S rV   ro   rX   s    r)   is_mapping_tru      rq   r+   TypeGuard[dict[object, object]]c                ,    t          | t                    S rV   )rJ   dictrX   s    r)   rN   rN          c4   r+   TypeGuard[list[object]]c                ,    t          | t                    S rV   )rJ   listrX   s    r)   rL   rL      ry   r+   TypeGuard[Iterable[object]]c                ,    t          | t                    S rV   )rJ   r
   rX   s    r)   is_iterabler      rh   r+   r(   c                    t          |           r1t          t          d |                                 D                       S t	          |           rt          t          d | D                       S | S )zMinimal reimplementation of copy.deepcopy() that will only copy certain object types:

    - mappings, e.g. `dict`
    - list

    This is done for performance reasons.
    c                4    i | ]\  }}|t          |          S r%   deepcopy_minimal)r&   kvs      r)   
<dictcomp>z$deepcopy_minimal.<locals>.<dictcomp>   s'    IIIDAq,Q//IIIr+   c                ,    g | ]}t          |          S r%   r   )r&   rR   s     r)   r*   z$deepcopy_minimal.<locals>.<listcomp>   s!    CCCU)%00CCCr+   )rp   r   r   itemsrL   )r(   s    r)   r   r      so     $ KBIIDJJLLIIIJJJt}} EBCCdCCCDDDKr+   z, or)delimfinalseqr   strr   c                   t          |           }|dk    rdS |dk    r| d         S |dk    r| d          d| d| d          S |                    | d d                   d| d| d          z   S )Nr   rC   rE   r    )rO   join)r   r   r   sizes       r)   
human_joinr      s    s88Dqyyrqyy1vqyya&++5++3q6+++::c#2#h"7e"7"7c"g"7"777r+   stringc                    d|  dS )zOAdd single quotation marks around the given string. Does *not* do any escaping.'r%   )r   s    r)   quoter      s    v===r+   variants Callable[[CallableT], CallableT]c                      d fd}|S )a4  Decorator to enforce a given set of arguments or variants of arguments are passed to the decorated function.

    Useful for enforcing runtime validation of overloaded functions.

    Example usage:
    ```py
    @overload
    def foo(*, a: str) -> str: ...


    @overload
    def foo(*, b: bool) -> str: ...


    # This enforces the same constraints that a static type checker would
    # i.e. that either a or b must be passed to the function
    @required_args(["a"], ["b"])
    def foo(*, a: str | None = None, b: bool | None = None) -> str: ...
    ```
    funcr   r!   c                     t          j                   j        }d |                                D             t	          j                   d fd            }|S )Nc                B    g | ]\  }}|j         |j        |j        hv |S r%   )kindPOSITIONAL_ONLYPOSITIONAL_OR_KEYWORD)r&   nameparams      r)   r*   z0required_args.<locals>.inner.<locals>.<listcomp>   sL     
 
 
ez%+    r+   argsr<   kwargsr!   c                 H  
 t                      
t          |           D ]g\  }}	 
                    |                    "# t          $ r9 t	          j         dt                     dt          |            d          d w xY w|                                D ]}
                    |           D ]!}t          
fd|D                       }|r nŌ"t                    dk    r t          d D                       }d| d}nt                    d	k    sJ t          t          d	                   
z
            }	t          |	          dk    rd
t          d |	D                        }ndt          |	d	                    }t	          |           | i |S )Nz	() takes z argument(s) but z were givenc              3      K   | ]}|v V  	d S rV   r%   )r&   r   given_paramss     r)   	<genexpr>z@required_args.<locals>.inner.<locals>.wrapper.<locals>.<genexpr>  s(      JJu4JJJJJJr+   rE   c                P    g | ]#}d t          d |D             d          z   dz   $S )(c                ,    g | ]}t          |          S r%   r   r&   args     r)   r*   zLrequired_args.<locals>.inner.<locals>.wrapper.<locals>.<listcomp>.<listcomp>  s    *I*I*I#5::*I*I*Ir+   and)r   ))r   )r&   variants     r)   r*   zArequired_args.<locals>.inner.<locals>.wrapper.<locals>.<listcomp>  sA    vvvbiz*I*I*I*I*IQVWWWWZ]]vvvr+   z,Missing required arguments; Expected either z arguments to be givenr   zMissing required arguments: c                ,    g | ]}t          |          S r%   r   r   s     r)   r*   zArequired_args.<locals>.inner.<locals>.wrapper.<locals>.<listcomp>  s    HgHgHgX[sHgHgHgr+   zMissing required argument: )set	enumerateaddrI   	TypeError__name__rO   keysallr   r|   r   )r   r   i_rD   r   matches
variationsmsgmissingr   r   
positionalr   s             @r)   wrapperz-required_args.<locals>.inner.<locals>.wrapper   s	   %(UUL!$    1  $$Z]3333!      #=kk3z??kkUXY]U^U^kkk   
 {{}} & &  %%%%# % %JJJJ'JJJKK E x==1$$!+vvmuvvv" "J lkkkCCx==1,,,, #3x{#3#3l#BCCG7||a''jZHgHg_fHgHgHg=h=hjjOE'!*<M<MOOnn$4((((s   AAB)r   r<   r   r<   r!   r<   )inspect	signature
parametersr   	functoolswraps)r   paramsr   r   r   s   `  @r)   innerzrequired_args.<locals>.inner   s    "4((3
 
%||~~
 
 

 
		!	) !	) !	) !	) !	) !	) !	) 
	!	)F r+   )r   r   r!   r   r%   )r   r   s   ` r)   required_argsr      s)    ,0 0 0 0 0 0d Lr+   _K_VNonec                    d S rV   r%   rX   s    r)   strip_not_givenr   )  s    (+r+   Mapping[_K, _V | NotGiven]dict[_K, _V]c                    d S rV   r%   rX   s    r)   r   r   -  s    FIcr+   c                    d S rV   r%   rX   s    r)   r   r   1  s    ,/Cr+   object | Nonec                h    | dS t          |           s| S d |                                 D             S )zHRemove all top-level keys where their values are instances of `NotGiven`Nc                D    i | ]\  }}t          |t                    ||S r%   rW   r&   rD   values      r)   r   z#strip_not_given.<locals>.<dictcomp>=  s-    XXX:3Juh<W<WXCXXXr+   )rp   r   rX   s    r)   r   r   5  s;    
{tc?? 
XXXXXXr+   valc                $    t          | d          S )N
   )base)r>   r   s    r)   coerce_integerr   @  s    sr+   floatc                     t          |           S rV   )r   r   s    r)   coerce_floatr   D  s    ::r+   boolc                &    | dk    p| dk    p| dk    S )Ntrue1onr%   r   s    r)   coerce_booleanr   H  s    &=5C3J5#+5r+   
int | Nonec                (    | d S t          |           S rV   )r   r   s    r)   maybe_coerce_integerr   L      
{t#r+   float | Nonec                (    | d S t          |           S rV   )r   r   s    r)   maybe_coerce_floatr   R  s    
{tr+   bool | Nonec                (    | d S t          |           S rV   )r   r   s    r)   maybe_coerce_booleanr   X  r   r+   prefixc                ^    |                      |          r| t          |          d         S | S )zXRemove a prefix from a string.

    Backport of `str.removeprefix` for Python < 3.9
    N)
startswithrO   )r   r   s     r)   removeprefixr   ^  s4    
    %c&kkmm$$Mr+   suffixc                `    |                      |          r| dt          |                    S | S )zXRemove a suffix from a string.

    Backport of `str.removesuffix` for Python < 3.9
    N)endswithrO   )r   r   s     r)   removesuffixr   h  s4    
 v &nVn%%Mr+   r   c                    t          |                                           }t          j                            |           }||fS rV   )r   
read_bytesosr9   basename)r9   contents	file_names      r)   file_from_pathr   r  s9    Dzz$$&&H  &&Ix  r+   headersr   headerc                   |                                 }t          |           rK|                                 D ]6\  }}|                                 |k    rt          |t                    r|c S 7t          j        dd |                                          }|||                                |fD ]}| 	                    |          }|r|c S t          d| d          )Nz([^\w])(\w)c                |    |                      d          |                      d                                          z   S )NrE   r   )groupupper)pats    r)   <lambda>z%get_required_header.<locals>.<lambda>  s,    #))A,,STI[I[I]I]:] r+   zCould not find z header)lowerru   r   rJ   r   resub
capitalizer  get
ValueError)r   r  lower_headerr   r   intercaps_headernormalized_headerr   s           r)   get_required_headerr  x  s    <<>>LG MMOO 	 	DAqwwyyL((Z3-?-?( vn.].]_e_p_p_r_rss$lFLLNNDTU  -.. 	LLL	 6v666
7
77r+   c                 L    	 t          j                    S # t          $ r Y dS w xY w)Nfalse)sniffiocurrent_async_library	Exceptionr%   r+   r)   get_async_libraryr    s8    ,...   wws    
##   maxsizer  c                V    t          j        |           }t          t          |          S )zmA version of functools.lru_cache that retains the type signature
    for the wrapped function arguments.
    r  )r   	lru_cacher   r   )r  r   s     r)   r  r    s0     !  G Wr+   datac                :   t          |           rd |                                 D             S t          |           r.t          | t          t
          t          f          sd | D             S t          | t          t          f          r| 	                                S | S )zvTranslates a mapping / sequence recursively in the same fashion
    as `pydantic` v2's `model_dump(mode="json")`.
    c                N    i | ]"\  }}t          |          t          |          #S r%   	json_safer   s      r)   r   zjson_safe.<locals>.<dictcomp>  s,    PPPZS%	#	% 0 0PPPr+   c                ,    g | ]}t          |          S r%   r   )r&   r(   s     r)   r*   zjson_safe.<locals>.<listcomp>  s    111D	$111r+   )
rp   r   r   rJ   r   bytes	bytearrayr   r   	isoformat)r  s    r)   r!  r!    s     $ QPP4::<<PPPP4 2D3y2I!J!J 211D1111$4())  ~~Kr+   clientTypeGuard[AzureOpenAI]c                .    ddl m} t          | |          S )Nr   )r   )	lib.azurer   rJ   )r&  r   s     r)   is_azure_clientr*    s$    ''''''fk***r+   TypeGuard[AsyncAzureOpenAI]c                .    ddl m} t          | |          S )Nr   )r   )r)  r   rJ   )r&  r   s     r)   is_async_azure_clientr-    s%    ,,,,,,f.///r+   )r   r    r!   r"   )r-   r.   r/   r0   r!   r1   )
r;   r<   r9   r=   r4   r>   r5   r?   r!   r1   )r;   rS   r!   rT   )r;   r<   r!   rZ   )r;   r`   r!   ra   )r;   r<   r!   rd   )r;   ri   r!   rj   )r;   r<   r!   rm   )r;   rr   r!   rs   )r;   r<   r!   rv   )r;   r<   r!   rz   )r;   r<   r!   r}   )r(   r   r!   r   )r   r=   r   r   r   r   r!   r   )r   r   r!   r   )r   r=   r!   r   )r;   r   r!   r   )r;   r   r!   r   )r;   r<   r!   r<   )r;   r   r!   r<   )r   r   r!   r>   )r   r   r!   r   )r   r   r!   r   )r   r?   r!   r   )r   r?   r!   r   )r   r?   r!   r   )r   r   r   r   r!   r   )r   r   r   r   r!   r   )r9   r   r!   r   )r   r   r  r   r!   r   )r!   r   )r  r   r!   r   )r  r<   r!   r<   )r&  r<   r!   r'  )r&  r<   r!   r+  )J
__future__r   r   r	  r   r   typingr   r   r   r   r   r	   r
   r   r   r   pathlibr   r   r   typing_extensionsr   r  _typesr   r   r   r   r   r<   r   r   r   r   r   r)  r   r   r,   r:   r7   rY   r^   rc   rg   rl   rp   ru   rN   rL   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r!  r*  r-  r%   r+   r)   <module>r3     s   " " " " " " 				 				                                   # # # # # # # # ' ' ' ' ' '  A A A A A A A A A A A AWT]]
')5#5
6
6
6GKwsF{';<<<	W\&)9:::
GKxS'9:::	 :999999997 7 7 7   &F F F FR) ) ) )" " " "" " " "% % % %% % % %$ $ $ $$ $ $ $! ! ! !! ! ! !% % % %     48d 8 8 8 8 8 8   
H H H HV WT]]WT]] 
 + + + 
 + 
 I I I 
 I 
 / / / 
 /Y Y Y Y      6 6 6 6               ! ! ! !8 8 8 8&    (+          + + + +0 0 0 0 0 0r+   