-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodels.py
More file actions
46 lines (37 loc) · 1.51 KB
/
models.py
File metadata and controls
46 lines (37 loc) · 1.51 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
39
40
41
42
43
44
45
46
from fastapi import APIRouter
from backend.services.model_service import get_all_models
from backend.services.cscs_l1_service import get_l1_synthetic_entries
from backend.config import get_settings
router = APIRouter()
settings = get_settings()
def _dnt_endpoint() -> str:
"""When OTELA_FIXTURE_PATH is set, read DNT from disk instead of HTTP —
used for iterating on the UI against synthesised post-upgrade payloads."""
if settings.otela_fixture_path:
return settings.otela_fixture_path
return settings.otela_head_addr + "/v1/dnt/table"
async def _with_l1(models: list[dict], with_details: bool) -> list[dict]:
"""Append synthetic L1 entries, skipping ids already present in the
OpenTela result so we don't double-list a model that's still launched
locally during a migration."""
existing = {m["id"] for m in models if m.get("id")}
for entry in await get_l1_synthetic_entries(with_details=with_details):
if entry["id"] not in existing:
models.append(entry)
return models
@router.get("/v1/models_detailed")
async def list_models_detailed():
models = get_all_models(_dnt_endpoint(), with_details=True)
models = await _with_l1(models, with_details=True)
return dict(
object="list",
data=models,
)
@router.get("/v1/models")
async def list_models():
models = get_all_models(_dnt_endpoint(), with_details=False)
models = await _with_l1(models, with_details=False)
return dict(
object="list",
data=models,
)