{ "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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
diffprediction_current
0[{'change_type': 'MODIFY', 'old_path': 'cupy/c...Extend memory management to consider CUDA stre...
1[{'change_type': 'MODIFY', 'old_path': 'tests/...Implement utility methods for parameterized te...
2[{'change_type': 'MODIFY', 'old_path': 'numpy/...Update numpy function imports to use numpy as ...
3[{'change_type': 'MODIFY', 'old_path': 'numpy/...Switch to using internal implementation method...
4[{'change_type': 'MODIFY', 'old_path': 'numpy/...Add type hints and refine array API wrappers\\n...
\n", "
" ] }, "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 }