beekeeper-monitors-watsonx 1.1.0.post1__tar.gz → 1.1.1__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.
Files changed (13) hide show
  1. {beekeeper_monitors_watsonx-1.1.0.post1 → beekeeper_monitors_watsonx-1.1.1}/PKG-INFO +2 -2
  2. {beekeeper_monitors_watsonx-1.1.0.post1 → beekeeper_monitors_watsonx-1.1.1}/beekeeper/monitors/watsonx/base.py +82 -66
  3. {beekeeper_monitors_watsonx-1.1.0.post1 → beekeeper_monitors_watsonx-1.1.1}/beekeeper/monitors/watsonx/custom_metric.py +6 -2
  4. {beekeeper_monitors_watsonx-1.1.0.post1 → beekeeper_monitors_watsonx-1.1.1}/beekeeper/monitors/watsonx/supporting_classes/enums.py +31 -2
  5. {beekeeper_monitors_watsonx-1.1.0.post1 → beekeeper_monitors_watsonx-1.1.1}/pyproject.toml +2 -2
  6. {beekeeper_monitors_watsonx-1.1.0.post1 → beekeeper_monitors_watsonx-1.1.1}/.gitignore +0 -0
  7. {beekeeper_monitors_watsonx-1.1.0.post1 → beekeeper_monitors_watsonx-1.1.1}/README.md +0 -0
  8. {beekeeper_monitors_watsonx-1.1.0.post1 → beekeeper_monitors_watsonx-1.1.1}/beekeeper/monitors/watsonx/__init__.py +0 -0
  9. {beekeeper_monitors_watsonx-1.1.0.post1 → beekeeper_monitors_watsonx-1.1.1}/beekeeper/monitors/watsonx/supporting_classes/__init__.py +0 -0
  10. {beekeeper_monitors_watsonx-1.1.0.post1 → beekeeper_monitors_watsonx-1.1.1}/beekeeper/monitors/watsonx/supporting_classes/credentials.py +0 -0
  11. {beekeeper_monitors_watsonx-1.1.0.post1 → beekeeper_monitors_watsonx-1.1.1}/beekeeper/monitors/watsonx/supporting_classes/metric.py +0 -0
  12. {beekeeper_monitors_watsonx-1.1.0.post1 → beekeeper_monitors_watsonx-1.1.1}/beekeeper/monitors/watsonx/utils/data_utils.py +0 -0
  13. {beekeeper_monitors_watsonx-1.1.0.post1 → beekeeper_monitors_watsonx-1.1.1}/beekeeper/monitors/watsonx/utils/instrumentation.py +0 -0
@@ -1,11 +1,11 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: beekeeper-monitors-watsonx
3
- Version: 1.1.0.post1
3
+ Version: 1.1.1
4
4
  Summary: beekeeper monitors watsonx extension
5
5
  Author-email: Leonardo Furnielis <leonardofurnielis@outlook.com>
6
6
  License: Apache-2.0
7
7
  Requires-Python: <4.0,>=3.10
8
- Requires-Dist: beekeeper-core<2.0.0,>=1.0.5
8
+ Requires-Dist: beekeeper-core<2.0.0,>=1.0.6
9
9
  Requires-Dist: certifi<2026.0.0,>=2025.4.26
10
10
  Requires-Dist: ibm-aigov-facts-client<1.0.97,>=1.0.96
11
11
  Requires-Dist: ibm-watson-openscale<3.1.0,>=3.0.49
@@ -2,16 +2,18 @@ import json
2
2
  import logging
3
3
  import os
4
4
  import uuid
5
- from typing import Dict, List, Literal, Union
5
+ import warnings
6
+ from typing import Dict, List, Union
6
7
 
7
8
  import certifi
8
9
  from beekeeper.core.monitors import PromptMonitor
9
10
  from beekeeper.core.monitors.types import PayloadRecord
11
+ from beekeeper.core.prompts import PromptTemplate
10
12
  from beekeeper.core.prompts.utils import extract_template_vars
11
13
  from beekeeper.monitors.watsonx.supporting_classes.credentials import (
12
14
  CloudPakforDataCredentials,
13
15
  )
