
    9|h                    b    d dl mZ d dlmZmZmZ d dlmZ d dlm	Z	  G d deee
ef            Zy)    )annotations)AnyDictList)BaseOutputParser)pre_initc                  b    e Zd ZU dZded<   ed
d       Zedd       Ze	dd       Z
ddZddZy	)CombiningOutputParserz)Combine multiple output parsers into one.zList[BaseOutputParser]parsersc                     y)NT )clss    a/var/www/html/test/engine/venv/lib/python3.12/site-packages/langchain/output_parsers/combining.pyis_lc_serializablez(CombiningOutputParser.is_lc_serializable   s        c                    |d   }t        |      dk  rt        d      |D ]6  }|j                  dk(  rt        d      |j                  dk(  s-t        d       |S )zValidate the parsers.r      zMust have at least two parsers	combiningzCannot nest combining parserslistzCannot combine list parsers)len
ValueError_type)r   valuesr   parsers       r   validate_parsersz&CombiningOutputParser.validate_parsers   sn     #w<!=>> 	@F||{* !@AA||v% !>??		@
 r   c                     y)zReturn the type key.r   r   )selfs    r   r   zCombiningOutputParser._type   s     r   c                    d| j                   d   j                          }dj                  d | j                   dd D              }| d| S )z7Instructions on how the LLM output should be formatted.zFor your first output: r   
c              3  B   K   | ]  }d |j                            yw)z^Complete that output fully. Then produce another output, separated by two newline characters: N)get_format_instructions).0ps     r   	<genexpr>z@CombiningOutputParser.get_format_instructions.<locals>.<genexpr>(   s>      
 mmn  nG  nG  nI  mJ  K
s      N)r   r!   join)r   initial
subsequents      r   r!   z-CombiningOutputParser.get_format_instructions$   s[     ,DLLO,S,S,U+VWYY 
\\!"%
 

 "ZL))r   c                    |j                  d      }t               }t        || j                        D ]3  \  }}|j	                  |j                  |j                                      5 |S )z Parse the output of an LLM call.z

)splitdictzipr   updateparsestrip)r   texttextsoutputtxtr   s         r   r.   zCombiningOutputParser.parse.   sU    

6"udll3 	5KCMM&,,syy{34	5r   N)returnbool)r   Dict[str, Any]r4   r6   )r4   str)r0   r7   r4   r6   )__name__
__module____qualname____doc____annotations__classmethodr   r   r   propertyr   r!   r.   r   r   r   r
   r
   	   sO    3##  
 
  *r   r
   N)
__future__r   typingr   r   r   langchain_core.output_parsersr   langchain_core.utilsr   r7   r
   r   r   r   <module>rC      s.    " " " : )+,T#s(^< +r   