
    g3fi%H                    &   d Z 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	m
Z
 ddlmZ ddlmZmZmZmZmZ ddlZddlmZ dd	lmZmZmZmZmZmZ dd
lmZ ddlmZ  ddl!m"Z"m#Z#m$Z$m%Z% ddl&mZ' dd
l&mZ( ddl)m*Z*m+Z+ erddl,m-Z- ddl.m/Z/ ddl0m1Z1  ejd                  ejf                        Z4 e*d      d5d       Z5e4jl                  Z7e4jp                  Z9dZ:dZ;eZ<e=e   Z> ede<      Z?d6dZ@d6dZAd6dZBd7dZCd8dZD G d de#      ZEddd	 	 	 	 	 	 	 	 	 	 	 d9d ZFddd	 	 	 	 	 	 	 	 	 	 	 d:d!ZGddd	 	 	 	 	 	 	 	 	 	 	 d;d"ZHed<d#       ZIed=d$       ZIed>d%       ZIed?d&       ZI	 	 	 	 d@d'ZI eddd()      ZJ eK       ZLdeLf	 	 	 	 	 	 	 	 	 dAd*ZM e	d+,      deLd-	 	 	 	 	 	 	 	 	 dBd.       ZN e	d+,      	 	 	 	 	 	 dCd/       ZO	 dD	 	 	 	 	 	 	 dEd0Z ePe      D  ch c]  } | j                  d1      r|  c} ZRdFd2ZSdddd3	 	 	 	 	 	 	 	 	 dGd4ZTyc c} w )HzUtilities for pydantic.    )annotationsN)nullcontext)	lru_cachewraps)GenericAlias)TYPE_CHECKINGAnyTypeVarcastoverload)version)	BaseModel
ConfigDictFieldPydanticDeprecationWarning	RootModelroot_validator)create_model)	FieldInfo)DEFAULT_REF_TEMPLATEGenerateJsonSchemaJsonSchemaModeJsonSchemaValue)r   )
deprecatedoverride)Callable)
ModelField)core_schemaz#Use PYDANTIC_VERSION.major instead.c                 "    t         j                  S )zDEPRECATED - Get the major version of Pydantic.

    Use PYDANTIC_VERSION.major instead.

    Returns:
        The major version of Pydantic.
    )PYDANTIC_VERSIONmajor     [/var/www/auto_recruiter/arenv/lib/python3.12/site-packages/langchain_core/utils/pydantic.pyget_pydantic_major_versionr%   6   s     !!!r#   FT
TBaseModel)boundc                "    t        | t              S )zCheck if the given class is Pydantic v1-like.

    Returns:
        `True` if the given class is a subclass of Pydantic `BaseModel` 1.x.
    )
issubclassBaseModelV1clss    r$   is_pydantic_v1_subclassr-   N   s     c;''r#   c                "    t        | t              S )zCheck if the given class is Pydantic v2-like.

    Returns:
        `True` if the given class is a subclass of Pydantic `BaseModel` 2.x.
    )r)   r   r+   s    r$   is_pydantic_v2_subclassr/   W   s     c9%%r#   c                z    t        j                  |       rt        | t              ryt	        | t
        t        f      S )a:  Check if the given class is a subclass of Pydantic `BaseModel`.

    Check if the given class is a subclass of any of the following:

    * `pydantic.BaseModel` in Pydantic 2.x
    * `pydantic.v1.BaseModel` in Pydantic 2.x

    Returns:
        `True` if the given class is a subclass of Pydantic `BaseModel`.
    F)inspectisclass
