Spaces:
Build error
Build error
# tracklight_server/api/ingest.py | |
from fastapi import APIRouter, Depends, HTTPException | |
from typing import List | |
from pydantic import BaseModel | |
from ..db import duckdb | |
from .auth import verify_token | |
router = APIRouter() | |
class Metric(BaseModel): | |
run_id: str | |
project: str | |
user: str | |
metric_name: str | |
value: float | |
timestamp: str | |
class Config(BaseModel): | |
run_id: str | |
config_name: str | |
value: str | |
def log_metrics(metrics: List[Metric], token: str = Depends(verify_token)): | |
""" | |
Receives a list of metrics and logs them to the database. | |
""" | |
try: | |
duckdb.insert_metrics([metric.dict() for metric in metrics]) | |
return {"message": "Metrics logged successfully."} | |
except Exception as e: | |
raise HTTPException(status_code=500, detail=str(e)) | |
def log_config(configs: List[Config], token: str = Depends(verify_token)): | |
""" | |
Receives a list of config values and logs them to the database. | |
""" | |
try: | |
duckdb.insert_config([config.dict() for config in configs]) | |
return {"message": "Configs logged successfully."} | |
except Exception as e: | |
raise HTTPException(status_code=500, detail=str(e)) | |