-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathextension.py
More file actions
38 lines (28 loc) · 1.13 KB
/
extension.py
File metadata and controls
38 lines (28 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import logging
from localstack import config
from localstack.extensions.api import Extension, http
from rolo.router import RuleAdapter, WithHost
from werkzeug.routing import Submount
LOG = logging.getLogger(__name__)
class LocalstackOpenAIExtension(Extension):
name = "openai"
submount = "/_extension/openai"
subdomain = "openai"
def on_extension_load(self):
logging.getLogger("localstack_openai").setLevel(
logging.DEBUG if config.DEBUG else logging.INFO
)
def update_gateway_routes(self, router: http.Router[http.RouteHandler]):
from localstack_openai.mock_openai import Api
api = RuleAdapter(Api())
# add path routes for localhost:4566/v1/chat/completion
router.add(
[
Submount(self.submount, [api]),
WithHost(f"{self.subdomain}.{config.LOCALSTACK_HOST.host}<__host__>", [api]),
]
)
LOG.info(
"OpenAI mock available at %s%s", str(config.LOCALSTACK_HOST).rstrip("/"), self.submount
)
LOG.info("OpenAI mock available at %s", f"{self.subdomain}.{config.LOCALSTACK_HOST}")