
    D_i.                        S r SSKrSSKrSSKJr  SSKJrJrJrJ	r	  SSK
JrJr  SSKJr  SSKJrJr  \R$                  " \5      r " S S	\5      r " S
 S\5      r " S S\5      r " S S\5      rS\S\S\S\4S jrS\S\S\4S jr " S S\\5      rS\S\S\S\4S jrS\\\4   S\\\4   S\\\4   4S jr S\!S\4S jr"g) zSerializable base class.    N)ABC)AnyLiteral	TypedDictcast)	BaseModel
ConfigDict)	FieldInfo)NotRequiredoverridec                   d    \ rS rSr% Sr\\S'    \\   \S'    \	\   \S'    \	\
\\4      \S'   Srg)	BaseSerialized   z"Base class for serialized objects.lcidnamegraph N)__name__
__module____qualname____firstlineno____doc__int__annotations__liststrr   dictr   __static_attributes__r       Z/home/james-whalen/.local/lib/python3.13/site-packages/langchain_core/load/serializable.pyr   r      s=    ,G2S	M.
c
!tCH~&&"r    r   c                   @    \ rS rSr% Sr\S   \S'    \\\	4   \S'   Sr
g)SerializedConstructor!   zSerialized constructor.constructortypekwargsr   N)r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r#   r#   !   s$    !
-
  :cN$r    r#   c                   *    \ rS rSr% Sr\S   \S'   Srg)SerializedSecret*   zSerialized secret.secretr&   r   N)r   r   r   r   r   r   r   r   r   r    r!   r)   r)   *   s    
(
5r    r)   c                   <    \ rS rSr% Sr\S   \S'    \S-  \S'   Srg)SerializedNotImplemented1   zSerialized not implemented.not_implementedr&   Nreprr   )	r   r   r   r   r   r   r   r   r   r   r    r!   r-   r-   1   s!    %
#
$$>
*+r    r-   valuekeymodelreturnc                 H    [        U5      R                  U   n[        X5      $ )zTry to determine if a value is different from the default.

Args:
    value: The value.
    key: The key.
    model: The Pydantic model.

Returns:
    Whether the value is different from the default.
)r&   model_fields_try_neq_default)r1   r2   r3   fields       r!   try_neq_defaultr9   :   s#     K$$S)EE))r    r8   c                 6    [        UR                  5       U :g  5      $ ! [         ap  n [        UR                  5       U :g  5      s S nA$ ! [         a<  n XR                  Ls S nAs S nA$ ! [         a  n S nA S nA S nAgS nAff = fS nAff = fS nAff = f)NF)boolget_default	Exceptionalldefault)r1   r8   _s      r!   r7   r7   I   s    	E%%'5011 	u((*e344 	MM111 u	sb    
BA
B

BA,!B"B&B,
B6B:BBBBBBc                     ^  \ rS rSrSrS\S\SS4U 4S jjr\S\4S j5       r	\S\
\   4S	 j5       r\S\\\4   4S
 j5       r\S\4S j5       r\S\
\   4S j5       r\" SS9r\S\4U 4S jj5       rS\\-  4U 4S jjrS\4S jrSrU =r$ )SerializableX   a  Serializable base class.

This class is used to serialize objects to JSON.

It relies on the following methods and properties:

- [`is_lc_serializable`][langchain_core.load.serializable.Serializable.is_lc_serializable]: Is this class serializable?

    By design, even if a class inherits from `Serializable`, it is not serializable
    by default. This is to prevent accidental serialization of objects that should
    not be serialized.
- [`get_lc_namespace`][langchain_core.load.serializable.Serializable.get_lc_namespace]: Get the namespace of the LangChain object.

    During deserialization, this namespace is used to identify
    the correct class to instantiate.

    Please see the `Reviver` class in `langchain_core.load.load` for more details.
    During deserialization an additional mapping is handle classes that have moved
    or been renamed across package versions.

