§
    è˜ºh¿  ã                  ó„   — d Z ddlmZ ddlmZmZmZ ddlmZ ddl	m
Z
 ddlmZmZ ddlmZ ddlmZ  G d	„ d
¦  «        ZdS )ú!Experiment with different models.é    )Úannotations)ÚListÚOptionalÚSequence)ÚBaseLLM©ÚPromptTemplate)Úget_color_mappingÚ
print_text)ÚChain©ÚLLMChainc                  ó@   — e Zd ZdZddd„Ze	 ddd„¦   «         Zdd„ZdS )ÚModelLaboratoryr   NÚchainsúSequence[Chain]ÚnamesúOptional[List[str]]c                ó  — |D ]„}t          |t          ¦  «        st          d¦  «        ‚t          |j        ¦  «        dk    rt          d|j        › �¦  «        ‚t          |j        ¦  «        dk    rt          d|j        › �¦  «        ‚Œ…|�/t          |¦  «        t          |¦  «        k    rt          d¦  «        ‚|| _        d„ t          t          | j        ¦  «        ¦  «        D ¦   «         }t          |¦  «        | _	        || _
        dS )zyInitialize with chains to experiment with.

        Args:
            chains: list of chains to experiment with.
        z¡ModelLaboratory should now be initialized with Chains. If you want to initialize with LLMs, use the `from_llms` method instead (`ModelLaboratory.from_llms(...)`)é   z;Currently only support chains with one input variable, got z<Currently only support chains with one output variable, got Nz0Length of chains does not match length of names.c                ó,   — g | ]}t          |¦  «        ‘ŒS © ©Ústr)Ú.0Úis     úb/var/www/html/services/rag-service/venv/lib/python3.11/site-packages/langchain/model_laboratory.pyú
<listcomp>z,ModelLaboratory.__init__.<locals>.<listcomp>,   s   € Ð?Ð?Ð? !•s˜1‘v”vÐ?Ð?Ð?ó    )Ú
isinstancer   Ú
ValueErrorÚlenÚ
input_keysÚoutput_keysr   Úranger   Úchain_colorsr   )Úselfr   r   ÚchainÚchain_ranges        r   Ú__init__zModelLaboratory.__init__   s5  € ð ð 	ð 	ˆEÝ˜e¥UÑ+Ô+ð Ý ðAñô ð õ
 �5Ô#Ñ$Ô$¨Ò)Ð)Ý ð.Ø Ô+ð.ð .ñô ð õ �5Ô$Ñ%Ô%¨Ò*Ð*Ý ð/Ø Ô,ð/ð /ñô ð ð +ð
 ÐÝ�5‰zŒz�S ™[œ[Ò(Ð(Ý Ð!SÑTÔTÐTØˆŒØ?Ð?¥u­S°´Ñ-=Ô-=Ñ'>Ô'>Ð?Ñ?Ô?ˆÝ-¨kÑ:Ô:ˆÔØˆŒ
ˆ
ˆ
r    ÚllmsúList[BaseLLM]ÚpromptúOptional[PromptTemplate]Úreturnc                óz   ‡— ‰€t          dgd¬¦  «        Šˆfd„|D ¦   «         }d„ |D ¦   «         } | ||¬¦  «        S )a)  Initialize with LLMs to experiment with and optional prompt.

        Args:
            llms: list of LLMs to experiment with
            prompt: Optional prompt to use to prompt the LLMs. Defaults to None.
                If a prompt was provided, it should only have one input variable.
        NÚ_inputz{_input})Úinput_variablesÚtemplatec                ó2   •— g | ]}t          |‰¬ ¦  «        ‘ŒS ))Úllmr.   r   )r   r6   r.   s     €r   r   z-ModelLaboratory.from_llms.<locals>.<listcomp>=   s&   ø€ ÐCÐCÐC°s•(˜s¨6Ð2Ñ2Ô2ÐCÐCÐCr    c                ó,   — g | ]}t          |¦  «        ‘ŒS r   r   )r   r6   s     r   r   z-ModelLaboratory.from_llms.<locals>.<listcomp>>   s   € Ð*Ð*Ð*˜c•�S‘”Ð*Ð*Ð*r    )r   r	   )Úclsr,   r.   r   r   s     `  r   Ú	from_llmszModelLaboratory.from_llms0   s_   ø€ ð ˆ>Ý#°X°JÈÐTÑTÔTˆFØCÐCÐCÐC¸dÐCÑCÔCˆØ*Ð* TÐ*Ñ*Ô*ˆØˆs�6 Ð'Ñ'Ô'Ð'r    Útextr   ÚNonec                óH  — t          d|› d�¦  «         t          | j        ¦  «        D ]y\  }}| j        �| j        |         }nt	          |¦  «        }t          |d¬¦  «         |                     |¦  «        }t          || j        t	          |¦  «                 d¬¦  «         ŒzdS )a3  Compare model outputs on an input text.

        If a prompt was provided with starting the laboratory, then this text will be
        fed into the prompt. If no prompt was provided, then the input text is the
        entire prompt.

        Args:
            text: input text to run all models on.
        z[1mInput:[0m
ú
N)Úendz

)Úcolorr>   )ÚprintÚ	enumerater   r   r   r   Úrunr'   )r(   r:   r   r)   ÚnameÚoutputs         r   ÚcomparezModelLaboratory.compareA   s±   € õ 	Ð/ tÐ/Ð/Ð/Ñ0Ô0Ð0Ý! $¤+Ñ.Ô.ð 	Lð 	L‰HˆAˆuØŒzÐ%Ø”z !”}��å˜5‘z”z�Ý�t Ð&Ñ&Ô&Ð&Ø—Y’Y˜t‘_”_ˆFÝ�v TÔ%6µs¸1±v´vÔ%>ÀFÐKÑKÔKÐKÐKð	Lð 	Lr    )N)r   r   r   r   )r,   r-   r.   r/   r0   r   )r:   r   r0   r;   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r+   Úclassmethodr9   rE   r   r    r   r   r      su   € € € € € Ø+Ð+ðð ð ð ð ð> àEIð(ð (ð (ð (ñ „[ð(ð Lð Lð Lð Lð Lð Lr    r   N)rI   Ú
__future__r   Útypingr   r   r   Ú#langchain_core.language_models.llmsr   Úlangchain_core.prompts.promptr
   Úlangchain_core.utils.inputr   r   Úlangchain.chains.baser   Úlangchain.chains.llmr   r   r   r    r   ú<module>rR      sá   ðØ 'Ð 'Ø "Ð "Ð "Ð "Ð "Ð "à +Ð +Ð +Ð +Ð +Ð +Ð +Ð +Ð +Ð +à 7Ð 7Ð 7Ð 7Ð 7Ð 7Ø 8Ð 8Ð 8Ð 8Ð 8Ð 8Ø DÐ DÐ DÐ DÐ DÐ DÐ DÐ Dà 'Ð 'Ð 'Ð 'Ð 'Ð 'Ø )Ð )Ð )Ð )Ð )Ð )ðELð ELð ELð ELð ELñ ELô ELð ELð ELð ELr    