Skip to content

Commit 62cda27

Browse files
committed
gw: Add helper for constructing a CMS URL
Add helper to construct a CMS URL given a model name and an optional endpoint. This function uses the server URL configuration option as base URL, but defaults to the treating the model name as a Docker service name if the configuration option is not set, allowing for local testing without a proxy. Signed-off-by: Phoevos Kalemkeris <[email protected]>
1 parent 070f71f commit 62cda27

File tree

1 file changed

+11
-0
lines changed
  • cogstack_model_gateway/gateway/routers

1 file changed

+11
-0
lines changed

cogstack_model_gateway/gateway/routers/utils.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from fastapi import Header, HTTPException, Path, Request
55

6+
from cogstack_model_gateway.common.config import get_config
67
from cogstack_model_gateway.common.utils import parse_content_type_header
78

89
MODEL_NAME_REGEX = r"^[a-zA-Z0-9][a-zA-Z0-9_.-]+$"
@@ -42,3 +43,13 @@ def validate_model_name(
4243
detail=f"Invalid model name. {VALID_MODEL_DESCRIPTION}",
4344
)
4445
return model_name
46+
47+
48+
def get_cms_url(model_name: str, endpoint: str = None) -> str:
49+
"""Get the URL of a CogStack Model Serve instance endpoint."""
50+
config = get_config()
51+
host_url = config.cms.host_url.rstrip("/") if config.cms.host_url else ""
52+
server_port = config.cms.server_port
53+
base_url = f"{host_url}/{model_name}" if host_url else f"http://{model_name}:{server_port}"
54+
endpoint = endpoint.lstrip("/") if endpoint else ""
55+
return f"{base_url}/{endpoint}" if endpoint else base_url

0 commit comments

Comments
 (0)