File size: 1,740 Bytes
e1d6e8a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
import os
from fastapi import FastAPI, UploadFile, File, Form, HTTPException
from fastapi.responses import JSONResponse
from dotenv import load_dotenv
from .core.analyzer import quick_analyze
from .core.reviewer import review_single_file
from .utils.file_utils import save_upload_temp, read_file_text
from .models.schemas import ReviewResponse
load_dotenv()
app = FastAPI(title="Code Review Agent v0.1", description="Single-file code review using MiniMax-M2 (Ollama).")
@app.post("/review/file", response_model=ReviewResponse)
async def review_file(file: UploadFile = File(...), persona: str = Form("general")):
if not file.filename:
raise HTTPException(status_code=400, detail="Missing filename")
temp_path = save_upload_temp(file)
code = read_file_text(temp_path)
ext = os.path.splitext(file.filename)[1].lower()
language = "python" if ext in (".py",) else "unknown"
analyzer_evidence = quick_analyze(temp_path, language)
review = review_single_file(temp_path, file.filename, code, analyzer_evidence, persona=persona)
try: os.remove(temp_path)
except OSError: pass
return JSONResponse(status_code=200, content=review.dict())
@app.get("/health")
async def health():
return {"status": "ok", "model": os.getenv("OLLAMA_MODEL", "Minimax-M2"), "engine": "Ollama"}
@app.get("/")
async def root():
return {
"message": "Welcome to Code Review Agent v0.1",
"usage": {
"endpoint": "/review/file",
"method": "POST",
"params": {"file": "upload your source file", "persona": "general|security|performance|style"},
"example": "curl -F 'file=@example.py' -F 'persona=security' http://localhost:8080/review/file"
}
}
|