Ë
    ´Œj  ã                  ó€   — 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
 ddlmZmZ ddlmZ dd	lmZ  G d
„ d«      Zy)z!Experiment with different models.é    )Úannotations)ÚSequence)ÚOptional)Ú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)
ÚModelLaboratoryzMA utility to experiment with and compare the performance of different models.Nc                óú  — |D ]y  }t        |t        «      sd}t        |«      ‚t        |j                  «      dk7  rd|j                  › �}t        |«      ‚t        |j
                  «      dk7  sŒkd|j
                  › �}Œ{ |�$t        |«      t        |«      k7  rd}t        |«      ‚|| _        t        t        | j                  «      «      D �cg c]  }t        |«      ‘Œ }}t        |«      | _
        || _        yc c}w )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.
        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.)Ú
isinstancer
   Ú
ValueErrorÚlenÚ
input_keysÚoutput_keysÚchainsÚrangeÚstrr   Úchain_colorsÚnames)Úselfr   r   ÚchainÚmsgÚiÚchain_ranges          úd/var/www/html/Fitness-lenito-AI-main/venv/lib/python3.12/site-packages/langchain/model_laboratory.pyÚ__init__zModelLaboratory.__init__   s  € ó  ˆEÜ˜e¤UÔ+ðAð ô
 ! “oÐ%Ü�5×#Ñ#Ó$¨Ò)ðØ ×+Ñ+Ð,ð.ð ô ! “oÐ%Ü�5×$Ñ$Ó%¨Ó*ðØ ×,Ñ,Ð-ð/ñ ð ð& Ð¤ U£¬s°6«{Ò!:ØDˆCÜ˜S“/Ð!ØˆŒÜ',¬S°·±Ó-=Ô'>Ó?Ñ'> !”s˜1•vÐ'>ˆÐ?Ü-¨kÓ:ˆÔØˆ�
ùò @s   ÃC8c                ó®   — |€t        dgd¬«      }|D �cg c]  }t        ||¬«      ‘Œ }}|D �cg c]  }t        |«      ‘Œ }} | ||¬«      S c c}w c c}w )a­  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_llmszModelLaboratory.from_llms>   s`   € ð  ˆ>Ü#°X°JÈÔTˆFÙ>BÓC¹d°s”(˜s¨6Ö2¸dˆÐCÙ%)Ó*¡T˜c”�S• TˆÐ*Ù�6 Ô'Ð'ùò DùÚ*s
   •A¯Ac                ó,  — t        d|› d�«       t        | j                  «      D ]m  \  }}| j                  �| j                  |   n
t	        |«      }t        |d¬«       |j                  |«      }t        || j                  t	        |«         d¬«       Œo 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.compareT   s{   € ô 	Ð& t f¨BÐ/Ô0Ü! $§+¡+Ö.‰HˆAˆuØ$(§J¡JÐ$:�4—:‘:˜a’=ÄÀEÃ
ˆDÜ�t Õ&Ø—Y‘Y˜t“_ˆFÜ�v T×%6Ñ%6´s¸1³vÑ%>ÀFÖKñ	 /ó    )N)r   zSequence[Chain]r   zOptional[list[str]])r(   zlist[BaseLLM]r&   zOptional[PromptTemplate]Úreturnr   )r1   r   r6   ÚNone)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r    Úclassmethodr)   r4   © r5   r   r   r      sF   „ ÙWô)ðV ð ,0ð(àð(ð )ð(ð 
ò	(ó ð(ô*Lr5   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   r=   r5   r   Ú<module>rF      s.   ðÙ 'å "å $Ý å 7Ý 8ß Då 'Ý )÷SLò SLr5   