dyff-schema 0.16.1__py3-none-any.whl → 0.18.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.

@@ -23,7 +23,6 @@ import abc
23
23
  import enum
24
24
  import urllib.parse
25
25
  from datetime import datetime
26
- from decimal import Decimal
27
26
  from enum import Enum
28
27
  from typing import Any, Literal, NamedTuple, Optional, Type, Union
29
28
 
@@ -160,6 +159,26 @@ def _oci_image_tag_maxlen():
160
159
  return 127
161
160
 
162
161
 
162
+ def identifier_regex():
163
+ """Python identifiers start with a letter or an underscore, and consist of letters,
164
+ numbers, and underscores."""
165
+ return r"^[a-zA-Z_][a-zA-Z0-9_]*$"
166
+
167
+
168
+ def identifier_maxlen():
169
+ """There isn't really a max length for Python identifiers, but this seems like a
170
+ reasonable limit for our use."""
171
+ return 127
172
+
173
+
174
+ def title_maxlen() -> int:
175
+ return 140
176
+
177
+
178
+ def summary_maxlen() -> int:
179
+ return 280
180
+
181
+
163
182
  class Entities(str, enum.Enum):
164
183
  """The kinds of entities in the dyff system."""
165
184
 
@@ -1559,42 +1578,51 @@ class ScoreSpec(DyffSchemaBaseModel):
1559
1578
  name: str = pydantic.Field(
1560
1579
  description="The name of the score. Used as a key for retrieving score data."
1561
1580
  " Must be unique within the Method context.",
1581
+ regex=identifier_regex(),
1582
+ max_length=identifier_maxlen(),
1562
1583
  )
1563
1584
 
1564
1585
  title: str = pydantic.Field(
1565
1586
  description="The title text to use when displaying score information.",
1566
- max_length=140,
1587
+ max_length=title_maxlen(),
1567
1588
  )
1568
1589
 
1569
1590
  summary: str = pydantic.Field(
1570
1591
  description="A short text description of what the score measures.",
1571
- max_length=140,
1592
+ max_length=summary_maxlen(),
1572
1593
  )
1573
1594
 
1574
1595
  valence: Literal["positive", "negative", "neutral"] = pydantic.Field(
1596
+ default="neutral",
1575
1597
  description="A score has 'positive' valence if 'more is better',"
1576
1598
  " 'negative' valence if 'less is better', and 'neutral' valence if"
1577
- " 'better' is not meaningful for this score."
1599
+ " 'better' is not meaningful for this score.",
1578
1600
  )
1579
1601
 
1580
1602
  priority: Literal["primary", "secondary"] = pydantic.Field(
1603
+ default="primary",
1581
1604
  description="The 'primary' score will be displayed in any UI widgets"
1582
- " that expect a single score."
1605
+ " that expect a single score. There must be exactly 1 primary score.",
1583
1606
  )
1584
1607
 
