a
    ”˜ëj  ã                   @  sp   d Z ddlmZ ddlmZmZmZ ddlmZ ddl	m
Z
 ddlmZ er\ddlmZmZ G dd	„ d	e
ƒZd
S )ú(Callback Handler that prints to std out.é    )Úannotations)ÚTYPE_CHECKINGÚAnyÚOptional)Úoverride)ÚBaseCallbackHandler)Ú
print_text)ÚAgentActionÚAgentFinishc                	   @  s¾   e Zd ZdZd dddœdd„Zeddd	dd
œdd„ƒZedd	ddœdd„ƒZed!ddd	d	dœdd„ƒZed"d	dddd	ddœdd„ƒZ	ed#dddd	ddœdd„ƒZ
ed$ddd	ddœdd„ƒZdS )%ÚStdOutCallbackHandlerr   NzOptional[str]ÚNone)ÚcolorÚreturnc                 C  s
   || _ dS )zxInitialize callback handler.

        Args:
            color: The color to use for the text. Defaults to None.
        N©r   )Úselfr   © r   ú^/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/langchain_core/callbacks/stdout.pyÚ__init__   s    zStdOutCallbackHandler.__init__zdict[str, Any]r   )Ú
serializedÚinputsÚkwargsr   c                 K  sJ   d|v r|d }n$|r2|  d|  ddg¡d ¡}nd}td|› d�ƒ dS )zöPrint out that we are entering a chain.

        Args:
            serialized (dict[str, Any]): The serialized chain.
            inputs (dict[str, Any]): The inputs to the chain.
            **kwargs (Any): Additional keyword arguments.
        ÚnameÚidz	<unknown>éÿÿÿÿz

[1m> Entering new z chain...[0mN)ÚgetÚprint)r   r   r   r   r   r   r   r   Úon_chain_start   s    
z$StdOutCallbackHandler.on_chain_start)Úoutputsr   r   c                 K  s   t dƒ dS )zµPrint out that we finished a chain.

        Args:
            outputs (dict[str, Any]): The outputs of the chain.
            **kwargs (Any): Additional keyword arguments.
        z
[1m> Finished chain.[0mN)r   )r   r   r   r   r   r   Úon_chain_end.   s    z"StdOutCallbackHandler.on_chain_endr
   )Úactionr   r   r   c                 K  s   t |j|p| jd� dS )zîRun on agent action.

        Args:
            action (AgentAction): The agent action.
            color (Optional[str]): The color to use for the text. Defaults to None.
            **kwargs (Any): Additional keyword arguments.
        r   N©r	   Úlogr   )r   r    r   r   r   r   r   Úon_agent_action8   s    z%StdOutCallbackHandler.on_agent_action)Úoutputr   Úobservation_prefixÚ
llm_prefixr   r   c                 K  sJ   t |ƒ}|durtd|› �ƒ t||p*| jd� |durFtd|› �ƒ dS )a¸  If not the final action, print out observation.

        Args:
            output (Any): The output to print.
            color (Optional[str]): The color to use for the text. Defaults to None.
            observation_prefix (Optional[str]): The observation prefix.
                Defaults to None.
            llm_prefix (Optional[str]): The LLM prefix. Defaults to None.
            **kwargs (Any): Additional keyword arguments.
        NÚ
r   )Ústrr	   r   )r   r$   r   r%   r&   r   r   r   r   Úon_tool_endE   s    z!StdOutCallbackHandler.on_tool_endÚ r(   )Útextr   Úendr   r   c                 K  s   t ||p| j|d� dS )a*  Run when the agent ends.

        Args:
            text (str): The text to print.
            color (Optional[str]): The color to use for the text. Defaults to None.
            end (str): The end character to use. Defaults to "".
            **kwargs (Any): Additional keyword arguments.
        ©r   r,   N)r	   r   )r   r+   r   r,   r   r   r   r   Úon_text_   s    zStdOutCallbackHandler.on_textr   )Úfinishr   r   r   c                 K  s   t |j|p| jdd� dS )zïRun on the agent end.

        Args:
            finish (AgentFinish): The agent finish.
            color (Optional[str]): The color to use for the text. Defaults to None.
            **kwargs (Any): Additional keyword arguments.
        r'   r-   Nr!   )r   r/   r   r   r   r   r   Úon_agent_finishq   s    z%StdOutCallbackHandler.on_agent_finish)N)N)NNN)Nr*   )N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r#   r)   r.   r0   r   r   r   r   r      s*   	 ÿ   û  ü ÿr   N)r4   Ú
__future__r   Útypingr   r   r   Ztyping_extensionsr   Zlangchain_core.callbacks.baser   Zlangchain_core.utilsr	   Zlangchain_core.agentsr
   r   r   r   r   r   r   Ú<module>   s   