Spaces:
Running
Running
Update project_controller.py
Browse files- project_controller.py +17 -34
project_controller.py
CHANGED
@@ -5,16 +5,15 @@ router = APIRouter()
|
|
5 |
service_config = ServiceConfig()
|
6 |
service_config.load()
|
7 |
|
8 |
-
@router.get("/list")
|
9 |
-
def list_projects():
|
10 |
-
return service_config.projects
|
11 |
-
|
12 |
@router.post("/add")
|
13 |
async def add_project(request: Request):
|
14 |
data = await request.json()
|
15 |
project_name = data.get("project_name")
|
|
|
|
|
16 |
if project_name in service_config.projects:
|
17 |
raise HTTPException(status_code=400, detail="Project already exists")
|
|
|
18 |
service_config.projects[project_name] = {
|
19 |
"enabled": False,
|
20 |
"versions": []
|
@@ -24,38 +23,22 @@ async def add_project(request: Request):
|
|
24 |
json.dump(service_config, f, indent=2)
|
25 |
return {"message": f"Project {project_name} added"}
|
26 |
|
27 |
-
@router.post("/
|
28 |
-
async def
|
29 |
data = await request.json()
|
30 |
project_name = data.get("project_name")
|
31 |
-
|
|
|
32 |
raise HTTPException(status_code=404, detail="Project not found")
|
33 |
-
service_config.projects[project_name]["enabled"] = True
|
34 |
-
with open(service_config.config_path, "w", encoding="utf-8") as f:
|
35 |
-
import json
|
36 |
-
json.dump(service_config, f, indent=2)
|
37 |
-
return {"message": f"Project {project_name} enabled"}
|
38 |
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
project_name = data.get("project_name")
|
43 |
-
if project_name not in service_config.projects:
|
44 |
-
raise HTTPException(status_code=404, detail="Project not found")
|
45 |
-
service_config.projects[project_name]["enabled"] = False
|
46 |
-
with open(service_config.config_path, "w", encoding="utf-8") as f:
|
47 |
-
import json
|
48 |
-
json.dump(service_config, f, indent=2)
|
49 |
-
return {"message": f"Project {project_name} disabled"}
|
50 |
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
with open(service_config.config_path, "w", encoding="utf-8") as f:
|
59 |
-
import json
|
60 |
-
json.dump(service_config, f, indent=2)
|
61 |
-
return {"message": f"Project {project_name} deleted"}
|
|
|
5 |
service_config = ServiceConfig()
|
6 |
service_config.load()
|
7 |
|
|
|
|
|
|
|
|
|
8 |
@router.post("/add")
|
9 |
async def add_project(request: Request):
|
10 |
data = await request.json()
|
11 |
project_name = data.get("project_name")
|
12 |
+
if not project_name:
|
13 |
+
raise HTTPException(status_code=400, detail="project_name cannot be empty")
|
14 |
if project_name in service_config.projects:
|
15 |
raise HTTPException(status_code=400, detail="Project already exists")
|
16 |
+
|
17 |
service_config.projects[project_name] = {
|
18 |
"enabled": False,
|
19 |
"versions": []
|
|
|
23 |
json.dump(service_config, f, indent=2)
|
24 |
return {"message": f"Project {project_name} added"}
|
25 |
|
26 |
+
@router.post("/publish")
|
27 |
+
async def publish_project(request: Request):
|
28 |
data = await request.json()
|
29 |
project_name = data.get("project_name")
|
30 |
+
project = service_config.projects.get(project_name)
|
31 |
+
if not project:
|
32 |
raise HTTPException(status_code=404, detail="Project not found")
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
+
latest_version = project["versions"][-1] if project["versions"] else None
|
35 |
+
if not latest_version:
|
36 |
+
raise HTTPException(status_code=400, detail="No version exists to publish")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
+
llm = latest_version.get("llm", {})
|
39 |
+
if not llm.get("repo_id"):
|
40 |
+
raise HTTPException(status_code=400, detail="repo_id is required")
|
41 |
+
if llm.get("use_fine_tune") and not llm.get("fine_tune_zip"):
|
42 |
+
raise HTTPException(status_code=400, detail="fine_tune_zip is required when use_fine_tune is true")
|
43 |
+
|
44 |
+
return {"message": f"Project {project_name} passed publish checks"}
|
|
|
|
|
|
|
|