
    f3fi$A                    4   d 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 ddlmZ ddlmZmZ dd	lmZ erdd
lmZ ddlmZ ddlmZ ddlmZ 	 	 	 	 ddZ G d de       Z! G d de      Z"	 	 	 	 	 	 ddZ# G d de"      Z$ddZ%ddZ&ddd dZ'y)!zBase message.    )annotations)TYPE_CHECKINGAnycastoverload)
ConfigDictField)warn_deprecated)Serializable)get_bolded_text)merge_dictsmerge_lists)is_interactive_env)Sequence)SelfcontentChatPromptTemplateBaseMessagec                n    t        | di       }|j                  d      }|t        |t              rd|dS y)al  Extract `reasoning_content` from `additional_kwargs`.

    Handles reasoning content stored in various formats:
    - `additional_kwargs["reasoning_content"]` (string) - Ollama, DeepSeek, XAI, Groq

    Args:
        message: The message to extract reasoning from.

    Returns:
        A `ReasoningContentBlock` if reasoning content is found, None otherwise.
    additional_kwargsreasoning_contentN	reasoning)typer   )getattrget
isinstancestr)messager   r   s      Z/var/www/auto_recruiter/arenv/lib/python3.12/site-packages/langchain_core/messages/base.py)_extract_reasoning_from_additional_kwargsr"      sE      )<bA)--.AB$4Es)K#2CDD    c                  $    e Zd ZdZdZddZddZy)TextAccessoraf  String-like object that supports both property and method access patterns.

    Exists to maintain backward compatibility while transitioning from method-based to
    property-based text access in message objects. In LangChain <v1.0, message text was
    accessed via `.text()` method calls. In v1.0=<, the preferred pattern is property
    access via `.text`.

    Rather than breaking existing code immediately, `TextAccessor` allows both
    patterns:
    - Modern property access: `message.text` (returns string directly)
    - Legacy method access: `message.text()` (callable, emits deprecation warning)

     c                .    t         j                  | |      S )z!Create new TextAccessor instance.)r   __new__)clsvalues     r!   r(   zTextAccessor.__new__@   s    {{3&&r#   c                4    t        ddd       t        |       S )a  Enable method-style text access for backward compatibility.

        This method exists solely to support legacy code that calls `.text()`
        as a method. New code should use property access (`.text`) instead.

        !!! deprecated
            As of `langchain-core` 1.0.0, calling `.text()` as a method is deprecated.
            Use `.text` as a property instead. This method will be removed in 2.0.0.

        Returns:
            The string content, identical to property access.

        z1.0.0z`Calling .text() as a method is deprecated. Use .text as a property instead (e.g., message.text).z2.0.0)sincer    removal)r
   r   selfs    r!   __call__zTextAccessor.__call__D   s&     	H 	
 4yr#   N)r*   r   returnr   )r1   r   )__name__
__module____qualname____doc__	__slots__r(   r0   r&   r#   r!   r%   r%   /   s     I'r#   r%   c                  ~    e Zd ZU dZded<   	  ee      Zded<   	  ee      Zded<   	 ded	<   	 d
Z	ded<   	  ed
d      Z
ded<   	  ed      Ze	 	 	 	 	 	 dd       Ze	 	 d	 	 	 	 	 	 	 dd       Z	 	 d	 	 	 	 	 	 	 d fdZedd       Zed d       Zed!d       Zed"d       Zd#dZ	 d$	 	 	 d%dZd&dZ xZS )'r   a  Base abstract message class.

    Messages are the inputs and outputs of a chat model.

    Examples include [`HumanMessage`][langchain.messages.HumanMessage],
    [`AIMessage`][langchain.messages.AIMessage], and
    [`SystemMessage`][langchain.messages.SystemMessage].
    str | list[str | dict]r   )default_factorydictr   response_metadatar   r   Nz
str | NonenameT)defaultcoerce_numbers_to_stridallow)extrac                     y Nr&   )r/   r   kwargss      r!   __init__zBaseMessage.__init__   s    
 r#   c                     y rC   r&   )r/   r   content_blocksrD   s       r!   rE   zBaseMessage.__init__   s     r#   c                P    |t        |   dd|i| yt        |   dd|i| y)a.  Initialize a `BaseMessage`.

        Specify `content` as positional arg or `content_blocks` for typing.

        Args:
            content: The contents of the message.
            content_blocks: Typed standard content.
            **kwargs: Additional arguments to pass to the parent class.
        Nr   r&   )superrE   )r/   r   rG   rD   	__class__s       r!   rE   zBaseMessage.__init__   s5     %G>^>v>G7W77r#   c                     y)zJ`BaseMessage` is serializable.

        Returns:
            True
        Tr&   r)   s    r!   is_lc_serializablezBaseMessage.is_lc_serializable   s     r#   c                
    g dS )zwGet the namespace of the LangChain object.

        Returns:
            `["langchain", "schema", "messages"]`
        )	langchainschemamessagesr&   rL   s    r!   get_lc_namespacezBaseMessage.get_lc_namespace   s
     32r#   c                B   ddl m} ddlm} ddlm} ddlm} ddlm	} ddl
m} g }t        | j                  t              r| j                  r| j                  gn| j                  }|D ]  }	t        |	t              r|j                  d|	d	       (t        |	t              s9|	j!                  d
      }
|
|j"                  vr|j                  d|	d       md|	v r|j                  d|	d       |j                  t%        d|	              |||||fD ]
  } ||      } |S )ztLoad content blocks from the message content.

        !!! version-added "Added in `langchain-core` 1.0.0"

        r   r   )#_convert_to_v1_from_anthropic_input)"_convert_to_v1_from_converse_input)_convert_to_v1_from_genai_input)"_convert_v0_multimodal_input_to_v1)*_convert_to_v1_from_chat_completions_inputtext)r   rY   r   non_standard)r   r*   source_typeztypes.ContentBlock)langchain_core.messagesr   3langchain_core.messages.block_translators.anthropicrT   :langchain_core.messages.block_translators.bedrock_converserU   6langchain_core.messages.block_translators.google_genairV   6langchain_core.messages.block_translators.langchain_v0rW   0langchain_core.messages.block_translators.openairX   r   r   appendr:   r   KNOWN_BLOCK_TYPESr   )r/   typesrT   rU   rV   rW   rX   blocksr   item	item_typeparsing_steps               r!   rG   zBaseMessage.content_blocks   s$    	=	
	
	
	
	
 ,. $,,, \\N	 	  	DD$$vt<=D$' HHV,	E$;$;; MM>D"IJ %,~&MN  MM$';T"BC%	D. /6/+.
 	*L "&)F	* r#   c                l   t        | j                  t              r| j                  }t        |      S | j                  D cg c]G  }t        |t              s3|j                  d      dk(  r!t        |j                  d      t              r|I }}dj	                  d |D              }t        |      S c c}w )a3  Get the text content of the message as a string.

        Can be used as both property (`message.text`) and method (`message.text()`).

        Handles both string and list content types (e.g. for content blocks). Only
        extracts blocks with `type: 'text'`; other block types are ignored.

        !!! deprecated
            As of `langchain-core` 1.0.0, calling `.text()` as a method is deprecated.
            Use `.text` as a property instead. This method will be removed in 2.0.0.

        Returns:
            The text content of the message.

        r   rY    c              3  J   K   | ]  }t        |t              r|n|d      yw)rY   N)r   r   ).0blocks     r!   	<genexpr>z#BaseMessage.text.<locals>.<genexpr>"  s'      !GLE3/U6]B!s   !#)r   r   r   r   joinr%   )r/   
text_valuerm   re   s       r!   rY   zBaseMessage.text  s    " dllC(J J'' "\\eS)IIf%/Juyy?PRU4V F   !PV! J J''s    AB1c                D    ddl m}  || g      }|j                  |      S )zConcatenate this message with another message.

        Args:
            other: Another message to concatenate with this one.

        Returns:
            A ChatPromptTemplate containing both messages.
        r   r   )rQ   )langchain_core.prompts.chatr   __add__)r/   otherr   prompts       r!   rs   zBaseMessage.__add__'  s#     	C#dV4~~e$$r#   c                    t        | j                  j                         dz   |      }| j                  |d| j                   z  }| d| j                   S )a  Get a pretty representation of the message.

        Args:
            html: Whether to format the message as HTML. If `True`, the message will be
                formatted with HTML tags.

        Returns:
            A pretty representation of the message.

        z Messageboldz
Name: z

)get_msg_title_reprr   titler<   r   )r/   htmlrz   s      r!   pretty_reprzBaseMessage.pretty_repr6  sT     #499??#4z#AM99 x		{++ET\\N++r#   c                J    t        | j                  t                            y)z-Print a pretty representation of the message.)r{   N)printr|   r   r.   s    r!   pretty_printzBaseMessage.pretty_printJ  s    d$6$89:r#   )r   r8   rD   r   r1   None)NN)r   zstr | list[str | dict] | NonerG   zlist[types.ContentBlock] | NonerD   r   r1   r   )r1   bool)r1   z	list[str])r1   zlist[types.ContentBlock])r1   r%   )rt   r   r1   r   )F)r{   r   r1   r   )r1   r   )r2   r3   r4   r5   __annotations__r	   r:   r   r;   r<   r?   r   model_configr   rE   classmethodrM   rR   propertyrG   rY   rs   r|   r   __classcell__)rJ   s   @r!   r   r   ]   s    $#&#D9t9 $D9t9I
I D* 4tDB
D L '  
	   26:>. 8 	
 
  26:>8.8 88 	8
 
8(   3 3 = =~ ( (>%" ,, 
,(;r#   c                @   | dn| }|D ]  }t        |t              rt        |t              r||z  })|g|}/t        |t              rt        t	        d|      |      }V|r!t        |d   t              r|dxx   |z  cc<   y|dk(  r|s|j                  |        |S )zMerge multiple message contents.

    Args:
        first_content: The first `content`. Can be a string or a list.
        contents: The other `content`s. Can be a string or a list.

    Returns:
        The merged content.

    rj   list)r   r   r   r   r   rb   )first_contentcontentsmergedr   s       r!   merge_contentr   O  s     !(RmF #fc"'3''! !+7+& ff!5w?F 
6":s32J'!J]MM'"-#. Mr#   c                      e Zd ZdZddZy)BaseMessageChunkzCMessage chunk, which can be concatenated with other Message chunks.c           
        t        |t              r| j                  | j                  | j                  t        | j                  |j                        t        | j                  |j                        t        | j                  |j                              S t        |t              rt        d |D              rvt        | j                  gd |D         }t        | j                  gd |D         }t        | j                  gd |D         }| j                  | j                  |||      S d| j                  j                   d|j                  j                   d	}t        |      )
a  Message chunks support concatenation with other message chunks.

        This functionality is useful to combine message chunks yielded from
        a streaming model into a complete message.

        Args:
            other: Another message chunk to concatenate with this one.

        Returns:
            A new message chunk that is the concatenation of this message chunk
            and the other message chunk.

        Raises:
            TypeError: If the other object is not a message chunk.

        Example:
            ```txt
              AIMessageChunk(content="Hello", ...)
            + AIMessageChunk(content=" World", ...)
            = AIMessageChunk(content="Hello World", ...)
            ```
        )r?   r   r   r   r;   c              3  <   K   | ]  }t        |t                y wrC   )r   r   rl   os     r!   rn   z+BaseMessageChunk.__add__.<locals>.<genexpr>  s      +
01Jq*++
s   c              3  4   K   | ]  }|j                     y wrC   r   r   s     r!   rn   z+BaseMessageChunk.__add__.<locals>.<genexpr>  s     3M!AII3M   c              3  4   K   | ]  }|j                     y wrC   )r   r   s     r!   rn   z+BaseMessageChunk.__add__.<locals>.<genexpr>       )M!!*=*=)Mr   c              3  4   K   | ]  }|j                     y wrC   )r;   r   s     r!   rn   z+BaseMessageChunk.__add__.<locals>.<genexpr>  r   r   )r?   r   r   r;   z$unsupported operand type(s) for +: "z" and "")r   r   rJ   r?   r   r   r   r   r   r;   r   allr2   	TypeError)r/   rt   r   r   r;   msgs         r!   rs   zBaseMessageChunk.__add__}  sa   . e-. >>77YY%dllEMMB"-**E,C,C# #.**E,C,C# " 
 
 eT"s +
5:+
 (
 $DLLN3Mu3MNG +&&!)Mu)M! !,&&!)Mu)M! >>77"3"3	 "   3~~&&'eoo../q2 	
 nr#   N)rt   r   r1   r   )r2   r3   r4   r5   rs   r&   r#   r!   r   r   z  s
    M;r#   r   c                <    | j                   | j                         dS )zConvert a Message to a dictionary.

    Args:
        message: Message to convert.

    Returns:
        Message as a dict. The dict will have a `type` key with the message type
        and a `data` key with the message data as a dict.

    )r   data)r   
model_dump)r    s    r!   message_to_dictr     s     LL'*<*<*>??r#   c                >    | D cg c]  }t        |       c}S c c}w )zConvert a sequence of Messages to a list of dictionaries.

    Args:
        messages: Sequence of messages (as `BaseMessage`s) to convert.

    Returns:
        List of messages as dicts.

    )r   )rQ   ms     r!   messages_to_dictr     s     )111OA111s   Frw   c                   d| z   dz   }dt        |      z
  dz  }d|z  }t        |      dz  r|dz   n|}|rt        |      }| | | S )zGet a title representation for a message.

    Args:
        title: The title.
        bold: Whether to bold the title.

    Returns:
        The title representation.

     P      =)lenr   )rz   rx   paddedsep_lensep
second_seps         r!   ry   ry     sc     5[3FCKA%G
-C!&kAos3J (U6(:,''r#   N)r    r   r1   z"types.ReasoningContentBlock | None)r   r8   r   r8   r1   r8   )r    r   r1   r:   )rQ   zSequence[BaseMessage]r1   z
list[dict])rz   r   rx   r   r1   r   )(r5   
__future__r   typingr   r   r   r   pydanticr   r	   langchain_core._api.deprecationr
    langchain_core.load.serializabler   langchain_core.utilsr   langchain_core.utils._merger   r   $langchain_core.utils.interactive_envr   collections.abcr   typing_extensionsr   r\   r   rd   rr   r   r"   r   r%   r   r   r   r   r   ry   r&   r#   r!   <module>r      s     " 5 5 & ; 9 0 @ C(&8>'.+3 +\o;, o;d()(%( (V>{ >B@
2 49 (r#   