§
    ™ŠtjQE  ã                  ó\  — 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 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j        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 dS )z3Interfaces to be implemented by general evaluators.é    )ÚannotationsN)ÚABCÚabstractmethod)ÚSequence)ÚEnum)ÚAny)Ú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dS )Ú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© ó    úa/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/langchain_classic/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ÐØIÐIr=   r   c                  ó:   — e Zd ZdZeed	d„¦   «         ¦   «         ZdS )
ÚLLMEvalChainz,A base class for evaluators that use an LLM.Úllmr   Úkwargsr   Úreturnc                ó   — dS )z#Create a new evaluator from an LLM.Nr<   )ÚclsrA   rB   s      r>   Úfrom_llmzLLMEvalChain.from_llmN   ó   € € € r=   N)rA   r   rB   r   rC   r@   )r$   r%   r&   r'   Úclassmethodr   rF   r<   r=   r>   r@   r@   K   sB   € € € € € Ø6Ð6àØð2ð 2ð 2ñ „^ñ „[ð2ð 2ð 2r=   r@   c                  ó€   — 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	d	S )Ú_EvalArgsMixinz(Mixin for checking evaluation arguments.rC   Úboolc                ó   — dS ©z2Whether this evaluator requires a reference label.Fr<   ©Úselfs    r>   Úrequires_referencez!_EvalArgsMixin.requires_referenceW   ó	   € ð ˆur=   c                ó   — dS )ú0Whether this evaluator requires an input string.Fr<   rN   s    r>   Úrequires_inputz_EvalArgsMixin.requires_input\   rQ   r=   Ústrc                ó"   — d| j         j        › d�S )z&Warning to show when input is ignored.zIgnoring input in ú, as it is not expected.©Ú	__class__r$   rN   s    r>   Ú_skip_input_warningz"_EvalArgsMixin._skip_input_warninga   s   € ð V D¤NÔ$;ÐUÐUÐUÐUr=   c                ó"   — d| j         j        › d�S )z*Warning to show when reference is ignored.zIgnoring reference in rW   rX   rN   s    r>   Ú_skip_reference_warningz&_EvalArgsMixin._skip_reference_warningf   s   € ð W T¤^Ô%<ÐVÐVÐVð	
r=   NÚ	referenceú
str | NoneÚinput_ÚNonec                ó&  — | j         r |€| j        j        › d�}t          |¦  «        ‚|�| j         st	          | j        d¬¦  «         | j        r |€| j        j        › d�}t          |¦  «        ‚|�| j        st	          | j        d¬¦  «         dS dS dS )aT  Check if the evaluation arguments are valid.

        Args:
            reference: The reference label.
            input_: 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.)rT   rY   r$   Ú
ValueErrorr	   rZ   rP   r\   )rO   r]   r_   Úmsgs       r>   Ú_check_evaluation_argsz%_EvalArgsMixin._check_evaluation_argsm   s½   € ð Ôð 	" 6 >Ø”^Ô,ÐHÐHÐHˆCÝ˜S‘/”/Ð!ØÐ dÔ&9ÐÝ�Ô)°aÐ8Ñ8Ô8Ð8ØÔ"ð 	" yÐ'8Ø”^Ô,ÐKÐKÐKˆCÝ˜S‘/”/Ð!ØÐ ¨Ô)@Ð Ý�Ô-¸!Ð<Ñ<Ô<Ð<Ð<Ð<ð !Ð Ð Ð r=   ©rC   rK   ©rC   rU   )NN)r]   r^   r_   r^   rC   r`   )
r$   r%   r&   r'   ÚpropertyrP   rT   rZ   r\   rf   r<   r=   r>   rJ   rJ   T   s½   € € € € € Ø2Ð2àðð ð ñ „Xðð ðð ð ñ „Xðð ðVð Vð Vñ „XðVð ð
ð 
ð 
ñ „Xð
ð !%Ø!ð=ð =ð =ð =ð =ð =ð =r=   rJ   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dS )ÚStringEvaluatorz‰String evaluator interface.

    Grade, tag, or otherwise evaluate predictions relative to their inputs
    and/or reference labels.
    rC   rU   c                ó   — | j         j        S )zThe name of the evaluation.rX   rN   s    r>   Úevaluation_namezStringEvaluator.evaluation_name�   s   € ð Œ~Ô&Ð&r=   rK   c                ó   — dS rM   r<   rN   s    r>   rP   z"StringEvaluator.requires_reference”   rQ   r=   N©r]   ÚinputÚ
