
    KKiQE                    :   S r SSKJr  SSKrSSKJr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  SS
KJr  SSKJr  SSKJr  \R.                  " \5      r " S S\\
5      r " S S\5      r " S S5      r " S S\\5      r " S S\\5      r " S S\\5      r g)z3Interfaces to be implemented by general evaluators.    )annotationsN)ABCabstractmethod)Sequence)Enum)Any)warn)AgentAction)BaseLanguageModel)run_in_executor)Chainc                      \ rS rSrSrSr Sr Sr Sr Sr	 Sr
 S	r S
r Sr Sr Sr Sr Sr Sr Sr Sr Sr Sr Sr SrSrg)EvaluatorType   z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_validation N)__name__
__module____qualname____firstlineno____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__static_attributes__r%       e/var/www/html/dynamic-report/venv/lib/python3.13/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                  6    \ rS rSrSr\\SS j5       5       rSrg)LLMEvalChainK   z,A base class for evaluators that use an LLM.c                    g)z#Create a new evaluator from an LLM.Nr%   )clsllmkwargss      rA   from_llmLLMEvalChain.from_llmN       r@   r%   N)rG   r   rH   r   returnrC   )	r&   r'   r(   r)   r*   classmethodr   rI   r?   r%   r@   rA   rC   rC   K   s    62  2r@   rC   c                      \ rS rSrSr\S
S j5       r\S
S j5       r\SS j5       r\SS j5       r	  S     SS jjr
S	rg)_EvalArgsMixinT   z(Mixin for checking evaluation arguments.c                    gz2Whether this evaluator requires a reference label.Fr%   selfs    rA   requires_reference!_EvalArgsMixin.requires_referenceW        r@   c                    g)0Whether this evaluator requires an input string.Fr%   rS   s    rA   requires_input_EvalArgsMixin.requires_input\   rW   r@   c                6    SU R                   R                   S3$ )z&Warning to show when input is ignored.zIgnoring input in , as it is not expected.	__class__r&   rS   s    rA   _skip_input_warning"_EvalArgsMixin._skip_input_warninga   s     $DNN$;$;#<<TUUr@   c                6    SU R                   R                   S3$ )z*Warning to show when reference is ignored.zIgnoring reference in r]   r^   rS   s    rA   _skip_reference_warning&_EvalArgsMixin._skip_reference_warningf   s!     %T^^%<%<$==UV	
r@   Nc                   U R                   (       a'  Uc$  U R                  R                   S3n[        U5      eUb%  U R                   (       d  [	        U R
                  SS9  U R                  (       a'  Uc$  U R                  R                   S3n[        U5      eUb'  U R                  (       d  [	        U R                  SS9  ggg)a  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.)rZ   r_   r&   
ValueErrorr	   r`   rU   rc   )rT   	referenceinput_msgs       rA   _check_evaluation_args%_EvalArgsMixin._check_evaluation_argsm   s     6>^^,,--GHCS/!d&9&9))a8""y'8^^,,--JKCS/! )@)@--!< *A r@   r%   rL   boolrL   str)NN)ri   
str | Nonerj   rr   rL   None)r&   r'   r(   r)   r*   propertyrU   rZ   r`   rc   rl   r?   r%   r@   rA   rO   rO   T   s    2    V V 
 
 !%!== = 
	= =r@   rO   c                      \ rS rSrSr\SS j5       r\SS j5       r\SSS.         SS jj5       r	SSS.         SS jjr
SSS.         SS	 jjrSSS.         SS
 jjrSrg)StringEvaluator   z}String evaluator interface.

Grade, tag, or otherwise evaluate predictions relative to their inputs
and/or reference labels.
c                .    U R                   R                  $ )zThe name of the evaluation.r^   rS   s    rA   evaluation_nameStringEvaluator.evaluation_name   s     ~~&&&r@   c                    grR   r%   rS   s    rA   rU   "StringEvaluator.requires_reference   rW   r@   Nri   inputc                   g)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%   rT   
predictionri   r~   rH   s        rA   _evaluate_strings!StringEvaluator._evaluate_strings   rK   r@   c               T   #    [        SU R                  4UUUS.UD6I Sh  vN $  N7f)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r   ri   r~   )r   r   r   s        rA   _aevaluate_strings"StringEvaluator._aevaluate_strings   sD     . %""
 "
 
 
 	
 
