
    g3fi@?                     6   d Z ddlZddl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
 ddlmZ ddlmZmZ ddlmZ ddlmZ ddlmZ dd	lmZmZ dd
lmZ ddlmZ deedf   defdZdeddfdZ ejB                  dej                  de	e"   fd       Z#ddddededz  dedz  defdZ$	 	 	 	 d>dededz  dedz  dedz  dedz  ddfdZ%dede&e   fdZ'd e(eef   d!e&e   de(eef   fd"Z)d#e(eef   d e(eef   d!e&e   de(eef   fd$Z*d%eez  defd&Z+ G d' d(      Z, e,       Z-ed)edeg ef   fd*       Z.ed)ed+edeg ef   fd,       Z.ed)e
e   d+edeg ef   fd-       Z.ed)ed.edeg ef   fd/       Z.ed)ee
e   z  d+ed.edz  deg ef   fd0       Z.ed)ed+dd.edz  deg edz  f   fd1       Z.ed)ee
e   z  d+ddeg edz  f   fd2       Z.e-dd3d)ee
e   z  d+ee,z  dz  d.edz  deg ef   eg edz  f   z  fd4Z.ed)ee
e   z  deg ef   fd5       Z/ed)ed+edeg ef   fd6       Z/ed)ee
e   z  d+ddeg edz  f   fd7       Z/ed)ed.edeg ef   fd8       Z/e-dd3d)ee
e   z  d+ee,z  dz  d.edz  deg edz  f   eg ef   z  fd9Z/d:Z0	 d;Z1	 d<edz  defd=Z2y)?zGeneric utility functions.    N)CallableIteratorSequence)version)Anyoverload)uuid4)parse	SecretStr)	HTTPErrorResponse)override)is_pydantic_v1_subclass
arg_groups.returnc                  ,     dt         dt         f fd}|S )zValidate specified keyword args are mutually exclusive.

    Args:
        *arg_groups: Groups of mutually exclusive keyword args.

    Returns:
        Decorator that validates the specified keyword args
        are mutually exclusive.
    funcr   c                 l     t        j                         dt        dt        dt        f fd       }|S )Nargskwargsr   c                  B   	D cg c]  }t        fd|D               }}t        |      D cg c]  \  }}|dk7  s| }}}|r@|D cg c]  }dj                  	|          }}ddj                  |       }t        |       
| i S c c}w c c}}w c c}w )z3Validate exactly one arg in each group is not None.c              3   F   K   | ]  }j                  |      d  y w)N   )get).0argr   s     X/var/www/auto_recruiter/arenv/lib/python3.12/site-packages/langchain_core/utils/utils.py	<genexpr>z?xor_args.<locals>.decorator.<locals>.wrapper.<locals>.<genexpr>(   s     J#fjjo.IAJs   !!r   z, zFExactly one argument in each of the following groups must be defined: )sum	enumeratejoin
ValueError)r   r   	arg_groupcountsicountinvalid_groupsinvalid_group_namesmsgr   r   s    `       r   wrapperz,xor_args.<locals>.decorator.<locals>.wrapper$   s    
 ", JJJF  1:&0APHAuUaZaPNPIW&XAtyyA'?&X#&X		"5679 
 !o%((( Q&Xs   BB BB)	functoolswrapsr   )r   r+   r   s   ` r   	decoratorzxor_args.<locals>.decorator#   s:    			)3 	)# 	)# 	) 
	)"     )r   )r   r.   s   ` r   xor_argsr0      s     X * r/   responsec                 t    	 | j                          y# t        $ r}t        | j                        |d}~ww xY w)zRaise an error with the response text.

    Args:
        response: The response to check for errors.

    Raises:
        ValueError: If the response has an error status code.
    N)raise_for_statusr   r#   text)r1   es     r   raise_for_status_with_textr6   ;   s4    /!!# /'Q./s    	727dt_valuec              #       K    G  fddt         j                         t         j                   }t         _         	 t         j                    |t         _         y# |t         _         w xY ww)a{  Context manager for mocking out datetime.now() in unit tests.

    Args:
        dt_value: The datetime value to use for datetime.now().

    Yields:
        The mocked datetime class.

    Example:
        ```python
        with mock_now(datetime.datetime(2011, 2, 3, 10, 11)):
            assert datetime.datetime.now() == datetime.datetime(2011, 2, 3, 10, 11)
        ```
    c                   X    e Zd ZdZeeddej                  dz  ddf fd              Zy)mock_now.<locals>.MockDateTimez3Mock datetime.datetime.now() with a fixed datetime.Ntzr   MockDateTimec           
           j                   j                  j                  j                  j                  j
                  j                  j                        S N)yearmonthdayhourminutesecondmicrosecondtzinfo)clsr;   r<   r7   s     r   nowz"mock_now.<locals>.MockDateTime.now^   sL      $$	 	r/   r>   )	__name__
