Fix NVIDIA NIM reasoning params for updated API · Alishahryar1/free-claude-code@f9e7f65 · GitHub
Skip to content

Commit f9e7f65

Browse files
committed
Fix NVIDIA NIM reasoning params for updated API
Replace dropped params (thinking, reasoning_split, include_reasoning, return_tokens_as_token_ids, reasoning_effort) with the new API format: chat_template_kwargs.enable_thinking=True and reasoning_budget=max_tokens.
1 parent 0003820 commit f9e7f65

5 files changed

Lines changed: 49 additions & 38 deletions

File tree

config/nim.py

Lines changed: 0 additions & 6 deletions

providers/nvidia_nim/request.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,8 @@ def build_request_body(request_data: Any, nim: NimSettings) -> dict:
6363
if request_extra:
6464
extra_body.update(request_extra)
6565

66-
# Handle thinking/reasoning mode
67-
extra_body.setdefault("thinking", {"type": "enabled"})
68-
extra_body.setdefault("reasoning_split", True)
69-
extra_body.setdefault(
70-
"chat_template_kwargs",
71-
{
72-
"thinking": True,
73-
"enable_thinking": True,
74-
"reasoning_split": True,
75-
"clear_thinking": False,
76-
},
77-
)
66+
extra_body.setdefault("chat_template_kwargs", {"enable_thinking": True})
67+
_set_extra(extra_body, "reasoning_budget", max_tokens)
7868

7969
req_top_k = getattr(request_data, "top_k", None)
8070
top_k = req_top_k if req_top_k is not None else nim.top_k
@@ -86,10 +76,7 @@ def build_request_body(request_data: Any, nim: NimSettings) -> dict:
8676
_set_extra(extra_body, "min_tokens", nim.min_tokens, ignore_value=0)
8777
_set_extra(extra_body, "chat_template", nim.chat_template)
8878
_set_extra(extra_body, "request_id", nim.request_id)
89-
_set_extra(extra_body, "return_tokens_as_token_ids", nim.return_tokens_as_token_ids)
9079
_set_extra(extra_body, "ignore_eos", nim.ignore_eos)
91-
_set_extra(extra_body, "reasoning_effort", nim.reasoning_effort)
92-
_set_extra(extra_body, "include_reasoning", nim.include_reasoning)
9380

9481
if extra_body:
9582
body["extra_body"] = extra_body

tests/config/test_config.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,6 @@ def test_top_p_valid(self, top_p):
125125
s = NimSettings(top_p=top_p)
126126
assert s.top_p == top_p
127127

128-
@pytest.mark.parametrize("effort", ["low", "medium", "high"])
129-
def test_reasoning_effort_valid(self, effort):
130-
s = NimSettings(reasoning_effort=effort)
131-
assert s.reasoning_effort == effort
132-
133128
def test_max_tokens_valid(self):
134129
s = NimSettings(max_tokens=1)
135130
assert s.max_tokens == 1
@@ -195,12 +190,6 @@ def test_min_tokens_negative(self):
195190
with pytest.raises(ValidationError):
196191
NimSettings(min_tokens=-1)
197192

198-
def test_reasoning_effort_invalid(self):
199-
from typing import Any, cast
200-
201-
with pytest.raises(ValidationError):
202-
NimSettings(reasoning_effort=cast(Any, "invalid"))
203-
204193

205194
class TestNimSettingsValidators:
206195
"""Test custom field validators in NimSettings."""

tests/providers/test_nvidia_nim.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,9 @@ async def test_build_request_body(nim_provider):
9999
assert body["messages"][0]["content"] == "System prompt"
100100

101101
assert "extra_body" in body
102-
assert "thinking" in body["extra_body"]
103-
assert body["extra_body"]["thinking"]["type"] == "enabled"
104-
105-
# Verify chat_template_kwargs includes both thinking keys for model compatibility
106102
ctk = body["extra_body"]["chat_template_kwargs"]
107-
assert ctk["thinking"] is True
108103
assert ctk["enable_thinking"] is True
109-
assert ctk["clear_thinking"] is False
104+
assert body["extra_body"]["reasoning_budget"] == body["max_tokens"]
110105

111106

112107
@pytest.mark.asyncio

tests/providers/test_nvidia_nim_request.py

Lines changed: 46 additions & 0 deletions

0 commit comments

Comments
 (0)