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:
2026-03-13 21:13:04 +00:00
parent 3bdada174c
commit e7af9ac365
5 changed files with 213 additions and 2 deletions

View File

@@ -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

View File

@@ -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,