Spaces:
Paused
Paused
Update admin_routes.py
Browse files- admin_routes.py +23 -23
admin_routes.py
CHANGED
|
@@ -73,7 +73,7 @@ class ProjectUpdate(BaseModel):
|
|
| 73 |
|
| 74 |
class VersionCreate(BaseModel):
|
| 75 |
caption: str
|
| 76 |
-
|
| 77 |
|
| 78 |
class IntentModel(BaseModel):
|
| 79 |
name: str
|
|
@@ -531,10 +531,10 @@ async def create_version(
|
|
| 531 |
log_info(f"✅ Version created for project {project_id} by {username}")
|
| 532 |
return new_version.model_dump()
|
| 533 |
|
| 534 |
-
@router.put("/projects/{project_id}/versions/{
|
| 535 |
async def update_version(
|
| 536 |
project_id: int,
|
| 537 |
-
|
| 538 |
update: VersionUpdate,
|
| 539 |
force: bool = Query(default=False, description="Force update despite conflicts"),
|
| 540 |
username: str = Depends(verify_token)
|
|
@@ -543,17 +543,17 @@ async def update_version(
|
|
| 543 |
try:
|
| 544 |
# Force parametresi kontrolü
|
| 545 |
if force:
|
| 546 |
-
log_warning(f"⚠️ Force update requested for version {
|
| 547 |
|
| 548 |
result = ConfigProvider.update_version(
|
| 549 |
project_id,
|
| 550 |
-
|
| 551 |
update.model_dump(),
|
| 552 |
username,
|
| 553 |
expected_last_update=update.last_update_date if not force else None
|
| 554 |
)
|
| 555 |
|
| 556 |
-
log_info(f"✅ Version {
|
| 557 |
return result
|
| 558 |
|
| 559 |
except RaceConditionError as e:
|
|
@@ -561,14 +561,14 @@ async def update_version(
|
|
| 561 |
# Force modunda race condition'ı yoksay
|
| 562 |
result = ConfigProvider.update_version(
|
| 563 |
project_id,
|
| 564 |
-
|
| 565 |
update.model_dump(),
|
| 566 |
username,
|
| 567 |
expected_last_update=None
|
| 568 |
)
|
| 569 |
return result
|
| 570 |
else:
|
| 571 |
-
log_warning(f"⚠️ Race condition detected for version {
|
| 572 |
raise HTTPException(
|
| 573 |
status_code=409,
|
| 574 |
detail={
|
|
@@ -581,19 +581,19 @@ async def update_version(
|
|
| 581 |
except ResourceNotFoundError:
|
| 582 |
raise HTTPException(status_code=404, detail="Version not found")
|
| 583 |
except Exception as e:
|
| 584 |
-
log_error(f"❌ Error updating version {
|
| 585 |
raise HTTPException(status_code=500, detail=str(e))
|
| 586 |
|
| 587 |
-
@router.post("/projects/{project_id}/versions/{
|
| 588 |
async def publish_version(
|
| 589 |
project_id: int,
|
| 590 |
-
|
| 591 |
username: str = Depends(verify_token)
|
| 592 |
):
|
| 593 |
"""Publish version"""
|
| 594 |
-
project, version = ConfigProvider.publish_version(project_id,
|
| 595 |
|
| 596 |
-
log_info(f"✅ Version {
|
| 597 |
|
| 598 |
# Notify LLM provider if project is enabled and provider requires repo info
|
| 599 |
cfg = ConfigProvider.get()
|
|
@@ -608,16 +608,16 @@ async def publish_version(
|
|
| 608 |
|
| 609 |
return {"success": True}
|
| 610 |
|
| 611 |
-
@router.delete("/projects/{project_id}/versions/{
|
| 612 |
async def delete_version(
|
| 613 |
project_id: int,
|
| 614 |
-
|
| 615 |
username: str = Depends(verify_token)
|
| 616 |
):
|
| 617 |
"""Delete version (soft delete)"""
|
| 618 |
-
ConfigProvider.delete_version(project_id,
|
| 619 |
|
| 620 |
-
log_info(f"✅ Version {
|
| 621 |
return {"success": True}
|
| 622 |
|
| 623 |
@router.get("/projects/{project_name}/versions")
|
|
@@ -638,7 +638,7 @@ async def get_project_versions(
|
|
| 638 |
for v in project.versions:
|
| 639 |
if not getattr(v, 'deleted', False):
|
| 640 |
versions.append({
|
| 641 |
-
"version_number": v.
|
| 642 |
"caption": v.caption,
|
| 643 |
"published": v.published,
|
| 644 |
"description": getattr(v, 'description', ''),
|
|
@@ -656,8 +656,8 @@ async def get_project_versions(
|
|
| 656 |
@router.get("/projects/{project_id}/versions/{version1_id}/compare/{version2_id}")
|
| 657 |
async def compare_versions(
|
| 658 |
project_id: int,
|
| 659 |
-
|
| 660 |
-
|
| 661 |
username: str = Depends(verify_token)
|
| 662 |
):
|
| 663 |
"""Compare two versions and return differences"""
|
|
@@ -665,8 +665,8 @@ async def compare_versions(
|
|
| 665 |
if not project:
|
| 666 |
raise HTTPException(status_code=404, detail="Project not found")
|
| 667 |
|
| 668 |
-
v1 = next((v for v in project.versions if v.
|
| 669 |
-
v2 = next((v for v in project.versions if v.
|
| 670 |
|
| 671 |
if not v1 or not v2:
|
| 672 |
raise HTTPException(status_code=404, detail="Version not found")
|
|
@@ -958,7 +958,7 @@ async def notify_llm_startup(project, version):
|
|
| 958 |
# Build project config for startup
|
| 959 |
project_config = {
|
| 960 |
"name": project.name,
|
| 961 |
-
"
|
| 962 |
"repo_id": version.llm.repo_id,
|
| 963 |
"generation_config": version.llm.generation_config,
|
| 964 |
"use_fine_tune": version.llm.use_fine_tune,
|
|
|
|
| 73 |
|
| 74 |
class VersionCreate(BaseModel):
|
| 75 |
caption: str
|
| 76 |
+
source_version_no: int | None = None
|
| 77 |
|
| 78 |
class IntentModel(BaseModel):
|
| 79 |
name: str
|
|
|
|
| 531 |
log_info(f"✅ Version created for project {project_id} by {username}")
|
| 532 |
return new_version.model_dump()
|
| 533 |
|
| 534 |
+
@router.put("/projects/{project_id}/versions/{version_no}")
|
| 535 |
async def update_version(
|
| 536 |
project_id: int,
|
| 537 |
+
version_no: int,
|
| 538 |
update: VersionUpdate,
|
| 539 |
force: bool = Query(default=False, description="Force update despite conflicts"),
|
| 540 |
username: str = Depends(verify_token)
|
|
|
|
| 543 |
try:
|
| 544 |
# Force parametresi kontrolü
|
| 545 |
if force:
|
| 546 |
+
log_warning(f"⚠️ Force update requested for version {version_no} by {username}")
|
| 547 |
|
| 548 |
result = ConfigProvider.update_version(
|
| 549 |
project_id,
|
| 550 |
+
version_no,
|
| 551 |
update.model_dump(),
|
| 552 |
username,
|
| 553 |
expected_last_update=update.last_update_date if not force else None
|
| 554 |
)
|
| 555 |
|
| 556 |
+
log_info(f"✅ Version {version_no} updated by {username}")
|
| 557 |
return result
|
| 558 |
|
| 559 |
except RaceConditionError as e:
|
|
|
|
| 561 |
# Force modunda race condition'ı yoksay
|
| 562 |
result = ConfigProvider.update_version(
|
| 563 |
project_id,
|
| 564 |
+
version_no,
|
| 565 |
update.model_dump(),
|
| 566 |
username,
|
| 567 |
expected_last_update=None
|
| 568 |
)
|
| 569 |
return result
|
| 570 |
else:
|
| 571 |
+
log_warning(f"⚠️ Race condition detected for version {version_no}")
|
| 572 |
raise HTTPException(
|
| 573 |
status_code=409,
|
| 574 |
detail={
|
|
|
|
| 581 |
except ResourceNotFoundError:
|
| 582 |
raise HTTPException(status_code=404, detail="Version not found")
|
| 583 |
except Exception as e:
|
| 584 |
+
log_error(f"❌ Error updating version {version_no}", e)
|
| 585 |
raise HTTPException(status_code=500, detail=str(e))
|
| 586 |
|
| 587 |
+
@router.post("/projects/{project_id}/versions/{version_no}/publish")
|
| 588 |
async def publish_version(
|
| 589 |
project_id: int,
|
| 590 |
+
version_no: int,
|
| 591 |
username: str = Depends(verify_token)
|
| 592 |
):
|
| 593 |
"""Publish version"""
|
| 594 |
+
project, version = ConfigProvider.publish_version(project_id, version_no, username)
|
| 595 |
|
| 596 |
+
log_info(f"✅ Version {version_no} published for project '{project.name}' by {username}")
|
| 597 |
|
| 598 |
# Notify LLM provider if project is enabled and provider requires repo info
|
| 599 |
cfg = ConfigProvider.get()
|
|
|
|
| 608 |
|
| 609 |
return {"success": True}
|
| 610 |
|
| 611 |
+
@router.delete("/projects/{project_id}/versions/{version_no}")
|
| 612 |
async def delete_version(
|
| 613 |
project_id: int,
|
| 614 |
+
version_no: int,
|
| 615 |
username: str = Depends(verify_token)
|
| 616 |
):
|
| 617 |
"""Delete version (soft delete)"""
|
| 618 |
+
ConfigProvider.delete_version(project_id, version_no, username)
|
| 619 |
|
| 620 |
+
log_info(f"✅ Version {version_no} deleted for project {project_id} by {username}")
|
| 621 |
return {"success": True}
|
| 622 |
|
| 623 |
@router.get("/projects/{project_name}/versions")
|
|
|
|
| 638 |
for v in project.versions:
|
| 639 |
if not getattr(v, 'deleted', False):
|
| 640 |
versions.append({
|
| 641 |
+
"version_number": v.no,
|
| 642 |
"caption": v.caption,
|
| 643 |
"published": v.published,
|
| 644 |
"description": getattr(v, 'description', ''),
|
|
|
|
| 656 |
@router.get("/projects/{project_id}/versions/{version1_id}/compare/{version2_id}")
|
| 657 |
async def compare_versions(
|
| 658 |
project_id: int,
|
| 659 |
+
version1_no: int,
|
| 660 |
+
version2_no: int,
|
| 661 |
username: str = Depends(verify_token)
|
| 662 |
):
|
| 663 |
"""Compare two versions and return differences"""
|
|
|
|
| 665 |
if not project:
|
| 666 |
raise HTTPException(status_code=404, detail="Project not found")
|
| 667 |
|
| 668 |
+
v1 = next((v for v in project.versions if v.no == version1_no), None)
|
| 669 |
+
v2 = next((v for v in project.versions if v.no == version2_no), None)
|
| 670 |
|
| 671 |
if not v1 or not v2:
|
| 672 |
raise HTTPException(status_code=404, detail="Version not found")
|
|
|
|
| 958 |
# Build project config for startup
|
| 959 |
project_config = {
|
| 960 |
"name": project.name,
|
| 961 |
+
"version_no": version.no,
|
| 962 |
"repo_id": version.llm.repo_id,
|
| 963 |
"generation_config": version.llm.generation_config,
|
| 964 |
"use_fine_tune": version.llm.use_fine_tune,
|