beekeeper-monitors-watsonx 1.0.5.post1__py3-none-any.whl → 1.0.7__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.
@@ -0,0 +1,137 @@
1
+ from typing import Any, Dict, Literal, Optional, Union
2
+
3
+ from pydantic.v1 import BaseModel
4
+
5
+
6
+ class CloudPakforDataCredentials(BaseModel):
7
+ """
8
+ Encapsulates the credentials required for IBM Cloud Pak for Data.
9
+
10
+ Attributes:
11
+ url (str): The host URL of the Cloud Pak for Data environment.
12
+ api_key (str, optional): The API key for the environment, if IAM is enabled.
13
+ username (str, optional): The username for the environment.
14
+ password (str, optional): The password for the environment.
15
+ bedrock_url (str, optional): The Bedrock URL. Required only when IAM integration is enabled on CP4D 4.0.x clusters.
16
+ instance_id (str, optional): The instance ID.
17
+ version (str, optional): The version of Cloud Pak for Data.
18
+ disable_ssl_verification (bool, optional): Indicates whether to disable SSL certificate verification.
19
+ Defaults to `True`.
20
+ """
21
+
22
+ url: str
23
+ api_key: Optional[str] = None
24
+ username: Optional[str] = None
25
+ password: Optional[str] = None
26
+ bedrock_url: Optional[str] = None
27
+ instance_id: Optional[Literal["icp", "openshift"]] = None
28
+ version: Optional[str] = None
29
+ disable_ssl_verification: bool = True
30
+
31
+ def __init__(
32
+ self,
33
+ url: str,
34
+ api_key: Optional[str] = None,
35
+ username: Optional[str] = None,
36
+ password: Optional[str] = None,
37
+ bedrock_url: Optional[str] = None,
38
+ instance_id: Optional[Literal["icp", "openshift"]] = None,
39
+ version: Optional[str] = None,
40
+ disable_ssl_verification: bool = True,
41
+ ) -> None:
42
+ super().__init__(
43
+ url=url,
44
+ api_key=api_key,
45
+ username=username,
46
+ password=password,
47
+ bedrock_url=bedrock_url,
48
+ instance_id=instance_id,
49
+ version=version,
50
+ disable_ssl_verification=disable_ssl_verification,
51
+ )
52
+
53
+ def to_dict(self) -> Dict[str, Any]:
54
+ cpd_creds = dict([(k, v) for k, v in self.__dict__.items()]) # noqa: C404
55
+
56
+ if "instance_id" in cpd_creds and self.instance_id.lower() not in [
57
+ "icp",
58
+ "openshift",
59
+ ]:
60
+ cpd_creds.pop("instance_id")
61
+
62
+ return cpd_creds
63
+
64
+
65
+ class IntegratedSystemCredentials(BaseModel):
66
+ """
67
+ Encapsulates the credentials for an Integrated System based on the authentication type.
68
+
69
+ Depending on the `auth_type`, only a subset of the properties is required.
70
+
71
+ Attributes:
72
+ auth_type (str): The type of authentication. Currently supports "basic" and "bearer".
73
+ username (str, optional): The username for Basic Authentication.
74
+ password (str, optional): The password for Basic Authentication.
75
+ token_url (str, optional): The URL of the authentication endpoint used to request a Bearer token.
76
+ token_method (str, optional): The HTTP method (e.g., "POST", "GET") used to request the Bearer token.
77
+ Defaults to "POST".
78
+ token_headers (Dict, optional): Optional headers to include when requesting the Bearer token.
79
+ Defaults to `None`.
80
+ token_payload (str | dict, optional): The body or payload to send when requesting the Bearer token.
81
+ Can be a string (e.g., raw JSON). Defaults to `None`.
82
+ """
83
+
84
+ auth_type: Literal["basic", "bearer"]
85
+ username: Optional[str] # basic
86
+ password: Optional[str] # basic
87
+ token_url: Optional[str] # bearer
88
+ token_method: Optional[str] = "POST" # bearer
89
+ token_headers: Optional[Dict] = {} # bearer
90
+ token_payload: Optional[Union[str, Dict]] = None # bearer
91
+
92
+ def __init__(
93
+ self,
94
+ auth_type: Literal["basic", "bearer"],
95
+ username: str = None,
96
+ password: str = None,
97
+ token_url: str = None,
98
+ token_method: str = "POST",
99
+ token_headers: Dict = {},
100
+ token_payload: Union[str, Dict] = None,
101
+ ) -> None:
102
+ if auth_type == "basic":
103
+ if not username or not password:
104
+ raise ValueError(
105
+ "`username` and `password` are required for auth_type = 'basic'.",
106
+ )
107
+ elif auth_type == "bearer":
108
+ if not token_url:
109
+ raise ValueError(
110
+ "`token_url` are required for auth_type = 'bearer'.",
111
+ )
112
+
113
+ super().__init__(
114
+ auth_type=auth_type,
115
+ username=username,
116
+ password=password,
117
+ token_url=token_url,
118
+ token_method=token_method,
119
+ token_headers=token_headers,
120
+ token_payload=token_payload,
121
+ )
122
+
123
+ def to_dict(self) -> Dict:
124
+ integrated_system_creds = {"auth_type": self.auth_type}
125
+
126
+ if self.auth_type == "basic":
127
+ integrated_system_creds["username"] = self.username
128
+ integrated_system_creds["password"] = self.password
129
+ elif self.auth_type == "bearer":
130
+ integrated_system_creds["token_info"] = {
131
+ "url": self.token_url,
132
+ "method": self.token_method,
133
+ "headers": self.token_headers,
134
+ "payload": self.token_payload,
135
+ }
136
+
137
+ return integrated_system_creds
@@ -0,0 +1,71 @@
1
+ from enum import Enum
2
+
3
+ _REGION_DATA = {
4
+ "us-south": {
5
+ "watsonxai": "https://us-south.ml.cloud.ibm.com",
6
+ "openscale": "https://api.aiopenscale.cloud.ibm.com",
7
+ "factsheet": None,
8
+ },
9
+ "eu-de": {
10
+ "watsonxai": "https://eu-de.ml.cloud.ibm.com",
11
+ "openscale": "https://eu-de.api.aiopenscale.cloud.ibm.com",
12
+ "factsheet": "frankfurt",
13
+ },
14
+ "au-syd": {
15
+ "watsonxai": "https://au-syd.ml.cloud.ibm.com",
16
+ "openscale": "https://au-syd.api.aiopenscale.cloud.ibm.com",
17
+ "factsheet": "sydney",
18
+ },
19
+ }
20
+
21
+
22
+ class Region(str, Enum):
23
+ """
24
+ Supported IBM watsonx.governance regions.
25
+
26
+ Defines the available regions where watsonx.governance SaaS
27
+ services are deployed.
28
+
29
+ Attributes:
30
+ US_SOUTH (str): "us-south".
31
+ EU_DE (str): "eu-de".
32
+ AU_SYD (str): "au-syd".
33
+ """
34
+
35
+ US_SOUTH = "us-south"
36
+ EU_DE = "eu-de"
37
+ AU_SYD = "au-syd"
38
+
39
+ @property
40
+ def watsonxai(self):
41
+ return _REGION_DATA[self.value]["watsonxai"]
42
+
43
+ @property
44
+ def openscale(self):
45
+ return _REGION_DATA[self.value]["openscale"]
46
+
47
+ @property
48
+ def factsheet(self):
49
+ return _REGION_DATA[self.value]["factsheet"]
50
+
51
+ @classmethod
52
+ def from_value(cls, value):
53
+ if value is None:
54
+ return cls.US_SOUTH
55
+
56
+ if isinstance(value, cls):
57
+ return value
58
+
59
+ if isinstance(value, str):
60
+ try:
61
+ return cls(value)
62
+ except ValueError:
63
+ raise ValueError(
64
+ "Invalid value for parameter 'region'. Received: '{}'. Valid values are: {}.".format(
65
+ value, [item.value for item in Region]
66
+ )
67
+ )
68
+
69
+ raise TypeError(
70
+ f"Invalid type for parameter 'region'. Expected str or Region, but received {type(value).__name__}."
71
+ )
@@ -0,0 +1,109 @@
1
+ from typing import Dict, List, Literal, Optional
2
+
3
+ from pydantic.v1 import BaseModel
4
+
5
+
6
+ class WatsonxLocalMetric(BaseModel):
7
+ """
8
+ Provides the IBM watsonx.governance local monitor metric definition.
9
+
10
+ Attributes:
11
+ name (str): The name of the metric.
12
+ data_type (str): The data type of the metric. Currently supports "string", "integer", "double", and "timestamp".
13
+ nullable (bool, optional): Indicates whether the metric can be null. Defaults to `False`.
14
+
15
+ Example:
16
+ ```python
17
+ from beekeeper.monitors.watsonx import WatsonxLocalMetric
18
+
19
+ WatsonxLocalMetric(name="context_quality", data_type="double")
20
+ ```
21
+ """
22
+
23
+ name: str
24
+ data_type: Literal["string", "integer", "double", "timestamp"]
25
+ nullable: bool = True
26
+
27
+ def to_dict(self) -> Dict:
28
+ return {"name": self.name, "type": self.data_type, "nullable": self.nullable}
29
+
30
+
31
+ class WatsonxMetricThreshold(BaseModel):
32
+ """
33
+ Defines the metric threshold for IBM watsonx.governance.
34
+
35
+ Attributes:
36
+ threshold_type (str): The threshold type. Can be either `lower_limit` or `upper_limit`.
37
+ default_value (float): The metric threshold value.
38
+
39
+ Example:
40
+ ```python
41
+ from beekeeper.monitors.watsonx import WatsonxMetricThreshold
42
+
43
+ WatsonxMetricThreshold(threshold_type="lower_limit", default_value=0.8)
44
+ ```
45
+ """
46
+
47
+ threshold_type: Literal["lower_limit", "upper_limit"]
48
+ default_value: float = None
49
+
50
+ def to_dict(self) -> Dict:
51
+ return {"type": self.threshold_type, "default": self.default_value}
52
+
53
+
54
+ class WatsonxMetric(BaseModel):
55
+ """
56
+ Defines the IBM watsonx.governance global monitor metric.
57
+
58
+ Attributes:
59
+ name (str): The name of the metric.
60
+ applies_to (List[str]): A list of task types that the metric applies to. Currently supports:
61
+ "summarization", "generation", "question_answering", "extraction", and "retrieval_augmented_generation".
62
+ thresholds (List[WatsonxMetricThreshold]): A list of metric thresholds associated with the metric.
63
+
64
+ Example:
65
+ ```python
66
+ from beekeeper.monitors.watsonx import (
67
+ WatsonxMetric,
68
+ WatsonxMetricThreshold,
69
+ )
70
+
71
+ WatsonxMetric(
72
+ name="context_quality",
73
+ applies_to=["retrieval_augmented_generation", "summarization"],
74
+ thresholds=[
75
+ WatsonxMetricThreshold(threshold_type="lower_limit", default_value=0.75)
76
+ ],
77
+ )
78
+ ```
79
+ """
80
+
81
+ name: str
82
+ applies_to: List[
83
+ Literal[
84
+ "summarization",
85
+ "generation",
86
+ "question_answering",
87
+ "extraction",
88
+ "retrieval_augmented_generation",
89
+ ]
90
+ ]
91
+ thresholds: Optional[List[WatsonxMetricThreshold]] = None
92
+
93
+ def to_dict(self) -> Dict:
94
+ from ibm_watson_openscale.base_classes.watson_open_scale_v2 import (
95
+ ApplicabilitySelection,
96
+ MetricThreshold,
97
+ )
98
+
99
+ monitor_metric = {
100
+ "name": self.name,
101
+ "applies_to": ApplicabilitySelection(problem_type=self.applies_to),
102
+ }
103
+
104
+ if self.thresholds is not None:
105
+ monitor_metric["thresholds"] = [
106
+ MetricThreshold(**threshold.to_dict()) for threshold in self.thresholds
107
+ ]
108
+
109
+ return monitor_metric
@@ -0,0 +1,31 @@
1
+ from typing import Dict, List
2
+
3
+
4
+ def validate_and_filter_dict(
5
+ original_dict: Dict, optional_keys: List, required_keys: List = []
6
+ ):
7
+ """
8
+ Validates that all required keys are present in a dictionary and returns a filtered dictionary
9
+ containing only the required and specified optional keys with non-None values.
10
+
11
+ Args:
12
+ original_dict (Dict): The original dictionary.
13
+ optional_keys (list): A list of keys to retain.
14
+ required_keys (list, optional): A list of keys that must be present in the dictionary. Defaults to None.
15
+ """
16
+ # Ensure all required keys are in the source dict
17
+ missing_keys = [key for key in required_keys if key not in original_dict]
18
+ if missing_keys:
19
+ raise KeyError(
20
+ f"Validation failed: the following required key(s) are missing from the dictionary: {missing_keys}. "
21
+ "Please provide these keys before proceeding."
22
+ )
23
+
24
+ all_keys_to_keep = set(required_keys + optional_keys)
25
+
26
+ # Create a new dictionary with only the key-value pairs where the key is in 'keys' and value is not None
27
+ return {
28
+ key: original_dict[key]
29
+ for key in all_keys_to_keep
30
+ if key in original_dict and original_dict[key] is not None
31
+ }
@@ -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.7
4
4
  Summary: beekeeper monitors watsonx extension
