
    f3fi.                        d Z ddlZddlZddlmZ ddlmZmZmZm	Z	 ddl
mZmZ ddlmZ ddlmZmZ  ej$                  e      Z G d d	e      Z G d
 de      Z G d de      Z G d de      ZdedededefdZdededefdZ G d dee      ZdedededefdZdeeef   deeef   deeef   fdZ de!defdZ"y) zSerializable base class.    N)ABC)AnyLiteral	TypedDictcast)	BaseModel
ConfigDict)	FieldInfo)NotRequiredoverridec                   \    e Zd ZU dZeed<   	 ee   ed<   	 ee   ed<   	 ee	ee
f      ed<   y)BaseSerializedz"Base class for serialized objects.lcidnamegraphN)__name__
__module____qualname____doc__int__annotations__liststrr   dictr        ^/var/www/auto_recruiter/arenv/lib/python3.12/site-packages/langchain_core/load/serializable.pyr   r      s=    ,G2S	M.
c
!tCH~&&"r   r   c                   8    e Zd ZU dZed   ed<   	 eeef   ed<   y)SerializedConstructorzSerialized constructor.constructortypekwargsN)	r   r   r   r   r   r   r   r   r   r   r   r   r    r    !   s$    !
-
  :cN$r   r    c                   "    e Zd ZU dZed   ed<   y)SerializedSecretzSerialized secret.secretr"   N)r   r   r   r   r   r   r   r   r   r%   r%   *   s    
(
5r   r%   c                   4    e Zd ZU dZed   ed<   	 edz  ed<   y)SerializedNotImplementedzSerialized not implemented.not_implementedr"   Nrepr)r   r   r   r   r   r   r   r   r   r   r(   r(   1   s!    %
#
$$>
*+r   r(   valuekeymodelreturnc                 J    t        |      j                  |   }t        | |      S )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)r+   r,   r-   fields       r   try_neq_defaultr3   :   s%     K$$S)EE5))r   r2   c                 2   	 t        |j                         | k7        S # t        $ ro}	 t        |j                         | k7        cY d }~S # t        $ r<}	 | |j                  ucY d }~cY d }~S # t        $ r}Y d }~Y d }~Y d }~yd }~ww xY wd }~ww xY wd }~ww xY w)NF)boolget_default	Exceptionalldefault)r+   r2   _s      r   r1   r1   I   s    	E%%'5011 	u((*e344 	EMM111 u	sb    	BA	B		BA+ B!B%B+	B4B	8BBB		BBBc                       e Zd ZdZdededdf fdZedefd       Zede	e
   fd       Zedee
e
f   fd	       Zedefd
       Zede	e
   fd       Z ed      Zedef fd       Zdeez  f fdZdefdZ xZS )Serializablea  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#   r.   Nc                 $    t        |   |i | y) N)super__init__)selfr=   r#   	__class__s      r   rA   zSerializable.__init__s   s    $)&)r   c                      y)aD  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_serializablezSerializable.is_lc_serializablew   s     r   c                 8    | j                   j                  d      S )a  Get 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   splitrE   s    r   get_lc_namespacezSerializable.get_lc_namespace   s     ~~##C((r   c                     i S )zxA map of constructor argument names to secret ids.

        For example, `{"openai_api_key": "OPENAI_API_KEY"}`
        r   rB   s    r   
lc_secretszSerializable.lc_secrets   s	     	r   c                     i S )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   rM   s    r   lc_attributeszSerializable.lc_attributes   s	     	r   c                     d| j                   v r)| j                   d   | j                   d   j                  }n| j                  }g | j                         |S )a4  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   rK   )rF   original_names     r   lc_idzSerializable.lc_id   s[     99911(;G==hGPPMLLM7%%'777r   ignore)extrac           	          t         |          D cg c]-  \  }}|t        |       j                  vst	        |||       r||f/ c}}S c c}}w )N)r@   __repr_args__r"   r0   r3   )rB   kvrC   s      r   rY   zSerializable.__repr_args__   sR     -/
1d000OAq$4O F
 	
 
s   2A	c                 |   | j                         s| j                         S t        |       j                  }i }i }| D ]7  \  }}t	        | ||      s||v r||   j
                  r(t        | ||      ||<   9 dg| j                  j                         D ]  }|t        u r n|r5ddg}|D ],  }t        ||      sd| j                   d| d}	t        |	       t        d|| nt        ||             }