__module____qualname____doc__classmethodr   datetimerF   rH   )r<   r7   s   r   r<   r:   [   s7    A			4/ 	> 	 
 
	r/   r<   N)rN   )r7   real_datetimer<   s   ` @r   mock_nowrP   J   sO     "x(( $ %%M$H*)Ms   8A+A A+A((A+)pip_namepackagemodule_namerQ   rR   c                    	 t        j                  | |      }|S # t        t        f$ rD}|xs& | j	                  dd      d   j                  dd      }d|  d| d	}t        |      |d
}~ww xY w)a~  Dynamically import a module.

    Raise an exception if the module is not installed.

    Args:
        module_name: The name of the module to import.
        pip_name: The name of the module to install with pip.
        package: The package to import the module from.

    Returns:
        The imported module.

    Raises:
        ImportError: If the module is not installed.
    .r   )maxsplitr   _-zCould not import z5 python package. Please install it with `pip install z`.N)	importlibimport_moduleImportErrorModuleNotFoundErrorsplitreplace)rS   rQ   rR   moduler5   r*   s         r   guard_importr`   u   s    $&((g> M ,- &V{00q0A!DLLSRUV} -33;*B@ 	 #A%&s    A-?A((A-
lt_versionlte_version
gt_versiongte_versionc                 f   t        t        |             }|%|t        |      k\  rd|  d| d| d}t        |      |%|t        |      kD  rd|  d| d| d}t        |      |%|t        |      k  rd|  d| d| d}t        |      |&|t        |      k  rd|  d| d| d}t        |      yy)	a  Check the version of a package.

    Args:
        package: The name of the package.
        lt_version: The version must be less than this.
        lte_version: The version must be less than or equal to this.
        gt_version: The version must be greater than this.
        gte_version: The version must be greater than or equal to this.


    Raises:
        ValueError: If the package version does not meet the requirements.
    Nz	Expected z version to be < z. Received rU   z version to be <= z version to be > z version to be >= )r
   r   r#   )rR   ra   rb   rc   rd   imported_versionr*   s          r   check_package_versionrg      s!   ( WW-."2eJ6G"Gy 1*[ # 	 o#3eK6H#Hy 2;-{ # 	 o"2eJ6G"Gy 1*[ # 	 o#3eK6H#Hy 2;-{ # 	 o $Ir/   pydantic_clsc                    t               }t        |       rd| j                  j                         D ]E  }|j	                  |j
                         |j                  s+|j	                  |j                         G |S | j                  j                         D ]>  \  }}|j	                  |       |j                  s$|j	                  |j                         @ |S )zGet field names, including aliases, for a pydantic class.

    Args:
        pydantic_cls: Pydantic class.

    Returns:
        Field names.
    )
setr   
__fields__valuesaddname	has_aliasaliasmodel_fieldsitems)rh   all_required_field_namesfieldrn   s       r   get_pydantic_field_namesru      s      #u|,!,,335 	:E$((4(,,U[[9	: $#	 (44::< 	:KD%$((.{{(,,U[[9	: $#r/   rl   rs   c           
         | j                  di       }t        |       D ]Q  }||v rd| d}t        |      ||vst        j                  d| d| d| dd	       | j                  |      ||<   S |j                  |j                               }|r6t        j                  d