isinstancer   r)   r   r*   r+   s    r$   is_basemodel_subclassr4   `   s.     ??3:c<#@cI{344r#   c                .    t        | t        t        f      S )a=  Check if the given class is an instance of Pydantic `BaseModel`.

    Check if the given class is an instance of any of the following:

    * `pydantic.BaseModel` in Pydantic 2.x
    * `pydantic.v1.BaseModel` in Pydantic 2.x

    Returns:
        `True` if the given class is an instance of Pydantic `BaseModel`.
    )r3   r   r*   )objs    r$   is_basemodel_instancer7   r   s     cI{344r#   c                     t        j                         5  t        j                  dt               t	        d      t               d fd              }ddd       |S # 1 sw Y   S xY w)zDecorator to run a function before model initialization.

    Args:
        func: The function to run before model initialization.

    Returns:
        The decorated function.
    ignoreactioncategoryT)prec                d   | j                   }|j                         D ]  \  }}t        | d      rXt        | j                  d      rB| j                  j                  r,|j
                  |v r|j                  |j
                        ||<   t        | d      rG| j                  j                  d      r,|j
                  |v r|j                  |j
                        ||<   ||vs||   |j                         r|j                  |j                         ||<   |j                  ||<   
  | |      S )a  Decorator to run a function before model initialization.

            Args:
                cls: The model class.
                values: The values to initialize the model with.

            Returns:
                The values to initialize the model with.
            Configallow_population_by_field_namemodel_configpopulate_by_name)model_fieldsitemshasattrr?   r@   aliaspoprA   getis_requireddefault_factorydefault)r,   valuesfieldsname
field_infofuncs        r$   wrapperzpre_init.<locals>.wrapper   s    %%F$*LLN : j C*

,LM

AA"((F2#)::j.>.>#?F4LC0((,,-?@"((F2#)::j.>.>#?F4L &&,*>$002!11='1'A'A'Ct'1'9'9t/:4 V$$r#   N)r,   type[BaseModel]rL   dict[str, Any]returnr	   )warningscatch_warningsfilterwarningsr   r   r   )rP   rQ   s   ` r$   pre_initrX      sh     
	 	 	" .%x:TU
 
D	!	t&	% 
 
"&	%.%` Na.%` Ns   ?AA)c                  .    e Zd ZdZe	 	 	 	 	 	 dd       Zy)_IgnoreUnserializablezA JSON schema generator that ignores unknown types.

    https://docs.pydantic.dev/latest/concepts/json_schema/#customizing-the-json-schema-generation-process
    c                    i S Nr"   )selfschema
