a
    aŠÝgˆ  ã                   @   sl   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 dZdZd	Zd
ZG dd„ de	ƒZdS )é    N)ÚUnion)ÚAgentActionÚAgentFinish)ÚOutputParserException)ÚAgentOutputParser)ÚFORMAT_INSTRUCTIONSzFinal Answer:z1Invalid Format: Missing 'Action:' after 'Thought:z7Invalid Format: Missing 'Action Input:' after 'Action:'zHParsing LLM output produced both a final answer and a parse-able action:c                   @   sV   e Zd ZU dZ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 )ÚMRKLOutputParserz&MRKL Output parser for the chat agent.Úformat_instructions)Úreturnc                 C   s   | j S )z<Returns formatting instructions for the given output parser.)r	   ©Úself© r   úq/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/langchain/agents/mrkl/output_parser.pyÚget_format_instructions   s    z(MRKLOutputParser.get_format_instructions)Útextr
   c           
      C   sf  t |v }d}t ||tj¡}|r|r| t ¡| | d¡¡k r~| t ¡tt ƒ }| d|¡}td|||…  ¡ i|d|… ƒS t	t
› d|› ƒ‚|rÚ| d¡ ¡ }| d¡}| d	¡}	|	 d
¡du rÎ|	 d¡}	t||	|ƒS |rútd| t ¡d  ¡ i|ƒS t d|tj¡s&t	d|› dt|dd‚n<t d|tj¡sRt	d|› dt|dd‚nt	d|› dƒ‚dS )a*  Parse the output from the agent into
        an AgentAction or AgentFinish object.

        Args:
            text: The text to parse.

        Returns:
            An AgentAction or AgentFinish object.

        Raises:
            OutputParserException: If the output could not be parsed.
        zFAction\s*\d*\s*:[\s]*(.*?)[\s]*Action\s*\d*\s*Input\s*\d*\s*:[\s]*(.*)r   z

ÚoutputNz: é   é   ú zSELECT Fú"éÿÿÿÿzAction\s*\d*\s*:[\s]*(.*?)zCould not parse LLM output: `ú`T)ZobservationZ
llm_outputZsend_to_llmz,[\s]*Action\s*\d*\s*Input\s*\d*\s*:[\s]*(.*))ÚFINAL_ANSWER_ACTIONÚreÚsearchÚDOTALLÚfindÚgroupÚlenr   Ústripr   Ú.FINAL_ANSWER_AND_PARSABLE_ACTION_ERROR_MESSAGEÚ
startswithr   ÚsplitÚ*MISSING_ACTION_AFTER_THOUGHT_ERROR_MESSAGEÚ/MISSING_ACTION_INPUT_AFTER_ACTION_ERROR_MESSAGE)
r   r   Zincludes_answerÚregexZaction_matchÚstart_indexZ	end_indexÚactionZaction_inputZ
tool_inputr   r   r   Úparse    sT    ÿÿÿ


ÿ
üÿ
üzMRKLOutputParser.parsec                 C   s   dS )NZmrklr   r   r   r   r   Ú_typea   s    zMRKLOutputParser._typeN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r	   ÚstrÚ__annotations__r   r   r   r   r(   Úpropertyr)   r   r   r   r   r      s   
Ar   )r   Útypingr   Zlangchain_core.agentsr   r   Zlangchain_core.exceptionsr   Zlangchain.agents.agentr   Zlangchain.agents.mrkl.promptr   r   r#   r$   r    r   r   r   r   r   Ú<module>   s   ÿÿÿ