File size: 9,600 Bytes
bb44b5c
 
e684577
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a3d6ea6
 
 
 
 
 
e684577
 
a3d6ea6
 
 
 
e684577
 
 
a3d6ea6
e684577
bb44b5c
 
 
a3d6ea6
 
bb44b5c
 
 
 
 
 
 
 
 
 
 
 
a3d6ea6
bb44b5c
 
 
 
a3d6ea6
 
bb44b5c
 
 
 
 
 
 
 
 
 
 
a3d6ea6
bb44b5c
 
 
a3d6ea6
bb44b5c
 
a3d6ea6
 
 
 
 
 
bb44b5c
 
 
a3d6ea6
 
 
 
 
 
 
 
 
 
 
 
 
bb44b5c
 
 
 
a3d6ea6
 
bb44b5c
 
 
 
 
 
 
 
 
a3d6ea6
 
 
 
 
 
 
 
 
 
bb44b5c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a3d6ea6
bb44b5c
 
 
 
a3d6ea6
bb44b5c
 
a3d6ea6
 
 
 
 
 
bb44b5c
 
 
a3d6ea6
 
 
 
 
 
 
 
 
 
bb44b5c
 
 
 
a3d6ea6
 
bb44b5c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a3d6ea6
bb44b5c
 
a3d6ea6
 
 
 
 
 
bb44b5c
 
 
 
 
e684577
a3d6ea6
 
 
 
 
 
 
 
 
 
bb44b5c
 
a3d6ea6
 
 
 
 
 
bb44b5c
 
e684577
a3d6ea6
 
 
 
 
 
 
 
 
 
