Spaces:
Sleeping
Sleeping
Commit
·
8f0a267
1
Parent(s):
0f85b1c
Test
Browse files
app.py
CHANGED
@@ -16,7 +16,62 @@ def respond(
|
|
16 |
temperature,
|
17 |
top_p,
|
18 |
):
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
for val in history:
|
22 |
if val[0]:
|
|
|
16 |
temperature,
|
17 |
top_p,
|
18 |
):
|
19 |
+
sytems = """
|
20 |
+
### Instructions:
|
21 |
+
Your task is to convert a question into a SQL query, given a Postgres database schema.
|
22 |
+
Adhere to these rules:
|
23 |
+
- **Deliberately go through the question and database schema word by word** to appropriately answer the question
|
24 |
+
- **Use Table Aliases** to prevent ambiguity. For example, `SELECT table1.col1, table2.col1 FROM table1 JOIN table2 ON table1.id = table2.id`.
|
25 |
+
- When creating a ratio, always cast the numerator as float
|
26 |
+
|
27 |
+
### Input:
|
28 |
+
Generate a SQL query that answers the question `{question}`.
|
29 |
+
This query will run on a database whose schema is represented in this string:
|
30 |
+
CREATE TABLE products (
|
31 |
+
product_id INTEGER PRIMARY KEY, -- Unique ID for each product
|
32 |
+
name VARCHAR(50), -- Name of the product
|
33 |
+
price DECIMAL(10,2), -- Price of each unit of the product
|
34 |
+
quantity INTEGER -- Current quantity in stock
|
35 |
+
);
|
36 |
+
|
37 |
+
CREATE TABLE customers (
|
38 |
+
customer_id INTEGER PRIMARY KEY, -- Unique ID for each customer
|
39 |
+
name VARCHAR(50), -- Name of the customer
|
40 |
+
address VARCHAR(100) -- Mailing address of the customer
|
41 |
+
);
|
42 |
+
|
43 |
+
CREATE TABLE salespeople (
|
44 |
+
salesperson_id INTEGER PRIMARY KEY, -- Unique ID for each salesperson
|
45 |
+
name VARCHAR(50), -- Name of the salesperson
|
46 |
+
region VARCHAR(50) -- Geographic sales region
|
47 |
+
);
|
48 |
+
|
49 |
+
CREATE TABLE sales (
|
50 |
+
sale_id INTEGER PRIMARY KEY, -- Unique ID for each sale
|
51 |
+
product_id INTEGER, -- ID of product sold
|
52 |
+
customer_id INTEGER, -- ID of customer who made purchase
|
53 |
+
salesperson_id INTEGER, -- ID of salesperson who made the sale
|
54 |
+
sale_date DATE, -- Date the sale occurred
|
55 |
+
quantity INTEGER -- Quantity of product sold
|
56 |
+
);
|
57 |
+
|
58 |
+
CREATE TABLE product_suppliers (
|
59 |
+
supplier_id INTEGER PRIMARY KEY, -- Unique ID for each supplier
|
60 |
+
product_id INTEGER, -- Product ID supplied
|
61 |
+
supply_price DECIMAL(10,2) -- Unit price charged by supplier
|
62 |
+
);
|
63 |
+
|
64 |
+
-- sales.product_id can be joined with products.product_id
|
65 |
+
-- sales.customer_id can be joined with customers.customer_id
|
66 |
+
-- sales.salesperson_id can be joined with salespeople.salesperson_id
|
67 |
+
-- product_suppliers.product_id can be joined with products.product_id
|
68 |
+
|
69 |
+
### Response:
|
70 |
+
Based on your instructions, here is the SQL query I have generated to answer the question `{question}`:
|
71 |
+
```sql
|
72 |
+
"""
|
73 |
+
|
74 |
+
messages = [{"role": "system", "content": sytems}]
|
75 |
|
76 |
for val in history:
|
77 |
if val[0]:
|