
    D_i%H                    ^   S r SSKJr  SSKrSSKrSSKrSSKJr  SSKJ	r	J
r
  SSKJr  SSKJrJrJrJrJr  SSKrSSKJr  SS	KJrJrJrJrJrJr  SS
KJr  SSKJr   SSK!J"r"J#r#J$r$J%r%  SSK&Jr'  SS
K&Jr(  SSK)J*r*J+r+  \(       a  SSK,J-r-  SSK.J/r/  SSK0J1r1  \Rd                  " \Rf                  5      r4\*" S5      S5S j5       r5\4Rl                  r7\4Rp                  r9Sr:Sr;\r<\=\   r>\" S\<S9r?S6S jr@S6S jrAS6S jrBS7S jrCS8S jrD " S S\#5      rESSS.           S9S  jjrFSSS.           S:S! jjrGSSS.           S;S" jjrH\S<S# j5       rI\S=S$ j5       rI\S>S% j5       rI\S?S& j5       rI    S@S' jrI\" SSS(S)9rJ\K" 5       rLS\L4         SAS* jjrM\	" S+S,9S\LS-.         SBS. jj5       rN\	" S+S,9      SCS/ j5       rO SD       SES0 jjr\P" \5       V s1 s H  o R                  S15      (       a  M  U iM     sn rRSFS2 jrSSSSS3.         SGS4 jjrTgs  sn f )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                 "    [         R                  $ )zDEPRECATED - Get the major version of Pydantic.

Use PYDANTIC_VERSION.major instead.

Returns:
    The major version of Pydantic.
)PYDANTIC_VERSIONmajor     W/home/james-whalen/.local/lib/python3.13/site-packages/langchain_core/utils/pydantic.pyget_pydantic_major_versionr%   6   s     !!!r#   FT
TBaseModel)boundc                "    [        U [        5      $ )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                "    [        U [        5      $ )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                    [         R                  " U 5      (       a  [        U [        5      (       a  g[	        U [
        [        45      $ )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   `   s4     ??3:c<#@#@cI{344r#   c                .    [        U [        [        45      $ )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                   ^  [         R                  " 5          [         R                  " S[        S9  [	        SS9[        T 5      SU 4S jj5       5       nSSS5        U$ ! , (       d  f       W$ = f)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                  > U R                   nUR                  5        GH+  u  p4[        U S5      (       ac  [        U R                  S5      (       aH  U R                  R                  (       a-  UR
                  U;   a  UR                  UR
                  5      X'   [        U S5      (       aM  U R                  R                  S5      (       a-  UR
                  U;   a  UR                  UR
                  5      X'   X1;  d  X   b  M  UR                  5       (       a  M  UR                  b  UR                  5       X'   GM  UR                  X'   GM.     T" X5      $ )zDecorator 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$   wrapperpre_init.<locals>.wrapper   s    %%F$*LLN  C**

,LMM

AA"((F2#)::j.>.>#?FLC00((,,-?@@"((F2#)::j.>.>#?FL &&,*>$0022!11='1'A'A'C'1'9'9/ %34 $$r#   N)r,   type[BaseModel]rL   dict[str, Any]returnr	   )warningscatch_warningsfilterwarningsr   r   r   )rP   rQ   s   ` r$   pre_initrY      sf     
	 	 	"x:TU
 
D	!	t&	% 
 
"&	% 
#` Na 
#	"` Ns   <A
A,c                  8    \ rS rSrSr\      SS j5       rSrg)_IgnoreUnserializable   zA JSON schema generator that ignores unknown types.

https://docs.pydantic.dev/latest/concepts/json_schema/#customizing-the-json-schema-generation-process
c                    0 $ Nr"   )selfschema
error_infos      r$   handle_invalid_for_json_schema4_IgnoreUnserializable.handle_invalid_for_json_schema   s	     	r#   r"   N)r`   zcore_schema.CoreSchemara   strrU   r   )__name__
__module____qualname____firstlineno____doc__r   rb   __static_attributes__r"   r#   r$   r[   r[      s3    
 ,:=	 r#   r[   descriptionsfn_descriptionc                  0 nU H}  nUR                   U   nUR                  (       a  UR                  (       d  UR                  OUR                  S-  nU(       a  Xc;   a  X6   UR                  l        XR                  4XV'   M     [        S[        U 40 UD65      n	[        R                  " U=(       d    UR                  =(       d    S5      U	l
        U	$ )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dedentri   )
