-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquery.py
More file actions
64 lines (52 loc) · 1.63 KB
/
query.py
File metadata and controls
64 lines (52 loc) · 1.63 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
#!/usr/bin/env python3
"""
Simple CLI wrapper for easy querying.
Usage: python query.py "Your natural language question"
"""
import os
from pathlib import Path
import subprocess
import sys
def main():
"""Simple wrapper for the CLI."""
if len(sys.argv) < 2:
print("Agent Pipeline Query Tool")
print("=" * 40)
print("Usage: python query.py '<your question>'")
print()
print("Examples:")
print(" python query.py 'Show all users'")
print(" python query.py 'Find employees with salary > 60000'")
print(" python query.py 'What departments do we have?'")
print(" python query.py 'Show average salary by department'")
print()
sys.exit(1)
# Get query from command line
query = " ".join(sys.argv[1:])
# Project root directory
project_dir = Path(__file__).parent
# Build command
cmd = [sys.executable, "-m", "agent_pipeline.cli.main", query]
print(f"Query: {query}")
print("Processing...")
print()
try:
# Run the CLI with proper environment
result = subprocess.run( # noqa: S603
cmd,
cwd=project_dir,
env={**dict(os.environ), "PYTHONPATH": str(project_dir / "src")},
timeout=120, # 2 minute timeout
)
sys.exit(result.returncode)
except subprocess.TimeoutExpired:
print("Query timed out after 2 minutes")
sys.exit(1)
except KeyboardInterrupt:
print("\nQuery cancelled")
sys.exit(1)
except Exception as e:
print(f"Error running query: {e}")
sys.exit(1)
if __name__ == "__main__":
main()