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:
parent
2326e30263
commit
7e267b95f8
1 changed files with 16 additions and 9 deletions
|
|
@ -214,15 +214,22 @@ class AnthropicClient(LLMClient):
|
||||||
try:
|
try:
|
||||||
# Create the appropriate tool based on whether response_model is provided
|
# Create the appropriate tool based on whether response_model is provided
|
||||||
tools, tool_choice = self._create_tool(response_model)
|
tools, tool_choice = self._create_tool(response_model)
|
||||||
result = await self.client.messages.create(
|
|
||||||
system=system_message.content,
|
# Build the message creation parameters
|
||||||
max_tokens=max_creation_tokens,
|
create_params: dict[str, typing.Any] = {
|
||||||
temperature=self.temperature,
|
'system': system_message.content,
|
||||||
messages=user_messages_cast,
|
'max_tokens': max_creation_tokens,
|
||||||
model=self.model,
|
'messages': user_messages_cast,
|
||||||
tools=tools,
|
'model': self.model,
|
||||||
tool_choice=tool_choice,
|
'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
|
# Extract the tool output from the response
|
||||||
for content_item in result.content:
|
for content_item in result.content:
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue