class_docstr: LIT WSGI application.
class_docstr_tok: ["LIT","WSGI","application","."]
docstr: Run the specified Metrics components.
  
  Args:
    data: JSON parsed from the HTTP Request body containing the inputs
      (required) and config (optional) for parameterizing the Metrics calls.
    model: The name of the model loaded in LIT, used to fetch the model
      predictions.
    dataset_name: The name of the dataset containing the ground truth labels
      for the provided inputs.
    metrics: An optional comma-separated string of metrics to run, if None it
      will run all Metrics loaded in this LitApp instance.
    do_predict: If true (default), will fetch the model predictions in this
      function using `_get_preds()` and pass them through to each Metrics
      component's run function.
    **unused_kw: Unused keyword arguments.
  
  Returns:
    A dictionary of metrics results where the keys are the name of the
    Metrics component and the values are list of dictionaries containing the
    prediction key (`pred_key`), the label key (`label_key`), and `metrics`
    for that pair of keys as a `Mapping[str, float]`.
  
  Raises:
    KeyError: If a model, dataset, or metric with the specified name is not
      loaded in the LitApp instance.
    ValueError: If there are no inputs.
code: def _get_metrics(
      self,
      data: types.JsonDict,
      model: Optional[str] = None,
      dataset_name: Optional[str] = None,
      metrics: Optional[str] = None,
      # TODO(b/278586715): Remove this parameter once linked bug is fixed.
      do_predict: str = "1",  # bool URL param; encoding as "0" /  "1" is safer.
      **unused_kw,
  ) -> types.JsonDict:
      """Run the specified Metrics components.
  
      Args:
        data: JSON parsed from the HTTP Request body containing the inputs
          (required) and config (optional) for parameterizing the Metrics calls.
        model: The name of the model loaded in LIT, used to fetch the model
          predictions.
        dataset_name: The name of the dataset containing the ground truth labels
          for the provided inputs.
        metrics: An optional comma-separated string of metrics to run, if None it
          will run all Metrics loaded in this LitApp instance.
        do_predict: If true (default), will fetch the model predictions in this
          function using `_get_preds()` and pass them through to each Metrics
          component's run function.
        **unused_kw: Unused keyword arguments.
  
      Returns:
        A dictionary of metrics results where the keys are the name of the
        Metrics component and the values are list of dictionaries containing the
        prediction key (`pred_key`), the label key (`label_key`), and `metrics`
        for that pair of keys as a `Mapping[str, float]`.
  
      Raises:
        KeyError: If a model, dataset, or metric with the specified name is not
          loaded in the LitApp instance.
        ValueError: If there are no inputs.
      """
      if dataset_name is None:
          raise ValueError(
              'Must provide a "dataset_name" to get examples.'
          )
      if model is None:
          raise ValueError(
              'Must provide a "model" name to get predictions.'
          )
  
      inputs = data.get("inputs")
      if not inputs:
          raise ValueError("Metrics cannot be computed without inputs.")
  
      if metrics:
          metrics_to_run = tuple(m for m in metrics.split(",") if m)
          unknown_metrics = [
              m for m in metrics_to_run if m not in self._metrics
          ]
          if unknown_metrics:
              raise KeyError(
                  f'Requested unknown metrics "{unknown_metrics}".'
              )
      else:
          metrics_to_run = tuple(self._metrics.keys())
  
      if utils.coerce_bool(do_predict):
          model_outputs = self._get_preds(data=data, model=model)
      else:
          model_outputs = None
  
      dataset: lit_dataset.IndexedDataset = self._datasets[dataset_name]
      mdl: lit_model.Model = self._models[model]
      config: Optional[types.JsonDict] = data.get("config")
  
      results: dict[str, Any] = {}
      for name in metrics_to_run:
          # TODO(b/254833485): Add type annotation once the metrics wrapper classes
          # inherit from lit_component.Metrics.
          metric = self._metrics[name]
  
          config_spec: types.Spec = metric.config_spec()
          if config_spec and config is not None:
              utils.validate_config_against_spec(
                  config, config_spec, f"Metric {name}"
              )
  
          results[name] = metric.run(
              [ex["data"] for ex in inputs],
              mdl,
              dataset,
              model_outputs=model_outputs,
              config=config,
          )
  
      return results
  
imports: from collections.abc import Callable, Iterable, Mapping, Sequence
  import functools
  import glob
  import math
  import os
  import random
  import threading
  import time
  from typing import Any, Optional, TypedDict, Union
  from absl import logging
  from lit_nlp.api import components
  from lit_nlp.api import dataset
  from lit_nlp.api import layout
  from lit_nlp.api import model
  from lit_nlp.api import types
  from lit_nlp.components import core
  from lit_nlp.lib import caching
  from lit_nlp.lib import flag_helpers
  from lit_nlp.lib import serialize
  from lit_nlp.lib import ui_state
  from lit_nlp.lib import utils
  from lit_nlp.lib import validation
  from lit_nlp.lib import wsgi_app
  import tqdm
label_desc: Use image node_id 17 for calling the LitApp obj's underlying member method code with example usage: obj._get_metrics(data, model, dataset_name, metrics, do_predict) and returns: results