code: def get_replacement_dict(
      rules: AnyStr
      | list[AnyStr | list[AnyStr] | tuple[AnyStr, AnyStr]]
  ) -> dict[AnyStr, AnyStr]:
      """Given a string with replacement rules, produces a dict of from: to"""
  
      if isinstance(rules, (bytes, str)):
          rules = [rules]
  
      pairs = dict()
      for rule in rules:
          if isinstance(rule, (list, tuple)):
              if len(rule) == 2:
                  pairs[rule[0]] = rule[1]
              else:
                  raise ValueError(
                      "Got a rule %s which is not a string or a pair of values (from, to)"
                      % repr(rule)
                  )
          elif len(rule) <= 2:
              raise ValueError("")
          else:
              rule_split = rule[1:].split(rule[0:1])
              if len(rule_split) != 2:
                  raise ValueError(
                      "Rename string must be of format '/pat1/replacement', "
                      "where / is an arbitrary character to decide replacement. "
                      "Got %r when trying to separate %r"
                      % (rule_split, rule)
                  )
              pairs[rule_split[0]] = rule_split[1]
      return pairs
  
imports: from __future__ import annotations
  import re
  from typing import AnyStr
label_desc: Use image node_id 1 for calling a global function with example usage: get_replacement_dict(rules) and returns: pairs