Melika Kheirieh commited on
Commit
f8b2087
·
1 Parent(s): d46c6fa

fix(adapter): add fallback lookup for uploaded DBs in /tmp/nl2sql_dbs

Browse files
adapters/llm/openai_provider.py CHANGED
@@ -148,6 +148,8 @@ CRITICAL RULES:
148
  7. Do not add unnecessary parentheses or formatting
149
  8. Match exact column and table names from the schema (case-sensitive)
150
  9. NEVER return empty SQL. If unsure, return the simplest valid SQL that answers the question.
 
 
151
 
152
  IMPORTANT:
153
  - For counting all rows: Use COUNT(*) not COUNT(column_name)
@@ -298,6 +300,8 @@ IMPORTANT RULES:
298
  3. Preserve the original intent of the query
299
  4. Follow SQLite syntax rules
300
  5. Don't add aliases or table prefixes unless necessary
 
 
301
 
302
  Return ONLY the corrected SQL query, nothing else."""
303
 
 
148
  7. Do not add unnecessary parentheses or formatting
149
  8. Match exact column and table names from the schema (case-sensitive)
150
  9. NEVER return empty SQL. If unsure, return the simplest valid SQL that answers the question.
151
+ 10. Use exact identifiers from `schema_preview` (case-insensitive match).
152
+ 11. Do NOT invent or pluralize table names. E.g., use `Artist`, not `artists`.
153
 
154
  IMPORTANT:
155
  - For counting all rows: Use COUNT(*) not COUNT(column_name)
 
300
  3. Preserve the original intent of the query
301
  4. Follow SQLite syntax rules
302
  5. Don't add aliases or table prefixes unless necessary
303
+ 6. Use exact identifiers from `schema_preview` (case-insensitive match).
304
+ 7. Do NOT invent or pluralize table names. E.g., use `Artist`, not `artists`.
305
 
306
  Return ONLY the corrected SQL query, nothing else."""
307
 
app/routers/nl2sql.py CHANGED
@@ -157,8 +157,15 @@ def _select_adapter(db_id: Optional[str]) -> Union[PostgresAdapter, SQLiteAdapte
157
  if db_id:
158
  cleanup_stale_dbs()
159
  path = get_db_path(db_id)
 
 
 
 
 
 
160
  if path and os.path.exists(path):
161
- return SQLiteAdapter(path)
 
162
  raise HTTPException(
163
  status_code=404, detail=f"db_id not found or expired: {db_id}"
164
  )
 
157
  if db_id:
158
  cleanup_stale_dbs()
159
  path = get_db_path(db_id)
160
+
161
+ if not path or not os.path.exists(path):
162
+ tmp_path = Path("/tmp/nl2sql_dbs") / f"{db_id}.sqlite"
163
+ if tmp_path.exists():
164
+ path = str(tmp_path)
165
+
166
  if path and os.path.exists(path):
167
+ return SQLiteAdapter(str(path))
168
+
169
  raise HTTPException(
170
  status_code=404, detail=f"db_id not found or expired: {db_id}"
171
  )