|j                  |
j                         t!        |      D ]$  }||   }||v s||   j"                  x}	  |||<   & |j                  |
j$                          |D ]8  }t        | |d      xs |j'                  |      }|&|j                  ||i       : dd	| j)                         |s|d
S t+        ||      d
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.r<      r!   )r   r"   r   r#   )rG   to_json_not_implementedr"   r0   _is_field_usefulexcludegetattrrC   mror<   hasattr
ValueErrorr   r@   updaterN   r   aliasrP   getrU   _replace_secrets)rB   r0   secrets	lc_kwargsrZ   r[   rF   deprecated_attributesattrmsgthisr,   r+   rh   secret_valuerC   s                  r   to_jsonzSerializable.to_json   s     &&(//11Dz..	 	/DAq#D!Q/L \!_%<%<"4A.IaL	/ 04>>--/0 "	1Cl""%)%
 2 .DsD)$T^^$4 5))- /34 
 )o-. sDAQRDNN4??+
 G} +<')#.444E. &+GEN+ T//0E"	1L  	6C"4d3Iy}}S7IL'  #|!45	6 !**,  	
 	
 ")W5
 	
r   c                     t        |       S )zhSerialize a "not implemented" object.

        Returns:
            `SerializedNotImplemented`.
        )r`   rM   s    r   r`   z$Serializable.to_json_not_implemented  s     't,,r   )r   r   r   r   r   rA   classmethodr5   rG   r   r   rK   propertyr   rN   rP   rU   r	   model_configr   rY   r    r(   rr   r`   __classcell__)rC   s   @r   r<   r<   X   s   4*c *S *T * 
4 
 
 	)c 	) 	) DcN   t   8d3i 8 8& L 
s 
 
L
.1II L
\-)A -r   r<   instc                 p   t        |       j                  j                  |      }|sy|j                         ry	 t	        |      }|ry|j                  t        u rt        |t              ry|j                  t        u rt        |t              ryt        ||      }|xs |S # t
        $ r}d}Y d}~kd}~ww xY w)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"   r0   ri   is_requiredr5   r7   default_factoryr   
isinstancer   r1   )rx   r,   r+   r2   value_is_truthyr:   value_neq_defaults          r   ra   ra     s     J##'',E u+  $E4)@ $E4)@(6 ///#    s   B   	B5)B00B5rootsecrets_mapc                     | j                         }|j                         D ]R  \  }}|j                  d      ^ }}|}|D ]#  }||vr n||   j                         ||<   ||   }% ||v sIdd|gd||<   T |S )NrI   r_   r&   )r   r"   r   )copyitemsrJ   )	r   r   resultpath	secret_idpartslastcurrentparts	            r   rj   rj   F  s     YY[F&,,. iC% 	$D7"#DM..0GDMdmG		$
 7?  kGDM Mr   objc                    g }	 t        | d      r*g | j                  j                  d      | j                  }nIt        | d      r=g | j                  j                  j                  d      | j                  j                  }dd|d	d
}t        j                  t
              5  t        |       |d<   d	d	d	       |S # t
        $ r t        j                  dd       Y [w xY w# 1 sw Y   |S xY w)zSerialize a "not implemented" object.

    Args:
        obj: Object to serialize.

    Returns:
        `SerializedNotImplemented`
    r   rI   rC   zFailed to serialize objectT)exc_infor_   r)   N)r   r"   r   r*   r*   )re   r   rJ   r   rC   r7   loggerdebug
contextlibsuppressr*   )r   id_r   s      r   r`   r`   [  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   A?B< #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   r5   r3   r1   r<   ra   r   rj   objectr`   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   