verifiers 0.4.2.dev109__py3-none-any.whl → 0.4.2.dev110__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.
- verifiers/v1/judges/decision.py +108 -15
- {verifiers-0.4.2.dev109.dist-info → verifiers-0.4.2.dev110.dist-info}/METADATA +1 -1
- {verifiers-0.4.2.dev109.dist-info → verifiers-0.4.2.dev110.dist-info}/RECORD +6 -6
- {verifiers-0.4.2.dev109.dist-info → verifiers-0.4.2.dev110.dist-info}/WHEEL +0 -0
- {verifiers-0.4.2.dev109.dist-info → verifiers-0.4.2.dev110.dist-info}/entry_points.txt +0 -0
- {verifiers-0.4.2.dev109.dist-info → verifiers-0.4.2.dev110.dist-info}/licenses/LICENSE +0 -0
verifiers/v1/judges/decision.py
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"""Decision-model judge using Prime's evaluations API by default."""
|
|
2
2
|
|
|
3
3
|
import json
|
|
4
|
-
from
|
|
4
|
+
from collections.abc import Callable, Sequence
|
|
5
|
+
from typing import Any, TypeVar, cast
|
|
5
6
|
|
|
6
7
|
from pydantic import Field
|
|
7
8
|
|
|
@@ -17,7 +18,14 @@ from verifiers.v1.judge import (
|
|
|
17
18
|
)
|
|
18
19
|
from verifiers.v1.task import TaskData
|
|
19
20
|
from verifiers.v1.trace import Trace
|
|
20
|
-
from verifiers.v1.types import Usage
|
|
21
|
+
from verifiers.v1.types import Messages, Usage
|
|
22
|
+
|
|
23
|
+
_Result = TypeVar("_Result")
|
|
24
|
+
_MAX_QUESTIONS = 64
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class DecisionScoreError(ValueError):
|
|
28
|
+
"""The evaluations response has no valid numeric grade."""
|
|
21
29
|
|
|
22
30
|
|
|
23
31
|
class DecisionJudgeConfig(JudgeConfig):
|
|
@@ -34,6 +42,8 @@ class DecisionJudgeConfig(JudgeConfig):
|
|
|
34
42
|
"""Task field containing the question; empty uses the task's prompt text."""
|
|
35
43
|
answer_field: str = ""
|
|
36
44
|
"""Optional task field containing a reference answer to include in the state."""
|
|
45
|
+
images_field: str = ""
|
|
46
|
+
"""Optional task field containing an ordered list of image data URLs."""
|
|
37
47
|
view: JudgeView = "last_reply"
|
|
38
48
|
|
|
39
49
|
|
|
@@ -44,45 +54,119 @@ class DecisionJudge(Judge[float, DecisionJudgeConfig]):
|
|
|
44
54
|
)
|
|
45
55
|
|
|
46
56
|
async def evaluate(
|
|
47
|
-
self,
|
|
57
|
+
self,
|
|
58
|
+
*,
|
|
59
|
+
images: list[str] | None = None,
|
|
60
|
+
trace: Trace | None = None,
|
|
61
|
+
trace_state: dict[str, Any] | None = None,
|
|
62
|
+
**fields: Any,
|
|
48
63
|
) -> JudgeResponse[float]:
|
|
64
|
+
"""Score fields with optional image evidence. Supply trace_state to log compact artifact metadata."""
|
|
65
|
+
return await self._evaluate_questions(
|
|
66
|
+
{"grade": self.build_messages(**fields)},
|
|
67
|
+
fields,
|
|
68
|
+
images,
|
|
69
|
+
trace,
|
|
70
|
+
trace_state,
|
|
71
|
+
lambda scores: scores[0],
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
async def evaluate_batch(
|
|
75
|
+
self,
|
|
76
|
+
questions: Sequence[str | Messages],
|
|
77
|
+
/,
|
|
78
|
+
*,
|
|
79
|
+
images: list[str] | None = None,
|
|
80
|
+
trace: Trace | None = None,
|
|
81
|
+
trace_state: dict[str, Any] | None = None,
|
|
82
|
+
**fields: Any,
|
|
83
|
+
) -> list[float]:
|
|
84
|
+
"""Score ordered question prompts against shared evidence, up to 64 questions per request."""
|
|
85
|
+
if isinstance(questions, str):
|
|
86
|
+
raise TypeError("evaluate_batch expects a sequence of question prompts")
|
|
87
|
+
scores = []
|
|
88
|
+
for start in range(0, len(questions), _MAX_QUESTIONS):
|
|
89
|
+
batch = {
|
|
90
|
+
f"criterion_{i}": prompt
|
|
91
|
+
for i, prompt in enumerate(
|
|
92
|
+
questions[start : start + _MAX_QUESTIONS], start
|
|
93
|
+
)
|
|
94
|
+
}
|
|
95
|
+
result = await self._evaluate_questions(
|
|
96
|
+
batch, fields, images, trace, trace_state, list
|
|
97
|
+
)
|
|
98
|
+
scores.extend(cast(list[float], result.parsed))
|
|
99
|
+
return scores
|
|
100
|
+
|
|
101
|
+
async def _evaluate_questions(
|
|
102
|
+
self,
|
|
103
|
+
questions: dict[str, str | Messages],
|
|
104
|
+
fields: dict[str, Any],
|
|
105
|
+
images: list[str] | None,
|
|
106
|
+
trace: Trace | None,
|
|
107
|
+
trace_state: dict[str, Any] | None,
|
|
108
|
+
parse: Callable[[list[float]], _Result],
|
|
109
|
+
) -> JudgeResponse[_Result]:
|
|
49
110
|
request = {
|
|
50
111
|
**self.config.sampling.model_dump(exclude_none=True),
|
|
51
112
|
"model": self.config.model,
|
|
52
113
|
"state": fields,
|
|
53
114
|
"questions": {
|
|
54
|
-
|
|
115
|
+
key: {
|
|
55
116
|
"type": "score",
|
|
56
|
-
"instructions":
|
|
117
|
+
"instructions": prompt,
|
|
57
118
|
"criteria": self.config.levels,
|
|
58
119
|
}
|
|
120
|
+
for key, prompt in questions.items()
|
|
59
121
|
},
|
|
60
122
|
}
|
|
123
|
+
if images:
|
|
124
|
+
request["images"] = images
|
|
61
125
|
async with build_async_openai(self.config) as client:
|
|
62
126
|
raw = await client.post(
|
|
63
127
|
self.config.base_url, cast_to=dict[str, Any], body=request
|
|
64
128
|
)
|
|
65
129
|
result = raw.get("result", raw) # Workers AI wraps its response in `result`.
|
|
66
|
-
|
|
130
|
+
# Some providers echo the input state and image data in the response.
|
|
131
|
+
compact = bool(images) or trace_state is not None
|
|
132
|
+
answers = result.get("answers") if isinstance(result, dict) else None
|
|
133
|
+
response: JudgeResponse[_Result] = JudgeResponse(
|
|
134
|
+
text=json.dumps(answers if compact else raw)
|
|
135
|
+
)
|
|
67
136
|
try:
|
|
68
|
-
if usage := result.get("usage"):
|
|
137
|
+
if isinstance(result, dict) and (usage := result.get("usage")):
|
|
69
138
|
response.usage = Usage(
|
|
70
|
-
prompt_tokens=usage.get(
|
|
139
|
+
prompt_tokens=usage.get(
|
|
140
|
+
"inputTokens", usage.get("input_tokens", 0)
|
|
141
|
+
),
|
|
71
142
|
completion_tokens=usage.get(
|
|
72
|
-
"outputTokens", usage.get("output_tokens")
|
|
143
|
+
"outputTokens", usage.get("output_tokens", 0)
|
|
73
144
|
),
|
|
74
145
|
cost=usage.get("cost"),
|
|
75
146
|
)
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
147
|
+
maximum = len(self.config.levels) - 1
|
|
148
|
+
scores = []
|
|
149
|
+
for key in questions:
|
|
150
|
+
grade = answers.get(key) if isinstance(answers, dict) else None
|
|
151
|
+
score = grade.get("score") if isinstance(grade, dict) else None
|
|
152
|
+
if type(score) not in (int, float) or not 0 <= score <= maximum:
|
|
153
|
+
raise DecisionScoreError(
|
|
154
|
+
f"invalid decision judge score for {key}: {score!r}"
|
|
155
|
+
)
|
|
156
|
+
scores.append(score / maximum)
|
|
157
|
+
response.parsed = parse(scores)
|
|
80
158
|
return response
|
|
81
159
|
finally:
|
|
82
160
|
# The call was billed even if the score could not be parsed.
|
|
83
161
|
if trace is not None:
|
|
162
|
+
logged = request.copy()
|
|
163
|
+
if images:
|
|
164
|
+
del logged["images"]
|
|
165
|
+
logged["image_count"] = len(images)
|
|
166
|
+
if trace_state is not None:
|
|
167
|
+
logged["state"] = trace_state
|
|
84
168
|
trace.record_judge_call(
|
|
85
|
-
name=self.reward_name, request=
|
|
169
|
+
name=self.reward_name, request=logged, response=response
|
|
86
170
|
)
|
|
87
171
|
|
|
88
172
|
async def score(self, task: TaskData, trace: Trace) -> float:
|
|
@@ -100,8 +184,17 @@ class DecisionJudge(Judge[float, DecisionJudgeConfig]):
|
|
|
100
184
|
f"decision judge found no {self.config.answer_field!r} field on the task"
|
|
101
185
|
)
|
|
102
186
|
fields["answer"] = answer
|
|
187
|
+
if self.config.images_field:
|
|
188
|
+
images = getattr(task, self.config.images_field, None)
|
|
189
|
+
if not isinstance(images, list) or not all(
|
|
190
|
+
isinstance(url, str) for url in images
|
|
191
|
+
):
|
|
192
|
+
raise ValueError(
|
|
193
|
+
f"decision judge expected a list of image URLs in {self.config.images_field!r}"
|
|
194
|
+
)
|
|
195
|
+
fields["images"] = images
|
|
103
196
|
result = await self.evaluate(trace=trace, **fields)
|
|
104
197
|
return cast(float, result.parsed)
|
|
105
198
|
|
|
106
199
|
|
|
107
|
-
__all__ = ["DecisionJudge", "DecisionJudgeConfig"]
|
|
200
|
+
__all__ = ["DecisionJudge", "DecisionJudgeConfig", "DecisionScoreError"]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: verifiers
|
|
3
|
-
Version: 0.4.2.
|
|
3
|
+
Version: 0.4.2.dev110
|
|
4
4
|
Summary: Verifiers: Environments for LLM Reinforcement Learning
|
|
5
5
|
Project-URL: Homepage, https://github.com/primeintellect-ai/verifiers
|
|
6
6
|
Project-URL: Documentation, https://github.com/primeintellect-ai/verifiers
|
|
@@ -126,7 +126,7 @@ verifiers/v1/interception/tunnel/base.py,sha256=UrHXwbpB_qdh4WHWZHpi2D-wEHcHgg06
|
|
|
126
126
|
verifiers/v1/interception/tunnel/custom.py,sha256=SJ3F592zwmrLKrbNktWgkB_84Xfozf6tUWoGmWCitLk,817
|
|
127
127
|
verifiers/v1/interception/tunnel/prime.py,sha256=fT78wpeDHVNbEZHdIFzQsIPGSn2r3K9jDLtSbXP57_0,4109
|
|
128
128
|
verifiers/v1/judges/__init__.py,sha256=z-16awBqEZJrlVYIb9HD-rk12RaABh6jodJgwX4blnA,410
|
|
129
|
-
verifiers/v1/judges/decision.py,sha256=
|
|
129
|
+
verifiers/v1/judges/decision.py,sha256=UoUy4WF9Vq2FfrtdroDEhx2JYB086HWLMsLi6f8UtMo,7694
|
|
130
130
|
verifiers/v1/judges/reference.py,sha256=TsJUtftcEnC20MsIE0lA8wTdPzCoiLIJHxGBad-WOuI,3878
|
|
131
131
|
verifiers/v1/judges/reference.txt,sha256=Ej35kGXiT2uJ0LcHIeez49rCS_9uHmCQKoVdn93V6A8,353
|
|
132
132
|
verifiers/v1/judges/rubric.py,sha256=yRaOnc6S6cqrLuySkMsgxsBFCRUA2bBjYSa5qOT-inQ,16158
|
|
@@ -185,8 +185,8 @@ verifiers/v1/utils/scope.py,sha256=zbs4pj6AVk4jywlAJ3AX0Q0_kzB9dBB02nY-9H4ELdQ,8
|
|
|
185
185
|
verifiers/v1/utils/score.py,sha256=493yJVMw8teCu9JxapxMFPFzI0hNUqdo0Y2nGW4kckk,6200
|
|
186
186
|
verifiers/v1/utils/trace_store.py,sha256=7F6xMhYgl3qmylnCU8-ekqswH16fUat1uegeM1OR9QQ,2563
|
|
187
187
|
verifiers/v1/utils/version.py,sha256=-obEo_-l9-D8FLef4hYxncOe-uJpxrM1g2Hig_37Sgs,1607
|
|
188
|
-
verifiers-0.4.2.
|
|
189
|
-
verifiers-0.4.2.
|
|
190
|
-
verifiers-0.4.2.
|
|
191
|
-
verifiers-0.4.2.
|
|
192
|
-
verifiers-0.4.2.
|
|
188
|
+
verifiers-0.4.2.dev110.dist-info/METADATA,sha256=OLMdLhyqNonAypPwhojwNf50ZFE_zwaJ9XV_Y0ggo0Y,5118
|
|
189
|
+
verifiers-0.4.2.dev110.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
190
|
+
verifiers-0.4.2.dev110.dist-info/entry_points.txt,sha256=qdMg7ajiFpDsHf7tuPMRclJXizu1J6LTWawS5YS0B0I,137
|
|
191
|
+
verifiers-0.4.2.dev110.dist-info/licenses/LICENSE,sha256=v0RrUsdV3IDoZhrRce297IXS3xMHNJ-_LdLpFAUWb9k,1072
|
|
192
|
+
verifiers-0.4.2.dev110.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|