Fix Anthropic client temperature type error

Fixed pyright type error where temperature parameter (float | None) was being passed directly to Anthropic's messages.create() method which expects (float | Omit).

Changes:
- Build message creation parameters as a dictionary
- Conditionally include temperature only when not None
- Use dictionary unpacking to pass parameters

This allows temperature to be properly omitted when None, rather than passing None as a value.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Daniel Chalef 2025-10-30 16:22:06 -07:00
parent 2326e30263
commit 7e267b95f8

View file

@ -214,15 +214,22 @@ class AnthropicClient(LLMClient):
try:
# Create the appropriate tool based on whether response_model is provided
tools, tool_choice = self._create_tool(response_model)
result = await self.client.messages.create(
system=system_message.content,
max_tokens=max_creation_tokens,
temperature=self.temperature,
messages=user_messages_cast,
model=self.model,
tools=tools,
tool_choice=tool_choice,
)
# Build the message creation parameters
create_params: dict[str, typing.Any] = {
'system': system_message.content,
'max_tokens': max_creation_tokens,
'messages': user_messages_cast,
'model': self.model,
'tools': tools,
'tool_choice': tool_choice,
}
# Only include temperature if it's not None
if self.temperature is not None:
create_params['temperature'] = self.temperature
result = await self.client.messages.create(**create_params)
# Extract the tool output from the response
for content_item in result.content: