Ë
    ´ŒjYH  ã                  óB  — d Z ddlmZ ddlZddlmZmZ ddlm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 ddlmZ ddlmZ  ej2                  e«      Z G d„ dee
«      Z G d„ de«      Z G d„ d«      Z G d„ dee«      Z  G d„ dee«      Z! G d„ dee«      Z"y)z3Interfaces to be implemented by general evaluators.é    )ÚannotationsN)ÚABCÚabstractmethod)ÚSequence)ÚEnum)ÚAnyÚOptionalÚUnion)Úwarn)ÚAgentAction)ÚBaseLanguageModel)Úrun_in_executor)ÚChainc                  ó†   — e Zd ZdZdZ	 dZ	 dZ	 dZ	 dZ	 dZ		 dZ
	 d	Z	 d
Z	 dZ	 dZ	 dZ	 dZ	 dZ	 dZ	 dZ	 dZ	 dZ	 dZ	 dZy)ÚEvaluatorTypezThe types of the evaluators.ÚqaÚcot_qaÚ
context_qaÚpairwise_stringÚscore_stringÚlabeled_pairwise_stringÚlabeled_score_stringÚ
trajectoryÚcriteriaÚlabeled_criteriaÚstring_distanceÚexact_matchÚregex_matchÚpairwise_string_distanceÚembedding_distanceÚpairwise_embedding_distanceÚjson_validityÚjson_equalityÚjson_edit_distanceÚjson_schema_validationN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚQAÚCOT_QAÚ
CONTEXT_QAÚPAIRWISE_STRINGÚSCORE_STRINGÚLABELED_PAIRWISE_STRINGÚLABELED_SCORE_STRINGÚAGENT_TRAJECTORYÚCRITERIAÚLABELED_CRITERIAÚSTRING_DISTANCEÚEXACT_MATCHÚREGEX_MATCHÚPAIRWISE_STRING_DISTANCEÚEMBEDDING_DISTANCEÚPAIRWISE_EMBEDDING_DISTANCEÚJSON_VALIDITYÚJSON_EQUALITYÚJSON_EDIT_DISTANCEÚJSON_SCHEMA_VALIDATION© ó    úe/var/www/html/Fitness-lenito-AI-main/venv/lib/python3.12/site-packages/langchain/evaluation/schema.pyr   r      sÂ   „ Ù&à	€Bðà€Fð%ð €JØSØ'€Oðà!€Lðà7ÐðHà1Ðð@à#ÐØVØ€Hð<à)Ðð7à'€OØPØ€KØIØ€KØNØ9ÐØ=Ø-ÐØMØ"?ÐØ;Ø#€MØ.Ø#€MØ=Ø-ÐØTØ5ÐØIr?   r   c                  ó,   — e Zd ZdZeedd„«       «       Zy)ÚLLMEvalChainz,A base class for evaluators that use an LLM.c                 ó   — y)z#Create a new evaluator from an LLM.Nr>   )ÚclsÚllmÚkwargss      r@   Úfrom_llmzLLMEvalChain.from_llmN   ó   � r?   N)rE   r   rF   r   ÚreturnrB   )r&   r'   r(   r)   Úclassmethodr   rG   r>   r?   r@   rB   rB   K   s   „ Ù6àØò2ó ó ñ2r?   rB   c                  óp   — e Zd ZdZedd„«       Zedd„«       Zed	d„«       Zed	d„«       Z	 	 d
	 	 	 	 	 dd„Z	y)Ú_EvalArgsMixinz(Mixin for checking evaluation arguments.c                 ó   — y©z2Whether this evaluator requires a reference label.Fr>   ©Úselfs    r@   Úrequires_referencez!_EvalArgsMixin.requires_referenceW   ó   € ð r?   c                 ó   — y)ú0Whether this evaluator requires an input string.Fr>   rO   s    r@   Úrequires_inputz_EvalArgsMixin.requires_input\   rR   r?   c                ó6   — d| j                   j                  › d�S )z&Warning to show when input is ignored.zIgnoring input in ú, as it is not expected.©Ú	__class__r&   rO   s    r@   Ú_skip_input_warningz"_EvalArgsMixin._skip_input_warninga   s   € ð $ D§N¡N×$;Ñ$;Ð#<Ð<TÐUÐUr?   c                ó6   — d| j                   j                  › d�S )z*Warning to show when reference is ignored.zIgnoring reference in rW   rX   rO   s    r@   Ú_skip_reference_warningz&_EvalArgsMixin._skip_reference_warningf   s!   € ð % T§^¡^×%<Ñ%<Ð$=Ð=UÐVð	
r?   Nc                ód  — | j                   r&|€$| j                  j                  › d�}t        |«      ‚|�#| j                   st	        | j
                  d¬«       | j                  r&|€$| j                  j                  › d�}t        |«      ‚|�%| j                  st	        | j                  d¬«       yyy)a‡  Check if the evaluation arguments are valid.

        Args:
            reference (Optional[str], optional): The reference label.
            input_ (Optional[str], optional): The input string.
        Raises:
            ValueError: If the evaluator requires an input string but none is provided,
                or if the evaluator requires a reference label but none is provided.
        Nz requires an input string.é   )Ú
stacklevelz requires a reference string.)rU   rY   r&   Ú
ValueErrorr   rZ   rQ   r\   )rP   Ú	referenceÚinput_Úmsgs       r@   Ú_check_evaluation_argsz%_EvalArgsMixin._check_evaluation_argsm   s¨   € ð ×Ò 6 >Ø—^‘^×,Ñ,Ð-Ð-GÐHˆCÜ˜S“/Ð!ØÐ d×&9Ò&9Ü�×)Ñ)°aÕ8Ø×"Ò" yÐ'8Ø—^‘^×,Ñ,Ð-Ð-JÐKˆCÜ˜S“/Ð!ØÐ ¨×)@Ò)@Ü�×-Ñ-¸!Ö<ð *AÐ r?   ©rI   Úbool©rI   Ústr)NN)ra   úOptional[str]rb   ri   rI   ÚNone)
r&   r'   r(   r)   ÚpropertyrQ   rU   rZ   r\   rd   r>   r?   r@   rL   rL   T   s~   „ Ù2àòó ðð òó ðð òVó ðVð ò
ó ð
ð $(Ø $ð=à ð=ð ð=ð 
ô	=r?   rL   c                  óÆ   — e Zd ZdZed
d„«       Zedd„«       Zedddœ	 	 	 	 	 	 	 	 	 dd„«       Zdddœ	 	 	 	 	 	 	 	 	 dd„Z	dddœ	 	 	 	 	 	 	 	 	 dd„Z
dddœ	 	 	 	 	 	 	 	 	 dd	„Zy)ÚStringEvaluatorzcGrade, tag, or otherwise evaluate predictions relative to their inputs
    and/or reference labels.c                ó.   — | j                   j                  S )zThe name of the evaluation.rX   rO   s    r@   Úevaluation_namezStringEvaluator.evaluation_name‹   s   € ð �~‰~×&Ñ&Ð&r?   c                 ó   — yrN   r>   rO   s    r@   rQ   z"StringEvaluator.requires_reference�   rR   r?   N©ra   Úinputc                ó   — y)a:  Evaluate Chain or LLM output, based on optional input and label.

        Args:
            prediction (str): The LLM or chain prediction to evaluate.
            reference (Optional[str], optional): The reference label to evaluate against.
            input (Optional[str], optional): The input to consider during evaluation.
            kwargs: Additional keyword arguments, including callbacks, tags, etc.
        Returns:
            dict: The evaluation results containing the score or value.
                It is recommended that the dictionary contain the following keys:
                     - score: the score of the evaluation, if applicable.
                     - value: the string value of the evaluation, if applicable.
                     - reasoning: the reasoning for the evaluation, if applicable.
        Nr>   ©rP   Ú
