
    @h	                     z    S SK r S SKrS SKJr  S SKJr  S SKJrJr  S SKJ	r	  S SK
Jr  S SKJr  Sr " S	 S
\5      rg)    N)Pattern)Union)AgentActionAgentFinish)OutputParserException)AgentOutputParser)FORMAT_INSTRUCTIONSzFinal Answer:c                       \ rS rSr% Sr\r\\S'    \	R                  " S\	R                  5      r\\S'    S\4S jrS\S\\\4   4S	 jr\S\4S
 j5       rSrg)ChatOutputParser   z!Output parser for the chat agent.format_instructionsz ^.*?`{3}(?:json)?\n(.*?)`{3}.*?$patternreturnc                     U R                   $ )z<Returns formatting instructions for the given output parser.)r   selfs    [/var/www/html/shao/venv/lib/python3.13/site-packages/langchain/agents/chat/output_parser.pyget_format_instructions(ChatOutputParser.get_format_instructions   s    '''    textc                 *   [         U;   n U R                  R                  U5      nU(       d  Sn[        U5      eUR	                  S5      n[
        R                  " UR                  5       5      nSU;   nU(       a  U(       a  SU 3n[        U5      e[        US   UR                  S0 5      U5      $ ! [         aV  nU(       d  SU 3n[        U5      UeUR                  [         5      S   R                  5       n	[        SU	0U5      s S	nA$ S	nAff = f)
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.
    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foundmsgr   responseincludes_actionexcr   s
             r   parseChatOutputParser.parse   s    .5	9LL''-E( o%[[^Fzz&,,.1H&(2O?004v7  ,C00"^R0   	9"4TF;+C0c9ZZ 34R8>>@F&1488	9s   B&B2 2
D<ADDDc                     g)Nchat r   s    r   _typeChatOutputParser._typeH   s    r   r2   N)__name__
__module____qualname____firstlineno____doc__r	   r   str__annotations__recompileDOTALLr   r   r   r   r   r   r.   propertyr3   __static_attributes__r2   r   r   r   r      su    +22)zz"EryyQGWQ,( (*9# *9%[(@"A *9X s  r   r   )r"   r<   r   typingr   langchain_core.agentsr   r   langchain_core.exceptionsr   langchain.agents.agentr   langchain.agents.chat.promptr	   r   r   r2   r   r   <module>rF      s0     	   : ; 4 <% ;( ;r   