bb44b5c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
{
 "cells": [
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": [
    "### How to run\n",
    "\n",
    "* Install libraries using the cell below (for grazie-api-gateway-client you will have to add a custom JB repository)\n",
    "* Put the production prompt to file `data/prod_prompt.txt`\n",
    "* Environment variables:\n",
    "    - `GRAZIE_API_JWT_TOKEN` -- JWT token for grazie (check `api_wrappers/grazie_wrapper.py` to adjust the client initialization if necessary)\n",
    "    - `HF_TOKEN` -- should _not_ be required; however, if it is, set it to a valid Hugging Face token"
   ],
   "id": "77d51d55b41735cf"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-06-20T16:09:07.968406Z",
     "start_time": "2024-06-20T16:09:07.955405Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# !pip install grazie-api-gateway-client\n",
    "# !pip install tqdm\n",
    "# !pip install pandas\n",
    "# !pip install datasets"
   ],
   "id": "91fa273e8987f6f6",
   "outputs": [],
   "execution_count": 1
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-06-20T16:09:10.353479Z",
     "start_time": "2024-06-20T16:09:07.970405Z"
    }
   },
   "cell_type": "code",
   "source": [
    "from api_wrappers.grazie_wrapper import generate_for_prompt\n",
    "from api_wrappers.hf_data_loader import load_full_commit_with_predictions_as_pandas\n",
    "from tqdm import tqdm\n",
    "\n",
    "tqdm.pandas()"
   ],
   "id": "ce11a4c781c152e",
   "outputs": [],
   "execution_count": 2
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-06-20T16:09:10.368996Z",
     "start_time": "2024-06-20T16:09:10.354434Z"
    }
   },
   "cell_type": "code",
   "source": [
    "with open(\"data/prod_prompt.txt\") as f:\n",
    "\tPROD_PROMPT = f.read().strip()\n",
    "\n",
    "def prod_prompt(diff):\n",
    "\treturn PROD_PROMPT.replace(\"$diff\", diff).replace(\"$text\", \"\")\n",
    "\n",
    "def generate_commit_message_prod(diff):\n",
    "\treturn generate_for_prompt(prod_prompt(diff))"
   ],
   "id": "84a769c8765a7b64",
   "outputs": [],
   "execution_count": 3
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-06-20T16:09:10.384590Z",
     "start_time": "2024-06-20T16:09:10.371410Z"
    }
   },
   "cell_type": "code",
   "source": "generate_commit_message_prod(\"TEST\")",
   "id": "af2f20def94b0490",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"Certainly! I'll need to see the specific code differences (diffs) you would like to have summarized into a commit message. Please provide the diffs so I can assist you properly.\""
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 4
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-06-20T16:09:22.224167Z",
     "start_time": "2024-06-20T16:09:10.388409Z"
    }
   },
   "cell_type": "code",
   "source": [
    "DATA = load_full_commit_with_predictions_as_pandas()[[\"mods\", \"prediction\"]].rename(columns={\"mods\": \"diff\", \"prediction\": \"prediction_current\"})\n",
    "DATA.head()"
   ],
   "id": "a49cabf576c9d692",
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Using the latest cached version of the dataset since JetBrains-Research/lca-commit-message-generation couldn't be found on the Hugging Face Hub\n",
      "Found the latest cached dataset configuration 'commitchronicle-py-long' at cache\\JetBrains-Research___lca-commit-message-generation\\commitchronicle-py-long\\0.0.0\\58dcef83a63cccebacd3e786afd73181cc9175e5 (last modified on Sun Apr  7 11:16:22 2024).\n",
      "Using the latest cached version of the dataset since JetBrains-Research/lca-results couldn't be found on the Hugging Face Hub\n",
      "Found the latest cached dataset configuration 'cmg_gpt_4_0613' at cache\\JetBrains-Research___lca-results\\cmg_gpt_4_0613\\0.0.0\\4b56bbf7243da371b3e0a42a0c9db1f37af98c39 (last modified on Fri May 31 16:00:33 2024).\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "                                                diff  \\\n",
       "0  [{'change_type': 'MODIFY', 'old_path': 'cupy/c...   \n",
       "1  [{'change_type': 'MODIFY', 'old_path': 'tests/...   \n",
       "2  [{'change_type': 'MODIFY', 'old_path': 'numpy/...   \n",
       "3  [{'change_type': 'MODIFY', 'old_path': 'numpy/...   \n",
       "4  [{'change_type': 'MODIFY', 'old_path': 'numpy/...   \n",
       "\n",
       "                                  prediction_current  \n",
       "0  Extend memory management to consider CUDA stre...  \n",
       "1  Implement utility methods for parameterized te...  \n",
       "2  Update numpy function imports to use numpy as ...  \n",
       "3  Switch to using internal implementation method...  \n",
       "4  Add type hints and refine array API wrappers\\n...  "
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>diff</th>\n",
       "      <th>prediction_current</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>[{'change_type': 'MODIFY', 'old_path': 'cupy/c...</td>\n",
       "      <td>Extend memory management to consider CUDA stre...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>[{'change_type': 'MODIFY', 'old_path': 'tests/...</td>\n",
       "      <td>Implement utility methods for parameterized te...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>[{'change_type': 'MODIFY', 'old_path': 'numpy/...</td>\n",
       "      <td>Update numpy function imports to use numpy as ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>[{'change_type': 'MODIFY', 'old_path': 'numpy/...</td>\n",
       "      <td>Switch to using internal implementation method...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>[{'change_type': 'MODIFY', 'old_path': 'numpy/...</td>\n",
       "      <td>Add type hints and refine array API wrappers\\n...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 5
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-06-20T16:21:20.410778Z",
     "start_time": "2024-06-20T16:09:22.227258Z"
    }
   },
   "cell_type": "code",
   "source": "DATA[\"prediction_prod\"] = DATA.progress_apply(lambda row: generate_commit_message_prod(str(row[\"diff\"])), axis=1)",
   "id": "9ded493e087f991d",
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 163/163 [11:58<00:00,  4.41s/it]\n"
     ]
    }
   ],
   "execution_count": 6
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-06-20T16:21:20.426781Z",
     "start_time": "2024-06-20T16:21:20.414781Z"
    }
   },
   "cell_type": "code",
   "source": [
    "current_avg_length = DATA[\"prediction_current\"].str.len().mean()\n",
    "print(f\"Current average length: {current_avg_length}\")"
   ],
   "id": "ad38c2dce387f26d",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Current average length: 625.5644171779142\n"
     ]
    }
   ],
   "execution_count": 7
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-06-20T16:21:20.442017Z",
     "start_time": "2024-06-20T16:21:20.429913Z"
    }
   },
   "cell_type": "code",
   "source": [
    "prod_avg_length = DATA[\"prediction_prod\"].str.len().mean()\n",
    "print(f\"Prod average length: {prod_avg_length}\")"
   ],
   "id": "ec8b4412410794a4",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Prod average length: 352.88957055214723\n"
     ]
    }
   ],
   "execution_count": 8
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-06-20T16:21:20.457884Z",
     "start_time": "2024-06-20T16:21:20.444852Z"
    }
   },
   "cell_type": "code",
   "source": "print(f\"Length ratio (current / prod): {current_avg_length / prod_avg_length})\")",
   "id": "10f087784896eca3",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Length ratio (current / prod): 1.772691712591923)\n"
     ]
    }
   ],
   "execution_count": 9
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}