§
    ™ŠtjÃ  ã                  ó|   — d Z 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
mZ ddlmZ ddlmZ  G d	„ d
¦  «        ZdS )z!Experiment with different models.é    )Úannotations)Ú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 )ÚModelLaboratoryzMA utility to experiment with and compare the performance of different models.NÚchainsúSequence[Chain]Únamesúlist[str] | Nonec                ó  — |D ]{}t          |t          ¦  «        sd}t          |¦  «        ‚t          |j        ¦  «        dk    rd|j        › �}t          |¦  «        ‚t          |j        ¦  «        dk    r
d|j        › �}Œ||�1t          |¦  «        t          |¦  «        k    rd}t          |¦  «        ‚|| _        d„ t          t          | j        ¦  «        ¦  «        D ¦   «         }t          |¦  «        | _	        || _
        dS )aº  Initialize the ModelLaboratory with chains to experiment with.

        Args:
            chains: A sequence of chains to experiment with.
                Each chain must have exactly one input and one output variable.
            names: Optional list of names corresponding to each chain.
                If provided, its length must match the number of chains.


        Raises:
            ValueError: If any chain is not an instance of `Chain`.
            ValueError: If a chain does not have exactly one input variable.
            ValueError: If a chain does not have exactly one output variable.
            ValueError: If the length of `names` does not match the number of chains.
        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     ú`/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/langchain_classic/model_laboratory.pyú
<listcomp>z,ModelLaboratory.__init__.<locals>.<listcomp>9   s   € Ð?Ð?Ð? !•s˜1‘v”vÐ?Ð?Ð?ó    )Ú
isinstancer
   Ú
ValueErrorÚlenÚ
input_keysÚoutput_keysr   Úranger   Úchain_colorsr   )Úselfr   r   ÚchainÚmsgÚchain_ranges         r   Ú__init__zModelLaboratory.__init__   s#  € ð  ð 	ð 	ˆEÝ˜e¥UÑ+Ô+ð &ðAð õ
 ! ‘o”oÐ%Ý�5Ô#Ñ$Ô$¨Ò)Ð)ð.Ø Ô+ð.ð .ð õ ! ‘o”oÐ%Ý�5Ô$Ñ%Ô%¨Ò*Ð*ð/Ø Ô,ð/ð /ð øð Ð¥ U¡¤­s°6©{¬{Ò!:Ð!:ØDˆCÝ˜S‘/”/Ð!ØˆŒØ?Ð?¥u­S°´Ñ-=Ô-=Ñ'>Ô'>Ð?Ñ?Ô?ˆÝ-¨kÑ:Ô:ˆÔØˆŒ
ˆ
ˆ
r   Úllmsúlist[BaseLLM]ÚpromptúPromptTemplate | NoneÚreturnc                óz   ‡— ‰€t          dgd¬¦  «        Šˆfd„|D ¦   «         }d„ |D ¦   «         } | ||¬¦  «        S )aq  Initialize the ModelLaboratory with LLMs and an optional prompt.

        Args:
            llms: A list of LLMs to experiment with.
            prompt: An optional prompt to use with the LLMs.
                If provided, the prompt must contain exactly one input variable.

        Returns:
            An instance of `ModelLaboratory` initialized with LLMs.
        NÚ_inputz{_input})Úinput_variablesÚtemplatec                ó2   •— g | ]}t          |‰¬ ¦  «        ‘ŒS ))Úllmr,   r   )r   r4   r,   s     €r   r   z-ModelLaboratory.from_llms.<locals>.<listcomp>O   s&   ø€ ÐCÐCÐC°s•(˜s¨6Ð2Ñ2Ô2ÐCÐCÐCr   c                ó,   — g | ]}t          |¦  «        ‘ŒS r   r   )r   r4   s     r   r   z-ModelLaboratory.from_llms.<locals>.<listcomp>P   s   € Ð*Ð*Ð*˜c•�S‘”Ð*Ð*Ð*r   )r   r   )Úclsr*   r,   r   r   s     `  r   Ú	from_llmszModelLaboratory.from_llms=   s_   ø€ ð  ˆ>Ý#°X°JÈÐTÑTÔTˆFØCÐCÐCÐC¸dÐCÑCÔCˆØ*Ð* TÐ*Ñ*Ô*ˆØˆs�6 Ð'Ñ'Ô'Ð'r   Útextr   ÚNonec                óF  — t          d|› d�¦  «         t          | j        ¦  «        D ]x\  }}| j        �| j        |         nt	          |¦  «        }t          |d¬¦  «         |                     |¦  «        }t          || j        t	          |¦  «                 d¬¦  «         Œyd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%   r8   r   r&   ÚnameÚoutputs         r   ÚcomparezModelLaboratory.compareS   s­   € õ 	Ð/ tÐ/Ð/Ð/Ñ0Ô0Ð0Ý! $¤+Ñ.Ô.ð 	Lð 	L‰HˆAˆuØ$(¤JÐ$:�4”:˜a”=�=ÅÀEÁ
Ä
ˆDÝ�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-   r.   r   )r8   r   r.   r9   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r)   Úclassmethodr7   rC   r   r   r   r   r      sx   € € € € € ØWÐWð)ð )ð )ð )ð )ðV ð )-ð(ð (ð (ð (ñ „[ð(ð*Lð Lð Lð Lð Lð Lr   r   N)rG   Ú
__future__r   Úcollections.abcr   Ú#langchain_core.language_models.llmsr   Úlangchain_core.prompts.promptr   Úlangchain_core.utils.inputr   r	   Úlangchain_classic.chains.baser
   Úlangchain_classic.chains.llmr   r   r   r   r   ú<module>rP      sÕ   ðØ 'Ð 'à "Ð "Ð "Ð "Ð "Ð "à $Ð $Ð $Ð $Ð $Ð $à 7Ð 7Ð 7Ð 7Ð 7Ð 7Ø 8Ð 8Ð 8Ð 8Ð 8Ð 8Ø DÐ DÐ DÐ DÐ DÐ DÐ DÐ Dà /Ð /Ð /Ð /Ð /Ð /Ø 1Ð 1Ð 1Ð 1Ð 1Ð 1ðSLð SLð SLð SLð SLñ SLô SLð SLð SLð SLr   