This commit is contained in:
Chester Curme 2024-11-05 11:17:44 -05:00
parent caed4e4ce8
commit 5fc4ec6bc9
3 changed files with 7 additions and 7 deletions

View File

@ -1125,19 +1125,19 @@ class ChatAnthropic(BaseChatModel):
"get_num_tokens_from_messages does not yet support counting tokens " "get_num_tokens_from_messages does not yet support counting tokens "
"in tool calls." "in tool calls."
) )
system, messages = _format_messages(messages) formatted_system, formatted_messages = _format_messages(messages)
if isinstance(system, str): if isinstance(formatted_system, str):
response = self._client.beta.messages.count_tokens( response = self._client.beta.messages.count_tokens(
betas=["token-counting-2024-11-01"], betas=["token-counting-2024-11-01"],
model=self.model, model=self.model,
system=system, system=formatted_system,
messages=messages, messages=formatted_messages, # type: ignore[arg-type]
) )
else: else:
response = self._client.beta.messages.count_tokens( response = self._client.beta.messages.count_tokens(
betas=["token-counting-2024-11-01"], betas=["token-counting-2024-11-01"],
model=self.model, model=self.model,
messages=messages, messages=formatted_messages, # type: ignore[arg-type]
) )
return response.input_tokens return response.input_tokens

View File

@ -317,7 +317,7 @@ async def test_anthropic_async_streaming_callback() -> None:
def test_anthropic_multimodal() -> None: def test_anthropic_multimodal() -> None:
"""Test that multimodal inputs are handled correctly.""" """Test that multimodal inputs are handled correctly."""
chat = ChatAnthropic(model=MODEL_NAME) # type: ignore[call-arg] chat = ChatAnthropic(model=MODEL_NAME) # type: ignore[call-arg]
messages = [ messages: list[BaseMessage] = [
HumanMessage( HumanMessage(
content=[ content=[
{ {

View File

@ -331,7 +331,7 @@ def dummy_tool() -> BaseTool:
arg1: int = Field(..., description="foo") arg1: int = Field(..., description="foo")
arg2: Literal["bar", "baz"] = Field(..., description="one of 'bar', 'baz'") arg2: Literal["bar", "baz"] = Field(..., description="one of 'bar', 'baz'")
class DummyFunction(BaseTool): class DummyFunction(BaseTool): # type: ignore[override]
args_schema: Type[BaseModel] = Schema args_schema: Type[BaseModel] = Schema
name: str = "dummy_function" name: str = "dummy_function"
description: str = "dummy function" description: str = "dummy function"