class_docstr: LIT WSGI application.
class_docstr_tok: ["LIT","WSGI","application","."]
docstr: Get model predictions.
  
  Args:
    data: data payload, containing 'inputs' field
    model: name of the model to run
    requested_types: optional, comma-separated list of type names to return
    requested_fields: optional, comma-separated list of field names to return
      in addition to the ones returned due to 'requested_types'.
    **kw: additional args passed to model.predict()
  
  Returns:
    list[JsonDict] containing requested fields of model predictions
  
  Raises:
    KeyError: If `data` does not have an 'inputs' property.
    TypeError: If one of entries in `requested_types` is not a valid LitType.
    ValueError: If the model returns a different number of predictions than
      the number of inputs.
docstr_tok: ["Get","model","predictions",".","Args",":","data",":","data","payload",",","containing","'inputs","'","field","model",":","name","of","the","model","to","run","requested_types",":","optional",",","comma-separated","list","of","type","names","to","return","requested_fields",":","optional",",","comma-separated","list","of","field","names","to","return","in","addition","to","the","ones","returned","due","to","'requested_types","'",".","*","*","kw",":","additional","args","passed","to","model.predict","(",")","Returns",":","list","[","JsonDict","]","containing","requested","fields","of","model","predictions","Raises",":","KeyError",":","If","`","data","`","does","not","have","an","'inputs","'","property",".","TypeError",":","If","one","of","entries","in","`","requested_types","`","is","not","a","valid","LitType",".","ValueError",":","If","the","model","returns","a","different","number","of","predictions","than","the","number","of","inputs","."]
code: def _get_preds(
      self,
      data: types.JsonDict,
      model: Optional[str] = None,
      requested_types: Optional[str] = None,
      requested_fields: Optional[str] = None,
      **kw,
  ):
      """Get model predictions.
  
      Args:
        data: data payload, containing 'inputs' field
        model: name of the model to run
        requested_types: optional, comma-separated list of type names to return
        requested_fields: optional, comma-separated list of field names to return
          in addition to the ones returned due to 'requested_types'.
        **kw: additional args passed to model.predict()
  
      Returns:
        list[JsonDict] containing requested fields of model predictions
  
      Raises:
        KeyError: If `data` does not have an 'inputs' property.
        TypeError: If one of entries in `requested_types` is not a valid LitType.
        ValueError: If the model returns a different number of predictions than
          the number of inputs.
      """
      if model is None:
          raise ValueError(
              'Must provide a "model" name to get preds from.'
          )
  
      inputs = data["inputs"]
      preds = list(
          self._models[model].predict(
              [ex["data"] for ex in inputs], **kw
          )
      )
  
      num_preds = len(preds)
      num_inputs = len(inputs)
      if num_preds != num_inputs:
          raise ValueError(
              f"Different number of model predictions ({num_preds}) than inputs"
              f" ({num_inputs})."
          )
  
      if not requested_types and not requested_fields:
          return preds
  
      # Figure out what to return to the frontend.
      output_spec = self._get_model_spec(model)["output"]
      requested_types = (
          requested_types.split(",") if requested_types else []
      )
      requested_fields = (
          requested_fields.split(",") if requested_fields else []
      )
      logging.info(
          "Requested types: %s, fields: %s",
          str(requested_types),
          str(requested_fields),
      )
      for t_name in requested_types:
          t_class = getattr(types, t_name, None)
          if not issubclass(t_class, types.LitType):
              raise TypeError(
                  f"Class '{t_name}' is not a valid LitType."
              )
          requested_fields.extend(
              utils.find_spec_keys(output_spec, t_class)
          )
      ret_keys = set(requested_fields)  # de-dupe
  
      # Return selected keys.
      logging.info("Will return keys: %s", str(ret_keys))
      # One record per input.
      ret = [
          utils.filter_by_keys(p, ret_keys.__contains__) for p in preds
      ]
      return ret
  
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 7 for calling the LitApp obj's underlying member method code with example usage: obj._get_preds(data, model, requested_types, requested_fields) and returns: ret, preds