Spaces:
Running
Running
updated error message
Browse files- app.py +3 -3
- validate_sql.py +4 -5
app.py
CHANGED
@@ -6,7 +6,7 @@ import sys
|
|
6 |
|
7 |
PROMPT_TEMPLATE = """### Instruction:\n{instruction}\n\n### Input:\n{input}\n### Question:\n{question}\n\n### Response (use duckdb shorthand if possible):\n"""
|
8 |
INSTRUCTION_TEMPLATE = """Your task is to generate valid duckdb SQL to answer the following question{has_schema}""" # noqa: E501
|
9 |
-
ERROR_MESSAGE = ":red[ Quack! Much to our regret, SQL generation has gone a tad duck-side-down.\nThe model is currently not able to craft a correct SQL query for this request. \nSorry my duck friend. ]\n\n:red[
|
10 |
STOP_TOKENS = ["###", ";", "--", "```"]
|
11 |
|
12 |
|
@@ -66,8 +66,8 @@ def validate_sql(query, schema):
|
|
66 |
)
|
67 |
# Get output and potential parser, and binder error message
|
68 |
stdout, stderr = process.communicate(timeout=0.5)
|
69 |
-
if
|
70 |
-
return False,
|
71 |
return True, ""
|
72 |
except subprocess.TimeoutExpired:
|
73 |
process.kill()
|
|
|
6 |
|
7 |
PROMPT_TEMPLATE = """### Instruction:\n{instruction}\n\n### Input:\n{input}\n### Question:\n{question}\n\n### Response (use duckdb shorthand if possible):\n"""
|
8 |
INSTRUCTION_TEMPLATE = """Your task is to generate valid duckdb SQL to answer the following question{has_schema}""" # noqa: E501
|
9 |
+
ERROR_MESSAGE = ":red[ Quack! Much to our regret, SQL generation has gone a tad duck-side-down.\nThe model is currently not able to craft a correct SQL query for this request. \nSorry my duck friend. ]\n\n:red[If the question is about your own database, make sure to set the correct schema. Otherwise, try to rephrase your request. ]\n\n```sql\n{sql_query}\n```\n\n```sql\n{error_msg}\n```"
|
10 |
STOP_TOKENS = ["###", ";", "--", "```"]
|
11 |
|
12 |
|
|
|
66 |
)
|
67 |
# Get output and potential parser, and binder error message
|
68 |
stdout, stderr = process.communicate(timeout=0.5)
|
69 |
+
if stdout != "":
|
70 |
+
return False, stdout.decode('utf8')
|
71 |
return True, ""
|
72 |
except subprocess.TimeoutExpired:
|
73 |
process.kill()
|
validate_sql.py
CHANGED
@@ -5,7 +5,6 @@ from duckdb import ParserException, SyntaxException, BinderException, CatalogExc
|
|
5 |
|
6 |
def validate_query(query, schemas):
|
7 |
try:
|
8 |
-
print("Running query: ", query)
|
9 |
with duckdb.connect(
|
10 |
":memory:", config={"enable_external_access": False}
|
11 |
) as duckdb_conn:
|
@@ -15,14 +14,14 @@ def validate_query(query, schemas):
|
|
15 |
cursor = duckdb_conn.cursor()
|
16 |
cursor.execute(query)
|
17 |
except ParserException as e:
|
18 |
-
|
19 |
except SyntaxException as e:
|
20 |
-
|
21 |
except BinderException as e:
|
22 |
-
|
23 |
except CatalogException as e:
|
24 |
if not ("but it exists" in str(e) and "extension" in str(e)):
|
25 |
-
|
26 |
except Exception as e:
|
27 |
return True
|
28 |
return True
|
|
|
5 |
|
6 |
def validate_query(query, schemas):
|
7 |
try:
|
|
|
8 |
with duckdb.connect(
|
9 |
":memory:", config={"enable_external_access": False}
|
10 |
) as duckdb_conn:
|
|
|
14 |
cursor = duckdb_conn.cursor()
|
15 |
cursor.execute(query)
|
16 |
except ParserException as e:
|
17 |
+
print(str(e))
|
18 |
except SyntaxException as e:
|
19 |
+
print(str(e))
|
20 |
except BinderException as e:
|
21 |
+
print(str(e))
|
22 |
except CatalogException as e:
|
23 |
if not ("but it exists" in str(e) and "extension" in str(e)):
|
24 |
+
print(str(e))
|
25 |
except Exception as e:
|
26 |
return True
|
27 |
return True
|