Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,23 +8,25 @@ api = os.getenv("GROQ_API_KEY")
|
|
| 8 |
|
| 9 |
def create_prompt(user_query, table_metadata):
|
| 10 |
system_prompt = """
|
| 11 |
-
You are a SQL query generator
|
| 12 |
-
|
| 13 |
|
| 14 |
-
|
| 15 |
-
-
|
| 16 |
-
-
|
| 17 |
-
-
|
| 18 |
-
-
|
| 19 |
-
- Output
|
| 20 |
|
| 21 |
Input:
|
| 22 |
User Query: {user_query}
|
| 23 |
-
Table Metadata:
|
|
|
|
| 24 |
|
| 25 |
Output:
|
| 26 |
-
SQL
|
| 27 |
-
|
|
|
|
| 28 |
return system_prompt.strip(), f"User Query: {user_query}\nTable Metadata: {table_metadata}"
|
| 29 |
|
| 30 |
def generate_output(system_prompt, user_prompt):
|
|
|
|
| 8 |
|
| 9 |
def create_prompt(user_query, table_metadata):
|
| 10 |
system_prompt = """
|
| 11 |
+
You are a SQL query generator for a single relational table.
|
| 12 |
+
You must strictly follow the metadata and never guess or invent column names.
|
| 13 |
|
| 14 |
+
Instructions:
|
| 15 |
+
- Use only the table and columns listed in the metadata.
|
| 16 |
+
- Never generate queries with columns not present in the metadata.
|
| 17 |
+
- If a column like 'gender' is not present, do not mention it.
|
| 18 |
+
- Do not hallucinate values. Use provided structure only.
|
| 19 |
+
- Output valid SQL (DuckDB-compatible), single line, no comments or explanations.
|
| 20 |
|
| 21 |
Input:
|
| 22 |
User Query: {user_query}
|
| 23 |
+
Table Metadata:
|
| 24 |
+
{table_metadata}
|
| 25 |
|
| 26 |
Output:
|
| 27 |
+
A single valid SQL SELECT statement using only metadata-provided columns.
|
| 28 |
+
"""
|
| 29 |
+
|
| 30 |
return system_prompt.strip(), f"User Query: {user_query}\nTable Metadata: {table_metadata}"
|
| 31 |
|
| 32 |
def generate_output(system_prompt, user_prompt):
|