File size: 3,549 Bytes
778d47d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Updated fixed SQL data saved to ../data/multi-agents/fixed/gpt-4o-mini-validator-fixer-bird_with_evidence_train.jsonl\n"
     ]
    }
   ],
   "source": [
    "import json\n",
    "from copy import deepcopy\n",
    "\n",
    "# File paths\n",
    "fixed_sql_bird_file = '../data/multi-agents/fixed/gpt-4o-mini-fixed-bird_with_evidence_train.jsonl'\n",
    "validator_select_file = '../data/multi-agents/validator/gpt-4o-mini-validator_select_bird_with_evidence_train.jsonl'\n",
    "validator_condition_file = '../data/multi-agents/validator/gpt-4o-mini-validator_condition_bird_with_evidence_train.jsonl'\n",
    "validator_join_file = '../data/multi-agents/validator/gpt-4o-mini-validator_join_bird_with_evidence_train.jsonl'\n",
    "\n",
    "# Function to load JSONL files\n",
    "def load_jsonl(file_path):\n",
    "    data = []\n",
    "    with open(file_path, 'r', encoding='utf-8') as file:\n",
    "        for line in file:\n",
    "            data.append(json.loads(line))\n",
    "    return data\n",
    "\n",
    "# Load all datasets\n",
    "fixed_sql_bird_data = load_jsonl(fixed_sql_bird_file)\n",
    "validator_select_data = load_jsonl(validator_select_file)\n",
    "validator_condition_data = load_jsonl(validator_condition_file)\n",
    "validator_join_data = load_jsonl(validator_join_file)\n",
    "\n",
    "# Process and add valid samples\n",
    "for sample_select, sample_condition, sample_join in zip(validator_select_data, validator_condition_data, validator_join_data):\n",
    "\n",
    "    # Extract correctness feedback\n",
    "    select_correct = sample_select.get('feedback_conclude')\n",
    "    condition_correct = sample_condition.get('feedback_conclude')\n",
    "    join_correct = sample_join.get('feedback_conclude')\n",
    "\n",
    "    # If all are correct, add a new sample to fixed_sql_bird_data\n",
    "    if select_correct and condition_correct and join_correct:\n",
    "        new_sample = deepcopy(sample_select)\n",
    "        new_sample = {\n",
    "            \"validator_select\": sample_select,\n",
    "            \"validator_condition\": sample_condition['validator_condition'],\n",
    "            \"validator_join\": sample_join['validator_join'],\n",
    "            \"fixed_sql\": [\"None\"]  # Empty list as per instructions\n",
    "        }\n",
    "        fixed_sql_bird_data.append(new_sample)\n",
    "\n",
    "# Save the updated fixed SQL data\n",
    "output_file = '../data/multi-agents/fixed/gpt-4o-mini-validator-fixer-bird_with_evidence_train.jsonl'\n",
    "with open(output_file, 'w', encoding='utf-8') as file:\n",
    "    for entry in fixed_sql_bird_data:\n",
    "        file.write(json.dumps(entry, ensure_ascii=False) + '\\n')\n",
    "\n",
    "print(f\"Updated fixed SQL data saved to {output_file}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "handbook",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.14"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}