File size: 4,282 Bytes
223ef32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/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'

    if not mordor_dir.exists():
        print(f"[ERROR] mordor_dataset not found at {mordor_dir}")
        sys.exit(1)

    # Find all JSON files
    files = sorted([p for p in mordor_dir.rglob('*.json')])
    if not files:
        print("[ERROR] No JSON files found in mordor_dataset")
        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)
            
            cmd = [sys.executable, str(pipeline_script), str(f), "--model", model_name]
            print(f'\n--- Processing: {f.relative_to(mordor_dir)}')
            print(f'    Model: {model_name}')
            
            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: {project_root / 'final_response'}/")
    print('='*80 + '\n')


if __name__ == "__main__":
    main()