a
    •˜ëjh  ã                   @   s\   d dl Z d dlmZ d dlmZmZ d dlmZ d dlm	Z	 d dl
mZ G dd„ de	ƒZdS )	é    N)ÚUnion)ÚAgentActionÚAgentFinish)ÚOutputParserException)ÚAgentOutputParser)ÚFORMAT_INSTRUCTIONSc                   @   sb   e Zd ZU dZdZeed< eZeed< edœdd„Z	ee
eef dœd	d
„Zeedœdd„ƒZdS )ÚConvoOutputParserz+Output parser for the conversational agent.ZAIÚ	ai_prefixÚformat_instructions)Úreturnc                 C   s   | j S )z<Returns formatting instructions for the given output parser.)r
   ©Úself© r   úl/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/langchain/agents/conversational/output_parser.pyÚget_format_instructions   s    z)ConvoOutputParser.get_format_instructions)Útextr   c                 C   s�   | j › d�|v r4td| | j › d�¡d  ¡ i|ƒS d}t ||tj¡}|s`d|› d�}t|ƒ‚| d¡}| d¡}t	| ¡ | d	¡ d
¡|ƒS )zËParse the output from the agent into an AgentAction or AgentFinish object.

        Args:
            text: The text to parse.

        Returns:
            An AgentAction or AgentFinish object.
        ú:Úoutputéÿÿÿÿz)Action: (.*?)[\n]*Action Input: ([\s\S]*)zCould not parse LLM output: `ú`é   é   ú ú")
r	   r   ÚsplitÚstripÚreÚsearchÚDOTALLr   Úgroupr   )r   r   ÚregexÚmatchÚmsgÚactionZaction_inputr   r   r   Úparse   s    	þ

zConvoOutputParser.parsec                 C   s   dS )NZconversationalr   r   r   r   r   Ú_type/   s    zConvoOutputParser._typeN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r	   ÚstrÚ__annotations__r   r
   r   r   r   r   r$   Úpropertyr%   r   r   r   r   r      s   
r   )r   Útypingr   Zlangchain_core.agentsr   r   Zlangchain_core.exceptionsr   Zlangchain.agents.agentr   Z&langchain.agents.conversational.promptr   r   r   r   r   r   Ú<module>   s   