Spaces:
Sleeping
Sleeping
Update app/main.py
Browse files- app/main.py +6 -6
app/main.py
CHANGED
|
@@ -12,7 +12,6 @@ from pydantic import BaseModel
|
|
| 12 |
import uvicorn
|
| 13 |
|
| 14 |
load_dotenv()
|
| 15 |
-
|
| 16 |
from app.predictor import classifier, guide_generator, reviewer
|
| 17 |
from app.core.model_loader import llm_engine
|
| 18 |
|
|
@@ -22,7 +21,7 @@ logger = logging.getLogger(__name__)
|
|
| 22 |
app = FastAPI(title="GitGud AI Service")
|
| 23 |
|
| 24 |
REPO_CACHE: Dict[str, Dict[str, List[float]]] = {}
|
| 25 |
-
executor = ThreadPoolExecutor(max_workers=
|
| 26 |
|
| 27 |
class FileRequest(BaseModel):
|
| 28 |
fileName: str
|
|
@@ -47,9 +46,9 @@ class ChatRequest(BaseModel):
|
|
| 47 |
repoName: str
|
| 48 |
|
| 49 |
def calculate_repo_health(total_vulns: int, avg_maint: float) -> int:
|
| 50 |
-
base_score = avg_maint * 10
|
| 51 |
-
penalty = total_vulns * 8
|
| 52 |
-
return int(max(10, min(100, base_score - penalty)))
|
| 53 |
|
| 54 |
def sync_review_worker(file_list: List[FileRequest]):
|
| 55 |
logger.info(f"--- [DEBUG] Processing {len(file_list)} files for code review ---")
|
|
@@ -141,7 +140,7 @@ async def get_dashboard_stats(request: BatchReviewRequest):
|
|
| 141 |
found_apis.add(f"/{match}")
|
| 142 |
|
| 143 |
num_files = len(maint_scores)
|
| 144 |
-
avg_maint = (sum(maint_scores) / num_files) if num_files > 0 else 0
|
| 145 |
health_score = calculate_repo_health(total_vulns, avg_maint)
|
| 146 |
|
| 147 |
return {
|
|
@@ -214,6 +213,7 @@ async def generate_guide(request: GuideRequest):
|
|
| 214 |
try:
|
| 215 |
markdown = guide_generator.generate_markdown(request.repoName, request.filePaths)
|
| 216 |
tree_match = re.search(r"Project Structure\n\n(.*?)(?=\n\n|$)", markdown, re.S)
|
|
|
|
| 217 |
structured_tree = []
|
| 218 |
if tree_match:
|
| 219 |
structured_tree = parse_tree_to_list(tree_match.group(1))
|
|
|
|
| 12 |
import uvicorn
|
| 13 |
|
| 14 |
load_dotenv()
|
|
|
|
| 15 |
from app.predictor import classifier, guide_generator, reviewer
|
| 16 |
from app.core.model_loader import llm_engine
|
| 17 |
|
|
|
|
| 21 |
app = FastAPI(title="GitGud AI Service")
|
| 22 |
|
| 23 |
REPO_CACHE: Dict[str, Dict[str, List[float]]] = {}
|
| 24 |
+
executor = ThreadPoolExecutor(max_workers=10)
|
| 25 |
|
| 26 |
class FileRequest(BaseModel):
|
| 27 |
fileName: str
|
|
|
|
| 46 |
repoName: str
|
| 47 |
|
| 48 |
def calculate_repo_health(total_vulns: int, avg_maint: float) -> int:
|
| 49 |
+
base_score = avg_maint * 10.0
|
| 50 |
+
penalty = total_vulns * 8.0
|
| 51 |
+
return int(max(10.0, min(100.0, base_score - penalty)))
|
| 52 |
|
| 53 |
def sync_review_worker(file_list: List[FileRequest]):
|
| 54 |
logger.info(f"--- [DEBUG] Processing {len(file_list)} files for code review ---")
|
|
|
|
| 140 |
found_apis.add(f"/{match}")
|
| 141 |
|
| 142 |
num_files = len(maint_scores)
|
| 143 |
+
avg_maint = (sum(maint_scores) / num_files) if num_files > 0 else 0.0
|
| 144 |
health_score = calculate_repo_health(total_vulns, avg_maint)
|
| 145 |
|
| 146 |
return {
|
|
|
|
| 213 |
try:
|
| 214 |
markdown = guide_generator.generate_markdown(request.repoName, request.filePaths)
|
| 215 |
tree_match = re.search(r"Project Structure\n\n(.*?)(?=\n\n|$)", markdown, re.S)
|
| 216 |
+
|
| 217 |
structured_tree = []
|
| 218 |
if tree_match:
|
| 219 |
structured_tree = parse_tree_to_list(tree_match.group(1))
|