Spaces:
Sleeping
Sleeping
feat: add FastAPI routes and main app entrypoint
Browse files- app/__init__.py +1 -0
- app/api/__init__.py +1 -0
- app/api/main.py +28 -0
- app/api/routes.py +76 -0
- app/core/__init__.py +2 -0
- app/services/__init__.py +0 -0
app/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
# App package
|
app/api/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
from app.api.routes import router
|
app/api/main.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 3 |
+
from app.api.routes import router
|
| 4 |
+
|
| 5 |
+
app = FastAPI(
|
| 6 |
+
title="AI Code Review Agent",
|
| 7 |
+
description="Multi-agent AI platform that simulates a software engineering team",
|
| 8 |
+
version="0.1.0"
|
| 9 |
+
)
|
| 10 |
+
|
| 11 |
+
# Allow Gradio frontend to talk to FastAPI
|
| 12 |
+
app.add_middleware(
|
| 13 |
+
CORSMiddleware,
|
| 14 |
+
allow_origins=["*"],
|
| 15 |
+
allow_methods=["*"],
|
| 16 |
+
allow_headers=["*"]
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
app.include_router(router, prefix="/api/v1")
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
@app.get("/")
|
| 23 |
+
def root():
|
| 24 |
+
return {
|
| 25 |
+
"message": "AI Code Review Agent",
|
| 26 |
+
"version": "0.1.0",
|
| 27 |
+
"docs": "/docs"
|
| 28 |
+
}
|
app/api/routes.py
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import APIRouter, HTTPException
|
| 2 |
+
from app.models.repository import RepositoryRequest, RepositoryResponse
|
| 3 |
+
from app.models.report import EngineeringReport
|
| 4 |
+
from app.tools.github_tool import clone_repository, delete_repository
|
| 5 |
+
from app.agents import (
|
| 6 |
+
repo_analysis_agent,
|
| 7 |
+
bug_detection_agent,
|
| 8 |
+
test_generation_agent,
|
| 9 |
+
code_review_agent,
|
| 10 |
+
report_generator_agent
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
router = APIRouter()
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
@router.get("/health")
|
| 17 |
+
def health_check():
|
| 18 |
+
return {"status": "ok", "message": "AI Code Review Agent is running"}
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
@router.post("/analyze", response_model=EngineeringReport)
|
| 22 |
+
def analyze_repository(request: RepositoryRequest):
|
| 23 |
+
"""
|
| 24 |
+
Full pipeline:
|
| 25 |
+
1. Clone repository
|
| 26 |
+
2. Run all agents
|
| 27 |
+
3. Return engineering report
|
| 28 |
+
"""
|
| 29 |
+
local_path = None
|
| 30 |
+
|
| 31 |
+
try:
|
| 32 |
+
# Step 1 - Clone
|
| 33 |
+
local_path = clone_repository(request.github_url)
|
| 34 |
+
|
| 35 |
+
# Step 2 - Run agents in order
|
| 36 |
+
metadata = repo_analysis_agent.run(request.github_url, local_path)
|
| 37 |
+
issues = bug_detection_agent.run(local_path)
|
| 38 |
+
tests = test_generation_agent.run(local_path)
|
| 39 |
+
review = code_review_agent.run(local_path, metadata)
|
| 40 |
+
report = report_generator_agent.run(metadata, issues, tests, review)
|
| 41 |
+
|
| 42 |
+
return report
|
| 43 |
+
|
| 44 |
+
except Exception as e:
|
| 45 |
+
raise HTTPException(status_code=500, detail=str(e))
|
| 46 |
+
|
| 47 |
+
finally:
|
| 48 |
+
# Step 3 - Cleanup cloned repo
|
| 49 |
+
if local_path:
|
| 50 |
+
delete_repository(local_path)
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
@router.post("/quick-analyze", response_model=RepositoryResponse)
|
| 54 |
+
def quick_analyze(request: RepositoryRequest):
|
| 55 |
+
"""
|
| 56 |
+
Only run repository analysis agent.
|
| 57 |
+
Faster, for testing purposes.
|
| 58 |
+
"""
|
| 59 |
+
local_path = None
|
| 60 |
+
|
| 61 |
+
try:
|
| 62 |
+
local_path = clone_repository(request.github_url)
|
| 63 |
+
metadata = repo_analysis_agent.run(request.github_url, local_path)
|
| 64 |
+
|
| 65 |
+
return RepositoryResponse(
|
| 66 |
+
success=True,
|
| 67 |
+
message="Repository analyzed successfully",
|
| 68 |
+
data=metadata
|
| 69 |
+
)
|
| 70 |
+
|
| 71 |
+
except Exception as e:
|
| 72 |
+
raise HTTPException(status_code=500, detail=str(e))
|
| 73 |
+
|
| 74 |
+
finally:
|
| 75 |
+
if local_path:
|
| 76 |
+
delete_repository(local_path)
|
app/core/__init__.py
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from app.core.config import get_settings
|
| 2 |
+
from app.core.llm import call_llm
|
app/services/__init__.py
ADDED
|
File without changes
|