P-Karthik-Mohan commited on
Commit
a3583f9
Β·
1 Parent(s): d664e16

Update README for 8 tasks and final scores

Browse files
Files changed (1) hide show
  1. README.md +94 -41
README.md CHANGED
@@ -27,27 +27,60 @@ making it a meaningful benchmark for AI reasoning and code generation.
27
 
28
  ---
29
 
 
 
 
 
 
 
 
 
 
 
 
30
  ## Tasks
31
 
32
- Three tasks of increasing difficulty, each graded by an automated SQL result comparator.
33
 
34
  ### Task 1 β€” Easy
35
  **"How many completed orders were placed in 2024?"**
36
  - Requires: COUNT, WHERE, date filtering
37
- - Tests: basic aggregation and filtering
38
- - Expected output: single row, single column
39
 
40
  ### Task 2 β€” Medium
41
  **"Find the top 5 customers by total revenue from completed orders."**
42
  - Requires: JOIN, GROUP BY, SUM, ORDER BY, LIMIT
43
- - Tests: multi-table joins and aggregation
44
- - Expected output: 5 rows with first_name, last_name, total_revenue
45
 
46
  ### Task 3 β€” Hard
47
  **"Rank product categories by total revenue using a window function."**
48
- - Requires: CTE (WITH), JOIN, GROUP BY, RANK() OVER (...)
49
- - Tests: advanced SQL β€” CTEs and window functions
50
- - Expected output: all categories with total_revenue and revenue_rank
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
 
52
  ---
53
 
@@ -73,12 +106,12 @@ Response:
73
  "schema": "Tables:\n customers (...)\n products (...)\n orders (...)",
74
  "hint": "Use COUNT with WHERE filters on status and order_date"
75
  },
76
- "info": {"message": "Task 1 loaded. Use POST /step with your SQL query."}
77
  }
78
  ```
79
 
80
  ### POST /step
81
- Submit a SQL query. Returns reward and feedback.
82
 
83
  Request:
84
  ```json
@@ -105,6 +138,9 @@ Response:
105
  ### GET /state
106
  Get current session β€” task info, all attempts, best score.
107
 
 
 
 
108
  ---
109
 
110
  ## Observation Space
@@ -139,21 +175,25 @@ FROM orders o JOIN customers c ON o.customer_id = c.customer_id
139
  WHERE o.status = 'completed'
140
  GROUP BY o.customer_id ORDER BY total_revenue DESC LIMIT 5
141
 
142
- -- Hard
143
- WITH rev AS (
144
- SELECT p.category, SUM(o.total_amount) AS total_revenue
145
- FROM orders o JOIN products p ON o.product_id = p.product_id
146
- WHERE o.status = 'completed' GROUP BY p.category
147
  )
148
- SELECT category, total_revenue, RANK() OVER (ORDER BY total_revenue DESC) AS revenue_rank
149
- FROM rev ORDER BY revenue_rank ASC
 
 
 
150
  ```
151
 
152
  ---
153
 
154
  ## Reward Function
155
 
156
- Partial credit score from 0.0 to 1.0 with three components:
 
157
 
158
  | Component | Weight | How it is measured |
159
  |---|---|---|
@@ -161,9 +201,6 @@ Partial credit score from 0.0 to 1.0 with three components:
161
  | Row count | 0.30 | Ratio of returned rows vs expected rows |
162
  | Cell values | 0.40 | Fraction of cells matching expected values |
163
 
164
- Even an imperfect query receives meaningful feedback β€” not just pass/fail.
165
- This gives the agent a gradient signal to improve from.
166
-
167
  ---
168
 
169
  ## Database Schema
@@ -171,31 +208,34 @@ This gives the agent a gradient signal to improve from.
171
  A realistic e-commerce dataset with 600 orders, 100 customers, 30 products.
172
 
173
  ```
174
- customers (customer_id, first_name, last_name, email, city, signup_date)
175
- products (product_id, product_name, category, price, stock)
176
- orders (order_id, customer_id, product_id, quantity, total_amount, order_date, status)
177
  ```
178
 
179
  All orders are dated in 2024. Status values: completed, pending, cancelled.
 
180
 
181
  ---
182
 
183
  ## Running the Baseline Agent
184
 
185
  ```bash
186
- pip install openai requests
187
 
188
- export API_BASE_URL=https://api.openai.com/v1
189
- export MODEL_NAME=gpt-4o-mini
190
- export HF_TOKEN=your_api_key_here
191
 