14
- from beekeeper.monitors.watsonx.supporting_classes.enums import Region
16
+ from beekeeper.monitors.watsonx.supporting_classes.enums import Region, TaskType
15
17
  from beekeeper.monitors.watsonx.utils.data_utils import validate_and_filter_dict
16
18
  from beekeeper.monitors.watsonx.utils.instrumentation import suppress_output
17
19
  from deprecated import deprecated
@@ -73,6 +75,8 @@ class WatsonxExternalPromptMonitor(PromptMonitor):
73
75
 
74
76
  Example:
75
77
  ```python
78
+ from beekeeper.monitors.watsonx.supporting_classes.enums import Region
79
+
76
80
  from beekeeper.monitors.watsonx import (
77
81
  WatsonxExternalPromptMonitor,
78
82
  CloudPakforDataCredentials,
@@ -80,7 +84,7 @@ class WatsonxExternalPromptMonitor(PromptMonitor):
80
84
 
81
85
  # watsonx.governance (IBM Cloud)
82
86
  wxgov_client = WatsonxExternalPromptMonitor(
83
- api_key="API_KEY", space_id="SPACE_ID"
87
+ api_key="API_KEY", space_id="SPACE_ID", region=Region.US_SOUTH
84
88
  )
85
89
 
86
90
  # watsonx.governance (CP4D)
@@ -244,13 +248,7 @@ class WatsonxExternalPromptMonitor(PromptMonitor):
244
248
  self,
245
249
  name: str,
246
250
  model_id: str,
247
- task_id: Literal[
248
- "extraction",
249
- "generation",
250
- "question_answering",
251
- "retrieval_augmented_generation",
252
- "summarization",
253
- ],
251
+ task_id: Union[TaskType, str],
254
252
  detached_model_provider: str,
255
253
  description: str = "",
256
254
  model_parameters: Dict = None,
@@ -291,13 +289,7 @@ class WatsonxExternalPromptMonitor(PromptMonitor):
291
289
  self,
292
290
  name: str,
293
291
  model_id: str,
294
- task_id: Literal[
295
- "extraction",
296
- "generation",
297
- "question_answering",
298
- "retrieval_augmented_generation",
299
- "summarization",
300
- ],
292
+ task_id: Union[TaskType, str],
301
293
  detached_model_provider: str,
302
294
  description: str = "",
303
295
  model_parameters: Dict = None,
@@ -333,13 +325,7 @@ class WatsonxExternalPromptMonitor(PromptMonitor):
333
325
  self,
334
326
  name: str,
335
327
  model_id: str,
336
- task_id: Literal[
337
- "extraction",
338
- "generation",
339
- "question_answering",
340
- "retrieval_augmented_generation",
341
- "summarization",
342
- ],
328
+ task_id: Union[TaskType, str],
343
329
  detached_model_provider: str,
344
330
  description: str = "",
345
331
  model_parameters: Dict = None,
@@ -347,9 +333,10 @@ class WatsonxExternalPromptMonitor(PromptMonitor):
347
333
  detached_model_url: str = None,
348
334
  detached_prompt_url: str = None,
349
335
  detached_prompt_additional_info: Dict = None,
336
+ prompt_template: Union[PromptTemplate, str] = None,
350
337
  prompt_variables: List[str] = None,
351
338
  locale: str = "en",
352
- input_text: str = None,
339
+ input_text: str = None, # DEPRECATED
353
340
  context_fields: List[str] = None,
354
341
  question_field: str = None,
355
342
  ) -> Dict:
@@ -359,7 +346,7 @@ class WatsonxExternalPromptMonitor(PromptMonitor):
359
346
  Args:
360
347
  name (str): The name of the External Prompt Template Asset.
361
348
  model_id (str): The ID of the model associated with the prompt.
362
- task_id (str): The task identifier.
349
+ task_id (TaskType): The task identifier.
363
350
  detached_model_provider (str): The external model provider.
364
351
  description (str, optional): A description of the External Prompt Template Asset.
365
352
  model_parameters (Dict, optional): Model parameters and their respective values.
@@ -367,9 +354,9 @@ class WatsonxExternalPromptMonitor(PromptMonitor):
367
354
  detached_model_url (str, optional): The URL of the external model.
368
355
  detached_prompt_url (str, optional): The URL of the external prompt.
369
356
  detached_prompt_additional_info (Dict, optional): Additional information related to the external prompt.
357
+ prompt_template (PromptTemplate, optional): The prompt template.
370
358
  prompt_variables (List[str], optional): Values for the prompt variables.
371
359
  locale (str, optional): Locale code for the input/output language. eg. "en", "pt", "es".
372
- input_text (str, optional): The input text for the prompt.
373
360
  context_fields (List[str], optional): A list of fields that will provide context to the prompt.
374
361
  Applicable only for "retrieval_augmented_generation" task type.
375
362
  question_field (str, optional): The field containing the question to be answered.
@@ -377,20 +364,37 @@ class WatsonxExternalPromptMonitor(PromptMonitor):
377
364
 
378
365
  Example:
379
366
  ```python
