-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanage.py
More file actions
49 lines (38 loc) · 1.43 KB
/
Copy pathmanage.py
File metadata and controls
49 lines (38 loc) · 1.43 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
from __future__ import annotations
import argparse
import json
from ai_sql_analyst.config import settings
from ai_sql_analyst.services.database import active_backend, execute_query, initialize_database
from ai_sql_analyst.services.evaluation import run_eval_suite
def init_db() -> None:
initialize_database()
columns, rows = execute_query("SELECT COUNT(*) AS customer_count FROM customers")
print(
json.dumps(
{
"backend": active_backend(),
"database": settings.postgres_dsn if active_backend() == "postgres" else str(settings.db_path),
"columns": columns,
"rows": rows,
},
indent=2,
)
)
def run_evals() -> None:
initialize_database()
result = run_eval_suite(workspace_id="demo")
print(json.dumps(result.model_dump(), indent=2))
if result.failed:
raise SystemExit(1)
def main() -> None:
parser = argparse.ArgumentParser(description="AI SQL Analyst management commands")
subcommands = parser.add_subparsers(dest="command", required=True)
subcommands.add_parser("init-db", help="Apply migrations and seed the configured database")
subcommands.add_parser("evals", help="Run the text-to-SQL evaluation suite")
args = parser.parse_args()
if args.command == "init-db":
init_db()
elif args.command == "evals":
run_evals()
if __name__ == "__main__":
main()