a
    •˜ëj®  ã                   @  s`   d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	 dZ
G dd„ deeeef  ƒZd	S )
é    )Úannotations)ÚAny)ÚBaseOutputParser)Úpre_init)Úoverrideé   c                   @  st   e Zd ZU dZded< eeddœdd„ƒƒZeddd	œd
d„ƒZ	e
ddœdd„ƒZddœdd„Zdddœdd„ZdS )ÚCombiningOutputParserz)Combine multiple output parsers into one.zlist[BaseOutputParser]ÚparsersÚbool)Úreturnc                 C  s   dS )NT© )Úclsr   r   úa/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/langchain/output_parsers/combining.pyÚis_lc_serializable   s    z(CombiningOutputParser.is_lc_serializablezdict[str, Any])Úvaluesr   c                 C  sZ   |d }t |ƒtk r d}t|ƒ‚|D ]0}|jdkr>d}t|ƒ‚|jdkr$d}t|ƒ‚q$|S )zValidate the parsers.r	   zMust have at least two parsersÚ	combiningzCannot nest combining parsersÚlistzCannot combine list parsers)ÚlenÚ_MIN_PARSERSÚ
ValueErrorÚ_type)r   r   r	   ÚmsgÚparserr   r   r   Úvalidate_parsers   s    


z&CombiningOutputParser.validate_parsersÚstrc                 C  s   dS )zReturn the type key.r   r   )Úselfr   r   r   r   &   s    zCombiningOutputParser._typec                 C  s@   d| j d  ¡ › �}d dd„ | j dd… D ƒ¡}|› d|› �S )z7Instructions on how the LLM output should be formatted.zFor your first output: r   Ú
c                 s  s   | ]}d |  ¡ › �V  qdS )z^Complete that output fully. Then produce another output, separated by two newline characters: N)Úget_format_instructions)Ú.0Úpr   r   r   Ú	<genexpr>.   s   ÿz@CombiningOutputParser.get_format_instructions.<locals>.<genexpr>é   N)r	   r   Újoin)r   ÚinitialZ
subsequentr   r   r   r   +   s
    
þz-CombiningOutputParser.get_format_instructions)Útextr   c                 C  s<   |  d¡}i }t|| jƒD ]\}}| | | ¡ ¡¡ q|S )z Parse the output of an LLM call.z

)ÚsplitÚzipr	   ÚupdateÚparseÚstrip)r   r$   ZtextsÚoutputÚtxtr   r   r   r   r(   4   s
    
zCombiningOutputParser.parseN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__Úclassmethodr   r   r   r   Úpropertyr   r   r(   r   r   r   r   r      s   
	r   N)Ú
__future__r   Útypingr   Zlangchain_core.output_parsersr   Zlangchain_core.utilsr   Ztyping_extensionsr   r   Údictr   r   r   r   r   r   Ú<module>   s   