
    ci:                         d Z ddlZddlmZmZmZmZmZ ddlm	Z	 ddl
mZ  G d dej                        Z G d d	e      Z G d
 de      Z G d de      Z G d de      Zy)z$Base classes for evaluation metrics.    N)AnyCallableDictLiteralUnion)	constants)metric_prompt_templatec                   8    e Zd ZdZdefdZd Zedefd       Zy)_Metricz)The abstract class for evaluation metric.metricc                     || _         y N_metric)selfr   s     H/tmp/pip-target-z3e9_cxr/lib/python/vertexai/evaluation/metrics/_base.py__init__z_Metric.__init__   s	        c                     | j                   S r   )metric_namer   s    r   __str__z_Metric.__str__"   s    r   returnc                     | j                   S r   r   r   s    r   r   z_Metric.metric_name%   s    ||r   N)	__name__
__module____qualname____doc__strr   r   propertyr    r   r   r   r      s1    3s   S  r   r   c                   `     e Zd ZdZdedeej                  ej                  ef   f fdZ	 xZ
S )_ModelBasedMetrica  A Model-based Metric.

    An evaluation metric that evaluates generative AI model responses with
    another generative model as a judge. This metric can be used to evaluate a
    single model, or two models side-by-side.

    For more details on when to use model-based metrics, see
    [Evaluation methods and metrics](https://cloud.google.com/vertex-ai/generative-ai/docs/models/determine-eval).
    r   r	   c                T    t         |   |       || _        t        |      | _        y)a  Initializes the model-based evaluation metric.

        Args:
          metric: Generic model based metric name.
          metric_prompt_template: A metric prompt template for performing
            the model-based evaluation. A freeform string is also accepted.
        r   N)superr   _raw_metric_prompt_templater   r	   )r   r   r	   	__class__s      r   r   z_ModelBasedMetric.__init__5   s+    " 	'+A(&)*@&A#r   )r   r   r   r   r   r   metric_prompt_template_basePointwiseMetricPromptTemplatePairwiseMetricPromptTemplater   __classcell__r(   s   @r   r#   r#   *   sI    B B !&'EE'DD!
	B Br   r#   c                   L     e Zd ZdZdedeeeef   geeef   f   f fdZ xZ	S )CustomMetrica  The custom evaluation metric.

    A fully-customized CustomMetric that can be used to evaluate a single model
    by defining a metric function for a computation-based metric. The
    CustomMetric is computed on the client-side using the user-defined metric
    function in SDK only, not by the Vertex Gen AI Evaluation Service.

      Attributes:
        name: The name of the metric.
        metric_function: The user-defined evaluation function to compute a metric
          score. Must use the dataset row dictionary as the metric function
          input and return per-instance metric result as a dictionary output.
          The metric score must mapped to the name of the CustomMetric as key.
    namemetric_functionc                 @    t         |   |       || _        || _        y)z"Initializes the evaluation metric.N)r&   r   r0   r1   )r   r0   r1   r(   s      r   r   zCustomMetric.__init__[   s!     		.r   )
r   r   r   r   r   r   r   r   r   r,   r-   s   @r   r/   r/   K   sG    // "#s(^cN
/ /r   r/   c                   V     e Zd ZdZdeej                  j                     f fdZ xZ	S )_AutomaticMetrica  An automatic metric that computes deterministic score based on reference.

    An lexicon-based evaluation metric that evaluate a generative model's
    response on the given evaluation task with reference ground truth answers.
    It is a type of pointwise evaluation metric.

    For more details on when to use automatic metrics, see
    [Evaluation methods and
    metrics](https://cloud.google.com/vertex-ai/generative-ai/docs/models/determine-eval).
    r   c                 &    t         |   |       y)z|Initializes the automatic evaluation metric.

        Args:
          metric: The automatic evaluation metric name.
        r%   N)r&   r   )r   r   r(   s     r   r   z_AutomaticMetric.__init__u   s     	'r   )
r   r   r   r   r   r   MetricROUGEr   r,   r-   s   @r   r4   r4   i   s+    		(	((../	( 	(r   r4   c                   v     e Zd ZdZdedededef fdZedefd       Zedefd	       Zedefd
       Z	 xZ
S )_TranslationMetricah  A Translation Metric.

    Evaluates a score for the given instance using an underlying machine
    learning model.
    For now, only COMET and MetricX are supported.

    For more details on how to evaluate translation, see
    [Evaluation a translation
    model](https://cloud.google.com/vertex-ai/generative-ai/docs/models/run-evaluation#translation).
    r0   versionsource_languagetarget_languagec                 P    || _         || _        || _        t        |   |       y)a  Initializes the Translation metric.

        Args:
          name: The name of the metric.
          version: The version to use for evaluation.
          source_language: The source language of the translation.
          target_language: The target language of the translation.
        r%   N)_version_source_language_target_languager&   r   )r   r0   r:   r;   r<   r(   s        r   r   z_TranslationMetric.__init__   s,       / /%r   r   c                     | j                   S r   )r>   r   s    r   r:   z_TranslationMetric.version   s    }}r   c                     | j                   S r   )r?   r   s    r   r;   z"_TranslationMetric.source_language       $$$r   c                     | j                   S r   )r@   r   s    r   r<   z"_TranslationMetric.target_language   rC   r   )r   r   r   r   r   r   r    r:   r;   r<   r,   r-   s   @r   r9   r9      s    	&& & 	&
 &*    % % % % % %r   r9   )r   abctypingr   r   r   r   r   vertexai.evaluationr   vertexai.evaluation.metricsr	   r)   ABCr   r#   r/   r4   r9   r!   r   r   <module>rJ      s^   " + 
 6 6 )
cgg B BB/7 /<(w (0+% +%r   