predictionú	str | Anyr]   ústr | Any | Nonerp   rB   r   Údictc               ó   — dS )aí  Evaluate Chain or LLM output, based on optional input and label.

        Args:
            prediction: The LLM or chain prediction to evaluate.
            reference: The reference label to evaluate against.
            input: The input to consider during evaluation.
            **kwargs: Additional keyword arguments, including callbacks, tags, etc.

        Returns:
            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<   ©rO   rq   r]   rp   rB   s        r>   Ú_evaluate_stringsz!StringEvaluator._evaluate_strings™   rG   r=   c             ‹  ó@   K  — t          d| j        f|||dœ|¤Žƒ d{V —†S )aü  Asynchronously evaluate Chain or LLM output, based on optional input and label.

        Args:
            prediction: The LLM or chain prediction to evaluate.
            reference: The reference label to evaluate against.
            input: The input to consider during evaluation.
            **kwargs: Additional keyword arguments, including callbacks, tags, etc.

        Returns:
            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©rq   r]   rp   )r   rw   rv   s        r>   Ú_aevaluate_stringsz"StringEvaluator._aevaluate_strings²   s`   è è € õ. %ØØÔ"ð
ð "ØØð
ð 
ð ð
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 	
r=   r^   c               óR   — |                       ||¬¦  «          | j        d|||dœ|¤ŽS )a½  Evaluate Chain or LLM output, based on optional input and label.

        Args:
            prediction: The LLM or chain prediction to evaluate.
            reference: The reference label to evaluate against.
            input: The input to consider during evaluation.
            **kwargs: Additional keyword arguments, including callbacks, tags, etc.

        Returns:
            The evaluation results containing the score or value.
        ©r]   r_   ry   r<   )rf   rw   rv   s        r>   Úevaluate_stringsz StringEvaluator.evaluate_stringsÒ   sQ   € ð& 	×#Ò#¨iÀÐ#ÑFÔFÐFØ%ˆtÔ%ð 
Ø!ØØð
ð 
ð ð	
ð 
ð 	
r=   c             ‹  ób   K  — |                       ||¬¦  «          | j        d|||dœ|¤Žƒ d{V —†S )aÌ  Asynchronously evaluate Chain or LLM output, based on optional input and label.

        Args:
            prediction: The LLM or chain prediction to evaluate.
            reference: The reference label to evaluate against.
            input: The input to consider during evaluation.
            **kwargs: Additional keyword arguments, including callbacks, tags, etc.

        Returns:
            The evaluation results containing the score or value.
        r|   ry   Nr<   )rf   rz   rv   s        r>   Úaevaluate_stringsz!StringEvaluator.aevaluate_stringsí   ss   è è € ð& 	×#Ò#¨iÀÐ#ÑFÔFÐFØ,�TÔ,ð 
Ø!ØØð
ð 
ð ð	
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 	
r=   rh   rg   )
rq   rr   r]   rs   rp   rs   rB   r   rC   rt   )
rq   rU   r]   r^   rp   r^   rB   r   rC   rt   )r$   r%   r&   r'   ri   rm   rP   r   rw   rz   r}   r   r<   r=   r>   rk   rk   ˆ   s  € € € € € ðð ð ð'ð 'ð 'ñ „Xð'ð ðð ð ñ „Xðð ð
 '+Ø"&ðð ð ð ð ñ „^ðð8 '+Ø"&ð
