-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlaunch.py
More file actions
235 lines (205 loc) Β· 8.71 KB
/
Copy pathlaunch.py
File metadata and controls
235 lines (205 loc) Β· 8.71 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
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#!/usr/bin/env python3
"""
Quick launcher for the current Exercise 1-9 curriculum.
This launcher exposes only the workflows used by the reconfigured course.
"""
import os
import sys
import subprocess
def get_preferred_python():
"""Return venv Python when available, otherwise current interpreter."""
venv_python = r"c:\Users\jpayne\Documents\Training\Notebooks for ML classes\training-env\Scripts\python.exe"
return venv_python if os.path.exists(venv_python) else sys.executable
def safe_input(prompt: str):
"""Read input safely; return None when stdin is unavailable."""
try:
return input(prompt)
except EOFError:
return None
def pause_for_user(prompt: str = "\nPress Enter to return to menu..."):
"""Pause only when interactive input is available."""
if sys.stdin and sys.stdin.isatty():
safe_input(prompt)
def show_menu():
"""Show main menu."""
print("π§ͺ GenAI Testing Tutorial - Quick Launcher")
print("=" * 60)
print()
print("1. π§ͺ Run Regression Testing")
print(" Test against gold standards with quality gates")
print()
print("2. π Run Evaluation Framework")
print(" Metric definitions used in Exercise 3")
print()
print("3. π Run Retrieval Experiment")
print(" Optional tuning support for Exercise 4")
print()
print("4. π Start Flask Application")
print(" Launch the chat interface")
print()
print("5. π‘οΈ Run Section 7 NFR Quick-Run")
print(" Generate Exercise 7 evidence artifacts")
print()
print("6. π€ Run Section 9 Agentic CI Suite")
print(" Generate Exercise 9 gate artifacts")
print()
print("7. π Open Documentation")
print(" View comprehensive guides and documentation")
print()
print("0. Exit")
print()
def run_regression_testing():
"""Launch regression testing."""
print("π§ͺ Launching Regression Testing...")
python_exec = get_preferred_python()
if python_exec != sys.executable:
print("Using training-env virtual environment with tf-keras...")
try:
subprocess.run([python_exec, "-m", "regression_testing.regression_testing"], check=True)
except subprocess.CalledProcessError as e:
print(f"β Error running regression tests: {e}")
else:
try:
subprocess.run([python_exec, "-m", "regression_testing.regression_testing"], check=True)
except subprocess.CalledProcessError as e:
print(f"β Error running regression tests: {e}")
except FileNotFoundError:
print("β Python not found. Make sure Python is in your PATH.")
def run_evaluation_framework():
"""Run evaluation framework."""
print("π Running Evaluation Framework...")
python_exec = get_preferred_python()
try:
subprocess.run([python_exec, "tests/evaluation_framework.py"], check=True)
except subprocess.CalledProcessError as e:
print(f"β Error running evaluation framework: {e}")
except FileNotFoundError:
print("β Python not found. Make sure Python is in your PATH.")
def run_retrieval_experiment():
"""Run optional retrieval tuning experiment used by Exercise 4."""
print("π Running Retrieval Experiment...")
python_exec = get_preferred_python()
try:
subprocess.run([python_exec, "experiments/retrieval_experiments.py"], check=True)
except subprocess.CalledProcessError as e:
print(f"β Error running retrieval experiment: {e}")
except FileNotFoundError:
print("β Python not found. Make sure Python is in your PATH.")
def start_flask_app():
"""Start the Flask application."""
python_exec = get_preferred_python()
if python_exec != sys.executable:
print("Using training-env virtual environment...")
print("π Starting Flask Application...")
print("The chat interface will be available at: http://localhost:5000")
print("Press Ctrl+C to stop the server.")
try:
# Preflight dependency check so users get an actionable fix command.
dependency_check = subprocess.run(
[python_exec, "-c", "import flask, flask_cors"],
capture_output=True,
text=True,
)
if dependency_check.returncode != 0:
print("β Missing required Flask dependencies for this Python environment.")
print(f"Using Python: {python_exec}")
print("Install dependencies with:")
print(f" \"{python_exec}\" -m pip install -r requirements.txt")
return
subprocess.run([python_exec, "run.py"], check=True)
except subprocess.CalledProcessError as e:
print(f"β Error starting Flask app: {e}")
except KeyboardInterrupt:
print("\nπ Server stopped.")
except FileNotFoundError:
print("β Python not found. Make sure Python is in your PATH.")
def run_section7_quickrun():
"""Run Section 7 quick-run artifact generator."""
print("π‘οΈ Running Section 7 NFR Quick-Run...")
python_exec = get_preferred_python()
try:
subprocess.run([python_exec, "section7_nfr_quickrun.py"], check=True)
except subprocess.CalledProcessError as e:
print(f"β Error running Section 7 quick-run: {e}")
except FileNotFoundError:
print("β Python not found. Make sure Python is in your PATH.")
def run_section9_suite():
"""Run Section 9 agentic CI suite artifact generator."""
print("π€ Running Section 9 Agentic CI Suite...")
python_exec = get_preferred_python()
try:
subprocess.run([python_exec, "section9_agentic_test_suite.py"], check=True)
except subprocess.CalledProcessError as e:
print(f"β Error running Section 9 suite: {e}")
except FileNotFoundError:
print("β Python not found. Make sure Python is in your PATH.")
def open_documentation():
"""Show documentation options."""
print("π Available Documentation:")
print()
print("Main documentation files:")
print("β’ README.md - Main project overview (this directory)")
print("β’ docs/Exercise-1.md ... docs/Exercise-9.md - Student lab guides")
print("β’ docs/Exercise-1-Instructor-Notes.md ... Exercise-9-Instructor-Notes.md")
print("β’ docs/Section-Bridge-RAG-to-Agentic.md - Section transition deck text")
print()
print("Online documentation:")
print("β’ Open any .md file in a text editor or markdown viewer")
print("β’ Use VS Code or similar for best viewing experience")
# Try to open main README
doc_choice = (safe_input("Open main README.md? (y/n): ") or "n").strip().lower()
if doc_choice == 'y':
try:
if os.name == 'nt': # Windows
os.startfile("README.md")
elif os.name == 'posix': # macOS and Linux
subprocess.run(["open", "README.md"], check=True)
except Exception as e:
print(f"β Could not open README.md automatically: {e}")
print("Please open README.md in your preferred text editor.")
def main():
"""Main launcher."""
while True:
show_menu()
try:
raw_choice = safe_input("Select option (0-7): ")
if raw_choice is None:
print("\nπ Input stream closed. Exiting launcher.")
break
choice = raw_choice.strip()
if choice == "0":
print("π Happy testing! Remember to explore all the testing approaches!")
break
elif choice == "1":
run_regression_testing()
elif choice == "2":
run_evaluation_framework()
elif choice == "3":
run_retrieval_experiment()
elif choice == "4":
start_flask_app()
elif choice == "5":
run_section7_quickrun()
elif choice == "6":
run_section9_suite()
elif choice == "7":
open_documentation()
else:
print("β Invalid choice. Please select 0-7.")
if choice != "0" and choice != "6": # Don't pause after Flask app
pause_for_user("\nPress Enter to return to menu...")
print("\n" + "="*80)
except KeyboardInterrupt:
print("\n\nπ Launcher interrupted. Goodbye!")
break
except Exception as e:
print(f"\nβ Error: {str(e)}")
pause_for_user("Press Enter to continue...")
if __name__ == "__main__":
# Change to script directory
script_dir = os.path.dirname(os.path.abspath(__file__))
os.chdir(script_dir)
print("π§ GenAI Testing Tutorial Quick Launcher")
print("Working directory:", os.getcwd())
print()
main()