arthur-common 2.1.51__py3-none-any.whl → 2.1.52__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.
Potentially problematic release.
This version of arthur-common might be problematic. Click here for more details.
- arthur_common/models/metrics.py +68 -12
- arthur_common/models/shield.py +0 -18
- {arthur_common-2.1.51.dist-info → arthur_common-2.1.52.dist-info}/METADATA +1 -1
- {arthur_common-2.1.51.dist-info → arthur_common-2.1.52.dist-info}/RECORD +5 -5
- {arthur_common-2.1.51.dist-info → arthur_common-2.1.52.dist-info}/WHEEL +0 -0
arthur_common/models/metrics.py
CHANGED
|
@@ -4,7 +4,7 @@ from enum import Enum
|
|
|
4
4
|
from typing import Literal, Optional
|
|
5
5
|
from uuid import UUID
|
|
6
6
|
|
|
7
|
-
from pydantic import BaseModel, Field, model_validator
|
|
7
|
+
from pydantic import BaseModel, Field, field_validator, model_validator
|
|
8
8
|
from typing_extensions import Self
|
|
9
9
|
|
|
10
10
|
from arthur_common.models.datasets import ModelProblemType
|
|
@@ -112,12 +112,9 @@ class AggregationMetricType(Enum):
|
|
|
112
112
|
NUMERIC = "numeric"
|
|
113
113
|
|
|
114
114
|
|
|
115
|
-
class
|
|
115
|
+
class BaseAggregationParameterSchema(BaseModel):
|
|
116
|
+
# fields for aggregation parameters shared across all parameter types and between default and custom metrics
|
|
116
117
|
parameter_key: str = Field(description="Name of the parameter.")
|
|
117
|
-
optional: bool = Field(
|
|
118
|
-
False,
|
|
119
|
-
description="Boolean denoting if the parameter is optional.",
|
|
120
|
-
)
|
|
121
118
|
friendly_name: str = Field(
|
|
122
119
|
description="User facing name of the parameter.",
|
|
123
120
|
)
|
|
@@ -126,7 +123,16 @@ class MetricsParameterSchema(BaseModel):
|
|
|
126
123
|
)
|
|
127
124
|
|
|
128
125
|
|
|
129
|
-
class
|
|
126
|
+
class MetricsParameterSchema(BaseAggregationParameterSchema):
|
|
127
|
+
# specific to default metrics/Python metrics—not available to custom aggregations
|
|
128
|
+
optional: bool = Field(
|
|
129
|
+
False,
|
|
130
|
+
description="Boolean denoting if the parameter is optional.",
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
class BaseDatasetParameterSchema(BaseAggregationParameterSchema):
|
|
135
|
+
# fields specific to dataset parameters shared across default and custom metrics
|
|
130
136
|
parameter_type: Literal["dataset"] = "dataset"
|
|
131
137
|
model_problem_type: Optional[ModelProblemType] = Field(
|
|
132
138
|
default=None,
|
|
@@ -134,12 +140,24 @@ class MetricsDatasetParameterSchema(MetricsParameterSchema):
|
|
|
134
140
|
)
|
|
135
141
|
|
|
136
142
|
|
|
137
|
-
class
|
|
143
|
+
class MetricsDatasetParameterSchema(MetricsParameterSchema, BaseDatasetParameterSchema):
|
|
144
|
+
# dataset parameter schema including fields specific to default metrics
|
|
145
|
+
pass
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
class BaseLiteralParameterSchema(BaseAggregationParameterSchema):
|
|
149
|
+
# fields specific to literal parameters shared across default and custom metrics
|
|
138
150
|
parameter_type: Literal["literal"] = "literal"
|
|
139
151
|
parameter_dtype: DType = Field(description="Data type of the parameter.")
|
|
140
152
|
|
|
141
153
|
|
|
142
|
-
class
|
|
154
|
+
class MetricsLiteralParameterSchema(MetricsParameterSchema, BaseLiteralParameterSchema):
|
|
155
|
+
# literal parameter schema including fields specific to default metrics
|
|
156
|
+
pass
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
class BaseColumnBaseParameterSchema(BaseAggregationParameterSchema):
|
|
160
|
+
# fields specific to all single or multiple column parameters shared across default and custom metrics
|
|
143
161
|
tag_hints: list[ScopeSchemaTag] = Field(
|
|
144
162
|
[],
|
|
145
163
|
description="List of tags that are applicable to this parameter. Datasets with columns that have matching tags can be inferred this way.",
|
|
@@ -165,12 +183,18 @@ class MetricsColumnBaseParameterSchema(MetricsParameterSchema):
|
|
|
165
183
|
return self
|
|
166
184
|
|
|
167
185
|
|
|
168
|
-
class
|
|
186
|
+
class BaseColumnParameterSchema(BaseColumnBaseParameterSchema):
|
|
187
|
+
# single column parameter schema common across default and custom metrics
|
|
169
188
|
parameter_type: Literal["column"] = "column"
|
|
170
189
|
|
|
171
190
|
|
|
172
|
-
|
|
173
|
-
|
|
191
|
+
class MetricsColumnParameterSchema(MetricsParameterSchema, BaseColumnParameterSchema):
|
|
192
|
+
# single column parameter schema specific to default metrics
|
|
193
|
+
parameter_type: Literal["column"] = "column"
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
class MetricsColumnListParameterSchema(MetricsParameterSchema, BaseColumnParameterSchema):
|
|
197
|
+
# list column parameter schema specific to default metrics
|
|
174
198
|
parameter_type: Literal["column_list"] = "column_list"
|
|
175
199
|
|
|
176
200
|
|
|
@@ -186,6 +210,13 @@ MetricsColumnSchemaUnion = (
|
|
|
186
210
|
)
|
|
187
211
|
|
|
188
212
|
|
|
213
|
+
CustomAggregationParametersSchemaUnion = (
|
|
214
|
+
BaseDatasetParameterSchema
|
|
215
|
+
| BaseLiteralParameterSchema
|
|
216
|
+
| BaseColumnParameterSchema
|
|
217
|
+
)
|
|
218
|
+
|
|
219
|
+
|
|
189
220
|
@dataclass
|
|
190
221
|
class DatasetReference:
|
|
191
222
|
dataset_name: str
|
|
@@ -229,3 +260,28 @@ class AggregationSpecSchema(BaseModel):
|
|
|
229
260
|
f"Column parameter '{param.parameter_key}' references dataset parameter '{param.source_dataset_parameter_key}' which does not exist.",
|
|
230
261
|
)
|
|
231
262
|
return self
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
class BaseReportedAggregation(BaseModel):
|
|
266
|
+
# in future will be used by default metrics
|
|
267
|
+
metric_name: str = Field(description="Name of the reported aggregation metric.")
|
|
268
|
+
description: str = Field(
|
|
269
|
+
description="Description of the reported aggregation metric and what it aggregates.",
|
|
270
|
+
)
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
class ReportedCustomAggregation(BaseReportedAggregation):
|
|
274
|
+
value_column: str = Field(description="Name of the column returned from the SQL query holding the metric value.")
|
|
275
|
+
timestamp_column: str = Field(description="Name of the column returned from the SQL query holding the timestamp buckets.")
|
|
276
|
+
metric_kind: AggregationMetricType = Field(
|
|
277
|
+
description="Return type of the reported aggregation metric value.",
|
|
278
|
+
)
|
|
279
|
+
dimension_columns: list[str] = Field(description="Name of any dimension columns returned from the SQL query. Max length is 1.")
|
|
280
|
+
|
|
281
|
+
@field_validator('dimension_columns')
|
|
282
|
+
@classmethod
|
|
283
|
+
def validate_dimension_columns_length(cls, v: list[str]) -> str:
|
|
284
|
+
if len(v) > 1:
|
|
285
|
+
raise ValueError('Only one dimension column can be specified.')
|
|
286
|
+
return v
|
|
287
|
+
|
arthur_common/models/shield.py
CHANGED
|
@@ -10,9 +10,7 @@ DEFAULT_PII_RULE_CONFIDENCE_SCORE_THRESHOLD = 0
|
|
|
10
10
|
|
|
11
11
|
class RuleType(str, Enum):
|
|
12
12
|
KEYWORD = "KeywordRule"
|
|
13
|
-
MODEL_HALLUCINATION = "ModelHallucinationRule"
|
|
14
13
|
MODEL_HALLUCINATION_V2 = "ModelHallucinationRuleV2"
|
|
15
|
-
MODEL_HALLUCINATION_V3 = "ModelHallucinationRuleV3"
|
|
16
14
|
MODEL_SENSITIVE_DATA = "ModelSensitiveDataRule"
|
|
17
15
|
PII_DATA = "PIIDataRule"
|
|
18
16
|
PROMPT_INJECTION = "PromptInjectionRule"
|
|
@@ -456,14 +454,6 @@ class NewRuleRequest(BaseModel):
|
|
|
456
454
|
detail="PromptInjectionRule can only be enabled for prompt. Please set the 'apply_to_response' field "
|
|
457
455
|
"to false.",
|
|
458
456
|
)
|
|
459
|
-
if (self.type == RuleType.MODEL_HALLUCINATION) and (
|
|
460
|
-
self.apply_to_prompt is True
|
|
461
|
-
):
|
|
462
|
-
raise HTTPException(
|
|
463
|
-
status_code=400,
|
|
464
|
-
detail="ModelHallucinationRule can only be enabled for response. Please set the 'apply_to_prompt' "
|
|
465
|
-
"field to false.",
|
|
466
|
-
)
|
|
467
457
|
if (self.type == RuleType.MODEL_HALLUCINATION_V2) and (
|
|
468
458
|
self.apply_to_prompt is True
|
|
469
459
|
):
|
|
@@ -472,14 +462,6 @@ class NewRuleRequest(BaseModel):
|
|
|
472
462
|
detail="ModelHallucinationRuleV2 can only be enabled for response. Please set the 'apply_to_prompt' "
|
|
473
463
|
"field to false.",
|
|
474
464
|
)
|
|
475
|
-
if (self.type == RuleType.MODEL_HALLUCINATION_V3) and (
|
|
476
|
-
self.apply_to_prompt is True
|
|
477
|
-
):
|
|
478
|
-
raise HTTPException(
|
|
479
|
-
status_code=400,
|
|
480
|
-
detail="ModelHallucinationRuleV3 can only be enabled for response. Please set the "
|
|
481
|
-
"'apply_to_prompt' field to false.",
|
|
482
|
-
)
|
|
483
465
|
if (self.apply_to_prompt is False) and (self.apply_to_response is False):
|
|
484
466
|
raise HTTPException(
|
|
485
467
|
status_code=400,
|
|
@@ -23,10 +23,10 @@ arthur_common/config/settings.yaml,sha256=0CrygUwJzC5mGcO5Xnvv2ttp-P7LIsx682jllY
|
|
|
23
23
|
arthur_common/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
24
24
|
arthur_common/models/connectors.py,sha256=5f5DUgOQ16P3lBPZ0zpUv9kTAqw45Agrl526F-iFJes,1862
|
|
25
25
|
arthur_common/models/datasets.py,sha256=giG_8mv_3ilBf7cIvRV0_TDCDdb4qxRbYZvl7hRb6l8,491
|
|
26
|
-
arthur_common/models/metrics.py,sha256=
|
|
26
|
+
arthur_common/models/metrics.py,sha256=ibJK2WkTw_yCTanx_4oU3CZFEmMWf9BcZYWeuvXsd7E,10885
|
|
27
27
|
arthur_common/models/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
28
28
|
arthur_common/models/schema_definitions.py,sha256=0zXZKHKr49d7ATml2Tzw1AIFfM0i0HjIblM-qOwNxk8,14878
|
|
29
|
-
arthur_common/models/shield.py,sha256=
|
|
29
|
+
arthur_common/models/shield.py,sha256=62SKLzlsUsuP3u7EnibtI1CrRYg3TummP4Wbwg5ZPUs,18310
|
|
30
30
|
arthur_common/models/task_job_specs.py,sha256=uZo8eiTBHWf2EZGEQrDfJGVyYg_8wd9MHWLxn-5oNUk,2797
|
|
31
31
|
arthur_common/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
32
32
|
arthur_common/tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -38,6 +38,6 @@ arthur_common/tools/functions.py,sha256=FWL4eWO5-vLp86WudT-MGUKvf2B8f02IdoXQFKd6
|
|
|
38
38
|
arthur_common/tools/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
39
39
|
arthur_common/tools/schema_inferer.py,sha256=Ur4CXGAkd6ZMSU0nMNrkOEElsBopHXq0lctTV8X92W8,5188
|
|
40
40
|
arthur_common/tools/time_utils.py,sha256=4gfiu9NXfvPZltiVNLSIQGylX6h2W0viNi9Kv4bKyfw,1410
|
|
41
|
-
arthur_common-2.1.
|
|
42
|
-
arthur_common-2.1.
|
|
43
|
-
arthur_common-2.1.
|
|
41
|
+
arthur_common-2.1.52.dist-info/METADATA,sha256=LfIOLc5zbA8nx7aTwN65q7L3JmGZOdhQGSYmnSn_Mh8,1609
|
|
42
|
+
arthur_common-2.1.52.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
|
43
|
+
arthur_common-2.1.52.dist-info/RECORD,,
|
|
File without changes
|