code: def openai_auto_retry_patch():
      """
      Context manager that patches the openai python package to automatically retry on transient
      errors.
      """
      import openai
  
      classes_to_patch = {
          "Audio": [
              "transcribe",
              "atranscribe",
              "translate",
              "atranslate",
          ],
          "Completion": [
              "create",
              "acreate",
          ],
          "ChatCompletion": [
              "create",
              "acreate",
          ],
          "Embedding": [
              "create",
              "acreate",
          ],
          "Edit": [
              "create",
              "acreate",
          ],
          "Image": [
              "create",
              "acreate",
              "create_variation",
              "acreate_variation",
              "create_edit",
              "acreate_edit",
          ],
          "Moderation": [
              "create",
              "acreate",
          ],
      }
      original_methods = {}
      try:
          retry_decorator = _create_retry_decorator()
          for class_name, method_names in classes_to_patch.items():
              for method_name in method_names:
                  class_obj = getattr(openai, class_name)
                  original_method = getattr(class_obj, method_name)
                  patched_method = retry_decorator(original_method)
                  original_methods[
                      (class_name, method_name)
                  ] = original_method
                  setattr(class_obj, method_name, patched_method)
          yield
      finally:
          # Restore the original methods
          for (
              class_name,
              method_name,
          ), original_method in original_methods.items():
              class_obj = getattr(openai, class_name)
              setattr(class_obj, method_name, original_method)
  
imports: import logging
  from contextlib import contextmanager
label_desc: Use image node_id 2 for calling a global function with example usage: openai_auto_retry_patch() without return types