
    3fiQE                    :   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 y)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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     a/var/www/auto_recruiter/arenv/lib/python3.12/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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)rC   r   rD   r   returnr@   )r$   r%   r&   r'   classmethodr   rE   r<   r=   r>   r@   r@   K   s    62  2r=   r@   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<   rM   s    r>   requires_inputz_EvalArgsMixin.requires_input\   rP   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$   rM   s    r>   _skip_input_warningz"_EvalArgsMixin._skip_input_warninga   s     $DNN$;$;#<<TUUr=   c                6    d| j                   j                   dS )z*Warning to show when reference is ignored.zIgnoring reference in rU   rV   rM   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)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.)rS   rW   r$   
ValueErrorr	   rX   rO   rZ   )rN   	referenceinput_msgs       r>   _check_evaluation_argsz%_EvalArgsMixin._check_evaluation_argsm   s     6>^^,,--GHCS/!d&9&9))a8""y'8^^,,--JKCS/! )@)@--!< *A r=   rG   boolrG   str)NN)r_   
str | Noner`   rg   rG   None)
r$   r%   r&   r'   propertyrO   rS   rX   rZ   rb   r<   r=   r>   rJ   rJ   T   s~    2    V V 
 
 !%!== = 
	=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y)StringEvaluatorzString evaluator interface.

    Grade, tag, or otherwise evaluate predictions relative to their inputs
    and/or reference labels.
    c                .    | j                   j                  S )zThe name of the evaluation.rV   rM   s    r>   evaluation_namezStringEvaluator.evaluation_name   s     ~~&&&r=   c                     yrL   r<   rM   s    r>   rO   z"StringEvaluator.requires_reference   rP   r=   Nr_   inputc                    y)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<   rN   
predictionr_   rp   rD   s        r>   _evaluate_stringsz!StringEvaluator._evaluate_strings   rF   r=   c               T   K   t        d| j                  f|||d| d{   S 7 w)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rs   r_   rp   )r   rt   rr   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: 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`   rv   r<   )rb   rt   rr   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: 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.
        ry   rv   Nr<   )rb   rw   rr   s        r>   aevaluate_stringsz!StringEvaluator.aevaluate_strings   sR     & 	##i#F,T,, 
!
 	
 
 	
 
s   -646re   rc   )
rs   z	str | Anyr_   str | Any | Nonerp   r}   rD   r   rG   dict)
rs   rf   r_   rg   rp   rg   rD   r   rG   r~   )r$   r%   r&   r'   ri   rm   rO   r   rt   rw   rz   r|   r<   r=   r>   rk   rk      s;    ' '   
 '+"&  $	
    
 8 '+"&
 
 $	

  
 
 

H !% 
 
 	

 
 
 

> !% 
 
 	

 
 
 

r=   rk   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).Nro   c                    y)  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<   rN   rs   prediction_br_   rp   rD   s         r>   _evaluate_string_pairsz.PairwiseStringEvaluator._evaluate_string_pairs  rF   r=   c               V   K   t        d| j                  f||||d| d{   S 7 w)  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rs   r   r_   rp   )r   r   r   s         r>   _aevaluate_string_pairsz/PairwiseStringEvaluator._aevaluate_string_pairs#  sH     * %''
 "%
 
 
 	
 
    )')c               V    | j                  ||        | j                  d||||d|S )r   ry   r   r<   )rb   r   r   s         r>   evaluate_string_pairsz-PairwiseStringEvaluator.evaluate_string_pairsB  sG    * 	##i#F*t** 
!%	

 
 	
r=   c               r   K   | j                  ||        | j                  d||||d| d{   S 7 w)r   ry   r   Nr<   )rb   r   r   s         r>   aevaluate_string_pairsz.PairwiseStringEvaluator.aevaluate_string_pairs`  sU     * 	##i#F1T11 
!%	

 
 
 	
 
   .757)rs   rf   r   rf   r_   rg   rp   rg   rD   r   rG   r~   )	r$   r%   r&   r'   r   r   r   r   r   r<   r=   r>   r   r   	  s8   N !%   	
    
 6 !% 
 
 	

 
 
 
 

H !% 
 
 	

 
 
 
 

F !% 
 
 	

 
 
 
 

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)rR   Tr<   rM   s    r>   rS   z'AgentTrajectoryEvaluator.requires_input  s     r=   N)r_   c                    y)  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<   rN   rs   agent_trajectoryrp   r_   rD   s         r>   _evaluate_agent_trajectoryz3AgentTrajectoryEvaluator._evaluate_agent_trajectory  rF   r=   c               V   K   t        d| j                  f||||d| d{   S 7 w)  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)rs   r   r_   rp   )r   r   r   s         r>   _aevaluate_agent_trajectoryz4AgentTrajectoryEvaluator._aevaluate_agent_trajectory  sH     , %++
 "-
 
 
 	
 
r   c               V    | j                  ||        | j                  d||||d|S )r   ry   rs   rp   r   r_   r<   )rb   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   ry   r   Nr<   )rb   r   r   s         r>   aevaluate_agent_trajectoryz3AgentTrajectoryEvaluator.aevaluate_agent_trajectory  sU     , 	##i#F5T55 
!-	

 
 
 	
 
r   rc   )rs   rf   r   z!Sequence[tuple[AgentAction, str]]rp   rf   r_   rg   rD   r   rG   r~   )r$   r%   r&   r'   ri   rS   r   r   r   r   r   r<   r=   r>   r   r     s@   6   !%  <	
    
 : !%
 
 <	

 
 
 
 

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$   loggerrf   r   r@   rJ   rk   r   r   r<   r=   r>   <module>r      s    9 "  # $    - < ; /			8	$3JC 3Jl25 21= 1=h~
nc ~
Bs
nc s
l|
~s |
r=   