code: def QueryBasedMetricsEvaluator(  # pylint: disable=invalid-name
      query_id: str,
      prediction_key: str,
      combine_fns: List[beam.CombineFn],
      metrics_key: str = constants.METRICS_KEY,
      run_after: Optional[
          str
      ] = slice_key_extractor.SLICE_KEY_EXTRACTOR_STAGE_NAME,
  ) -> evaluator.Evaluator:
      """Creates an Evaluator for evaluating metrics and plots.
  
      Args:
        query_id: Key of query ID column in the features dictionary.
        prediction_key: Key in predictions dictionary to use as the prediction (for
          sorting examples within the query). Use the empty string if the Estimator
          returns a predictions Tensor (not a dictionary).
        combine_fns: List of query based metrics combine functions.
        metrics_key: Name to use for metrics key in Evaluation output.
        run_after: Extractor to run after (None means before any extractors).
  
      Returns:
        Evaluator for computing query-based metrics. The output will be stored under
        'metrics' and 'plots' keys.
      """
      # pylint: disable=no-value-for-parameter
      return evaluator.Evaluator(
          stage_name="EvaluateQueryBasedMetrics",
          run_after=run_after,
          ptransform=EvaluateQueryBasedMetrics(
              query_id=query_id,
              prediction_key=prediction_key,
              combine_fns=combine_fns,
              metrics_key=metrics_key,
          ),
      )
  
imports: from typing import Any, Dict, Iterable, Iterator, List, Optional, Tuple
  import apache_beam
  import numpy
  import tensorflow
  from tensorflow_model_analysis import constants
  from tensorflow_model_analysis.api import types
  from tensorflow_model_analysis.eval_saved_model import constants
  from tensorflow_model_analysis.eval_saved_model import encoding
  from tensorflow_model_analysis.eval_saved_model import util
  from tensorflow_model_analysis.evaluators import evaluator
  from tensorflow_model_analysis.evaluators.query_metrics import query_types
  from tensorflow_model_analysis.extractors import extractor
  from tensorflow_model_analysis.extractors import slice_key_extractor
label_desc: Use image node_id 1 for calling a global function with example usage: QueryBasedMetricsEvaluator(query_id, prediction_key, combine_fns, metrics_key, run_after) and returns: evaluator