Skip to content

Commit 66a3bcd

Browse files
committed
Merge pull request 'feat: opus 4.1 and gpt-5 special config' (#458) from spec_config into development
Reviewed-on: https://git.biggo.com/Funmula/dive-mcp-host/pulls/458
2 parents e007244 + 243bf24 commit 66a3bcd

File tree

2 files changed

+124
-1
lines changed

2 files changed

+124
-1
lines changed

dive_mcp_host/host/conf/llm.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class LLMConfiguration(BaseModel):
8282

8383
base_url: str | None = Field(default=None, alias="baseURL")
8484
skip_tls_verify: bool | None = Field(default=None)
85-
temperature: float | None = Field(default=0)
85+
temperature: float | None = Field(default=None)
8686
top_p: float | None = Field(default=None)
8787

8888
model_config = pydantic_model_config
@@ -150,6 +150,28 @@ def dump_api_key(self, v: SecretStr | None) -> str | None:
150150
"""Serialize the api_key field to plain text."""
151151
return v.get_secret_value() if v else None
152152

153+
@model_validator(mode="after")
154+
def temperature_top_p(self) -> Self:
155+
"""Update default headers for large tokens."""
156+
if (
157+
"claude-opus-4-1" in self.model
158+
and self.configuration
159+
and self.configuration.temperature
160+
and self.configuration.top_p
161+
):
162+
self.configuration.top_p = None
163+
164+
if (
165+
"gpt-5" in self.model
166+
and self.configuration
167+
and (temperature := self.configuration.temperature)
168+
):
169+
if temperature > 0:
170+
self.configuration.temperature = 1
171+
else:
172+
self.configuration.temperature = None
173+
return self
174+
153175

154176
class LLMBedrockConfig(BaseLLMConfig):
155177
"""Configuration for Bedrock LLM models."""

tests/test_models.py

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,3 +230,104 @@ def test_ollama_skip_tls_verify() -> None:
230230
)
231231

232232
assert model._client._client._transport._pool._ssl_context.verify_mode == CERT_NONE # type: ignore
233+
234+
235+
def test_opus_4_1_temperature_top_p() -> None:
236+
"""Test the temperature and top_p."""
237+
raw_config: dict = {
238+
"modelProvider": "anthropic",
239+
"model": "claude-opus-4-1",
240+
}
241+
242+
# test opus 4.1
243+
simple_1 = raw_config.copy()
244+
llm_config = LLMConfig.model_validate(simple_1)
245+
246+
# with temperature and top_p
247+
simple_2 = raw_config.copy()
248+
simple_2["configuration"] = {"temperature": 0.5, "top_p": 0.5}
249+
llm_config = LLMConfig.model_validate(simple_2)
250+
# should be subset of llm_config.to_load_model_kwargs()
251+
kwargs = llm_config.to_load_model_kwargs()
252+
assert "top_p" not in kwargs
253+
assert "temperature" in kwargs
254+
assert kwargs["temperature"] == 0.5
255+
256+
# test only temperature
257+
simple_3 = raw_config.copy()
258+
simple_3["configuration"] = {"temperature": 0.5}
259+
llm_config = LLMConfig.model_validate(simple_3)
260+
kwargs = llm_config.to_load_model_kwargs()
261+
assert "top_p" not in kwargs
262+
assert "temperature" in kwargs
263+
assert kwargs["temperature"] == 0.5
264+
265+
# test only top_p
266+
simple_4 = raw_config.copy()
267+
simple_4["configuration"] = {"top_p": 0.5}
268+
llm_config = LLMConfig.model_validate(simple_4)
269+
kwargs = llm_config.to_load_model_kwargs()
270+
assert "top_p" in kwargs
271+
assert "temperature" not in kwargs
272+
assert kwargs["top_p"] == 0.5
273+
274+
# oap provider
275+
simple_5 = simple_2.copy()
276+
simple_5["modelProvider"] = "oap"
277+
llm_config = LLMConfig.model_validate(simple_5)
278+
kwargs = llm_config.to_load_model_kwargs()
279+
assert "top_p" not in kwargs
280+
assert "temperature" in kwargs
281+
assert kwargs["temperature"] == 0.5
282+
283+
# test general llm config
284+
simple_6 = simple_2.copy()
285+
simple_6["model"] = "gpt-4o"
286+
llm_config = LLMConfig.model_validate(simple_6)
287+
kwargs = llm_config.to_load_model_kwargs()
288+
assert "top_p" in kwargs
289+
assert "temperature" in kwargs
290+
assert kwargs["temperature"] == 0.5
291+
assert kwargs["top_p"] == 0.5
292+
293+
294+
def test_gpt_5_temperature() -> None:
295+
"""Test the GPT-5 temperature."""
296+
raw_config: dict = {
297+
"modelProvider": "openai",
298+
"model": "gpt-5",
299+
}
300+
301+
simple_1 = raw_config.copy()
302+
llm_config = LLMConfig.model_validate(simple_1)
303+
kwargs = llm_config.to_load_model_kwargs()
304+
assert "temperature" not in kwargs
305+
306+
simple_2 = raw_config.copy()
307+
simple_2["configuration"] = {"temperature": 0.5}
308+
llm_config = LLMConfig.model_validate(simple_2)
309+
kwargs = llm_config.to_load_model_kwargs()
310+
assert "temperature" in kwargs
311+
assert kwargs["temperature"] == 1
312+
313+
simple_3 = raw_config.copy()
314+
simple_3["configuration"] = {"temperature": 0}
315+
llm_config = LLMConfig.model_validate(simple_3)
316+
kwargs = llm_config.to_load_model_kwargs()
317+
assert "temperature" not in kwargs
318+
319+
# test oap provider
320+
simple_4 = simple_2.copy()
321+
simple_4["modelProvider"] = "oap"
322+
llm_config = LLMConfig.model_validate(simple_4)
323+
kwargs = llm_config.to_load_model_kwargs()
324+
assert "temperature" in kwargs
325+
assert kwargs["temperature"] == 1
326+
327+
# test general llm config
328+
simple_5 = simple_2.copy()
329+
simple_5["model"] = "gpt-4o"
330+
llm_config = LLMConfig.model_validate(simple_5)
331+
kwargs = llm_config.to_load_model_kwargs()
332+
assert "temperature" in kwargs
333+
assert kwargs["temperature"] == 0.5

0 commit comments

Comments
 (0)