predictionra   rr   rF   s        r@   Ú_evaluate_stringsz!StringEvaluator._evaluate_strings•   rH   r?   c             ‹  óT   K  — t        d| j                  f|||dœ|¤Žƒ d{  –—† S 7 Œ­w)aI  Asynchronously evaluate Chain or LLM output, based on optional input and label.

        Args:
            prediction (str): The LLM or chain prediction to evaluate.
            reference (Optional[str], optional): The reference label to evaluate against.
            input (Optional[str], optional): The input to consider during evaluation.
            kwargs: Additional keyword arguments, including callbacks, tags, etc.
        Returns:
            dict: The evaluation results containing the score or value.
                It is recommended that the dictionary contain the following keys:
                     - score: the score of the evaluation, if applicable.
                     - value: the string value of the evaluation, if applicable.
                     - reasoning: the reasoning for the evaluation, if applicable.
        N©ru   ra   rr   )r   rv   rt   s        r@   Ú_aevaluate_stringsz"StringEvaluator._aevaluate_strings­   sE   è ø€ ô, %ØØ×"Ñ"ð
ð "ØØñ
ð ñ
÷ 
ð 	
ð 
ús   ‚(¡&¢(c               óT   — | j                  ||¬«        | j                  d|||dœ|¤ŽS )aú  Evaluate Chain or LLM output, based on optional input and label.

        Args:
            prediction (str): The LLM or chain prediction to evaluate.
            reference (Optional[str], optional): The reference label to evaluate against.
            input (Optional[str], optional): The input to consider during evaluation.
            kwargs: Additional keyword arguments, including callbacks, tags, etc.
        Returns:
            dict: The evaluation results containing the score or value.
        ©ra   rb   rx   r>   )rd   rv   rt   s        r@   Úevaluate_stringsz StringEvaluator.evaluate_stringsÌ   sD   € ð$ 	×#Ñ#¨iÀÐ#ÔFØ%ˆt×%Ñ%ð 
Ø!ØØñ
ð ñ	
ð 	
r?   c             ‹  óp   K  — | j                  ||¬«        | j                  d|||dœ|¤Žƒ d{  –—† S 7 Œ­w)a	  Asynchronously evaluate Chain or LLM output, based on optional input and label.

        Args:
            prediction (str): The LLM or chain prediction to evaluate.
            reference (Optional[str], optional): The reference label to evaluate against.
            input (Optional[str], optional): The input to consider during evaluation.
            kwargs: Additional keyword arguments, including callbacks, tags, etc.
        Returns:
            dict: The evaluation results containing the score or value.
        r{   rx   Nr>   )rd   ry   rt   s        r@   Úaevaluate_stringsz!StringEvaluator.aevaluate_stringsæ   sR   è ø€ ð$ 	×#Ñ#¨iÀÐ#ÔFØ,�T×,Ñ,ð 
Ø!ØØñ
ð ñ	
÷ 
ð 	
ð 
ús   ‚-6¯4°6rg   re   )
ru   zUnion[str, Any]ra   úOptional[Union[str, Any]]rr   r   rF   r   rI   Údict)
ru   rh   ra   ri   rr   ri   rF   r   rI   r€   )r&   r'   r(   r)   rk   ro   rQ   r   rv   ry   r|   r~   r>   r?   r@   rm   rm   ‡   s;  „ ñ ð ò'ó ð'ð òó ðð ð
 04Ø+/ñð $ðð -ð	ð
 )ðð ðð 
òó ðð6 04Ø+/ñ
ð $ð
ð -ð	
ð
 )ð