rN   modelfield_namesrl   rm   rM   
field_namefieldtrtns
             r$   _create_subset_model_v1r      s     F!
  , ~~e&6&6 ""T)	 	
 J6+7+CE(!1!12 " "OD$CF$C
DC//."GEMM"GRHCKJr#   c               X   U=(       d    0 n0 nU Hr  nUR                   U   nUR                  XxR                  5      n	[        XR                  S9n
UR
                  (       a  UR
                  U
l        UR                  U
4Xg'   Mt     [        S[        U 40 UDS[        SS90D65      nUR                  R                  5        V Vs/ s H  u  pX;   d  M  X4PM     nn n[        U5      Ul
        [        R                  " U=(       d    UR                  =(       d    S5      Ul        U$ s  snn f )z:Create a Pydantic model with a subset of the model fields.)ru   rK   rS   
__config__Tarbitrary_types_allowedrp   )rC   rH   ru   FieldInfoV2rK   metadata
annotationr   _create_model_baser   __annotations__rD   dictrw   rx   ri   )rN   ry   rz   rl   rm   descriptions_rM   r{   r|   ru   rO   r~   r   selected_annotationss                 r$   _create_subset_model_v2r      s    !&BMF!
"":.#''
4E4EF [--P
>>"'..J#..
; " 	
	
'1$'O	
C !& 5 5 ; ; = =D 	 =   34C//."GEMM"GRHCKJs   D&D&c               `    [        U[        5      (       a  [        U UUUUS9$ [        U UUUUS9$ )zpCreate subset model using the same pydantic version as the input model.

Returns:
    The created subset model.
rk   )r)   r*   r   r   )rN   ry   rz   rl   rm   s        r$   _create_subset_modelr     sK     %%%&%)
 	
 #!% r#   c                    g r^   r"   ry   s    r$   
get_fieldsr   2  s    BEr#   c                    g r^   r"   r   s    r$   r   r   6  s    <?r#   c                    g r^   r"   r   s    r$   r   r   :  s    CFr#   c                    g r^   r"   r   s    r$   r   r   >  s    =@r#   c                    [        U [        5      (       d  [        U 5      n [        U [        5      (       a  U R                  $ [        U [
        5      (       a  U R                  $ SU  3n[        U5      e)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*   rq   	TypeError)ry   msgs     r$   r   r   B  sb     eT""U%##!!!%%%+E7
3C
C.r#   r"   )r   frozenprotected_namespacesc                R  ^  S[         4       SU 4S jjjnS[         [        S4           SU 4S jjjnSU0[        SS9[        U5      [        U5      U=(       d    SS	.nU[        La  X6S'   [
        R                  " 5           [        U[        5      (       aC  [        U[        5      (       d.  [        U[        5      (       a  [
        R                  " S
