Spaces:
Sleeping
Sleeping
Melika Kheirieh
commited on
Commit
·
3954d57
1
Parent(s):
78914bb
feat(pipeline): auto-derive schema_preview when db_id is provided
Browse files- app/routers/nl2sql.py +11 -4
app/routers/nl2sql.py
CHANGED
|
@@ -295,6 +295,15 @@ async def upload_db(file: UploadFile = File(...)):
|
|
| 295 |
return {"db_id": db_id}
|
| 296 |
|
| 297 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 298 |
# -------------------------------
|
| 299 |
# Main NL2SQL endpoint
|
| 300 |
# -------------------------------
|
|
@@ -308,8 +317,8 @@ def nl2sql_handler(
|
|
| 308 |
while keeping all other stages from the YAML configs intact.
|
| 309 |
"""
|
| 310 |
db_id = getattr(request, "db_id", None)
|
| 311 |
-
|
| 312 |
-
cast(Optional[str], getattr(request, "schema_preview", None))
|
| 313 |
)
|
| 314 |
|
| 315 |
# Choose runner: default pipeline from YAML OR per-request override with a specific adapter
|
|
@@ -317,10 +326,8 @@ def nl2sql_handler(
|
|
| 317 |
adapter = _select_adapter(db_id)
|
| 318 |
pipeline = _build_pipeline(adapter)
|
| 319 |
runner = pipeline.run
|
| 320 |
-
final_preview = provided_preview # keep simple; derive only if you have a SQLite schema helper
|
| 321 |
else:
|
| 322 |
runner = run
|
| 323 |
-
final_preview = provided_preview or ""
|
| 324 |
|
| 325 |
# Execute pipeline
|
| 326 |
try:
|
|
|
|
| 295 |
return {"db_id": db_id}
|
| 296 |
|
| 297 |
|
| 298 |
+
def _final_schema_preview(db_id: Optional[str], provided_preview: Optional[str]) -> str:
|
| 299 |
+
if provided_preview and provided_preview.strip():
|
| 300 |
+
return provided_preview
|
| 301 |
+
if db_id:
|
| 302 |
+
adapter = _select_adapter(db_id)
|
| 303 |
+
return _derive_schema_preview(adapter) or ""
|
| 304 |
+
return ""
|
| 305 |
+
|
| 306 |
+
|
| 307 |
# -------------------------------
|
| 308 |
# Main NL2SQL endpoint
|
| 309 |
# -------------------------------
|
|
|
|
| 317 |
while keeping all other stages from the YAML configs intact.
|
| 318 |
"""
|
| 319 |
db_id = getattr(request, "db_id", None)
|
| 320 |
+
final_preview = _final_schema_preview(
|
| 321 |
+
db_id, cast(Optional[str], getattr(request, "schema_preview", None))
|
| 322 |
)
|
| 323 |
|
| 324 |
# Choose runner: default pipeline from YAML OR per-request override with a specific adapter
|
|
|
|
| 326 |
adapter = _select_adapter(db_id)
|
| 327 |
pipeline = _build_pipeline(adapter)
|
| 328 |
runner = pipeline.run
|
|
|
|
| 329 |
else:
|
| 330 |
runner = run
|
|
|
|
| 331 |
|
| 332 |
# Execute pipeline
|
| 333 |
try:
|