Skip to content

Commit 0d7ef9a

Browse files
Userclaude
andcommitted
refactor: simplify LiteLLM client parameter handling
- Remove all model-specific hardcoding except minimal Claude workaround - Always include standard params (temperature, top_p, max_tokens) - Use additional_drop_params for Claude temperature/top_p conflict - Let LiteLLM handle most provider differences via drop_params=True - Add comment noting this is a temporary workaround for LiteLLM bug 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 6485c03 commit 0d7ef9a

1 file changed

Lines changed: 10 additions & 14 deletions

File tree

ace/llm_providers/litellm_client.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -217,18 +217,16 @@ def complete(self, prompt: str, **kwargs: Any) -> LLMResponse:
217217
"messages": messages,
218218
"temperature": kwargs.get("temperature", self.config.temperature),
219219
"max_tokens": kwargs.get("max_tokens", self.config.max_tokens),
220+
"top_p": kwargs.get("top_p", self.config.top_p),
220221
"timeout": kwargs.get("timeout", self.config.timeout),
221222
"num_retries": kwargs.get("num_retries", self.config.max_retries),
222223
"drop_params": True, # Automatically drop unsupported parameters
223224
}
224225

225-
# Only add top_p if temperature is not set (for Anthropic compatibility)
226-
if self.config.temperature == 0.0 and kwargs.get("temperature", 0.0) == 0.0:
227-
call_params["top_p"] = kwargs.get("top_p", self.config.top_p)
228-
229-
# Force JSON response for models that support it
230-
if "gpt" in self.config.model.lower() and "json" in prompt.lower():
231-
call_params["response_format"] = {"type": "json_object"}
226+
# Work around LiteLLM bug: explicitly drop top_p for Claude when temperature is set
227+
# This can be removed once LiteLLM properly handles this with drop_params
228+
if "claude" in self.config.model.lower() and call_params["temperature"] > 0:
229+
call_params["additional_drop_params"] = ["top_p"]
232230

233231
# Add API key if available
234232
if self.config.api_key:
@@ -294,18 +292,16 @@ async def acomplete(self, prompt: str, **kwargs: Any) -> LLMResponse:
294292
"messages": messages,
295293
"temperature": kwargs.get("temperature", self.config.temperature),
296294
"max_tokens": kwargs.get("max_tokens", self.config.max_tokens),
295+
"top_p": kwargs.get("top_p", self.config.top_p),
297296
"timeout": kwargs.get("timeout", self.config.timeout),
298297
"num_retries": kwargs.get("num_retries", self.config.max_retries),
299298
"drop_params": True, # Automatically drop unsupported parameters
300299
}
301300

302-
# Only add top_p if temperature is not set (for Anthropic compatibility)
303-
if self.config.temperature == 0.0 and kwargs.get("temperature", 0.0) == 0.0:
304-
call_params["top_p"] = kwargs.get("top_p", self.config.top_p)
305-
306-
# Force JSON response for models that support it
307-
if "gpt" in self.config.model.lower() and "json" in prompt.lower():
308-
call_params["response_format"] = {"type": "json_object"}
301+
# Work around LiteLLM bug: explicitly drop top_p for Claude when temperature is set
302+
# This can be removed once LiteLLM properly handles this with drop_params
303+
if "claude" in self.config.model.lower() and call_params["temperature"] > 0:
304+
call_params["additional_drop_params"] = ["top_p"]
309305

310306
# Add API key if available
311307
if self.config.api_key:

0 commit comments

Comments
 (0)