code-puppy 0.0.378__py3-none-any.whl → 0.0.379__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.
- code_puppy/http_utils.py +39 -19
- code_puppy/model_factory.py +6 -1
- {code_puppy-0.0.378.dist-info → code_puppy-0.0.379.dist-info}/METADATA +1 -1
- {code_puppy-0.0.378.dist-info → code_puppy-0.0.379.dist-info}/RECORD +9 -9
- {code_puppy-0.0.378.data → code_puppy-0.0.379.data}/data/code_puppy/models.json +0 -0
- {code_puppy-0.0.378.data → code_puppy-0.0.379.data}/data/code_puppy/models_dev_api.json +0 -0
- {code_puppy-0.0.378.dist-info → code_puppy-0.0.379.dist-info}/WHEEL +0 -0
- {code_puppy-0.0.378.dist-info → code_puppy-0.0.379.dist-info}/entry_points.txt +0 -0
- {code_puppy-0.0.378.dist-info → code_puppy-0.0.379.dist-info}/licenses/LICENSE +0 -0
code_puppy/http_utils.py
CHANGED
|
@@ -102,17 +102,24 @@ class RetryingAsyncClient(httpx.AsyncClient):
|
|
|
102
102
|
|
|
103
103
|
This replaces the Tenacity transport with a more direct subclass implementation,
|
|
104
104
|
which plays nicer with proxies and custom transports (like Antigravity).
|
|
105
|
+
|
|
106
|
+
Special handling for Cerebras: Their Retry-After headers are absurdly aggressive
|
|
107
|
+
(often 60s), so we ignore them and use a 3s base backoff instead.
|
|
105
108
|
"""
|
|
106
109
|
|
|
107
110
|
def __init__(
|
|
108
111
|
self,
|
|
109
112
|
retry_status_codes: tuple = (429, 502, 503, 504),
|
|
110
113
|
max_retries: int = 5,
|
|
114
|
+
model_name: str = "",
|
|
111
115
|
**kwargs,
|
|
112
116
|
):
|
|
113
117
|
super().__init__(**kwargs)
|
|
114
118
|
self.retry_status_codes = retry_status_codes
|
|
115
119
|
self.max_retries = max_retries
|
|
120
|
+
self.model_name = model_name.lower() if model_name else ""
|
|
121
|
+
# Cerebras sends crazy aggressive Retry-After headers (60s), ignore them
|
|
122
|
+
self._ignore_retry_headers = "cerebras" in self.model_name
|
|
116
123
|
|
|
117
124
|
async def send(self, request: httpx.Request, **kwargs: Any) -> httpx.Response:
|
|
118
125
|
"""Send request with automatic retries for rate limits and server errors."""
|
|
@@ -131,32 +138,39 @@ class RetryingAsyncClient(httpx.AsyncClient):
|
|
|
131
138
|
# Close response if we're going to retry
|
|
132
139
|
await response.aclose()
|
|
133
140
|
|
|
134
|
-
# Determine wait time
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
if retry_after:
|
|
142
|
-
try:
|
|
143
|
-
wait_time = float(retry_after)
|
|
144
|
-
except ValueError:
|
|
145
|
-
# Try parsing http-date
|
|
146
|
-
from email.utils import parsedate_to_datetime
|
|
141
|
+
# Determine wait time - Cerebras gets special treatment
|
|
142
|
+
if self._ignore_retry_headers:
|
|
143
|
+
# Cerebras: 3s base with exponential backoff (3s, 6s, 12s...)
|
|
144
|
+
wait_time = 3.0 * (2**attempt)
|
|
145
|
+
else:
|
|
146
|
+
# Default exponential backoff: 1s, 2s, 4s...
|
|
147
|
+
wait_time = 1.0 * (2**attempt)
|
|
147
148
|
|
|
149
|
+
# Check Retry-After header (only for non-Cerebras)
|
|
150
|
+
retry_after = response.headers.get("Retry-After")
|
|
151
|
+
if retry_after:
|
|
148
152
|
try:
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
+
wait_time = float(retry_after)
|
|
154
|
+
except ValueError:
|
|
155
|
+
# Try parsing http-date
|
|
156
|
+
from email.utils import parsedate_to_datetime
|
|
157
|
+
|
|
158
|
+
try:
|
|
159
|
+
date = parsedate_to_datetime(retry_after)
|
|
160
|
+
wait_time = date.timestamp() - time.time()
|
|
161
|
+
except Exception:
|
|
162
|
+
pass
|
|
153
163
|
|
|
154
164
|
# Cap wait time
|
|
155
165
|
wait_time = max(0.5, min(wait_time, 60.0))
|
|
156
166
|
|
|
157
167
|
if attempt < self.max_retries:
|
|
168
|
+
provider_note = (
|
|
169
|
+
" (ignoring header)" if self._ignore_retry_headers else ""
|
|
170
|
+
)
|
|
158
171
|
emit_info(
|
|
159
|
-
f"HTTP retry: {response.status_code} received
|
|
172
|
+
f"HTTP retry: {response.status_code} received{provider_note}. "
|
|
173
|
+
f"Waiting {wait_time:.1f}s (attempt {attempt + 1}/{self.max_retries})"
|
|
160
174
|
)
|
|
161
175
|
await asyncio.sleep(wait_time)
|
|
162
176
|
|
|
@@ -219,12 +233,14 @@ def create_async_client(
|
|
|
219
233
|
verify: Union[bool, str] = None,
|
|
220
234
|
headers: Optional[Dict[str, str]] = None,
|
|
221
235
|
retry_status_codes: tuple = (429, 502, 503, 504),
|
|
236
|
+
model_name: str = "",
|
|
222
237
|
) -> httpx.AsyncClient:
|
|
223
238
|
config = _resolve_proxy_config(verify)
|
|
224
239
|
|
|
225
240
|
if not config.disable_retry:
|
|
226
241
|
return RetryingAsyncClient(
|
|
227
242
|
retry_status_codes=retry_status_codes,
|
|
243
|
+
model_name=model_name,
|
|
228
244
|
proxy=config.proxy_url,
|
|
229
245
|
verify=config.verify,
|
|
230
246
|
headers=headers or {},
|
|
@@ -290,6 +306,7 @@ def create_reopenable_async_client(
|
|
|
290
306
|
verify: Union[bool, str] = None,
|
|
291
307
|
headers: Optional[Dict[str, str]] = None,
|
|
292
308
|
retry_status_codes: tuple = (429, 502, 503, 504),
|
|
309
|
+
model_name: str = "",
|
|
293
310
|
) -> Union[ReopenableAsyncClient, httpx.AsyncClient]:
|
|
294
311
|
config = _resolve_proxy_config(verify)
|
|
295
312
|
|
|
@@ -309,12 +326,15 @@ def create_reopenable_async_client(
|
|
|
309
326
|
kwargs = {**base_kwargs, "client_class": client_class}
|
|
310
327
|
if not config.disable_retry:
|
|
311
328
|
kwargs["retry_status_codes"] = retry_status_codes
|
|
329
|
+
kwargs["model_name"] = model_name
|
|
312
330
|
return ReopenableAsyncClient(**kwargs)
|
|
313
331
|
else:
|
|
314
332
|
# Fallback to RetryingAsyncClient or plain AsyncClient
|
|
315
333
|
if not config.disable_retry:
|
|
316
334
|
return RetryingAsyncClient(
|
|
317
|
-
retry_status_codes=retry_status_codes,
|
|
335
|
+
retry_status_codes=retry_status_codes,
|
|
336
|
+
model_name=model_name,
|
|
337
|
+
**base_kwargs,
|
|
318
338
|
)
|
|
319
339
|
else:
|
|
320
340
|
return httpx.AsyncClient(**base_kwargs)
|
code_puppy/model_factory.py
CHANGED
|
@@ -585,7 +585,12 @@ class ModelFactory:
|
|
|
585
585
|
return None
|
|
586
586
|
# Add Cerebras 3rd party integration header
|
|
587
587
|
headers["X-Cerebras-3rd-Party-Integration"] = "code-puppy"
|
|
588
|
-
|
|
588
|
+
# Pass "cerebras" so RetryingAsyncClient knows to ignore Cerebras's
|
|
589
|
+
# absurdly aggressive Retry-After headers (they send 60s!)
|
|
590
|
+
# Note: model_config["name"] is "zai-glm-4.7", not "cerebras"
|
|
591
|
+
client = create_async_client(
|
|
592
|
+
headers=headers, verify=verify, model_name="cerebras"
|
|
593
|
+
)
|
|
589
594
|
provider_args = dict(
|
|
590
595
|
api_key=api_key,
|
|
591
596
|
http_client=client,
|
|
@@ -8,10 +8,10 @@ code_puppy/config.py,sha256=eAyVqiu8SwzJQpaJu80rlJvd8XXY51DqafMsP5lBRI4,55827
|
|
|
8
8
|
code_puppy/error_logging.py,sha256=a80OILCUtJhexI6a9GM-r5LqIdjvSRzggfgPp2jv1X0,3297
|
|
9
9
|
code_puppy/gemini_code_assist.py,sha256=KGS7sO5OLc83nDF3xxS-QiU6vxW9vcm6hmzilu79Ef8,13867
|
|
10
10
|
code_puppy/gemini_model.py,sha256=UHb5vFC9zrEdFJ-yCN3vNCdp0UxP156BL_fwbnEhaw8,27988
|
|
11
|
-
code_puppy/http_utils.py,sha256=
|
|
11
|
+
code_puppy/http_utils.py,sha256=Xel6UyQGO6X_5BlrtPYO1hVXN24aqP72tn5g1uUkluU,11491
|
|
12
12
|
code_puppy/keymap.py,sha256=IvMkTlB_bIqOWpbTpmftkdyjhtD5todXuEIw1zCZ4u0,3584
|
|
13
13
|
code_puppy/main.py,sha256=82r3vZy_XcyEsenLn82BnUusaoyL3Bpm_Th_jKgqecE,273
|
|
14
|
-
code_puppy/model_factory.py,sha256=
|
|
14
|
+
code_puppy/model_factory.py,sha256=5ndms7O0_bJftizpJMbsdYs3geixn3vZKL2105zEgmM,32338
|
|
15
15
|
code_puppy/model_switching.py,sha256=3IsnSWKHLWzI5d2WDYNg0Xr78BeYNN1WrZuzas-lYJ4,2064
|
|
16
16
|
code_puppy/model_utils.py,sha256=cG1V4fsIOEQIb0W88FyGcsMWNv8SpmRAXN3A7LBEoyE,5116
|
|
17
17
|
code_puppy/models.json,sha256=SC7N2lV1Q8ikXlalRNqABkNvuuL_8fIIk638739-gGY,3319
|
|
@@ -225,10 +225,10 @@ code_puppy/tools/browser/chromium_terminal_manager.py,sha256=w1thQ_ACb6oV45L93TS
|
|
|
225
225
|
code_puppy/tools/browser/terminal_command_tools.py,sha256=9byOZku-dwvTtCl532xt7Lumed_jTn0sLvUe_X75XCQ,19068
|
|
226
226
|
code_puppy/tools/browser/terminal_screenshot_tools.py,sha256=J_21YO_495NvYgNFu9KQP6VYg2K_f8CtSdZuF94Yhnw,18448
|
|
227
227
|
code_puppy/tools/browser/terminal_tools.py,sha256=F5LjVH3udSCFHmqC3O1UJLoLozZFZsEdX42jOmkqkW0,17853
|
|
228
|
-
code_puppy-0.0.
|
|
229
|
-
code_puppy-0.0.
|
|
230
|
-
code_puppy-0.0.
|
|
231
|
-
code_puppy-0.0.
|
|
232
|
-
code_puppy-0.0.
|
|
233
|
-
code_puppy-0.0.
|
|
234
|
-
code_puppy-0.0.
|
|
228
|
+
code_puppy-0.0.379.data/data/code_puppy/models.json,sha256=SC7N2lV1Q8ikXlalRNqABkNvuuL_8fIIk638739-gGY,3319
|
|
229
|
+
code_puppy-0.0.379.data/data/code_puppy/models_dev_api.json,sha256=wHjkj-IM_fx1oHki6-GqtOoCrRMR0ScK0f-Iz0UEcy8,548187
|
|
230
|
+
code_puppy-0.0.379.dist-info/METADATA,sha256=ldoaFKnfpIocHpmV_ZBTVEjfW0l7YWxIX7qRXJt1rQM,27604
|
|
231
|
+
code_puppy-0.0.379.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
232
|
+
code_puppy-0.0.379.dist-info/entry_points.txt,sha256=Tp4eQC99WY3HOKd3sdvb22vZODRq0XkZVNpXOag_KdI,91
|
|
233
|
+
code_puppy-0.0.379.dist-info/licenses/LICENSE,sha256=31u8x0SPgdOq3izJX41kgFazWsM43zPEF9eskzqbJMY,1075
|
|
234
|
+
code_puppy-0.0.379.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|