error_infos      r$   handle_invalid_for_json_schemaz4_IgnoreUnserializable.handle_invalid_for_json_schema   s	     	r#   N)r^   zcore_schema.CoreSchemar_   strrT   r   )__name__
__module____qualname____doc__r   r`   r"   r#   r$   rZ   rZ      s3    
 ,:=	 r#   rZ   descriptionsfn_descriptionc               v   i }|D ]o  }|j                   |   }|j                  r|j                  s|j                  n|j                  dz  }|r||v r||   |j                  _        ||j                  f||<   q t        dt        | fi |      }	t        j                  |xs |j                  xs d      |	_
        |	S )z=Create a Pydantic model with only a subset of model's fields.Ntype[BaseModelV1] )
__fields__required
allow_noneouter_type_rO   descriptionr   create_model_v1textwrapdedentre   )
rN   modelfield_namesrg   rh   rM   
field_namefieldtrtns
             r$   _create_subset_model_v1rz      s     F! 3
  , ~~e&6&6 ""T)	 	
 J,6+7
+CE(!1!12z3 "OD$CF$C
DC//."GEMM"GRHCKJr#   c               4   |xs i }i }|D ]r  }|j                   |   }|j                  ||j                        }	t        |	|j                        }
|j
                  r|j
                  |
_        |j                  |
f||<   t t        dt        | fi |dt        d      i      }|j                  j                         D  cg c]  \  } }| |v r| |f }} }t        |      |_
        t        j                  |xs |j                  xs d      |_        |S c c}} w )z:Create a Pydantic model with a subset of the model fields.)rp   rK   rR   
__config__Tarbitrary_types_allowedrk   )rC   rH   rp   FieldInfoV2rK   metadata
annotationr   _create_model_baser   __annotations__rD   dictrr   rs   re   )rN   rt   ru   rg   rh   descriptions_rM   rv   rw   rp   rO   ry   r   selected_annotationss                 r$   _create_subset_model_v2r      s)    !&BMF! <
"":.#''
E4E4EF [%--P
>>"'..J#..
;z< 	
	
'1$'O	
C !& 5 5 ; ; =D*; 
z  34C//."GEMM"GRHCKJs   Dc               b    t        |t              rt        | ||||      S t        | ||||      S )z|Create subset model using the same pydantic version as the input model.

    Returns:
        The created subset model.
    rf   )r)   r*   rz   r   )rN   rt   ru   rg   rh   s        r$   _create_subset_modelr     sH     %%&%)
 	
 #!% r#   c                     y r\   r"   rt   s    r$   
get_fieldsr   2  s    BEr#   c                     y r\   r"   r   s    r$   r   r   6  s    <?r#   c                     y r\   r"   r   s    r$   r   r   :  s    CFr#   c                     y r\   r"   r   s    r$   r   r   >  s    =@r#   c                    t        | t              st        |       } t        | t              r| j                  S t        | t
              r| j                  S d|  }t        |      )zReturn the field names of a Pydantic model.

    Args:
        model: The Pydantic model or instance.

    Raises:
        TypeError: If the model is not a Pydantic model.
    zExpected a Pydantic model. Got )r3   typer)   r   rC   r*   rl   	TypeError)rt   msgs     r$   r   r   B  sY     eT"U%#!!!%%+E7
3C
C.r#   r"   )r~   frozenprotected_namespacesc                    dt         f	 	 	 	 	 	 	 d fd}dt         t        df	 	 	 	 	 	 	 	 	 	 	 d fd}d|it        d      t        |      t        |      |xs dd	}|t        ur||d<   t        j                         5  	 t        |t              r;t        |t              s+t        |t              rt        j                  d
t               t         t        f|      }ddd       t!        d      S # t        $ r Y 1w xY w# 1 sw Y   $xY w)zCreate a base class.Tc                d    t        dt        | |             }|j                  ||      }|d<   |S )Nrj   )by_aliasref_templatetitle)r   superr^   )r,   r   r   	super_clsschema_rN   s        r$   r^   z"_create_root_model.<locals>.schemaf  s<    
 ,eCo>	""H<"Pr#   
validationrR   c                h    t        dt        | |             }|j                  ||||      }|d<   |S )NrR   )r   r   schema_generatormoder   )r   r   model_json_schema)r,   r   r   r   r   r   r   rN   s          r$   r   z-_create_root_model.<locals>.model_json_schemap  sJ     *E#sO<	--%-	 . 
  r#   rootr}   zlangchain_core.runnables.utils)r   rA   r^   r   rc   r9   r:   N)r,   rj   r   boolr   ra   rT   rS   )r,   rR   r   r   r   ra   r   ztype[GenerateJsonSchema]r   r   rT   rS   )r   r   r   classmethod
NO_DEFAULTrU   rV   r3   r   r   r)   r*   rW   r   r   r   r   )rN   type_module_namedefault_r^   r   base_class_attributescustom_root_types   `       r$   _create_root_modelr   ^  s\    0  
	 05G+  3	
  
$ #E?"4@f%():;!E%E z!(0f%		 	 	" K
	5$'"5,7uk2''#.H
  yl4IJK !#344  		K Ks1   ?DAC2D2	C>;D=C>>DD
   )maxsize)r   r   c                    t        | |||      S )N)r   r   )r   )
model_namer   r   r   s       r$   _create_root_model_cachedr     s     EH+ r#   c               8    t        | fdt        it        |      S )Nr|   )r   _SchemaConfig_remap_field_definitions)r   field_definitionss     r$   _create_model_cachedr     s,       ##4
5 r#   c               T    i }d|v r|j                  d      |d<   t        | f||d|S )a  Create a Pydantic model with the given field definitions.

    Please use `create_model_v2` instead of this function.

    Args:
        model_name: The name of the model.
        module_name: The name of the module where the model is defined.
            This is used by Pydantic to resolve any forward references.
        **field_definitions: The field definitions for the model.

    Returns:
        The created model.
    __root__r   )r   r   )rG   create_model_v2)r   r   r   kwargss       r$   r   r     sK    & F&&*..z:v+ 	 r#   _c                Z   i }| j                         D ]  \  }}|j                  d      s|t        v rrt        |t              rdt         d| d}t        |      |\  }}|t        ||||j                  d      j                  dd      j                               f|d| <   |||<    |S )zDThis remaps fields to avoid colliding with internal pydantic fields.r   zVRemapping for fields starting with '_' or fields with a name matching a reserved name zB is not supported if  the field is a pydantic Field instance. Got . )rK   rF   serialization_aliasr   private_)
