dyff-schema 0.27.3__py3-none-any.whl → 0.28.0__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 dyff-schema might be problematic. Click here for more details.

dyff/schema/__init__.py CHANGED
@@ -2,11 +2,11 @@
2
2
  # SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import importlib
5
- from typing import Iterable, Type
5
+ from typing import Any, Iterable, Type, TypeVar, Union
6
6
 
7
7
  import pydantic
8
8
 
9
- from .base import DyffSchemaBaseModel
9
+ from .base import DyffBaseModel, DyffSchemaBaseModel
10
10
  from .version import SomeSchemaVersion
11
11
 
12
12
 
@@ -33,7 +33,34 @@ def named_data_schema(
33
33
  return _symbol(f"dyff.schema.v{version}.r{revision}.dataset.{name}")
34
34
 
35
35
 
36
+ _UpcastTargetT = TypeVar("_UpcastTargetT", bound=DyffBaseModel)
37
+ _UpcastSourceT = TypeVar("_UpcastSourceT", bound=DyffBaseModel)
38
+
39
+
40
+ def upcast(
41
+ t: type[_UpcastTargetT], obj: Union[_UpcastSourceT, dict[str, Any]]
42
+ ) -> _UpcastTargetT:
43
+ """Perform a "structural upcast" on a Pydantic model instance.
44
+
45
+ An upcast is possible when the top-level fields of the target type are a subset of
46
+ the top-level fields of the source type, and the data in each source field validates
47
+ against the corresponding target field. In particular, an upcast is possible when
48
+ the source type is a Python subclass of the target type.
49
+
50
+ The upcast is "shallow" in the sense that sub-objects must validate as-is. In
51
+ particular, most Dyff schema types do not allow additional properties, so validation
52
+ will fail if a sub-object of the source object has fields that are not present in
53
+ the corresponding sub-object of the target type.
54
+ """
55
+ if not isinstance(obj, dict):
56
+ # Preserve the unset status
57
+ obj = obj.dict(exclude_unset=True)
58
+ fields = {k: v for k, v in obj.items() if k in t.__fields__}
59
+ return t.parse_obj(fields)
60
+
61
+
36
62
  __all__ = [
37
63
  "named_data_schema",
38
64
  "product_schema",
65
+ "upcast",
39
66
  ]
@@ -15,7 +15,6 @@ from .base import DyffSchemaBaseModel, JsonMergePatchSemantics, Null
15
15
  from .platform import (
16
16
  DyffEntityType,
17
17
  EntityIdentifier,
18
- EntityKindLiteral,
19
18
  FamilyMember,
20
19
  FamilyMembers,
21
20
  LabelKeyType,
@@ -60,6 +59,7 @@ class Command(SchemaVersion, DyffSchemaBaseModel):
60
59
  "EditEntityLabels",
61
60
  "EditFamilyMembers",
62
61
  "ForgetEntity",
62
+ "RestoreEntity",
63
63
  "UpdateEntityStatus",
64
64
  ]
65
65
 
@@ -219,6 +219,43 @@ class ForgetEntity(Command):
219
219
  # ----------------------------------------------------------------------------
220
220
 
221
221
 
222
+ class RestoreEntityAttributes(DyffSchemaBaseModel):
223
+ entity: DyffEntityType = pydantic.Field(
224
+ description="The full spec of the entity to restore."
225
+ )
226
+
227
+ ifRevisionMatch: Optional[str] = pydantic.Field(
228
+ default=None,
229
+ description="Do not change the entity if its revision does not match"
230
+ " the given revision.",
231
+ )
232
+
233
+ ifRevisionUndefined: Optional[bool] = pydantic.Field(
234
+ default=None,
235
+ description="Allow changing entities that have no revision."
236
+ " By default, entities with no revision will be changed if and only if"
237
+ " no other matching criteria are specified."
238
+ " This should be the case only for legacy data.",
239
+ )
240
+
241
+
242
+ class RestoreEntityData(EntityIdentifier):
243
+ attributes: RestoreEntityAttributes = pydantic.Field(
244
+ description="The command attributes"
245
+ )
246
+
247
+
248
+ class RestoreEntity(Command):
249
+ """Restore an entity to a given state."""
250
+
251
+ command: Literal["RestoreEntity"] = "RestoreEntity"
252
+
253
+ data: RestoreEntityData = pydantic.Field(description="The command data.")
254
+
255
+
256
+ # ----------------------------------------------------------------------------
257
+
258
+
222
259
  class UpdateEntityStatusAttributes(JsonMergePatchSemantics):
223
260
  """Attributes for the UpdateEntityStatus command."""
224
261
 
@@ -256,6 +293,7 @@ DyffCommandType = Union[
256
293
  EditEntityLabels,
257
294
  EditFamilyMembers,
258
295
  ForgetEntity,
296
+ RestoreEntity,
259
297
  UpdateEntityStatus,
260
298
  ]
261
299
 
@@ -277,6 +315,9 @@ __all__ = [
277
315
  "EntityIdentifier",
278
316
  "FamilyIdentifier",
279
317
  "ForgetEntity",
318
+ "RestoreEntity",
319
+ "RestoreEntityAttributes",
320
+ "RestoreEntityData",
280
321
  "UpdateEntityStatus",
281
322
  "UpdateEntityStatusAttributes",
282
323
  "UpdateEntityStatusData",
@@ -301,9 +301,7 @@ class EntityIdentifier(DyffSchemaBaseModel):
301
301
 
302
302
  id: str = pydantic.Field(description="The .id of the entity.")
303
303
  kind: EntityKindLiteral = pydantic.Field(
304
- description="The .kind of the entity. This is optional because"
305
- " sometimes you need to send a command without knowing the kind,"
306
- " but it should be set whenever possible.",
304
+ description="The .kind of the entity.",
307
305
  )
308
306
 
309
307
 
@@ -20,6 +20,7 @@ from typing import Any, Literal, Optional, Union
20
20
 
21
21
  import pydantic
22
22
 
23
+ from ... import upcast
23
24
  from . import commands
24
25
  from .base import DyffBaseModel, JsonMergePatchSemantics, Null
25
26
  from .platform import (
@@ -29,6 +30,7 @@ from .platform import (
29
30
  DatasetBase,
30
31
  DataView,
31
32
  DocumentationBase,
33
+ Evaluation,
32
34
  EvaluationBase,
33
35
  FamilyBase,
34
36
  FamilyMemberBase,
@@ -197,6 +199,27 @@ class EvaluationCreateRequest(DyffEntityCreateRequest, EvaluationBase):
197
199
  )
198
200
  return values
199
201
 
202
+ @staticmethod
203
+ def repeat_of(evaluation: Evaluation) -> EvaluationCreateRequest:
204
+ """Return a request that will run an existing Evaluation again with the same
205
+ configuration."""
206
+ base = upcast(EvaluationBase, evaluation)
207
+ if evaluation.inferenceSessionReference:
208
+ return EvaluationCreateRequest(
209
+ account=evaluation.account,
210
+ inferenceSessionReference=evaluation.inferenceSessionReference,
211
+ **base.dict(),
212
+ )
213
+ else:
214
+ return EvaluationCreateRequest(
215
+ account=evaluation.account,
216
+ inferenceSession=EvaluationInferenceSessionRequest(
217
+ inferenceService=evaluation.inferenceSession.inferenceService.id,
218
+ **upcast(InferenceSessionBase, evaluation.inferenceSession).dict(),
219
+ ),
220
+ **base.dict(),
221
+ )
222
+
200
223
 
201
224
  class FamilyCreateRequest(DyffEntityCreateRequest, FamilyBase):
202
225
  pass
@@ -403,6 +426,7 @@ class ScoreQueryRequest(DyffRequestDefaultValidators):
403
426
 
404
427
  id: Optional[str] = pydantic.Field(default=None)
405
428
  name: Optional[str] = pydantic.Field(default=None)
429
+ analysis: Optional[str] = pydantic.Field(default=None)
406
430
  method: Optional[str] = pydantic.Field(default=None)
407
431
  methodName: Optional[str] = pydantic.Field(default=None)
408
432
  dataset: Optional[str] = pydantic.Field(default=None)
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: dyff-schema
3
- Version: 0.27.3
3
+ Version: 0.28.0
4
4
  Summary: Data models for the Dyff AI auditing platform.
5
5
  Author-email: Digital Safety Research Institute <contact@dsri.org>
6
6
  License: Apache-2.0
@@ -27,6 +27,7 @@ Requires-Dist: jsonpath-ng
27
27
  Requires-Dist: numpy<2
28
28
  Requires-Dist: pyarrow
29
29
  Requires-Dist: pydantic<2
30
+ Dynamic: license-file
30
31
 
31
32
  # dyff-schema
32
33
 
@@ -1,4 +1,4 @@
1
- dyff/schema/__init__.py,sha256=JcpxaRHNYgLjJWLjVayLlqacb2GX49Pazpwb8m-BctM,1031
1
+ dyff/schema/__init__.py,sha256=Nua_5EC8HHIxBp6u0SmnApz1WmlYSJ8tDsayD4zEl_Y,2237
2
2
  dyff/schema/adapters.py,sha256=YMTHv_2VlLGFp-Kqwa6H51hjffHmk8gXjZilHysIF5Q,123
3
3
  dyff/schema/annotations.py,sha256=nE6Jk1PLqlShj8uqjE_EzZC9zYnTDW5AVtQcjysiK8M,10018
4
4
  dyff/schema/base.py,sha256=jvaNtsSZyFfsdUZTcY_U-yfLY5_GyrMxSXhON2R9XR0,119
@@ -25,9 +25,9 @@ dyff/schema/v0/__init__.py,sha256=L5y8UhRnojerPYHumsxQJRcHCNz8Hj9NM8b47mewMNs,92
25
25
  dyff/schema/v0/r1/__init__.py,sha256=L5y8UhRnojerPYHumsxQJRcHCNz8Hj9NM8b47mewMNs,92
26
26
  dyff/schema/v0/r1/adapters.py,sha256=dmQS2ecgDX4ZvTMOW-6NzV_Oq_UpaiyFd7QnSNoOnK8,33057
27
27
  dyff/schema/v0/r1/base.py,sha256=Rry7GKdQyCLNXskB1CxqVlhVsgM8pw6a4xy3BFk_lRc,21095
28
- dyff/schema/v0/r1/commands.py,sha256=eBXoDxmRZ9s2Idj1srmIaLPCn6QVbWXwpbNDHaJZDco,8354
29
- dyff/schema/v0/r1/platform.py,sha256=XqDSV0vCLjSPwwMe87Ah6qz4rYCGg9eMYuVf6VUFViM,81566
30
- dyff/schema/v0/r1/requests.py,sha256=AIBzfOnDEMVh1sCOCM6oKMVwZTCW3v9f5BVKB2s3-X0,16025
28
+ dyff/schema/v0/r1/commands.py,sha256=zgaggy9x2lPaDwRSVtyd7jrZ2gjJDbyghsdj2RmEaBs,9607
29
+ dyff/schema/v0/r1/platform.py,sha256=BNKQt-2udkPt7_Qg5s-I0U8m3Sb7eKbQYqvg87rkNfg,81416
30
+ dyff/schema/v0/r1/requests.py,sha256=56R_yOdbDOEcY0og2GoY5bXeG6ifn7z3ypNdBOF_igk,17043
31
31
  dyff/schema/v0/r1/test.py,sha256=X6dUyVd5svcPCI-PBMOAqEfK9jv3bRDvkQTJzwS96c0,10720
32
32
  dyff/schema/v0/r1/version.py,sha256=isKAGuGxsdru8vDaYmI4YiZdJOu_wNxXK7u6QzD6FE4,392
33
33
  dyff/schema/v0/r1/dataset/__init__.py,sha256=LbVlkO2asyGYBKk2z49xjJYTM-pu9y9e4eQDXgTDLnM,2553
@@ -39,9 +39,9 @@ dyff/schema/v0/r1/dataset/text.py,sha256=nLIn91Zlt0tNdXUklSgjJ-kEDxoPX32ISLkiv2D
39
39
  dyff/schema/v0/r1/dataset/vision.py,sha256=aIe0fbfM_g3DsrDTdg2K803YKLjZBpurM_VJcJFuZLc,369
40
40
  dyff/schema/v0/r1/io/__init__.py,sha256=L5y8UhRnojerPYHumsxQJRcHCNz8Hj9NM8b47mewMNs,92
41
41
  dyff/schema/v0/r1/io/vllm.py,sha256=CUE9y8KthtUI7sD49S875rDmPvKotSXVIRaBS79aBZs,5320
42
- dyff_schema-0.27.3.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
43
- dyff_schema-0.27.3.dist-info/METADATA,sha256=tHACi-1R9vZ6FRJ9WViyF41vFt4eEYDzERRT6sC1jAU,3482
44
- dyff_schema-0.27.3.dist-info/NOTICE,sha256=YONACu0s_Ui6jNi-wtEsVQbTU1JIkh8wvLH6d1-Ni_w,43
45
- dyff_schema-0.27.3.dist-info/WHEEL,sha256=52BFRY2Up02UkjOa29eZOS2VxUrpPORXg1pkohGGUS8,91
46
- dyff_schema-0.27.3.dist-info/top_level.txt,sha256=9e3VVdeX73t_sUJOPQPCcGtYO1JhoErhHIi3WoWGcFI,5
47
- dyff_schema-0.27.3.dist-info/RECORD,,
42
+ dyff_schema-0.28.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
43
+ dyff_schema-0.28.0.dist-info/licenses/NOTICE,sha256=YONACu0s_Ui6jNi-wtEsVQbTU1JIkh8wvLH6d1-Ni_w,43
44
+ dyff_schema-0.28.0.dist-info/METADATA,sha256=2SxPi0TcWR7YZcaINtotNvXiyI7kkfbEAhm3CkD1hGg,3504
45
+ dyff_schema-0.28.0.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
46
+ dyff_schema-0.28.0.dist-info/top_level.txt,sha256=9e3VVdeX73t_sUJOPQPCcGtYO1JhoErhHIi3WoWGcFI,5
47
+ dyff_schema-0.28.0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (76.0.0)
2
+ Generator: setuptools (78.1.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5