s   (&(c               L    U R                  X#S9  U R                  " SUUUS.UD6$ )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.
ri   rj   r   r%   )rl   r   r   s        rA   evaluate_strings StringEvaluator.evaluate_strings   s@    & 	##i#F%% 
!
 	
 	
r@   c               h   #    U R                  X#S9  U R                  " SUUUS.UD6I Sh  vN $  N7f)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   r   Nr%   )rl   r   r   s        rA   aevaluate_strings!StringEvaluator.aevaluate_strings   sM     & 	##i#F,, 
!
 	
 
 	
 
s   )202r%   rp   rn   )
r   z	str | Anyri   str | Any | Noner~   r   rH   r   rL   dict)
r   rq   ri   rr   r~   rr   rH   r   rL   r   )r&   r'   r(   r)   r*   rt   ry   rU   r   r   r   r   r   r?   r%   r@   rA   rv   rv      s@    ' '   
 '+"&  $	
    
 8 '+"&
 
 $	

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

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

 
 
 

 
r@   rv   c                      \ rS rSrSr\SSS.           S
S jj5       rSSS.           S
S jjrSSS.           S
S jjrSSS.           S
S jjr	S	r
g)PairwiseStringEvaluatori	  zDCompare the output of two models (or two outputs of the same model).Nr}   c                   g)  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%   rT   r   prediction_bri   r~   rH   s         rA   _evaluate_string_pairs.PairwiseStringEvaluator._evaluate_string_pairs  rK   r@   c               V   #    [        SU R                  4UUUUS.UD6I Sh  vN $  N7f)  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r   r   ri   r~   )r   r   r   s         rA   _aevaluate_string_pairs/PairwiseStringEvaluator._aevaluate_string_pairs#  sG     * %''
 "%
 
 
 	
 
    )')c               N    U R                  X4S9  U R                  " SUUUUS.UD6$ )r   r   r   r%   )rl   r   r   s         rA   evaluate_string_pairs-PairwiseStringEvaluator.evaluate_string_pairsB  sC    * 	##i#F** 
!%	

 
 	
r@   c               j   #    U R                  X4S9  U R                  " SUUUUS.UD6I Sh  vN $  N7f)r   r   r   Nr%   )rl   r   r   s         rA   aevaluate_string_pairs.PairwiseStringEvaluator.aevaluate_string_pairs`  sP     * 	##i#F11 
!%	

 
 
 	
 
   *313r%   )r   rq   r   rq   ri   rr   r~   rr   rH   r   rL   r   )r&   r'   r(   r)   r*   r   r   r   r   r   r?   r%   r@   rA   r   r   	  s=   N !%   	
    
 6 !% 
 
 	

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

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

 
 
 
 

 
r@   r   c                      \ rS rSrSr\SS j5       r\SS.           SS jj5       rSS.           SS jjr	SS.           SS jjr
SS.           SS	 jjrS
rg)AgentTrajectoryEvaluatori  z,Interface for evaluating agent trajectories.c                    g)rY   Tr%   rS   s    rA   rZ   'AgentTrajectoryEvaluator.requires_input  s     r@   N)ri   c                   g)8  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%   rT   r   agent_trajectoryr~   ri   rH   s         rA   _evaluate_agent_trajectory3AgentTrajectoryEvaluator._evaluate_agent_trajectory  rK   r@   c               V   #    [        SU R                  4UUUUS.UD6I Sh  vN $  N7f)G  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)r   r   ri   r~   )r   r   r   s         rA   _aevaluate_agent_trajectory4AgentTrajectoryEvaluator._aevaluate_agent_trajectory  sG     , %++
 "-
 
 
 	
 
r   c               N    U R                  XCS9  U R                  " SUUUUS.UD6$ )r   r   r   r~   r   ri   r%   )rl   r   r   s         rA   evaluate_agent_trajectory2AgentTrajectoryEvaluator.evaluate_agent_trajectory  sC    , 	##i#F.. 
!-	

 
 	
r@   c               j   #    U R                  XCS9  U R                  " SUUUUS.UD6I Sh  vN $  N7f)r   r   r   Nr%   )rl   r   r   s         rA   aevaluate_agent_trajectory3AgentTrajectoryEvaluator.aevaluate_agent_trajectory  sP     , 	##i#F55 
!-	

 
 
 	
 
r   r%   rn   )r   rq   r   z!Sequence[tuple[AgentAction, str]]r~   rq   ri   rr   rH   r   rL   r   )r&   r'   r(   r)   r*   rt   rZ   r   r   r   r   r   r?   r%   r@   rA   r   r     sE   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&   loggerrq   r   rC   rO   rv   r   r   r%   r@   rA   <module>r      s    9 "  # $    - < ; /			8	$3JC 3Jl25 21= 1=h~
nc ~
Bs
nc s
l|
~s |
r@   