verifiers 0.3.2.dev135__py3-none-any.whl → 0.3.2.dev137__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.
@@ -3,14 +3,22 @@
3
3
  import argparse
4
4
  import asyncio
5
5
  import json
6
+ import logging
6
7
  import subprocess
7
8
  from contextlib import AsyncExitStack
8
9
  from pathlib import Path
9
10
  from typing import TYPE_CHECKING
10
11
 
11
12
  import httpx
12
- from openai import APIStatusError, AsyncOpenAI, omit
13
+ from openai import APIConnectionError, APIStatusError, AsyncOpenAI, omit
13
14
  from openai.lib.streaming.chat import AsyncChatCompletionStream
15
+ from tenacity import (
16
+ AsyncRetrying,
17
+ before_sleep_log,
18
+ retry_if_exception_type,
19
+ stop_after_attempt,
20
+ wait_random_exponential,
21
+ )
14
22
 
15
23
  if TYPE_CHECKING:
16
24
  # The harness bundles this module into the generated script before execution.
@@ -245,9 +253,28 @@ async def chat(
245
253
  kwargs["tools"] = tools
246
254
  if tools and tool_choice is not None:
247
255
  kwargs["tool_choice"] = tool_choice
248
- raw_stream = await client.chat.completions.create(
249
- **kwargs, stream=True, stream_options={"include_usage": True}
250
- )
256
+ async for attempt in AsyncRetrying(
257
+ retry=retry_if_exception_type((APIConnectionError, httpx.TransportError)),
258
+ stop=stop_after_attempt(client.max_retries + 1),
259
+ wait=wait_random_exponential(multiplier=0.5, max=8.0),
260
+ before_sleep=before_sleep_log(logging.getLogger(__name__), logging.WARNING),
261
+ reraise=True,
262
+ ):
263
+ # Reuse the interception server's body-digest replay guard on stream retries.
264
+ retry_count = attempt.retry_state.attempt_number - 1
265
+ headers = {"x-stainless-retry-count": str(retry_count)} if retry_count else omit
266
+ raw_stream = await client.chat.completions.create(
267
+ **kwargs,
268
+ stream=True,
269
+ stream_options={"include_usage": True},
270
+ extra_headers=headers,
271
+ )
272
+ # The SDK retries request setup; only stream consumption is retried here.
273
+ with attempt:
274
+ return await _read_chat_completion(raw_stream)
275
+
276
+
277
+ async def _read_chat_completion(raw_stream):
251
278
  # Accumulate native deltas without auto-parsing tool arguments or treating
252
279
  # finish_reason="length" as an exception: compaction owns that decision.
253
280
  async with AsyncChatCompletionStream(
@@ -271,7 +298,10 @@ async def chat(
271
298
  or not completion.choices
272
299
  or any(choice.finish_reason is None for choice in completion.choices)
273
300
  ):
274
- raise RuntimeError("model stream ended before a completion finished")
301
+ raise APIConnectionError(
302
+ message="Model stream ended before a completion finished",
303
+ request=raw_stream.response.request,
304
+ )
275
305
  for choice in completion.choices:
276
306
  overrides = message_overrides.setdefault(choice.index, {})
277
307
  overrides.setdefault("role", "assistant")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: verifiers
3
- Version: 0.3.2.dev135
3
+ Version: 0.3.2.dev137
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
@@ -118,7 +118,7 @@ verifiers/v1/harnesses/terminus_2/harness.py,sha256=cKQJluW01mkxEccTLFwSWsVMavyi
118
118
  verifiers/v1/harnesses/terminus_2/program.py,sha256=X8MZdyItU3gbXGXnGOlJ9LWcUTnqIDaxlhkZvoRiqKY,2703
119
119
  verifiers/v1/harnesses/utils/__init__.py,sha256=eTS-Ft2HwoLiYn5u1t_KueLmaZB_W12cdYmcVsE-G5A,364
120
120
  verifiers/v1/harnesses/utils/compaction.py,sha256=DeY6CYLEsv7-vJm26sT2mRaPHu3W2ywiZhvFr_pi6Hg,10495
121
- verifiers/v1/harnesses/utils/core.py,sha256=emAeNqtha__3cR0u7pvoQGnl2sE57wadE0wlKGtO1Yk,18520
121
+ verifiers/v1/harnesses/utils/core.py,sha256=A4B_TbZBQVd6IYQyytrO8gbmrO-aVqjRl0-w8GClWF4,19676
122
122
  verifiers/v1/harnesses/utils/install.py,sha256=BDkkUVZ1brSzCrbQOvMO5mVIE2DsV2pE7rTC5yROYUw,2992
123
123
  verifiers/v1/harnesses/utils/launch.py,sha256=RqPuUY-kT2XVuLSGtXW7kRQEaP-o2KzkiJ7vcoo2neM,2883
124
124
  verifiers/v1/harnesses/utils/mcp.py,sha256=oNhKfLjAW-wScJcDIsW_HfuvKY-JkaGBBZrRLqgRK1g,7355
@@ -190,8 +190,8 @@ verifiers/v1/utils/retries.py,sha256=Y2ZgrAjn-qNkRKZP_RVNL_7EK0iaRcZeCa404lpGYi4
190
190
  verifiers/v1/utils/scope.py,sha256=bzUEiWDOVdbj7dXOwGOlzsQ_-Xu0j9NR5TalQB-8TS8,838
191
191
  verifiers/v1/utils/score.py,sha256=493yJVMw8teCu9JxapxMFPFzI0hNUqdo0Y2nGW4kckk,6200
192
192
  verifiers/v1/utils/version.py,sha256=-obEo_-l9-D8FLef4hYxncOe-uJpxrM1g2Hig_37Sgs,1607
193
- verifiers-0.3.2.dev135.dist-info/METADATA,sha256=OCF9X7j75M276Mq19ujDEeu7fg0QXyYiVGfrv3oOfBA,4161
194
- verifiers-0.3.2.dev135.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
195
- verifiers-0.3.2.dev135.dist-info/entry_points.txt,sha256=iugElcdWPKbQM7uFF0lZ8iUpHsNr17-BwEAAjJWxV3U,259
196
- verifiers-0.3.2.dev135.dist-info/licenses/LICENSE,sha256=v0RrUsdV3IDoZhrRce297IXS3xMHNJ-_LdLpFAUWb9k,1072
197
- verifiers-0.3.2.dev135.dist-info/RECORD,,
193
+ verifiers-0.3.2.dev137.dist-info/METADATA,sha256=VQI1rjxyohbv-YuGV_gy0Ej5r4i_AmPXzYM2FkPrmro,4161
194
+ verifiers-0.3.2.dev137.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
195
+ verifiers-0.3.2.dev137.dist-info/entry_points.txt,sha256=iugElcdWPKbQM7uFF0lZ8iUpHsNr17-BwEAAjJWxV3U,259
196
+ verifiers-0.3.2.dev137.dist-info/licenses/LICENSE,sha256=v0RrUsdV3IDoZhrRce297IXS3xMHNJ-_LdLpFAUWb9k,1072
197
+ verifiers-0.3.2.dev137.dist-info/RECORD,,