- [`lc_secrets`][langchain_core.load.serializable.Serializable.lc_secrets]: A map of constructor argument names to secret ids.
- [`lc_attributes`][langchain_core.load.serializable.Serializable.lc_attributes]: List of additional attribute names that should be included
    as part of the serialized representation.
argsr'   r4   Nc                 &   > [         TU ]  " U0 UD6  g) N)super__init__)selfrD   r'   	__class__s      r!   rH   Serializable.__init__s   s    $)&)r    c                     g)a  Is this class serializable?

By design, even if a class inherits from `Serializable`, it is not serializable
by default. This is to prevent accidental serialization of objects that should
not be serialized.

Returns:
    Whether the class is serializable. Default is `False`.
Fr   clss    r!   is_lc_serializableSerializable.is_lc_serializablew   s     r    c                 8    U R                   R                  S5      $ )zGet the namespace of the LangChain object.

For example, if the class is [`langchain.llms.openai.OpenAI`][langchain_openai.OpenAI],
then the namespace is `["langchain", "llms", "openai"]`

Returns:
    The namespace.
.)r   splitrM   s    r!   get_lc_namespaceSerializable.get_lc_namespace   s     ~~##C((r    c                     0 $ )zhA map of constructor argument names to secret ids.

For example, `{"openai_api_key": "OPENAI_API_KEY"}`
r   rI   s    r!   
lc_secretsSerializable.lc_secrets   s	     	r    c                     0 $ )zList of attribute names that should be included in the serialized kwargs.

These attributes must be accepted by the constructor.

Default is an empty dictionary.
r   rW   s    r!   lc_attributesSerializable.lc_attributes   s	     	r    c                     SU R                   ;   a*  U R                   S   b  U R                   S   R                  nOU R                  n/ U R                  5       QUP$ )a  Return a unique identifier for this class for serialization purposes.

The unique identifier is a list of strings that describes the path
to the object.

