beekeeper-monitors-watsonx 1.0.5.post1__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.post1
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
@@ -231,7 +231,7 @@ class IntegratedSystemCredentials(BaseModel):
231
231
  # ===== Monitor Classes =====
232
232
  class WatsonxExternalPromptMonitor(PromptMonitor):
233
233
  """
234
- 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.
235
235
 
236
236
  Note:
237
237
  One of the following parameters is required to create a prompt monitor:
@@ -411,7 +411,7 @@ class WatsonxExternalPromptMonitor(PromptMonitor):
411
411
  return wml_client.deployments.get_uid(created_deployment)
412
412
 
413
413
  @deprecated(
414
- reason="'add_prompt_observer()' is deprecated and will be removed in a future version. Use 'add_prompt_monitor()' instead.",
414
+ reason="'add_prompt_observer()' is deprecated and will be removed in a future version. Use 'create_prompt_monitor()' instead.",
415
415
  version="1.0.5",
416
416
  action="always",
417
417
  )
@@ -439,7 +439,7 @@ class WatsonxExternalPromptMonitor(PromptMonitor):
439
439
  context_fields: List[str] = None,
440
440
  question_field: str = None,
441
441
  ) -> Dict:
442
- return self.add_prompt_monitor(
442
+ return self.create_prompt_monitor(
443
443
  name=name,
444
444
  model_id=model_id,
445
445
  task_id=task_id,
@@ -457,6 +457,11 @@ class WatsonxExternalPromptMonitor(PromptMonitor):
457
457
  question_field=question_field,
458
458
  )
459
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
+ )
460
465
  def add_prompt_monitor(
461
466
  self,
462
467
  name: str,
@@ -480,9 +485,51 @@ class WatsonxExternalPromptMonitor(PromptMonitor):
480
485
  input_text: str = None,
481
486
  context_fields: List[str] = None,
482
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,
483
530
  ) -> Dict:
484
531
  """
485
- 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.
486
533
 
487
534
  Args:
488
535
  name (str): The name of the External Prompt Template Asset.
@@ -505,7 +552,7 @@ class WatsonxExternalPromptMonitor(PromptMonitor):
505
552
 
506
553
  Example:
507
554
  ```python
508
- wxgov_client.add_prompt_monitor(
555
+ wxgov_client.create_prompt_monitor(
509
556
  name="Detached prompt (model AWS Anthropic)",
510
557
  model_id="anthropic.claude-v2",
511
558
  task_id="retrieval_augmented_generation",
@@ -805,7 +852,8 @@ class WatsonxExternalPromptMonitor(PromptMonitor):
805
852
 
806
853
  class WatsonxPromptMonitor(PromptMonitor):
807
854
  """
808
- 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.
809
857
 
810
858
  Note:
811
859
  One of the following parameters is required to create a prompt monitor:
@@ -980,7 +1028,7 @@ class WatsonxPromptMonitor(PromptMonitor):
980
1028
  return wml_client.deployments.get_uid(created_deployment)
981
1029
 
982
1030
  @deprecated(
983
- reason="'add_prompt_observer()' is deprecated and will be removed in a future version. Use 'add_prompt_monitor()' instead.",
1031
+ reason="'add_prompt_observer()' is deprecated and will be removed in a future version. Use 'create_prompt_monitor()' instead.",
984
1032
  version="1.0.5",
985
1033
  action="always",
986
1034
  )
@@ -1003,7 +1051,7 @@ class WatsonxPromptMonitor(PromptMonitor):
1003
1051
  context_fields: List[str] = None,
1004
1052
  question_field: str = None,
1005
1053
  ) -> Dict:
1006
- return self.add_prompt_monitor(
1054
+ return self.create_prompt_monitor(
1007
1055
  name=name,
1008
1056
  model_id=model_id,
1009
1057
  task_id=task_id,
@@ -1016,6 +1064,11 @@ class WatsonxPromptMonitor(PromptMonitor):
1016
1064
  question_field=question_field,
1017
1065
  )
1018
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
+ )
1019
1072
  def add_prompt_monitor(
1020
1073
  self,
1021
1074
  name: str,
@@ -1034,6 +1087,38 @@ class WatsonxPromptMonitor(PromptMonitor):
1034
1087
  input_text: str = None,
1035
1088
  context_fields: List[str] = None,
1036
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,
1037
1122
  ) -> Dict:
1038
1123
  """
1039
1124
  Creates an IBM Prompt Template Asset and ssetup monitor for the given prompt template asset.
@@ -1054,7 +1139,7 @@ class WatsonxPromptMonitor(PromptMonitor):
1054
1139
 
1055
1140
  Example:
1056
1141
  ```python