rD   
startswith_RESERVED_NAMESr3   r   NotImplementedErrorr   lstripreplacer   )r   remappedkeyvaluer   r   r   s          r$   r   r     s    H'--/ "
U>>##"8%-00?/@ ADDG5K 
 *#..#OE8$(+**S/11#s;AAC	*Hxu%& "HSM+", Or#   )r   r   r   c          	     \   |xs i }|rC|rd| }t        |      t        |t              r|d   |d   d}nd|i}	 t        | fd|i|}|S t        |j                               }d}|D ]  }	|	j                  d      sd	} |rt        j                         n	t               5  |rt        j                  d
       	 t        | fi |cddd       S # t        $ r t        | fd|i|}Y |S w xY w# t        $ r' t        | fdt        it!        |      cY cddd       S w xY w# 1 sw Y   yxY w)a  Create a Pydantic model with the given field definitions.

    Attention:
        Please do not use outside of langchain packages. This API
        is subject to change at any time.

    Args:
        model_name: The name of the model.
        module_name: The name of the module where the model is defined.
            This is used by Pydantic to resolve any forward references.
        field_definitions: The field definitions for the model.
        root: Type for a root model (`RootModel`)

    Returns:
        The created model.
    zAWhen specifying __root__ no other fields should be provided. Got r      )r   r   r   r   Frt   Tr9   )r;   Nr|   )r   r3   tupler   r   r   setkeysr   rU   rV   r   rW   r   r   r   r   )
r   r   r   r   r   r   named_root_modelnamescapture_warningsrN   s
             r$   r   r     s   . */R22C1DF  &c**dE"#AwDG<Ft_F
	8 (3 7=    !&&()E $??7##$
 '7	 	 	"KM ##84	'
H6GH	 '  	1 '   
  	0  	%( ++<=  
	 s;   C "D"<C/C,+C,/$DD"DD""D+)rT   int)r,   r   rT   r   )r6   r	   rT   r   )rP   r   rT   r	   )rN   ra   rt   rj   ru   listrg   dict | Nonerh   
str | NonerT   rj   )rN   ra   rt   rR   ru   	list[str]rg   r   rh   r   rT   rR   )rN   ra   rt   TypeBaseModelru   r   rg   r   rh   r   rT   rR   )rt   rR   rT   dict[str, FieldInfoV2])rt   r   rT   r   )rt   rj   rT   dict[str, ModelField])rt   r*   rT   r   )rt   z7type[BaseModel | BaseModelV1] | BaseModel | BaseModelV1rT   z.dict[str, FieldInfoV2] | dict[str, ModelField])
rN   ra   r   r	   r   r   r   objectrT   rR   )
r   ra   r   r	   r   r   r   r   rT   rR   )r   ra   r   r	   rT   rR   r\   )r   ra   r   r   r   r	   rT   rR   )r   rS   rT   rS   )
r   ra   r   r   r   zdict[str, Any] | Noner   z
Any | NonerT   rR   )Ure   
__future__r   r1   rr   rU   
contextlibr   	functoolsr   r   typesr   typingr   r	   r
   r   r   pydantic	packagingr   r   r   r   r   r   r   r   r   pydantic.fieldsr   r   pydantic.json_schemar   r   r   r   pydantic.v1r*   rq   typing_extensionsr   r   collections.abcr   pydantic.v1.fieldsr   pydantic_corer   parse__version__r    r%   r!   PYDANTIC_MAJOR_VERSIONminorPYDANTIC_MINOR_VERSIONIS_PYDANTIC_V1IS_PYDANTIC_V2PydanticBaseModelr   r   r&   r-   r/   r4   r7   rX   rZ   rz   r   r   r   r   r   r   r   r   r   dirr   r   r   r   )r   s   0r$   <module>r      s    "    " &      5  1 7 2(-) 7==!5!56  12" 3" *// )//  Y\):;
(&5$59x
. 
$ !%!%
 
   D !%!%&
&& &
 & & &d !%!%
 
   < 
 E 
 E 
 ? 
 ? 
 F 
 F 
 @ 
 @B3*  B X
 #!	:5
:5:5 :5 	:5
 :5z 3
 #!			 		
 	 	 	 3		 	 		 	 # 	
 R #&i.L3s8K3L> #/3HH H -	H
 H H? Ms   H0H