Skip to content

Commit 3310f9f

Browse files
committed
Pass everything.
1 parent 1546793 commit 3310f9f

3 files changed

Lines changed: 27 additions & 33 deletions

File tree

src/modelbench/record.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,9 @@ def default(self, o):
103103
del result["_scoring_log"]
104104
return result
105105
elif isinstance(o, BenchmarkDefinition):
106-
benchmark_version = o.get_uid_part("version")
107-
return {"uid": o.uid, "hazards": o.hazards(), "version": benchmark_version}
106+
def_dict = {"uid": o.uid, "hazards": o.hazards()}
107+
def_dict.update(o.uid_dict)
108+
return def_dict
108109
elif isinstance(o, HazardDefinition):
109110
result = {"uid": o.uid, "reference_standard": o.reference_standard()}
110111
if o._tests:

src/modelbench/uid.py

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,13 @@ def __init__(self):
4545
This object's UID would be "ice_cream-chocolate"
4646
"""
4747

48-
@staticmethod
49-
def _render_uid(self, uid_def):
48+
@property
49+
def uid_definition(self) -> dict:
50+
if not hasattr(self.__class__, "_uid_definition"):
51+
raise AttributeError("classes with HasUid must define _uid_definition")
52+
return self.__class__._uid_definition
53+
54+
def _as_string(self, k, o):
5055
def clean_string(s):
5156
if isinstance(s, Enum):
5257
s = s.value.lower()
@@ -56,38 +61,25 @@ def clean_string(s):
5661
else:
5762
return s
5863

59-
def as_string(k, o):
60-
if k == "class" and o == "self":
61-
return clean_string(self.__class__.__name__)
62-
if isinstance(o, type):
63-
return clean_string(o.__name__)
64-
if isinstance(o, classmethod):
65-
return clean_string(str(o.__wrapped__(self.__class__)))
66-
if callable(o):
67-
return clean_string(str(o(self)))
68-
if o.startswith("self."):
69-
return clean_string(self.__getattribute__(o[5:]))
70-
return clean_string(str(o))
71-
72-
return "-".join(as_string(k, v) for k, v in uid_def.items())
64+
if k == "class" and o == "self":
65+
return clean_string(self.__class__.__name__)
66+
if isinstance(o, type):
67+
return clean_string(o.__name__)
68+
if isinstance(o, classmethod):
69+
return clean_string(str(o.__wrapped__(self.__class__)))
70+
if callable(o):
71+
return clean_string(str(o(self)))
72+
if o.startswith("self."):
73+
return clean_string(self.__getattribute__(o[5:]))
74+
return clean_string(str(o))
7375

7476
@property
75-
def uid(self):
76-
if not hasattr(self.__class__, "_uid_definition"):
77-
raise AttributeError("classes with HasUid must define _uid_definition")
77+
def uid(self) -> str:
78+
return "-".join(self._as_string(k, v) for k, v in self.uid_definition.items())
7879

79-
return HasUid._render_uid(self, self.__class__._uid_definition)
80-
81-
def get_uid_part(self, part_name: str) -> str:
82-
"""Gets string-rendered value of a specific part of the UID."""
83-
if not hasattr(self.__class__, "_uid_definition"):
84-
raise AttributeError("classes with HasUid must define _uid_definition")
85-
86-
uid_def = self.__class__._uid_definition
87-
if part_name not in uid_def:
88-
raise KeyError(f"part name {part_name} not found in _uid_definition")
89-
90-
return HasUid._render_uid(self, {part_name: uid_def[part_name]})
80+
@property
81+
def uid_dict(self) -> dict:
82+
return {k: self._as_string(k, v) for k, v in self.uid_definition.items()}
9183

9284
def __str__(self):
9385
return f"{self.__class__.__name__}({self.uid})"

tests/modelbench_tests/test_record.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ def test_general_benchmark_definition():
190190
j = encode_and_parse(GeneralPurposeAiChatBenchmarkV1(locale=EN_US, prompt_set="practice"))
191191
assert j["uid"] == "general_purpose_ai_chat_benchmark-1.1-en_us-practice-default"
192192
assert j["version"] == "1.1"
193+
assert j["prompt_set"] == "practice"
193194
assert "safe_hazard-1.1-cse-en_us-practice" in [i["uid"] for i in j["hazards"]]
194195

195196

0 commit comments

Comments
 (0)