code: def str_interpolate(
      template: str,
      matches: "List[Match]",
      context: "Context",
      skip_checks: bool = False,
      key=None,
      config=None,
  ):
      index, buf = 0, ""
      for match in matches:
          start, end = match.span(0)
          expr = get_expression(match, skip_checks=skip_checks)
          value = context.select(expr, unwrap=True)
          validate_value(value, key)
          buf += template[index:start] + to_str(value, config=config)
          index = end
      buf += template[index:]
      # regex already backtracks and avoids any `${` starting with
      # backslashes(`\`). We just need to replace those by `${`.
      return buf.replace(r"\${", BRACE_OPEN)
  
imports: import os
  import re
  import typing
  from collections.abc import Iterable, Mapping
  from functools import singledispatch
  from funcy import memoize, rpartial
  from dvc.exceptions import DvcException
  from dvc.utils.flatten import flatten
label_desc: Use image node_id 18 for calling a global function with example usage: str_interpolate(template, matches, context, skip_checks, key, config) and returns: buf