Spaces:
Paused
Paused
Update admin_routes.py
Browse files- admin_routes.py +49 -0
admin_routes.py
CHANGED
|
@@ -224,6 +224,46 @@ def add_activity_log(config: dict, username: str, action: str,
|
|
| 224 |
if len(config["activity_log"]) > 1000:
|
| 225 |
config["activity_log"] = config["activity_log"][-1000:]
|
| 226 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 227 |
# ===================== Auth Endpoints =====================
|
| 228 |
@router.post("/login", response_model=LoginResponse)
|
| 229 |
async def login(request: LoginRequest):
|
|
@@ -725,6 +765,15 @@ async def publish_version(
|
|
| 725 |
save_config(config)
|
| 726 |
|
| 727 |
log(f"β
Version {version_id} published for project '{project['name']}' by {username}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 728 |
return {"success": True}
|
| 729 |
|
| 730 |
@router.delete("/projects/{project_id}/versions/{version_id}")
|
|
|
|
| 224 |
if len(config["activity_log"]) > 1000:
|
| 225 |
config["activity_log"] = config["activity_log"][-1000:]
|
| 226 |
|
| 227 |
+
async def notify_spark(project: dict, version: dict, global_config: dict):
|
| 228 |
+
"""Notify Spark about published version"""
|
| 229 |
+
import httpx
|
| 230 |
+
|
| 231 |
+
spark_endpoint = global_config.get("spark_endpoint", "").rstrip("/")
|
| 232 |
+
if not spark_endpoint:
|
| 233 |
+
log("β οΈ Spark endpoint not configured")
|
| 234 |
+
return
|
| 235 |
+
|
| 236 |
+
work_mode = global_config.get("work_mode", "hfcloud")
|
| 237 |
+
cloud_token = global_config.get("cloud_token", "")
|
| 238 |
+
|
| 239 |
+
# Decrypt token if needed
|
| 240 |
+
if cloud_token and cloud_token.startswith("enc:"):
|
| 241 |
+
from encryption_utils import decrypt
|
| 242 |
+
cloud_token = decrypt(cloud_token)
|
| 243 |
+
|
| 244 |
+
payload = {
|
| 245 |
+
"work_mode": work_mode,
|
| 246 |
+
"cloud_token": cloud_token,
|
| 247 |
+
"project_name": project["name"],
|
| 248 |
+
"project_version": version["id"],
|
| 249 |
+
"repo_id": version["llm"]["repo_id"],
|
| 250 |
+
"generation_config": version["llm"]["generation_config"],
|
| 251 |
+
"use_fine_tune": version["llm"]["use_fine_tune"],
|
| 252 |
+
"fine_tune_zip": version["llm"]["fine_tune_zip"] if version["llm"]["use_fine_tune"] else None
|
| 253 |
+
}
|
| 254 |
+
|
| 255 |
+
log(f"π Notifying Spark about {project['name']} v{version['id']}")
|
| 256 |
+
|
| 257 |
+
async with httpx.AsyncClient(timeout=30) as client:
|
| 258 |
+
try:
|
| 259 |
+
response = await client.post(spark_endpoint + "/startup", json=payload)
|
| 260 |
+
response.raise_for_status()
|
| 261 |
+
result = response.json()
|
| 262 |
+
log(f"β
Spark notification successful: {result.get('message', 'OK')}")
|
| 263 |
+
except Exception as e:
|
| 264 |
+
log(f"β Spark notification failed: {e}")
|
| 265 |
+
raise
|
| 266 |
+
|
| 267 |
# ===================== Auth Endpoints =====================
|
| 268 |
@router.post("/login", response_model=LoginResponse)
|
| 269 |
async def login(request: LoginRequest):
|
|
|
|
| 765 |
save_config(config)
|
| 766 |
|
| 767 |
log(f"β
Version {version_id} published for project '{project['name']}' by {username}")
|
| 768 |
+
|
| 769 |
+
# Notify Spark if project is enabled
|
| 770 |
+
if project.get("enabled", False):
|
| 771 |
+
try:
|
| 772 |
+
await notify_spark(project, version, config.get("config", {}))
|
| 773 |
+
except Exception as e:
|
| 774 |
+
log(f"β οΈ Failed to notify Spark: {e}")
|
| 775 |
+
# Don't fail the publish
|
| 776 |
+
|
| 777 |
return {"success": True}
|
| 778 |
|
| 779 |
@router.delete("/projects/{project_id}/versions/{version_id}")
|