File size: 4,760 Bytes
9e3d618 |
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 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
#!/usr/bin/env python3
"""
Execute the complete 3-agent pipeline on all JSON files in mordor_dataset.
This runs:
1. Log Analysis Agent
2. Retrieval Supervisor (with Database Agent and Grader)
3. Response Agent
Outputs are saved to final_response/ folder.
Usage: python execute_pipeline.py [--model MODEL_NAME]
"""
import subprocess
from pathlib import Path
import sys
import argparse
def find_project_root(start: Path) -> Path:
"""Find the project root by looking for common markers."""
for p in [start] + list(start.parents):
if (
(p / "mordor_dataset").exists()
or (p / "src").exists()
or (p / ".git").exists()
):
return p
return start.parent
def main():
"""Execute pipeline on all mordor dataset files"""
parser = argparse.ArgumentParser(
description="Execute pipeline on all mordor dataset files",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="""
Examples:
# Run with default model (Gemini 2.0 Flash)
python execute_pipeline.py
# Run with specific model
python execute_pipeline.py --model google_genai:gemini-2.0-flash
python execute_pipeline.py --model groq:gpt-oss-120b
python execute_pipeline.py --model groq:llama-3.1-8b-instant
Available models:
- google_genai:gemini-2.0-flash (default)
- google_genai:gemini-1.5-flash
- groq:gpt-oss-120b
- groq:gpt-oss-20b
- groq:llama-3.1-8b-instant
- groq:llama-3.3-70b-versatile
""",
)
parser.add_argument(
"--model",
default="google_genai:gemini-2.0-flash",
help="Model to use for analysis (default: google_genai:gemini-2.0-flash)",
)
args = parser.parse_args()
model_name = args.model
current_file = Path(__file__).resolve()
project_root = find_project_root(current_file.parent)
mordor_dir = project_root / "mordor_dataset"
datasets_dir = mordor_dir / "datasets"
if not datasets_dir.exists():
print(f"[ERROR] mordor_dataset/datasets not found at {datasets_dir}")
sys.exit(1)
# Find all JSON files in the datasets directory
files = sorted([p for p in datasets_dir.rglob("*.json")])
if not files:
print("[ERROR] No JSON files found in mordor_dataset/datasets")
sys.exit(1)
print("=" * 80)
print("EXECUTING FULL PIPELINE ON ALL MORDOR FILES")
print("=" * 80)
print(f"Model: {model_name}")
print(f"Found {len(files)} files to process\n")
# Group files by folder
files_by_folder = {}
for f in files:
folder_name = f.parent.name
if folder_name not in files_by_folder:
files_by_folder[folder_name] = []
files_by_folder[folder_name].append(f)
# Process files
total_success = 0
total_failed = 0
for folder_name in sorted(files_by_folder.keys()):
folder_files = files_by_folder[folder_name]
print(f"\n{'='*80}")
print(f"Processing folder: {folder_name} ({len(folder_files)} files)")
print(f"{'='*80}")
for f in folder_files:
# Assume pipeline script is at src/scripts/run_simple_pipeline.py
pipeline_script = (
project_root / "src" / "scripts" / "run_simple_pipeline.py"
)
if not pipeline_script.exists():
print(f"[ERROR] Pipeline script not found: {pipeline_script}")
sys.exit(1)
# Set output directory to mordor_dataset/eval_output
output_dir = str(mordor_dir / "eval_output")
cmd = [
sys.executable,
str(pipeline_script),
str(f),
"--model",
model_name,
"--output-dir",
output_dir,
]
print(f"\n--- Processing: {f.relative_to(datasets_dir)}")
print(f" Model: {model_name}")
print(f" Output: {output_dir}")
try:
subprocess.run(cmd, check=True)
total_success += 1
except subprocess.CalledProcessError as e:
print(f"[ERROR] Pipeline failed for {f.name}: {e}")
total_failed += 1
# Summary
print("\n" + "=" * 80)
print("PIPELINE EXECUTION COMPLETE")
print("=" * 80)
print(f"Model used: {model_name}")
print(f"Total files processed: {len(files)}")
print(f"Successful: {total_success}")
print(f"Failed: {total_failed}")
print(f"Results saved to: {mordor_dir / 'eval_output'}/")
print("=" * 80 + "\n")
if __name__ == "__main__":
main() |