File size: 1,398 Bytes
125f9c0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Single source of truth for Modal endpoint URLs.

Modal's deployed web URLs are deterministic: they're built from the WORKSPACE
slug + the app/function name. So instead of hardcoding three full URLs (which
break the moment you switch workspaces — e.g. moving to the credit workspace),
we derive them all from one value: MODAL_WORKSPACE.

Switching workspaces is then a one-line change (MODAL_WORKSPACE=... in .env),
not a code edit across registry.py / vision.py / guardian.py.

Explicit MODAL_*_URL env vars still win if set, so nothing here removes the
escape hatch for a non-standard URL.
"""
from __future__ import annotations

# app name -> the web-endpoint label Modal appends after "<workspace>--".
# vLLM/llama.cpp expose @modal.web_server functions named `serve`; FLUX exposes
# a class endpoint (class Flux, method generate) -> "<app>-flux-generate".
_SUFFIX = {
    "vllm":     "small-hack-vllm-serve",
    "llamacpp": "small-hack-llamacpp-serve",
    "flux":     "small-hack-flux-flux-generate",
}


def derive(workspace: str) -> dict[str, str]:
    """Map a workspace slug -> {vllm, llamacpp, flux} base URLs."""
    ws = (workspace or "").strip()
    base = {k: f"https://{ws}--{suf}.modal.run" for k, suf in _SUFFIX.items()}
    # The OpenAI-compatible servers live under /v1; FLUX is a bare POST endpoint.
    base["vllm"] += "/v1"
    base["llamacpp"] += "/v1"
    return base