
    Ng?	                     z    d dl Z d dlZd dl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Z G d d	e          ZdS )
    N)PatternUnion)AgentActionAgentFinish)OutputParserException)AgentOutputParser)FORMAT_INSTRUCTIONSzFinal Answer:c                       e Zd ZU dZeZeed<   	  ej	        dej
                  Zeed<   	 defdZdedeeef         fdZedefd	            Zd
S )ChatOutputParserz!Output parser for the chat agent.format_instructionsz ^.*?`{3}(?:json)?\n(.*?)`{3}.*?$patternreturnc                     | j         S )z<Returns formatting instructions for the given output parser.)r   selfs    _/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain/agents/chat/output_parser.pyget_format_instructionsz(ChatOutputParser.get_format_instructions   s    ''    textc                 L   t           |v }	 | j                            |          }|st          d          |                    d          }t          j        |                                          }d|v }|r|rt          d|           t          |d         |
                    di           |          S # t          $ rc}|st          d|           ||                    t                     d                                         }t          d|i|          cY d	}~S d	}~ww xY w)
ad  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.
            ValueError: If the action could not be found.
        zaction not found   actionzDParsing LLM output produced a final answer and a parse-able action: action_inputzCould not parse LLM output: outputN)FINAL_ANSWER_ACTIONr   search
ValueErrorgroupjsonloadsstripr   r   get	Exceptionsplitr   )	r   r   includes_answerfoundr   responseincludes_actionexcr   s	            r   parsezChatOutputParser.parse   sb    .5	9L''--E 5 !3444[[^^Fz&,,..11H&(2O ? +7047 7   "HLL$D$Dd    	9 	9 	9" +9499  ZZ 344R8>>@@F&1488888888	9s   B*B6 6
D# ADD#D#c                     dS )Nchat r   s    r   _typezChatOutputParser._typeD   s    vr   N)__name__
__module____qualname____doc__r	   r   str__annotations__recompileDOTALLr   r   r   r   r   r   r+   propertyr/   r.   r   r   r   r      s         ++2222)!rz"EryQQGWQQQ,( ( ( ( ('9# '9%[(@"A '9 '9 '9 '9R s    X  r   r   )r    r6   typingr   r   langchain_core.agentsr   r   langchain_core.exceptionsr   langchain.agents.agentr   langchain.agents.chat.promptr	   r   r   r.   r   r   <module>r?      s     				 ! ! ! ! ! ! ! ! : : : : : : : : ; ; ; ; ; ; 4 4 4 4 4 4 < < < < < <% 8 8 8 8 8( 8 8 8 8 8r   