File size: 3,565 Bytes
b92d20c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2d2c6e4
 
 
 
b92d20c
 
2d2c6e4
b92d20c
 
 
 
 
 
 
 
2d2c6e4
 
b92d20c
 
 
 
 
 
 
2d2c6e4
 
 
b92d20c
2d2c6e4
 
 
 
50242cc
2d2c6e4
 
b92d20c
 
2d2c6e4
 
 
b92d20c
2d2c6e4
b92d20c
 
 
 
50242cc
b92d20c
2d2c6e4
b92d20c
 
 
 
 
 
 
 
 
2d2c6e4
b92d20c
 
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"""
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
FILE: run_benchmark.py
FOLDER: examples/
PURPOSE: Runs 10 episodes with 3 review types and prints comparison stats
USED BY: Judges evaluating the reward heuristic dynamically
KEY CLASSES/FUNCTIONS: main()
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
"""

import os
import asyncio
from codereview_env.client import CodeReviewEnv
from codereview_env.models import CodeReviewAction

TYPES = [
    {"name": "Generic (bad)", "text": "LGTM looks good!"},
    {"name": "Medium", "text": "There might be an issue here. Consider fixing it."},
    {
        "name": "Specific (good)",
        "text": "Line 3: Critical bug β€” The indexing is exceeding array bounds causing a runtime error. Switch `>` to `>=` to patch it safely.",
    },
]


async def main():
    print("============================================================")
    print(" πŸ“Š CodeReview-Env Dynamic Benchmarking ")
    print(" Running 10 episodes for each review type.")
    print("============================================================\n")

    port = os.getenv("PORT", "8000")
    base_url = f"http://localhost:{port}"

    results = {"Generic (bad)": [], "Medium": [], "Specific (good)": []}

    async with CodeReviewEnv(base_url=base_url) as env:
        for t in TYPES:
            print(f"Evaluating: {t['name']}...")
            for i in range(10):
                try:
                    await env.reset()
                    action = CodeReviewAction(
                        review_comment=t["text"], severity="major"
                    )
                    result = await env.step(action)
                    rew = float(
                        result.reward
                        if hasattr(result, "reward")
                        else (
                            result.get("reward", 0.05) if hasattr(result, "get") else 0.05
                        )
                    )
                    results[t["name"]].append(rew)
                except Exception as e:
                    print(
                        f"Error on iteration {i}: {e}. Ensure API relies on localhost:{port}"
                    )
                    break

    # Calculate statistics
    stats = {}
    for k, v in results.items():
        if len(v) == 0:
            stats[k] = (0.05, 0.05, 0.05)
            continue
        stats[k] = (sum(v) / len(v), min(v), max(v))  # Avg  # Min  # Max

    # Output Table
    print("\nβ”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”")
    print("β”‚ Review Type    β”‚ Avg Reward   β”‚ Min Reward   β”‚ Max Reward   β”‚")
    print("β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€")
    for k, (avg, mn, mx) in stats.items():
        print(f"β”‚ {k:<14} β”‚    {avg:.2f}      β”‚    {mn:.2f}      β”‚    {mx:.2f}      β”‚")
    print("β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜\n")


if __name__ == "__main__":
    asyncio.run(main())