Spaces:
Paused
Paused
File size: 1,722 Bytes
fb5b6b9 cf590c1 fb5b6b9 cf590c1 fb5b6b9 cf590c1 fb5b6b9 cf590c1 fb5b6b9 cf590c1 fb5b6b9 cf590c1 |
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 |
from fastapi import APIRouter, Request, HTTPException
from service_config import ServiceConfig
router = APIRouter()
service_config = ServiceConfig()
service_config.load()
@router.post("/add")
async def add_project(request: Request):
data = await request.json()
project_name = data.get("project_name")
if not project_name:
raise HTTPException(status_code=400, detail="project_name cannot be empty")
if project_name in service_config.projects:
raise HTTPException(status_code=400, detail="Project already exists")
service_config.projects[project_name] = {
"enabled": False,
"versions": []
}
with open(service_config.config_path, "w", encoding="utf-8") as f:
import json
json.dump(service_config, f, indent=2)
return {"message": f"Project {project_name} added"}
@router.post("/publish")
async def publish_project(request: Request):
data = await request.json()
project_name = data.get("project_name")
project = service_config.projects.get(project_name)
if not project:
raise HTTPException(status_code=404, detail="Project not found")
latest_version = project["versions"][-1] if project["versions"] else None
if not latest_version:
raise HTTPException(status_code=400, detail="No version exists to publish")
llm = latest_version.get("llm", {})
if not llm.get("repo_id"):
raise HTTPException(status_code=400, detail="repo_id is required")
if llm.get("use_fine_tune") and not llm.get("fine_tune_zip"):
raise HTTPException(status_code=400, detail="fine_tune_zip is required when use_fine_tune is true")
return {"message": f"Project {project_name} passed publish checks"}
|