code: def serialize_to_str(x: Any) -> str:
      if isinstance(x, str):
          return x
      elif isinstance(x, BaseModel):
          return model_dump_json(x)
      else:
          return json.dumps(x)
  
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 13 for calling a global function with example usage: serialize_to_str(x) and returns: x, model_dump_json, json