code: def predictions(
      model: Model,
      idata: az.InferenceData,
      conditional: Union[str, dict, list, None] = None,
      average_by: Union[str, list, bool, None] = None,
      target: str = "mean",
      pps: bool = False,
      use_hdi: bool = True,
      prob=None,
      transforms=None,
      sample_new_groups=False,
  ) -> pd.DataFrame:
      """Compute Conditional Adjusted Predictions
  
      Parameters
      ----------
      model : bambi.Model
          The model for which we want to plot the predictions.
      idata : arviz.InferenceData
          The InferenceData object that contains the samples from the posterior distribution of
          the model.
      conditional : str, list, dict, optional
          The covariates we would like to condition on. If dict, keys are the covariate names and
          values are the values to condition on.
      average_by: str, list, bool, optional
          The covariates we would like to average by. The passed covariate(s) will marginalize
          over the other covariates in the model. If True, it averages over all covariates
          in the model to obtain the average estimate. Defaults to `None`.
      target : str
          Which model parameter to plot. Defaults to 'mean'. Passing a parameter into target only
          works when pps is False as the target may not be available in the posterior predictive
          distribution.
      pps: bool, optional
          Whether to plot the posterior predictive samples. Defaults to `False`.
      use_hdi : bool, optional
          Whether to compute the highest density interval (defaults to True) or the quantiles.
      prob : float, optional
          The probability for the credibility intervals. Must be between 0 and 1. Defaults to 0.94.
          Changing the global variable `az.rcParam["stats.hdi_prob"]` affects this default.
      transforms : dict, optional
          Transformations that are applied to each of the variables being plotted. The keys are the
          name of the variables, and the values are functions to be applied. Defaults to `None`.
      sample_new_groups : bool, optional
          If the model contains group-level effects, and data is passed for unseen groups, whether
          to sample from the new groups. Defaults to `False`.
  
      Returns
      -------
      cap_data : pandas.DataFrame
          A DataFrame with the `create_cap_data` and model predictions.
  
      Raises
      ------
      ValueError
          If `pps` is `True` and `target` is not `"mean"`.
          If `conditional` is a list and the length is greater than 3.
          If `prob` is not > 0 and < 1.
      """
      if pps and target != "mean":
          raise ValueError(
              "When passing 'pps=True', target must be 'mean'"
          )
  
      if isinstance(conditional, list):
          if len(conditional) > 3:
              raise ValueError(
                  f"Only 3 covariates can be passed to 'conditional'. {len(conditional)} "
                  "were passed. If you would like to pass more than 3 covariates, use "
                  "a dictionary."
              )
  
      conditional_info = ConditionalInfo(model, conditional)
      transforms = transforms if transforms is not None else {}
  
      if prob is None:
          prob = az.rcParams["stats.hdi_prob"]
      if not 0 < prob < 1:
          raise ValueError(
              f"'prob' must be greater than 0 and smaller than 1. It is {prob}."
          )
  
      cap_data = create_predictions_data(conditional_info)
  
      if target != "mean":
          component = model.components[target]
          if component.alias:
              # use only the aliased name (without appended target)
              response_name = get_aliased_name(component)
              target = None
          else:
              # use the default response "y" and append target
              response_name = get_aliased_name(
                  model.response_component.response_term
              )
      else:
          response_name = get_aliased_name(
              model.response_component.response_term
          )
  
      response = ResponseInfo(response_name, target)
      response_transform = transforms.get(response_name, identity)
  
      if pps:
          idata = model.predict(
              idata,
              data=cap_data,
              sample_new_groups=sample_new_groups,
              inplace=False,
              kind="pps",
          )
          y_hat = response_transform(
              idata["posterior_predictive"][response.name]
          )
          y_hat_mean = y_hat.mean(("chain", "draw"))
      else:
          idata = model.predict(
              idata,
              data=cap_data,
              sample_new_groups=sample_new_groups,
              inplace=False,
          )
          y_hat = response_transform(
              idata["posterior"][response.name_target]
          )
          y_hat_mean = y_hat.mean(("chain", "draw"))
  
      if use_hdi and pps:
          y_hat_bounds = az.hdi(y_hat, prob)[response.name].T
      elif use_hdi:
          y_hat_bounds = az.hdi(y_hat, prob)[response.name_target].T
      else:
          lower_bound = round((1 - prob) / 2, 4)
          upper_bound = 1 - lower_bound
          y_hat_bounds = y_hat.quantile(
              q=(lower_bound, upper_bound), dim=("chain", "draw")
          )
  
      lower_bound = round((1 - prob) / 2, 4)
      upper_bound = 1 - lower_bound
      response.lower_bound, response.upper_bound = (
          lower_bound,
          upper_bound,
      )
  
      cap_data = cap_data.copy()
      if y_hat_mean.ndim > 1:
          cap_data = merge(y_hat_mean, y_hat_bounds, cap_data)
          cap_data = cap_data.rename(
              columns={
                  f"{response.name}_dim": "estimate_dim",
                  f"{response.name_target}": "estimate",
                  f"{response.name_target}_x": response.lower_bound_name,
                  f"{response.name_target}_y": response.upper_bound_name,
              }
          )
      else:
          cap_data["estimate"] = y_hat_mean
          cap_data[response.lower_bound_name] = y_hat_bounds[0]
          cap_data[response.upper_bound_name] = y_hat_bounds[1]
  
      if average_by is not None:
          if average_by is True:
              average_by = "all"
          cap_data = average_over(cap_data, covariate=average_by)
  
      return cap_data
  
imports: from dataclasses import dataclass, field
  import itertools
  from typing import Dict, Union
  import arviz
  import numpy
  import pandas
  from pandas.api.types import is_categorical_dtype, is_string_dtype
  import xarray
  from bambi.models import Model
  from bambi.interpret.create_data import create_differences_data, create_predictions_data
  from bambi.interpret.utils import average_over, ConditionalInfo, enforce_dtypes, identity, merge, VariableInfo
  from bambi.utils import get_aliased_name
label_desc: Use image node_id 1 for calling a global function with example usage: predictions(model, idata, conditional, average_by, target, pps, use_hdi, prob, transforms, sample_new_groups) and returns: cap_data