code: def _add_model_to_pipeline(
      pipeline: ForecastingPipeline, model: BaseForecaster
  ) -> ForecastingPipeline:
      """Removes the dummy model from the preprocessing pipeline and adds the
      passed model to it instead.
  
      # TODO: Check if sktime can provide a convenience method for this functionality
  
      Parameters
      ----------
      pipeline : ForecastingPipeline
          A ForecastingPipeline to be used as the base to replace the final model.
      model : BaseForecaster
          sktime compatible model (without the pipeline). i.e. last step of
          the pipeline TransformedTargetForecaster
  
      Returns
      -------
      ForecastingPipeline
          The forecasting pipeline with the dummy model replaced with the correct one.
      """
      pipeline_with_model = deepcopy(pipeline)
  
      # Make sure to update `steps` and `steps_` for both the `ForecastingPipeline`
      # as well as the `TransformedTargetForecaster` else this causes issues when
      # the method is used in `predict_model` where it tries to predict using the
      # "dummy" Forecaster instead of the correct one.
  
      # Until sktime 0.17.0, we had to explicitly do this for all 4 combinations
      # of steps/steps_. Sometime after that, the functionality has changed and
      # updating `pipeline_with_model.steps[-1][1].steps` also updates
      # `pipeline_with_model.steps_[-1][1].steps` automatically. Hence, if we try
      # to do this again, it fails. Since we are supporting older and newer
      # versions of sktime, we need to check for this and act accordingly.
      # Here we check that `pipeline_with_model.steps_[-1][1].steps` has something
      # in it and that the last step is named "model" or not. This is needed since
      # here could be other steps in the pipeline that are not named "model" so
      # just checking length is not enough.
      pipeline_with_model.steps[-1][1].steps.pop()
      pipeline_with_model.steps[-1][1].steps_.pop()
      if (
          len(pipeline_with_model.steps_[-1][1].steps) > 0
          and pipeline_with_model.steps_[-1][1].steps[-1][0] == "model"
      ):
          pipeline_with_model.steps_[-1][1].steps.pop()
      pipeline_with_model.steps_[-1][1].steps_.pop()
  
      pipeline_with_model.steps[-1][1].steps.extend([("model", model)])
      pipeline_with_model.steps[-1][1].steps_.extend([("model", model)])
      if (len(pipeline_with_model.steps_[-1][1].steps) == 0) or (
          len(pipeline_with_model.steps_[-1][1].steps) > 0
          and pipeline_with_model.steps_[-1][1].steps[-1][0] != "model"
      ):
          pipeline_with_model.steps_[-1][1].steps.extend(
              [("model", model)]
          )
      pipeline_with_model.steps_[-1][1].steps_.extend(
          [("model", model)]
      )
  
      # Clone Tags so that the ability to get prediction intervals can be set correctly
      # based on the replacement model and not based on the pipeline model
      # https://github.com/sktime/sktime/blob/v0.14.0/sktime/forecasting/compose/_pipeline.py#L313-L318
      tags_to_clone = [
          "ignores-exogeneous-X",  # does estimator ignore the exogeneous X?
          "capability:pred_int",  # can the estimator produce prediction intervals?
          "requires-fh-in-fit",  # is forecasting horizon already required in fit?
          "enforce_index_type",  # index type that needs to be enforced in X/y
      ]
  
      # Clone tags for TransformedTargetForecaster
      pipeline_with_model.steps[-1][1].clone_tags(model, tags_to_clone)
      pipeline_with_model.steps_[-1][1].clone_tags(model, tags_to_clone)
      # Clone tags for ForecastingPipeline
      pipeline_with_model.clone_tags(model, tags_to_clone)
  
      return pipeline_with_model
  
file_path: pycaret/pycaret/utils/time_series/forecasting/pipeline.py
imports: from copy import deepcopy
  from typing import Optional, Tuple
  import pandas
  from sktime.forecasting.base import BaseForecaster
  from sktime.forecasting.compose import ForecastingPipeline
  from sktime.transformations.compose import TransformerPipeline
  from sktime.transformations.series.impute import Imputer
label_desc: Use image node_id 1 for calling a global function with example usage: _add_model_to_pipeline(pipeline, model) and returns: pipeline_with_model