code: def nlg_app(base_url="/"):
      app = Sanic("test_nlg")
  
      @app.route(base_url, methods=["POST"])
      async def generate(request):
          """Simple HTTP NLG generator, checks that the incoming request
          is format according to the spec."""
  
          nlg_request_format_spec = {
              "type": "object",
              "properties": {
                  "response": {"type": "string"},
                  "id": {"type": ["string", "null"]},
                  "arguments": {"type": "object"},
                  "tracker": {
                      "type": "object",
                      "properties": {
                          "sender_id": {"type": "string"},
                          "slots": {"type": "object"},
                          "latest_message": {"type": "object"},
                          "latest_event_time": {"type": "number"},
                          "paused": {"type": "boolean"},
                          "events": {"type": "array"},
                      },
                  },
                  "channel": {
                      "type": "object",
                      "properties": {"name": {"type": "string"}},
                  },
              },
          }
  
          nlg_call = request.json
  
          jsonschema.validate(nlg_call, nlg_request_format_spec)
  
          if nlg_call.get("response") == "utter_greet":
              response_dict = {"text": "Hey there!"}
          else:
              response_dict = {"text": "Sorry, didn't get that."}
          return response.json(response_dict)
  
      return app
  
imports: import uuid
  from typing import Text, Any
  import jsonschema
  import pytest
  from sanic import Sanic, response
  from rasa.core.nlg.callback import CallbackNaturalLanguageGenerator
  from rasa.core.nlg.response import TemplatedNaturalLanguageGenerator
  from rasa.utils.endpoints import EndpointConfig, read_endpoint_config
  from rasa.core.agent import Agent
label_desc: Use image node_id 1 for calling a global function with example usage: nlg_app(base_url) and returns: app, response