5
5
  Author-email: Leonardo Furnielis <leonardofurnielis@outlook.com>
6
6
  License: Apache-2.0
@@ -0,0 +1,12 @@
1
+ beekeeper/monitors/watsonx/__init__.py,sha256=iJv6D68IT00ZC40TNSVYtqyFTen9sWoDqUtxvVVJjOE,789
2
+ beekeeper/monitors/watsonx/base.py,sha256=_nCOD09F46O64T9964gvCyhmX8hFupb0T9DDZlRftBs,47075
3
+ beekeeper/monitors/watsonx/custom_metric.py,sha256=eoosf2WKdru28ShhLEdlj5ldjyYGl3Feop6TA1U3gZY,22185
4
+ beekeeper/monitors/watsonx/supporting_classes/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ beekeeper/monitors/watsonx/supporting_classes/credentials.py,sha256=x4rYoOFvx0pWDhFZfuy6fM0rj7JCivaSYn_jYFXlV8U,5190
6
+ beekeeper/monitors/watsonx/supporting_classes/enums.py,sha256=7HkSrjU7D8pFPCRdYk_1oE27r_sZ_nIL6cuShIdtmR8,1895
7
+ beekeeper/monitors/watsonx/supporting_classes/metric.py,sha256=iERXRi0iBFHITFaLtonoV97nNUCPXbieD7Z1wX6bvX8,3370
8
+ beekeeper/monitors/watsonx/utils/data_utils.py,sha256=qBLYtHGY0MJ0JJ8BpFDT2YIjA3QOYJQNemLvpA3DMz0,1252
9
+ beekeeper/monitors/watsonx/utils/instrumentation.py,sha256=ztgR1kZ9h-JvASzRA47AYHdc-Isv33EQum9XBLg-dQk,525
10
+ beekeeper_monitors_watsonx-1.0.7.dist-info/METADATA,sha256=NHZe3EfiayFDVoY4TK7Qoo9U0mqPyyqxEXxncEgnefM,716
11
+ beekeeper_monitors_watsonx-1.0.7.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
12
+ beekeeper_monitors_watsonx-1.0.7.dist-info/RECORD,,
@@ -1,6 +0,0 @@
1
- beekeeper/monitors/watsonx/__init__.py,sha256=erL0eO3J4wf1_i8kwK242uyXkMPElY3uftW6-ThqGow,521
2
- beekeeper/monitors/watsonx/base.py,sha256=3mrzGrKFx4lggdPbwAmFWq5LbhqQQJJBYr0g5Xd_KpY,73222
3
- beekeeper/monitors/watsonx/instrumentation.py,sha256=ztgR1kZ9h-JvASzRA47AYHdc-Isv33EQum9XBLg-dQk,525
4
- beekeeper_monitors_watsonx-1.0.5.post1.dist-info/METADATA,sha256=EirQIiLXaz2J4TpuS8DHMxT5mYqwBUUMN0XckdQh_io,722
5
- beekeeper_monitors_watsonx-1.0.5.post1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
6
- beekeeper_monitors_watsonx-1.0.5.post1.dist-info/RECORD,,