beekeeper-monitors-watsonx 1.0.5__tar.gz → 1.0.6__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: beekeeper-monitors-watsonx
3
- Version: 1.0.5
3
+ Version: 1.0.6
4
4
  Summary: beekeeper monitors watsonx extension
5
5
  Author-email: Leonardo Furnielis <leonardofurnielis@outlook.com>
6
6
  License: Apache-2.0
@@ -10,6 +10,7 @@ from beekeeper.core.monitors import PromptMonitor
10
10
  from beekeeper.core.monitors.types import PayloadRecord
11
11
  from beekeeper.core.prompts.utils import extract_template_vars
12
12
  from beekeeper.monitors.watsonx.instrumentation import suppress_output
13
+ from deprecated import deprecated
13
14
  from pydantic.v1 import BaseModel
14
15
 
15
16
  os.environ["REQUESTS_CA_BUNDLE"] = certifi.where()
@@ -230,7 +231,7 @@ class IntegratedSystemCredentials(BaseModel):
230
231
  # ===== Monitor Classes =====
231
232
  class WatsonxExternalPromptMonitor(PromptMonitor):
232
233
  """
233
- Provides functionality to interact with IBM watsonx.governance for monitoring external LLMs.
234
+ Provides functionality to interact with IBM watsonx.governance for monitoring prompts executed on external LLMs.
234
235
 
235
236
  Note:
236
237
  One of the following parameters is required to create a prompt monitor:
@@ -409,6 +410,58 @@ class WatsonxExternalPromptMonitor(PromptMonitor):
409
410
 
410
411
  return wml_client.deployments.get_uid(created_deployment)
411
412
 
413
+ @deprecated(
414
+ reason="'add_prompt_observer()' is deprecated and will be removed in a future version. Use 'create_prompt_monitor()' instead.",
415
+ version="1.0.5",
416
+ action="always",
417
+ )
418
+ def add_prompt_observer(
419
+ self,
420
+ name: str,
421
+ model_id: str,
422
+ task_id: Literal[
423
+ "extraction",
424
+ "generation",
425
+ "question_answering",
426
+ "retrieval_augmented_generation",
427
+ "summarization",
428
+ ],
429
+ detached_model_provider: str,
430
+ description: str = "",
431
+ model_parameters: Dict = None,
432
+ detached_model_name: str = None,
433
+ detached_model_url: str = None,
434
+ detached_prompt_url: str = None,
435
+ detached_prompt_additional_info: Dict = None,
436
+ prompt_variables: List[str] = None,
437
+ locale: str = "en",
438
+ input_text: str = None,
439
+ context_fields: List[str] = None,
440
+ question_field: str = None,
441
+ ) -> Dict:
442
+ return self.create_prompt_monitor(
443
+ name=name,
444
+ model_id=model_id,
445
+ task_id=task_id,
446
+ detached_model_provider=detached_model_provider,
447
+ description=description,
448
+ model_parameters=model_parameters,
449
+ detached_model_name=detached_model_name,
450
+ detached_model_url=detached_model_url,
451
+ detached_prompt_url=detached_prompt_url,
452
+ detached_prompt_additional_info=detached_prompt_additional_info,
453
+ prompt_variables=prompt_variables,
454
+ locale=locale,
455
+ input_text=input_text,
456
+ context_fields=context_fields,
457
+ question_field=question_field,
458
+ )
459
+
460
+ @deprecated(
461
+ reason="'add_prompt_monitor()' is deprecated and will be removed in a future version. Use 'create_prompt_monitor()' instead.",
462
+ version="1.0.6",
463
+ action="always",
464
+ )
412
465
  def add_prompt_monitor(
413
466
  self,
414
467
  name: str,
@@ -432,9 +485,51 @@ class WatsonxExternalPromptMonitor(PromptMonitor):
432
485
  input_text: str = None,
433
486
  context_fields: List[str] = None,
434
487
  question_field: str = None,
488
+ ) -> Dict:
489
+ return self.create_prompt_monitor(
490
+ name=name,
491
+ model_id=model_id,
492
+ task_id=task_id,
493
+ detached_model_provider=detached_model_provider,
494
+ description=description,
495
+ model_parameters=model_parameters,
496
+ detached_model_name=detached_model_name,
497
+ detached_model_url=detached_model_url,
498
+ detached_prompt_url=detached_prompt_url,
499
+ detached_prompt_additional_info=detached_prompt_additional_info,
500
+ prompt_variables=prompt_variables,
501
+ locale=locale,
502
+ input_text=input_text,
503
+ context_fields=context_fields,
504
+ question_field=question_field,
505
+ )
506
+
507
+ def create_prompt_monitor(
508
+ self,
509
+ name: str,
510
+ model_id: str,
511
+ task_id: Literal[
512
+ "extraction",
513
+ "generation",
514
+ "question_answering",
515
+ "retrieval_augmented_generation",
516
+ "summarization",
517
+ ],
518
+ detached_model_provider: str,
519
+ description: str = "",
520
+ model_parameters: Dict = None,
521
+ detached_model_name: str = None,
522
+ detached_model_url: str = None,
523
+ detached_prompt_url: str = None,
524
+ detached_prompt_additional_info: Dict = None,
525
+ prompt_variables: List[str] = None,
526
+ locale: str = "en",
527
+ input_text: str = None,
528
+ context_fields: List[str] = None,
529
+ question_field: str = None,
435
530
  ) -> Dict:
436
531
  """