ð ð
ð 
ó
ðF $(Ø#ñ
ð ð
ð !ð	
ð
 ð
ð ð
ð 
ó
ð< $(Ø#ñ
ð ð
ð !ð	
ð
 ð
ð ð
ð 
ô
r?   rm   c                  ó²   — e Zd ZdZedddœ	 	 	 	 	 	 	 	 	 	 	 dd„«       Zdddœ	 	 	 	 	 	 	 	 	 	 	 dd„Zdddœ	 	 	 	 	 	 	 	 	 	 	 dd„Zdddœ	 	 	 	 	 	 	 	 	 	 	 dd„Zy)	ÚPairwiseStringEvaluatorzDCompare the output of two models (or two outputs of the same model).Nrq   c                ó   — y)á1  Evaluate the output string pairs.

        Args:
            prediction (str): The output string from the first model.
            prediction_b (str): The output string from the second model.
            reference (Optional[str], optional): The expected output / reference string.
            input (Optional[str], optional): The input string.
            kwargs: Additional keyword arguments, such as callbacks and optional reference strings.
        Returns:
            dict: A dictionary containing the preference, scores, and/or other information.
        Nr>   ©rP   ru   Úprediction_bra   rr   rF   s         r@   Ú_evaluate_string_pairsz.PairwiseStringEvaluator._evaluate_string_pairs  rH   r?   c             ‹  óV   K  — t        d| j                  f||||dœ|¤Žƒ d{  –—† S 7 Œ­w)á@  Asynchronously evaluate the output string pairs.

        Args:
            prediction (str): The output string from the first model.
            prediction_b (str): The output string from the second model.
            reference (Optional[str], optional): The expected output / reference string.
            input (Optional[str], optional): The input string.
            kwargs: Additional keyword arguments, such as callbacks and optional reference strings.
        Returns:
            dict: A dictionary containing the preference, scores, and/or other information.
        N©ru   r†   ra   rr   )r   r‡   r…   s         r@   Ú_aevaluate_string_pairsz/PairwiseStringEvaluator._aevaluate_string_pairs  sH   è ø€ ô( %ØØ×'Ñ'ð
ð "Ø%ØØñ
ð ñ
÷ 
ð 	
ð 
úó   ‚ )¢'£)c               óV   — | j                  ||¬«        | j                  d||||dœ|¤ŽS )r„   r{   rŠ   r>   )rd   r‡   r…   s         r@   Úevaluate_string_pairsz-PairwiseStringEvaluator.evaluate_string_pairs8  sG   € ð( 	×#Ñ#¨iÀÐ#ÔFØ*ˆt×*Ñ*ð 
Ø!Ø%ØØñ	
ð
 ñ
ð 	
r?   c             ‹  ór   K  — | j                  ||¬«        | j                  d||||dœ|¤Žƒ d{  –—† S 7 Œ­w)r‰   r{   rŠ   Nr>   )rd   r‹   r…   s         r@   Úaevaluate_string_pairsz.PairwiseStringEvaluator.aevaluate_string_pairsU  sU   è ø€ ð( 	×#Ñ#¨iÀÐ#ÔFØ1�T×1Ñ1ð 
Ø!Ø%ØØñ	
ð
 ñ
÷ 
ð 	
ð 
úó   ‚.7°5±7)ru   rh   r†   rh   ra   ri   rr   ri   rF   r   rI   r€   )	r&   r'   r(   r)   r   r‡   r‹   rŽ   r�   r>   r?   r@   r‚   r‚     s8  „ ÙNàð $(Ø#ñð ðð ð	ð
 !ðð ðð ðð 
