Petr Tsvetkov commited on
Commit
bb44b5c
β€’
1 Parent(s): 347f566

Length comparison template notebook; grazie token is needed to run

Browse files
api_wrappers/grazie_wrapper.py CHANGED
@@ -9,9 +9,9 @@ from grazie.api.client.profiles import LLMProfile
9
  import config
10
 
11
  client = GrazieApiGatewayClient(
12
- grazie_agent=GrazieAgent(name="commit-rewriting-synthetic-end-to-start", version="dev"),
13
  url=GrazieApiGatewayUrls.STAGING,
14
- auth_type=AuthType.USER,
15
  grazie_jwt_token=config.GRAZIE_API_JWT_TOKEN
16
  )
17
 
 
9
  import config
10
 
11
  client = GrazieApiGatewayClient(
12
+ grazie_agent=GrazieAgent("grazie-toolformers", "v1.0"),
13
  url=GrazieApiGatewayUrls.STAGING,
14
+ auth_type=AuthType.SERVICE,
15
  grazie_jwt_token=config.GRAZIE_API_JWT_TOKEN
16
  )
17
 
generated_message_length_comparison.ipynb ADDED
@@ -0,0 +1,322 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "metadata": {
5
+ "ExecuteTime": {
6
+ "end_time": "2024-05-31T13:59:45.809229Z",
7
+ "start_time": "2024-05-31T13:59:45.738228Z"
8
+ }
9
+ },
10
+ "cell_type": "code",
11
+ "source": [
12
+ "from api_wrappers.grazie_wrapper import generate_for_prompt\n",
13
+ "from api_wrappers.hf_data_loader import load_full_commit_with_predictions_as_pandas\n",
14
+ "from tqdm import tqdm\n",
15
+ "\n",
16
+ "tqdm.pandas()"
17
+ ],
18
+ "id": "ce11a4c781c152e",
19
+ "outputs": [],
20
+ "execution_count": 9
21
+ },
22
+ {
23
+ "metadata": {
24
+ "ExecuteTime": {
25
+ "end_time": "2024-05-31T13:59:46.750857Z",
26
+ "start_time": "2024-05-31T13:59:46.726738Z"
27
+ }
28
+ },
29
+ "cell_type": "code",
30
+ "source": [
31
+ "with open(\"data/prod_prompt.txt\") as f:\n",
32
+ "\tPROD_PROMPT = f.read().strip()\n",
33
+ "\n",
34
+ "def prod_prompt(diff):\n",
35
+ "\treturn PROD_PROMPT.replace(\"$diff\", diff).replace(\"$text\", \"\")\n",
36
+ "\n",
37
+ "def generate_commit_message_prod(diff):\n",
38
+ "\tgenerate_for_prompt(prod_prompt(diff))"
39
+ ],
40
+ "id": "84a769c8765a7b64",
41
+ "outputs": [],
42
+ "execution_count": 10
43
+ },
44
+ {
45
+ "metadata": {
46
+ "ExecuteTime": {
47
+ "end_time": "2024-05-31T14:00:17.941407Z",
48
+ "start_time": "2024-05-31T13:59:48.952862Z"
49
+ }
50
+ },
51
+ "cell_type": "code",
52
+ "source": "generate_commit_message_prod(\"TEST\")",
53
+ "id": "af2f20def94b0490",
54
+ "outputs": [
55
+ {
56
+ "ename": "KeyboardInterrupt",
57
+ "evalue": "",
58
+ "output_type": "error",
59
+ "traceback": [
60
+ "\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
61
+ "\u001B[1;31mRequestFailedException\u001B[0m Traceback (most recent call last)",
62
+ "File \u001B[1;32mD:\\petrtsv\\work\\jetbrains\\commit-rewriting-processing\\api_wrappers\\grazie_wrapper.py:35\u001B[0m, in \u001B[0;36mllm_request\u001B[1;34m(prompt)\u001B[0m\n\u001B[0;32m 34\u001B[0m \u001B[38;5;28;01mtry\u001B[39;00m:\n\u001B[1;32m---> 35\u001B[0m output \u001B[38;5;241m=\u001B[39m \u001B[43mclient\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mchat\u001B[49m\u001B[43m(\u001B[49m\n\u001B[0;32m 36\u001B[0m \u001B[43m \u001B[49m\u001B[43mchat\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43mChatPrompt\u001B[49m\u001B[43m(\u001B[49m\u001B[43m)\u001B[49m\n\u001B[0;32m 37\u001B[0m \u001B[43m \u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43madd_system\u001B[49m\u001B[43m(\u001B[49m\u001B[38;5;124;43m\"\u001B[39;49m\u001B[38;5;124;43mYou are a helpful assistant.\u001B[39;49m\u001B[38;5;124;43m\"\u001B[39;49m\u001B[43m)\u001B[49m\n\u001B[0;32m 38\u001B[0m \u001B[43m \u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43madd_user\u001B[49m\u001B[43m(\u001B[49m\u001B[43mprompt\u001B[49m\u001B[43m)\u001B[49m\u001B[43m,\u001B[49m\n\u001B[0;32m 39\u001B[0m \u001B[43m \u001B[49m\u001B[43mprofile\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43mLLMProfile\u001B[49m\u001B[43m(\u001B[49m\u001B[43mconfig\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mLLM_MODEL\u001B[49m\u001B[43m)\u001B[49m\n\u001B[0;32m 40\u001B[0m \u001B[43m \u001B[49m\u001B[43m)\u001B[49m\u001B[38;5;241m.\u001B[39mcontent\n\u001B[0;32m 41\u001B[0m \u001B[38;5;28;01mexcept\u001B[39;00m:\n",
63
+ "File \u001B[1;32mD:\\petrtsv\\work\\jetbrains\\commit-rewriting-processing\\.venv\\lib\\site-packages\\grazie\\api\\client\\gateway.py:193\u001B[0m, in \u001B[0;36mGrazieApiGatewayClient.chat\u001B[1;34m(self, chat, profile, prompt_id, parameters, headers)\u001B[0m\n\u001B[0;32m 192\u001B[0m chunks: List[ChatResponseStream] \u001B[38;5;241m=\u001B[39m []\n\u001B[1;32m--> 193\u001B[0m \u001B[38;5;28;01mfor\u001B[39;00m stream_response \u001B[38;5;129;01min\u001B[39;00m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mchat_stream(chat, profile\u001B[38;5;241m=\u001B[39mprofile, prompt_id\u001B[38;5;241m=\u001B[39mprompt_id, parameters\u001B[38;5;241m=\u001B[39mparameters, headers\u001B[38;5;241m=\u001B[39mheaders):\n\u001B[0;32m 194\u001B[0m chunks\u001B[38;5;241m.\u001B[39mappend(stream_response)\n",
64
+ "File \u001B[1;32mD:\\petrtsv\\work\\jetbrains\\commit-rewriting-processing\\.venv\\lib\\site-packages\\grazie\\api\\client\\gateway.py:254\u001B[0m, in \u001B[0;36mGrazieApiGatewayClient.chat_stream\u001B[1;34m(self, chat, profile, prompt_id, parameters, headers)\u001B[0m\n\u001B[0;32m 246\u001B[0m response \u001B[38;5;241m=\u001B[39m requests\u001B[38;5;241m.\u001B[39mpost(\n\u001B[0;32m 247\u001B[0m url\u001B[38;5;241m=\u001B[39m\u001B[38;5;124mf\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;132;01m{\u001B[39;00m\u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_api_gateway_url\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;124m/\u001B[39m\u001B[38;5;132;01m{\u001B[39;00m\u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_auth_type\u001B[38;5;241m.\u001B[39mvalue\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;124m/v5/llm/chat/stream/v6\u001B[39m\u001B[38;5;124m\"\u001B[39m,\n\u001B[0;32m 248\u001B[0m headers\u001B[38;5;241m=\u001B[39m\u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_generate_headers(headers),\n\u001B[1;32m (...)\u001B[0m\n\u001B[0;32m 251\u001B[0m stream\u001B[38;5;241m=\u001B[39m\u001B[38;5;28;01mTrue\u001B[39;00m\n\u001B[0;32m 252\u001B[0m )\n\u001B[1;32m--> 254\u001B[0m \u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43m_raise_if_error\u001B[49m\u001B[43m(\u001B[49m\u001B[43mresponse\u001B[49m\u001B[43m)\u001B[49m\n\u001B[0;32m 256\u001B[0m \u001B[38;5;28;01mfor\u001B[39;00m event \u001B[38;5;129;01min\u001B[39;00m _decode_llm_sse(\u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_parse_sse_response(response\u001B[38;5;241m.\u001B[39miter_lines()), LLMChatEventV6):\n",
65
+ "File \u001B[1;32mD:\\petrtsv\\work\\jetbrains\\commit-rewriting-processing\\.venv\\lib\\site-packages\\grazie\\api\\client\\gateway.py:298\u001B[0m, in \u001B[0;36mGrazieApiGatewayClient._raise_if_error\u001B[1;34m(self, response)\u001B[0m\n\u001B[0;32m 297\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m response\u001B[38;5;241m.\u001B[39mstatus_code \u001B[38;5;241m!=\u001B[39m \u001B[38;5;241m200\u001B[39m:\n\u001B[1;32m--> 298\u001B[0m \u001B[38;5;28;01mraise\u001B[39;00m RequestFailedException(\u001B[38;5;124mf\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;132;01m{\u001B[39;00mresponse\u001B[38;5;241m.\u001B[39mstatus_code\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;124m Error: \u001B[39m\u001B[38;5;132;01m{\u001B[39;00mresponse\u001B[38;5;241m.\u001B[39mreason\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;124m. \u001B[39m\u001B[38;5;132;01m{\u001B[39;00mresponse\u001B[38;5;241m.\u001B[39mtext\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;124m\"\u001B[39m)\n",
66
+ "\u001B[1;31mRequestFailedException\u001B[0m: 401 Error: Unauthorized. ",
67
+ "\nDuring handling of the above exception, another exception occurred:\n",
68
+ "\u001B[1;31mKeyboardInterrupt\u001B[0m Traceback (most recent call last)",
69
+ "Cell \u001B[1;32mIn[11], line 1\u001B[0m\n\u001B[1;32m----> 1\u001B[0m \u001B[43mgenerate_commit_message_prod\u001B[49m\u001B[43m(\u001B[49m\u001B[38;5;124;43m\"\u001B[39;49m\u001B[38;5;124;43mTEST\u001B[39;49m\u001B[38;5;124;43m\"\u001B[39;49m\u001B[43m)\u001B[49m\n",
70
+ "Cell \u001B[1;32mIn[10], line 8\u001B[0m, in \u001B[0;36mgenerate_commit_message_prod\u001B[1;34m(diff)\u001B[0m\n\u001B[0;32m 7\u001B[0m \u001B[38;5;28;01mdef\u001B[39;00m \u001B[38;5;21mgenerate_commit_message_prod\u001B[39m(diff):\n\u001B[1;32m----> 8\u001B[0m \t\u001B[43mgenerate_for_prompt\u001B[49m\u001B[43m(\u001B[49m\u001B[43mprod_prompt\u001B[49m\u001B[43m(\u001B[49m\u001B[43mdiff\u001B[49m\u001B[43m)\u001B[49m\u001B[43m)\u001B[49m\n",
71
+ "File \u001B[1;32mD:\\petrtsv\\work\\jetbrains\\commit-rewriting-processing\\api_wrappers\\grazie_wrapper.py:57\u001B[0m, in \u001B[0;36mgenerate_for_prompt\u001B[1;34m(prompt)\u001B[0m\n\u001B[0;32m 54\u001B[0m LLM_CACHE_USED[prompt] \u001B[38;5;241m=\u001B[39m \u001B[38;5;241m0\u001B[39m\n\u001B[0;32m 56\u001B[0m \u001B[38;5;28;01mwhile\u001B[39;00m LLM_CACHE_USED[prompt] \u001B[38;5;241m>\u001B[39m\u001B[38;5;241m=\u001B[39m \u001B[38;5;28mlen\u001B[39m(LLM_CACHE[prompt]):\n\u001B[1;32m---> 57\u001B[0m new_response \u001B[38;5;241m=\u001B[39m \u001B[43mllm_request\u001B[49m\u001B[43m(\u001B[49m\u001B[43mprompt\u001B[49m\u001B[43m)\u001B[49m\n\u001B[0;32m 58\u001B[0m LLM_CACHE[prompt]\u001B[38;5;241m.\u001B[39mappend(new_response)\n\u001B[0;32m 60\u001B[0m \u001B[38;5;28;01mwith\u001B[39;00m \u001B[38;5;28mopen\u001B[39m(LLM_CACHE_FILE, \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mwb\u001B[39m\u001B[38;5;124m\"\u001B[39m) \u001B[38;5;28;01mas\u001B[39;00m file:\n",
72
+ "File \u001B[1;32mD:\\petrtsv\\work\\jetbrains\\commit-rewriting-processing\\api_wrappers\\grazie_wrapper.py:42\u001B[0m, in \u001B[0;36mllm_request\u001B[1;34m(prompt)\u001B[0m\n\u001B[0;32m 35\u001B[0m output \u001B[38;5;241m=\u001B[39m client\u001B[38;5;241m.\u001B[39mchat(\n\u001B[0;32m 36\u001B[0m chat\u001B[38;5;241m=\u001B[39mChatPrompt()\n\u001B[0;32m 37\u001B[0m \u001B[38;5;241m.\u001B[39madd_system(\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mYou are a helpful assistant.\u001B[39m\u001B[38;5;124m\"\u001B[39m)\n\u001B[0;32m 38\u001B[0m \u001B[38;5;241m.\u001B[39madd_user(prompt),\n\u001B[0;32m 39\u001B[0m profile\u001B[38;5;241m=\u001B[39mLLMProfile(config\u001B[38;5;241m.\u001B[39mLLM_MODEL)\n\u001B[0;32m 40\u001B[0m )\u001B[38;5;241m.\u001B[39mcontent\n\u001B[0;32m 41\u001B[0m \u001B[38;5;28;01mexcept\u001B[39;00m:\n\u001B[1;32m---> 42\u001B[0m \u001B[43mtime\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43msleep\u001B[49m\u001B[43m(\u001B[49m\u001B[43mconfig\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mGRAZIE_TIMEOUT_SEC\u001B[49m\u001B[43m)\u001B[49m\n\u001B[0;32m 44\u001B[0m \u001B[38;5;28;01massert\u001B[39;00m output \u001B[38;5;129;01mis\u001B[39;00m \u001B[38;5;129;01mnot\u001B[39;00m \u001B[38;5;28;01mNone\u001B[39;00m\n\u001B[0;32m 46\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m output\n",
73
+ "\u001B[1;31mKeyboardInterrupt\u001B[0m: "
74
+ ]
75
+ }
76
+ ],
77
+ "execution_count": 11
78
+ },
79
+ {
80
+ "metadata": {
81
+ "ExecuteTime": {
82
+ "end_time": "2024-05-31T14:00:33.963374Z",
83
+ "start_time": "2024-05-31T14:00:21.253920Z"
84
+ }
85
+ },
86
+ "cell_type": "code",
87
+ "source": [
88
+ "DATA = load_full_commit_with_predictions_as_pandas()[[\"mods\", \"prediction\"]].rename(columns={\"mods\": \"diff\", \"prediction\": \"prediction_current\"})\n",
89
+ "DATA.head()"
90
+ ],
91
+ "id": "a49cabf576c9d692",
92
+ "outputs": [
93
+ {
94
+ "data": {
95
+ "text/plain": [
96
+ "Downloading readme: 0%| | 0.00/2.41k [00:00<?, ?B/s]"
97
+ ],
98
+ "application/vnd.jupyter.widget-view+json": {
99
+ "version_major": 2,
100
+ "version_minor": 0,
101
+ "model_id": "5dc984c015fc4493aedbfb5a70f7b026"
102
+ }
103
+ },
104
+ "metadata": {},
105
+ "output_type": "display_data"
106
+ },
107
+ {
108
+ "name": "stderr",
109
+ "output_type": "stream",
110
+ "text": [
111
+ "Downloading data: 100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 163k/163k [00:00<00:00, 474kB/s]\n",
112
+ "Downloading data: 100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 167k/167k [00:00<00:00, 493kB/s]\n",
113
+ "Downloading data: 100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 163k/163k [00:00<00:00, 684kB/s]\n"
114
+ ]
115
+ },
116
+ {
117
+ "data": {
118
+ "text/plain": [
119
+ "Generating test split: 0 examples [00:00, ? examples/s]"
120
+ ],
121
+ "application/vnd.jupyter.widget-view+json": {
122
+ "version_major": 2,
123
+ "version_minor": 0,
124
+ "model_id": "5f55866359b345d09a67f87888b8ad73"
125
+ }
126
+ },
127
+ "metadata": {},
128
+ "output_type": "display_data"
129
+ },
130
+ {
131
+ "data": {
132
+ "text/plain": [
133
+ " diff \\\n",
134
+ "0 [{'change_type': 'MODIFY', 'old_path': 'cupy/c... \n",
135
+ "1 [{'change_type': 'MODIFY', 'old_path': 'tests/... \n",
136
+ "2 [{'change_type': 'MODIFY', 'old_path': 'numpy/... \n",
137
+ "3 [{'change_type': 'MODIFY', 'old_path': 'numpy/... \n",
138
+ "4 [{'change_type': 'MODIFY', 'old_path': 'numpy/... \n",
139
+ "\n",
140
+ " prediction_current \n",
141
+ "0 Extend memory management to consider CUDA stre... \n",
142
+ "1 Implement utility methods for parameterized te... \n",
143
+ "2 Update numpy function imports to use numpy as ... \n",
144
+ "3 Switch to using internal implementation method... \n",
145
+ "4 Add type hints and refine array API wrappers\\n... "
146
+ ],
147
+ "text/html": [
148
+ "<div>\n",
149
+ "<style scoped>\n",
150
+ " .dataframe tbody tr th:only-of-type {\n",
151
+ " vertical-align: middle;\n",
152
+ " }\n",
153
+ "\n",
154
+ " .dataframe tbody tr th {\n",
155
+ " vertical-align: top;\n",
156
+ " }\n",
157
+ "\n",
158
+ " .dataframe thead th {\n",
159
+ " text-align: right;\n",
160
+ " }\n",
161
+ "</style>\n",
162
+ "<table border=\"1\" class=\"dataframe\">\n",
163
+ " <thead>\n",
164
+ " <tr style=\"text-align: right;\">\n",
165
+ " <th></th>\n",
166
+ " <th>diff</th>\n",
167
+ " <th>prediction_current</th>\n",
168
+ " </tr>\n",
169
+ " </thead>\n",
170
+ " <tbody>\n",
171
+ " <tr>\n",
172
+ " <th>0</th>\n",
173
+ " <td>[{'change_type': 'MODIFY', 'old_path': 'cupy/c...</td>\n",
174
+ " <td>Extend memory management to consider CUDA stre...</td>\n",
175
+ " </tr>\n",
176
+ " <tr>\n",
177
+ " <th>1</th>\n",
178
+ " <td>[{'change_type': 'MODIFY', 'old_path': 'tests/...</td>\n",
179
+ " <td>Implement utility methods for parameterized te...</td>\n",
180
+ " </tr>\n",
181
+ " <tr>\n",
182
+ " <th>2</th>\n",
183
+ " <td>[{'change_type': 'MODIFY', 'old_path': 'numpy/...</td>\n",
184
+ " <td>Update numpy function imports to use numpy as ...</td>\n",
185
+ " </tr>\n",
186
+ " <tr>\n",
187
+ " <th>3</th>\n",
188
+ " <td>[{'change_type': 'MODIFY', 'old_path': 'numpy/...</td>\n",
189
+ " <td>Switch to using internal implementation method...</td>\n",
190
+ " </tr>\n",
191
+ " <tr>\n",
192
+ " <th>4</th>\n",
193
+ " <td>[{'change_type': 'MODIFY', 'old_path': 'numpy/...</td>\n",
194
+ " <td>Add type hints and refine array API wrappers\\n...</td>\n",
195
+ " </tr>\n",
196
+ " </tbody>\n",
197
+ "</table>\n",
198
+ "</div>"
199
+ ]
200
+ },
201
+ "execution_count": 12,
202
+ "metadata": {},
203
+ "output_type": "execute_result"
204
+ }
205
+ ],
206
+ "execution_count": 12
207
+ },
208
+ {
209
+ "metadata": {
210
+ "ExecuteTime": {
211
+ "end_time": "2024-05-30T13:20:38.052443Z",
212
+ "start_time": "2024-05-30T13:20:26.913353Z"
213
+ }
214
+ },
215
+ "cell_type": "code",
216
+ "source": "DATA[\"prediction_prod\"] = DATA.progress_apply(lambda row: generate_commit_message_prod(str(row[\"diff\"])), axis=1)",
217
+ "id": "9ded493e087f991d",
218
+ "outputs": [
219
+ {
220
+ "name": "stderr",
221
+ "output_type": "stream",
222
+ "text": [
223
+ " 1%| | 1/163 [00:10<29:35, 10.96s/it]\n"
224
+ ]
225
+ },
226
+ {
227
+ "ename": "KeyboardInterrupt",
228
+ "evalue": "",
229
+ "output_type": "error",
230
+ "traceback": [
231
+ "\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
232
+ "\u001B[1;31mRequestFailedException\u001B[0m Traceback (most recent call last)",
233
+ "File \u001B[1;32mD:\\petrtsv\\work\\jetbrains\\commit-rewriting-processing\\api_wrappers\\grazie_wrapper.py:35\u001B[0m, in \u001B[0;36mllm_request\u001B[1;34m(prompt)\u001B[0m\n\u001B[0;32m 34\u001B[0m \u001B[38;5;28;01mtry\u001B[39;00m:\n\u001B[1;32m---> 35\u001B[0m output \u001B[38;5;241m=\u001B[39m output \u001B[38;5;241m=\u001B[39m \u001B[43mclient\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mchat\u001B[49m\u001B[43m(\u001B[49m\n\u001B[0;32m 36\u001B[0m \u001B[43m \u001B[49m\u001B[43mchat\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43mChatPrompt\u001B[49m\u001B[43m(\u001B[49m\u001B[43m)\u001B[49m\n\u001B[0;32m 37\u001B[0m \u001B[43m \u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43madd_system\u001B[49m\u001B[43m(\u001B[49m\u001B[38;5;124;43m\"\u001B[39;49m\u001B[38;5;124;43mYou are a helpful assistant.\u001B[39;49m\u001B[38;5;124;43m\"\u001B[39;49m\u001B[43m)\u001B[49m\n\u001B[0;32m 38\u001B[0m \u001B[43m \u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43madd_user\u001B[49m\u001B[43m(\u001B[49m\u001B[43mprompt\u001B[49m\u001B[43m)\u001B[49m\u001B[43m,\u001B[49m\n\u001B[0;32m 39\u001B[0m \u001B[43m \u001B[49m\u001B[43mprofile\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43mLLMProfile\u001B[49m\u001B[43m(\u001B[49m\u001B[43mconfig\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mLLM_MODEL\u001B[49m\u001B[43m)\u001B[49m\n\u001B[0;32m 40\u001B[0m \u001B[43m \u001B[49m\u001B[43m)\u001B[49m\u001B[38;5;241m.\u001B[39mcontent\n\u001B[0;32m 41\u001B[0m \u001B[38;5;28;01mexcept\u001B[39;00m:\n",
234
+ "File \u001B[1;32mD:\\petrtsv\\work\\jetbrains\\commit-rewriting-processing\\.venv\\lib\\site-packages\\grazie\\api\\client\\gateway.py:193\u001B[0m, in \u001B[0;36mGrazieApiGatewayClient.chat\u001B[1;34m(self, chat, profile, prompt_id, parameters, headers)\u001B[0m\n\u001B[0;32m 192\u001B[0m chunks: List[ChatResponseStream] \u001B[38;5;241m=\u001B[39m []\n\u001B[1;32m--> 193\u001B[0m \u001B[38;5;28;01mfor\u001B[39;00m stream_response \u001B[38;5;129;01min\u001B[39;00m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mchat_stream(chat, profile\u001B[38;5;241m=\u001B[39mprofile, prompt_id\u001B[38;5;241m=\u001B[39mprompt_id, parameters\u001B[38;5;241m=\u001B[39mparameters, headers\u001B[38;5;241m=\u001B[39mheaders):\n\u001B[0;32m 194\u001B[0m chunks\u001B[38;5;241m.\u001B[39mappend(stream_response)\n",
235
+ "File \u001B[1;32mD:\\petrtsv\\work\\jetbrains\\commit-rewriting-processing\\.venv\\lib\\site-packages\\grazie\\api\\client\\gateway.py:254\u001B[0m, in \u001B[0;36mGrazieApiGatewayClient.chat_stream\u001B[1;34m(self, chat, profile, prompt_id, parameters, headers)\u001B[0m\n\u001B[0;32m 246\u001B[0m response \u001B[38;5;241m=\u001B[39m requests\u001B[38;5;241m.\u001B[39mpost(\n\u001B[0;32m 247\u001B[0m url\u001B[38;5;241m=\u001B[39m\u001B[38;5;124mf\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;132;01m{\u001B[39;00m\u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_api_gateway_url\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;124m/\u001B[39m\u001B[38;5;132;01m{\u001B[39;00m\u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_auth_type\u001B[38;5;241m.\u001B[39mvalue\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;124m/v5/llm/chat/stream/v6\u001B[39m\u001B[38;5;124m\"\u001B[39m,\n\u001B[0;32m 248\u001B[0m headers\u001B[38;5;241m=\u001B[39m\u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_generate_headers(headers),\n\u001B[1;32m (...)\u001B[0m\n\u001B[0;32m 251\u001B[0m stream\u001B[38;5;241m=\u001B[39m\u001B[38;5;28;01mTrue\u001B[39;00m\n\u001B[0;32m 252\u001B[0m )\n\u001B[1;32m--> 254\u001B[0m \u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43m_raise_if_error\u001B[49m\u001B[43m(\u001B[49m\u001B[43mresponse\u001B[49m\u001B[43m)\u001B[49m\n\u001B[0;32m 256\u001B[0m \u001B[38;5;28;01mfor\u001B[39;00m event \u001B[38;5;129;01min\u001B[39;00m _decode_llm_sse(\u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_parse_sse_response(response\u001B[38;5;241m.\u001B[39miter_lines()), LLMChatEventV6):\n",
236
+ "File \u001B[1;32mD:\\petrtsv\\work\\jetbrains\\commit-rewriting-processing\\.venv\\lib\\site-packages\\grazie\\api\\client\\gateway.py:298\u001B[0m, in \u001B[0;36mGrazieApiGatewayClient._raise_if_error\u001B[1;34m(self, response)\u001B[0m\n\u001B[0;32m 297\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m response\u001B[38;5;241m.\u001B[39mstatus_code \u001B[38;5;241m!=\u001B[39m \u001B[38;5;241m200\u001B[39m:\n\u001B[1;32m--> 298\u001B[0m \u001B[38;5;28;01mraise\u001B[39;00m RequestFailedException(\u001B[38;5;124mf\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;132;01m{\u001B[39;00mresponse\u001B[38;5;241m.\u001B[39mstatus_code\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;124m Error: \u001B[39m\u001B[38;5;132;01m{\u001B[39;00mresponse\u001B[38;5;241m.\u001B[39mreason\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;124m. \u001B[39m\u001B[38;5;132;01m{\u001B[39;00mresponse\u001B[38;5;241m.\u001B[39mtext\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;124m\"\u001B[39m)\n",
237
+ "\u001B[1;31mRequestFailedException\u001B[0m: 401 Error: Unauthorized. ",
238
+ "\nDuring handling of the above exception, another exception occurred:\n",
239
+ "\u001B[1;31mKeyboardInterrupt\u001B[0m Traceback (most recent call last)",
240
+ "Cell \u001B[1;32mIn[17], line 1\u001B[0m\n\u001B[1;32m----> 1\u001B[0m DATA[\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mprediction_prod\u001B[39m\u001B[38;5;124m\"\u001B[39m] \u001B[38;5;241m=\u001B[39m \u001B[43mDATA\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mprogress_apply\u001B[49m\u001B[43m(\u001B[49m\u001B[38;5;28;43;01mlambda\u001B[39;49;00m\u001B[43m \u001B[49m\u001B[43mrow\u001B[49m\u001B[43m:\u001B[49m\u001B[43m \u001B[49m\u001B[43mgenerate_commit_message_prod\u001B[49m\u001B[43m(\u001B[49m\u001B[38;5;28;43mstr\u001B[39;49m\u001B[43m(\u001B[49m\u001B[43mrow\u001B[49m\u001B[43m[\u001B[49m\u001B[38;5;124;43m\"\u001B[39;49m\u001B[38;5;124;43mdiff\u001B[39;49m\u001B[38;5;124;43m\"\u001B[39;49m\u001B[43m]\u001B[49m\u001B[43m)\u001B[49m\u001B[43m)\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43maxis\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[38;5;241;43m1\u001B[39;49m\u001B[43m)\u001B[49m\n",
241
+ "File \u001B[1;32mD:\\petrtsv\\work\\jetbrains\\commit-rewriting-processing\\.venv\\lib\\site-packages\\tqdm\\std.py:917\u001B[0m, in \u001B[0;36mtqdm.pandas.<locals>.inner_generator.<locals>.inner\u001B[1;34m(df, func, *args, **kwargs)\u001B[0m\n\u001B[0;32m 914\u001B[0m \u001B[38;5;66;03m# Apply the provided function (in **kwargs)\u001B[39;00m\n\u001B[0;32m 915\u001B[0m \u001B[38;5;66;03m# on the df using our wrapper (which provides bar updating)\u001B[39;00m\n\u001B[0;32m 916\u001B[0m \u001B[38;5;28;01mtry\u001B[39;00m:\n\u001B[1;32m--> 917\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28mgetattr\u001B[39m(df, df_function)(wrapper, \u001B[38;5;241m*\u001B[39m\u001B[38;5;241m*\u001B[39mkwargs)\n\u001B[0;32m 918\u001B[0m \u001B[38;5;28;01mfinally\u001B[39;00m:\n\u001B[0;32m 919\u001B[0m t\u001B[38;5;241m.\u001B[39mclose()\n",
242
+ "File \u001B[1;32mD:\\petrtsv\\work\\jetbrains\\commit-rewriting-processing\\.venv\\lib\\site-packages\\pandas\\core\\frame.py:10361\u001B[0m, in \u001B[0;36mDataFrame.apply\u001B[1;34m(self, func, axis, raw, result_type, args, by_row, engine, engine_kwargs, **kwargs)\u001B[0m\n\u001B[0;32m 10347\u001B[0m \u001B[38;5;28;01mfrom\u001B[39;00m \u001B[38;5;21;01mpandas\u001B[39;00m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01mcore\u001B[39;00m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01mapply\u001B[39;00m \u001B[38;5;28;01mimport\u001B[39;00m frame_apply\n\u001B[0;32m 10349\u001B[0m op \u001B[38;5;241m=\u001B[39m frame_apply(\n\u001B[0;32m 10350\u001B[0m \u001B[38;5;28mself\u001B[39m,\n\u001B[0;32m 10351\u001B[0m func\u001B[38;5;241m=\u001B[39mfunc,\n\u001B[1;32m (...)\u001B[0m\n\u001B[0;32m 10359\u001B[0m kwargs\u001B[38;5;241m=\u001B[39mkwargs,\n\u001B[0;32m 10360\u001B[0m )\n\u001B[1;32m> 10361\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[43mop\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mapply\u001B[49m\u001B[43m(\u001B[49m\u001B[43m)\u001B[49m\u001B[38;5;241m.\u001B[39m__finalize__(\u001B[38;5;28mself\u001B[39m, method\u001B[38;5;241m=\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mapply\u001B[39m\u001B[38;5;124m\"\u001B[39m)\n",
243
+ "File \u001B[1;32mD:\\petrtsv\\work\\jetbrains\\commit-rewriting-processing\\.venv\\lib\\site-packages\\pandas\\core\\apply.py:916\u001B[0m, in \u001B[0;36mFrameApply.apply\u001B[1;34m(self)\u001B[0m\n\u001B[0;32m 913\u001B[0m \u001B[38;5;28;01melif\u001B[39;00m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mraw:\n\u001B[0;32m 914\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mapply_raw(engine\u001B[38;5;241m=\u001B[39m\u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mengine, engine_kwargs\u001B[38;5;241m=\u001B[39m\u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mengine_kwargs)\n\u001B[1;32m--> 916\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mapply_standard\u001B[49m\u001B[43m(\u001B[49m\u001B[43m)\u001B[49m\n",
244
+ "File \u001B[1;32mD:\\petrtsv\\work\\jetbrains\\commit-rewriting-processing\\.venv\\lib\\site-packages\\pandas\\core\\apply.py:1063\u001B[0m, in \u001B[0;36mFrameApply.apply_standard\u001B[1;34m(self)\u001B[0m\n\u001B[0;32m 1061\u001B[0m \u001B[38;5;28;01mdef\u001B[39;00m \u001B[38;5;21mapply_standard\u001B[39m(\u001B[38;5;28mself\u001B[39m):\n\u001B[0;32m 1062\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mengine \u001B[38;5;241m==\u001B[39m \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mpython\u001B[39m\u001B[38;5;124m\"\u001B[39m:\n\u001B[1;32m-> 1063\u001B[0m results, res_index \u001B[38;5;241m=\u001B[39m \u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mapply_series_generator\u001B[49m\u001B[43m(\u001B[49m\u001B[43m)\u001B[49m\n\u001B[0;32m 1064\u001B[0m \u001B[38;5;28;01melse\u001B[39;00m:\n\u001B[0;32m 1065\u001B[0m results, res_index \u001B[38;5;241m=\u001B[39m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mapply_series_numba()\n",
245
+ "File \u001B[1;32mD:\\petrtsv\\work\\jetbrains\\commit-rewriting-processing\\.venv\\lib\\site-packages\\pandas\\core\\apply.py:1081\u001B[0m, in \u001B[0;36mFrameApply.apply_series_generator\u001B[1;34m(self)\u001B[0m\n\u001B[0;32m 1078\u001B[0m \u001B[38;5;28;01mwith\u001B[39;00m option_context(\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mmode.chained_assignment\u001B[39m\u001B[38;5;124m\"\u001B[39m, \u001B[38;5;28;01mNone\u001B[39;00m):\n\u001B[0;32m 1079\u001B[0m \u001B[38;5;28;01mfor\u001B[39;00m i, v \u001B[38;5;129;01min\u001B[39;00m \u001B[38;5;28menumerate\u001B[39m(series_gen):\n\u001B[0;32m 1080\u001B[0m \u001B[38;5;66;03m# ignore SettingWithCopy here in case the user mutates\u001B[39;00m\n\u001B[1;32m-> 1081\u001B[0m results[i] \u001B[38;5;241m=\u001B[39m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mfunc(v, \u001B[38;5;241m*\u001B[39m\u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39margs, \u001B[38;5;241m*\u001B[39m\u001B[38;5;241m*\u001B[39m\u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mkwargs)\n\u001B[0;32m 1082\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;28misinstance\u001B[39m(results[i], ABCSeries):\n\u001B[0;32m 1083\u001B[0m \u001B[38;5;66;03m# If we have a view on v, we need to make a copy because\u001B[39;00m\n\u001B[0;32m 1084\u001B[0m \u001B[38;5;66;03m# series_generator will swap out the underlying data\u001B[39;00m\n\u001B[0;32m 1085\u001B[0m results[i] \u001B[38;5;241m=\u001B[39m results[i]\u001B[38;5;241m.\u001B[39mcopy(deep\u001B[38;5;241m=\u001B[39m\u001B[38;5;28;01mFalse\u001B[39;00m)\n",
246
+ "File \u001B[1;32mD:\\petrtsv\\work\\jetbrains\\commit-rewriting-processing\\.venv\\lib\\site-packages\\tqdm\\std.py:912\u001B[0m, in \u001B[0;36mtqdm.pandas.<locals>.inner_generator.<locals>.inner.<locals>.wrapper\u001B[1;34m(*args, **kwargs)\u001B[0m\n\u001B[0;32m 906\u001B[0m \u001B[38;5;28;01mdef\u001B[39;00m \u001B[38;5;21mwrapper\u001B[39m(\u001B[38;5;241m*\u001B[39margs, \u001B[38;5;241m*\u001B[39m\u001B[38;5;241m*\u001B[39mkwargs):\n\u001B[0;32m 907\u001B[0m \u001B[38;5;66;03m# update tbar correctly\u001B[39;00m\n\u001B[0;32m 908\u001B[0m \u001B[38;5;66;03m# it seems `pandas apply` calls `func` twice\u001B[39;00m\n\u001B[0;32m 909\u001B[0m \u001B[38;5;66;03m# on the first column/row to decide whether it can\u001B[39;00m\n\u001B[0;32m 910\u001B[0m \u001B[38;5;66;03m# take a fast or slow code path; so stop when t.total==t.n\u001B[39;00m\n\u001B[0;32m 911\u001B[0m t\u001B[38;5;241m.\u001B[39mupdate(n\u001B[38;5;241m=\u001B[39m\u001B[38;5;241m1\u001B[39m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;129;01mnot\u001B[39;00m t\u001B[38;5;241m.\u001B[39mtotal \u001B[38;5;129;01mor\u001B[39;00m t\u001B[38;5;241m.\u001B[39mn \u001B[38;5;241m<\u001B[39m t\u001B[38;5;241m.\u001B[39mtotal \u001B[38;5;28;01melse\u001B[39;00m \u001B[38;5;241m0\u001B[39m)\n\u001B[1;32m--> 912\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m func(\u001B[38;5;241m*\u001B[39margs, \u001B[38;5;241m*\u001B[39m\u001B[38;5;241m*\u001B[39mkwargs)\n",
247
+ "Cell \u001B[1;32mIn[17], line 1\u001B[0m, in \u001B[0;36m<lambda>\u001B[1;34m(row)\u001B[0m\n\u001B[1;32m----> 1\u001B[0m DATA[\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mprediction_prod\u001B[39m\u001B[38;5;124m\"\u001B[39m] \u001B[38;5;241m=\u001B[39m DATA\u001B[38;5;241m.\u001B[39mprogress_apply(\u001B[38;5;28;01mlambda\u001B[39;00m row: \u001B[43mgenerate_commit_message_prod\u001B[49m\u001B[43m(\u001B[49m\u001B[38;5;28;43mstr\u001B[39;49m\u001B[43m(\u001B[49m\u001B[43mrow\u001B[49m\u001B[43m[\u001B[49m\u001B[38;5;124;43m\"\u001B[39;49m\u001B[38;5;124;43mdiff\u001B[39;49m\u001B[38;5;124;43m\"\u001B[39;49m\u001B[43m]\u001B[49m\u001B[43m)\u001B[49m\u001B[43m)\u001B[49m, axis\u001B[38;5;241m=\u001B[39m\u001B[38;5;241m1\u001B[39m)\n",
248
+ "Cell \u001B[1;32mIn[3], line 8\u001B[0m, in \u001B[0;36mgenerate_commit_message_prod\u001B[1;34m(diff)\u001B[0m\n\u001B[0;32m 7\u001B[0m \u001B[38;5;28;01mdef\u001B[39;00m \u001B[38;5;21mgenerate_commit_message_prod\u001B[39m(diff):\n\u001B[1;32m----> 8\u001B[0m \t\u001B[43mgenerate_for_prompt\u001B[49m\u001B[43m(\u001B[49m\u001B[43mprod_prompt\u001B[49m\u001B[43m(\u001B[49m\u001B[43mdiff\u001B[49m\u001B[43m)\u001B[49m\u001B[43m)\u001B[49m\n",
249
+ "File \u001B[1;32mD:\\petrtsv\\work\\jetbrains\\commit-rewriting-processing\\api_wrappers\\grazie_wrapper.py:57\u001B[0m, in \u001B[0;36mgenerate_for_prompt\u001B[1;34m(prompt)\u001B[0m\n\u001B[0;32m 54\u001B[0m LLM_CACHE_USED[prompt] \u001B[38;5;241m=\u001B[39m \u001B[38;5;241m0\u001B[39m\n\u001B[0;32m 56\u001B[0m \u001B[38;5;28;01mwhile\u001B[39;00m LLM_CACHE_USED[prompt] \u001B[38;5;241m>\u001B[39m\u001B[38;5;241m=\u001B[39m \u001B[38;5;28mlen\u001B[39m(LLM_CACHE[prompt]):\n\u001B[1;32m---> 57\u001B[0m new_response \u001B[38;5;241m=\u001B[39m \u001B[43mllm_request\u001B[49m\u001B[43m(\u001B[49m\u001B[43mprompt\u001B[49m\u001B[43m)\u001B[49m\n\u001B[0;32m 58\u001B[0m LLM_CACHE[prompt]\u001B[38;5;241m.\u001B[39mappend(new_response)\n\u001B[0;32m 60\u001B[0m \u001B[38;5;28;01mwith\u001B[39;00m \u001B[38;5;28mopen\u001B[39m(LLM_CACHE_FILE, \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mwb\u001B[39m\u001B[38;5;124m\"\u001B[39m) \u001B[38;5;28;01mas\u001B[39;00m file:\n",
250
+ "File \u001B[1;32mD:\\petrtsv\\work\\jetbrains\\commit-rewriting-processing\\api_wrappers\\grazie_wrapper.py:42\u001B[0m, in \u001B[0;36mllm_request\u001B[1;34m(prompt)\u001B[0m\n\u001B[0;32m 35\u001B[0m output \u001B[38;5;241m=\u001B[39m output \u001B[38;5;241m=\u001B[39m client\u001B[38;5;241m.\u001B[39mchat(\n\u001B[0;32m 36\u001B[0m chat\u001B[38;5;241m=\u001B[39mChatPrompt()\n\u001B[0;32m 37\u001B[0m \u001B[38;5;241m.\u001B[39madd_system(\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mYou are a helpful assistant.\u001B[39m\u001B[38;5;124m\"\u001B[39m)\n\u001B[0;32m 38\u001B[0m \u001B[38;5;241m.\u001B[39madd_user(prompt),\n\u001B[0;32m 39\u001B[0m profile\u001B[38;5;241m=\u001B[39mLLMProfile(config\u001B[38;5;241m.\u001B[39mLLM_MODEL)\n\u001B[0;32m 40\u001B[0m )\u001B[38;5;241m.\u001B[39mcontent\n\u001B[0;32m 41\u001B[0m \u001B[38;5;28;01mexcept\u001B[39;00m:\n\u001B[1;32m---> 42\u001B[0m \u001B[43mtime\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43msleep\u001B[49m\u001B[43m(\u001B[49m\u001B[43mconfig\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mGRAZIE_TIMEOUT_SEC\u001B[49m\u001B[43m)\u001B[49m\n\u001B[0;32m 44\u001B[0m \u001B[38;5;28;01massert\u001B[39;00m output \u001B[38;5;129;01mis\u001B[39;00m \u001B[38;5;129;01mnot\u001B[39;00m \u001B[38;5;28;01mNone\u001B[39;00m\n\u001B[0;32m 46\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m output\n",
251
+ "\u001B[1;31mKeyboardInterrupt\u001B[0m: "
252
+ ]
253
+ }
254
+ ],
255
+ "execution_count": 17
256
+ },
257
+ {
258
+ "metadata": {
259
+ "ExecuteTime": {
260
+ "end_time": "2024-05-31T14:00:33.979797Z",
261
+ "start_time": "2024-05-31T14:00:33.965373Z"
262
+ }
263
+ },
264
+ "cell_type": "code",
265
+ "source": [
266
+ "current_avg_length = DATA[\"prediction_current\"].str.len().mean()\n",
267
+ "print(f\"Current average length: {current_avg_length}\")"
268
+ ],
269
+ "id": "ad38c2dce387f26d",
270
+ "outputs": [
271
+ {
272
+ "name": "stdout",
273
+ "output_type": "stream",
274
+ "text": [
275
+ "Current average length: 625.5644171779142\n"
276
+ ]
277
+ }
278
+ ],
279
+ "execution_count": 13
280
+ },
281
+ {
282
+ "metadata": {},
283
+ "cell_type": "code",
284
+ "outputs": [],
285
+ "execution_count": null,
286
+ "source": [
287
+ "prod_avg_length = DATA[\"prediction_prod\"].str.len().mean()\n",
288
+ "print(f\"Prod average length: {prod_avg_length}\")"
289
+ ],
290
+ "id": "ec8b4412410794a4"
291
+ },
292
+ {
293
+ "metadata": {},
294
+ "cell_type": "code",
295
+ "outputs": [],
296
+ "execution_count": null,
297
+ "source": "print(f\"Length ratio (current / prod): {current_avg_length / prod_avg_length})\")",
298
+ "id": "10f087784896eca3"
299
+ }
300
+ ],
301
+ "metadata": {
302
+ "kernelspec": {
303
+ "display_name": "Python 3",
304
+ "language": "python",
305
+ "name": "python3"
306
+ },
307
+ "language_info": {
308
+ "codemirror_mode": {
309
+ "name": "ipython",
310
+ "version": 2
311
+ },
312
+ "file_extension": ".py",
313
+ "mimetype": "text/x-python",
314
+ "name": "python",
315
+ "nbconvert_exporter": "python",
316
+ "pygments_lexer": "ipython2",
317
+ "version": "2.7.6"
318
+ }
319
+ },
320
+ "nbformat": 4,
321
+ "nbformat_minor": 5
322
+ }