Sync latest fixes
Browse files
benchmarks/text2sql/benchmark_text2sql.py
CHANGED
|
@@ -144,10 +144,11 @@ def compute_schema_metrics(results: List[Text2SQLResult], golden_path: str) -> d
|
|
| 144 |
|
| 145 |
|
| 146 |
class Text2SQLBenchmark:
|
| 147 |
-
def __init__(self, api_key: str, embedding_model: str = "openai-small", llm_model: str = "gpt-4o-mini"):
|
| 148 |
self.api_key = api_key
|
| 149 |
self.embedding_model = embedding_model
|
| 150 |
self.llm_model = llm_model
|
|
|
|
| 151 |
os.environ["OPENAI_API_KEY"] = api_key
|
| 152 |
os.environ["OPENAI_API_BASE"] = "https://api.openai.com/v1"
|
| 153 |
|
|
@@ -179,7 +180,7 @@ class Text2SQLBenchmark:
|
|
| 179 |
print_progress(i + 1, total, "Progress")
|
| 180 |
|
| 181 |
# Auto-build KG if schema summary exists (generates from .sqlite if needed)
|
| 182 |
-
if not kg_exists(db):
|
| 183 |
from src.text2sql.runner import ensure_db_summary
|
| 184 |
schema_path = ensure_db_summary(db) or get_schema_path(db)
|
| 185 |
if not schema_path:
|
|
@@ -315,6 +316,10 @@ async def main():
|
|
| 315 |
parser.add_argument("--benchmark", type=str, default="spider2-lite",
|
| 316 |
choices=["spider2-lite", "bird"],
|
| 317 |
help="Benchmark dataset (default: spider2-lite)")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 318 |
|
| 319 |
args = parser.parse_args()
|
| 320 |
|
|
@@ -323,7 +328,7 @@ async def main():
|
|
| 323 |
print("ERROR: Set OPENAI_API_KEY environment variable")
|
| 324 |
return
|
| 325 |
|
| 326 |
-
benchmark = Text2SQLBenchmark(api_key, args.embedding, args.llm)
|
| 327 |
|
| 328 |
jsonl_files = {
|
| 329 |
"spider2-lite": QAFD_RAG_HOME / "data" / "text2sql" / "spider2-lite" / "spider2-lite.jsonl",
|
|
|
|
| 144 |
|
| 145 |
|
| 146 |
class Text2SQLBenchmark:
|
| 147 |
+
def __init__(self, api_key: str, embedding_model: str = "openai-small", llm_model: str = "gpt-4o-mini", force_build: bool = False):
|
| 148 |
self.api_key = api_key
|
| 149 |
self.embedding_model = embedding_model
|
| 150 |
self.llm_model = llm_model
|
| 151 |
+
self.force_build = force_build
|
| 152 |
os.environ["OPENAI_API_KEY"] = api_key
|
| 153 |
os.environ["OPENAI_API_BASE"] = "https://api.openai.com/v1"
|
| 154 |
|
|
|
|
| 180 |
print_progress(i + 1, total, "Progress")
|
| 181 |
|
| 182 |
# Auto-build KG if schema summary exists (generates from .sqlite if needed)
|
| 183 |
+
if self.force_build or not kg_exists(db):
|
| 184 |
from src.text2sql.runner import ensure_db_summary
|
| 185 |
schema_path = ensure_db_summary(db) or get_schema_path(db)
|
| 186 |
if not schema_path:
|
|
|
|
| 316 |
parser.add_argument("--benchmark", type=str, default="spider2-lite",
|
| 317 |
choices=["spider2-lite", "bird"],
|
| 318 |
help="Benchmark dataset (default: spider2-lite)")
|
| 319 |
+
parser.add_argument("--force-build", action="store_true",
|
| 320 |
+
help="Force rebuild KG even if it exists")
|
| 321 |
+
parser.add_argument("--build", action="store_true",
|
| 322 |
+
help="Build KG only, don't run benchmark")
|
| 323 |
|
| 324 |
args = parser.parse_args()
|
| 325 |
|
|
|
|
| 328 |
print("ERROR: Set OPENAI_API_KEY environment variable")
|
| 329 |
return
|
| 330 |
|
| 331 |
+
benchmark = Text2SQLBenchmark(api_key, args.embedding, args.llm, force_build=args.force_build)
|
| 332 |
|
| 333 |
jsonl_files = {
|
| 334 |
"spider2-lite": QAFD_RAG_HOME / "data" / "text2sql" / "spider2-lite" / "spider2-lite.jsonl",
|