| dd	       |D ]  }|j                  |      | |<    || d<   | S )a  Build `model_kwargs` param from Pydantic constructor values.

    Args:
        values: All init args passed in by user.
        all_required_field_names: All required field names for the pydantic class.

    Returns:
        Extra kwargs.

    Raises:
        ValueError: If a field is specified in both `values` and `extra_kwargs`.
        ValueError: If a field is specified in `model_kwargs`.
    model_kwargsFound  supplied twice.	WARNING! + is not default parameter.
                F was transferred to model_kwargs.
                Please confirm that  is what you intended.   
stacklevelParameters a should be specified explicitly. Instead they were passed in as part of `model_kwargs` parameter.)r   listr#   warningswarnpopintersectionkeys)rl   rs   extra_kwargs
field_namer*   invalid_model_kwargsks          r   _build_model_kwargsr      s   " ::nb1L6l >
%:,&67CS/!55MMj\ * %%/L0FJ 	 (.zz*'=L$> 4@@ARARATU./ 0O P	

 & 	,A$((+F1I	, *F>Mr/   r   c           
      (   t        |      D ]Q  }|| v rd| d}t        |      ||vst        j                  d| d| d| dd       |j	                  |      | |<   S |j                  | j                               }|rd	| d
}t        |      | S )a]  Build extra kwargs from values and extra_kwargs.

    !!! danger "DON'T USE"
        Kept for backwards-compatibility but should never have been public. Use the
        internal `_build_model_kwargs` function instead.

    Args:
        extra_kwargs: Extra kwargs passed in by user.
        values: Values passed in by user.
        all_required_field_names: All required field names for the pydantic class.

    Returns:
        Extra kwargs.

    Raises:
        ValueError: If a field is specified in both `values` and `extra_kwargs`.
        ValueError: If a field is specified in `model_kwargs`.
    rx   ry   rz   r{   r|   r}   r~   r   r   r   )r   r#   r   r   r   r   r   )r   rl   rs   r   r*   r   s         r   build_extra_kwargsr     s    0 6l >
%:,&67CS/!55MMj\ * %%/L0FJ 	 (.zz*'=L$> 4@@ARARATU./ 0O P 	 o r/   valuec                 <    t        | t              r| S t        |       S )zConvert a string to a SecretStr if needed.

    Args:
        value: The value to convert.

    Returns:
        The SecretStr value.
    )
isinstancer   )r   s    r   convert_to_secret_strr   9  s     %#Ur/   c                       e Zd ZdZy)_NoDefaultTypez.Type to indicate no default value is provided.N)rI   rJ   rK   rL    r/   r   r   r   G  s    8r/   r   keyc                     y r>   r   r   s    r   from_envr   N  s    03r/   defaultc                    y r>   r   r   r   s     r   r   r   R  s    ADr/   c                    y r>   r   r   s     r   r   r   V  s    KNr/   error_messagec                    y r>   r   r   r   s     r   r   r   Z  s    GJr/   c                    y r>   r   r   r   r   s      r   r   r   ^  s     r/   c                    y r>   r   r   s      r   r   r   d        #r/   c                    y r>   r   r   s     r   r   r   j  r   r/   )r   r   c               .     dt         dz  f fd}|S )a  Create a factory method that gets a value from an environment variable.

    Args:
        key: The environment variable to look up. If a list of keys is provided,
            the first key found in the environment will be used.
            If no key is found, the default value will be used if set,
            otherwise an error will be raised.
        default: The default value to return if the environment variable is not set.
        error_message: the error message which will be raised if the key is not found
            and no default value is provided.
            This will be raised as a ValueError.

    Returns:
        factory method that will look up the value from the environment.
    r   Nc                  x   t        t        t        f      r.D ])  } | t        j                  v st        j                  |    c S  t        t
              r%t        j                  v rt        j                     S t        t
        t        d      f      rS rt              d d d d}t        |      )zGet a value from an environment variable.

        Raises:
            ValueError: If the environment variable is not set and no default is
                provided.

        Returns:
            The value from the environment.
        NDid not find &, please add an environment variable `` which contains it, or pass `` as a named parameter.)r   r   tupleosenvironstrtyper#   r   r*   r   r   r   s     r   get_from_env_fnz!from_env.<locals>.get_from_env_fn  s     cD%=) )

