verifiers 0.4.2.dev47__py3-none-any.whl → 0.4.2.dev48__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.
@@ -214,6 +214,13 @@ def append_user_notice(
214
214
  messages.append(message)
215
215
 
216
216
 
217
+ def _error_type(status_code: int) -> str:
218
+ """The OpenAI error `type` for an HTTP status."""
219
+ if status_code == 429:
220
+ return "rate_limit_error"
221
+ return "server_error" if status_code >= 500 else "invalid_request_error"
222
+
223
+
217
224
  def is_sse_done_event(raw: bytes) -> bool:
218
225
  """Whether one complete SSE event carries the DONE sentinel."""
219
226
  # Ordinary OpenAI events carry JSON objects; reject their hot path before splitting lines.
@@ -313,8 +320,16 @@ class Dialect(ABC, Generic[RespT]):
313
320
  return is_sse_done_event(chunk)
314
321
 
315
322
  def error_body(self, message: str, *, status_code: int = 400) -> dict:
316
- """An error payload in this format's error shape (OpenAI by default)."""
317
- return {"error": {"message": message, "type": "invalid_request_error"}}
323
+ """An error payload in this format's error shape (OpenAI by default). Its `code` is
324
+ the HTTP status, as OpenAI-compatible servers report it, so a client reading the
325
+ payload off a committed stream can classify it as it would the status."""
326
+ return {
327
+ "error": {
328
+ "message": message,
329
+ "type": _error_type(status_code),
330
+ "code": status_code,
331
+ }
332
+ }
318
333
 
319
334
  def stream_keepalive(self, first: bool) -> bytes:
320
335
  """A keepalive for a committed SSE stream whose turn is still being produced (`first`
@@ -325,7 +340,11 @@ class Dialect(ABC, Generic[RespT]):
325
340
 
326
341
  def stream_error(self, error: dict, *, status_code: int | None = None) -> bytes:
327
342
  """An `error_body` as an SSE event, for a failure after the stream is committed.
328
- OpenAI SDKs raise on any event carrying `error`."""
343
+ OpenAI SDKs raise on any event carrying `error`; once HTTP 200 is committed,
344
+ clients classify retries from its `type` and `code`."""
345
+ if status_code is not None:
346
+ classified = {"type": _error_type(status_code), "code": status_code}
347
+ error = {**error, "error": {**error.get("error", {}), **classified}}
329
348
  return b"data: " + json.dumps(error).encode() + b"\n\n"
330
349
 
331
350
  @abstractmethod
@@ -27,6 +27,7 @@ from verifiers.v1.dialects.base import (
27
27
  append_user_notice,
28
28
  parse_sse_event,
29
29
  )
30
+ from verifiers.v1.errors import ProviderError
30
31
  from verifiers.v1.types import (
31
32
  AssistantMessage,
32
33
  FinishReason,
@@ -292,6 +293,15 @@ class ChatStreamParser(StreamParser):
292
293
  chunk = parse_sse_event(raw)
293
294
  if chunk is None:
294
295
  return
296
+ # A provider fails a stream mid-way with a chunk carrying `error` (which the OpenAI
297
+ # SDK raises on) and/or finishing with "error": fail the turn, not a partial reply.
298
+ error = chunk.get("error")
299
+ if error or any(
300
+ choice.get("finish_reason") == "error"
301
+ for choice in chunk.get("choices") or []
302
+ ):
303
+ message = error.get("message") if isinstance(error, dict) else error
304
+ raise ProviderError(f"upstream stream failed: {message or 'unknown error'}")
295
305
  if self.head is None:
296
306
  self.head = chunk
297
307
  self.usage = chunk.get("usage") or self.usage
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: verifiers
3
- Version: 0.4.2.dev47
3
+ Version: 0.4.2.dev48
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
@@ -54,8 +54,8 @@ verifiers/v1/configs/cli/run.py,sha256=j6ccPxFPiWsmCAmbZcc_EtElNOMaKS9YiiSDMqudc
54
54
  verifiers/v1/configs/cli/validate.py,sha256=j6qRi2EvacXTCARnVhkFRtX9xF3IP3eVVt-Zv2ER5Vw,4073
55
55
  verifiers/v1/dialects/__init__.py,sha256=MNOYM2NdTlSxGK4VtoEjMtD5zya2MpjPDX5jMvZUWEo,736
56
56
  verifiers/v1/dialects/anthropic.py,sha256=5FZyAV2Aa9UU_tmoSJi4_FYxSw_QFk5e0v0v6LNxKk0,27338
57
- verifiers/v1/dialects/base.py,sha256=9C0Co6XAQrZsIWnJiAMtwPF5B00z-c20_RiSs51-TG4,16227
58
- verifiers/v1/dialects/chat.py,sha256=quhjv9ipa0ces3VYB5ZbegB_RwIAK5vj17c6NiQF74s,24507
57
+ verifiers/v1/dialects/base.py,sha256=klpNBA9_hpJdEAoQsJRpa5yUArkTIwmIbdyUe69Jj_o,17039
58
+ verifiers/v1/dialects/chat.py,sha256=ea_B3tEWgnYjGoyBJI-ysuRyEEMMcA1_H9M6nTf7jec,25082
59
59
  verifiers/v1/dialects/responses.py,sha256=aoRe94g_Wa2BfHfEUdM8XVesn-RcwfXHoXl1lN4r-qE,31272
60
60
  verifiers/v1/envs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
61
61
  verifiers/v1/envs/agentic_judge/__init__.py,sha256=6vwtMCQ_cuvuubCF5-nrE5W7gGgzE-LIPKorkM5DXdw,309
@@ -187,8 +187,8 @@ verifiers/v1/utils/scope.py,sha256=zbs4pj6AVk4jywlAJ3AX0Q0_kzB9dBB02nY-9H4ELdQ,8
187
187
  verifiers/v1/utils/score.py,sha256=493yJVMw8teCu9JxapxMFPFzI0hNUqdo0Y2nGW4kckk,6200
188
188
  verifiers/v1/utils/trace_store.py,sha256=Qo9qvsJAl8PoRUavjQAfUB2VNxmUtYQtU2ejLKPzY9c,3382
189
189
  verifiers/v1/utils/version.py,sha256=-obEo_-l9-D8FLef4hYxncOe-uJpxrM1g2Hig_37Sgs,1607
190
- verifiers-0.4.2.dev47.dist-info/METADATA,sha256=F0Vx5epXRFpFuDSDPOkEQZUMTGT1TTzpy_fV6elIgy4,5115
191
- verifiers-0.4.2.dev47.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
192
- verifiers-0.4.2.dev47.dist-info/entry_points.txt,sha256=qdMg7ajiFpDsHf7tuPMRclJXizu1J6LTWawS5YS0B0I,137
193
- verifiers-0.4.2.dev47.dist-info/licenses/LICENSE,sha256=v0RrUsdV3IDoZhrRce297IXS3xMHNJ-_LdLpFAUWb9k,1072
194
- verifiers-0.4.2.dev47.dist-info/RECORD,,
190
+ verifiers-0.4.2.dev48.dist-info/METADATA,sha256=u0sh9E4Sz5RFyKkqOPOFnwawip7obMpfaOFiEePDheQ,5115
191
+ verifiers-0.4.2.dev48.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
192
+ verifiers-0.4.2.dev48.dist-info/entry_points.txt,sha256=qdMg7ajiFpDsHf7tuPMRclJXizu1J6LTWawS5YS0B0I,137
193
+ verifiers-0.4.2.dev48.dist-info/licenses/LICENSE,sha256=v0RrUsdV3IDoZhrRce297IXS3xMHNJ-_LdLpFAUWb9k,1072
194
+ verifiers-0.4.2.dev48.dist-info/RECORD,,