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