[        S9  [        T [        4U5      nSSS5        [!        SW5      $ ! [         a     N2f = f! , (       d  f       N*= f)zCreate a base class.Tc                Z   > [        S[        X 5      5      nUR                  XS9nTUS'   U$ )Nro   )by_aliasref_templatetitle)r   superr`   )r,   r   r   	super_clsschema_rN   s        r$   r`   "_create_root_model.<locals>.schemaf  s8    
 ,eCo>	""H"Pr#   
validationrS   c                `   > [        S[        X 5      5      nUR                  UUUUS9nTUS'   U$ )NrS   )r   r   schema_generatormoder   )r   r   model_json_schema)r,   r   r   r   r   r   r   rN   s          r$   r   -_create_root_model.<locals>.model_json_schemap  sH     *E#O<	--%-	 . 
  r#   rootr   zlangchain_core.runnables.utils)r   rA   r`   r   rf   r9   r:   N)r,   ro   r   boolr   rd   rU   rT   )r,   rS   r   r   r   rd   r   ztype[GenerateJsonSchema]r   r   rU   rT   )r   r   r   classmethod
NO_DEFAULTrV   rW   r3   r   r   r)   r*   rX   r   r   r   r   )rN   type_module_namedefault_r`   r   base_class_attributescustom_root_types   `       r$   _create_root_modelr   ^  sa    0  
	  05G+  3	
  
 $ #E?"4@f%():;!E%E z!(0f%		 	 	"
	5$''"5,77uk22''#.H
  yl4IJ 
# !#344  		 
#	"s1   D
AD"D
DDDD
D&   )maxsize)r   r   c                   [        XX2S9$ )N)r   r   )r   )
model_namer   r   r   s       r$   _create_root_model_cachedr     s     H r#   c               8    [        U 4S[        0[        U5      D6$ )Nr   )r   _SchemaConfig_remap_field_definitions)r   field_definitionss     r$   _create_model_cachedr     s,       ##4
5 r#   c               X    0 nSU;   a  UR                  S5      US'   [        U 4UUS.UD6$ )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                l   0 nU R                  5        H  u  p#UR                  S5      (       d
  U[        ;   at  [        U[        5      (       a  S[         SU S3n[        U5      eUu  pVU[        UUUUR                  S5      R                  SS5      R                  5       S94USU 3'   M  X1U'   M     U$ )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'--/
>>##"8%--00?/@ ADDG5K 
 *#..#OE$(+**S/11#s;AAC	*Hxu%& "SM+ 0, Or#   )r   r   r   c          	        U=(       d    0 nU(       aM  U(       a  SU 3n[        U5      e[        U[        5      (       a  US   US   S.nOSU0n [        U 4SU0UD6nU$ [        UR                  5       5      nSnU H  n	U	R                  S5      (       d  M  S	nM     U(       a  [        R                  " 5       O	[        5          U(       a  [        R                  " S
S9   [        U 40 UD6sSSS5        $ ! [         a    [        U 4SU0UD6n U$ f = f! [         a'    [        U 4S[        0[!        U5      D6s sSSS5        $ f = f! , (       d  f       g= f)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   Fry   Tr9   )r;   Nr   )r   r3   tupler   r   r   setkeysr   rV   rW   r   rX   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	I##84	'
H6GH	 
J	I'  	1 '   
  	0  	%( ++<=  
J	I
	 
J	Is<   C6 E	!D6DD%E:E	EE		
E)rU   int)r,   r   rU   r   )r6   r	   rU   r   )rP   r   rU   r	   )rN   rd   ry   ro   rz   listrl   dict | Nonerm   
str | NonerU   ro   )rN   rd   ry   rS   rz   	list[str]rl   r   rm   r   rU   rS   )rN   rd   ry   TypeBaseModelrz   r   rl   r   rm   r   rU   rS   )ry   rS   rU   dict[str, FieldInfoV2])ry   r   rU   r   )ry   ro   rU   dict[str, ModelField])ry   r*   rU   r   )ry   z7type[BaseModel | BaseModelV1] | BaseModel | BaseModelV1rU   z.dict[str, FieldInfoV2] | dict[str, ModelField])
rN   rd   r   r	   r   r   r   objectrU   rS   )
r   rd   r   r	   r   r   r   r   rU   rS   )r   rd   r   r	   rU   rS   r^   )r   rd   r   r   r   r	   rU   rS   )r   rT   rU   rT   )
r   rd   r   r   r   zdict[str, Any] | Noner   z
Any | NonerU   rS   )Uri   
__future__r   r1   rw   rV   
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*   rv   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   rY   r[   r   r   r   r   r   r   r   r   r   r   dirr   r   r   r   )r   s   0r$   <module>r      s    "    " &      5  1 7 2(-)==!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.L.3s8K3.L> #/3HH H -	H
 H H? Ms   *H*H*