1057
- wxgov_client.add_prompt_monitor(
1142
+ wxgov_client.create_prompt_monitor(
1058
1143
  name="IBM prompt template",
1059
1144
  model_id="ibm/granite-3-2b-instruct",
1060
1145
  task_id="retrieval_augmented_generation",
@@ -1439,7 +1524,9 @@ class WatsonxMetric(BaseModel):
1439
1524
 
1440
1525
 
1441
1526
  # ===== Metric Classes =====
1442
- class WatsonxCustomMetric:
1527
+
1528
+
1529
+ class WatsonxCustomMetricsManager:
1443
1530
  """
1444
1531
  Provides functionality to set up a custom metric to measure your model's performance with IBM watsonx.governance.
1445
1532
 
@@ -1452,12 +1539,12 @@ class WatsonxCustomMetric:
1452
1539
  Example:
1453
1540
  ```python
1454
1541
  from beekeeper.monitors.watsonx import (
1455
- WatsonxCustomMetric,
1542
+ WatsonxCustomMetricsManager,
1456
1543
  CloudPakforDataCredentials,
1457
1544
  )
1458
1545
 
1459
1546
  # watsonx.governance (IBM Cloud)
1460
- wxgov_client = WatsonxCustomMetric(api_key="API_KEY")
1547
+ wxgov_client = WatsonxCustomMetricsManager(api_key="API_KEY")
1461
1548
 
1462
1549
  # watsonx.governance (CP4D)
1463
1550
  cpd_creds = CloudPakforDataCredentials(
@@ -1468,7 +1555,7 @@ class WatsonxCustomMetric:
1468
1555
  instance_id="openshift",
1469
1556
  )
1470
1557
 
1471
- wxgov_client = WatsonxCustomMetric(cpd_creds=cpd_creds)
1558
+ wxgov_client = WatsonxCustomMetricsManager(cpd_creds=cpd_creds)
1472
1559
  ```
1473
1560
  """
1474
1561
 
@@ -1658,6 +1745,11 @@ class WatsonxCustomMetric:
1658
1745
  return data_marts[0].metadata.id
1659
1746
 
1660
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
+ )
1661
1753
  def add_metric_definition(
1662
1754
  self,
1663
1755
  name: str,
@@ -1665,9 +1757,25 @@ class WatsonxCustomMetric:
1665
1757
  integrated_system_url: str,
1666
1758
  integrated_system_credentials: IntegratedSystemCredentials,
1667
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,
1668
1776
  ):
1669
1777
  """
1670
- Creates a custom monitor definition for IBM watsonx.governance.
1778
+ Creates a custom metric definition for IBM watsonx.governance.
1671
1779
 
1672
1780
  This must be done before using custom metrics.
1673
1781
 
@@ -1686,7 +1794,7 @@ class WatsonxCustomMetric:
1686
1794
  WatsonxMetricThreshold,
1687
1795
  )
1688
1796
 
1689
- wxgov_client.add_metric_definition(
1797
+ wxgov_client.create_metric_definition(
1690
1798
  name="Custom Metric - Custom LLM Quality",
1691
1799
  metrics=[
1692
1800
  WatsonxMetric(
@@ -1739,7 +1847,7 @@ class WatsonxCustomMetric:
1739
1847
  }
1740
1848
 
1741
1849
  @deprecated(
1742
- reason="'add_observer_instance()' is deprecated and will be removed in a future version. Use 'add_monitor_instance()' from 'beekeeper-monitors-watsonx' instead.",
1850
+ reason="'add_observer_instance()' is deprecated and will be removed in a future version. Use 'attach_monitor_instance()' from 'beekeeper-monitors-watsonx' instead.",
1743
1851
  version="1.0.5",
1744
1852
  action="always",
1745
1853
  )
@@ -1749,20 +1857,37 @@ class WatsonxCustomMetric:
1749
1857
  monitor_definition_id: str,
1750
1858
  subscription_id: str,
1751
1859
  ):
1752
- return self.add_monitor_instance(
1860
+ return self.attach_monitor_instance(
1753
1861
  integrated_system_id=integrated_system_id,
1754
1862
  monitor_definition_id=monitor_definition_id,
1755
1863
  subscription_id=subscription_id,
1756
1864
  )
1757
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
+ )
1758
1871
  def add_monitor_instance(
1759
1872
  self,
1760
1873
  integrated_system_id: str,
1761
1874
  monitor_definition_id: str,
1762
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,
1763
1888
  ):
1764
1889
  """
1765
- Enables a custom monitor for the specified subscription and monitor definition.
1890
+ Attaches the specified monitor definition to the specified subscription.
1766
1891
 
1767
1892
  Args:
1768
1893
  integrated_system_id (str): The ID of the integrated system.
@@ -1771,7 +1896,7 @@ class WatsonxCustomMetric:
1771
1896
 
1772
1897
  Example:
1773
1898
  ```python
1774
- wxgov_client.add_monitor_instance(
1899
+ wxgov_client.attach_monitor_instance(
1775
1900
  integrated_system_id="019667ca-5687-7838-8d29-4ff70c2b36b0",
1776
1901
  monitor_definition_id="custom_llm_quality",
1777
1902
  subscription_id="0195e95d-03a4-7000-b954-b607db10fe9e",
@@ -1825,7 +1950,7 @@ class WatsonxCustomMetric:
1825
1950
  request_records: Dict[str, Union[float, int]],
1826
1951
  ):
1827
1952
  """
1828
- Publishes computed custom metrics for a specific global monitor instance.
1953
+ Publishes computed metrics to the specified global monitor instance.
1829
1954
 
1830
1955
  Args:
1831
1956
  monitor_instance_id (str): The unique ID of the monitor instance.
@@ -1878,7 +2003,24 @@ class WatsonxCustomMetric:
1878
2003
  ).result
1879
2004
 
1880
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
+ )
1881
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(
1882
2024
  self,
1883
2025
  name: str,
1884
2026
  metrics: List[WatsonxLocalMetric],
@@ -1896,7 +2038,7 @@ class WatsonxCustomMetric:
1896
2038
  ```python
1897
2039
  from beekeeper.monitors.watsonx import WatsonxLocalMetric
1898
2040
 
1899
- wxgov_client.add_local_metric_definition(
2041
+ wxgov_client.create_local_metric_definition(
1900
2042
  name="Custom LLM Local Metric",
1901
2043
  subscription_id="019674ca-0c38-745f-8e9b-58546e95174e",
1902
2044
  metrics=[
@@ -1956,7 +2098,7 @@ class WatsonxCustomMetric:
1956
2098
  request_records: List[Dict],
1957
2099
  ):
1958
2100
  """
1959
- Publishes computed custom metrics for a specific transaction record.
2101
+ Publishes computed metrics to the specified transaction record.
1960
2102
 
1961
2103
  Args:
1962
2104
  metric_instance_id (str): The unique ID of the custom transaction metric.
@@ -2000,3 +2142,13 @@ class WatsonxCustomMetric:
2000
2142
  ```
2001
2143
  """
2002
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.post1"
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" }