-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_llm_local.py
More file actions
104 lines (87 loc) · 3.16 KB
/
test_llm_local.py
File metadata and controls
104 lines (87 loc) · 3.16 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env python3
"""
Local test script for running the scenario miner with LLM.
This runs the same mining process as the GitHub action but with LLM enabled.
Good for testing locally on a small number of recent issues before deploying.
Usage:
python test_llm_local.py [--days N] [--output-dir DIR]
Examples:
# Mine issues from last 7 days with LLM
python test_llm_local.py --days 7
# Mine issues from last 30 days, save to test-results/
python test_llm_local.py --days 30 --output-dir test-results
Required environment variables:
ANTHROPIC_API_KEY - Your Anthropic API key for LLM
GITHUB_TOKEN - GitHub PAT for higher API limits (optional but recommended)
"""
import os
import sys
import subprocess
from datetime import datetime, timedelta
def main():
# Check for required environment variables
if not os.getenv("ANTHROPIC_API_KEY"):
print("❌ Error: ANTHROPIC_API_KEY not set")
print("\nSet it with:")
print(" export ANTHROPIC_API_KEY='your-key-here'")
return 1
if not os.getenv("GITHUB_TOKEN"):
print("⚠️ Warning: GITHUB_TOKEN not set (API rate limits will be lower)")
print("Set it with:")
print(" export GITHUB_TOKEN='your-token-here'\n")
# Parse arguments
import argparse
parser = argparse.ArgumentParser(
description="Run scenario miner with LLM on recent issues"
)
parser.add_argument(
"--days",
type=int,
default=7,
help="Number of days back to mine (default: 7)"
)
parser.add_argument(
"--output-dir",
default="./test-results",
help="Output directory for results (default: ./test-results)"
)
parser.add_argument(
"--verbose",
action="store_true",
help="Enable verbose logging"
)
args = parser.parse_args()
# Calculate date
since_date = datetime.now() - timedelta(days=args.days)
since_date_str = since_date.strftime("%Y-%m-%d")
print(f"🚀 Running scenario miner with LLM")
print(f"📅 Mining issues since: {since_date_str} ({args.days} days ago)")
print(f"📂 Output directory: {args.output_dir}")
print(f"🤖 LLM model: {os.getenv('LLM_MODEL', 'claude-3-5-sonnet-20241022')}")
print()
# Build command - same as GitHub action but WITH LLM
cmd = [
".venv/bin/python",
"-m",
"ot_miner.cli",
"--output-dir", args.output_dir,
"--since-date", since_date_str,
]
if args.verbose:
cmd.append("--verbose")
print(f"💻 Running: {' '.join(cmd)}\n")
# Run the command
try:
result = subprocess.run(cmd, check=True)
print(f"\n✅ Mining complete!")
print(f"📁 Results saved to: {args.output_dir}/")
return result.returncode
except subprocess.CalledProcessError as e:
print(f"\n❌ Mining failed with exit code {e.returncode}")
return e.returncode
except FileNotFoundError:
print("\n❌ Error: Could not find .venv/bin/python")
print("Make sure you've installed dependencies with: uv sync")
return 1
if __name__ == "__main__":
sys.exit(main())