Update app.py
Browse files
app.py
CHANGED
|
@@ -89,23 +89,25 @@ if submitted:
|
|
| 89 |
client = OpenAI(api_key=api_key)
|
| 90 |
|
| 91 |
# System prompt with schema
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
|
|
|
|
|
|
| 109 |
response = client.chat.completions.create(
|
| 110 |
model="gpt-4o",
|
| 111 |
messages=[
|
|
@@ -115,8 +117,10 @@ if submitted:
|
|
| 115 |
temperature=0.3
|
| 116 |
)
|
| 117 |
|
|
|
|
| 118 |
sql_query = response.choices[0].message.content.strip()
|
| 119 |
-
|
|
|
|
| 120 |
# Execute and display results
|
| 121 |
with sqlite3.connect('database.db') as conn:
|
| 122 |
cursor = conn.cursor()
|
|
|
|
| 89 |
client = OpenAI(api_key=api_key)
|
| 90 |
|
| 91 |
# System prompt with schema
|
| 92 |
+
system_context = """You are a SQL expert. Given these SQL tables:
|
| 93 |
+
CREATE TABLE Produkte (
|
| 94 |
+
ProduktID INTEGER PRIMARY KEY,
|
| 95 |
+
Produktname TEXT NOT NULL,
|
| 96 |
+
Preis REAL NOT NULL
|
| 97 |
+
);
|
| 98 |
+
CREATE TABLE Bestellungen (
|
| 99 |
+
BestellungID INTEGER PRIMARY KEY,
|
| 100 |
+
ProduktID INTEGER,
|
| 101 |
+
Menge INTEGER,
|
| 102 |
+
Bestelldatum TEXT,
|
| 103 |
+
Person TEXT,
|
| 104 |
+
FOREIGN KEY (ProduktID) REFERENCES Produkte(ProduktID)
|
| 105 |
+
);
|
| 106 |
+
Generate ONLY the raw SQL query for the user's request.
|
| 107 |
+
NEVER use markdown code blocks or any formatting.
|
| 108 |
+
ONLY output the pure SQL statement."""
|
| 109 |
+
|
| 110 |
+
# Generate SQL query
|
| 111 |
response = client.chat.completions.create(
|
| 112 |
model="gpt-4o",
|
| 113 |
messages=[
|
|
|
|
| 117 |
temperature=0.3
|
| 118 |
)
|
| 119 |
|
| 120 |
+
# Clean up the response
|
| 121 |
sql_query = response.choices[0].message.content.strip()
|
| 122 |
+
sql_query = sql_query.replace("```sql", "").replace("```", "").strip() # Add this line
|
| 123 |
+
|
| 124 |
# Execute and display results
|
| 125 |
with sqlite3.connect('database.db') as conn:
|
| 126 |
cursor = conn.cursor()
|