Spaces:
Sleeping
Sleeping
fix(code_review_agent): replace broken manual JSON parse with call_llm_for_json; remove unused call_llm import
Browse files
app/agents/code_review_agent.py
CHANGED
|
@@ -2,7 +2,7 @@ from app.core.logger import get_logger
|
|
| 2 |
|
| 3 |
import os
|
| 4 |
from app.tools.file_scanner import get_python_files
|
| 5 |
-
from app.core.llm import
|
| 6 |
from app.core.prompts import CODE_REVIEW_PROMPT
|
| 7 |
from app.models.review import ReviewSuggestions
|
| 8 |
from app.models.repository import RepositoryMetadata
|
|
@@ -35,21 +35,10 @@ async def run(local_path: str, metadata: RepositoryMetadata) -> ReviewSuggestion
|
|
| 35 |
overall_score=0.0
|
| 36 |
)
|
| 37 |
|
| 38 |
-
# Step 3 - Call LLM
|
| 39 |
source_code = "\n\n".join(source_samples)
|
| 40 |
prompt = CODE_REVIEW_PROMPT.format(source_code=source_code)
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
# Step 4 - Parse response
|
| 44 |
-
try:
|
| 45 |
-
cleaned = llm_response.strip().removeprefix("```json").removeprefix("```").removesuffix("```").strip()
|
| 46 |
-
llm_data = json.loads(cleaned)
|
| 47 |
-
except json.JSONDecodeError:
|
| 48 |
-
logger.error(
|
| 49 |
-
"Failed to parse LLM response as JSON",
|
| 50 |
-
extra={"raw_response": llm_response[:500]},
|
| 51 |
-
)
|
| 52 |
-
llm_data = await call_llm_for_json(prompt)
|
| 53 |
|
| 54 |
review = ReviewSuggestions(
|
| 55 |
solid_violations=llm_data.get("solid_violations", []),
|
|
|
|
| 2 |
|
| 3 |
import os
|
| 4 |
from app.tools.file_scanner import get_python_files
|
| 5 |
+
from app.core.llm import call_llm_for_json
|
| 6 |
from app.core.prompts import CODE_REVIEW_PROMPT
|
| 7 |
from app.models.review import ReviewSuggestions
|
| 8 |
from app.models.repository import RepositoryMetadata
|
|
|
|
| 35 |
overall_score=0.0
|
| 36 |
)
|
| 37 |
|
| 38 |
+
# Step 3 - Call LLM and parse JSON in one shot
|
| 39 |
source_code = "\n\n".join(source_samples)
|
| 40 |
prompt = CODE_REVIEW_PROMPT.format(source_code=source_code)
|
| 41 |
+
llm_data = await call_llm_for_json(prompt)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
review = ReviewSuggestions(
|
| 44 |
solid_violations=llm_data.get("solid_violations", []),
|