Clamp Anthropic temperature to [0.0, 1.0] in _build_anthropic_payload (#1737)
Anthropic's Messages API rejects temperature > 1.0 with HTTP 400, but _build_anthropic_payload forwarded it verbatim. The shipped "Nietzsche" preset uses temperature 1.2 and the UI slider allows up to 2.0, so every Claude request under such a preset hard-broke. Clamp into [0.0, 1.0] in the Anthropic builder only (OpenAI keeps its wider 0.0-2.0 range). Covers all three Anthropic call paths, which build through this one function. None is passed through unchanged. Fixes #1615 Co-authored-by: Ethan <23321960+0xLeathery@users.noreply.github.com>
This commit is contained in:
@@ -512,6 +512,12 @@ def _build_anthropic_payload(model, messages, temperature, max_tokens, stream=Fa
|
||||
# Convert multimodal content (image_url → image) for Anthropic
|
||||
content = _convert_openai_content_to_anthropic(m["content"])
|
||||
chat_messages.append({"role": m["role"], "content": content})
|
||||
# Anthropic only accepts temperature in [0.0, 1.0] and 400s on anything above
|
||||
# 1.0. Clamp here (in the Anthropic builder only) so presets/sliders that use
|
||||
# the wider OpenAI 0.0-2.0 range — e.g. the shipped "Nietzsche" preset at 1.2
|
||||
# — don't hard-break every Claude request. OpenAI's own path is left untouched.
|
||||
if temperature is not None:
|
||||
temperature = max(0.0, min(temperature, 1.0))
|
||||
payload = {
|
||||
"model": model,
|
||||
"messages": chat_messages,
|
||||
|
||||
Reference in New Issue
Block a user