{ "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": [ "
\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": 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 }