Spaces:
Running
Running
VladGeekPro Copilot commited on
Commit ·
92ce1cc
1
Parent(s): 8759264
ChangedModelForQueryGeneration
Browse filesCo-authored-by: Copilot <copilot@github.com>
- sql_generator.py +9 -9
sql_generator.py
CHANGED
|
@@ -96,7 +96,7 @@ def _get_sql_generator() -> Any:
|
|
| 96 |
if _SQL_GENERATOR is None:
|
| 97 |
from transformers import pipeline
|
| 98 |
|
| 99 |
-
model_id = os.getenv("SQL_MODEL", "
|
| 100 |
_SQL_GENERATOR = pipeline(
|
| 101 |
task="text2text-generation",
|
| 102 |
model=model_id,
|
|
@@ -109,14 +109,13 @@ def _get_sql_generator() -> Any:
|
|
| 109 |
|
| 110 |
def _build_prompt(payload: SqlGenerationRequest) -> str:
|
| 111 |
return (
|
| 112 |
-
"
|
| 113 |
-
"Return only SQL
|
| 114 |
-
"Use only
|
| 115 |
-
"Never generate
|
| 116 |
-
"
|
| 117 |
-
f"
|
| 118 |
-
f"
|
| 119 |
-
f"User request:\n{payload.question}\n\n"
|
| 120 |
"SQL:"
|
| 121 |
)
|
| 122 |
|
|
@@ -171,6 +170,7 @@ def generate_sql(question: str, limit: int = 200) -> str:
|
|
| 171 |
prompt,
|
| 172 |
max_new_tokens=256,
|
| 173 |
do_sample=False,
|
|
|
|
| 174 |
truncation=True,
|
| 175 |
)
|
| 176 |
|
|
|
|
| 96 |
if _SQL_GENERATOR is None:
|
| 97 |
from transformers import pipeline
|
| 98 |
|
| 99 |
+
model_id = os.getenv("SQL_MODEL", "gaussalgo/T5-LM-Large-text2sql-spider")
|
| 100 |
_SQL_GENERATOR = pipeline(
|
| 101 |
task="text2text-generation",
|
| 102 |
model=model_id,
|
|
|
|
| 109 |
|
| 110 |
def _build_prompt(payload: SqlGenerationRequest) -> str:
|
| 111 |
return (
|
| 112 |
+
"Task: generate one SQLite SQL query for the question. "
|
| 113 |
+
"Return only SQL, no markdown and no explanation. "
|
| 114 |
+
"Use only schema objects provided below. "
|
| 115 |
+
"Never generate non-SELECT statements.\n\n"
|
| 116 |
+
f"Question: {payload.question}\n"
|
| 117 |
+
f"Schema: {DEFAULT_DB_SCHEMA}\n"
|
| 118 |
+
f"Constraints: output must start with SELECT; apply LIMIT {payload.limit} when not aggregate.\n"
|
|
|
|
| 119 |
"SQL:"
|
| 120 |
)
|
| 121 |
|
|
|
|
| 170 |
prompt,
|
| 171 |
max_new_tokens=256,
|
| 172 |
do_sample=False,
|
| 173 |
+
num_beams=4,
|
| 174 |
truncation=True,
|
| 175 |
)
|
| 176 |
|