For example, for the class `langchain.llms.openai.OpenAI`, the id is
`["langchain", "llms", "openai", "OpenAI"]`.
origin)__pydantic_generic_metadata__r   rT   )rN   original_names     r!   lc_idSerializable.lc_id   s[     99911(;G==hGPPMLLM7%%'777r    ignore)extrac           	         > [         TU ]  5        VVs/ s H4  u  pU[        U 5      R                  ;  d  [	        X!U 5      (       d  M1  X4PM6     snn$ s  snnf )N)rG   __repr_args__r&   r6   r9   )rI   kvrJ   s      r!   rf   Serializable.__repr_args__   sS     -/
/d000OA$4O QF/
 	
 
s   0AAc                   > U R                  5       (       d  U R                  5       $ [        U 5      R                  n0 n0 nU  H@  u  pE[	        XU5      (       d  M  XA;   a  X   R
                  (       a  M2  [        XU5      X4'   MB     S/U R                  R                  5       Q H  nU[        L a    OU(       a;  SS/nU H1  n[        Xh5      (       d  M  SU R                   SU S3n	[        U	5      e   [        SUc  U O
[        X`5      5      n
UR                  U
R                  5        [!        U5       H&  nX+   nX;   d  M  X   R"                  =n c  M"  XU'   M(     UR                  U
R$                  5        M     U H>  n[        XS5      =(       d    UR'                  U5      nUc  M,  UR                  X05        M@     SS	U R)                  5       U(       d  US
.$ [+        X25      S
.$ )zSerialize the object to JSON.

Raises:
    ValueError: If the class has deprecated attributes.

Returns:
    A JSON serializable object or a `SerializedNotImplemented` object.
Nlc_namespacelc_serializablezClass z has a deprecated attribute z3. Please use the corresponding classmethod instead.rB      r%   )r   r&   r   r'   )rO   to_json_not_implementedr&   r6   _is_field_usefulexcludegetattrrJ   mrorB   hasattr
ValueErrorr   rG   updaterX   r   aliasr[   getra   _replace_secrets)rI   r6   secrets	lc_kwargsrg   rh   rN   deprecated_attributesattrmsgthisr2   r1   rv   secret_valuerJ   s                  r!   to_jsonSerializable.to_json   s    &&((//11Dz..	DA#DQ// \_%<%<"4A.IL  04>>--/0Cl""%)%
 2Ds))$T^^$4 5))- /34 
 )o- 2 sAQRDNN4??+
 G}').444E. &+EN % T//0E 1L C"4d3Iy}}S7IL'  #!45  !**,  	
 	
 ")5
 	
r    c                     [        U 5      $ )zPSerialize a "not implemented" object.

Returns:
    `SerializedNotImplemented`.
)rn   rW   s    r!   rn   $Serializable.to_json_not_implemented  s     't,,r    r   )r   r   r   r   r   r   rH   classmethodr;   rO   r   r   rT   propertyr   rX   r[   ra   r	   model_configr   rf   r#   r-   r   rn   r   __classcell__)rJ   s   @r!   rB   rB   X   s   4*c *S *T * 
4 
 
 	)c 	) 	) DcN   t   8d3i 8 8& L 
s 
 
L
.1II L
\-)A - -r    rB   instc                    [        U 5      R                  R                  U5      nU(       d  gUR                  5       (       a  g [	        U5      nU(       a  gUR                  [        L a  [        U[        5      (       a  gUR                  [        L a  [        U[        5      (       a  g[        X#5      nU=(       d    U$ ! [
         a  nSn SnANSnAff = f)a  Check if a field is useful as a constructor argument.

Args:
    inst: The instance.
    key: The key.
    value: The value.

Returns:
    Whether the field is useful. If the field is required, it is useful.
    If the field is not required, it is useful if the value is not `None`.
    If the field is not required and the value is `None`, it is useful if the
    default value is different from the value.
FTN)r&   r6   rw   is_requiredr;   r=   default_factoryr   
isinstancer   r7   )r   r2   r1   r8   value_is_truthyr@   value_neq_defaults          r!   ro   ro     s     J##'',E u+  $E4)@)@ $E4)@)@(6 ///#    s   B? ?
C	CCrootsecrets_mapc                     U R                  5       nUR                  5        HR  u  p4UR                  S5      Gt pVUnU H"  nX;  a    OXx   R                  5       Xx'   Xx   nM$     Xg;   d  MI  SSU/S.Xv'   MT     U$ )NrR   rm   r+   )r   r&   r   )copyitemsrS   )	r   r   resultpath	secret_idpartslastcurrentparts	            r!   rx   rx   F  s     YY[F&,,.C%D"#M..0GMmG	 
 ?  kGM / Mr    objc                    / n [        U S5      (       a*  / U R                  R                  S5      QU R                  PnON[        U S5      (       a=  / U R                  R                  R                  S5      QU R                  R                  PnSSUS	S
.n[        R                  " [
        5         [        U 5      US'   S	S	S	5        U$ ! [
         a    [        R                  SSS9   NZf = f! , (       d  f       U$ = f)ztSerialize a "not implemented" object.

Args:
    obj: Object to serialize.

Returns:
    `SerializedNotImplemented`
r   rR   rJ   zFailed to serialize objectT)exc_inform   r/   N)r   r&   r   r0   r0   )rs   r   rS   r   rJ   r=   loggerdebug
contextlibsuppressr0   )r   id_r   s      r!   rn   rn   [  s     CB3
##<CNN((-<s||<CS+&&PCMM,,2237P9O9OPC
 !	(F 
		Y	'cv 
(M  B1DAB 
(	'Ms#   :C AC .C+C('C(+
C:)#r   r   loggingabcr   typingr   r   r   r   pydanticr   r	   pydantic.fieldsr
   typing_extensionsr   r   	getLoggerr   r   r   r#   r)   r-   r   r;   r9   r7   rB   ro   r   rx   objectrn   r   r    r!   <module>r      s        + % 3			8	$
#Y 
#%N %6~ 6,~ ,*3 *S * *t *C 	 d ~-9c ~-B*0< *0c *0# *0$ *0Z
sCx.'+CH~	#s(^* ,D r    