File size: 7,288 Bytes
bb44b5c
 
e684577
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bb44b5c
 
 
e684577
 
bb44b5c
 
 
 
 
 
 
 
 
 
 
 
e684577
bb44b5c
 
 
 
e684577
 
bb44b5c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e684577
bb44b5c
 
e684577
bb44b5c
 
 
e684577
 
bb44b5c
 
 
 
e684577
 
bb44b5c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e684577
bb44b5c
 
 
 
e684577
bb44b5c
 
e684577
bb44b5c
 
 
e684577
 
bb44b5c
 
 
 
e684577
 
bb44b5c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e684577
bb44b5c
 
 
 
 
 
 
 
e684577
 
 
bb44b5c
 
 
 
 
e684577
 
 
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
{
 "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": {},
   "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": null
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-31T16:15:11.790663Z",
     "start_time": "2024-05-31T16:15:11.777607Z"
    }
   },
   "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": 20
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-31T16:15:13.223782Z",
     "start_time": "2024-05-31T16:15:13.207891Z"
    }
   },
   "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",
    "\tgenerate_for_prompt(prod_prompt(diff))"
   ],
   "id": "84a769c8765a7b64",
   "outputs": [],
   "execution_count": 21
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": "generate_commit_message_prod(\"TEST\")",
   "id": "af2f20def94b0490",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-31T16:15:24.167706Z",
     "start_time": "2024-05-31T16:15:16.619781Z"
    }
   },
   "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": [
    {
     "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": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 22
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": "DATA[\"prediction_prod\"] = DATA.progress_apply(lambda row: generate_commit_message_prod(str(row[\"diff\"])), axis=1)",
   "id": "9ded493e087f991d",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-31T16:15:24.183660Z",
     "start_time": "2024-05-31T16:15:24.170584Z"
    }
   },
   "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": 23
  },
  {
   "metadata": {},
   "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": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": "print(f\"Length ratio (current / prod): {current_avg_length / prod_avg_length})\")",
   "id": "10f087784896eca3",
   "outputs": [],
   "execution_count": null
  }
 ],
 "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
}