beekeeper-monitors-watsonx 1.1.1__py3-none-any.whl → 1.1.2__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.
- beekeeper/monitors/watsonx/base.py +141 -2
- beekeeper/monitors/watsonx/supporting_classes/enums.py +13 -0
- {beekeeper_monitors_watsonx-1.1.1.dist-info → beekeeper_monitors_watsonx-1.1.2.dist-info}/METADATA +1 -1
- {beekeeper_monitors_watsonx-1.1.1.dist-info → beekeeper_monitors_watsonx-1.1.2.dist-info}/RECORD +5 -5
- {beekeeper_monitors_watsonx-1.1.1.dist-info → beekeeper_monitors_watsonx-1.1.2.dist-info}/WHEEL +0 -0
|
@@ -202,6 +202,40 @@ class WatsonxExternalPromptMonitor(PromptMonitor):
|
|
|
202
202
|
|
|
203
203
|
return created_detached_pta.to_dict()["asset_id"]
|
|
204
204
|
|
|
205
|
+
def _delete_detached_prompt(self, detached_pta_id: str) -> None:
|
|
206
|
+
from ibm_aigov_facts_client import ( # type: ignore
|
|
207
|
+
AIGovFactsClient,
|
|
208
|
+
CloudPakforDataConfig,
|
|
209
|
+
)
|
|
210
|
+
|
|
211
|
+
try:
|
|
212
|
+
if hasattr(self, "_fact_cpd_creds") and self._fact_cpd_creds:
|
|
213
|
+
cpd_creds = CloudPakforDataConfig(**self._fact_cpd_creds)
|
|
214
|
+
|
|
215
|
+
aigov_client = AIGovFactsClient(
|
|
216
|
+
container_id=self._container_id,
|
|
217
|
+
container_type=self._container_type,
|
|
218
|
+
cloud_pak_for_data_configs=cpd_creds,
|
|
219
|
+
disable_tracing=True,
|
|
220
|
+
)
|
|
221
|
+
|
|
222
|
+
else:
|
|
223
|
+
aigov_client = AIGovFactsClient(
|
|
224
|
+
api_key=self._api_key,
|
|
225
|
+
container_id=self._container_id,
|
|
226
|
+
container_type=self._container_type,
|
|
227
|
+
disable_tracing=True,
|
|
228
|
+
region=self.region.factsheet,
|
|
229
|
+
)
|
|
230
|
+
|
|
231
|
+
except Exception as e:
|
|
232
|
+
logging.error(
|
|
233
|
+
f"Error connecting to IBM watsonx.governance (factsheets): {e}",
|
|
234
|
+
)
|
|
235
|
+
raise
|
|
236
|
+
|
|
237
|
+
suppress_output(aigov_client.assets.delete_prompt_asset, detached_pta_id)
|
|
238
|
+
|
|
205
239
|
def _create_deployment_pta(self, asset_id: str, name: str, model_id: str) -> str:
|
|
206
240
|
from ibm_watsonx_ai import APIClient, Credentials # type: ignore
|
|
207
241
|
|
|
@@ -239,6 +273,30 @@ class WatsonxExternalPromptMonitor(PromptMonitor):
|
|
|
239
273
|
|
|
240
274
|
return wml_client.deployments.get_uid(created_deployment)
|
|
241
275
|
|
|
276
|
+
def _delete_deployment_pta(self, deployment_id: str):
|
|
277
|
+
from ibm_watsonx_ai import APIClient, Credentials # type: ignore
|
|
278
|
+
|
|
279
|
+
try:
|
|
280
|
+
if hasattr(self, "_wml_cpd_creds") and self._wml_cpd_creds:
|
|
281
|
+
creds = Credentials(**self._wml_cpd_creds)
|
|
282
|
+
|
|
283
|
+
wml_client = APIClient(creds)
|
|
284
|
+
wml_client.set.default_space(self.space_id)
|
|
285
|
+
|
|
286
|
+
else:
|
|
287
|
+
creds = Credentials(
|
|
288
|
+
url=self.region.watsonxai,
|
|
289
|
+
api_key=self._api_key,
|
|
290
|
+
)
|
|
291
|
+
wml_client = APIClient(creds)
|
|
292
|
+
wml_client.set.default_space(self.space_id)
|
|
293
|
+
|
|
294
|
+
except Exception as e:
|
|
295
|
+
logging.error(f"Error connecting to IBM watsonx.ai Runtime: {e}")
|
|
296
|
+
raise
|
|
297
|
+
|
|
298
|
+
suppress_output(wml_client.deployments.delete, deployment_id)
|
|
299
|
+
|
|
242
300
|
@deprecated(
|
|
243
301
|
reason="'add_prompt_observer()' is deprecated and will be removed in a future version. Use 'create_prompt_monitor()' instead.",
|
|
244
302
|
version="1.0.5",
|
|
@@ -381,6 +439,8 @@ class WatsonxExternalPromptMonitor(PromptMonitor):
|
|
|
381
439
|
```
|
|
382
440
|
"""
|
|
383
441
|
task_id = TaskType.from_value(task_id).value
|
|
442
|
+
rollback_stack = []
|
|
443
|
+
|
|
384
444
|
# DEPRECATION NOTICE
|
|
385
445
|
if input_text is not None:
|
|
386
446
|
warnings.warn(
|
|
@@ -493,11 +553,14 @@ class WatsonxExternalPromptMonitor(PromptMonitor):
|
|
|
493
553
|
prompt_details,
|
|
494
554
|
detached_asset_details,
|
|
495
555
|
)
|
|
556
|
+
rollback_stack.append(lambda: self._delete_detached_prompt(detached_pta_id))
|
|
557
|
+
|
|
496
558
|
deployment_id = None
|
|
497
559
|
if self._container_type == "space":
|
|
498
560
|
deployment_id = suppress_output(
|
|
499
561
|
self._create_deployment_pta, detached_pta_id, name, model_id
|
|
500
562
|
)
|
|
563
|
+
rollback_stack.append(lambda: self._delete_deployment_pta(deployment_id))
|
|
501
564
|
|
|
502
565
|
monitors = {
|
|
503
566
|
"generative_ai_quality": {
|
|
@@ -558,10 +621,17 @@ class WatsonxExternalPromptMonitor(PromptMonitor):
|
|
|
558
621
|
|
|
559
622
|
generative_ai_monitor_details = generative_ai_monitor_details.result._to_dict()
|
|
560
623
|
|
|
624
|
+
wos_status = generative_ai_monitor_details.get("status", {})
|
|
625
|
+
if wos_status.get("state") == "ERROR":
|
|
626
|
+
for rollback_step in reversed(rollback_stack):
|
|
627
|
+
rollback_step()
|
|
628
|
+
raise Exception(wos_status.get("failure"))
|
|
629
|
+
|
|
630
|
+
|
|
561
631
|
return {
|
|
562
632
|
"detached_prompt_template_asset_id": detached_pta_id,
|
|
563
633
|
"deployment_id": deployment_id,
|
|
564
|
-
"subscription_id": generative_ai_monitor_details
|
|
634
|
+
"subscription_id": generative_ai_monitor_details.get("subscription_id", None),
|
|
565
635
|
}
|
|
566
636
|
|
|
567
637
|
def store_payload_records(
|
|
@@ -938,6 +1008,40 @@ class WatsonxPromptMonitor(PromptMonitor):
|
|
|
938
1008
|
|
|
939
1009
|
return created_pta.to_dict()["asset_id"]
|
|
940
1010
|
|
|
1011
|
+
def _delete_prompt(self, pta_id: str) -> None:
|
|
1012
|
+
from ibm_aigov_facts_client import ( # type: ignore
|
|
1013
|
+
AIGovFactsClient,
|
|
1014
|
+
CloudPakforDataConfig,
|
|
1015
|
+
)
|
|
1016
|
+
|
|
1017
|
+
try:
|
|
1018
|
+
if hasattr(self, "_fact_cpd_creds") and self._fact_cpd_creds:
|
|
1019
|
+
cpd_creds = CloudPakforDataConfig(**self._fact_cpd_creds)
|
|
1020
|
+
|
|
1021
|
+
aigov_client = AIGovFactsClient(
|
|
1022
|
+
container_id=self._container_id,
|
|
1023
|
+
container_type=self._container_type,
|
|
1024
|
+
cloud_pak_for_data_configs=cpd_creds,
|
|
1025
|
+
disable_tracing=True,
|
|
1026
|
+
)
|
|
1027
|
+
|
|
1028
|
+
else:
|
|
1029
|
+
aigov_client = AIGovFactsClient(
|
|
1030
|
+
api_key=self._api_key,
|
|
1031
|
+
container_id=self._container_id,
|
|
1032
|
+
container_type=self._container_type,
|
|
1033
|
+
disable_tracing=True,
|
|
1034
|
+
region=self.region.factsheet,
|
|
1035
|
+
)
|
|
1036
|
+
|
|
1037
|
+
except Exception as e:
|
|
1038
|
+
logging.error(
|
|
1039
|
+
f"Error connecting to IBM watsonx.governance (factsheets): {e}",
|
|
1040
|
+
)
|
|
1041
|
+
raise
|
|
1042
|
+
|
|
1043
|
+
suppress_output(aigov_client.assets.delete_prompt_asset, pta_id)
|
|
1044
|
+
|
|
941
1045
|
def _create_deployment_pta(self, asset_id: str, name: str, model_id: str) -> str:
|
|
942
1046
|
from ibm_watsonx_ai import APIClient, Credentials # type: ignore
|
|
943
1047
|
|
|
@@ -976,6 +1080,30 @@ class WatsonxPromptMonitor(PromptMonitor):
|
|
|
976
1080
|
|
|
977
1081
|
return wml_client.deployments.get_uid(created_deployment)
|
|
978
1082
|
|
|
1083
|
+
def _delete_deployment_pta(self, deployment_id: str):
|
|
1084
|
+
from ibm_watsonx_ai import APIClient, Credentials # type: ignore
|
|
1085
|
+
|
|
1086
|
+
try:
|
|
1087
|
+
if hasattr(self, "_wml_cpd_creds") and self._wml_cpd_creds:
|
|
1088
|
+
creds = Credentials(**self._wml_cpd_creds)
|
|
1089
|
+
|
|
1090
|
+
wml_client = APIClient(creds)
|
|
1091
|
+
wml_client.set.default_space(self.space_id)
|
|
1092
|
+
|
|
1093
|
+
else:
|
|
1094
|
+
creds = Credentials(
|
|
1095
|
+
url=self.region.watsonxai,
|
|
1096
|
+
api_key=self._api_key,
|
|
1097
|
+
)
|
|
1098
|
+
wml_client = APIClient(creds)
|
|
1099
|
+
wml_client.set.default_space(self.space_id)
|
|
1100
|
+
|
|
1101
|
+
except Exception as e:
|
|
1102
|
+
logging.error(f"Error connecting to IBM watsonx.ai Runtime: {e}")
|
|
1103
|
+
raise
|
|
1104
|
+
|
|
1105
|
+
suppress_output(wml_client.deployments.delete, deployment_id)
|
|
1106
|
+
|
|
979
1107
|
@deprecated(
|
|
980
1108
|
reason="'add_prompt_observer()' is deprecated and will be removed in a future version. Use 'create_prompt_monitor()' instead.",
|
|
981
1109
|
version="1.0.5",
|
|
@@ -1085,6 +1213,8 @@ class WatsonxPromptMonitor(PromptMonitor):
|
|
|
1085
1213
|
```
|
|
1086
1214
|
"""
|
|
1087
1215
|
task_id = TaskType.from_value(task_id).value
|
|
1216
|
+
rollback_stack = []
|
|
1217
|
+
|
|
1088
1218
|
# DEPRECATION NOTICE
|
|
1089
1219
|
if input_text is not None:
|
|
1090
1220
|
warnings.warn(
|
|
@@ -1178,11 +1308,14 @@ class WatsonxPromptMonitor(PromptMonitor):
|
|
|
1178
1308
|
pta_id = suppress_output(
|
|
1179
1309
|
self._create_prompt_template, prompt_details, asset_details
|
|
1180
1310
|
)
|
|
1311
|
+
rollback_stack.append(lambda: self._delete_detached_prompt(pta_id))
|
|
1312
|
+
|
|
1181
1313
|
deployment_id = None
|
|
1182
1314
|
if self._container_type == "space":
|
|
1183
1315
|
deployment_id = suppress_output(
|
|
1184
1316
|
self._create_deployment_pta, pta_id, name, model_id
|
|
1185
1317
|
)
|
|
1318
|
+
rollback_stack.append(lambda: self._delete_deployment_pta(deployment_id))
|
|
1186
1319
|
|
|
1187
1320
|
monitors = {
|
|
1188
1321
|
"generative_ai_quality": {
|
|
@@ -1243,10 +1376,16 @@ class WatsonxPromptMonitor(PromptMonitor):
|
|
|
1243
1376
|
|
|
1244
1377
|
generative_ai_monitor_details = generative_ai_monitor_details._to_dict()
|
|
1245
1378
|
|
|
1379
|
+
wos_status = generative_ai_monitor_details.get("status", {})
|
|
1380
|
+
if wos_status.get("state") == "ERROR":
|
|
1381
|
+
for rollback_step in reversed(rollback_stack):
|
|
1382
|
+
rollback_step()
|
|
1383
|
+
raise Exception(wos_status.get("failure"))
|
|
1384
|
+
|
|
1246
1385
|
return {
|
|
1247
1386
|
"prompt_template_asset_id": pta_id,
|
|
1248
1387
|
"deployment_id": deployment_id,
|
|
1249
|
-
"subscription_id": generative_ai_monitor_details
|
|
1388
|
+
"subscription_id": generative_ai_monitor_details.get("subscription_id", None),
|
|
1250
1389
|
}
|
|
1251
1390
|
|
|
1252
1391
|
def store_payload_records(
|
|
@@ -72,6 +72,19 @@ class Region(str, Enum):
|
|
|
72
72
|
|
|
73
73
|
|
|
74
74
|
class TaskType(Enum):
|
|
75
|
+
"""
|
|
76
|
+
Supported IBM watsonx.governance tasks.
|
|
77
|
+
|
|
78
|
+
Attributes:
|
|
79
|
+
QUESTION_ANSWERING (str): "question_answering"
|
|
80
|
+
SUMMARIZATION (str): "summarization"
|
|
81
|
+
RETRIEVAL_AUGMENTED_GENERATION (str): "retrieval_augmented_generation"
|
|
82
|
+
CLASSIFICATION (str): "classification"
|
|
83
|
+
GENERATION (str): "generation"
|
|
84
|
+
CODE (str): "code"
|
|
85
|
+
EXTRACTION (str): "extraction"
|
|
86
|
+
"""
|
|
87
|
+
|
|
75
88
|
QUESTION_ANSWERING = "question_answering"
|
|
76
89
|
SUMMARIZATION = "summarization"
|
|
77
90
|
RETRIEVAL_AUGMENTED_GENERATION = "retrieval_augmented_generation"
|
{beekeeper_monitors_watsonx-1.1.1.dist-info → beekeeper_monitors_watsonx-1.1.2.dist-info}/RECORD
RENAMED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
beekeeper/monitors/watsonx/__init__.py,sha256=iJv6D68IT00ZC40TNSVYtqyFTen9sWoDqUtxvVVJjOE,789
|
|
2
|
-
beekeeper/monitors/watsonx/base.py,sha256=
|
|
2
|
+
beekeeper/monitors/watsonx/base.py,sha256=gx_iduLDy1TmMSM-jw9OyUNKltxV8xUeMz-POPhjT6k,62174
|
|
3
3
|
beekeeper/monitors/watsonx/custom_metric.py,sha256=XdJ26lb0y_P1nirJE_krpKONuqJjP3sWFApoG-DR6hk,23959
|
|
4
4
|
beekeeper/monitors/watsonx/supporting_classes/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
5
|
beekeeper/monitors/watsonx/supporting_classes/credentials.py,sha256=x4rYoOFvx0pWDhFZfuy6fM0rj7JCivaSYn_jYFXlV8U,5190
|
|
6
|
-
beekeeper/monitors/watsonx/supporting_classes/enums.py,sha256=
|
|
6
|
+
beekeeper/monitors/watsonx/supporting_classes/enums.py,sha256=Kp8_-YYQ2Z2ha9_pYyF7F7DaZOVFJoV4YSoCqoEgbOk,3274
|
|
7
7
|
beekeeper/monitors/watsonx/supporting_classes/metric.py,sha256=iERXRi0iBFHITFaLtonoV97nNUCPXbieD7Z1wX6bvX8,3370
|
|
8
8
|
beekeeper/monitors/watsonx/utils/data_utils.py,sha256=qBLYtHGY0MJ0JJ8BpFDT2YIjA3QOYJQNemLvpA3DMz0,1252
|
|
9
9
|
beekeeper/monitors/watsonx/utils/instrumentation.py,sha256=ztgR1kZ9h-JvASzRA47AYHdc-Isv33EQum9XBLg-dQk,525
|
|
10
|
-
beekeeper_monitors_watsonx-1.1.
|
|
11
|
-
beekeeper_monitors_watsonx-1.1.
|
|
12
|
-
beekeeper_monitors_watsonx-1.1.
|
|
10
|
+
beekeeper_monitors_watsonx-1.1.2.dist-info/METADATA,sha256=9NZNF7aRduO-j9Up_BfNbgIRWrBb67zbcGnTvylHk_E,716
|
|
11
|
+
beekeeper_monitors_watsonx-1.1.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
12
|
+
beekeeper_monitors_watsonx-1.1.2.dist-info/RECORD,,
|
{beekeeper_monitors_watsonx-1.1.1.dist-info → beekeeper_monitors_watsonx-1.1.2.dist-info}/WHEEL
RENAMED
|
File without changes
|