o
    Zh                     @   sP   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	 G dd de	Z
dS )    N)Union)AgentActionAgentFinish)OutputParserException)AgentOutputParserc                   @   s<   e Zd ZdZdedeeef fddZe	defddZ
dS )	ReActOutputParserz"Output parser for the ReAct agent.textreturnc                 C   s   d}|  dd |std| |  dd }|t|d  }td|}|d u r7td| |d|d}}|d	krMtd
|i|S t	|||S )NzAction: 
zCould not parse LLM Output: z(.*?)\[(.*?)\]z"Could not parse action directive:       ZFinishoutput)
stripsplit
startswithr   lenresearchgroupr   r   )selfr   Zaction_prefixZaction_blockZ
action_strZ
re_matchesactionZaction_input r   [/var/www/html/lang_env/lib/python3.10/site-packages/langchain/agents/react/output_parser.pyparse   s   zReActOutputParser.parsec                 C   s   dS )NZreactr   )r   r   r   r   _type    s   zReActOutputParser._typeN)__name__
__module____qualname____doc__strr   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   r   r   r   r   r   <module>   s    