367
+ from beekeeper.monitors.watsonx.supporting_classes.enums import TaskType
368
+
380
369
  wxgov_client.create_prompt_monitor(
381
370
  name="Detached prompt (model AWS Anthropic)",
382
371
  model_id="anthropic.claude-v2",
383
- task_id="retrieval_augmented_generation",
372
+ task_id=TaskType.RETRIEVAL_AUGMENTED_GENERATION,
384
373
  detached_model_provider="AWS Bedrock",
385
374
  detached_model_name="Anthropic Claude 2.0",
386
375
  detached_model_url="https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-claude.html",
387
- prompt_variables=["context1", "context2", "input_query"],
388
- input_text="Prompt text to be given",
389
- context_fields=["context1", "context2"],
376
+ prompt_template="You are a helpful AI assistant that provides clear and accurate answers. {context}. Question: {input_query}.",
377
+ prompt_variables=["context", "input_query"],
378
+ context_fields=["context"],
390
379
  question_field="input_query",
391
380
  )
392
381
  ```
393
382
  """
383
+ task_id = TaskType.from_value(task_id).value
384
+ # DEPRECATION NOTICE
385
+ if input_text is not None:
386
+ warnings.warn(
387
+ "DEPRECATION NOTICE: `input_text` is deprecated and will be removed in a future release. "
388
+ "Use `prompt_template` instead.",
389
+ DeprecationWarning,
390
+ stacklevel=2,
391
+ )
392
+
393
+ if prompt_template is None:
394
+ prompt_template = input_text
395
+ # END DEPRECATION NOTICE
396
+ prompt_template = PromptTemplate.from_value(prompt_template)
397
+
394
398
  if (not (self.project_id or self.space_id)) or (
395
399
  self.project_id and self.space_id
396
400
  ):
@@ -399,7 +403,7 @@ class WatsonxExternalPromptMonitor(PromptMonitor):
399
403
  "Both were provided: 'project_id' and 'space_id' cannot be set at the same time."
400
404
  )
401
405
 
402
- if task_id == "retrieval_augmented_generation":
406
+ if task_id == TaskType.RETRIEVAL_AUGMENTED_GENERATION.value:
403
407
  if not context_fields or not question_field:
404
408
  raise ValueError(
405
409
  "For 'retrieval_augmented_generation' task, requires non-empty 'context_fields' and 'question_field'."
@@ -413,7 +417,9 @@ class WatsonxExternalPromptMonitor(PromptMonitor):
413
417
  prompt_metadata.pop("locale", None)
414
418
 
415
419
  # Update name of keys to aigov_facts api
416
- prompt_metadata["input"] = prompt_metadata.pop("input_text", None)
420
+ prompt_metadata["input"] = getattr(
421
+ prompt_metadata.pop("prompt_template", None), "template", None
422
+ )
417
423
  prompt_metadata["model_provider"] = prompt_metadata.pop(
418
424
  "detached_model_provider",
419
425
  None,
@@ -671,8 +677,9 @@ class WatsonxExternalPromptMonitor(PromptMonitor):
671
677
  """
672
678
  Stores records to the feedback logging system.
673
679
 
674
- Note:
675
- Feedback data for external prompt **must include** the model output named `generated_text`.
680
+ Info:
681
+ - Feedback data for external prompt **must include** the model output named `generated_text`.
682
+ - For prompt monitors created using Beekeeper, the label field is `reference_output`.
676
683
 
677
684
  Args:
678
685
  request_records (List[Dict]): A list of records to be logged, where each record is represented as a dictionary.
@@ -808,13 +815,17 @@ class WatsonxPromptMonitor(PromptMonitor):
808
815
 
809
816
  Example:
810
817
  ```python
