verifiers 0.3.1.dev67__py3-none-any.whl → 0.3.1.dev69__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/cli/eval/main.py +1 -1
- verifiers/v1/cli/eval/runner.py +0 -1
- verifiers/v1/cli/output.py +48 -14
- verifiers/v1/clients/train.py +5 -2
- verifiers/v1/dialects/__init__.py +0 -2
- verifiers/v1/dialects/anthropic.py +33 -42
- verifiers/v1/dialects/base.py +22 -39
- verifiers/v1/dialects/chat.py +76 -65
- verifiers/v1/dialects/responses.py +31 -59
- verifiers/v1/graph.py +6 -1
- verifiers/v1/tasksets/nemo_gym/response.py +12 -4
- verifiers/v1/types.py +2 -1
- {verifiers-0.3.1.dev67.dist-info → verifiers-0.3.1.dev69.dist-info}/METADATA +1 -1
- {verifiers-0.3.1.dev67.dist-info → verifiers-0.3.1.dev69.dist-info}/RECORD +17 -17
- {verifiers-0.3.1.dev67.dist-info → verifiers-0.3.1.dev69.dist-info}/WHEEL +0 -0
- {verifiers-0.3.1.dev67.dist-info → verifiers-0.3.1.dev69.dist-info}/entry_points.txt +0 -0
- {verifiers-0.3.1.dev67.dist-info → verifiers-0.3.1.dev69.dist-info}/licenses/LICENSE +0 -0
verifiers/v1/cli/eval/main.py
CHANGED
|
@@ -31,7 +31,7 @@ logger = logging.getLogger(__name__)
|
|
|
31
31
|
|
|
32
32
|
USAGE = (
|
|
33
33
|
"usage: uv run eval [<taskset-id>] [--env.id <id>] [options] [@ file.toml]\n"
|
|
34
|
-
" uv run eval @ <run-dir>/configs/eval.json --resume (re-run the run's missing/errored rollouts)"
|
|
34
|
+
" uv run eval @ <run-dir>/configs/resolved/eval.json --resume (re-run the run's missing/errored rollouts)"
|
|
35
35
|
)
|
|
36
36
|
|
|
37
37
|
|
verifiers/v1/cli/eval/runner.py
CHANGED
|
@@ -140,7 +140,6 @@ async def _server(
|
|
|
140
140
|
async def run_eval(config: EvalConfig) -> list[Episode]:
|
|
141
141
|
from verifiers.v1.utils.loaders import load_environment, load_taskset
|
|
142
142
|
|
|
143
|
-
logger.info("eval config:\n%s", config.model_dump_json(indent=2))
|
|
144
143
|
# The env comes up in this process only for an in-process run; a served run's
|
|
145
144
|
# workers each load their own, and this process owns just the taskset.
|
|
146
145
|
env = None if config.serve is not None else load_environment(config.env)
|
verifiers/v1/cli/output.py
CHANGED
|
@@ -28,9 +28,13 @@ TRACES_FILE = "traces.jsonl"
|
|
|
28
28
|
"""Filename a run's rollout episodes are written to (one JSON episode per line)."""
|
|
29
29
|
|
|
30
30
|
CONFIG_DIR = "configs"
|
|
31
|
-
"""Directory inside a run dir holding its
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
"""Directory inside a run dir holding its configs: the launch TOML copied verbatim to
|
|
32
|
+
`configs/<cli>.toml`, and the resolved config at `configs/resolved/<cli>.json`
|
|
33
|
+
(re-runnable via `@ <run-dir>/configs/resolved/<cli>.json`). Resolved configs are JSON,
|
|
34
|
+
not TOML: JSON keeps nulls, so explicit None settings round-trip exactly on re-parse."""
|
|
35
|
+
|
|
36
|
+
RESOLVED_DIR = "resolved"
|
|
37
|
+
"""Subdirectory of `configs/` holding the resolved per-component JSON dumps."""
|
|
34
38
|
|
|
35
39
|
|
|
36
40
|
def create_attempt_log_dir(run_dir: Path) -> Path:
|
|
@@ -68,13 +72,13 @@ def attempt_log_file(run_dir: Path) -> Path:
|
|
|
68
72
|
|
|
69
73
|
|
|
70
74
|
def saved_config_path(run_dir: Path) -> Path | None:
|
|
71
|
-
"""The run's saved resolved config (`configs/<cli>.json
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
return
|
|
75
|
+
"""The run's saved resolved config (`configs/resolved/<cli>.json`; legacy runs
|
|
76
|
+
kept it at `configs/<cli>.json`), None if absent."""
|
|
77
|
+
for config_dir in (run_dir / CONFIG_DIR / RESOLVED_DIR, run_dir / CONFIG_DIR):
|
|
78
|
+
candidates = sorted(config_dir.glob("*.json")) if config_dir.is_dir() else []
|
|
79
|
+
if candidates:
|
|
80
|
+
return candidates[0]
|
|
81
|
+
return None
|
|
78
82
|
|
|
79
83
|
|
|
80
84
|
# Compiling an adapter is the expensive part; run output reuses only a few model classes.
|
|
@@ -92,22 +96,52 @@ def output_path(config: EvalConfig) -> Path:
|
|
|
92
96
|
def write_config(
|
|
93
97
|
config: BaseModel, results_dir: Path, filename: str = "eval.json"
|
|
94
98
|
) -> Path:
|
|
95
|
-
"""Write the run's resolved config to `configs/<filename>` (re-readable via
|
|
99
|
+
"""Write the run's resolved config to `configs/resolved/<filename>` (re-readable via
|
|
96
100
|
`@ <path>`); return its path. The full model dump is written, nulls included, so the
|
|
97
101
|
file round-trips exactly."""
|
|
98
|
-
config_dir = results_dir / CONFIG_DIR
|
|
102
|
+
config_dir = results_dir / CONFIG_DIR / RESOLVED_DIR
|
|
99
103
|
config_dir.mkdir(parents=True, exist_ok=True)
|
|
100
104
|
config_path = config_dir / filename
|
|
101
105
|
config_path.write_text(json.dumps(config.model_dump(mode="json"), indent=2))
|
|
102
106
|
return config_path
|
|
103
107
|
|
|
104
108
|
|
|
109
|
+
def write_launch_toml(results_dir: Path, name: str = "eval") -> None:
|
|
110
|
+
"""Copy the launch `@` TOML file(s) verbatim to `configs/<name>.toml`."""
|
|
111
|
+
import sys
|
|
112
|
+
|
|
113
|
+
argv = sys.argv[1:]
|
|
114
|
+
paths = []
|
|
115
|
+
for i, arg in enumerate(argv):
|
|
116
|
+
# root config references only: `@ file`; a `--flag @ file` / `--flag @file`
|
|
117
|
+
# is a nested reference and belongs under its flag, not in the launch copy
|
|
118
|
+
if (
|
|
119
|
+
arg == "@"
|
|
120
|
+
and i + 1 < len(argv)
|
|
121
|
+
and (i == 0 or not argv[i - 1].startswith("--"))
|
|
122
|
+
):
|
|
123
|
+
paths.append(Path(argv[i + 1]))
|
|
124
|
+
tomls = [(p, p.read_text()) for p in paths if p.suffix == ".toml" and p.is_file()]
|
|
125
|
+
if not tomls:
|
|
126
|
+
return
|
|
127
|
+
texts = (
|
|
128
|
+
[text for _, text in tomls]
|
|
129
|
+
if len(tomls) == 1
|
|
130
|
+
else [f"# @ {p}\n{text}" for p, text in tomls]
|
|
131
|
+
)
|
|
132
|
+
config_dir = results_dir / CONFIG_DIR
|
|
133
|
+
config_dir.mkdir(parents=True, exist_ok=True)
|
|
134
|
+
(config_dir / f"{name}.toml").write_text("\n".join(texts))
|
|
135
|
+
|
|
136
|
+
|
|
105
137
|
def save_config(
|
|
106
138
|
config: BaseModel, results_dir: Path, filename: str = "eval.json"
|
|
107
139
|
) -> None:
|
|
108
|
-
"""Set up the run's output dir: write the resolved config
|
|
109
|
-
`traces.jsonl`. Call once up front, before episodes start
|
|
140
|
+
"""Set up the run's output dir: write the resolved config, copy the launch TOML,
|
|
141
|
+
and start a fresh (empty) `traces.jsonl`. Call once up front, before episodes start
|
|
142
|
+
landing."""
|
|
110
143
|
write_config(config, results_dir, filename)
|
|
144
|
+
write_launch_toml(results_dir, Path(filename).stem)
|
|
111
145
|
(results_dir / TRACES_FILE).write_text(
|
|
112
146
|
""
|
|
113
147
|
) # fresh; appended to as rollouts complete
|
verifiers/v1/clients/train.py
CHANGED
|
@@ -59,8 +59,11 @@ def serialize_completion(response: Response, model: str) -> dict:
|
|
|
59
59
|
message["tool_calls"] = [
|
|
60
60
|
{
|
|
61
61
|
"id": c.id,
|
|
62
|
-
"type":
|
|
63
|
-
|
|
62
|
+
"type": c.type,
|
|
63
|
+
c.type: {
|
|
64
|
+
"name": c.name,
|
|
65
|
+
"input" if c.type == "custom" else "arguments": c.arguments,
|
|
66
|
+
},
|
|
64
67
|
}
|
|
65
68
|
for c in response.message.tool_calls
|
|
66
69
|
]
|
|
@@ -5,7 +5,6 @@ from verifiers.v1.dialects.chat import (
|
|
|
5
5
|
ChatDialect,
|
|
6
6
|
parse_message,
|
|
7
7
|
parse_tools,
|
|
8
|
-
response_from_wire,
|
|
9
8
|
)
|
|
10
9
|
from verifiers.v1.dialects.responses import ResponsesDialect
|
|
11
10
|
|
|
@@ -23,5 +22,4 @@ __all__ = [
|
|
|
23
22
|
"StreamParser",
|
|
24
23
|
"parse_message",
|
|
25
24
|
"parse_tools",
|
|
26
|
-
"response_from_wire",
|
|
27
25
|
]
|
|
@@ -10,15 +10,14 @@ import json
|
|
|
10
10
|
import re
|
|
11
11
|
from collections.abc import Callable, Mapping
|
|
12
12
|
from dataclasses import dataclass, field
|
|
13
|
-
from typing import cast
|
|
14
13
|
|
|
15
14
|
from anthropic.types import Message as AnthropicMessage
|
|
16
|
-
from anthropic.types import MessageCreateParams
|
|
17
15
|
from anthropic.types import Usage as AnthropicUsage
|
|
18
16
|
|
|
19
17
|
from verifiers.v1.configs.runtime import NetworkPolicyConfig
|
|
20
18
|
from verifiers.v1.dialects.base import (
|
|
21
19
|
Dialect,
|
|
20
|
+
RawRequest,
|
|
22
21
|
StreamParser,
|
|
23
22
|
append_user_notice,
|
|
24
23
|
blocked_url,
|
|
@@ -46,7 +45,7 @@ from verifiers.v1.types import (
|
|
|
46
45
|
)
|
|
47
46
|
|
|
48
47
|
# Anthropic stop_reason -> vf finish_reason.
|
|
49
|
-
STOP_REASONS = {
|
|
48
|
+
STOP_REASONS: dict[str, FinishReason] = {
|
|
50
49
|
"end_turn": "stop",
|
|
51
50
|
"max_tokens": "length",
|
|
52
51
|
"tool_use": "tool_calls",
|
|
@@ -299,30 +298,29 @@ def parse_messages(body: dict) -> Messages:
|
|
|
299
298
|
def response_from_wire(message: AnthropicMessage) -> Response:
|
|
300
299
|
"""An Anthropic `Message` -> a vf `Response` (its content blocks folded into one assistant
|
|
301
300
|
message: text -> content, thinking -> reasoning, tool_use -> tool calls)."""
|
|
302
|
-
|
|
303
|
-
blocks = data.get("content") or []
|
|
304
|
-
state = [block for block in blocks if block["type"] in THINKING]
|
|
305
|
-
state.sort(key=lambda block: THINKING.index(block["type"]))
|
|
301
|
+
state: list[dict] = []
|
|
306
302
|
content: list[str] = []
|
|
307
303
|
reasoning: list[str] = []
|
|
308
304
|
calls: list[ToolCall] = []
|
|
309
|
-
for block in
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
305
|
+
for block in message.content:
|
|
306
|
+
if block.type in THINKING:
|
|
307
|
+
state.append(block.model_dump())
|
|
308
|
+
if block.type == "text":
|
|
309
|
+
content.append(block.text)
|
|
310
|
+
elif block.type == "thinking":
|
|
311
|
+
reasoning.append(block.thinking)
|
|
312
|
+
elif block.type == "tool_use":
|
|
316
313
|
calls.append(
|
|
317
314
|
ToolCall(
|
|
318
|
-
id=block.
|
|
319
|
-
name=block.
|
|
320
|
-
arguments=json.dumps(block.
|
|
315
|
+
id=block.id,
|
|
316
|
+
name=block.name,
|
|
317
|
+
arguments=json.dumps(block.input or {}),
|
|
321
318
|
)
|
|
322
319
|
)
|
|
323
|
-
|
|
320
|
+
state.sort(key=lambda block: THINKING.index(block["type"]))
|
|
321
|
+
finish = STOP_REASONS.get(message.stop_reason or "")
|
|
324
322
|
provider_usage = message.usage
|
|
325
|
-
output_details =
|
|
323
|
+
output_details = provider_usage.model_dump().get("output_tokens_details")
|
|
326
324
|
# Anthropic reports three disjoint input buckets. Cache writes are uncached work;
|
|
327
325
|
# cache reads are the reusable subset exposed separately by vf.Usage.
|
|
328
326
|
usage = Usage(
|
|
@@ -338,9 +336,9 @@ def response_from_wire(message: AnthropicMessage) -> Response:
|
|
|
338
336
|
cost=getattr(provider_usage, "cost", None),
|
|
339
337
|
)
|
|
340
338
|
return Response(
|
|
341
|
-
id=
|
|
339
|
+
id=message.id,
|
|
342
340
|
created=0,
|
|
343
|
-
model=
|
|
341
|
+
model=message.model,
|
|
344
342
|
message=AssistantMessage(
|
|
345
343
|
content="".join(content) or None,
|
|
346
344
|
reasoning_content="".join(reasoning) or None,
|
|
@@ -384,21 +382,14 @@ class AnthropicStreamParser(StreamParser):
|
|
|
384
382
|
"signature_delta",
|
|
385
383
|
):
|
|
386
384
|
field_name = delta_type.removesuffix("_delta")
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
self.block_parts[index] = fields
|
|
391
|
-
parts = fields.get(field_name)
|
|
392
|
-
if parts is None:
|
|
393
|
-
parts = [block.get(field_name, "")]
|
|
394
|
-
fields[field_name] = parts
|
|
385
|
+
parts = self.block_parts.setdefault(index, {}).setdefault(
|
|
386
|
+
field_name, [block.get(field_name, "")]
|
|
387
|
+
)
|
|
395
388
|
parts.append(delta.get(field_name, ""))
|
|
396
389
|
elif delta_type == "input_json_delta":
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
self.partial_json[index] = parts
|
|
401
|
-
parts.append(delta.get("partial_json", ""))
|
|
390
|
+
self.partial_json.setdefault(index, []).append(
|
|
391
|
+
delta.get("partial_json", "")
|
|
392
|
+
)
|
|
402
393
|
elif kind == "message_delta":
|
|
403
394
|
self.message.update(
|
|
404
395
|
{
|
|
@@ -436,7 +427,7 @@ class ModdedAnthropicMessage(AnthropicMessage):
|
|
|
436
427
|
usage: ModdedUsage # type: ignore[assignment]
|
|
437
428
|
|
|
438
429
|
|
|
439
|
-
class AnthropicDialect(Dialect[
|
|
430
|
+
class AnthropicDialect(Dialect[AnthropicMessage]):
|
|
440
431
|
sampling_fields = frozenset(
|
|
441
432
|
{
|
|
442
433
|
"temperature",
|
|
@@ -456,8 +447,8 @@ class AnthropicDialect(Dialect[MessageCreateParams, AnthropicMessage]):
|
|
|
456
447
|
response_type = ModdedAnthropicMessage
|
|
457
448
|
|
|
458
449
|
def mediate_external_capabilities(
|
|
459
|
-
self, body:
|
|
460
|
-
) -> tuple[
|
|
450
|
+
self, body: RawRequest, policy: NetworkPolicyConfig
|
|
451
|
+
) -> tuple[RawRequest, list[str]]:
|
|
461
452
|
mediated = body
|
|
462
453
|
capabilities: list[str] = []
|
|
463
454
|
|
|
@@ -570,7 +561,7 @@ class AnthropicDialect(Dialect[MessageCreateParams, AnthropicMessage]):
|
|
|
570
561
|
"error": {"type": "invalid_request_error", "message": message},
|
|
571
562
|
}
|
|
572
563
|
|
|
573
|
-
def parse_request(self, body:
|
|
564
|
+
def parse_request(self, body: RawRequest) -> Request:
|
|
574
565
|
tools = [
|
|
575
566
|
Tool(
|
|
576
567
|
name=t["name"],
|
|
@@ -681,7 +672,7 @@ class AnthropicDialect(Dialect[MessageCreateParams, AnthropicMessage]):
|
|
|
681
672
|
def stream_parser(self) -> StreamParser:
|
|
682
673
|
return AnthropicStreamParser(self.validate_response)
|
|
683
674
|
|
|
684
|
-
def parse_sampling(self, body:
|
|
675
|
+
def parse_sampling(self, body: RawRequest) -> Sampling:
|
|
685
676
|
settings = {k: v for k, v in body.items() if k in self.sampling_fields}
|
|
686
677
|
# Lift `output_config.effort` (where `apply_overrides` puts the eval's
|
|
687
678
|
# reasoning effort) onto the typed knob; keep any other output-config keys.
|
|
@@ -696,8 +687,8 @@ class AnthropicDialect(Dialect[MessageCreateParams, AnthropicMessage]):
|
|
|
696
687
|
return Sampling.model_validate(settings)
|
|
697
688
|
|
|
698
689
|
def apply_overrides(
|
|
699
|
-
self, body:
|
|
700
|
-
) ->
|
|
690
|
+
self, body: RawRequest, model: str, sampling: SamplingConfig
|
|
691
|
+
) -> RawRequest:
|
|
701
692
|
# Preserve native fields except the eval's model + sampling. `temperature`/`top_p` are
|
|
702
693
|
# authoritative (always dropped, the eval's applied if set); `max_tokens` is required by
|
|
703
694
|
# the API, so the program's is kept unless the eval sets one.
|
|
@@ -717,4 +708,4 @@ class AnthropicDialect(Dialect[MessageCreateParams, AnthropicMessage]):
|
|
|
717
708
|
for k, v in body.items()
|
|
718
709
|
if k not in ("temperature", "top_p") and k not in overrides
|
|
719
710
|
}
|
|
720
|
-
return
|
|
711
|
+
return {**steered, **overrides}
|
verifiers/v1/dialects/base.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"""The `Dialect` abstraction: one native wire format, translated to vf for the trace.
|
|
2
2
|
|
|
3
|
-
A `Dialect[
|
|
3
|
+
A `Dialect[RespT]` is the per-format translator the interception server uses to build the
|
|
4
4
|
trace from the program's native request + the provider's native response. The server serves
|
|
5
5
|
every registered dialect's `routes` (see `dialects.DIALECTS`), so a request's format is resolved
|
|
6
6
|
from the endpoint the program's SDK posts to — the harness declares nothing.
|
|
@@ -14,21 +14,20 @@ exception is `apply_overrides` (impose the eval's model + sampling in this forma
|
|
|
14
14
|
import json
|
|
15
15
|
import logging
|
|
16
16
|
from abc import ABC, abstractmethod
|
|
17
|
-
from collections.abc import Callable,
|
|
18
|
-
from typing import ClassVar, Generic, TypeVar
|
|
17
|
+
from collections.abc import Callable, Mapping
|
|
18
|
+
from typing import Any, ClassVar, Generic, TypeVar
|
|
19
19
|
from urllib.parse import urlsplit
|
|
20
20
|
|
|
21
|
-
from pydantic import AnyHttpUrl, BaseModel,
|
|
21
|
+
from pydantic import AnyHttpUrl, BaseModel, ValidationError
|
|
22
22
|
from pydantic_core import from_json
|
|
23
23
|
|
|
24
24
|
from verifiers.v1.configs.runtime import NetworkPolicyConfig
|
|
25
25
|
from verifiers.v1.types import Request, Response, Sampling, SamplingConfig
|
|
26
26
|
|
|
27
|
-
ReqT = TypeVar("ReqT")
|
|
28
27
|
RespT = TypeVar("RespT", bound=BaseModel)
|
|
28
|
+
RawRequest = dict[str, Any]
|
|
29
29
|
|
|
30
30
|
logger = logging.getLogger(__name__)
|
|
31
|
-
HTTP_URL_ADAPTER = TypeAdapter(AnyHttpUrl)
|
|
32
31
|
|
|
33
32
|
PROVIDER_CAPABILITY_POLICY_CODE = "provider_capability_unavailable"
|
|
34
33
|
CAPABILITY_NOTICE = (
|
|
@@ -43,7 +42,7 @@ def blocked_url(value: str, policy: NetworkPolicyConfig) -> bool:
|
|
|
43
42
|
if value.lower().startswith("data:"):
|
|
44
43
|
return False
|
|
45
44
|
try:
|
|
46
|
-
url =
|
|
45
|
+
url = AnyHttpUrl(value)
|
|
47
46
|
except ValidationError:
|
|
48
47
|
return True
|
|
49
48
|
host = url.host.lower().rstrip(".").strip("[]")
|
|
@@ -171,26 +170,6 @@ def parse_sse_event(raw: bytes) -> dict | None:
|
|
|
171
170
|
return json.loads(data.decode("utf-8", errors="replace"))
|
|
172
171
|
|
|
173
172
|
|
|
174
|
-
def iter_sse_reverse(raw: bytes) -> Iterator[dict]:
|
|
175
|
-
"""Yield JSON SSE payloads from the end without decoding earlier events."""
|
|
176
|
-
decoded = raw.decode("utf-8", errors="replace")
|
|
177
|
-
first_newline = decoded.find("\n")
|
|
178
|
-
separator = (
|
|
179
|
-
"\r\n\r\n"
|
|
180
|
-
if first_newline > 0 and decoded[first_newline - 1] == "\r"
|
|
181
|
-
else "\n\n"
|
|
182
|
-
)
|
|
183
|
-
for block in reversed(decoded.split(separator)):
|
|
184
|
-
data = "\n".join(
|
|
185
|
-
line.removeprefix("data:").strip()
|
|
186
|
-
for line in block.splitlines()
|
|
187
|
-
if line.startswith("data:")
|
|
188
|
-
)
|
|
189
|
-
if not data or data == "[DONE]":
|
|
190
|
-
continue
|
|
191
|
-
yield json.loads(data)
|
|
192
|
-
|
|
193
|
-
|
|
194
173
|
class StreamParser(ABC):
|
|
195
174
|
"""Incrementally assemble one native SSE stream into a vf response."""
|
|
196
175
|
|
|
@@ -205,11 +184,11 @@ class StreamParser(ABC):
|
|
|
205
184
|
"""Finalize and return the assembled response after the stream ends."""
|
|
206
185
|
|
|
207
186
|
|
|
208
|
-
class Dialect(ABC, Generic[
|
|
209
|
-
"""One native API's wire format,
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
187
|
+
class Dialect(ABC, Generic[RespT]):
|
|
188
|
+
"""One native API's wire format, typed over its validated response (`RespT`). Requests stay
|
|
189
|
+
as mutable native JSON because the gateway preserves provider extensions while mediating and
|
|
190
|
+
rewriting them. Implement a `Dialect` + register it in `dialects.DIALECTS` and a harness
|
|
191
|
+
speaking that format works end-to-end."""
|
|
213
192
|
|
|
214
193
|
sampling_fields: ClassVar[frozenset[str]] = frozenset()
|
|
215
194
|
"""Request keys that are call settings — what shapes generation given the same
|
|
@@ -243,7 +222,7 @@ class Dialect(ABC, Generic[ReqT, RespT]):
|
|
|
243
222
|
(default: an `Authorization: Bearer` token; Anthropic uses `x-api-key`)."""
|
|
244
223
|
return headers.get("Authorization", "").removeprefix("Bearer ")
|
|
245
224
|
|
|
246
|
-
def streaming(self, body:
|
|
225
|
+
def streaming(self, body: RawRequest) -> bool:
|
|
247
226
|
"""Whether the request asks for a streamed (SSE) response."""
|
|
248
227
|
return bool(body.get("stream"))
|
|
249
228
|
|
|
@@ -261,17 +240,17 @@ class Dialect(ABC, Generic[ReqT, RespT]):
|
|
|
261
240
|
|
|
262
241
|
@abstractmethod
|
|
263
242
|
def mediate_external_capabilities(
|
|
264
|
-
self, body:
|
|
265
|
-
) -> tuple[
|
|
243
|
+
self, body: RawRequest, policy: NetworkPolicyConfig
|
|
244
|
+
) -> tuple[RawRequest, list[str]]:
|
|
266
245
|
"""Remove provider-side capabilities during restricted execution. Implementations add
|
|
267
246
|
the same policy context on every call because the agent does not retain injected request
|
|
268
247
|
content. Returned paths never contain request values."""
|
|
269
248
|
|
|
270
249
|
@abstractmethod
|
|
271
|
-
def parse_request(self, body:
|
|
250
|
+
def parse_request(self, body: RawRequest) -> Request:
|
|
272
251
|
"""The native request -> the typed model request."""
|
|
273
252
|
|
|
274
|
-
def parse_sampling(self, body:
|
|
253
|
+
def parse_sampling(self, body: RawRequest) -> Sampling:
|
|
275
254
|
"""The native request's call settings -> the canonical `Sampling` (for the
|
|
276
255
|
trace's per-call records): the `sampling_fields` whitelist, with this format's
|
|
277
256
|
aliases mapped onto the typed knobs; dialect-specific keys ride as extras."""
|
|
@@ -288,7 +267,9 @@ class Dialect(ABC, Generic[ReqT, RespT]):
|
|
|
288
267
|
return self.response_type.model_validate(raw)
|
|
289
268
|
|
|
290
269
|
@abstractmethod
|
|
291
|
-
def rewrite_request(
|
|
270
|
+
def rewrite_request(
|
|
271
|
+
self, body: RawRequest, before: Request, after: Request
|
|
272
|
+
) -> None:
|
|
292
273
|
"""Patch rewritten user/tool messages into the native conversation."""
|
|
293
274
|
|
|
294
275
|
@abstractmethod
|
|
@@ -304,7 +285,9 @@ class Dialect(ABC, Generic[ReqT, RespT]):
|
|
|
304
285
|
"""Create the per-request incremental parser for a native SSE response."""
|
|
305
286
|
|
|
306
287
|
@abstractmethod
|
|
307
|
-
def apply_overrides(
|
|
288
|
+
def apply_overrides(
|
|
289
|
+
self, body: RawRequest, model: str, sampling: SamplingConfig
|
|
290
|
+
) -> RawRequest:
|
|
308
291
|
"""Return `body` with the eval's `model` + `sampling` imposed in this protocol's shape —
|
|
309
292
|
model overlays; sampling is authoritative (the program's sampling keys are dropped, the
|
|
310
293
|
eval's applied). Capability mediation may subsequently remove restricted fields."""
|
verifiers/v1/dialects/chat.py
CHANGED
|
@@ -11,15 +11,15 @@ import time
|
|
|
11
11
|
from collections.abc import Mapping
|
|
12
12
|
from dataclasses import dataclass
|
|
13
13
|
from dataclasses import field as dataclass_field
|
|
14
|
-
from typing import Any
|
|
14
|
+
from typing import Any
|
|
15
15
|
from urllib.parse import urlsplit
|
|
16
16
|
|
|
17
17
|
from openai.types.chat import ChatCompletion
|
|
18
|
-
from openai.types.chat.completion_create_params import CompletionCreateParams
|
|
19
18
|
|
|
20
19
|
from verifiers.v1.configs.runtime import NetworkPolicyConfig
|
|
21
20
|
from verifiers.v1.dialects.base import (
|
|
22
21
|
Dialect,
|
|
22
|
+
RawRequest,
|
|
23
23
|
StreamParser,
|
|
24
24
|
append_user_notice,
|
|
25
25
|
blocked_url,
|
|
@@ -84,12 +84,6 @@ def reasoning_text(data: Mapping[str, Any]) -> str | None:
|
|
|
84
84
|
return None
|
|
85
85
|
|
|
86
86
|
|
|
87
|
-
def _content_text(content) -> str:
|
|
88
|
-
if isinstance(content, list):
|
|
89
|
-
return "".join(p.get("text", "") for p in content if isinstance(p, dict))
|
|
90
|
-
return content or ""
|
|
91
|
-
|
|
92
|
-
|
|
93
87
|
def parse_message(raw: dict) -> Message:
|
|
94
88
|
"""An OpenAI chat request message dict -> a typed Message. User/system bodies keep their
|
|
95
89
|
image parts (multimodal ingress); assistant bodies flatten to text."""
|
|
@@ -105,18 +99,29 @@ def parse_message(raw: dict) -> Message:
|
|
|
105
99
|
)
|
|
106
100
|
if role == "assistant":
|
|
107
101
|
details = raw.get("reasoning_details")
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
102
|
+
text = (
|
|
103
|
+
"".join(part.get("text", "") for part in content if isinstance(part, dict))
|
|
104
|
+
if isinstance(content, list)
|
|
105
|
+
else content or ""
|
|
106
|
+
)
|
|
107
|
+
calls = []
|
|
108
|
+
for call in raw.get("tool_calls") or []:
|
|
109
|
+
kind = call.get("type") or (
|
|
110
|
+
"custom" if call.get("custom") is not None else "function"
|
|
111
|
+
)
|
|
112
|
+
native = call[kind]
|
|
113
|
+
calls.append(
|
|
114
|
+
ToolCall(
|
|
115
|
+
id=call["id"],
|
|
116
|
+
type=kind,
|
|
117
|
+
name=native["name"],
|
|
118
|
+
arguments=native["input" if kind == "custom" else "arguments"],
|
|
119
|
+
)
|
|
113
120
|
)
|
|
114
|
-
for c in (raw.get("tool_calls") or [])
|
|
115
|
-
] or None
|
|
116
121
|
return AssistantMessage(
|
|
117
|
-
content=
|
|
122
|
+
content=text or None,
|
|
118
123
|
reasoning_content=reasoning_text(raw),
|
|
119
|
-
tool_calls=calls,
|
|
124
|
+
tool_calls=calls or None,
|
|
120
125
|
provider_state=details if isinstance(details, list) and details else None,
|
|
121
126
|
)
|
|
122
127
|
return UserMessage(content=content_to_parts(content))
|
|
@@ -169,8 +174,13 @@ def message_to_wire(message: Message) -> dict:
|
|
|
169
174
|
wire["tool_calls"] = [
|
|
170
175
|
{
|
|
171
176
|
"id": call.id,
|
|
172
|
-
"type":
|
|
173
|
-
|
|
177
|
+
"type": call.type,
|
|
178
|
+
call.type: {
|
|
179
|
+
"name": call.name,
|
|
180
|
+
"input"
|
|
181
|
+
if call.type == "custom"
|
|
182
|
+
else "arguments": call.arguments,
|
|
183
|
+
},
|
|
174
184
|
}
|
|
175
185
|
for call in message.tool_calls
|
|
176
186
|
]
|
|
@@ -191,13 +201,8 @@ def response_from_wire(completion: ChatCompletion) -> Response:
|
|
|
191
201
|
"""An OpenAI chat.completion -> a vf `Response` (the one place raw provider objects cross
|
|
192
202
|
into our typed `Response`). No token ids: training tokens come from the renderer client."""
|
|
193
203
|
choice = completion.choices[0]
|
|
194
|
-
message = choice.message
|
|
195
|
-
|
|
196
|
-
details = data.get("reasoning_details")
|
|
197
|
-
tool_calls = [
|
|
198
|
-
ToolCall(id=tc.id, name=tc.function.name, arguments=tc.function.arguments)
|
|
199
|
-
for tc in (message.tool_calls or [])
|
|
200
|
-
] or None
|
|
204
|
+
message = parse_message(choice.message.model_dump())
|
|
205
|
+
assert isinstance(message, AssistantMessage)
|
|
201
206
|
finish: FinishReason = (
|
|
202
207
|
choice.finish_reason if choice.finish_reason in FINISH_REASONS else None
|
|
203
208
|
)
|
|
@@ -206,12 +211,7 @@ def response_from_wire(completion: ChatCompletion) -> Response:
|
|
|
206
211
|
id=completion.id,
|
|
207
212
|
created=completion.created,
|
|
208
213
|
model=completion.model,
|
|
209
|
-
message=
|
|
210
|
-
content=message.content,
|
|
211
|
-
reasoning_content=reasoning_text(data),
|
|
212
|
-
tool_calls=tool_calls,
|
|
213
|
-
provider_state=details if isinstance(details, list) and details else None,
|
|
214
|
-
),
|
|
214
|
+
message=message,
|
|
215
215
|
finish_reason=finish,
|
|
216
216
|
usage=usage,
|
|
217
217
|
)
|
|
@@ -224,11 +224,9 @@ class ChatStreamParser(StreamParser):
|
|
|
224
224
|
message: dict = dataclass_field(
|
|
225
225
|
default_factory=lambda: {"role": "assistant", "content": None}
|
|
226
226
|
)
|
|
227
|
-
message_parts: dict[str, list[str]] = dataclass_field(
|
|
228
|
-
default_factory=lambda: {key: [] for key in REASONING_FIELDS[:2] + ("content",)}
|
|
229
|
-
)
|
|
227
|
+
message_parts: dict[str, list[str]] = dataclass_field(default_factory=dict)
|
|
230
228
|
tool_calls: dict[int, dict] = dataclass_field(default_factory=dict)
|
|
231
|
-
|
|
229
|
+
tool_inputs: dict[int, list[str]] = dataclass_field(default_factory=dict)
|
|
232
230
|
reasoning_details: list[dict] = dataclass_field(default_factory=list)
|
|
233
231
|
reasoning_detail_parts: dict[int, tuple[str, list[str]]] = dataclass_field(
|
|
234
232
|
default_factory=dict
|
|
@@ -251,7 +249,7 @@ class ChatStreamParser(StreamParser):
|
|
|
251
249
|
delta = choice.get("delta") or {}
|
|
252
250
|
for key in ("content", "reasoning_content", "reasoning"):
|
|
253
251
|
if delta.get(key) is not None:
|
|
254
|
-
self.message_parts[
|
|
252
|
+
self.message_parts.setdefault(key, []).append(delta[key])
|
|
255
253
|
for detail in delta.get("reasoning_details") or []:
|
|
256
254
|
previous = self.reasoning_details[-1] if self.reasoning_details else {}
|
|
257
255
|
detail_type = detail.get("type")
|
|
@@ -281,16 +279,27 @@ class ChatStreamParser(StreamParser):
|
|
|
281
279
|
self.reasoning_details.append(detail)
|
|
282
280
|
for tool_call in delta.get("tool_calls") or []:
|
|
283
281
|
index = tool_call.get("index", 0)
|
|
284
|
-
slot = self.tool_calls.setdefault(
|
|
285
|
-
index,
|
|
286
|
-
{"type": "function", "function": {"name": "", "arguments": ""}},
|
|
287
|
-
)
|
|
282
|
+
slot = self.tool_calls.setdefault(index, {})
|
|
288
283
|
slot["id"] = tool_call.get("id") or slot.get("id", "")
|
|
289
|
-
|
|
290
|
-
if
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
284
|
+
kind = tool_call.get("type")
|
|
285
|
+
if kind is None:
|
|
286
|
+
kind = (
|
|
287
|
+
"custom"
|
|
288
|
+
if tool_call.get("custom") is not None
|
|
289
|
+
else "function"
|
|
290
|
+
if tool_call.get("function") is not None
|
|
291
|
+
else slot.get("type")
|
|
292
|
+
)
|
|
293
|
+
if kind is None:
|
|
294
|
+
continue
|
|
295
|
+
slot["type"] = kind
|
|
296
|
+
native = slot.setdefault(kind, {"name": ""})
|
|
297
|
+
delta_native = tool_call.get(kind) or {}
|
|
298
|
+
if delta_native.get("name"):
|
|
299
|
+
native["name"] = delta_native["name"]
|
|
300
|
+
input_field = "input" if kind == "custom" else "arguments"
|
|
301
|
+
self.tool_inputs.setdefault(index, []).append(
|
|
302
|
+
delta_native.get(input_field) or ""
|
|
294
303
|
)
|
|
295
304
|
|
|
296
305
|
def finish(self) -> Response:
|
|
@@ -299,12 +308,17 @@ class ChatStreamParser(StreamParser):
|
|
|
299
308
|
self.message[key] = "".join(parts)
|
|
300
309
|
for index, (content_field, parts) in self.reasoning_detail_parts.items():
|
|
301
310
|
self.reasoning_details[index][content_field] = "".join(parts)
|
|
302
|
-
for index, parts in self.
|
|
303
|
-
self.tool_calls[index]
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
]
|
|
311
|
+
for index, parts in self.tool_inputs.items():
|
|
312
|
+
call = self.tool_calls[index]
|
|
313
|
+
input_field = "input" if call["type"] == "custom" else "arguments"
|
|
314
|
+
call[call["type"]][input_field] = "".join(parts)
|
|
315
|
+
tool_calls = [
|
|
316
|
+
self.tool_calls[index]
|
|
317
|
+
for index in sorted(self.tool_calls)
|
|
318
|
+
if self.tool_calls[index].get("type") in _CLIENT_TOOL_TYPES
|
|
319
|
+
]
|
|
320
|
+
if tool_calls:
|
|
321
|
+
self.message["tool_calls"] = tool_calls
|
|
308
322
|
if self.reasoning_details:
|
|
309
323
|
self.message["reasoning_details"] = self.reasoning_details
|
|
310
324
|
head = self.head or {}
|
|
@@ -327,7 +341,7 @@ class ChatStreamParser(StreamParser):
|
|
|
327
341
|
return response
|
|
328
342
|
|
|
329
343
|
|
|
330
|
-
class ChatDialect(Dialect[
|
|
344
|
+
class ChatDialect(Dialect[ChatCompletion]):
|
|
331
345
|
sampling_fields = frozenset(
|
|
332
346
|
{
|
|
333
347
|
"temperature",
|
|
@@ -358,14 +372,14 @@ class ChatDialect(Dialect[CompletionCreateParams, ChatCompletion]):
|
|
|
358
372
|
response_type = ModdedChatCompletion
|
|
359
373
|
|
|
360
374
|
def mediate_external_capabilities(
|
|
361
|
-
self, body:
|
|
362
|
-
) -> tuple[
|
|
375
|
+
self, body: RawRequest, policy: NetworkPolicyConfig
|
|
376
|
+
) -> tuple[RawRequest, list[str]]:
|
|
363
377
|
mediated = body
|
|
364
378
|
capabilities: list[str] = []
|
|
365
379
|
|
|
366
380
|
if mediated.pop("web_search_options", None) is not None:
|
|
367
381
|
capabilities.append("web_search_options")
|
|
368
|
-
if
|
|
382
|
+
if mediated.pop("plugins", None) is not None:
|
|
369
383
|
capabilities.append("plugins")
|
|
370
384
|
|
|
371
385
|
audio = mediated.get("audio")
|
|
@@ -479,7 +493,7 @@ class ChatDialect(Dialect[CompletionCreateParams, ChatCompletion]):
|
|
|
479
493
|
append_user_notice(mediated.setdefault("messages", []))
|
|
480
494
|
return mediated, capabilities
|
|
481
495
|
|
|
482
|
-
def parse_request(self, body:
|
|
496
|
+
def parse_request(self, body: RawRequest) -> Request:
|
|
483
497
|
if body.get("n", 1) != 1:
|
|
484
498
|
raise ValueError("chat completions require n=1")
|
|
485
499
|
messages: Messages = []
|
|
@@ -496,7 +510,7 @@ class ChatDialect(Dialect[CompletionCreateParams, ChatCompletion]):
|
|
|
496
510
|
tool_names[call.id] = call.name
|
|
497
511
|
return Request(messages=messages, tools=parse_tools(body.get("tools")))
|
|
498
512
|
|
|
499
|
-
def parse_sampling(self, body:
|
|
513
|
+
def parse_sampling(self, body: RawRequest) -> Sampling:
|
|
500
514
|
settings = {k: v for k, v in body.items() if k in self.sampling_fields}
|
|
501
515
|
# Canonicalize the max-tokens alias; when both ride the wire (an eval override
|
|
502
516
|
# on top of a harness's `max_completion_tokens`), the override wins.
|
|
@@ -512,7 +526,7 @@ class ChatDialect(Dialect[CompletionCreateParams, ChatCompletion]):
|
|
|
512
526
|
body.get("messages", []), before.messages, after.messages, strict=True
|
|
513
527
|
):
|
|
514
528
|
if rewritten != original:
|
|
515
|
-
native["content"] =
|
|
529
|
+
native["content"] = _content_to_wire(rewritten.content)
|
|
516
530
|
if isinstance(rewritten, ToolMessage):
|
|
517
531
|
if rewritten.name is None:
|
|
518
532
|
native.pop("name", None)
|
|
@@ -546,8 +560,8 @@ class ChatDialect(Dialect[CompletionCreateParams, ChatCompletion]):
|
|
|
546
560
|
return ChatStreamParser()
|
|
547
561
|
|
|
548
562
|
def apply_overrides(
|
|
549
|
-
self, body:
|
|
550
|
-
) ->
|
|
563
|
+
self, body: RawRequest, model: str, sampling: SamplingConfig
|
|
564
|
+
) -> RawRequest:
|
|
551
565
|
# Preserve the program's native fields, overlaying only what the eval owns: the model and
|
|
552
566
|
# the sampling knobs it set. The selected model is authoritative even if a permissive
|
|
553
567
|
# sampling config carries an extra field named `model`.
|
|
@@ -559,7 +573,4 @@ class ChatDialect(Dialect[CompletionCreateParams, ChatCompletion]):
|
|
|
559
573
|
for k, v in body.items()
|
|
560
574
|
if not max_tokens_overridden or k not in max_token_keys
|
|
561
575
|
}
|
|
562
|
-
return
|
|
563
|
-
CompletionCreateParams,
|
|
564
|
-
{**steered, **overrides, "model": model},
|
|
565
|
-
)
|
|
576
|
+
return {**steered, **overrides, "model": model}
|
|
@@ -10,21 +10,22 @@ parsing reads the `output` items. Relay-only: the eval client forwards the progr
|
|
|
10
10
|
import json
|
|
11
11
|
import re
|
|
12
12
|
from collections import deque
|
|
13
|
-
from typing import cast
|
|
14
13
|
|
|
15
|
-
from openai.types.responses import (
|
|
14
|
+
from openai.types.responses.response_usage import (
|
|
15
|
+
InputTokensDetails,
|
|
16
|
+
OutputTokensDetails,
|
|
16
17
|
ResponseUsage,
|
|
17
18
|
)
|
|
18
|
-
from openai.types.responses.response_create_params import ResponseCreateParams
|
|
19
19
|
from pydantic import BaseModel, ConfigDict
|
|
20
20
|
|
|
21
21
|
from verifiers.v1.configs.runtime import NetworkPolicyConfig
|
|
22
22
|
from verifiers.v1.dialects.base import (
|
|
23
23
|
Dialect,
|
|
24
|
+
RawRequest,
|
|
24
25
|
StreamParser,
|
|
25
26
|
append_user_notice,
|
|
26
27
|
blocked_url,
|
|
27
|
-
|
|
28
|
+
parse_sse_event,
|
|
28
29
|
provider_allowed_domains,
|
|
29
30
|
)
|
|
30
31
|
from verifiers.v1.errors import OverlongPromptError, model_error
|
|
@@ -97,19 +98,17 @@ BLANK_PNG = (
|
|
|
97
98
|
)
|
|
98
99
|
|
|
99
100
|
|
|
100
|
-
class ProviderUsageInputTokensDetails(
|
|
101
|
+
class ProviderUsageInputTokensDetails(InputTokensDetails):
|
|
101
102
|
"""Permissive input token details: OpenAI-compatible providers may omit fields
|
|
102
103
|
the pinned SDK declares required (e.g. ``cache_write_tokens``)."""
|
|
103
104
|
|
|
104
|
-
model_config = ConfigDict(extra="allow")
|
|
105
105
|
cache_write_tokens: int | None = None
|
|
106
106
|
cached_tokens: int | None = None
|
|
107
107
|
|
|
108
108
|
|
|
109
|
-
class ProviderUsageOutputTokensDetails(
|
|
109
|
+
class ProviderUsageOutputTokensDetails(OutputTokensDetails):
|
|
110
110
|
"""Permissive output token details: providers may omit ``reasoning_tokens``."""
|
|
111
111
|
|
|
112
|
-
model_config = ConfigDict(extra="allow")
|
|
113
112
|
reasoning_tokens: int | None = None
|
|
114
113
|
|
|
115
114
|
|
|
@@ -275,24 +274,26 @@ def mediate_content(value, path: str, policy: NetworkPolicyConfig):
|
|
|
275
274
|
return mediated, capabilities
|
|
276
275
|
|
|
277
276
|
|
|
278
|
-
def fold_assistant(items: list[dict]) -> AssistantMessage:
|
|
279
|
-
"""
|
|
277
|
+
def fold_assistant(items: list[dict] | None) -> AssistantMessage:
|
|
278
|
+
"""Assistant-side Responses items -> one typed assistant message."""
|
|
280
279
|
content = ""
|
|
281
280
|
reasoning: list[str] = []
|
|
282
281
|
calls: list[ToolCall] = []
|
|
283
|
-
for item in items:
|
|
284
|
-
|
|
282
|
+
for item in items or []:
|
|
283
|
+
kind = item.get("type")
|
|
284
|
+
if kind == "reasoning":
|
|
285
285
|
reasoning += [s.get("text", "") for s in item.get("summary") or []]
|
|
286
286
|
reasoning += [c.get("text", "") for c in item.get("content") or []]
|
|
287
|
-
elif
|
|
287
|
+
elif kind in ("function_call", "custom_tool_call"):
|
|
288
288
|
calls.append(
|
|
289
289
|
ToolCall(
|
|
290
290
|
id=item.get("call_id", ""),
|
|
291
|
+
type="custom" if kind == "custom_tool_call" else "function",
|
|
291
292
|
name=item.get("name", ""),
|
|
292
293
|
arguments=item.get("arguments", item.get("input", "")),
|
|
293
294
|
)
|
|
294
295
|
)
|
|
295
|
-
else:
|
|
296
|
+
else:
|
|
296
297
|
raw = item.get("content")
|
|
297
298
|
content += (
|
|
298
299
|
raw
|
|
@@ -336,33 +337,11 @@ def response_from_wire(response: OpenAIResponse) -> Response:
|
|
|
336
337
|
f"upstream Responses request did not complete: {detail}",
|
|
337
338
|
status_code=status_code,
|
|
338
339
|
)
|
|
339
|
-
|
|
340
|
-
reasoning: list[str] = []
|
|
341
|
-
calls: list[ToolCall] = []
|
|
342
|
-
for item in data.get("output") or []:
|
|
343
|
-
kind = item.get("type")
|
|
344
|
-
if kind == "message":
|
|
345
|
-
content += "".join(
|
|
346
|
-
p.get("text", "")
|
|
347
|
-
for p in item.get("content") or []
|
|
348
|
-
if p.get("type") == "output_text"
|
|
349
|
-
)
|
|
350
|
-
elif kind == "reasoning":
|
|
351
|
-
reasoning += [s.get("text", "") for s in item.get("summary") or []]
|
|
352
|
-
reasoning += [c.get("text", "") for c in item.get("content") or []]
|
|
353
|
-
elif kind in ("function_call", "custom_tool_call"):
|
|
354
|
-
calls.append(
|
|
355
|
-
ToolCall(
|
|
356
|
-
id=item.get("call_id", ""),
|
|
357
|
-
name=item.get("name", ""),
|
|
358
|
-
arguments=item.get("arguments", item.get("input", "")),
|
|
359
|
-
)
|
|
360
|
-
)
|
|
361
|
-
tool_calls = calls or None
|
|
340
|
+
message = fold_assistant(data.get("output"))
|
|
362
341
|
finish: FinishReason = (
|
|
363
342
|
"length"
|
|
364
343
|
if data.get("status") == "incomplete"
|
|
365
|
-
else ("tool_calls" if tool_calls else "stop")
|
|
344
|
+
else ("tool_calls" if message.tool_calls else "stop")
|
|
366
345
|
)
|
|
367
346
|
usage = None
|
|
368
347
|
if response.usage:
|
|
@@ -384,12 +363,7 @@ def response_from_wire(response: OpenAIResponse) -> Response:
|
|
|
384
363
|
id=data.get("id", ""),
|
|
385
364
|
created=data.get("created_at", 0),
|
|
386
365
|
model=data.get("model", ""),
|
|
387
|
-
message=
|
|
388
|
-
content=content or None,
|
|
389
|
-
reasoning_content="\n".join(r for r in reasoning if r) or None,
|
|
390
|
-
tool_calls=tool_calls,
|
|
391
|
-
provider_state=data.get("output"),
|
|
392
|
-
),
|
|
366
|
+
message=message,
|
|
393
367
|
finish_reason=finish,
|
|
394
368
|
usage=usage,
|
|
395
369
|
)
|
|
@@ -409,8 +383,9 @@ class ResponsesStreamParser(StreamParser):
|
|
|
409
383
|
|
|
410
384
|
def finish(self) -> Response:
|
|
411
385
|
events = self.terminal_events or self.events
|
|
412
|
-
for
|
|
413
|
-
|
|
386
|
+
for raw in reversed(events):
|
|
387
|
+
event = parse_sse_event(raw)
|
|
388
|
+
if event and event.get("type") in FINAL_EVENTS:
|
|
414
389
|
response = response_from_wire(
|
|
415
390
|
OpenAIResponse.model_validate(event["response"])
|
|
416
391
|
)
|
|
@@ -419,7 +394,7 @@ class ResponsesStreamParser(StreamParser):
|
|
|
419
394
|
raise ValueError("Responses stream ended without a terminal event")
|
|
420
395
|
|
|
421
396
|
|
|
422
|
-
class ResponsesDialect(Dialect[
|
|
397
|
+
class ResponsesDialect(Dialect[OpenAIResponse]):
|
|
423
398
|
sampling_fields = frozenset(
|
|
424
399
|
{
|
|
425
400
|
"temperature",
|
|
@@ -440,8 +415,8 @@ class ResponsesDialect(Dialect[ResponseCreateParams, OpenAIResponse]):
|
|
|
440
415
|
response_type = OpenAIResponse
|
|
441
416
|
|
|
442
417
|
def mediate_external_capabilities(
|
|
443
|
-
self, body:
|
|
444
|
-
) -> tuple[
|
|
418
|
+
self, body: RawRequest, policy: NetworkPolicyConfig
|
|
419
|
+
) -> tuple[RawRequest, list[str]]:
|
|
445
420
|
mediated = body
|
|
446
421
|
capabilities: list[str] = []
|
|
447
422
|
|
|
@@ -451,7 +426,7 @@ class ResponsesDialect(Dialect[ResponseCreateParams, OpenAIResponse]):
|
|
|
451
426
|
|
|
452
427
|
if mediated.pop("prompt", None) is not None:
|
|
453
428
|
capabilities.append("prompt")
|
|
454
|
-
if
|
|
429
|
+
if mediated.pop("plugins", None) is not None:
|
|
455
430
|
capabilities.append("plugins")
|
|
456
431
|
|
|
457
432
|
raw_input = mediated.get("input")
|
|
@@ -559,7 +534,7 @@ class ResponsesDialect(Dialect[ResponseCreateParams, OpenAIResponse]):
|
|
|
559
534
|
# trailing `[DONE]`, so the turn-ending event is the final event, not the sentinel.
|
|
560
535
|
return any(marker in chunk for marker in _TERMINAL_MARKERS)
|
|
561
536
|
|
|
562
|
-
def parse_sampling(self, body:
|
|
537
|
+
def parse_sampling(self, body: RawRequest) -> Sampling:
|
|
563
538
|
settings = {k: v for k, v in body.items() if k in self.sampling_fields}
|
|
564
539
|
# Lift `reasoning.effort` onto the typed knob; keep any other reasoning keys
|
|
565
540
|
# (e.g. `summary`) as the wire sent them.
|
|
@@ -575,7 +550,7 @@ class ResponsesDialect(Dialect[ResponseCreateParams, OpenAIResponse]):
|
|
|
575
550
|
settings["max_tokens"] = settings.pop("max_output_tokens")
|
|
576
551
|
return Sampling.model_validate(settings)
|
|
577
552
|
|
|
578
|
-
def parse_request(self, body:
|
|
553
|
+
def parse_request(self, body: RawRequest) -> Request:
|
|
579
554
|
prompt: Messages = []
|
|
580
555
|
if instructions := body.get("instructions"):
|
|
581
556
|
prompt.append(SystemMessage(content=instructions))
|
|
@@ -596,10 +571,7 @@ class ResponsesDialect(Dialect[ResponseCreateParams, OpenAIResponse]):
|
|
|
596
571
|
run = []
|
|
597
572
|
if assistant:
|
|
598
573
|
run.append(item)
|
|
599
|
-
elif item.get("type") in
|
|
600
|
-
"function_call_output",
|
|
601
|
-
"custom_tool_call_output",
|
|
602
|
-
):
|
|
574
|
+
elif item.get("type") in TEXT_TOOL_OUTPUT_TYPES:
|
|
603
575
|
output = item.get("output")
|
|
604
576
|
content = (
|
|
605
577
|
parse_content(output)
|
|
@@ -753,8 +725,8 @@ class ResponsesDialect(Dialect[ResponseCreateParams, OpenAIResponse]):
|
|
|
753
725
|
return ResponsesStreamParser()
|
|
754
726
|
|
|
755
727
|
def apply_overrides(
|
|
756
|
-
self, body:
|
|
757
|
-
) ->
|
|
728
|
+
self, body: RawRequest, model: str, sampling: SamplingConfig
|
|
729
|
+
) -> RawRequest:
|
|
758
730
|
# Preserve native fields except the eval's model + sampling, mapped to the Responses shape
|
|
759
731
|
# (`max_tokens` -> `max_output_tokens`); sampling is authoritative.
|
|
760
732
|
s = sampling.wire_args()
|
|
@@ -790,4 +762,4 @@ class ResponsesDialect(Dialect[ResponseCreateParams, OpenAIResponse]):
|
|
|
790
762
|
for k, v in body.items()
|
|
791
763
|
if k not in _SAMPLING_KEYS and k not in overrides
|
|
792
764
|
}
|
|
793
|
-
return
|
|
765
|
+
return {**steered, **overrides}
|
verifiers/v1/graph.py
CHANGED
|
@@ -288,9 +288,14 @@ def message_hash(message: Message) -> str:
|
|
|
288
288
|
add(json.dumps(state, sort_keys=True))
|
|
289
289
|
for tc in message.tool_calls or []:
|
|
290
290
|
add("tool_call")
|
|
291
|
+
add(tc.type)
|
|
291
292
|
add(tc.id)
|
|
292
293
|
add(tc.name)
|
|
293
|
-
add(
|
|
294
|
+
add(
|
|
295
|
+
tc.arguments
|
|
296
|
+
if tc.type == "custom"
|
|
297
|
+
else _canonical_tool_arguments(tc.arguments)
|
|
298
|
+
)
|
|
294
299
|
elif isinstance(message, ToolMessage):
|
|
295
300
|
add("tool_call_id")
|
|
296
301
|
add(message.tool_call_id)
|
|
@@ -22,14 +22,17 @@ def trace_to_nemo_response(
|
|
|
22
22
|
)
|
|
23
23
|
|
|
24
24
|
output: list[dict[str, Any]] = []
|
|
25
|
+
call_types: dict[str, str] = {}
|
|
25
26
|
started = False
|
|
26
27
|
|
|
27
28
|
for node in branches[0].nodes:
|
|
28
29
|
message = node.message
|
|
29
30
|
if isinstance(message, AssistantMessage) and node.sampled:
|
|
30
31
|
started = True
|
|
32
|
+
call_types.update((call.id, call.type) for call in message.tool_calls or [])
|
|
31
33
|
if message.provider_state and all(
|
|
32
|
-
item.get("type")
|
|
34
|
+
item.get("type")
|
|
35
|
+
in {"reasoning", "message", "function_call", "custom_tool_call"}
|
|
33
36
|
for item in message.provider_state
|
|
34
37
|
):
|
|
35
38
|
output.extend(message.provider_state)
|
|
@@ -62,9 +65,12 @@ def trace_to_nemo_response(
|
|
|
62
65
|
)
|
|
63
66
|
output.extend(
|
|
64
67
|
{
|
|
65
|
-
"type": "
|
|
68
|
+
"type": "custom_tool_call"
|
|
69
|
+
if call.type == "custom"
|
|
70
|
+
else "function_call",
|
|
66
71
|
"call_id": call.id,
|
|
67
|
-
|
|
72
|
+
"name": call.name,
|
|
73
|
+
("input" if call.type == "custom" else "arguments"): call.arguments,
|
|
68
74
|
}
|
|
69
75
|
for call in message.tool_calls or []
|
|
70
76
|
)
|
|
@@ -78,7 +84,9 @@ def trace_to_nemo_response(
|
|
|
78
84
|
)
|
|
79
85
|
output.append(
|
|
80
86
|
{
|
|
81
|
-
"type": "
|
|
87
|
+
"type": "custom_tool_call_output"
|
|
88
|
+
if call_types.get(message.tool_call_id) == "custom"
|
|
89
|
+
else "function_call_output",
|
|
82
90
|
"call_id": message.tool_call_id,
|
|
83
91
|
"output": content,
|
|
84
92
|
}
|
verifiers/v1/types.py
CHANGED
|
@@ -65,9 +65,10 @@ class UserMessage(BaseModel):
|
|
|
65
65
|
|
|
66
66
|
class ToolCall(BaseModel):
|
|
67
67
|
id: str
|
|
68
|
+
type: Literal["function", "custom"] = "function"
|
|
68
69
|
name: str
|
|
69
70
|
arguments: str
|
|
70
|
-
"""Raw
|
|
71
|
+
"""Raw function arguments or custom-tool input, exactly as the model emitted it."""
|
|
71
72
|
|
|
72
73
|
|
|
73
74
|
class AssistantMessage(BaseModel):
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: verifiers
|
|
3
|
-
Version: 0.3.1.
|
|
3
|
+
Version: 0.3.1.dev69
|
|
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
|
|
@@ -173,7 +173,7 @@ verifiers/v1/agent.py,sha256=cMRVKzg9Vs6DCLJ5vXj8xc3-PJ2S6fhoJctS7zHinKM,31393
|
|
|
173
173
|
verifiers/v1/env.py,sha256=CEhzjojhg5jqbOYruUnc5U7TtgDHDSx8NiiFA0qfbt8,18234
|
|
174
174
|
verifiers/v1/episode.py,sha256=uStvI4WqgJT50hmHIB55m5B-ASqqLz-fZ-ynBz9uzEY,5474
|
|
175
175
|
verifiers/v1/errors.py,sha256=kQeEPX06TwAIuiz7MlWFYirrpKbx5STi6A5b_dtQQoA,6885
|
|
176
|
-
verifiers/v1/graph.py,sha256=
|
|
176
|
+
verifiers/v1/graph.py,sha256=vjxIrE0e-IXeb8fIY0pRGfwrQlGsIAe9IjwHNZXqizk,30652
|
|
177
177
|
verifiers/v1/harness.py,sha256=ziECqEBWV34UWbLlxrkhY6MwkbVYkoXBOoaY7mZxwTs,14753
|
|
178
178
|
verifiers/v1/judge.py,sha256=Pvr0C41ah1qkNSZ0WXdkDvBMfv5YSfY1REHncwlJ8cg,9346
|
|
179
179
|
verifiers/v1/rollout.py,sha256=vpjvlxufnV-ko1X2JZrNW-7CL8OQWI3h3Z3BtOrKv6M,23796
|
|
@@ -182,14 +182,14 @@ verifiers/v1/state.py,sha256=EckF2bWp-vV4b1jYJ9sLI5xrfGuI5spIgYYwW926toI,595
|
|
|
182
182
|
verifiers/v1/task.py,sha256=ZiAE5uGxgHWqz8UF5YJHs80RgSKhxGMGQo4lJusSRus,11375
|
|
183
183
|
verifiers/v1/taskset.py,sha256=fp2E0IEhL_Ybj9cegZwljfTmW27p_30zTWHFKw_kXE4,4374
|
|
184
184
|
verifiers/v1/trace.py,sha256=GbuQVcPUFdBYSXqeO36UT6xKBQCtY656Tg8Icgut_xk,24908
|
|
185
|
-
verifiers/v1/types.py,sha256=
|
|
185
|
+
verifiers/v1/types.py,sha256=a1wqL8T7KQg9WxkaDIZpmOyU6xT2VeSr1K4SWiW8ef4,9660
|
|
186
186
|
verifiers/v1/acp/__init__.py,sha256=-QQh5ZT0o9j98CzqltsheccmM3Xqqyneu-vN1U0NJ38,10232
|
|
187
187
|
verifiers/v1/acp/runner.py,sha256=aP7yyXMDp1nkU-L20BSqcwqRo9YEhNnpM8u_dWfFpCw,9528
|
|
188
188
|
verifiers/v1/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
189
189
|
verifiers/v1/cli/debug.py,sha256=x3bqOwwbwwfwQQpxHrZeKdxsW3ZVtUT9cAn_r4aOro4,11631
|
|
190
190
|
verifiers/v1/cli/gepa.py,sha256=7YpppEMeuY2m1X5szGkybzTHztnIs83CvnSizhiEC-w,4210
|
|
191
191
|
verifiers/v1/cli/init.py,sha256=LFF_1e2XTdgIKjWoqq_IAlOzAXcARPEroblcEGv0fCU,7599
|
|
192
|
-
verifiers/v1/cli/output.py,sha256=
|
|
192
|
+
verifiers/v1/cli/output.py,sha256=HZbkHw662ppVdpTGutrKuQOSeBvtsAj5qjUokCkwkv0,8457
|
|
193
193
|
verifiers/v1/cli/replay.py,sha256=JhhI_O8PLhtHbgLie5dG03RrTynvZtsEPX-MLY3KQy4,10240
|
|
194
194
|
verifiers/v1/cli/resolve.py,sha256=Q1EHM7wWQo0YkwJA898qtZbYLaIkjIVq3Q7kUp2YIxs,4346
|
|
195
195
|
verifiers/v1/cli/resume.py,sha256=hqV5AxxqeIInJeEZQerQznuijhMNijFEFcHZIltfLdE,470
|
|
@@ -200,14 +200,14 @@ verifiers/v1/cli/dashboard/eval.py,sha256=IgyEVBfTcyuKw_rXaHrRRFX4ESlwsekaPi-bxD
|
|
|
200
200
|
verifiers/v1/cli/dashboard/replay.py,sha256=_X5up9MJsRbd_sWe4LgNTPNT8k1ip4xNpo50hxI3Ljk,2697
|
|
201
201
|
verifiers/v1/cli/dashboard/validate.py,sha256=rLsQ_31DjTIZpC_VO7zSG41ncUEBxqCx8mL9nTnGiMc,3650
|
|
202
202
|
verifiers/v1/cli/eval/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
203
|
-
verifiers/v1/cli/eval/main.py,sha256=
|
|
203
|
+
verifiers/v1/cli/eval/main.py,sha256=D5-lth_F04iAZYTHglzPufdh-P9lBivD7-GgfFvWmz8,6321
|
|
204
204
|
verifiers/v1/cli/eval/resume.py,sha256=fYkWa0Fudq--IWfk25j_McLm67bXYWvksWmJR4u4QAU,3811
|
|
205
|
-
verifiers/v1/cli/eval/runner.py,sha256=
|
|
205
|
+
verifiers/v1/cli/eval/runner.py,sha256=tZDPWzd6U7-5N43HGRlV7p-RnUiDleYwMUBVHzWH7mk,10015
|
|
206
206
|
verifiers/v1/clients/__init__.py,sha256=Ysig0tE_0E4Jsfgfes1XHN-fK1s_RCXdqZD6E7lK4PU,507
|
|
207
207
|
verifiers/v1/clients/base.py,sha256=PoDw4GMqrfuPTFVK6n2jDmlD0_lJ5zTrYcNio5yq6K8,1691
|
|
208
208
|
verifiers/v1/clients/client.py,sha256=zqC_AkiD9pl0kxxIbupNiehbS-YnVdp3EMZ0LOHTd8U,3125
|
|
209
209
|
verifiers/v1/clients/eval.py,sha256=-OcYUqlj8dBRjyuffMvymc1fMfZcjo-p5q8ZSMvDGzY,8106
|
|
210
|
-
verifiers/v1/clients/train.py,sha256=
|
|
210
|
+
verifiers/v1/clients/train.py,sha256=OqxDP2PhSINc_8CUrZRJtUfsTqXKqTBBUl029YGeBDk,18597
|
|
211
211
|
verifiers/v1/configs/__init__.py,sha256=X7u6X7B3ieD1HZl79Tv1kg-yPHbT0QLvAebaGqxVtvA,317
|
|
212
212
|
verifiers/v1/configs/agent.py,sha256=L5P6ombAi4U5wwsspMHAuM8111sB9AVdm8q6B5iV1lw,3251
|
|
213
213
|
verifiers/v1/configs/client.py,sha256=E7ZxeWBFV_AP8MyfxXncTZs-Yn-QKdDS57HCAzqVTrQ,4437
|
|
@@ -226,11 +226,11 @@ verifiers/v1/configs/cli/eval.py,sha256=AkT-wY_pm4WJ8zNABvfC3GoYOjrNCkyVXtUGquBD
|
|
|
226
226
|
verifiers/v1/configs/cli/init.py,sha256=JvIUOdhfZfNOXg2wm2i06jLLHpb97tNMzZqmcK_9wVw,916
|
|
227
227
|
verifiers/v1/configs/cli/replay.py,sha256=vUCNs-9j1CXcAZhGozN1EaztcXK_dYVK3iN_fRmbSXw,2929
|
|
228
228
|
verifiers/v1/configs/cli/validate.py,sha256=NXQ9KvhGLODLrg1fs3Jn-SOq1hhPxauVWiPSEp6wje0,3691
|
|
229
|
-
verifiers/v1/dialects/__init__.py,sha256=
|
|
230
|
-
verifiers/v1/dialects/anthropic.py,sha256=
|
|
231
|
-
verifiers/v1/dialects/base.py,sha256=
|
|
232
|
-
verifiers/v1/dialects/chat.py,sha256=
|
|
233
|
-
verifiers/v1/dialects/responses.py,sha256=
|
|
229
|
+
verifiers/v1/dialects/__init__.py,sha256=MNOYM2NdTlSxGK4VtoEjMtD5zya2MpjPDX5jMvZUWEo,736
|
|
230
|
+
verifiers/v1/dialects/anthropic.py,sha256=abwcKRsKkgfgLSuntxBMdL03enG7roRdGoHTYfswafM,26887
|
|
231
|
+
verifiers/v1/dialects/base.py,sha256=pcFqWXSl50VtMuzcY5cyhsc4WpKCM5wT-tskTFZV7CM,12203
|
|
232
|
+
verifiers/v1/dialects/chat.py,sha256=_pMsNpbffiXiK0_0tboAKtuj7-smUnkS9H0LPK4j1mU,23662
|
|
233
|
+
verifiers/v1/dialects/responses.py,sha256=PYHWuJSz84i5teHWn0uGany1--P04kw3ryKfFGJ4y84,29254
|
|
234
234
|
verifiers/v1/envs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
235
235
|
verifiers/v1/envs/agentic_judge/__init__.py,sha256=LfEcRHLG_siKzhzWmODDXWSLpLgfum3UFdQDK9XG0gk,325
|
|
236
236
|
verifiers/v1/envs/agentic_judge/env.py,sha256=yVMdq0zBOX7vkEkhnhHTUDM-KKcoOIHUt7yEggOs4ng,14615
|
|
@@ -321,7 +321,7 @@ verifiers/v1/tasksets/lean/__init__.py,sha256=oyv-GbJQBvCyGwo7Ysxm2NjZW-aX4j1uDo
|
|
|
321
321
|
verifiers/v1/tasksets/lean/scoring.py,sha256=sfzsT6MUK0zdMgAQ57_P_0CBaPHy3M7go71QMr5hDrs,10599
|
|
322
322
|
verifiers/v1/tasksets/lean/taskset.py,sha256=XgUqX0uJvHC8sKFhbK92iu6nUGcPuXCUpI3ZBhDcb7c,9025
|
|
323
323
|
verifiers/v1/tasksets/nemo_gym/__init__.py,sha256=654gAvG3Wd_Z_nh6mypeKn4s_IIQ0Ge6vcZvxTHC2_E,306
|
|
324
|
-
verifiers/v1/tasksets/nemo_gym/response.py,sha256=
|
|
324
|
+
verifiers/v1/tasksets/nemo_gym/response.py,sha256=u_-qvmcyVHRC9fLJx5ED7BjCCUv5JttuTxM_GzZObkM,4382
|
|
325
325
|
verifiers/v1/tasksets/nemo_gym/server.py,sha256=BTe9dk3uOR7H862ZvIIfCQ6ET17oA2SWkI2Ya-zl8sQ,1459
|
|
326
326
|
verifiers/v1/tasksets/nemo_gym/taskset.py,sha256=INE5-LlVADM1bdiZvPQc8fXr8AGAqqN7cIQw-uwA6EI,6582
|
|
327
327
|
verifiers/v1/tasksets/nemo_gym/toolset.py,sha256=x92XnuPRihMkEnKr9XO3QADqFfEmuxQFxaV6c7LOBks,3996
|
|
@@ -348,8 +348,8 @@ verifiers/v1/utils/prime.py,sha256=UTYRjp9cbjNb6CVmBHda-1wWZAIIfxNOmTyNuT7_wL4,9
|
|
|
348
348
|
verifiers/v1/utils/retries.py,sha256=Y2ZgrAjn-qNkRKZP_RVNL_7EK0iaRcZeCa404lpGYi4,5417
|
|
349
349
|
verifiers/v1/utils/score.py,sha256=-R5Cog14r_tJ6Q_oOfGr5VPAm2CCUhofYZB6B9lm4wM,5787
|
|
350
350
|
verifiers/v1/utils/version.py,sha256=-obEo_-l9-D8FLef4hYxncOe-uJpxrM1g2Hig_37Sgs,1607
|
|
351
|
-
verifiers-0.3.1.
|
|
352
|
-
verifiers-0.3.1.
|
|
353
|
-
verifiers-0.3.1.
|
|
354
|
-
verifiers-0.3.1.
|
|
355
|
-
verifiers-0.3.1.
|
|
351
|
+
verifiers-0.3.1.dev69.dist-info/METADATA,sha256=zJvPx_lxk4Q1clezb1LPpd3beE3omEKaBzvjjd2RcCI,4654
|
|
352
|
+
verifiers-0.3.1.dev69.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
|
|
353
|
+
verifiers-0.3.1.dev69.dist-info/entry_points.txt,sha256=hZ5wDc1T8y-EvOziw7kQqatBJ6PbdSu2ygP5rjANl7c,564
|
|
354
|
+
verifiers-0.3.1.dev69.dist-info/licenses/LICENSE,sha256=v0RrUsdV3IDoZhrRce297IXS3xMHNJ-_LdLpFAUWb9k,1072
|
|
355
|
+
verifiers-0.3.1.dev69.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|