Spaces:
Running
Running
Deploy 573d8548
Browse files- .opencodereview/vectors/chroma.sqlite3 +2 -2
- eval_data/eval_results.json +7 -6
- eval_data/prs.jsonl +0 -1
- eval_data/ragas_eval.py +7 -4
- main.py +46 -0
- requirements.txt +1 -2
- scripts/alert.py +1 -6
.opencodereview/vectors/chroma.sqlite3
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:588b33aeab4fd94273595702c1438b1b888bedde857cf88d2370ad5205e19346
|
| 3 |
+
size 9547776
|
eval_data/eval_results.json
CHANGED
|
@@ -2,15 +2,16 @@
|
|
| 2 |
{
|
| 3 |
"tp": 0,
|
| 4 |
"fp": 0,
|
| 5 |
-
"fn":
|
| 6 |
"precision": 0.0,
|
| 7 |
"recall": 0.0,
|
| 8 |
"f1": 0.0,
|
| 9 |
"agent_findings": 0,
|
| 10 |
-
"human_comments":
|
| 11 |
-
"id": "
|
| 12 |
-
"repo": "
|
| 13 |
-
"pr_number":
|
| 14 |
-
"title": "
|
|
|
|
| 15 |
}
|
| 16 |
]
|
|
|
|
| 2 |
{
|
| 3 |
"tp": 0,
|
| 4 |
"fp": 0,
|
| 5 |
+
"fn": 3,
|
| 6 |
"precision": 0.0,
|
| 7 |
"recall": 0.0,
|
| 8 |
"f1": 0.0,
|
| 9 |
"agent_findings": 0,
|
| 10 |
+
"human_comments": 3,
|
| 11 |
+
"id": "psf_requests_7431",
|
| 12 |
+
"repo": "psf/requests",
|
| 13 |
+
"pr_number": 7431,
|
| 14 |
+
"title": "Fix mutability issues with headers input types",
|
| 15 |
+
"trace_id": null
|
| 16 |
}
|
| 17 |
]
|
eval_data/prs.jsonl
CHANGED
|
@@ -1 +0,0 @@
|
|
| 1 |
-
{"id": "test_repo_test_1", "repo": "demo-org/demo-repo", "pr_number": 1, "title": "Test PR for evaluation", "diff": "diff --git a/src/auth.py b/src/auth.py\nindex abc123..def456 100644\n--- a/src/auth.py\n+++ b/src/auth.py\n@@ -42,7 +42,9 @@ def login(username, password):\n user = db.get_user(username)\n- if user.password == password:\n+ if constant_time_compare(password, user.password):\n return create_session(user)\n return None\n", "changed_files": [{"path": "src/auth.py", "status": "modified", "content": "def login(username, password):\n user = db.get_user(username)\n if constant_time_compare(password, user.password):\n return create_session(user)\n return None\n", "diff_hunk": "@@ -42,7 +42,9 @@ def login(username, password): ..."}], "ground_truth": [{"file_path": "src/auth.py", "line": 42, "comment": "Should use constant-time comparison for passwords", "reviewer": "test-human"}]}
|
|
|
|
|
|
eval_data/ragas_eval.py
CHANGED
|
@@ -38,18 +38,21 @@ _RAGAS_AVAILABLE: bool | None = None
|
|
| 38 |
|
| 39 |
|
| 40 |
def _check_ragas() -> bool:
|
| 41 |
-
"""Return True if RAGAS
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
global _RAGAS_AVAILABLE
|
| 43 |
if _RAGAS_AVAILABLE is not None:
|
| 44 |
return _RAGAS_AVAILABLE
|
| 45 |
try:
|
| 46 |
import ragas # noqa: F401
|
| 47 |
-
import litellm # noqa: F401
|
| 48 |
_RAGAS_AVAILABLE = True
|
| 49 |
except ImportError:
|
| 50 |
logger.warning(
|
| 51 |
-
"ragas
|
| 52 |
-
"pip install ragas litellm"
|
| 53 |
)
|
| 54 |
_RAGAS_AVAILABLE = False
|
| 55 |
return _RAGAS_AVAILABLE
|
|
|
|
| 38 |
|
| 39 |
|
| 40 |
def _check_ragas() -> bool:
|
| 41 |
+
"""Return True if RAGAS is available.
|
| 42 |
+
|
| 43 |
+
Note: ``litellm`` is NOT required because RAGAS scoring uses the
|
| 44 |
+
project's own LLM factory (Gemini or Groq via LangChain), not
|
| 45 |
+
litellm internally.
|
| 46 |
+
"""
|
| 47 |
global _RAGAS_AVAILABLE
|
| 48 |
if _RAGAS_AVAILABLE is not None:
|
| 49 |
return _RAGAS_AVAILABLE
|
| 50 |
try:
|
| 51 |
import ragas # noqa: F401
|
|
|
|
| 52 |
_RAGAS_AVAILABLE = True
|
| 53 |
except ImportError:
|
| 54 |
logger.warning(
|
| 55 |
+
"ragas not installed. Install with: pip install ragas"
|
|
|
|
| 56 |
)
|
| 57 |
_RAGAS_AVAILABLE = False
|
| 58 |
return _RAGAS_AVAILABLE
|
main.py
CHANGED
|
@@ -300,6 +300,52 @@ def _run_with_hitl(graph, repo: str, pr_number: int) -> None:
|
|
| 300 |
handler=handler,
|
| 301 |
)
|
| 302 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 303 |
logger.info("=" * 60)
|
| 304 |
|
| 305 |
click.echo()
|
|
|
|
| 300 |
handler=handler,
|
| 301 |
)
|
| 302 |
|
| 303 |
+
# ββ Compute and log RAGAS retrieval scores βββββββββββββββββ
|
| 304 |
+
context_chunks = state.values.get("context_chunks", [])
|
| 305 |
+
if context_chunks:
|
| 306 |
+
try:
|
| 307 |
+
from eval_data.ragas_eval import compute_ragas_retrieval_scores
|
| 308 |
+
|
| 309 |
+
query = state.values.get("diff", "") or ""
|
| 310 |
+
contexts = [c.content for c in context_chunks if c.content]
|
| 311 |
+
|
| 312 |
+
# Build answer text from findings + verdict for
|
| 313 |
+
# faithfulness & answer_relevancy metrics
|
| 314 |
+
answer_lines = []
|
| 315 |
+
for f in final_findings:
|
| 316 |
+
answer_lines.append(
|
| 317 |
+
f"[{f.severity.value}] {f.file_path}:{f.line_start}-{f.line_end}: {f.comment}"
|
| 318 |
+
)
|
| 319 |
+
if state.values.get("verdict"):
|
| 320 |
+
v = state.values["verdict"]
|
| 321 |
+
answer_lines.append(
|
| 322 |
+
f"Verdict: {v.recommendation} (score={v.overall_score}/10) β {v.summary}"
|
| 323 |
+
)
|
| 324 |
+
answer_text = "\n".join(answer_lines) if answer_lines else None
|
| 325 |
+
|
| 326 |
+
ragas_scores = compute_ragas_retrieval_scores(
|
| 327 |
+
query=query,
|
| 328 |
+
retrieved_contexts=contexts,
|
| 329 |
+
answer=answer_text,
|
| 330 |
+
)
|
| 331 |
+
|
| 332 |
+
for metric_name, value in ragas_scores.items():
|
| 333 |
+
log_langfuse_score(
|
| 334 |
+
name=f"ragas_{metric_name}",
|
| 335 |
+
value=value,
|
| 336 |
+
comment=f"{repo}#{pr_number} β {metric_name}",
|
| 337 |
+
handler=handler,
|
| 338 |
+
)
|
| 339 |
+
|
| 340 |
+
logger.info(
|
| 341 |
+
" RAGAS scores logged to Langfuse: %s",
|
| 342 |
+
" | ".join(f"{k}={v:.4f}" for k, v in ragas_scores.items()),
|
| 343 |
+
)
|
| 344 |
+
except ImportError:
|
| 345 |
+
logger.info("RAGAS not installed β skipping RAGAS scoring (pip install ragas)")
|
| 346 |
+
except Exception as exc:
|
| 347 |
+
logger.warning("RAGAS scoring failed: %s", exc)
|
| 348 |
+
|
| 349 |
logger.info("=" * 60)
|
| 350 |
|
| 351 |
click.echo()
|
requirements.txt
CHANGED
|
@@ -12,5 +12,4 @@ chromadb
|
|
| 12 |
langsmith>=0.7
|
| 13 |
langfuse
|
| 14 |
requests-cache>=1.2
|
| 15 |
-
ragas>=0.3
|
| 16 |
-
litellm
|
|
|
|
| 12 |
langsmith>=0.7
|
| 13 |
langfuse
|
| 14 |
requests-cache>=1.2
|
| 15 |
+
ragas>=0.3,<0.4
|
|
|
scripts/alert.py
CHANGED
|
@@ -99,12 +99,7 @@ def _run_smoke_test() -> dict[str, Any]:
|
|
| 99 |
"metadata": metadata,
|
| 100 |
}
|
| 101 |
|
| 102 |
-
|
| 103 |
-
trace_name="opencodereview/alert-check",
|
| 104 |
-
tags=["cli", "alert", "demo-org/demo-repo"],
|
| 105 |
-
session_id=thread_id,
|
| 106 |
-
)
|
| 107 |
-
with _langfuse_trace(
|
| 108 |
trace_name="opencodereview/alert-check",
|
| 109 |
tags=["cli", "alert", "demo-org/demo-repo"],
|
| 110 |
session_id=thread_id,
|
|
|
|
| 99 |
"metadata": metadata,
|
| 100 |
}
|
| 101 |
|
| 102 |
+
with langfuse_trace(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
trace_name="opencodereview/alert-check",
|
| 104 |
tags=["cli", "alert", "demo-org/demo-repo"],
|
| 105 |
session_id=thread_id,
|