818
+ from beekeeper.monitors.watsonx.supporting_classes.enums import Region
819
+
811
820
  from beekeeper.monitors.watsonx import (
812
821
  WatsonxPromptMonitor,
813
822
  CloudPakforDataCredentials,
814
823
  )
815
824
 
816
825
  # watsonx.governance (IBM Cloud)
817
- wxgov_client = WatsonxPromptMonitor(api_key="API_KEY", space_id="SPACE_ID")
826
+ wxgov_client = WatsonxPromptMonitor(
827
+ api_key="API_KEY", space_id="SPACE_ID", region=Region.US_SOUTH
828
+ )
818
829
 
819
830
  # watsonx.governance (CP4D)
820
831
  cpd_creds = CloudPakforDataCredentials(
@@ -974,13 +985,7 @@ class WatsonxPromptMonitor(PromptMonitor):
974
985
  self,
975
986
  name: str,
976
987
  model_id: str,
977
- task_id: Literal[
978
- "extraction",
979
- "generation",
980
- "question_answering",
981
- "retrieval_augmented_generation",
982
- "summarization",
983
- ],
988
+ task_id: Union[TaskType, str],
984
989
  description: str = "",
985
990
  model_parameters: Dict = None,
986
991
  prompt_variables: List[str] = None,
@@ -1011,13 +1016,7 @@ class WatsonxPromptMonitor(PromptMonitor):
1011
1016
  self,
1012
1017
  name: str,
1013
1018
  model_id: str,
1014
- task_id: Literal[
1015
- "extraction",
1016
- "generation",
1017
- "question_answering",
1018
- "retrieval_augmented_generation",
1019
- "summarization",
1020
- ],
1019
+ task_id: Union[TaskType, str],
1021
1020
  description: str = "",
1022
1021
  model_parameters: Dict = None,
1023
1022
  prompt_variables: List[str] = None,
@@ -1043,18 +1042,13 @@ class WatsonxPromptMonitor(PromptMonitor):
1043
1042
  self,
1044
1043
  name: str,
1045
1044
  model_id: str,
1046
- task_id: Literal[
1047
- "extraction",
1048
- "generation",
1049
- "question_answering",
1050
- "retrieval_augmented_generation",
1051
- "summarization",
1052
- ],
1045
+ task_id: Union[TaskType, str],
1053
1046
  description: str = "",
1054
1047
  model_parameters: Dict = None,
1048
+ prompt_template: Union[PromptTemplate, str] = None,
1055
1049
  prompt_variables: List[str] = None,
1056
1050
  locale: str = "en",
1057
- input_text: str = None,
1051
+ input_text: str = None, # DEPRECATED
1058
1052
  context_fields: List[str] = None,
1059
1053
  question_field: str = None,
1060
1054
  ) -> Dict:
@@ -1064,12 +1058,12 @@ class WatsonxPromptMonitor(PromptMonitor):
1064
1058
  Args:
1065
1059
  name (str): The name of the Prompt Template Asset.
1066
1060
  model_id (str): The ID of the model associated with the prompt.
1067
- task_id (str): The task identifier.
1061
+ task_id (TaskType): The task identifier.
1068
1062
  description (str, optional): A description of the Prompt Template Asset.
1069
1063
  model_parameters (Dict, optional): A dictionary of model parameters and their respective values.
1064
+ prompt_template (PromptTemplate, optional): The prompt template.
1070
1065
  prompt_variables (List[str], optional): A list of values for prompt input variables.
1071
1066
  locale (str, optional): Locale code for the input/output language. eg. "en", "pt", "es".
