code: def generate_gbnf_grammar(
      model: Type[BaseModel], processed_models: set, created_rules: dict
  ) -> (list, bool, bool):
      """
  
      Generate GBnF Grammar
  
      Generates a GBnF grammar for a given model.
  
      :param model: A Pydantic model class to generate the grammar for. Must be a subclass of BaseModel.
      :param processed_models: A set of already processed models to prevent infinite recursion.
      :param created_rules: A dict containing already created rules to prevent duplicates.
      :return: A list of GBnF grammar rules in string format. And two booleans indicating if an extra markdown or triple quoted string is in the grammar.
      Example Usage:
      ```
      model = MyModel
      processed_models = set()
      created_rules = dict()
  
      gbnf_grammar = generate_gbnf_grammar(model, processed_models, created_rules)
      ```
      """
      if model in processed_models:
          return []
  
      processed_models.add(model)
      model_name = format_model_and_field_name(model.__name__)
  
      if not issubclass(model, BaseModel):
          # For non-Pydantic classes, generate model_fields from __annotations__ or __init__
          if (
              hasattr(model, "__annotations__")
              and model.__annotations__
          ):
              model_fields = {
                  name: (typ, ...)
                  for name, typ in model.__annotations__.items()
              }
          else:
              init_signature = inspect.signature(model.__init__)
              parameters = init_signature.parameters
              model_fields = {
                  name: (param.annotation, param.default)
                  for name, param in parameters.items()
                  if name != "self"
              }
      else:
          # For Pydantic models, use model_fields and check for ellipsis (required fields)
          model_fields = model.__annotations__
  
      model_rule_parts = []
      nested_rules = []
      has_markdown_code_block = False
      has_triple_quoted_string = False
      look_for_markdown_code_block = False
      look_for_triple_quoted_string = False
      for field_name, field_info in model_fields.items():
          if not issubclass(model, BaseModel):
              field_type, default_value = field_info
              # Check if the field is optional (not required)
              is_optional = (
                  default_value is not inspect.Parameter.empty
              ) and (default_value is not Ellipsis)
          else:
              field_type = field_info
              field_info = model.model_fields[field_name]
              is_optional = (
                  field_info.is_required is False
                  and get_origin(field_type) is Optional
              )
          rule_name, additional_rules = generate_gbnf_rule_for_type(
              model_name,
              format_model_and_field_name(field_name),
              field_type,
              is_optional,
              processed_models,
              created_rules,
              field_info,
          )
          look_for_markdown_code_block = (
              True if rule_name == "markdown_code_block" else False
          )
          look_for_triple_quoted_string = (
              True if rule_name == "triple_quoted_string" else False
          )
          if (
              not look_for_markdown_code_block
              and not look_for_triple_quoted_string
          ):
              if rule_name not in created_rules:
                  created_rules[rule_name] = additional_rules
              model_rule_parts.append(
                  f' ws "\\"{field_name}\\"" ":" ws {rule_name}'
              )  # Adding escaped quotes
              nested_rules.extend(additional_rules)
          else:
              has_triple_quoted_string = look_for_triple_quoted_string
              has_markdown_code_block = look_for_markdown_code_block
  
      fields_joined = r' "," "\n" '.join(model_rule_parts)
      model_rule = (
          rf'{model_name} ::= "{{" "\n" {fields_joined} "\n" ws "}}"'
      )
  
      has_special_string = False
      if has_triple_quoted_string:
          model_rule += '"\\n" ws "}"'
          model_rule += '"\\n" triple-quoted-string'
          has_special_string = True
      if has_markdown_code_block:
          model_rule += '"\\n" ws "}"'
          model_rule += '"\\n" markdown-code-block'
          has_special_string = True
      all_rules = [model_rule] + nested_rules
  
      return all_rules, has_special_string
  
imports: import inspect
  import json
  from copy import copy
  from inspect import isclass, getdoc
  from types import NoneType
  from docstring_parser import parse
  from pydantic import BaseModel, create_model, Field
  from typing import Any, Type, List, get_args, get_origin, Tuple, Union, Optional, _GenericAlias
  from enum import Enum
  from typing import get_type_hints, Callable
  import re
  from enum import Enum
label_desc: Use image node_id 9 for calling a global function with example usage: generate_gbnf_grammar(model, processed_models, created_rules) and returns: all_rules,  has_special_string, list