437
- Creates a Detached/External Prompt Template Asset and setup monitor for a given prompt template asset.
532
+ Creates a detached (external) prompt template asset and attaches a monitor to the specified prompt template asset.
438
533
 
439
534
  Args:
440
535
  name (str): The name of the External Prompt Template Asset.
@@ -457,7 +552,7 @@ class WatsonxExternalPromptMonitor(PromptMonitor):
457
552
 
458
553
  Example:
459
554
  ```python
460
- wxgov_client.add_prompt_monitor(
555
+ wxgov_client.create_prompt_monitor(
461
556
  name="Detached prompt (model AWS Anthropic)",
462
557
  model_id="anthropic.claude-v2",
463
558
  task_id="retrieval_augmented_generation",
@@ -757,7 +852,8 @@ class WatsonxExternalPromptMonitor(PromptMonitor):
757
852
 
758
853
  class WatsonxPromptMonitor(PromptMonitor):
759
854
  """
760
- Provides functionality to interact with IBM watsonx.governance for monitoring IBM watsonx.ai LLMs.
855
+ Provides functionality to interact with IBM watsonx.governance for monitoring prompts executed within
856
+ IBM watsonx.ai LLMs.
761
857
 
762
858
  Note:
763
859
  One of the following parameters is required to create a prompt monitor:
@@ -931,6 +1027,48 @@ class WatsonxPromptMonitor(PromptMonitor):
931
1027
 
932
1028
  return wml_client.deployments.get_uid(created_deployment)
933
1029
 
1030
+ @deprecated(
1031
+ reason="'add_prompt_observer()' is deprecated and will be removed in a future version. Use 'create_prompt_monitor()' instead.",
1032
+ version="1.0.5",
1033
+ action="always",
1034
+ )
1035
+ def add_prompt_observer(
1036
+ self,
1037
+ name: str,
1038
+ model_id: str,
1039
+ task_id: Literal[
1040
+ "extraction",
1041
+ "generation",
1042
+ "question_answering",
1043
+ "retrieval_augmented_generation",
1044
+ "summarization",
1045
+ ],
1046
+ description: str = "",
1047
+ model_parameters: Dict = None,
1048
+ prompt_variables: List[str] = None,
1049
+ locale: str = "en",
1050
+ input_text: str = None,
1051
+ context_fields: List[str] = None,
1052
+ question_field: str = None,
1053
+ ) -> Dict:
1054
+ return self.create_prompt_monitor(
1055
+ name=name,
1056
+ model_id=model_id,
1057
+ task_id=task_id,
1058
+ description=description,
1059
+ model_parameters=model_parameters,
1060
+ prompt_variables=prompt_variables,
1061
+ locale=locale,
1062
+ input_text=input_text,
1063
+ context_fields=context_fields,
1064
+ question_field=question_field,
1065
+ )
1066
+
1067
+ @deprecated(
1068
+ reason="'add_prompt_observer()' is deprecated and will be removed in a future version. Use 'create_prompt_monitor()' instead.",
1069
+ version="1.0.6",
1070
+ action="always",
1071
+ )
934
1072
  def add_prompt_monitor(
935
1073
  self,
936
1074
  name: str,
@@ -949,6 +1087,38 @@ class WatsonxPromptMonitor(PromptMonitor):
949
1087
  input_text: str = None,
950
1088
  context_fields: List[str] = None,
951
1089
  question_field: str = None,
1090
+ ) -> Dict:
1091
+ return self.create_prompt_monitor(
1092
+ name=name,
1093
+ model_id=model_id,
1094
+ task_id=task_id,
1095
+ description=description,
1096
+ model_parameters=model_parameters,
1097
+ prompt_variables=prompt_variables,
1098
+ locale=locale,
1099
+ input_text=input_text,
1100
+ context_fields=context_fields,
1101
+ question_field=question_field,
1102
+ )
1103
+
1104
+ def create_prompt_monitor(
1105
+ self,
1106
+ name: str,
1107
+ model_id: str,
1108
+ task_id: Literal[
1109
+ "extraction",
1110
+ "generation",
1111
+ "question_answering",
1112
+ "retrieval_augmented_generation",
1113
+ "summarization",
1114
+ ],
1115
+ description: str = "",
1116
+ model_parameters: Dict = None,
1117
+ prompt_variables: List[str] = None,
1118
+ locale: str = "en",
1119
+ input_text: str = None,
1120
+ context_fields: List[str] = None,
1121
+ question_field: str = None,
952
1122
  ) -> Dict:
953
1123
  """
954
1124
  Creates an IBM Prompt Template Asset and ssetup monitor for the given prompt template asset.
@@ -969,7 +1139,7 @@ class WatsonxPromptMonitor(PromptMonitor):
969
1139
 
970
1140
  Example:
971
1141
  ```python