ð 
ð 
ð 
ð 
ð 
ðH !%Ø ð
ð 
ð 
ð 
ð 
ð 
ð> !%Ø ð
ð 
ð 
ð 
ð 
ð 
ð 
ð 
r=   rk   c                  ób   — 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dS )ÚPairwiseStringEvaluatorzDCompare the output of two models (or two outputs of the same model).Nro   rq   rU   Úprediction_br]   r^   rp   rB   r   rC   rt   c               ó   — dS )áè  Evaluate the output string pairs.

        Args:
            prediction: The output string from the first model.
            prediction_b: The output string from the second model.
            reference: The expected output / reference string.
            input: The input string.
            **kwargs: Additional keyword arguments, such as callbacks and optional reference strings.

        Returns:
            `dict` containing the preference, scores, and/or other information.
        Nr<   ©rO   rq   r‚   r]   rp   rB   s         r>   Ú_evaluate_string_pairsz.PairwiseStringEvaluator._evaluate_string_pairs  rG   r=   c             ‹  óB   K  — t          d| j        f||||dœ|¤Žƒ d{V —†S )á÷  Asynchronously evaluate the output string pairs.

        Args:
            prediction: The output string from the first model.
            prediction_b: The output string from the second model.
            reference: The expected output / reference string.
            input: The input string.
            **kwargs: Additional keyword arguments, such as callbacks and optional reference strings.

        Returns:
            `dict` containing the preference, scores, and/or other information.
        N©rq   r‚   r]   rp   )r   r†   r…   s         r>   Ú_aevaluate_string_pairsz/PairwiseStringEvaluator._aevaluate_string_pairs#  sc   è è € õ* %ØØÔ'ð
ð "Ø%ØØð
ð 
ð ð
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 	
r=   c               óT   — |                       ||¬¦  «          | j        d||||dœ|¤ŽS )r„   r|   r‰   r<   )rf   r†   r…   s         r>   Úevaluate_string_pairsz-PairwiseStringEvaluator.evaluate_string_pairsB  sT   € ð* 	×#Ò#¨iÀÐ#ÑFÔFÐFØ*ˆtÔ*ð 
Ø!Ø%ØØð	
ð 
ð
 ð
