
    Ng                        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.
        zModelLaboratory 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     V/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain/model_laboratory.py
<listcomp>z,ModelLaboratory.__init__.<locals>.<listcomp>-   s    ???!s1vv???    )
isinstancer   
ValueErrorlen
input_keysoutput_keysr   ranger   chain_colorsr   )selfr   r   chainchain_ranges        r   __init__zModelLaboratory.__init__   s5     	 	EeU++  A  
 5#$$)) . +. .   5$%%** / ,/ /   +
 5zzS[[(( !STTT??uS-=-='>'>???-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Cs(s6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_llms1   s_     >#XJTTTFCCCCdCCC**T***s6''''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.compareB   s     	/t///000!$+.. 	L 	LHAuz%z!}5zzt&&&&YYt__FvT%6s1vv%>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    