ragaai-catalyst 2.2.5b6__py3-none-any.whl → 2.2.6b1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ragaai_catalyst/prompt_manager.py +285 -112
- ragaai_catalyst/tracers/agentic_tracing/upload/trace_uploader.py +2 -8
- ragaai_catalyst/tracers/agentic_tracing/upload/upload_agentic_traces.py +1 -1
- ragaai_catalyst/tracers/agentic_tracing/upload/upload_code.py +1 -1
- ragaai_catalyst/tracers/agentic_tracing/utils/create_dataset_schema.py +1 -1
- {ragaai_catalyst-2.2.5b6.dist-info → ragaai_catalyst-2.2.6b1.dist-info}/METADATA +1 -1
- {ragaai_catalyst-2.2.5b6.dist-info → ragaai_catalyst-2.2.6b1.dist-info}/RECORD +11 -11
- /ragaai_catalyst/{tracers/agentic_tracing/upload/session_manager.py → session_manager.py} +0 -0
- {ragaai_catalyst-2.2.5b6.dist-info → ragaai_catalyst-2.2.6b1.dist-info}/WHEEL +0 -0
- {ragaai_catalyst-2.2.5b6.dist-info → ragaai_catalyst-2.2.6b1.dist-info}/licenses/LICENSE +0 -0
- {ragaai_catalyst-2.2.5b6.dist-info → ragaai_catalyst-2.2.6b1.dist-info}/top_level.txt +0 -0
@@ -1,9 +1,16 @@
|
|
1
1
|
import os
|
2
|
-
import
|
2
|
+
from ragaai_catalyst.session_manager import session_manager
|
3
3
|
import json
|
4
4
|
import re
|
5
5
|
from .ragaai_catalyst import RagaAICatalyst
|
6
6
|
import copy
|
7
|
+
import logging
|
8
|
+
import time
|
9
|
+
from urllib3.exceptions import PoolError, MaxRetryError, NewConnectionError
|
10
|
+
from requests.exceptions import ConnectionError, Timeout, RequestException
|
11
|
+
from http.client import RemoteDisconnected
|
12
|
+
|
13
|
+
logger = logging.getLogger(__name__)
|
7
14
|
|
8
15
|
class PromptManager:
|
9
16
|
NUM_PROJECTS = 100
|
@@ -17,38 +24,80 @@ class PromptManager:
|
|
17
24
|
project_name (str): The name of the project.
|
18
25
|
|
19
26
|
Raises:
|
20
|
-
requests.RequestException: If there's an error with the API request.
|
21
27
|
ValueError: If the project is not found.
|
22
28
|
"""
|
23
29
|
self.project_name = project_name
|
24
30
|
self.base_url = f"{RagaAICatalyst.BASE_URL}/playground/prompt"
|
25
31
|
self.timeout = 10
|
26
32
|
self.size = 99999 #Number of projects to fetch
|
33
|
+
self.project_id = None
|
34
|
+
self.headers = {}
|
27
35
|
|
28
36
|
try:
|
29
|
-
|
37
|
+
start_time = time.time()
|
38
|
+
response = session_manager.make_request_with_retry(
|
39
|
+
"GET",
|
30
40
|
f"{RagaAICatalyst.BASE_URL}/v2/llm/projects?size={self.size}",
|
31
41
|
headers={
|
32
42
|
"Authorization": f'Bearer {os.getenv("RAGAAI_CATALYST_TOKEN")}',
|
33
43
|
},
|
34
44
|
timeout=self.timeout,
|
35
45
|
)
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
+
elapsed_ms = (time.time() - start_time) * 1000
|
47
|
+
logger.debug(f"API Call: [GET] /v2/llm/projects | Status: {response.status_code} | Time: {elapsed_ms:.2f}ms")
|
48
|
+
|
49
|
+
if response.status_code in [200, 201]:
|
50
|
+
# logger.debug("Projects list retrieved successfully")
|
51
|
+
project_list = [
|
52
|
+
project["name"] for project in response.json()["data"]["content"]
|
53
|
+
]
|
54
|
+
self.project_id = [
|
55
|
+
project["id"] for project in response.json()["data"]["content"] if project["name"]==project_name
|
56
|
+
][0]
|
57
|
+
elif response.status_code == 401:
|
58
|
+
logger.warning("Received 401 error during fetching project list. Attempting to refresh token.")
|
59
|
+
token = RagaAICatalyst.get_token(force_refresh=True)
|
60
|
+
headers = {
|
61
|
+
"Authorization": f"Bearer {token}",
|
62
|
+
}
|
63
|
+
start_time = time.time()
|
64
|
+
response = session_manager.make_request_with_retry(
|
65
|
+
"GET", f"{RagaAICatalyst.BASE_URL}/v2/llm/projects?size={self.size}",
|
66
|
+
headers=headers, timeout=self.timeout
|
67
|
+
)
|
68
|
+
elapsed_ms = (time.time() - start_time) * 1000
|
69
|
+
logger.debug(f"API Call: [GET] /v2/llm/projects (retry) | Status: {response.status_code} | Time: {elapsed_ms:.2f}ms")
|
70
|
+
|
71
|
+
if response.status_code in [200, 201]:
|
72
|
+
logger.info("Project list fetched successfully after 401 token refresh")
|
73
|
+
project_list = [
|
74
|
+
project["name"] for project in response.json()["data"]["content"]
|
75
|
+
]
|
76
|
+
self.project_id = [
|
77
|
+
project["id"] for project in response.json()["data"]["content"] if project["name"]==project_name
|
78
|
+
][0]
|
79
|
+
else:
|
80
|
+
logger.error("Failed to fetch project list after 401 token refresh")
|
81
|
+
return
|
82
|
+
else:
|
83
|
+
logger.error(f"HTTP {response.status_code} error when fetching project list")
|
84
|
+
return
|
85
|
+
|
86
|
+
except (PoolError, MaxRetryError, NewConnectionError, ConnectionError, Timeout, RemoteDisconnected) as e:
|
87
|
+
session_manager.handle_request_exceptions(e, "fetching project list")
|
88
|
+
logger.error(f"Failed to fetch project list, PromptManager will have limited functionality")
|
89
|
+
return
|
90
|
+
except RequestException as e:
|
91
|
+
logger.error(f"Error while fetching project list: {e}")
|
92
|
+
logger.error(f"PromptManager will have limited functionality")
|
93
|
+
return
|
46
94
|
except (KeyError, json.JSONDecodeError) as e:
|
47
|
-
|
95
|
+
logger.error(f"Error parsing project list: {str(e)}")
|
96
|
+
return
|
48
97
|
|
49
98
|
if self.project_name not in project_list:
|
50
|
-
|
51
|
-
|
99
|
+
logger.error("Project not found. Please enter a valid project name")
|
100
|
+
return
|
52
101
|
|
53
102
|
self.headers = {
|
54
103
|
"Authorization": f'Bearer {os.getenv("RAGAAI_CATALYST_TOKEN")}',
|
@@ -61,17 +110,19 @@ class PromptManager:
|
|
61
110
|
List all available prompts.
|
62
111
|
|
63
112
|
Returns:
|
64
|
-
list: A list of prompt names.
|
65
|
-
|
66
|
-
Raises:
|
67
|
-
requests.RequestException: If there's an error with the API request.
|
113
|
+
list: A list of prompt names, or empty list if error occurs.
|
68
114
|
"""
|
115
|
+
if not self.project_id:
|
116
|
+
logger.error("PromptManager not properly initialized, cannot list prompts")
|
117
|
+
return []
|
118
|
+
|
69
119
|
prompt = Prompt()
|
70
120
|
try:
|
71
121
|
prompt_list = prompt.list_prompts(self.base_url, self.headers, self.timeout)
|
72
122
|
return prompt_list
|
73
|
-
except
|
74
|
-
|
123
|
+
except Exception as e:
|
124
|
+
logger.error(f"Error listing prompts: {str(e)}")
|
125
|
+
return []
|
75
126
|
|
76
127
|
def get_prompt(self, prompt_name, version=None):
|
77
128
|
"""
|
@@ -82,34 +133,39 @@ class PromptManager:
|
|
82
133
|
version (str, optional): The version of the prompt. Defaults to None.
|
83
134
|
|
84
135
|
Returns:
|
85
|
-
PromptObject: An object representing the prompt.
|
86
|
-
|
87
|
-
Raises:
|
88
|
-
ValueError: If the prompt or version is not found.
|
89
|
-
requests.RequestException: If there's an error with the API request.
|
136
|
+
PromptObject: An object representing the prompt, or None if error occurs.
|
90
137
|
"""
|
138
|
+
if not self.project_id:
|
139
|
+
logger.error("PromptManager not properly initialized, cannot get prompt")
|
140
|
+
return None
|
141
|
+
|
91
142
|
try:
|
92
143
|
prompt_list = self.list_prompts()
|
93
|
-
except
|
94
|
-
|
144
|
+
except Exception as e:
|
145
|
+
logger.error(f"Error fetching prompt list: {str(e)}")
|
146
|
+
return None
|
95
147
|
|
96
148
|
if prompt_name not in prompt_list:
|
97
|
-
|
149
|
+
logger.error("Prompt not found. Please enter a valid prompt name")
|
150
|
+
return None
|
98
151
|
|
99
152
|
try:
|
100
153
|
prompt_versions = self.list_prompt_versions(prompt_name)
|
101
|
-
except
|
102
|
-
|
154
|
+
except Exception as e:
|
155
|
+
logger.error(f"Error fetching prompt versions: {str(e)}")
|
156
|
+
return None
|
103
157
|
|
104
158
|
if version and version not in prompt_versions.keys():
|
105
|
-
|
159
|
+
logger.error("Version not found. Please enter a valid version name")
|
160
|
+
return None
|
106
161
|
|
107
162
|
prompt = Prompt()
|
108
163
|
try:
|
109
164
|
prompt_object = prompt.get_prompt(self.base_url, self.headers, self.timeout, prompt_name, version)
|
110
165
|
return prompt_object
|
111
|
-
except
|
112
|
-
|
166
|
+
except Exception as e:
|
167
|
+
logger.error(f"Error fetching prompt: {str(e)}")
|
168
|
+
return None
|
113
169
|
|
114
170
|
def list_prompt_versions(self, prompt_name):
|
115
171
|
"""
|
@@ -119,26 +175,29 @@ class PromptManager:
|
|
119
175
|
prompt_name (str): The name of the prompt.
|
120
176
|
|
121
177
|
Returns:
|
122
|
-
dict: A dictionary mapping version names to prompt texts.
|
123
|
-
|
124
|
-
Raises:
|
125
|
-
ValueError: If the prompt is not found.
|
126
|
-
requests.RequestException: If there's an error with the API request.
|
178
|
+
dict: A dictionary mapping version names to prompt texts, or empty dict if error occurs.
|
127
179
|
"""
|
180
|
+
if not self.project_id:
|
181
|
+
logger.error("PromptManager not properly initialized, cannot list prompt versions")
|
182
|
+
return {}
|
183
|
+
|
128
184
|
try:
|
129
185
|
prompt_list = self.list_prompts()
|
130
|
-
except
|
131
|
-
|
186
|
+
except Exception as e:
|
187
|
+
logger.error(f"Error fetching prompt list: {str(e)}")
|
188
|
+
return {}
|
132
189
|
|
133
190
|
if prompt_name not in prompt_list:
|
134
|
-
|
191
|
+
logger.error("Prompt not found. Please enter a valid prompt name")
|
192
|
+
return {}
|
135
193
|
|
136
194
|
prompt = Prompt()
|
137
195
|
try:
|
138
196
|
prompt_versions = prompt.list_prompt_versions(self.base_url, self.headers, self.timeout, prompt_name)
|
139
197
|
return prompt_versions
|
140
|
-
except
|
141
|
-
|
198
|
+
except Exception as e:
|
199
|
+
logger.error(f"Error fetching prompt versions: {str(e)}")
|
200
|
+
return {}
|
142
201
|
|
143
202
|
|
144
203
|
class Prompt:
|
@@ -158,21 +217,48 @@ class Prompt:
|
|
158
217
|
timeout (int): The timeout for the request.
|
159
218
|
|
160
219
|
Returns:
|
161
|
-
list: A list of prompt names.
|
162
|
-
|
163
|
-
Raises:
|
164
|
-
requests.RequestException: If there's an error with the API request.
|
165
|
-
ValueError: If there's an error parsing the prompt list.
|
220
|
+
list: A list of prompt names, or empty list if error occurs.
|
166
221
|
"""
|
167
222
|
try:
|
168
|
-
|
169
|
-
response.
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
223
|
+
start_time = time.time()
|
224
|
+
response = session_manager.make_request_with_retry("GET", url, headers=headers, timeout=timeout)
|
225
|
+
elapsed_ms = (time.time() - start_time) * 1000
|
226
|
+
logger.debug(f"API Call: [GET] {url} | Status: {response.status_code} | Time: {elapsed_ms:.2f}ms")
|
227
|
+
|
228
|
+
if response.status_code in [200, 201]:
|
229
|
+
prompt_list = [prompt["name"] for prompt in response.json()["data"]]
|
230
|
+
return prompt_list
|
231
|
+
elif response.status_code == 401:
|
232
|
+
logger.warning("Received 401 error during listing prompts. Attempting to refresh token.")
|
233
|
+
token = RagaAICatalyst.get_token(force_refresh=True)
|
234
|
+
new_headers = headers.copy()
|
235
|
+
new_headers["Authorization"] = f"Bearer {token}"
|
236
|
+
|
237
|
+
start_time = time.time()
|
238
|
+
response = session_manager.make_request_with_retry("GET", url, headers=new_headers, timeout=timeout)
|
239
|
+
elapsed_ms = (time.time() - start_time) * 1000
|
240
|
+
logger.debug(f"API Call: [GET] {url} (retry) | Status: {response.status_code} | Time: {elapsed_ms:.2f}ms")
|
241
|
+
|
242
|
+
if response.status_code in [200, 201]:
|
243
|
+
logger.info("Prompts listed successfully after 401 token refresh")
|
244
|
+
prompt_list = [prompt["name"] for prompt in response.json()["data"]]
|
245
|
+
return prompt_list
|
246
|
+
else:
|
247
|
+
logger.error("Failed to list prompts after 401 token refresh")
|
248
|
+
return []
|
249
|
+
else:
|
250
|
+
logger.error(f"HTTP {response.status_code} error when listing prompts")
|
251
|
+
return []
|
252
|
+
|
253
|
+
except (PoolError, MaxRetryError, NewConnectionError, ConnectionError, Timeout, RemoteDisconnected) as e:
|
254
|
+
session_manager.handle_request_exceptions(e, "listing prompts")
|
255
|
+
return []
|
256
|
+
except RequestException as e:
|
257
|
+
logger.error(f"Error while listing prompts: {e}")
|
258
|
+
return []
|
174
259
|
except (KeyError, json.JSONDecodeError) as e:
|
175
|
-
|
260
|
+
logger.error(f"Error parsing prompt list: {str(e)}")
|
261
|
+
return []
|
176
262
|
|
177
263
|
def _get_response_by_version(self, base_url, headers, timeout, prompt_name, version):
|
178
264
|
"""
|
@@ -186,21 +272,47 @@ class Prompt:
|
|
186
272
|
version (str): The version of the prompt.
|
187
273
|
|
188
274
|
Returns:
|
189
|
-
response: The response object containing the prompt version data.
|
190
|
-
|
191
|
-
Raises:
|
192
|
-
requests.RequestException: If there's an error with the API request.
|
193
|
-
ValueError: If there's an error parsing the prompt version.
|
275
|
+
response: The response object containing the prompt version data, or None if error occurs.
|
194
276
|
"""
|
195
277
|
try:
|
196
|
-
|
197
|
-
|
198
|
-
response.
|
199
|
-
|
200
|
-
|
278
|
+
url = f"{base_url}/version/{prompt_name}?version={version}"
|
279
|
+
start_time = time.time()
|
280
|
+
response = session_manager.make_request_with_retry("GET", url, headers=headers, timeout=timeout)
|
281
|
+
elapsed_ms = (time.time() - start_time) * 1000
|
282
|
+
logger.debug(f"API Call: [GET] {url} | Status: {response.status_code} | Time: {elapsed_ms:.2f}ms")
|
283
|
+
|
284
|
+
if response.status_code in [200, 201]:
|
285
|
+
return response
|
286
|
+
elif response.status_code == 401:
|
287
|
+
logger.warning(f"Received 401 error during fetching prompt version {version} for {prompt_name}. Attempting to refresh token.")
|
288
|
+
token = RagaAICatalyst.get_token(force_refresh=True)
|
289
|
+
new_headers = headers.copy()
|
290
|
+
new_headers["Authorization"] = f"Bearer {token}"
|
291
|
+
|
292
|
+
start_time = time.time()
|
293
|
+
response = session_manager.make_request_with_retry("GET", url, headers=new_headers, timeout=timeout)
|
294
|
+
elapsed_ms = (time.time() - start_time) * 1000
|
295
|
+
logger.debug(f"API Call: [GET] {url} (retry) | Status: {response.status_code} | Time: {elapsed_ms:.2f}ms")
|
296
|
+
|
297
|
+
if response.status_code in [200, 201]:
|
298
|
+
logger.info(f"Prompt version {version} for {prompt_name} fetched successfully after 401 token refresh")
|
299
|
+
return response
|
300
|
+
else:
|
301
|
+
logger.error(f"Failed to fetch prompt version {version} for {prompt_name} after 401 token refresh")
|
302
|
+
return None
|
303
|
+
else:
|
304
|
+
logger.error(f"HTTP {response.status_code} error when fetching prompt version {version} for {prompt_name}")
|
305
|
+
return None
|
306
|
+
|
307
|
+
except (PoolError, MaxRetryError, NewConnectionError, ConnectionError, Timeout, RemoteDisconnected) as e:
|
308
|
+
session_manager.handle_request_exceptions(e, f"fetching prompt version {version} for {prompt_name}")
|
309
|
+
return None
|
310
|
+
except RequestException as e:
|
311
|
+
logger.error(f"Error while fetching prompt version {version} for {prompt_name}: {e}")
|
312
|
+
return None
|
201
313
|
except (KeyError, json.JSONDecodeError, IndexError) as e:
|
202
|
-
|
203
|
-
|
314
|
+
logger.error(f"Error parsing prompt version: {str(e)}")
|
315
|
+
return None
|
204
316
|
|
205
317
|
def _get_response(self, base_url, headers, timeout, prompt_name):
|
206
318
|
"""
|
@@ -213,21 +325,47 @@ class Prompt:
|
|
213
325
|
prompt_name (str): The name of the prompt.
|
214
326
|
|
215
327
|
Returns:
|
216
|
-
response: The response object containing the latest prompt version data.
|
217
|
-
|
218
|
-
Raises:
|
219
|
-
requests.RequestException: If there's an error with the API request.
|
220
|
-
ValueError: If there's an error parsing the prompt version.
|
328
|
+
response: The response object containing the latest prompt version data, or None if error occurs.
|
221
329
|
"""
|
222
330
|
try:
|
223
|
-
|
224
|
-
|
225
|
-
response.
|
226
|
-
|
227
|
-
|
331
|
+
url = f"{base_url}/version/{prompt_name}"
|
332
|
+
start_time = time.time()
|
333
|
+
response = session_manager.make_request_with_retry("GET", url, headers=headers, timeout=timeout)
|
334
|
+
elapsed_ms = (time.time() - start_time) * 1000
|
335
|
+
logger.debug(f"API Call: [GET] {url} | Status: {response.status_code} | Time: {elapsed_ms:.2f}ms")
|
336
|
+
|
337
|
+
if response.status_code in [200, 201]:
|
338
|
+
return response
|
339
|
+
elif response.status_code == 401:
|
340
|
+
logger.warning(f"Received 401 error during fetching latest prompt version for {prompt_name}. Attempting to refresh token.")
|
341
|
+
token = RagaAICatalyst.get_token(force_refresh=True)
|
342
|
+
new_headers = headers.copy()
|
343
|
+
new_headers["Authorization"] = f"Bearer {token}"
|
344
|
+
|
345
|
+
start_time = time.time()
|
346
|
+
response = session_manager.make_request_with_retry("GET", url, headers=new_headers, timeout=timeout)
|
347
|
+
elapsed_ms = (time.time() - start_time) * 1000
|
348
|
+
logger.debug(f"API Call: [GET] {url} (retry) | Status: {response.status_code} | Time: {elapsed_ms:.2f}ms")
|
349
|
+
|
350
|
+
if response.status_code in [200, 201]:
|
351
|
+
logger.info(f"Latest prompt version for {prompt_name} fetched successfully after 401 token refresh")
|
352
|
+
return response
|
353
|
+
else:
|
354
|
+
logger.error(f"Failed to fetch latest prompt version for {prompt_name} after 401 token refresh")
|
355
|
+
return None
|
356
|
+
else:
|
357
|
+
logger.error(f"HTTP {response.status_code} error when fetching latest prompt version for {prompt_name}")
|
358
|
+
return None
|
359
|
+
|
360
|
+
except (PoolError, MaxRetryError, NewConnectionError, ConnectionError, Timeout, RemoteDisconnected) as e:
|
361
|
+
session_manager.handle_request_exceptions(e, f"fetching latest prompt version for {prompt_name}")
|
362
|
+
return None
|
363
|
+
except RequestException as e:
|
364
|
+
logger.error(f"Error while fetching latest prompt version for {prompt_name}: {e}")
|
365
|
+
return None
|
228
366
|
except (KeyError, json.JSONDecodeError, IndexError) as e:
|
229
|
-
|
230
|
-
|
367
|
+
logger.error(f"Error parsing prompt version: {str(e)}")
|
368
|
+
return None
|
231
369
|
|
232
370
|
def _get_prompt_by_version(self, base_url, headers, timeout, prompt_name, version):
|
233
371
|
"""
|
@@ -241,14 +379,17 @@ class Prompt:
|
|
241
379
|
version (str): The version of the prompt.
|
242
380
|
|
243
381
|
Returns:
|
244
|
-
str: The text of the prompt.
|
245
|
-
|
246
|
-
Raises:
|
247
|
-
requests.RequestException: If there's an error with the API request.
|
382
|
+
str: The text of the prompt, or empty string if error occurs.
|
248
383
|
"""
|
249
384
|
response = self._get_response_by_version(base_url, headers, timeout, prompt_name, version)
|
250
|
-
|
251
|
-
|
385
|
+
if response is None:
|
386
|
+
return ""
|
387
|
+
try:
|
388
|
+
prompt_text = response.json()["data"]["docs"][0]["textFields"]
|
389
|
+
return prompt_text
|
390
|
+
except (KeyError, json.JSONDecodeError, IndexError) as e:
|
391
|
+
logger.error(f"Error parsing prompt text: {str(e)}")
|
392
|
+
return ""
|
252
393
|
|
253
394
|
def get_prompt(self, base_url, headers, timeout, prompt_name, version=None):
|
254
395
|
"""
|
@@ -262,22 +403,24 @@ class Prompt:
|
|
262
403
|
version (str, optional): The version of the prompt. Defaults to None.
|
263
404
|
|
264
405
|
Returns:
|
265
|
-
PromptObject: An object representing the prompt.
|
266
|
-
|
267
|
-
Raises:
|
268
|
-
requests.RequestException: If there's an error with the API request.
|
406
|
+
PromptObject: An object representing the prompt, or None if error occurs.
|
269
407
|
"""
|
270
408
|
if version:
|
271
409
|
response = self._get_response_by_version(base_url, headers, timeout, prompt_name, version)
|
272
|
-
prompt_text = response.json()["data"]["docs"][0]["textFields"]
|
273
|
-
prompt_parameters = response.json()["data"]["docs"][0]["modelSpecs"]["parameters"]
|
274
|
-
model = response.json()["data"]["docs"][0]["modelSpecs"]["model"]
|
275
410
|
else:
|
276
411
|
response = self._get_response(base_url, headers, timeout, prompt_name)
|
412
|
+
|
413
|
+
if response is None:
|
414
|
+
return None
|
415
|
+
|
416
|
+
try:
|
277
417
|
prompt_text = response.json()["data"]["docs"][0]["textFields"]
|
278
418
|
prompt_parameters = response.json()["data"]["docs"][0]["modelSpecs"]["parameters"]
|
279
419
|
model = response.json()["data"]["docs"][0]["modelSpecs"]["model"]
|
280
|
-
|
420
|
+
return PromptObject(prompt_text, prompt_parameters, model)
|
421
|
+
except (KeyError, json.JSONDecodeError, IndexError) as e:
|
422
|
+
logger.error(f"Error parsing prompt data: {str(e)}")
|
423
|
+
return None
|
281
424
|
|
282
425
|
|
283
426
|
def list_prompt_versions(self, base_url, headers, timeout, prompt_name):
|
@@ -291,25 +434,55 @@ class Prompt:
|
|
291
434
|
prompt_name (str): The name of the prompt.
|
292
435
|
|
293
436
|
Returns:
|
294
|
-
dict: A dictionary mapping version names to prompt texts.
|
295
|
-
|
296
|
-
Raises:
|
297
|
-
requests.RequestException: If there's an error with the API request.
|
298
|
-
ValueError: If there's an error parsing the prompt versions.
|
437
|
+
dict: A dictionary mapping version names to prompt texts, or empty dict if error occurs.
|
299
438
|
"""
|
300
439
|
try:
|
301
|
-
|
302
|
-
|
303
|
-
response.
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
440
|
+
url = f"{base_url}/{prompt_name}/version"
|
441
|
+
start_time = time.time()
|
442
|
+
response = session_manager.make_request_with_retry("GET", url, headers=headers, timeout=timeout)
|
443
|
+
elapsed_ms = (time.time() - start_time) * 1000
|
444
|
+
logger.debug(f"API Call: [GET] {url} | Status: {response.status_code} | Time: {elapsed_ms:.2f}ms")
|
445
|
+
|
446
|
+
if response.status_code in [200, 201]:
|
447
|
+
version_names = [version["name"] for version in response.json()["data"]]
|
448
|
+
prompt_versions = {}
|
449
|
+
for version in version_names:
|
450
|
+
prompt_versions[version] = self._get_prompt_by_version(base_url, headers, timeout, prompt_name, version)
|
451
|
+
return prompt_versions
|
452
|
+
elif response.status_code == 401:
|
453
|
+
logger.warning(f"Received 401 error during listing prompt versions for {prompt_name}. Attempting to refresh token.")
|
454
|
+
token = RagaAICatalyst.get_token(force_refresh=True)
|
455
|
+
new_headers = headers.copy()
|
456
|
+
new_headers["Authorization"] = f"Bearer {token}"
|
457
|
+
|
458
|
+
start_time = time.time()
|
459
|
+
response = session_manager.make_request_with_retry("GET", url, headers=new_headers, timeout=timeout)
|
460
|
+
elapsed_ms = (time.time() - start_time) * 1000
|
461
|
+
logger.debug(f"API Call: [GET] {url} (retry) | Status: {response.status_code} | Time: {elapsed_ms:.2f}ms")
|
462
|
+
|
463
|
+
if response.status_code in [200, 201]:
|
464
|
+
logger.info(f"Prompt versions for {prompt_name} listed successfully after 401 token refresh")
|
465
|
+
version_names = [version["name"] for version in response.json()["data"]]
|
466
|
+
prompt_versions = {}
|
467
|
+
for version in version_names:
|
468
|
+
prompt_versions[version] = self._get_prompt_by_version(base_url, new_headers, timeout, prompt_name, version)
|
469
|
+
return prompt_versions
|
470
|
+
else:
|
471
|
+
logger.error(f"Failed to list prompt versions for {prompt_name} after 401 token refresh")
|
472
|
+
return {}
|
473
|
+
else:
|
474
|
+
logger.error(f"HTTP {response.status_code} error when listing prompt versions for {prompt_name}")
|
475
|
+
return {}
|
476
|
+
|
477
|
+
except (PoolError, MaxRetryError, NewConnectionError, ConnectionError, Timeout, RemoteDisconnected) as e:
|
478
|
+
session_manager.handle_request_exceptions(e, f"listing prompt versions for {prompt_name}")
|
479
|
+
return {}
|
480
|
+
except RequestException as e:
|
481
|
+
logger.error(f"Error while listing prompt versions for {prompt_name}: {e}")
|
482
|
+
return {}
|
311
483
|
except (KeyError, json.JSONDecodeError) as e:
|
312
|
-
|
484
|
+
logger.error(f"Error parsing prompt versions: {str(e)}")
|
485
|
+
return {}
|
313
486
|
|
314
487
|
|
315
488
|
class PromptObject:
|
@@ -325,7 +498,7 @@ class PromptObject:
|
|
325
498
|
self.text = text
|
326
499
|
self.parameters = parameters
|
327
500
|
self.model = model
|
328
|
-
|
501
|
+
|
329
502
|
def _extract_variable_from_content(self, content):
|
330
503
|
"""
|
331
504
|
Extract variables from the content.
|
@@ -3,22 +3,16 @@ trace_uploader.py - A dedicated process for handling trace uploads
|
|
3
3
|
"""
|
4
4
|
|
5
5
|
import os
|
6
|
-
import sys
|
7
6
|
import json
|
8
7
|
import time
|
9
|
-
import signal
|
10
8
|
import logging
|
11
9
|
import argparse
|
12
10
|
import tempfile
|
13
|
-
from pathlib import Path
|
14
|
-
import multiprocessing
|
15
|
-
import queue
|
16
11
|
from datetime import datetime
|
17
12
|
import atexit
|
18
|
-
import glob
|
19
13
|
from logging.handlers import RotatingFileHandler
|
20
14
|
import concurrent.futures
|
21
|
-
from typing import Dict, Any
|
15
|
+
from typing import Dict, Any
|
22
16
|
import threading
|
23
17
|
import uuid
|
24
18
|
|
@@ -50,7 +44,7 @@ try:
|
|
50
44
|
from ragaai_catalyst.tracers.agentic_tracing.upload.upload_code import upload_code
|
51
45
|
# from ragaai_catalyst.tracers.agentic_tracing.upload.upload_trace_metric import upload_trace_metric
|
52
46
|
from ragaai_catalyst.tracers.agentic_tracing.utils.create_dataset_schema import create_dataset_schema_with_trace
|
53
|
-
from ragaai_catalyst.
|
47
|
+
from ragaai_catalyst.session_manager import session_manager
|
54
48
|
from ragaai_catalyst import RagaAICatalyst
|
55
49
|
IMPORTS_AVAILABLE = True
|
56
50
|
except ImportError:
|
@@ -7,7 +7,7 @@ from urllib.parse import urlparse, urlunparse
|
|
7
7
|
from urllib3.exceptions import PoolError, MaxRetryError, NewConnectionError
|
8
8
|
from requests.exceptions import ConnectionError, Timeout, RequestException
|
9
9
|
from http.client import RemoteDisconnected
|
10
|
-
from .session_manager import session_manager
|
10
|
+
from ragaai_catalyst.session_manager import session_manager
|
11
11
|
|
12
12
|
logger = logging.getLogger(__name__)
|
13
13
|
|
@@ -9,7 +9,7 @@ from requests.exceptions import ConnectionError, Timeout, RequestException
|
|
9
9
|
from http.client import RemoteDisconnected
|
10
10
|
|
11
11
|
from ragaai_catalyst.ragaai_catalyst import RagaAICatalyst
|
12
|
-
from .session_manager import session_manager
|
12
|
+
from ragaai_catalyst.session_manager import session_manager
|
13
13
|
|
14
14
|
logger = logging.getLogger(__name__)
|
15
15
|
|
@@ -9,7 +9,7 @@ from requests.exceptions import ConnectionError, Timeout, RequestException
|
|
9
9
|
from http.client import RemoteDisconnected
|
10
10
|
|
11
11
|
from ragaai_catalyst import RagaAICatalyst
|
12
|
-
from ragaai_catalyst.
|
12
|
+
from ragaai_catalyst.session_manager import session_manager
|
13
13
|
|
14
14
|
IGNORED_KEYS = {"log_source", "recorded_on"}
|
15
15
|
logger = logging.getLogger(__name__)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: ragaai_catalyst
|
3
|
-
Version: 2.2.
|
3
|
+
Version: 2.2.6b1
|
4
4
|
Summary: RAGA AI CATALYST
|
5
5
|
Author-email: Kiran Scaria <kiran.scaria@raga.ai>, Kedar Gaikwad <kedar.gaikwad@raga.ai>, Dushyant Mahajan <dushyant.mahajan@raga.ai>, Siddhartha Kosti <siddhartha.kosti@raga.ai>, Ritika Goel <ritika.goel@raga.ai>, Vijay Chaurasia <vijay.chaurasia@raga.ai>, Tushar Kumar <tushar.kumar@raga.ai>, Rishabh Pandey <rishabh.pandey@raga.ai>, Jyotsana C G <jyotsana@raga.ai>
|
6
6
|
Requires-Python: <=3.13.2,>=3.10
|
@@ -5,10 +5,11 @@ ragaai_catalyst/evaluation.py,sha256=8P2zUMSMsQGmKdv7_dZ8F0iXWYddvappgKPN5oJXWuY
|
|
5
5
|
ragaai_catalyst/guard_executor.py,sha256=VLqVO1gAEBaovoQQUjdNkivH1dXACFTsuXQ1nzAALQQ,14008
|
6
6
|
ragaai_catalyst/guardrails_manager.py,sha256=_VrARJ1udmCF8TklNKy7XTQUaM8ATDhTOAGDonBkFro,14245
|
7
7
|
ragaai_catalyst/internal_api_completion.py,sha256=DdICI5yfEudiOAIC8L4oxH0Qz7kX-BZCdo9IWsi2gNo,2965
|
8
|
-
ragaai_catalyst/prompt_manager.py,sha256=
|
8
|
+
ragaai_catalyst/prompt_manager.py,sha256=9IoCTxjCY9FKopq6BoB0fVb3FtuSj3BBsNyD9AeH7ds,26265
|
9
9
|
ragaai_catalyst/proxy_call.py,sha256=CHxldeceZUaLU-to_hs_Kf1z_b2vHMssLS_cOBedu78,5499
|
10
10
|
ragaai_catalyst/ragaai_catalyst.py,sha256=ZlcpOgJA9lVRi51YFy4dVfsxU0I79LJu0MnVI5BIL-c,25201
|
11
11
|
ragaai_catalyst/redteaming_old.py,sha256=W2d89Ok8W-C8g7TBM3fDIFLof3q9FuYSr0jcryH2XQo,7097
|
12
|
+
ragaai_catalyst/session_manager.py,sha256=sOlxeIYIP8tycaTtZC9xkZosi6EDJUxvDw0_rc_NLI8,6823
|
12
13
|
ragaai_catalyst/synthetic_data_generation.py,sha256=AumjIzKk-Uvn7RQGatpx7TPvlI4NjU-rUiVFockoGNg,37969
|
13
14
|
ragaai_catalyst/utils.py,sha256=TlhEFwLyRU690HvANbyoRycR3nQ67lxVUQoUOfTPYQ0,3772
|
14
15
|
ragaai_catalyst/redteaming/__init__.py,sha256=TJdvZpaZGFsg9qKONdjTosSVLZGadYFpHG6KE0xapKU,155
|
@@ -35,12 +36,11 @@ ragaai_catalyst/tracers/agentic_tracing/data/data_structure.py,sha256=icAtNzKN_I
|
|
35
36
|
ragaai_catalyst/tracers/agentic_tracing/tracers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
36
37
|
ragaai_catalyst/tracers/agentic_tracing/tracers/main_tracer.py,sha256=Wq4LFclPlLy47LyXvbaLeYiSMQABj7VYS3J87xyea_E,4159
|
37
38
|
ragaai_catalyst/tracers/agentic_tracing/upload/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
38
|
-
ragaai_catalyst/tracers/agentic_tracing/upload/
|
39
|
-
ragaai_catalyst/tracers/agentic_tracing/upload/
|
40
|
-
ragaai_catalyst/tracers/agentic_tracing/upload/
|
41
|
-
ragaai_catalyst/tracers/agentic_tracing/upload/upload_code.py,sha256=IAhNFS-nbV_ImNz8Xp98qU4r-2naj49qg9q08x53TFE,12521
|
39
|
+
ragaai_catalyst/tracers/agentic_tracing/upload/trace_uploader.py,sha256=mDpLqTE6j7gnxTS1Siev-gW_mnUJ086UB5l1bBoA9vU,25007
|
40
|
+
ragaai_catalyst/tracers/agentic_tracing/upload/upload_agentic_traces.py,sha256=oAiP6k3wYc6LTi4tHQctTMhTzpk492x5JTt5wEKcwC4,14541
|
41
|
+
ragaai_catalyst/tracers/agentic_tracing/upload/upload_code.py,sha256=a3pqyVvu5OJ9oDesHO6TeeCPHG-V0RSu1ZLKB-rYxCw,12536
|
42
42
|
ragaai_catalyst/tracers/agentic_tracing/utils/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
43
|
-
ragaai_catalyst/tracers/agentic_tracing/utils/create_dataset_schema.py,sha256=
|
43
|
+
ragaai_catalyst/tracers/agentic_tracing/utils/create_dataset_schema.py,sha256=GJex8B7mgzFDQgxzFIolce0RUWGYRYog_ijkC9nNt1E,3856
|
44
44
|
ragaai_catalyst/tracers/agentic_tracing/utils/file_name_tracker.py,sha256=YG601l1a29ov9VPu9Vl4RXxgL7l16k54_WWnoTNoG58,2064
|
45
45
|
ragaai_catalyst/tracers/agentic_tracing/utils/llm_utils.py,sha256=PiyXvEj_qu0EnJFjk4GfGyWFZbwlvQQh0hdQ_lm0p8E,22976
|
46
46
|
ragaai_catalyst/tracers/agentic_tracing/utils/model_costs.json,sha256=2tzGw_cKCTPcfjEm7iGvFE6pTw7gMTPzeBov_MTaXNY,321336
|
@@ -58,8 +58,8 @@ ragaai_catalyst/tracers/utils/model_prices_and_context_window_backup.json,sha256
|
|
58
58
|
ragaai_catalyst/tracers/utils/rag_extraction_logic_final.py,sha256=3ygkRT__lLDRflRttjzPu28tIA8cTCiGQVMQjqMItqQ,11309
|
59
59
|
ragaai_catalyst/tracers/utils/trace_json_converter.py,sha256=NPsxU04u6MCOMqisrgiAIv1bXFjWNwlrUn-LScC8f-s,12109
|
60
60
|
ragaai_catalyst/tracers/utils/utils.py,sha256=o-p9n2ZuophdrV0wrixu-BqRHCkovup_klc3mS8mU8g,2374
|
61
|
-
ragaai_catalyst-2.2.
|
62
|
-
ragaai_catalyst-2.2.
|
63
|
-
ragaai_catalyst-2.2.
|
64
|
-
ragaai_catalyst-2.2.
|
65
|
-
ragaai_catalyst-2.2.
|
61
|
+
ragaai_catalyst-2.2.6b1.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
62
|
+
ragaai_catalyst-2.2.6b1.dist-info/METADATA,sha256=qNKQxUD_sI5zPNeZFouH9xRsPdo1Wb0IxrLwAKB-ldg,17735
|
63
|
+
ragaai_catalyst-2.2.6b1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
64
|
+
ragaai_catalyst-2.2.6b1.dist-info/top_level.txt,sha256=HpgsdRgEJMk8nqrU6qdCYk3di7MJkDL0B19lkc7dLfM,16
|
65
|
+
ragaai_catalyst-2.2.6b1.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|