code: def model_server_app(
      model_path: Text, model_hash: Text = "somehash"
  ) -> Sanic:
      app = Sanic("test_agent")
      app.ctx.number_of_model_requests = 0
  
      @app.route("/model", methods=["GET"])
      async def model(request: Request) -> ResponseStream:
          """Simple HTTP model server responding with a trained model."""
  
          if model_hash == request.headers.get("If-None-Match"):
              return response.text("", 204)
  
          app.ctx.number_of_model_requests += 1
  
          return await response.file_stream(
              location=model_path,
              headers={
                  "ETag": model_hash,
                  "filename": Path(model_path).name,
              },
              mime_type="application/gzip",
          )
  
      return app
  
imports: import asyncio
  from http import HTTPStatus
  import json
  from pathlib import Path
  from typing import Any, Dict, Text, Callable, Optional
  from unittest.mock import patch
  import uuid
  from aioresponses import aioresponses
  import pytest
  from _pytest.monkeypatch import MonkeyPatch
  from pytest_sanic.utils import TestClient
  from sanic import Sanic, response
  from sanic.request import Request
  from sanic.response import ResponseStream
  import rasa.core
  from rasa.core.exceptions import AgentNotReady
  from rasa.core.utils import AvailableEndpoints
  from rasa.exceptions import ModelNotFound
  from rasa.nlu.persistor import Persistor
  from rasa.shared.core.events import ActionExecuted, BotUttered, DefinePrevUserUtteredFeaturization, SessionStarted, UserUttered
  from rasa.shared.nlu.constants import INTENT_NAME_KEY
  import rasa.shared.utils.common
  import rasa.utils.io
  from rasa.core import jobs
  from rasa.core.agent import Agent, load_agent
  from rasa.core.channels.channel import UserMessage
  from rasa.shared.core.domain import Domain
  from rasa.shared.constants import INTENT_MESSAGE_PREFIX
  from rasa.utils.endpoints import EndpointConfig
  from tests.conftest import with_assistant_ids, with_model_ids
label_desc: Use image node_id 1 for calling a global function with example usage: model_server_app(model_path, model_hash) and returns: app, unknown, response