1585
- minimum: Optional[Decimal] = pydantic.Field(
1608
+ minimum: Optional[float] = pydantic.Field(
1586
1609
  default=None, description="The minimum possible value, if known."
1587
1610
  )
1588
1611
 
1589
- maximum: Optional[Decimal] = pydantic.Field(
1612
+ maximum: Optional[float] = pydantic.Field(
1590
1613
  default=None, description="The maximum possible value, if known."
1591
1614
  )
1592
1615
 
1593
1616
  format: str = pydantic.Field(
1594
- default="{quantity}",
1617
+ default="{quantity:.1f}",
1618
+ # Must use the 'quantity' key in the format string:
1619
+ # (Maybe string not ending in '}')(something like '{quantity:f}')(maybe another string)
1620
+ regex=r"^(.*[^{])?[{]quantity(:[^}]*)?[}]([^}].*)?$",
1595
1621
  description="A Python 'format' string describing how to render the score"
1596
- " as a string. You can use the keys 'quantity' and 'unit' in the format"
1597
- " string (e.g., '{quantity} {unit}').",
1622
+ " as a string. You *must* use the keyword 'quantity' in the format"
1623
+ " string, and you may use 'unit' as well (e.g., '{quantity:.2f} {unit}')."
1624
+ " It is *strongly recommended* that you limit the output precision"
1625
+ " appropriately; use ':.0f' for integer-valued scores.",
1598
1626
  )
1599
1627
 
1600
1628
  unit: Optional[str] = pydantic.Field(
@@ -1603,6 +1631,11 @@ class ScoreSpec(DyffSchemaBaseModel):
1603
1631
  " Use standard SI abbreviations where possible for better indexing.",
1604
1632
  )
1605
1633
 
1634
+ def quantity_string(self, quantity: float) -> str:
1635
+ """Formats the given quantity as a string, according to the formatting
1636
+ information stored in this ScoreSpec."""
1637
+ return self.format_quantity(self.format, quantity, unit=self.unit)
1638
+
1606
1639
  @pydantic.root_validator
1607
1640
  def _validate_minimum_maximum(cls, values):
1608
1641
  minimum = values.get("minimum")
@@ -1613,15 +1646,17 @@ class ScoreSpec(DyffSchemaBaseModel):
1613
1646
 
1614
1647
  @pydantic.validator("format")
1615
1648
  def _validate_format(cls, v):
1616
- try:
1617
- cls._format_quantity(v, Decimal("3.14"), unit="kg")
1618
- except Exception:
1619
- raise ValueError(f"invalid format: '{v}'")
1649
+ x = cls.format_quantity(v, 3.14, unit="kg")
1650
+ y = cls.format_quantity(v, -2.03, unit="kg")
1651
+ if x == y:
1652
+ # Formatted results for different quantities should be different
1653
+ raise ValueError("format string does not mention 'quantity'")
1654
+
1620
1655
  return v
1621
1656
 
1622
1657
  @classmethod
1623
- def _format_quantity(
1624
- cls, format: str, quantity: Decimal, *, unit: Optional[str] = None
1658
+ def format_quantity(
1659
+ cls, format: str, quantity: float, *, unit: Optional[str] = None
1625
1660
  ) -> str:
1626
1661
  return format.format(quantity=quantity, unit=unit)
1627
1662
 
@@ -1824,19 +1859,20 @@ class ScoreData(ScoreSpec):
1824
1859
  description="The Analysis that generated the current score instance."
1825
1860
  )
1826
1861
 
1827
- quantity: Decimal = pydantic.Field(
1862
+ quantity: float = pydantic.Field(
1828
1863
  description="The numeric quantity associated with the score."
1829
- " Callers should set the desired precision explicitly."
1864
+ )
1865
+
1866
+ quantityString: str = pydantic.Field(
1867
+ description="The formatted string representation of .quantity,"
1868
+ " after processing with the .format specification."
1830
1869
  )
1831
1870
 
1832
1871
  text: str = pydantic.Field(
1833
1872
  description="A short text description of what the quantity means.",
1834
- max_length=140,
1873
+ max_length=summary_maxlen(),
1835
1874
  )
1836
1875
 
1837
- def format_quantity(self) -> str:
1838
- return self._format_quantity(self.format, self.quantity, unit=self.unit)
1839
-
1840
1876
 
1841
1877
  class Score(ScoreData):
1842
1878
  """A Score is a numeric quantity describing an aspect of system performance.
@@ -2160,6 +2196,7 @@ DyffEntityType = Union[DyffEntityTypeExceptRevision, Revision]
2160
2196
 
2161
2197
 
2162
2198
  __all__ = [
2199
+ "SYSTEM_ATTRIBUTES",
2163
2200
  "Accelerator",
2164
2201
  "AcceleratorGPU",
2165
2202
  "AccessGrant",
@@ -2193,6 +2230,7 @@ __all__ = [
2193
2230
  "DocumentationBase",
2194
2231
  "DyffDataSchema",
2195
2232
  "DyffEntity",
2233
+ "DyffEntityType",
2196
2234
  "DyffModelWithID",
2197
2235
  "DyffSchemaBaseModel",
2198
2236
  "Entities",
@@ -2295,9 +2333,11 @@ __all__ = [
2295
2333
  "ModelStatusReason",
2296
2334
  "ReportStatus",
2297
2335
  "ReportStatusReason",
2336
+ "identifier_regex",
2337
+ "identifier_maxlen",
2298
2338
  "is_status_terminal",
2299
2339
  "is_status_failure",
2300
2340
  "is_status_success",
2301
- "DyffEntityType",
2302
- "SYSTEM_ATTRIBUTES",
2341
+ "summary_maxlen",
2342
+ "title_maxlen",
2303
2343
  ]
@@ -290,6 +290,25 @@ class SafetyCaseQueryRequest(_AnalysisProductQueryRequest):
290
290
  pass
291
291
 
292
292
 
293
+ class ScoreQueryRequest(DyffRequestDefaultValidators):
294
+ query: Optional[str] = pydantic.Field(
295
+ default=None,
296
+ description="A JSON structure describing a query, encoded as a string."
297
+ " Valid keys are the same as the valid query keys for the corresponding"
298
+ " endpoint. Values can be scalars or lists. Lists are treated as"
299
+ " disjunctive queries (i.e., 'value $in list').",
300
+ )
301
+
302
+ id: Optional[str] = pydantic.Field(default=None)
303
+ name: Optional[str] = pydantic.Field(default=None)
304
+ method: Optional[str] = pydantic.Field(default=None)
305
+ methodName: Optional[str] = pydantic.Field(default=None)
306
+ dataset: Optional[str] = pydantic.Field(default=None)
307
+ evaluation: Optional[str] = pydantic.Field(default=None)
308
+ inferenceService: Optional[str] = pydantic.Field(default=None)
309
+ model: Optional[str] = pydantic.Field(default=None)
310
+
311
+
293
312
  __all__ = [
294
313
  "AnalysisCreateRequest",
295
314
  "AuditQueryRequest",
@@ -323,4 +342,5 @@ __all__ = [
323
342
  "ReportCreateRequest",
324
343
  "ReportQueryRequest",
325
344
  "SafetyCaseQueryRequest",
345
+ "ScoreQueryRequest",
326
346
  ]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dyff-schema
3
- Version: 0.16.1
3
+ Version: 0.18.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
@@ -23,8 +23,8 @@ dyff/schema/v0/__init__.py,sha256=L5y8UhRnojerPYHumsxQJRcHCNz8Hj9NM8b47mewMNs,92
23
23
  dyff/schema/v0/r1/__init__.py,sha256=L5y8UhRnojerPYHumsxQJRcHCNz8Hj9NM8b47mewMNs,92
24
24
  dyff/schema/v0/r1/adapters.py,sha256=2t2oxsnGfSEDKKDIEYw4qqLXMH7qlFIwPVuLyUmbsHs,23552
25
25
  dyff/schema/v0/r1/base.py,sha256=i7eOKXDGS8_J9k2aVObUTpSOnA8CAgRW7Quj1fSbyRg,19403
26
- dyff/schema/v0/r1/platform.py,sha256=GozVE9Z8Axc8q6hTMl-pNgx1VqyQTmmZ5FpkBhWiBNw,72509
27
- dyff/schema/v0/r1/requests.py,sha256=MMMtSfT9JpE2X7PLQGIuI4v7mMlJ-8DiZ65jc2hE0zc,10976
26
+ dyff/schema/v0/r1/platform.py,sha256=LqYVZdeRBBCY3OZ0L3dobhUmQPzN51ik4T9BoUyQHbM,73976
27
+ dyff/schema/v0/r1/requests.py,sha256=yvMHi4P02DIoibczP-PLMkgkh5XR_VFQNfCtFTorlYs,11891
28
28
  dyff/schema/v0/r1/test.py,sha256=X6dUyVd5svcPCI-PBMOAqEfK9jv3bRDvkQTJzwS96c0,10720
29
29
  dyff/schema/v0/r1/version.py,sha256=isKAGuGxsdru8vDaYmI4YiZdJOu_wNxXK7u6QzD6FE4,392
30
30
  dyff/schema/v0/r1/dataset/__init__.py,sha256=LbVlkO2asyGYBKk2z49xjJYTM-pu9y9e4eQDXgTDLnM,2553
@@ -35,9 +35,9 @@ dyff/schema/v0/r1/dataset/text.py,sha256=nLIn91Zlt0tNdXUklSgjJ-kEDxoPX32ISLkiv2D
35
35
  dyff/schema/v0/r1/dataset/vision.py,sha256=aIe0fbfM_g3DsrDTdg2K803YKLjZBpurM_VJcJFuZLc,369
36
36
  dyff/schema/v0/r1/io/__init__.py,sha256=L5y8UhRnojerPYHumsxQJRcHCNz8Hj9NM8b47mewMNs,92
37
37
  dyff/schema/v0/r1/io/vllm.py,sha256=CUE9y8KthtUI7sD49S875rDmPvKotSXVIRaBS79aBZs,5320
38
- dyff_schema-0.16.1.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
39
- dyff_schema-0.16.1.dist-info/METADATA,sha256=lkw05lD3LmoKsoh54qgxeDkcztewPcC26Zs0rLXhrkM,3482
40
- dyff_schema-0.16.1.dist-info/NOTICE,sha256=YONACu0s_Ui6jNi-wtEsVQbTU1JIkh8wvLH6d1-Ni_w,43
41
- dyff_schema-0.16.1.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
42
- dyff_schema-0.16.1.dist-info/top_level.txt,sha256=9e3VVdeX73t_sUJOPQPCcGtYO1JhoErhHIi3WoWGcFI,5
43
- dyff_schema-0.16.1.dist-info/RECORD,,
38
+ dyff_schema-0.18.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
39
+ dyff_schema-0.18.0.dist-info/METADATA,sha256=HN9-j-LkdQYLzQyKV18GoajMwOOAmchU8EQbjtaGIIc,3482
40
+ dyff_schema-0.18.0.dist-info/NOTICE,sha256=YONACu0s_Ui6jNi-wtEsVQbTU1JIkh8wvLH6d1-Ni_w,43
41
+ dyff_schema-0.18.0.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
42
+ dyff_schema-0.18.0.dist-info/top_level.txt,sha256=9e3VVdeX73t_sUJOPQPCcGtYO1JhoErhHIi3WoWGcFI,5
43
+ dyff_schema-0.18.0.dist-info/RECORD,,