code: def expand_uuid_prefixes(
      args: Namespace, prefixes: Optional[Union[str, List[str]]] = None
  ) -> Union[str, List[str]]:
      if prefixes is None:
          prefixes = RemoteTaskGetIDsFunc[args._command](args)  # type: ignore
  
      was_single = False
      if isinstance(prefixes, str):
          was_single = True
          prefixes = [prefixes]
  
      # Avoid making a network request if everything is already a full UUID.
      if not all(TASK_ID_REGEX.match(p) for p in prefixes):
          if args._command not in RemoteTaskNewAPIs:
              raise api.errors.BadRequestException(
                  f"partial UUIDs not supported for 'det {args._command} {args._subcommand}'"
              )
          api_path = RemoteTaskNewAPIs[args._command]
          api_full_path = "api/v1/{}".format(api_path)
          res = api.get(args.master, api_full_path).json()[api_path]
          all_ids: List[str] = [x["id"] for x in res]
  
          def expand(prefix: str) -> str:
              if TASK_ID_REGEX.match(prefix):
                  return prefix
  
              # Could do better algorithmically than repeated linear scans, but let's not complicate
              # the code unless it becomes an issue in practice.
              ids = [x for x in all_ids if x.startswith(prefix)]
              if len(ids) > 1:
                  raise api.errors.BadRequestException(
                      f"partial UUID '{prefix}' not unique"
                  )
              elif len(ids) == 0:
                  raise api.errors.BadRequestException(
                      f"partial UUID '{prefix}' not found"
                  )
              return ids[0]
  
          prefixes = [expand(p) for p in prefixes]
  
      if was_single:
          prefixes = prefixes[0]
      return prefixes
  
imports: import base64
  import json
  import operator
  import re
  from argparse import Namespace
  from collections import OrderedDict
  from functools import reduce
  from pathlib import Path
  from typing import IO, Any, Dict, Iterable, List, Optional, Tuple, Union
  from termcolor import colored
  import determined.cli.render
  from determined import cli
  from determined.cli import render
  from determined.common import api, context, declarative_argparse, util
  from determined.common.api import authentication
  from determined.util import merge_dicts
label_desc: Use image node_id 1 for calling a global function with example usage: expand_uuid_prefixes(args, prefixes) and returns: prefixes, ids, prefix