-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
executable file
·143 lines (114 loc) · 3.76 KB
/
Copy pathcli.py
File metadata and controls
executable file
·143 lines (114 loc) · 3.76 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
#!/usr/bin/env python3
"""
SynthGen Command Line Interface.
This module provides a command-line interface for the SynthGen tool,
allowing users to generate synthetic data for SQL Server schemas.
"""
import argparse
import json
import random
import sys
from pathlib import Path
from typing import Optional
from orchestrator import Orchestrator
def parse_args():
"""Parse command-line arguments.
Returns:
Parsed arguments namespace
"""
parser = argparse.ArgumentParser(
description="SynthGen: Generate realistic, constraint-valid synthetic data for SQL Server schemas",
formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
parser.add_argument(
"sql_script",
help="Path to the SQL Server CREATE script for the target schema"
)
parser.add_argument(
"ref_data_dir",
help="Directory containing reference data CSVs (one per lookup table)"
)
parser.add_argument(
"--rules", "-r",
help="Path to the Generation-Rules JSON document"
)
parser.add_argument(
"--artifacts-dir", "-a",
default="artifacts",
help="Directory to store artifacts and output files"
)
parser.add_argument(
"--run-id",
help="Unique identifier for this run (for reproducibility)"
)
parser.add_argument(
"--seed", "-s",
type=int,
help="Random seed for reproducible generation"
)
parser.add_argument(
"--llm-model",
default="gpt-4o",
help="Specific OpenAI model to use"
)
return parser.parse_args()
def main() -> int:
"""Main CLI entry point.
Returns:
Exit code (0 for success, non-zero for failure)
"""
args = parse_args()
# Validate input paths
sql_script_path = Path(args.sql_script)
if not sql_script_path.is_file():
print(f"Error: SQL script not found: {args.sql_script}", file=sys.stderr)
return 1
ref_data_dir = Path(args.ref_data_dir)
if not ref_data_dir.is_dir():
print(f"Error: Reference data directory not found: {args.ref_data_dir}", file=sys.stderr)
return 1
if args.rules:
rules_path = Path(args.rules)
if not rules_path.is_file():
print(f"Error: Rules file not found: {args.rules}", file=sys.stderr)
return 1
else:
rules_path = None
# Use provided seed or generate a random one
seed = args.seed
if seed is None:
seed = random.randint(1, 1_000_000)
print(f"Using random seed: {seed}")
# Create and run the orchestrator
orchestrator = Orchestrator(
sql_script_path=sql_script_path,
ref_data_dir=ref_data_dir,
rules_path=rules_path,
run_id=args.run_id,
artifacts_dir=args.artifacts_dir,
llm_provider="openai", # Only using OpenAI for PoC
llm_model=args.llm_model,
seed=seed
)
try:
# Save run metadata
orchestrator.save_run_metadata()
# Run the pipeline
result = orchestrator.run()
# Print summary
print("\nExecution Summary:")
print(f" Run ID: {result['run_id']}")
print(f" Execution time: {result['execution_time']:.2f} seconds")
print(f" Artifacts directory: {result['artifacts_dir']}")
if result.get("errors"):
print(f" Errors: {len(result['errors'])}")
return 1
else:
print(" Status: Success")
print(f" Validation result: {result.get('validation_result', 'unknown')}")
return 0
except Exception as e:
print(f"Error: {str(e)}", file=sys.stderr)
return 1
if __name__ == "__main__":
sys.exit(main())