Spaces:
Running
Running
Commit ·
de28646
1
Parent(s): 4c86c77
Revert "fix(nim): handle progressive payload downgrades on NIM 500 internal server errors"
Browse filesThis reverts commit 4c86c7757bca02f7e34658248ea839e89a1932a1.
src/free_claude_code/providers/nvidia_nim/client.py
CHANGED
|
@@ -5,7 +5,6 @@ import json
|
|
| 5 |
import re
|
| 6 |
import sys
|
| 7 |
from collections.abc import Mapping
|
| 8 |
-
from copy import deepcopy
|
| 9 |
from typing import Any
|
| 10 |
|
| 11 |
import httpx
|
|
@@ -217,23 +216,11 @@ class NvidiaNimProvider(OpenAIChatProvider):
|
|
| 217 |
"""Return NIM tool argument aliases captured while building this request."""
|
| 218 |
return nim_tool_argument_aliases_from_body(body)
|
| 219 |
|
| 220 |
-
def
|
| 221 |
-
|
| 222 |
-
error: Exception,
|
| 223 |
-
body: dict,
|
| 224 |
-
used_retry_kinds: set[str],
|
| 225 |
-
) -> dict | None:
|
| 226 |
-
"""Progressively downgrade request body on NIM 400 and 500 errors."""
|
| 227 |
-
base_retry = super()._next_create_retry_body(error, body, used_retry_kinds)
|
| 228 |
-
if base_retry is not None:
|
| 229 |
-
return base_retry
|
| 230 |
-
|
| 231 |
status_code = getattr(error, "status_code", None)
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
isinstance(error, openai.BadRequestError)
|
| 235 |
-
or status_code == 400
|
| 236 |
-
or is_500
|
| 237 |
)
|
| 238 |
|
| 239 |
error_text = str(error)
|
|
@@ -242,41 +229,35 @@ class NvidiaNimProvider(OpenAIChatProvider):
|
|
| 242 |
error_text = f"{error_text} {json.dumps(error_body, default=str)}"
|
| 243 |
error_text = error_text.lower()
|
| 244 |
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
_is_reasoning_budget_rejection(error_text)
|
| 248 |
-
or "chat_template" in error_text
|
| 249 |
-
or bad_request_like
|
| 250 |
):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 251 |
retry_body = clone_body_without_chat_template(body)
|
| 252 |
if retry_body is None:
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
logger.warning(
|
| 257 |
-
"NIM_STREAM: retrying without chat_template/reasoning_budget after NIM error"
|
| 258 |
-
)
|
| 259 |
-
return retry_body
|
| 260 |
|
| 261 |
-
|
| 262 |
-
if "nim_reasoning_content" not in used_retry_kinds and (
|
| 263 |
-
"reasoning_content" in error_text or bad_request_like
|
| 264 |
-
):
|
| 265 |
retry_body = clone_body_without_reasoning_content(body)
|
| 266 |
-
if retry_body is
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
# Step 3: Strip entire extra_body
|
| 274 |
-
if "nim_extra_body" not in used_retry_kinds and is_500 and "extra_body" in body:
|
| 275 |
-
cloned = deepcopy(body)
|
| 276 |
-
cloned.pop("extra_body", None)
|
| 277 |
-
used_retry_kinds.add("nim_extra_body")
|
| 278 |
-
logger.warning("NIM_STREAM: retrying without extra_body after NIM 500 error")
|
| 279 |
-
return cloned
|
| 280 |
|
| 281 |
return None
|
| 282 |
|
|
|
|
| 5 |
import re
|
| 6 |
import sys
|
| 7 |
from collections.abc import Mapping
|
|
|
|
| 8 |
from typing import Any
|
| 9 |
|
| 10 |
import httpx
|
|
|
|
| 216 |
"""Return NIM tool argument aliases captured while building this request."""
|
| 217 |
return nim_tool_argument_aliases_from_body(body)
|
| 218 |
|
| 219 |
+
def _get_retry_request_body(self, error: Exception, body: dict) -> dict | None:
|
| 220 |
+
"""Retry once with a downgraded body when NIM rejects a known field."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 221 |
status_code = getattr(error, "status_code", None)
|
| 222 |
+
bad_request_like = isinstance(error, openai.BadRequestError) or (
|
| 223 |
+
status_code == 400
|
|
|
|
|
|
|
|
|
|
| 224 |
)
|
| 225 |
|
| 226 |
error_text = str(error)
|
|
|
|
| 229 |
error_text = f"{error_text} {json.dumps(error_body, default=str)}"
|
| 230 |
error_text = error_text.lower()
|
| 231 |
|
| 232 |
+
if _is_reasoning_budget_rejection(error_text) and (
|
| 233 |
+
bad_request_like or status_code == 500
|
|
|
|
|
|
|
|
|
|
| 234 |
):
|
| 235 |
+
retry_body = clone_body_without_reasoning_budget(body)
|
| 236 |
+
if retry_body is None:
|
| 237 |
+
return None
|
| 238 |
+
logger.warning(
|
| 239 |
+
"NIM_STREAM: retrying without reasoning budget after upstream rejection"
|
| 240 |
+
)
|
| 241 |
+
return retry_body
|
| 242 |
+
|
| 243 |
+
if not bad_request_like:
|
| 244 |
+
return None
|
| 245 |
+
|
| 246 |
+
if "chat_template" in error_text:
|
| 247 |
retry_body = clone_body_without_chat_template(body)
|
| 248 |
if retry_body is None:
|
| 249 |
+
return None
|
| 250 |
+
logger.warning("NIM_STREAM: retrying without chat_template after 400 error")
|
| 251 |
+
return retry_body
|
|
|
|
|
|
|
|
|
|
|
|
|
| 252 |
|
| 253 |
+
if "reasoning_content" in error_text:
|
|
|
|
|
|
|
|
|
|
| 254 |
retry_body = clone_body_without_reasoning_content(body)
|
| 255 |
+
if retry_body is None:
|
| 256 |
+
return None
|
| 257 |
+
logger.warning(
|
| 258 |
+
"NIM_STREAM: retrying without reasoning_content after 400 error"
|
| 259 |
+
)
|
| 260 |
+
return retry_body
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 261 |
|
| 262 |
return None
|
| 263 |
|