192
  python inference.py
193
  ```
194
 
195
  Expected output:
196
  ```
197
- Tasks solved : 3 / 3
198
- Average reward : 1.000 / 1.000
 
 
199
  Results saved to results.json
200
  ```
201
 
@@ -224,10 +264,13 @@ docker run -p 7860:7860 sql-analyst-env
224
 
225
  ## Hardware Requirements
226
 
227
- - CPU: 1-2 vCPU
228
- - RAM: 8GB
229
- - GPU: Not required
230
- - Inference time: Under 5 minutes for all 3 tasks
 
 
 
231
 
232
  ---
233
 
@@ -235,12 +278,22 @@ docker run -p 7860:7860 sql-analyst-env
235
 
236
  ```
237
  sql-analyst-env/
238
- β”œβ”€β”€ main.py # FastAPI server
239
- β”œβ”€β”€ seed.py # Database seeder
240
- β”œβ”€β”€ inference.py # Baseline AI agent
241
- β”œβ”€β”€ openenv.yaml # OpenEnv specification
242
- β”œβ”€β”€ Dockerfile # Container for HF Spaces
243
  β”œβ”€β”€ requirements.txt # Python dependencies
244
  └── data/
245
- └── ecommerce.db # SQLite database
246
- ```
 
 
 
 
 
 
 
 
 
 
 
27
 
28
  ---
29
 
30
+ ## Baseline Agent Results
31
+
32
+ | Metric | Score |
33
+ |---|---|
34
+ | Tasks solved | 6 / 8 |
35
+ | Average reward | 0.985 / 1.000 |
36
+ | Model used | llama-3.1-8b-instant (Groq) |
37
+ | Time to complete | Under 3 minutes |
38
+
39
+ ---
40
+
41
  ## Tasks
42
 
43
+ Eight tasks of increasing difficulty, each graded by an automated SQL result comparator.
44
 
45
  ### Task 1 β€” Easy
46
  **"How many completed orders were placed in 2024?"**
47
  - Requires: COUNT, WHERE, date filtering
48
+ - Expected output: single row β€” total_orders
 
49
 
50
  ### Task 2 β€” Medium
51
  **"Find the top 5 customers by total revenue from completed orders."**
52
  - Requires: JOIN, GROUP BY, SUM, ORDER BY, LIMIT
53
+ - Expected output: 5 rows β€” first_name, last_name, total_revenue
 
54
 
55
  ### Task 3 β€” Hard
56
  **"Rank product categories by total revenue using a window function."**
57
+ - Requires: CTE, JOIN, GROUP BY, RANK() OVER (...)
58
+ - Expected output: all categories β€” category, total_revenue, revenue_rank
59
+
60
+ ### Task 4 β€” Medium
61
+ **"Find average product price per category, only for categories with more than 2 products."**
62
+ - Requires: GROUP BY, AVG, HAVING
63
+ - Expected output: category, avg_price
64
+
65
+ ### Task 5 β€” Hard
66
+ **"Find customers who ordered from both Electronics and Clothing categories."**
67
+ - Requires: INTERSECT, multiple JOINs
68
+ - Expected output: customer_id, first_name
69
+
70
+ ### Task 6 β€” Expert
71
+ **"Calculate month-over-month revenue growth % for 2024."**
72
+ - Requires: LAG() window function, CTE, STRFTIME
73
+ - Expected output: month, total_revenue, prev_revenue, growth_pct
74
+
75
+ ### Task 7 β€” Expert
76
+ **"For each city, find the best-selling product by quantity."**
77
+ - Requires: RANK() OVER (PARTITION BY city ...), CTE
78
+ - Expected output: city, product_name, total_quantity
79
+
80
+ ### Task 8 β€” Expert
81
+ **"Find customers who spent more in H2 2024 than H1 2024."**
82
+ - Requires: CASE WHEN, conditional SUM, HAVING
83
+ - Expected output: customer_id, first_name, last_name, h1_revenue, h2_revenue
84
 
85
  ---
86
 
 
106
  "schema": "Tables:\n customers (...)\n products (...)\n orders (...)",
107
  "hint": "Use COUNT with WHERE filters on status and order_date"
108
  },
109
+ "info": {"message": "Task 1 loaded."}
110
  }
111
  ```
112
 
113
  ### POST /step
114
+ Submit a SQL query. Returns reward 0.0-1.0 and feedback.
115
 
116
  Request:
117
  ```json
 
138
  ### GET /state
139
  Get current session β€” task info, all attempts, best score.
140
 
141
+ ### GET /health
142
+ Returns {"status": "ok", "db_exists": true} when server is ready.
143
+
144
  ---
145
 
146
  ## Observation Space
 
175
  WHERE o.status = 'completed'
176
  GROUP BY o.customer_id ORDER BY total_revenue DESC LIMIT 5
177
 
178
+ -- Expert
179
+ WITH monthly AS (
180
+ SELECT STRFTIME('%Y-%m', order_date) AS month, SUM(total_amount) AS total_revenue
181
+ FROM orders WHERE status = 'completed' AND order_date LIKE '2024%'
182
+ GROUP BY month
183
  )
184
+ SELECT month, total_revenue,
185
+ LAG(total_revenue) OVER (ORDER BY month) AS prev_revenue,
186
+ ROUND((total_revenue - LAG(total_revenue) OVER (ORDER BY month))
187
+ / LAG(total_revenue) OVER (ORDER BY month) * 100, 2) AS growth_pct
188
+ FROM monthly ORDER BY month ASC
189
  ```
190
 
191
  ---
192
 
193
  ## Reward Function
194
 
195
+ Partial credit score from 0.0 to 1.0 with three components.
196
+ Even an imperfect query receives meaningful feedback β€” not just pass/fail.
197
 
198
  | Component | Weight | How it is measured |
199
  |---|---|---|
 
201
  | Row count | 0.30 | Ratio of returned rows vs expected rows |
202
  | Cell values | 0.40 | Fraction of cells matching expected values |
203
 
 
 
 
204
  ---
205
 
206
  ## Database Schema
 
208
  A realistic e-commerce dataset with 600 orders, 100 customers, 30 products.
209
 
210
  ```
211
+ customers (customer_id, first_name, last_name, email, city, signup_date) β€” 100 rows
212
+ products (product_id, product_name, category, price, stock) β€” 30 rows
213
+ orders (order_id, customer_id, product_id, quantity, total_amount, order_date, status) β€” 600 rows
214
  ```
215
 
216
  All orders are dated in 2024. Status values: completed, pending, cancelled.
217
+ 10 product categories: Electronics, Clothing, Books, Home & Garden, Sports, Beauty, Toys, Food & Grocery, Automotive, Music.
218
 
219
  ---
220
 
221
  ## Running the Baseline Agent
222
 
223
  ```bash
224
+ pip install openai requests python-dotenv
225
 
226
+ export API_BASE_URL=https://api.groq.com/openai/v1
227
+ export MODEL_NAME=llama-3.1-8b-instant
228
+ export HF_TOKEN=your_groq_api_key_here
229
 
230
  python inference.py
231
  ```
232
 
233
  Expected output:
234
  ```
235
+ SQL Analyst OpenEnv β€” Baseline Inference Agent
236
+ Model : llama-3.1-8b-instant
237
+ Tasks solved : 6 / 8
238
+ Average reward : 0.985 / 1.000
239
  Results saved to results.json
240
  ```
241
 
 
264
 
265
  ## Hardware Requirements
266
 
267
+ | Resource | Requirement |
268
+ |---|---|
269
+ | CPU | 1-2 vCPU |
270
+ | RAM | 8GB |
271
+ | GPU | Not required |
272
+ | Disk | ~50MB |
273
+ | Inference time | Under 5 minutes for all 8 tasks |
274
 
275
  ---
276
 
 
278
 
279
  ```
280
  sql-analyst-env/
281
+ β”œβ”€β”€ main.py # FastAPI server β€” /reset, /step, /state endpoints
282
+ β”œβ”€β”€ seed.py # Database seeder β€” creates ecommerce.db
283
+ β”œβ”€β”€ inference.py # Baseline AI agent using OpenAI-compatible client
284
+ β”œβ”€β”€ openenv.yaml # OpenEnv specification file
285
+ β”œβ”€β”€ Dockerfile # Container for Hugging Face Spaces
286
  β”œβ”€β”€ requirements.txt # Python dependencies
287
  └── data/
288
+ └── ecommerce.db # SQLite database (auto-created by seed.py)
289
+ ```
290
+
291
+ ---
292
+
293
+ ## Built With
294
+
295
+ - FastAPI β€” REST API framework
296
+ - SQLite β€” embedded database, no setup required
297
+ - OpenAI Python client β€” compatible with Groq, Together, OpenAI
298
+ - Docker β€” containerized deployment
299
+ - Hugging Face Spaces β€” hosting