ð 
ð 	
r=   c             ‹  ód   K  — |                       ||¬¦  «          | j        d||||dœ|¤Žƒ d{V —†S )rˆ   r|   r‰   Nr<   )rf   rŠ   r…   s         r>   Úaevaluate_string_pairsz.PairwiseStringEvaluator.aevaluate_string_pairs`  sv   è è € ð* 	×#Ò#¨iÀÐ#ÑFÔFÐFØ1�TÔ1ð 
Ø!Ø%ØØð	
ð 
ð
 ð
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 	
r=   )rq   rU   r‚   rU   r]   r^   rp   r^   rB   r   rC   rt   )	r$   r%   r&   r'   r   r†   rŠ   rŒ   rŽ   r<   r=   r>   r�   r�   	  s¾   € € € € € ØNÐNàð !%Ø ðð ð ð ð ñ „^ðð6 !%Ø ð
ð 
ð 
ð 
ð 
ð 
ðH !%Ø ð
ð 
ð 
ð 
ð 
ð 
ðF !%Ø ð
ð 
ð 
ð 
ð 
ð 
ð 
ð 
r=   r�   c                  ór   — 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
dS )ÚAgentTrajectoryEvaluatorz,Interface for evaluating agent trajectories.rC   rK   c                ó   — dS )rS   Tr<   rN   s    r>   rT   z'AgentTrajectoryEvaluator.requires_input‚  s	   € ð ˆtr=   N)r]   rq   rU   Úagent_trajectoryú!Sequence[tuple[AgentAction, str]]rp   r]   r^   rB   r   rt   c               ó   — dS )áˆ  Evaluate a trajectory.

        Args:
            prediction: The final predicted response.
            agent_trajectory:
                The intermediate steps forming the agent trajectory.
            input: The input to the agent.
            reference: The reference answer.
            **kwargs: Additional keyword arguments.

        Returns:
            The evaluation result.
        Nr<   ©rO   rq   r’   rp   r]   rB   s         r>   Ú_evaluate_agent_trajectoryz3AgentTrajectoryEvaluator._evaluate_agent_trajectory‡  rG   r=   c             ‹  óB   K  — t          d| j        f||||dœ|¤Žƒ d{V —†S )á—  Asynchronously evaluate a trajectory.

        Args:
            prediction: The final predicted response.
            agent_trajectory:
                The intermediate steps forming the agent trajectory.
            input: The input to the agent.
            reference: The reference answer.
            **kwargs: Additional keyword arguments.

        Returns:
            The evaluation result.
        N)rq   r’   r]   rp   )r   r—   r–   s         r>   Ú_aevaluate_agent_trajectoryz4AgentTrajectoryEvaluator._aevaluate_agent_trajectoryŸ  sc   è è € õ, %ØØÔ+ð
ð "Ø-ØØð
ð 
ð ð
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 	
r=   c               óT   — |                       ||¬¦  «          | j        d||||dœ|¤ŽS )r•   r|   ©rq   rp   r’   r]   r<   )rf   r—   r–   s         r>   Úevaluate_agent_trajectoryz2AgentTrajectoryEvaluator.evaluate_agent_trajectory¿  sT   € ð, 	×#Ò#¨iÀÐ#ÑFÔFÐFØ.ˆtÔ.ð 
Ø!ØØ-Øð	
ð 
ð
 ð
ð 
ð 	
r=   c             ‹  ód   K  — |                       ||¬¦  «          | j        d||||dœ|¤Žƒ d{V —†S )r™   r|   rœ   Nr<   )rf   rš   r–   s         r>   Úaevaluate_agent_trajectoryz3AgentTrajectoryEvaluator.aevaluate_agent_trajectoryÞ  sv   è è € ð, 	×#Ò#¨iÀÐ#ÑFÔFÐFØ5�TÔ5ð 
Ø!ØØ-Øð	
ð 
ð
 ð
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 	
r=   rg   )rq   rU   r’   r“   rp   rU   r]   r^   rB   r   rC   rt   )r$   r%   r&   r'   ri   rT   r   r—   rš   r�   rŸ   r<   r=   r>   r�   r�     sÒ   € € € € € Ø6Ð6àðð ð ñ „Xðð ð !%ðð ð ð ð ñ „^ðð: !%ð
ð 
ð 
ð 
ð 
ð 
ðL !%ð
ð 
ð 
ð 
ð 
ð 
ðJ !%ð
ð 
ð 
ð 
ð 
ð 
ð 
ð 
r=   r�   )!r'   Ú
__future__r   ÚloggingÚabcr   r   Úcollections.abcr   Úenumr   Útypingr   Úwarningsr	   Úlangchain_core.agentsr
   Úlangchain_core.language_modelsr   Úlangchain_core.runnables.configr   Úlangchain_classic.chains.baser   Ú	getLoggerr$   ÚloggerrU   r   r@   rJ   rk   r�   r�   r<   r=   r>   ú<module>r­      s  ðØ 9Ð 9à "Ð "Ð "Ð "Ð "Ð "à €€€Ø #Ð #Ð #Ð #Ð #Ð #Ð #Ð #Ø $Ð $Ð $Ð $Ð $Ð $Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð à -Ð -Ð -Ð -Ð -Ð -Ø <Ð <Ð <Ð <Ð <Ð <Ø ;Ð ;Ð ;Ð ;Ð ;Ð ;à /Ð /Ð /Ð /Ð /Ð /à	ˆÔ	˜8Ñ	$Ô	$€ð3Jð 3Jð 3Jð 3Jð 3J�C˜ñ 3Jô 3Jð 3Jðl2ð 2ð 2ð 2ð 2�5ñ 2ô 2ð 2ð1=ð 1=ð 1=ð 1=ð 1=ñ 1=ô 1=ð 1=ðh~
ð ~
ð ~
ð ~
ð ~
�n cñ ~
ô ~
ð ~
ðBs
ð s
ð s
ð s
ð s
˜n¨cñ s
ô s
ð s
ðl|
ð |
ð |
ð |
ð |
˜~¨sñ |
ô |
ð |
ð |
ð |
r=   