1072
- input_text (str, optional): The input text for the prompt.
1073
1067
  context_fields (List[str], optional): A list of fields that will provide context to the prompt.
1074
1068
  Applicable only for the `retrieval_augmented_generation` task type.
1075
1069
  question_field (str, optional): The field containing the question to be answered.
@@ -1077,17 +1071,34 @@ class WatsonxPromptMonitor(PromptMonitor):
1077
1071
 
1078
1072
  Example:
1079
1073
  ```python
1074
+ from beekeeper.monitors.watsonx.supporting_classes.enums import TaskType
1075
+
1080
1076
  wxgov_client.create_prompt_monitor(
1081
1077
  name="IBM prompt template",
1082
1078
  model_id="ibm/granite-3-2b-instruct",
1083
- task_id="retrieval_augmented_generation",
1084
- prompt_variables=["context1", "context2", "input_query"],
1085
- input_text="Prompt text to be given",
1086
- context_fields=["context1", "context2"],
1079
+ task_id=TaskType.RETRIEVAL_AUGMENTED_GENERATION,
1080
+ prompt_template="You are a helpful AI assistant that provides clear and accurate answers. {context}. Question: {input_query}.",
1081
+ prompt_variables=["context", "input_query"],
1082
+ context_fields=["context"],
1087
1083
  question_field="input_query",
1088
1084
  )
1089
1085
  ```
1090
1086
  """
1087
+ task_id = TaskType.from_value(task_id).value
1088
+ # DEPRECATION NOTICE
1089
+ if input_text is not None:
1090
+ warnings.warn(
1091
+ "DEPRECATION NOTICE: `input_text` is deprecated and will be removed in a future release. "
1092
+ "Use `prompt_template` instead.",
1093
+ DeprecationWarning,
1094
+ stacklevel=2,
1095
+ )
1096
+
1097
+ if prompt_template is None:
1098
+ prompt_template = input_text
1099
+ # END DEPRECATION NOTICE
1100
+ prompt_template = PromptTemplate.from_value(prompt_template)
1101
+
1091
1102
  if (not (self.project_id or self.space_id)) or (
1092
1103
  self.project_id and self.space_id
1093
1104
  ):
@@ -1096,7 +1107,7 @@ class WatsonxPromptMonitor(PromptMonitor):
1096
1107
  "Both were provided: 'project_id' and 'space_id' cannot be set at the same time."
1097
1108
  )
1098
1109
 
1099
- if task_id == "retrieval_augmented_generation":
1110
+ if task_id == TaskType.RETRIEVAL_AUGMENTED_GENERATION.value:
1100
1111
  if not context_fields or not question_field:
1101
1112
  raise ValueError(
1102
1113
  "For 'retrieval_augmented_generation' task, requires non-empty 'context_fields' and 'question_field'."
@@ -1110,7 +1121,9 @@ class WatsonxPromptMonitor(PromptMonitor):
1110
1121
  prompt_metadata.pop("locale", None)
1111
1122
 
1112
1123
  # Update name of keys to aigov_facts api
1113
- prompt_metadata["input"] = prompt_metadata.pop("input_text", None)
1124
+ prompt_metadata["input"] = getattr(
1125
+ prompt_metadata.pop("prompt_template", None), "template", None
1126
+ )
1114
1127
 
1115
1128
  # Update list of vars to dict
1116
1129
  prompt_metadata["prompt_variables"] = Dict.fromkeys(
@@ -1350,6 +1363,9 @@ class WatsonxPromptMonitor(PromptMonitor):
1350
1363
  """
1351
1364
  Stores records to the feedback logging system.
1352
1365
 
1366
+ Info:
1367
+ - For prompt monitors created using Beekeeper, the label field is `reference_output`.
1368
+
1353
1369
  Args:
1354
1370
  request_records (List[Dict]): A list of records to be logged, where each record is represented as a dictionary.
1355
1371
  subscription_id (str, optional): The subscription ID associated with the records being logged.
@@ -29,13 +29,17 @@ class WatsonxCustomMetricsManager:
29
29
 
30
30
  Example:
