feat: add AI provider commands with on-chain payment
- Create ai.py with serve and request commands - request includes balance verification and payment via blockchain send - serve runs FastAPI server and optionally registers jobs with coordinator Update marketplace.py: - Add gpu unregister command (DELETE endpoint)
This commit is contained in:
@@ -2,11 +2,14 @@ from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import json
|
||||
import warnings
|
||||
from collections import defaultdict
|
||||
from contextlib import suppress
|
||||
from dataclasses import dataclass
|
||||
from typing import Any, Callable, Dict, List, Optional, Set
|
||||
|
||||
warnings.filterwarnings("ignore", message="coroutine.* was never awaited", category=RuntimeWarning)
|
||||
|
||||
try:
|
||||
from starlette.broadcast import Broadcast
|
||||
except ImportError: # pragma: no cover - Starlette removed Broadcast in recent versions
|
||||
|
||||
@@ -426,6 +426,26 @@ async def send_payment(
|
||||
}
|
||||
|
||||
|
||||
@router.delete("/marketplace/gpu/{gpu_id}")
|
||||
async def delete_gpu(
|
||||
gpu_id: str,
|
||||
session: Annotated[Session, Depends(get_session)],
|
||||
force: bool = Query(default=False, description="Force delete even if GPU is booked")
|
||||
) -> Dict[str, Any]:
|
||||
"""Delete (unregister) a GPU from the marketplace."""
|
||||
gpu = _get_gpu_or_404(session, gpu_id)
|
||||
|
||||
if gpu.status == "booked" and not force:
|
||||
raise HTTPException(
|
||||
status_code=http_status.HTTP_409_CONFLICT,
|
||||
detail=f"GPU {gpu_id} is currently booked. Use force=true to delete anyway."
|
||||
)
|
||||
|
||||
session.delete(gpu)
|
||||
session.commit()
|
||||
return {"status": "deleted", "gpu_id": gpu_id}
|
||||
|
||||
|
||||
@router.get("/marketplace/gpu/{gpu_id}/reviews")
|
||||
async def get_gpu_reviews(
|
||||
gpu_id: str,
|
||||
|
||||
Reference in New Issue
Block a user