
    Ig                    |    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y)!Experiment with different models.    )annotations)ListOptionalSequence)BaseLLM)PromptTemplate)get_color_mapping
print_text)Chain)LLMChainc                  B    e Zd ZdZdddZe	 d	 	 	 	 	 dd       Zd	dZy)
ModelLaboratoryr   Nc                   |D ]}  }t        |t              st        d      t        |j                        dk7  rt        d|j                         t        |j
                        dk7  sgt        d|j
                          |"t        |      t        |      k7  rt        d      || _        t        t        | j                              D cg c]  }t        |       }}t        |      | _
        || _        yc c}w )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.)
isinstancer   
ValueErrorlen
input_keysoutput_keyschainsrangestrr
   chain_colorsnames)selfr   r   chainichain_ranges         W/var/www/html/answerous/venv/lib/python3.12/site-packages/langchain/model_laboratory.py__init__zModelLaboratory.__init__   s
     	EeU+ A 
 5##$)  ++,.  5$$%*  ,,-/ 	" 5zS[( !STT',S-='>?!s1v??-k:
 @s   C:c                    |t        dgd      }|D cg c]  }t        ||       }}|D cg c]  }t        |       }} | ||      S c c}w c c}w )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.
        _inputz{_input})input_variablestemplate)llmprompt)r   )r	   r   r   )clsllmsr'   r&   r   r   s         r    	from_llmszModelLaboratory.from_llms1   s^     >#XJTF>BCs(s62CC%)*cS**6'' D*s
   AAc                .   t        d| d       t        | j                        D ]n  \  }}| j                  | j                  |   }nt	        |      }t        |d       |j                  |      }t        || j                  t	        |         d       p y)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   textr   r   nameoutputs         r    comparezModelLaboratory.compareB   s     	&tfB/0!$++. 	LHAuzz%zz!}5zt&YYt_FvT%6%6s1v%>FK	L    )N)r   zSequence[Chain]r   zOptional[List[str]])r)   zList[BaseLLM]r'   zOptional[PromptTemplate]returnr   )r2   r   r7   None)__name__
__module____qualname____doc__r!   classmethodr*   r5    r6   r    r   r      s?    +> EI( (*B(	( ( Lr6   r   N)r<   
__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>   r6   r    <module>rF      s.    ' " + + 7 8 D ' )EL ELr6   