31
31
  ```python
32
+ from beekeeper.monitors.watsonx.supporting_classes.enums import Region
33
+
32
34
  from beekeeper.monitors.watsonx import (
33
35
  WatsonxCustomMetricsManager,
34
36
  CloudPakforDataCredentials,
35
37
  )
36
38
 
37
39
  # watsonx.governance (IBM Cloud)
38
- wxgov_client = WatsonxCustomMetricsManager(api_key="API_KEY")
40
+ wxgov_client = WatsonxCustomMetricsManager(
41
+ api_key="API_KEY", region=Region.US_SOUTH
42
+ )
39
43
 
40
44
  # watsonx.governance (CP4D)
41
45
  cpd_creds = CloudPakforDataCredentials(
@@ -484,7 +488,7 @@ class WatsonxCustomMetricsManager:
484
488
 
485
489
  Example:
486
490
  ```python
487
- wxgov_client.put_metrics(
491
+ wxgov_client.store_metric_data(
488
492
  monitor_instance_id="01966801-f9ee-7248-a706-41de00a8a998",
489
493
  run_id="RUN_ID",
490
494
  request_records={"context_quality": 0.914, "sensitivity": 0.85},
@@ -49,7 +49,7 @@ class Region(str, Enum):
49
49
  return _REGION_DATA[self.value]["factsheet"]
50
50
 
51
51
  @classmethod
52
- def from_value(cls, value):
52
+ def from_value(cls, value: str) -> "Region":
53
53
  if value is None:
54
54
  return cls.US_SOUTH
55
55
 
@@ -58,7 +58,7 @@ class Region(str, Enum):
58
58
 
59
59
  if isinstance(value, str):
60
60
  try:
61
- return cls(value)
61
+ return cls(value.lower())
62
62
  except ValueError:
63
63
  raise ValueError(
64
64
  "Invalid value for parameter 'region'. Received: '{}'. Valid values are: {}.".format(
@@ -69,3 +69,32 @@ class Region(str, Enum):
69
69
  raise TypeError(
70
70
  f"Invalid type for parameter 'region'. Expected str or Region, but received {type(value).__name__}."
71
71
  )
72
+
73
+
74
+ class TaskType(Enum):
75
+ QUESTION_ANSWERING = "question_answering"
76
+ SUMMARIZATION = "summarization"
77
+ RETRIEVAL_AUGMENTED_GENERATION = "retrieval_augmented_generation"
78
+ CLASSIFICATION = "classification"
79
+ GENERATION = "generation"
80
+ CODE = "code"
81
+ EXTRACTION = "extraction"
82
+
83
+ @classmethod
84
+ def from_value(cls, value: str) -> "TaskType":
85
+ if isinstance(value, cls):
86
+ return value
87
+
88
+ if isinstance(value, str):
89
+ try:
90
+ return cls(value.lower())
91
+ except ValueError:
92
+ raise ValueError(
93
+ "Invalid value for parameter 'task_id'. Received: '{}'. Valid values are: {}.".format(
94
+ value, [item.value for item in TaskType]
95
+ )
96
+ )
97
+
98
+ raise TypeError(
99
+ f"Invalid type for parameter 'task_id'. Expected str or TaskType, but received {type(value).__name__}."
100
+ )
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "beekeeper-monitors-watsonx"
7
- version = "1.1.0.post1"
7
+ version = "1.1.1"
8
8
  description = "beekeeper monitors watsonx extension"
9
9
  authors = [{ name = "Leonardo Furnielis", email = "leonardofurnielis@outlook.com" }]
10
10
  license = { text = "Apache-2.0" }
@@ -16,7 +16,7 @@ dependencies = [
16
16
  "ibm-aigov-facts-client>=1.0.96,<1.0.97",
17
17
  "ibm-watson-openscale>=3.0.49,<3.1.0",
18
18
  "ibm-watsonx-ai>=1.3.26,<2.0.0",
19
- "beekeeper-core>=1.0.5,<2.0.0",
19
+ "beekeeper-core>=1.0.6,<2.0.0",
20
20
  ]
21
21
 
22
22
  [tool.hatch.build.targets.sdist]