Spaces:
Sleeping
Sleeping
Commit
·
3c698c1
1
Parent(s):
553e0dd
Test
Browse files
app.py
CHANGED
@@ -6,8 +6,7 @@ from huggingface_hub import InferenceClient
|
|
6 |
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
7 |
"""
|
8 |
hf_token = os.getenv("user_token")
|
9 |
-
|
10 |
-
client = InferenceClient("defog/llama-3-sqlcoder-8b", token=hf_token)
|
11 |
|
12 |
|
13 |
def respond(
|
@@ -18,67 +17,17 @@ def respond(
|
|
18 |
temperature,
|
19 |
top_p,
|
20 |
):
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
# CREATE TABLE products (
|
33 |
-
# product_id INTEGER PRIMARY KEY, -- Unique ID for each product
|
34 |
-
# name VARCHAR(50), -- Name of the product
|
35 |
-
# price DECIMAL(10,2), -- Price of each unit of the product
|
36 |
-
# quantity INTEGER -- Current quantity in stock
|
37 |
-
# );
|
38 |
-
|
39 |
-
# CREATE TABLE customers (
|
40 |
-
# customer_id INTEGER PRIMARY KEY, -- Unique ID for each customer
|
41 |
-
# name VARCHAR(50), -- Name of the customer
|
42 |
-
# address VARCHAR(100) -- Mailing address of the customer
|
43 |
-
# );
|
44 |
-
|
45 |
-
# CREATE TABLE salespeople (
|
46 |
-
# salesperson_id INTEGER PRIMARY KEY, -- Unique ID for each salesperson
|
47 |
-
# name VARCHAR(50), -- Name of the salesperson
|
48 |
-
# region VARCHAR(50) -- Geographic sales region
|
49 |
-
# );
|
50 |
-
|
51 |
-
# CREATE TABLE sales (
|
52 |
-
# sale_id INTEGER PRIMARY KEY, -- Unique ID for each sale
|
53 |
-
# product_id INTEGER, -- ID of product sold
|
54 |
-
# customer_id INTEGER, -- ID of customer who made purchase
|
55 |
-
# salesperson_id INTEGER, -- ID of salesperson who made the sale
|
56 |
-
# sale_date DATE, -- Date the sale occurred
|
57 |
-
# quantity INTEGER -- Quantity of product sold
|
58 |
-
# );
|
59 |
-
|
60 |
-
# CREATE TABLE product_suppliers (
|
61 |
-
# supplier_id INTEGER PRIMARY KEY, -- Unique ID for each supplier
|
62 |
-
# product_id INTEGER, -- Product ID supplied
|
63 |
-
# supply_price DECIMAL(10,2) -- Unit price charged by supplier
|
64 |
-
# );
|
65 |
-
|
66 |
-
# -- sales.product_id can be joined with products.product_id
|
67 |
-
# -- sales.customer_id can be joined with customers.customer_id
|
68 |
-
# -- sales.salesperson_id can be joined with salespeople.salesperson_id
|
69 |
-
# -- product_suppliers.product_id can be joined with products.product_id
|
70 |
-
|
71 |
-
# ### Response:
|
72 |
-
# Based on your instructions, here is the SQL query I have generated to answer the question `{question}`:
|
73 |
-
# ```sql
|
74 |
-
# """
|
75 |
-
|
76 |
-
sytems2= """
|
77 |
-
<|begin_of_text|><|start_header_id|>user<|end_header_id|>
|
78 |
-
|
79 |
-
Generate a SQL query to answer this question: `{question}`
|
80 |
-
|
81 |
-
DDL statements:
|
82 |
CREATE TABLE products (
|
83 |
product_id INTEGER PRIMARY KEY, -- Unique ID for each product
|
84 |
name VARCHAR(50), -- Name of the product
|
@@ -117,12 +66,13 @@ CREATE TABLE product_suppliers (
|
|
117 |
-- sales.customer_id can be joined with customers.customer_id
|
118 |
-- sales.salesperson_id can be joined with salespeople.salesperson_id
|
119 |
-- product_suppliers.product_id can be joined with products.product_id
|
120 |
-
<|eot_id|><|start_header_id|>assistant<|end_header_id|>
|
121 |
|
122 |
-
|
|
|
123 |
```sql
|
124 |
"""
|
125 |
-
|
|
|
126 |
|
127 |
for val in history:
|
128 |
if val[0]:
|
|
|
6 |
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
7 |
"""
|
8 |
hf_token = os.getenv("user_token")
|
9 |
+
client = InferenceClient("Qwen/Qwen2.5-Coder-3B-Instruct", token=hf_token)
|
|
|
10 |
|
11 |
|
12 |
def respond(
|
|
|
17 |
temperature,
|
18 |
top_p,
|
19 |
):
|
20 |
+
sytems = """
|
21 |
+
### Instructions:
|
22 |
+
Your task is to convert a question into a SQL query, given a Postgres database schema.
|
23 |
+
Adhere to these rules:
|
24 |
+
- **Deliberately go through the question and database schema word by word** to appropriately answer the question
|
25 |
+
- **Use Table Aliases** to prevent ambiguity. For example, `SELECT table1.col1, table2.col1 FROM table1 JOIN table2 ON table1.id = table2.id`.
|
26 |
+
- When creating a ratio, always cast the numerator as float
|
27 |
+
|
28 |
+
### Input:
|
29 |
+
Generate a SQL query that answers the question `{question}`.
|
30 |
+
This query will run on a database whose schema is represented in this string:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
CREATE TABLE products (
|
32 |
product_id INTEGER PRIMARY KEY, -- Unique ID for each product
|
33 |
name VARCHAR(50), -- Name of the product
|
|
|
66 |
-- sales.customer_id can be joined with customers.customer_id
|
67 |
-- sales.salesperson_id can be joined with salespeople.salesperson_id
|
68 |
-- product_suppliers.product_id can be joined with products.product_id
|
|
|
69 |
|
70 |
+
### Response:
|
71 |
+
Based on your instructions, here is the SQL query I have generated to answer the question `{question}`:
|
72 |
```sql
|
73 |
"""
|
74 |
+
|
75 |
+
messages = [{"role": "system", "content": sytems}]
|
76 |
|
77 |
for val in history:
|
78 |
if val[0]:
|