972
- wxgov_client.add_prompt_monitor(
1142
+ wxgov_client.create_prompt_monitor(
973
1143
  name="IBM prompt template",
974
1144
  model_id="ibm/granite-3-2b-instruct",
975
1145
  task_id="retrieval_augmented_generation",
@@ -1354,7 +1524,9 @@ class WatsonxMetric(BaseModel):
1354
1524
 
1355
1525
 
1356
1526
  # ===== Metric Classes =====
1357
- class WatsonxCustomMetric:
1527
+
1528
+
1529
+ class WatsonxCustomMetricsManager:
1358
1530
  """
1359
1531
  Provides functionality to set up a custom metric to measure your model's performance with IBM watsonx.governance.
1360
1532
 
@@ -1367,12 +1539,12 @@ class WatsonxCustomMetric:
1367
1539
  Example:
1368
1540
  ```python
1369
1541
  from beekeeper.monitors.watsonx import (
1370
- WatsonxCustomMetric,
1542
+ WatsonxCustomMetricsManager,
1371
1543
  CloudPakforDataCredentials,
1372
1544
  )
1373
1545
 
1374
1546
  # watsonx.governance (IBM Cloud)
1375
- wxgov_client = WatsonxCustomMetric(api_key="API_KEY")
1547
+ wxgov_client = WatsonxCustomMetricsManager(api_key="API_KEY")
1376
1548
 
1377
1549
  # watsonx.governance (CP4D)
1378
1550
  cpd_creds = CloudPakforDataCredentials(
@@ -1383,7 +1555,7 @@ class WatsonxCustomMetric:
1383
1555
  instance_id="openshift",
1384
1556
  )
1385
1557
 
1386
- wxgov_client = WatsonxCustomMetric(cpd_creds=cpd_creds)
1558
+ wxgov_client = WatsonxCustomMetricsManager(cpd_creds=cpd_creds)
1387
1559
  ```
1388
1560
  """
1389
1561
 
@@ -1573,6 +1745,11 @@ class WatsonxCustomMetric:
1573
1745
  return data_marts[0].metadata.id
1574
1746
 
1575
1747
  # ===== Global Custom Metrics =====
1748
+ @deprecated(
1749
+ reason="'add_metric_definition()' is deprecated and will be removed in a future version. Use 'create_metric_definition()' instead.",
1750
+ version="1.0.6",
1751
+ action="always",
1752
+ )
1576
1753
  def add_metric_definition(
1577
1754
  self,
1578
1755
  name: str,
@@ -1580,9 +1757,25 @@ class WatsonxCustomMetric:
1580
1757
  integrated_system_url: str,
1581
1758
  integrated_system_credentials: IntegratedSystemCredentials,
1582
1759
  schedule: bool = False,
1760
+ ):
1761
+ return self.create_metric_definition(
1762
+ name=name,
1763
+ metrics=metrics,
1764
+ integrated_system_url=integrated_system_url,
1765
+ integrated_system_credentials=integrated_system_credentials,
1766
+ schedule=schedule,
1767
+ )
1768
+
1769
+ def create_metric_definition(
1770
+ self,
1771
+ name: str,
1772
+ metrics: List[WatsonxMetric],
1773
+ integrated_system_url: str,
1774
+ integrated_system_credentials: IntegratedSystemCredentials,
1775
+ schedule: bool = False,
1583
1776
  ):
1584
1777
  """
1585
- Creates a custom monitor definition for IBM watsonx.governance.
1778
+ Creates a custom metric definition for IBM watsonx.governance.
1586
1779
 
1587
1780
  This must be done before using custom metrics.
1588
1781
 
@@ -1601,7 +1794,7 @@ class WatsonxCustomMetric:
1601
1794
  WatsonxMetricThreshold,
1602
1795
  )
1603
1796
 
1604
- wxgov_client.add_metric_definition(
1797
+ wxgov_client.create_metric_definition(
1605
1798
  name="Custom Metric - Custom LLM Quality",
1606
1799
  metrics=[
1607
1800
  WatsonxMetric(
@@ -1653,14 +1846,48 @@ class WatsonxCustomMetric:
1653
1846
  "monitor_definition_id": external_monitor_id,
1654
1847
  }
1655
1848
 
1849
+ @deprecated(
1850
+ reason="'add_observer_instance()' is deprecated and will be removed in a future version. Use 'attach_monitor_instance()' from 'beekeeper-monitors-watsonx' instead.",
1851
+ version="1.0.5",
1852
+ action="always",
1853
+ )
1854
+ def add_observer_instance(
1855
+ self,
1856
+ integrated_system_id: str,
1857
+ monitor_definition_id: str,
1858
+ subscription_id: str,
1859
+ ):
1860
+ return self.attach_monitor_instance(
1861
+ integrated_system_id=integrated_system_id,
1862
+ monitor_definition_id=monitor_definition_id,
1863
+ subscription_id=subscription_id,
1864
+ )
1865
+
1866
+ @deprecated(
1867
+ reason="'add_monitor_instance()' is deprecated and will be removed in a future version. Use 'attach_monitor_instance()' from 'beekeeper-monitors-watsonx' instead.",
1868
+ version="1.0.6",
1869
+ action="always",
1870
+ )
1656
1871
  def add_monitor_instance(
1657
1872
  self,
1658
1873
  integrated_system_id: str,
1659
1874
  monitor_definition_id: str,
1660
1875
  subscription_id: str,
1876
+ ):
1877
+ return self.attach_monitor_instance(
1878
+ integrated_system_id=integrated_system_id,
1879
+ monitor_definition_id=monitor_definition_id,
1880
+ subscription_id=subscription_id,
1881
+ )
1882
+
1883
+ def attach_monitor_instance(
1884
+ self,
1885
+ integrated_system_id: str,
1886
+ monitor_definition_id: str,
1887
+ subscription_id: str,
1661
1888
  ):
1662
1889
  """
1663
- Enables a custom monitor for the specified subscription and monitor definition.
1890
+ Attaches the specified monitor definition to the specified subscription.
1664
1891
 
1665
1892
  Args:
1666
1893
  integrated_system_id (str): The ID of the integrated system.
@@ -1669,7 +1896,7 @@ class WatsonxCustomMetric:
1669
1896
 
1670
1897
  Example:
1671
1898
  ```python
1672
- wxgov_client.add_monitor_instance(
1899
+ wxgov_client.attach_monitor_instance(
1673
1900
  integrated_system_id="019667ca-5687-7838-8d29-4ff70c2b36b0",
1674
1901
  monitor_definition_id="custom_llm_quality",
1675
1902
  subscription_id="0195e95d-03a4-7000-b954-b607db10fe9e",
@@ -1723,7 +1950,7 @@ class WatsonxCustomMetric:
1723
1950
  request_records: Dict[str, Union[float, int]],
1724
1951
  ):
1725
1952
  """
1726
- Publishes computed custom metrics for a specific global monitor instance.
1953
+ Publishes computed metrics to the specified global monitor instance.
1727
1954
 
1728
1955
  Args:
1729
1956
  monitor_instance_id (str): The unique ID of the monitor instance.
@@ -1776,7 +2003,24 @@ class WatsonxCustomMetric:
1776
2003
  ).result
1777
2004
 
1778
2005
  # ===== Local Custom Metrics =====
2006
+ @deprecated(
2007
+ reason="'add_local_metric_definition()' is deprecated and will be removed in a future version. Use 'create_local_metric_definition()' from 'beekeeper-monitors-watsonx' instead.",
2008
+ version="1.0.6",
2009
+ action="always",
2010
+ )
1779
2011
  def add_local_metric_definition(
2012
+ self,
2013
+ name: str,
2014
+ metrics: List[WatsonxMetric],
2015
+ subscription_id: str,
2016
+ ):
2017
+ return self.create_local_metric_definition(
2018
+ name=name,
2019
+ metrics=metrics,
2020
+ subscription_id=subscription_id,
2021
+ )
2022
+
2023
+ def create_local_metric_definition(
1780
2024
  self,
1781
2025
  name: str,
1782
2026
  metrics: List[WatsonxLocalMetric],
@@ -1794,7 +2038,7 @@ class WatsonxCustomMetric:
1794
2038
  ```python
1795
2039
  from beekeeper.monitors.watsonx import WatsonxLocalMetric
1796
2040
 
1797
- wxgov_client.add_local_metric_definition(
2041
+ wxgov_client.create_local_metric_definition(
1798
2042
  name="Custom LLM Local Metric",
1799
2043
  subscription_id="019674ca-0c38-745f-8e9b-58546e95174e",
1800
2044
  metrics=[
@@ -1854,7 +2098,7 @@ class WatsonxCustomMetric:
1854
2098
  request_records: List[Dict],
1855
2099
  ):
1856
2100
  """
1857
- Publishes computed custom metrics for a specific transaction record.
2101
+ Publishes computed metrics to the specified transaction record.
1858
2102
 
1859
2103
  Args:
1860
2104
  metric_instance_id (str): The unique ID of the custom transaction metric.
@@ -1898,3 +2142,13 @@ class WatsonxCustomMetric:
1898
2142
  ```
1899
2143
  """
1900
2144
  return self._get_dataset_data(metric_instance_id)
2145
+
2146
+
2147
+ @deprecated(
2148
+ reason="'WatsonxCustomMetric()' is deprecated and will be removed in a future version. "
2149
+ "Use 'WatsonxCustomMetricsManager' instead.",
2150
+ version="1.0.6",
2151
+ action="always",
2152
+ )
2153
+ class WatsonxCustomMetric(WatsonxCustomMetricsManager):
2154
+ pass
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "beekeeper-monitors-watsonx"
7
- version = "1.0.5"
7
+ version = "1.0.6"
8
8
  description = "beekeeper monitors watsonx extension"
9
9
  authors = [{ name = "Leonardo Furnielis", email = "leonardofurnielis@outlook.com" }]
10
10
  license = { text = "Apache-2.0" }