code: def load_basemodels_if_needed(
      func: Callable[..., Any]
  ) -> Callable[..., Any]:
      """A decorator to load the parameters of a function if they are Pydantic models
  
      Args:
          func: The function with annotated parameters
  
      Returns:
          A function that loads the parameters before calling the original function
  
      """
      # get the type annotations of the parameters
      typed_signature = get_typed_signature(func)
      param_annotations = get_param_annotations(typed_signature)
  
      # get functions for loading BaseModels when needed based on the type annotations
      kwargs_mapping = {
          k: get_load_param_if_needed_function(t)
          for k, t in param_annotations.items()
      }
  
      # remove the None values
      kwargs_mapping = {
          k: f for k, f in kwargs_mapping.items() if f is not None
      }
  
      # a function that loads the parameters before calling the original function
      @functools.wraps(func)
      def _load_parameters_if_needed(*args: Any, **kwargs: Any) -> Any:
          # load the BaseModels if needed
          for k, f in kwargs_mapping.items():
              kwargs[k] = f(kwargs[k], param_annotations[k])
  
          # call the original function
          return func(*args, **kwargs)
  
      @functools.wraps(func)
      async def _a_load_parameters_if_needed(
          *args: Any, **kwargs: Any
      ) -> Any:
          # load the BaseModels if needed
          for k, f in kwargs_mapping.items():
              kwargs[k] = f(kwargs[k], param_annotations[k])
  
          # call the original function
          return await func(*args, **kwargs)
  
      if inspect.iscoroutinefunction(func):
          return _a_load_parameters_if_needed
      else:
          return _load_parameters_if_needed
  
imports: import functools
  import inspect
  import json
  from logging import getLogger
  from typing import Any, Callable, Dict, ForwardRef, List, Optional, Set, Tuple, Type, TypeVar, Union
  from pydantic import BaseModel, Field
  from typing_extensions import Annotated, Literal, get_args, get_origin
  from ._pydantic import JsonSchemaValue, evaluate_forwardref, model_dump, model_dump_json, type2schema
label_desc: Use image node_id 12 for calling a global function with example usage: load_basemodels_if_needed(func) and returns: func, unknown, _a_load_parameters_if_needed, _load_parameters_if_needed