?::a=() c3C2::$5::c?"gT$Z01N]++C5 ! ,. 	
 or/   )r   )r   r   r   r   s   ``` r   r   r   p  s    .S4Z 8 r/   c                     y r>   r   r   s    r   secret_from_envr     s    MPr/   c                    y r>   r   r   s     r   r   r     s    NQr/   c                    y r>   r   r   s     r   r   r     s     &)r/   c                    y r>   r   r   s     r   r   r     s    TWr/   c               .     dt         dz  f fd}|S )a  Secret from env.

    Args:
        key: The environment variable to look up.
        default: The default value to return if the environment variable is not set.
        error_message: the error message which will be raised if the key is not found
            and no default value is provided.
            This will be raised as a ValueError.

    Returns:
        factory method that will look up the secret from the environment.
    r   Nc                     t        t        t        f      r7D ]2  } | t        j                  v st        t        j                  |          c S  t        t              r.t        j                  v rt        t        j                           S t        t              rt              S yrt              d d d d}t        |      )zGet a value from an environment variable.

        Raises:
            ValueError: If the environment variable is not set and no default is
                provided.

        Returns:
            The secret from the environment.
        Nr   r   r   r   )r   r   r   r   r   r   r   r#   r   s     r   get_secret_from_envz,secret_from_env.<locals>.get_secret_from_env  s     cD%=) 4

?$RZZ]334 c3C2::$5RZZ_--gs#W%%?]++C5 ! ,. 	
 or/   r   )r   r   r   r   s   ``` r   r   r     s    (T!1 : r/   lc_zlc_run-id_valc                 .    | xs t          t                S )aT  Ensure the ID is a valid string, generating a new UUID if not provided.

    Auto-generated UUIDs are prefixed by `'lc_'` to indicate they are
    LangChain-generated IDs.

    Args:
        id_val: Optional string ID value to validate.

    Returns:
        A string ID, either the validated provided value or a newly generated UUID4.
    )LC_AUTO_PREFIXr	   )r   s    r   	ensure_idr     s     1'y11r/   )NNNN)3rL   
contextlibrN   r,   rY   r   r   collections.abcr   r   r   importlib.metadatar   typingr   r   uuidr	   packaging.versionr
   pydanticr   requestsr   r   typing_extensionsr   langchain_core.utils.pydanticr   r   r   r0   r6   contextmanagerr   rP   r`   rg   rj   ru   dictr   r   r   r   
_NoDefaultr   r   r   LC_ID_PREFIXr   r   r/   r   <module>r      s         	  8 8 &    #  ( &
 %S/  h  F/ /d / '*x(( '*Xd^ '* '*V 15D#&:?BTz@ ""!",,d
, t, d
	,
 t, 
,^$3 $3s8 $.*cN*!#h* 
#s(^*\/sCx./cN/ "#h/ 
#s(^	/dS Y 9 9 
 
 3# 3Xb#g. 3 
 3 
 D# Dc Dhr3w.? D 
 D 
 N(3- N NS8I N 
 N 
 J# JC JHRW4E J 
 J 
	x}	-0ADtb#g 

 
#	#!#25*#b#*n# 
#
 
#	x}	#-1#b#*n# 
# ,6 $3	x}	3 >!D(	3
 :3 b#g"cDj.113l 
 Px}, PHR]4K P 
 P 
 Q QS QXb)m5L Q 
 Q 
)	x}	)-1)b)d""#) 
)
 
 W W3 W8B	M;R W 
 W ,6 $1	x}	1 >!D(	1
 :1 b)d""#hr9}&==1h  I2cDj 2S 2r/   