code: def last_boxed_only_string(string: str) -> Optional[str]:
      """Source: https://github.com/hendrycks/math
      Extract the last \\boxed{...} or \\fbox{...} element from a string.
      """
      idx = string.rfind("\\boxed")
      if idx < 0:
          idx = string.rfind("\\fbox")
          if idx < 0:
              return None
  
      i = idx
      right_brace_idx = None
      num_left_braces_open = 0
      while i < len(string):
          if string[i] == "{":
              num_left_braces_open += 1
          if string[i] == "}":
              num_left_braces_open -= 1
              if num_left_braces_open == 0:
                  right_brace_idx = i
                  break
          i += 1
  
      if right_brace_idx is None:
          retval = None
      else:
          retval = string[idx : right_brace_idx + 1]
  
      return retval
  
file_path: autogen/autogen/math_utils.py
imports: from typing import Optional
  from autogen import oai, DEFAULT_MODEL
label_desc: Use image node_id 3 for calling a global function with example usage: last_boxed_only_string(string) and returns: retval, None