Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions backend/app/llm/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ def __init__(self, model_config: ModelConfig):
self.api_key = api_key
self.model = model_config.model
self.temperature = model_config.temperature
# Reasoning models on some gateways reject the `temperature` parameter
# entirely. Omit it for the Anthropic Messages protocol so those models
# (e.g. Claude Opus 4.8) accept the request; other protocols keep it.
self.request_temperature = (
None
if protocol is ModelApiProtocol.ANTHROPIC_MESSAGES
else self.temperature
)
self.max_output_tokens = model_config.max_output_tokens
legacy_extra_body = getattr(model_config, "legacy_extra_body", {})
protocol_options = getattr(model_config, "protocol_options", {})
Expand Down Expand Up @@ -160,7 +168,7 @@ def generate_text(
request: dict[str, Any] = {
"model": self.model,
"messages": request_messages,
"temperature": self.temperature,
"temperature": self.request_temperature,
"max_tokens": max_output_tokens,
}
if cancellation is not None:
Expand Down Expand Up @@ -290,7 +298,7 @@ def generate_text_stream(
stream_request = {
"model": self.model,
"messages": request_messages,
"temperature": self.temperature,
"temperature": self.request_temperature,
"max_tokens": current_max_tokens,
**_thinking_request_kwargs(
getattr(self, "thinking_mode", ""),
Expand Down
6 changes: 5 additions & 1 deletion backend/app/llm/protocol_drivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,12 @@ def _anthropic_request(request: dict[str, Any]) -> dict[str, Any]:
"model": request["model"],
"messages": converted,
"max_tokens": request["max_tokens"],
"temperature": request["temperature"],
}
# Some gateways expose reasoning models (e.g. Claude Opus 4.8) that reject the
# `temperature` parameter outright. Only include it when a value is provided.
temperature = request.get("temperature")
if temperature is not None:
payload["temperature"] = temperature
system = "\n\n".join(part for part in system_parts if part)
if system:
payload["system"] = system
Expand Down