òó ðð4 $(Ø#ñ
ð ð
ð ð	
ð
 !ð
ð ð
ð ð
ð 
ó
ðF $(Ø#ñ
ð ð
ð ð	
ð
 !ð
ð ð
ð ð
ð 
ó
ðD $(Ø#ñ
ð ð
ð ð	
ð
 !ð
ð ð
ð ð
ð 
ô
r?   r‚   c                  ó¼   — e Zd ZdZed	d„«       Zeddœ	 	 	 	 	 	 	 	 	 	 	 d
d„«       Zddœ	 	 	 	 	 	 	 	 	 	 	 d
d„Zddœ	 	 	 	 	 	 	 	 	 	 	 d
d„Z	ddœ	 	 	 	 	 	 	 	 	 	 	 d
d„Z
y)ÚAgentTrajectoryEvaluatorz,Interface for evaluating agent trajectories.c                 ó   — y)rT   Tr>   rO   s    r@   rU   z'AgentTrajectoryEvaluator.requires_inputv  s   € ð r?   N)ra   c                ó   — y)á–  Evaluate a trajectory.

        Args:
            prediction (str): The final predicted response.
            agent_trajectory (List[Tuple[AgentAction, str]]):
                The intermediate steps forming the agent trajectory.
            input (str): The input to the agent.
            reference (Optional[str]): The reference answer.

        Returns:
            dict: The evaluation result.
        Nr>   ©rP   ru   Úagent_trajectoryrr   ra   rF   s         r@   Ú_evaluate_agent_trajectoryz3AgentTrajectoryEvaluator._evaluate_agent_trajectory{  rH   r?   c             ‹  óV   K  — t        d| j                  f||||dœ|¤Žƒ d{  –—† S 7 Œ­w)á¥  Asynchronously evaluate a trajectory.

        Args:
            prediction (str): The final predicted response.
            agent_trajectory (List[Tuple[AgentAction, str]]):
                The intermediate steps forming the agent trajectory.
            input (str): The input to the agent.
            reference (Optional[str]): The reference answer.

        Returns:
            dict: The evaluation result.
        N)ru   r˜   ra   rr   )r   r™   r—   s         r@   Ú_aevaluate_agent_trajectoryz4AgentTrajectoryEvaluator._aevaluate_agent_trajectory’  sH   è ø€ ô* %ØØ×+Ñ+ð
ð "Ø-ØØñ
ð ñ
÷ 
ð 	
ð 
úrŒ   c               óV   — | j                  ||¬«        | j                  d||||dœ|¤ŽS )r–   r{   ©ru   rr   r˜   ra   r>   )rd   r™   r—   s         r@   Úevaluate_agent_trajectoryz2AgentTrajectoryEvaluator.evaluate_agent_trajectory±  sG   € ð* 	×#Ñ#¨iÀÐ#ÔFØ.ˆt×.Ñ.ð 
Ø!ØØ-Øñ	
ð
 ñ
ð 	
r?   c             ‹  ór   K  — | j                  ||¬«        | j                  d||||dœ|¤Žƒ d{  –—† S 7 Œ­w)r›   r{   rž   Nr>   )rd   rœ   r—   s         r@   Úaevaluate_agent_trajectoryz3AgentTrajectoryEvaluator.aevaluate_agent_trajectoryÏ  sU   è ø€ ð* 	×#Ñ#¨iÀÐ#ÔFØ5�T×5Ñ5ð 
Ø!ØØ-Øñ	
ð
 ñ
÷ 
ð 	
ð 
úr‘   re   )ru   rh   r˜   z!Sequence[tuple[AgentAction, str]]rr   rh   ra   ri   rF   r   rI   r€   )r&   r'   r(   r)   rk   rU   r   r™   rœ   rŸ   r¡   r>   r?   r@   r“   r“   s  s@  „ Ù6àòó ðð ð $(ñð ðð <ð	ð
 ðð !ðð ðð 
òó ðð8 $(ñ
ð ð
ð <ð	
ð
 ð
ð !ð
ð ð
ð 
ó
ðJ $(ñ
ð ð
ð <ð	
ð
 ð
ð !ð
ð ð
ð 
ó
ðH $(ñ
ð ð
ð <ð	
ð
 ð
ð !ð
ð ð
ð 
ô
r?   r“   )#r)   Ú
__future__r   ÚloggingÚabcr   r   Úcollections.abcr   Úenumr   Útypingr   r	   r
   Úwarningsr   Úlangchain_core.agentsr   Úlangchain_core.language_modelsr   Úlangchain_core.runnables.configr   Úlangchain.chains.baser   Ú	getLoggerr&   Úloggerrh   r   rB   rL   rm   r‚   r“   r>   r?   r@   Ú<module>r¯      s˜   ðÙ 9å "ã ß #Ý $Ý ß 'Ñ 'Ý å -Ý <Ý ;å 'à	ˆ×	Ñ	˜8Ó	$€ô3J�C˜ô 3Jôl2�5ô 2÷0=ñ 0=ôfw
�n cô w
ôto
˜n¨cô o
ôdx
˜~¨sõ x
r?   