
    Ah                        S r SSKJr  SSKJr  SSKJr  SSKJr  SSK	J
r
  SSKJrJr  SSKJr  SS	KJr   " S
 S5      rg)z!Experiment with different models.    )annotations)Sequence)Optional)BaseLLM)PromptTemplate)get_color_mapping
print_text)Chain)LLMChainc                  T    \ rS rSrSrSS	S jjr\ S     S
S jj5       rSS jrSr	g)ModelLaboratory   zMA utility to experiment with and compare the performance of different models.Nc                   U H  n[        U[        5      (       d  Sn[        U5      e[        UR                  5      S:w  a  SUR                   3n[        U5      e[        UR
                  5      S:w  d  Ms  SUR
                   3nM     Ub%  [        U5      [        U5      :w  a  Sn[        U5      eXl        [        [        U R                  5      5       Vs/ sH  n[        U5      PM     nn[        U5      U l
        X l        gs  snf )a~  Initialize the ModelLaboratory with chains to experiment with.

Args:
    chains (Sequence[Chain]): A sequence of chains to experiment with.
    Each chain must have exactly one input and one output variable.
names (Optional[List[str]]): 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.
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msgichain_ranges          R/var/www/html/shao/venv/lib/python3.13/site-packages/langchain/model_laboratory.py__init__ModelLaboratory.__init__   s     EeU++A 
 !o%5##$) ++,.  !o%5$$%* ,,-/  & Us6{!:DCS/!',S-='>?'>!s1v'>?-k:
 @s   Dc                    Uc  [        S/SS9nU Vs/ sH  n[        X2S9PM     nnU Vs/ sH  n[        U5      PM     nnU " XES9$ s  snf s  snf )au  Initialize the ModelLaboratory with LLMs and an optional prompt.

Args:
    llms (List[BaseLLM]): A list of LLMs to experiment with.
    prompt (Optional[PromptTemplate]): An optional prompt to use with the LLMs.
        If provided, the prompt must contain exactly one input variable.

Returns:
    ModelLaboratory: An instance of `ModelLaboratory` initialized with LLMs.
_inputz{_input})input_variablestemplate)llmprompt)r   )r   r   r   )clsllmsr(   r'   r   r   s         r    	from_llmsModelLaboratory.from_llms>   s\      >#XJTF>BCds(s2dC%)*TcST*6'' D*s
   AAc                "   [        SU S35        [        U R                  5       Hg  u  p#U R                  b  U R                  U   O
[	        U5      n[        USS9  UR                  U5      n[        XPR                  [	        U5         SS9  Mi     g)a  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    compareModelLaboratory.compareT   sw     	&tfB/0!$++.HA$(JJ$:4::a=E
Dt&YYt_Fv%6%6s1v%>FK	 /    )r   r   r   )N)r   zSequence[Chain]r   zOptional[list[str]])r*   zlist[BaseLLM]r(   zOptional[PromptTemplate]returnr   )r4   r   r:   None)
__name__
__module____qualname____firstlineno____doc__r!   classmethodr+   r7   __static_attributes__ r9   r    r   r      sF    W)V  ,0(( )( 
	( (*Lr9   r   N)r@   
__future__r   collections.abcr   typingr   #langchain_core.language_models.llmsr   langchain_core.prompts.promptr   langchain_core.utils.inputr   r	   langchain.chains.baser
   langchain.chains.llmr   r   rC   r9   r    <module>rL      s.    ' " $  7 8 D ' )SL SLr9   