code: def run_rai_insights(
      model,
      train_data,
      test_data,
      target_column,
      categorical_features,
      manager_type,
      manager_args=None,
      classes=None,
      feature_metadata=None,
  ):
      if manager_args is None:
          manager_args = {}
  
      if classes is not None:
          task_type = ModelTask.CLASSIFICATION
      else:
          task_type = ModelTask.REGRESSION
  
      if manager_type == ManagerNames.COUNTERFACTUAL:
          feature_importance = manager_args.get(
              ManagerParams.FEATURE_IMPORTANCE
          )
          if feature_importance:
              test_data = test_data[0:20]
          else:
              test_data = test_data[0:1]
  
      if model is None:
          with pytest.warns(
              UserWarning,
              match="INVALID-MODEL-WARNING: "
              "No valid model is supplied. "
              "The explanations, error analysis and "
              "counterfactuals may not work",
          ):
              rai_insights = RAIInsights(
                  model,
                  train_data,
                  test_data,
                  target_column,
                  categorical_features=categorical_features,
                  task_type=task_type,
                  feature_metadata=feature_metadata,
              )
      else:
          rai_insights = RAIInsights(
              model,
              train_data,
              test_data,
              target_column,
              categorical_features=categorical_features,
              task_type=task_type,
              feature_metadata=feature_metadata,
          )
  
      if manager_type == ManagerNames.EXPLAINER:
          setup_explainer(rai_insights)
      elif manager_type == ManagerNames.ERROR_ANALYSIS:
          setup_error_analysis(rai_insights)
  
      validate_rai_insights(
          rai_insights,
          train_data,
          test_data,
          target_column,
          task_type,
          categorical_features,
          feature_metadata,
      )
  
      if manager_type == ManagerNames.CAUSAL:
          treatment_features = manager_args.get(
              ManagerParams.TREATMENT_FEATURES
          )
          max_cat_expansion = manager_args.get(
              ManagerParams.MAX_CAT_EXPANSION
          )
          validate_causal(
              rai_insights,
              train_data,
              target_column,
              treatment_features,
              max_cat_expansion,
          )
      elif manager_type == ManagerNames.COUNTERFACTUAL:
          desired_class = manager_args.get(ManagerParams.DESIRED_CLASS)
          desired_range = manager_args.get(ManagerParams.DESIRED_RANGE)
          feature_importance = manager_args.get(
              ManagerParams.FEATURE_IMPORTANCE
          )
          validate_counterfactual(
              rai_insights,
              desired_class=desired_class,
              desired_range=desired_range,
              feature_importance=feature_importance,
          )
      elif manager_type == ManagerNames.ERROR_ANALYSIS:
          validate_error_analysis(rai_insights)
      elif manager_type == ManagerNames.EXPLAINER:
          validate_explainer(
              rai_insights, train_data, test_data, classes
          )
  
      with TemporaryDirectory() as tmpdir:
          path = Path(tmpdir) / "rai_test_path"
          # save the rai_insights
          rai_insights.save(path)
  
          # Validate the common set of state produced when rai insights
          # are saved on the disk.
          validate_common_state_directories(path, task_type)
  
          # Validate the directory structure of the state saved
          # by the managers.
          validate_component_state_directory(path, manager_type)
  
          # load the rai_insights
          rai_insights = RAIInsights.load(path)
  
          validate_rai_insights(
              rai_insights,
              train_data,
              test_data,
              target_column,
              task_type,
              categorical_features,
              feature_metadata,
          )
  
          if manager_type == ManagerNames.ERROR_ANALYSIS:
              validate_error_analysis(rai_insights)
              # validate adding new reports after deserialization works
              setup_error_analysis(rai_insights, max_depth=4)
              validate_error_analysis(rai_insights, expected_reports=2)
          elif manager_type == ManagerNames.EXPLAINER:
              validate_explainer(
                  rai_insights, train_data, test_data, classes
              )
              # validate adding new explainer config after deserialization works
              setup_explainer(rai_insights)
              validate_explainer(
                  rai_insights, train_data, test_data, classes
              )
  
imports: import os
  import pickle
  from pathlib import Path
  from tempfile import TemporaryDirectory
  import numpy
  import pandas
  import pytest
  from tests.causal_manager_validator import validate_causal
  from tests.common_utils import create_iris_data
  from tests.counterfactual_manager_validator import validate_counterfactual
  from tests.error_analysis_validator import setup_error_analysis, validate_error_analysis
  from tests.explainer_manager_validator import setup_explainer, validate_explainer
  from rai_test_utils.datasets.tabular import create_binary_classification_dataset, create_cancer_data, create_housing_data
  from rai_test_utils.models.model_utils import create_models_classification, create_models_regression
  from rai_test_utils.models.sklearn import create_complex_classification_pipeline
  from rai_test_utils.utilities import is_valid_uuid
  from raiutils.models import ModelTask
  from responsibleai import RAIInsights
  from responsibleai._internal.constants import ManagerNames, SerializationAttributes
  from responsibleai._tools.shared.state_directory_management import DirectoryManager
  from responsibleai.feature_metadata import FeatureMetadata
label_desc: Use image node_id 1 for calling a global function with example usage: run_rai_insights(model, train_data, test_data, target_column, categorical_features, manager_type, manager_args, classes, feature_metadata) without return types