Adhishtanaka commited on
Commit
dfb2f93
·
verified ·
1 Parent(s): 609ec5d

Delete Evaluate_LLM.ipynb

Browse files
Files changed (1) hide show
  1. Evaluate_LLM.ipynb +0 -650
Evaluate_LLM.ipynb DELETED
@@ -1,650 +0,0 @@
1
- {
2
- "cells": [
3
- {
4
- "cell_type": "code",
5
- "execution_count": 18,
6
- "metadata": {
7
- "colab": {
8
- "base_uri": "https://localhost:8080/"
9
- },
10
- "id": "al2rU2WkVIWX",
11
- "outputId": "4a8eee5c-4ba5-4a5f-f956-589a0692e175"
12
- },
13
- "outputs": [
14
- {
15
- "name": "stdout",
16
- "output_type": "stream",
17
- "text": [
18
- "Drive already mounted at /content/drive; to attempt to forcibly remount, call drive.mount(\"/content/drive\", force_remount=True).\n",
19
- "✅ Model folder found at: /content/drive/MyDrive/Model1Folder\n",
20
- "✅ All files copied to: /content/hi/hi\n"
21
- ]
22
- }
23
- ],
24
- "source": [
25
- "import os\n",
26
- "import shutil\n",
27
- "from google.colab import drive\n",
28
- "\n",
29
- "# Mount Google Drive\n",
30
- "drive.mount('/content/drive')\n",
31
- "\n",
32
- "# Paths\n",
33
- "DRIVE_MODEL_FOLDER = \"/content/drive/MyDrive/Model1Folder\"\n",
34
- "LOCAL_WORK_FOLDER = \"/content/hi\"\n",
35
- "model_folder = os.path.join(LOCAL_WORK_FOLDER, \"hi\")\n",
36
- "\n",
37
- "# Create destination folder\n",
38
- "os.makedirs(model_folder, exist_ok=True)\n",
39
- "\n",
40
- "# Copy model files if available\n",
41
- "if not os.path.exists(DRIVE_MODEL_FOLDER):\n",
42
- " print(f\"❌ Model folder not found at: {DRIVE_MODEL_FOLDER}\")\n",
43
- "else:\n",
44
- " print(f\"✅ Model folder found at: {DRIVE_MODEL_FOLDER}\")\n",
45
- " for filename in os.listdir(DRIVE_MODEL_FOLDER):\n",
46
- " shutil.copy2(os.path.join(DRIVE_MODEL_FOLDER, filename), os.path.join(model_folder, filename))\n",
47
- " print(f\"✅ All files copied to: {model_folder}\")\n"
48
- ]
49
- },
50
- {
51
- "cell_type": "code",
52
- "execution_count": null,
53
- "metadata": {
54
- "colab": {
55
- "base_uri": "https://localhost:8080/"
56
- },
57
- "id": "bs52onDScqSm",
58
- "outputId": "8e1c2f29-928a-4220-cf63-a8dd4402bbd8"
59
- },
60
- "outputs": [
61
- {
62
- "name": "stdout",
63
- "output_type": "stream",
64
- "text": [
65
- "Loading llama-cpp model from: /content/hi/hi/unsloth.Q4_K_M.gguf\n"
66
- ]
67
- },
68
- {
69
- "name": "stderr",
70
- "output_type": "stream",
71
- "text": [
72
- "llama_context: n_ctx_per_seq (2048) < n_ctx_train (131072) -- the full capacity of the model will not be utilized\n",
73
- "llama_kv_cache_unified: LLAMA_SET_ROWS=0, using old ggml_cpy() method for backwards compatibility\n"
74
- ]
75
- },
76
- {
77
- "name": "stdout",
78
- "output_type": "stream",
79
- "text": [
80
- "Generating SQL questions...\n",
81
- "\n",
82
- "Generated 10 questions.\n",
83
- "\n",
84
- "Running LLaMA on question 1 / 10\n",
85
- "Running LLaMA on question 2 / 10\n",
86
- "Running LLaMA on question 3 / 10\n",
87
- "Running LLaMA on question 4 / 10\n",
88
- "Running LLaMA on question 5 / 10\n",
89
- "Running LLaMA on question 6 / 10\n",
90
- "Running LLaMA on question 7 / 10\n",
91
- "Running LLaMA on question 8 / 10\n",
92
- "Running LLaMA on question 9 / 10\n",
93
- "Running LLaMA on question 10 / 10\n",
94
- "Evaluating answer 1 with Groq\n",
95
- "Evaluating answer 2 with Groq\n",
96
- "Evaluating answer 3 with Groq\n",
97
- "Evaluating answer 4 with Groq\n",
98
- "Evaluating answer 5 with Groq\n",
99
- "Evaluating answer 6 with Groq\n",
100
- "Evaluating answer 7 with Groq\n",
101
- "Evaluating answer 8 with Groq\n",
102
- "Evaluating answer 9 with Groq\n",
103
- "Evaluating answer 10 with Groq\n",
104
- "\n",
105
- "=== Summary ===\n",
106
- "Average Score: 6.5/10\n",
107
- "Average Percentage: 65.0%\n",
108
- "\n",
109
- "\n",
110
- "=== Detailed Results ===\n",
111
- "\n",
112
- "--- QA Pair 1 ---\n",
113
- "Question:\n",
114
- " CREATE TABLE Orders (OrderID INT, CustomerID INT, OrderDate DATE);\n",
115
- "INSERT INTO Orders (OrderID, CustomerID, OrderDate) VALUES (1, 101, '2021-01-01'), (2, 102, '2021-01-15');\n",
116
- "Answer:\n",
117
- " SELECT * FROM Orders;\n",
118
- "\n",
119
- "This SQL query retrieves all the records from the Orders table, including the OrderID, CustomerID, and OrderDate columns.\n",
120
- "Evaluation:\n",
121
- " The answer is **correct** and **partially complete**. \n",
122
- "\n",
123
- "**Rating: 7/10**\n",
124
- "\n",
125
- "**Explanation:**\n",
126
- "\n",
127
- "* **Correctness:** The SQL query `SELECT * FROM Orders;` is syntactically correct and will accurately retrieve all data from the `Orders` table.\n",
128
- "* **Completeness:** While the query itself is correct, it lacks context. A good response would also:\n",
129
- "\n",
130
- " * **Explain the purpose:** State that the query is used to display all orders stored in the table.\n",
131
- " * **Show the output:** Include a sample of the expected output based on the inserted data.\n",
132
- " * **Discuss alternatives:** Mention that `SELECT` can be used with specific column names for more controlled output (e.g., `SELECT OrderID, OrderDate FROM Orders`).\n",
133
- "\n",
134
- "\n",
135
- "Let me know if you'd like a more comprehensive explanation or have other SQL queries you'd like help with!\n",
136
- "Score: 7/10 (70%)\n",
137
- "\n",
138
- "\n",
139
- "--- QA Pair 2 ---\n",
140
- "Question:\n",
141
- " How do I find the total number of orders made by each customer?\n",
142
- "Answer:\n",
143
- " To find the total number of orders made by each customer, you can use the GROUP BY and SUM function in SQL or the GROUP BY and COUNT function in SQL Server.\n",
144
- "\n",
145
- "For SQL:\n",
146
- "\n",
147
- "```sql\n",
148
- "SELECT customer_name, SUM(orders) as total_orders\n",
149
- "FROM orders\n",
150
- "GROUP BY customer_name;\n",
151
- "```\n",
152
- "\n",
153
- "For SQL Server:\n",
154
- "\n",
155
- "```sql\n",
156
- "SELECT customer_name, SUM(orders) as total_orders\n",
157
- "FROM orders\n",
158
- "GROUP BY customer_name;\n",
159
- "```\n",
160
- "\n",
161
- "This query will calculate the total number of orders made by each customer by summing the orders for each customer.\n",
162
- "Evaluation:\n",
163
- " The answer is partially correct but incomplete. \n",
164
- "\n",
165
- "Here's a breakdown and rating:\n",
166
- "\n",
167
- "**Rating: 6/10**\n",
168
- "\n",
169
- "**Strengths:**\n",
170
- "\n",
171
- "* **Correct SQL Structure:** The provided SQL query structure is generally correct for achieving the desired outcome. Using `GROUP BY customer_name` and `SUM(orders)` or `COUNT(orders)` is the appropriate approach.\n",
172
- "\n",
173
- "**Weaknesses:**\n",
174
- "\n",
175
- "* **Assumptions:** The answer assumes the table is named \"orders\" and has columns named \"customer_name\" and \"orders\". Real-world database schemas can vary greatly. \n",
176
- "* **Missing Clarification on 'orders' Column:** It's unclear what the \"orders\" column represents. \n",
177
- " * Does it store a numerical count of orders per customer?\n",
178
- " * Does it contain order IDs? \n",
179
- " * Is it a date/timestamp representing the order date?\n",
180
- "* **No SQL Server Distinction:** While the SQL code for SQL and SQL Server is identical in this case, for more complex scenarios, there might be subtle syntax differences. \n",
181
- "\n",
182
- "**Improvements:**\n",
183
- "\n",
184
- "1. **Replace Placeholder Names:** Replace \"orders\" and \"customer_name\" with actual column names from the target database.\n",
185
- "2. **Explain \"orders\" Column:** Clearly state what the \"orders\" column represents to avoid ambiguity. \n",
186
- "3. **Provide Alternative Using COUNT:** Explicitly mention that `COUNT(orders)` can be used instead of `SUM(orders)` if the \"orders\" column contains individual order IDs.\n",
187
- "4. **Highlight Potential Variations:** Briefly note that SQL syntax might have minor differences across various database systems.\n",
188
- "\n",
189
- "\n",
190
- "\n",
191
- "Let me know if you'd like a more tailored example based on a specific database schema!\n",
192
- "Score: 6/10 (60%)\n",
193
- "\n",
194
- "\n",
195
- "--- QA Pair 3 ---\n",
196
- "Question:\n",
197
- " --------------------------------------------------------\n",
198
- "Answer:\n",
199
- " It seems like you're starting to write a story or scenario. Can you tell me a bit more about what's happening? What's the main plot or conflict?\n",
200
- "Evaluation:\n",
201
- " The answer provided is **not relevant** to the given context. \n",
202
- "\n",
203
- "**Rating: 1/10**\n",
204
- "\n",
205
- "**Explanation:**\n",
206
- "\n",
207
- "The prompt requests information about SQL, specifically asking for help with a SQL query. Instead of addressing the query, the AI diverts the conversation to story writing, asking for a plot or conflict. This is a significant misinterpretation of the user's intent. \n",
208
- "\n",
209
- "\n",
210
- "Let me know if you have a specific SQL query you'd like help with, and I'll be happy to assist!\n",
211
- "Score: 1/10 (10%)\n",
212
- "\n",
213
- "\n",
214
- "--- QA Pair 4 ---\n",
215
- "Question:\n",
216
- " CREATE TABLE Employees (EmployeeID INT, DepartmentID INT, Salary INT);\n",
217
- "INSERT INTO Employees (EmployeeID, DepartmentID, Salary) VALUES (1, 101, 50000), (2, 101, 60000), (3, 102, 70000);\n",
218
- "Answer:\n",
219
- " CREATE TABLE Employees (EmployeeID INT, DepartmentID INT, Salary INT);\n",
220
- "INSERT INTO Employees (EmployeeID, DepartmentID, Salary) VALUES (1, 101, 50000), (2, 101, 60000), (3, 102, 70000);\n",
221
- "\n",
222
- "This SQL query creates a new table named \"Employees\" and inserts three rows into it with the specified employee ID, department ID, and salary.\n",
223
- "Evaluation:\n",
224
- " The answer is **correct and complete**. It accurately reflects the provided SQL statements. \n",
225
- "\n",
226
- "**Rating: 10/10**\n",
227
- "\n",
228
- "**Explanation:**\n",
229
- "\n",
230
- "* **CREATE TABLE ...:** This statement correctly defines the structure of the \"Employees\" table with three columns: EmployeeID (integer), DepartmentID (integer), and Salary (integer).\n",
231
- "* **INSERT INTO ... VALUES ...:** This statement correctly inserts three rows of data into the \"Employees\" table. Each row has the specified EmployeeID, DepartmentID, and Salary values.\n",
232
- "\n",
233
- "The answer clearly explains what the SQL code does, making it helpful for learning purposes. \n",
234
- "\n",
235
- "\n",
236
- "Let me know if you have any other SQL queries you'd like me to evaluate!\n",
237
- "Score: 10/10 (100%)\n",
238
- "\n",
239
- "\n",
240
- "--- QA Pair 5 ---\n",
241
- "Question:\n",
242
- " How do I find the average salary of employees in department 102?\n",
243
- "Answer:\n",
244
- " To find the average salary of employees in department 102, you can use the following steps:\n",
245
- "\n",
246
- "1. Identify the department number: In this scenario, the department number is 102.\n",
247
- "2. Collect the data: You need to collect the salary data of employees in the department 102.\n",
248
- "3. Perform calculations: Once you have the data, you need to perform the necessary calculations to find the average salary.\n",
249
- "4. Output the result: You need to output the average salary to the user.\n",
250
- "\n",
251
- "Here's a sample code in SQL to find the average salary of employees in department 102:\n",
252
- "\n",
253
- "```sql\n",
254
- "SELECT department_number, AVG(salary) as average_salary\n",
255
- "FROM employees\n",
256
- "WHERE department_number = 102\n",
257
- "GROUP BY department_number;\n",
258
- "```\n",
259
- "\n",
260
- "This SQL query performs the following steps:\n",
261
- "\n",
262
- "- Selects the department number and calculates the average salary of employees in the department 102.\n",
263
- "- Filters the data to include only employees with the department number 102.\n",
264
- "- Groups the data by the department number and calculates the average salary for each group.\n",
265
- "\n",
266
- "By running this query, you can get the average salary of employees in department 102.\n",
267
- "Evaluation:\n",
268
- " The answer is **8/10**. \n",
269
- "\n",
270
- "**Here's why:**\n",
271
- "\n",
272
- "* **Correctness:** The SQL query provided is accurate and will effectively calculate the average salary of employees in department 102. \n",
273
- "* **Completeness:** \n",
274
- " * The explanation of the query's steps is clear and helpful.\n",
275
- " * It accurately describes the purpose of each clause (SELECT, WHERE, GROUP BY, AVG). \n",
276
- " * **Minor Improvement:** It could be more explicit about why `GROUP BY department_number` is necessary to get a single average for each department.\n",
277
- "\n",
278
- "* **Clarity:** The language is easy to understand, making it suitable for a beginner. \n",
279
- "\n",
280
- "**Suggestions for improvement:**\n",
281
- "\n",
282
- "* **Elaborate on `GROUP BY`:** Explain that without `GROUP BY`, the AVG() function would calculate the average salary of *all* employees, not just those in department 102. \n",
283
- "\n",
284
- "\n",
285
- "Let me know if you'd like more detailed explanations on any specific aspect of the SQL query!\n",
286
- "Score: 8/10 (80%)\n",
287
- "\n",
288
- "\n",
289
- "--- QA Pair 6 ---\n",
290
- "Question:\n",
291
- " --------------------------------------------------------\n",
292
- "Answer:\n",
293
- " It seems you've started a new message, but it doesn't appear to be related to the problem or question you're trying to ask. \n",
294
- "\n",
295
- "Could you please provide more context or clarify what you're trying to achieve or ask about? I'll do my best to assist you.\n",
296
- "Evaluation:\n",
297
- " The answer is a **7/10**. \n",
298
- "\n",
299
- "Here's why:\n",
300
- "\n",
301
- "* **Correctness:** The answer is factually correct. It acknowledges that there is no provided question and politely requests clarification.\n",
302
- "* **Completeness:** While it's polite and accurate, it could be improved by offering a few suggestions on how the user could rephrase their request. For example, it could say something like:\n",
303
- "\n",
304
- " \"To help me understand, could you please:\n",
305
- "\n",
306
- " * **Rephrase your question:** \n",
307
- " * **Tell me what you're trying to accomplish:** \n",
308
- " * **Share any relevant code or database schema:**\"\n",
309
- "\n",
310
- "This provides more guidance and makes it easier for the user to get the help they need. \n",
311
- "\n",
312
- "\n",
313
- "* **Tone:** The tone is helpful and encouraging.\n",
314
- "Score: 7/10 (70%)\n",
315
- "\n",
316
- "\n",
317
- "--- QA Pair 7 ---\n",
318
- "Question:\n",
319
- " CREATE TABLE Cars (CarID INT, Color VARCHAR(20), Year INT);\n",
320
- "INSERT INTO Cars (CarID, Color, Year) VALUES (1, 'Blue', 2010), (2, 'Red', 2015), (3, 'Blue', 2018);\n",
321
- "Answer:\n",
322
- " INSERT INTO Cars (CarID, Color, Year) VALUES (1, 'Blue', 2010), (2, 'Red', 2015), (3, 'Blue', 2018);\n",
323
- "\n",
324
- "This SQL query inserts three records into the Cars table, each with a unique CarID, a specified Color, and a corresponding Year.\n",
325
- "Evaluation:\n",
326
- " The answer is **7/10**. \n",
327
- "\n",
328
- "Here's why:\n",
329
- "\n",
330
- "* **Correctness:** The SQL code provided is syntactically correct and will successfully insert the specified data into the `Cars` table. \n",
331
- "* **Completeness:** \n",
332
- "\n",
333
- "The answer only shows the `INSERT` statement. A more complete and helpful response would include:\n",
334
- "\n",
335
- "* **Explanation of the `CREATE TABLE` statement:** This statement defines the structure of the `Cars` table with columns for `CarID`, `Color`, and `Year`. \n",
336
- "* **Understanding of Data Types:** Mentioning the data types for each column (e.g., `INT` for `CarID` and `Year`, `VARCHAR(20)` for `Color`).\n",
337
- "* **Practical Explanation:**\n",
338
- " Instead of just stating the code works, explain what each part of the `INSERT` statement does:\n",
339
- " * `INSERT INTO Cars`: Specifies the target table.\n",
340
- " * `(CarID, Color, Year)`: Lists the columns where data will be inserted.\n",
341
- " * `VALUES (1, 'Blue', 2010)`: Provides the data values for the first row, and so on.\n",
342
- "\n",
343
- "**An improved response:**\n",
344
- "\n",
345
- "```sql\n",
346
- "-- Create the Cars table\n",
347
- "CREATE TABLE Cars (\n",
348
- " CarID INT, \n",
349
- " Color VARCHAR(20), \n",
350
- " Year INT\n",
351
- ");\n",
352
- "\n",
353
- "-- Insert three car records into the table \n",
354
- "INSERT INTO Cars (CarID, Color, Year) \n",
355
- "VALUES \n",
356
- " (1, 'Blue', 2010), \n",
357
- " (2, 'Red', 2015), \n",
358
- " (3, 'Blue', 2018);\n",
359
- "```\n",
360
- "\n",
361
- "This response provides a better understanding of the code's purpose and functionality.\n",
362
- "Score: 7/10 (70%)\n",
363
- "\n",
364
- "\n",
365
- "--- QA Pair 8 ---\n",
366
- "Question:\n",
367
- " How do I find the number of cars of each color?\n",
368
- "Answer:\n",
369
- " To find the number of cars of each color, you can use the following steps:\n",
370
- "\n",
371
- "1. Collect car data: You'll need access to a database or a dataset that contains information about the number of cars of different colors.\n",
372
- "2. Identify the data: Once you have the data, identify the columns that contain information about the color of each car.\n",
373
- "3. Filter the data: Filter the data to include only the columns that contain the color information (e.g., 'color' or 'color_code').\n",
374
- "4. Group the data: Group the data by the color column(s) to get the number of cars for each color.\n",
375
- "5. Calculate the sum: Calculate the sum of the number of cars for each color to get the final answer.\n",
376
- "\n",
377
- "Example SQL query to find the number of cars of each color:\n",
378
- "```sql\n",
379
- "SELECT color, COUNT(*) as num_cars\n",
380
- "FROM cars\n",
381
- "GROUP BY color;\n",
382
- "```\n",
383
- "This query groups the data by the 'color' column and calculates the sum of the 'num_cars' column to get the number of cars for each color.\n",
384
- "\n",
385
- "Example using Python and pandas library:\n",
386
- "```python\n",
387
- "import pandas as pd\n",
388
- "\n",
389
- "# Load the data\n",
390
- "data = pd.read_csv('cars.csv')\n",
391
- "\n",
392
- "# Identify the data\n",
393
- "color_data = data[['\n",
394
- "Evaluation:\n",
395
- " The answer is mostly correct and provides a good general approach. \n",
396
- "\n",
397
- "**Rating: 8/10**\n",
398
- "\n",
399
- "**Here's why:**\n",
400
- "\n",
401
- "* **Strengths:**\n",
402
- " * Clearly outlines the steps involved in finding the car count by color.\n",
403
- " * Provides a valid SQL query example and a Python example using pandas.\n",
404
- " * Explains the concepts of grouping and counting in a straightforward manner.\n",
405
- "* **Weaknesses:**\n",
406
- " * The Python example is incomplete. It starts to show how to load data but doesn't finish the query to count cars by color. \n",
407
- " * It assumes the dataset has a column named 'color'. A more robust answer would mention that the column name might vary depending on the dataset. \n",
408
- "\n",
409
- "**Suggestions for Improvement:**\n",
410
- "\n",
411
- "* Complete the Python example to demonstrate the full process.\n",
412
- "* Add a note about how the column name might differ in different datasets and encourage the user to inspect their data.\n",
413
- "* Briefly mention alternative methods like using a `WHERE` clause to filter by color if the focus is on specific colors rather than all of them.\n",
414
- "\n",
415
- "\n",
416
- "\n",
417
- "Let me know if you'd like the complete Python example!\n",
418
- "Score: 8/10 (80%)\n",
419
- "\n",
420
- "\n",
421
- "--- QA Pair 9 ---\n",
422
- "Question:\n",
423
- " --------------------------------------------------------\n",
424
- "Answer:\n",
425
- " It appears you're using a formatting style similar to Markdown, a lightweight markup language. However, I couldn't find a standard for its usage.\n",
426
- "Evaluation:\n",
427
- " The answer is **2/10**.\n",
428
- "\n",
429
- "Here's why:\n",
430
- "\n",
431
- "* **Incorrect:** The response doesn't actually address the core of the user's request. The user asks a question expecting an SQL-related answer. The response focuses on the formatting style itself instead. \n",
432
- "* **Unhelpful:** While identifying the formatting style is technically correct, it doesn't provide any value to the user who is seeking help with SQL.\n",
433
- "\n",
434
- "**To be a good SQL tutor, the response should:**\n",
435
- "\n",
436
- "1. **Understand the SQL context:** Recognize that the user is likely asking about SQL syntax or concepts.\n",
437
- "2. **Provide a direct answer:** Address the specific SQL question in the prompt, offering code examples, explanations, or guidance where applicable.\n",
438
- "3. **Be helpful and informative:** Guide the user towards a better understanding of SQL. \n",
439
- "\n",
440
- "\n",
441
- "Let me know if you'd like me to provide a helpful SQL answer based on a specific SQL question. I'm here to help!\n",
442
- "Score: 2/10 (20%)\n",
443
- "\n",
444
- "\n",
445
- "--- QA Pair 10 ---\n",
446
- "Question:\n",
447
- " CREATE TABLE Customers (CustomerID INT, Email VARCHAR(50));\n",
448
- "INSERT INTO Customers (CustomerID, Email) VALUES (101, '[email protected]'), (102, '[email protected]'), (103, '[email protected]');\n",
449
- "Answer:\n",
450
- " CREATE TABLE Customers (\n",
451
- " CustomerID INT,\n",
452
- " Email VARCHAR(50)\n",
453
- ");\n",
454
- "\n",
455
- "INSERT INTO Customers (CustomerID, Email) VALUES (101, '[email protected]'), (102, '[email protected]'), (103, '[email protected]');\n",
456
- "\n",
457
- "The query creates a table named 'Customers' with two columns: 'CustomerID' and 'Email'. It then inserts three records into the 'Customers' table with the given 'CustomerID' and 'Email' values.\n",
458
- "Evaluation:\n",
459
- " The answer is **9/10**.\n",
460
- "\n",
461
- "**Correctness:**\n",
462
- "\n",
463
- "* The SQL statements for creating the table and inserting data are syntactically correct.\n",
464
- "* **Data types:** The answer correctly identifies `INT` for `CustomerID` and `VARCHAR(50)` for `Email`.\n",
465
- "\n",
466
- "* **Values:** The inserted values are also correct.\n",
467
- "\n",
468
- "**Completeness:**\n",
469
- "\n",
470
- "* **Schema Explanations (minor missing point):** A brief explanation of what each column represents would be beneficial. For example:\n",
471
- "\n",
472
- " ```sql\n",
473
- " CREATE TABLE Customers (\n",
474
- " CustomerID INT, -- Unique identifier for each customer\n",
475
- " Email VARCHAR(50) -- Email address of the customer\n",
476
- " ); \n",
477
- " ```\n",
478
- "\n",
479
- "\n",
480
- "**Overall:** The answer is very good. It accurately provides the SQL code and a basic understanding of what the code does. Adding a little more context about the column meanings would make it even stronger.\n",
481
- "Score: 9/10 (90%)\n",
482
- "\n",
483
- "\n"
484
- ]
485
- }
486
- ],
487
- "source": [
488
- "# Install dependencies\n",
489
- "!pip install llama-cpp-python groq --quiet\n",
490
- "\n",
491
- "import os\n",
492
- "import re\n",
493
- "from groq import Groq\n",
494
- "from llama_cpp import Llama\n",
495
- "\n",
496
- "# === Configuration ===\n",
497
- "# Replace with your own Groq API key\n",
498
- "client = Groq(api_key=\"\")\n",
499
- "\n",
500
- "# Local model path\n",
501
- "LOCAL_WORK_FOLDER = \"/content/hi/hi\"\n",
502
- "MODEL_FILENAME = \"unsloth.Q4_K_M.gguf\"\n",
503
- "MODEL_PATH = f\"{LOCAL_WORK_FOLDER}/{MODEL_FILENAME}\"\n",
504
- "\n",
505
- "# === Load LLaMA model ===\n",
506
- "print(f\"Loading llama-cpp model from: {MODEL_PATH}\")\n",
507
- "llm = Llama(\n",
508
- " model_path=MODEL_PATH,\n",
509
- " n_ctx=2048,\n",
510
- " n_threads=8,\n",
511
- " n_gpu_layers=0,\n",
512
- " verbose=False,\n",
513
- ")\n",
514
- "\n",
515
- "# === Generate SQL Questions ===\n",
516
- "def generate_sql_questions_groq(num=10):\n",
517
- " prompt = f\"\"\"\n",
518
- "Generate exactly {num} *distinct* SQL questions. Each should consist of:\n",
519
- "- SQL table creation\n",
520
- "- Some INSERT statements\n",
521
- "- A final SQL-related question\n",
522
- "\n",
523
- "📌 Format each as a single block, like:\n",
524
- "\n",
525
- "CREATE TABLE Students (Name VARCHAR(50), Marks INT);\n",
526
- "INSERT INTO Students (Name, Marks) VALUES ('Alice', 85), ('Bob', 90);\n",
527
- "How do I find the average marks of all students?\n",
528
- "\n",
529
- "Separate each block with two newlines.\n",
530
- "Do NOT generate more than {num} questions.\n",
531
- "Only output the questions — no explanation.\n",
532
- "\"\"\"\n",
533
- " chat_completion = client.chat.completions.create(\n",
534
- " model=\"llama3-8b-8192\",\n",
535
- " messages=[{\"role\": \"user\", \"content\": prompt}],\n",
536
- " )\n",
537
- " raw_output = chat_completion.choices[0].message.content.strip()\n",
538
- "\n",
539
- " # Post-process: limit to `num` questions max\n",
540
- " all_questions = [p.strip() for p in raw_output.split(\"\\n\\n\") if p.strip()]\n",
541
- " trimmed = all_questions[:num]\n",
542
- " return \"\\n\\n\".join(trimmed)\n",
543
- "\n",
544
- "\n",
545
- "# === Get Answers from LLaMA ===\n",
546
- "def get_llama_answers(questions):\n",
547
- " answers = []\n",
548
- " if llm is None:\n",
549
- " print(\"LLaMA model not loaded. Skipping answer generation.\")\n",
550
- " return answers\n",
551
- "\n",
552
- " for i, message in enumerate(questions):\n",
553
- " print(f\"Running LLaMA on question {i+1} / {len(questions)}\")\n",
554
- " response = llm.create_chat_completion(\n",
555
- " messages=[message],\n",
556
- " temperature=0.7,\n",
557
- " max_tokens=256,\n",
558
- " stop=[\"</s>\"]\n",
559
- " )\n",
560
- " ans = response[\"choices\"][0][\"message\"][\"content\"]\n",
561
- " answers.append({\"question\": message[\"content\"], \"answer\": ans})\n",
562
- " return answers\n",
563
- "\n",
564
- "# === Evaluate Answers using Groq ===\n",
565
- "def evaluate_answers_groq(qa_pairs):\n",
566
- " evaluations = []\n",
567
- " total_score = 0\n",
568
- "\n",
569
- " for i, qa in enumerate(qa_pairs):\n",
570
- " print(f\"Evaluating answer {i+1} with Groq\")\n",
571
- " eval_prompt = f\"\"\"\n",
572
- "You are an expert SQL tutor.\n",
573
- "\n",
574
- "Question:\n",
575
- "{qa['question']}\n",
576
- "\n",
577
- "Answer:\n",
578
- "{qa['answer']}\n",
579
- "\n",
580
- "Evaluate the correctness and completeness of the answer.\n",
581
- "Rate it 1 to 10 and provide a brief explanation.\n",
582
- "\"\"\"\n",
583
- " chat_completion = client.chat.completions.create(\n",
584
- " model=\"gemma2-9b-it\",\n",
585
- " messages=[{\"role\": \"user\", \"content\": eval_prompt}],\n",
586
- " )\n",
587
- " evaluation_text = chat_completion.choices[0].message.content.strip()\n",
588
- "\n",
589
- " # Extract score (1 to 10) using regex\n",
590
- " score_match = re.search(r'\\b([1-9]|10)\\b', evaluation_text)\n",
591
- " score = int(score_match.group(1)) if score_match else 0\n",
592
- " total_score += score\n",
593
- "\n",
594
- " evaluations.append({\n",
595
- " \"question\": qa[\"question\"],\n",
596
- " \"answer\": qa[\"answer\"],\n",
597
- " \"evaluation\": evaluation_text,\n",
598
- " \"score\": score,\n",
599
- " \"percentage\": round(score * 10, 1)\n",
600
- " })\n",
601
- "\n",
602
- " avg_score = round(total_score / len(qa_pairs), 2)\n",
603
- " avg_percentage = round(avg_score * 10, 2)\n",
604
- "\n",
605
- " print(f\"\\n=== Summary ===\")\n",
606
- " print(f\"Average Score: {avg_score}/10\")\n",
607
- " print(f\"Average Percentage: {avg_percentage}%\")\n",
608
- "\n",
609
- " return evaluations\n",
610
- "\n",
611
- "# === Main Pipeline ===\n",
612
- "if llm:\n",
613
- " print(\"Generating SQL questions...\")\n",
614
- " questions_text = generate_sql_questions_groq(10)\n",
615
- " questions = parse_questions(questions_text)\n",
616
- "\n",
617
- " print(f\"\\nGenerated {len(questions)} questions.\\n\")\n",
618
- "\n",
619
- " answers = get_llama_answers(questions)\n",
620
- "\n",
621
- " if answers:\n",
622
- " evaluations = evaluate_answers_groq(answers)\n",
623
- "\n",
624
- " print(\"\\n\\n=== Detailed Results ===\\n\")\n",
625
- " for i, res in enumerate(evaluations):\n",
626
- " print(f\"--- QA Pair {i+1} ---\")\n",
627
- " print(\"Question:\\n\", res[\"question\"])\n",
628
- " print(\"Answer:\\n\", res[\"answer\"])\n",
629
- " print(\"Evaluation:\\n\", res[\"evaluation\"])\n",
630
- " print(f\"Score: {res['score']}/10 ({res['percentage']}%)\\n\\n\")\n",
631
- "else:\n",
632
- " print(\"LLaMA model not loaded. Cannot proceed.\")\n"
633
- ]
634
- }
635
- ],
636
- "metadata": {
637
- "colab": {
638
- "provenance": []
639
- },
640
- "kernelspec": {
641
- "display_name": "Python 3",
642
- "name": "python3"
643
- },
644
- "language_info": {
645
- "name": "python"
646
- }
647
- },
648
- "nbformat": 4,
649
- "nbformat_minor": 0
650
- }