class_docstr: Integration with the Nixtla TimeGPT models for
  zero-shot time series forecasting.
class_docstr_tok: ["Integration","with","the","Nixtla","TimeGPT","models","for","zero-shot","time","series","forecasting","."]
docstr: Makes forecasts with the TimeGPT API. 
docstr_tok: ["Makes","forecasts","with","the","TimeGPT","API","."]
code: def predict(self, df, args={}):
      """Makes forecasts with the TimeGPT API."""
      model_args = self.model_storage.json_get("model_args")
      args = args["predict_params"]
      prediction_df = self._transform_to_nixtla_df(df, model_args)
      timegpt = TimeGPT(token=model_args["token"])
  
      forecast_df = timegpt.forecast(
          prediction_df,
          # TODO: supporting param override when JOINing with a WHERE clause is blocked by mindsdb_sql#285
          h=args.get("horizon", model_args.get("horizon", 1)),
          freq=args.get(
              "freq", model_args["freq"]
          ),  # automatically infers correct frequency if not provided by user
          level=model_args["level"],
          finetune_steps=args.get(
              "finetune_steps", model_args["finetune_steps"]
          ),
          validate_token=args.get(
              "validate_token", model_args["validate_token"]
          ),
          date_features=args.get(
              "date_features", model_args["date_features"]
          ),
          date_features_to_one_hot=args.get(
              "date_features_to_one_hot",
              model_args["date_features_to_one_hot"],
          ),
          clean_ex_first=args.get(
              "clean_ex_first", model_args["clean_ex_first"]
          ),
          # anomaly detection
          add_history=args.get(
              "add_history", model_args["add_history"]
          )  # insample bounds and anomaly detection
          # TODO: enable this post-refactor (#6861)
          # X_df=None,  # exogenous variables
      )
  
      if model_args["mode"] == "forecasting":
          results_df = forecast_df[["unique_id", "ds", "TimeGPT"]]
          results_df = get_results_from_nixtla_df(
              results_df, model_args
          )
      elif model_args["mode"] == "anomalydetection":
          forecast_df["ds"] = pd.to_datetime(forecast_df["ds"])
          results_df = forecast_df.merge(
              prediction_df, how="inner"
          )  # some rows drop because of TimeGPT's cold start
          results_df["anomaly"] = (
              results_df["y"]
              > results_df[f'TimeGPT-hi-{model_args["level"][0]}']
          ) | (
              results_df["y"]
              < results_df[f'TimeGPT-lo-{model_args["level"][0]}']
          )
  
          forecast_df = results_df  # rewrite forecast_df so that we can reuse code below for prediction intervals
          results_df = get_results_from_nixtla_df(
              results_df, model_args
          )
          results_df = results_df.rename(
              {"y": f'observed_{model_args["target"]}'}, axis=1
          )
      else:
          raise Exception(
              f'Unsupported prediction mode: {model_args["mode"]}'
          )
  
      # infer date
      ds_col = model_args["order_by"]
      if not pd.api.types.is_datetime64_any_dtype(results_df[ds_col]):
          results_df[ds_col] = pd.to_datetime(results_df[ds_col])
  
      results_df = results_df.rename(
          {"TimeGPT": model_args["target"]}, axis=1
      )
  
      # add prediction intervals
      levels = sorted(model_args["level"], reverse=True)
      for i, level in enumerate(levels):
          if i == 0:
              # NOTE: this should be simplified once we refactor the expected time series output within MindsDB
              results_df["confidence"] = (
                  level / 100
              )  # we report the highest level as the overall confidence
              results_df["lower"] = forecast_df[f"TimeGPT-lo-{level}"]
              results_df["upper"] = forecast_df[f"TimeGPT-hi-{level}"]
          else:
              results_df[f"lower_{level}"] = forecast_df[
                  f"TimeGPT-lo-{level}"
              ]
              results_df[f"upper_{level}"] = forecast_df[
                  f"TimeGPT-hi-{level}"
              ]
  
      return results_df
  
file_path: mindsdb/mindsdb/integrations/handlers/timegpt_handler/timegpt_handler.py
imports: from typing import Optional, Dict
  import pandas
  from nixtlats import TimeGPT
  from mindsdb.integrations.libs.base import BaseMLEngine
  from mindsdb.integrations.utilities.handler_utils import get_api_key
  from mindsdb.integrations.utilities.time_series_utils import get_results_from_nixtla_df
label_desc: Use image node_id 2 for calling the TimeGPTHandler obj's underlying member method code with example usage: obj.predict(df, args) and returns: results_df