diff --git a/libs/partners/anthropic/langchain_anthropic/chat_models.py b/libs/partners/anthropic/langchain_anthropic/chat_models.py index 9e428296ad6..5795e5eaf08 100644 --- a/libs/partners/anthropic/langchain_anthropic/chat_models.py +++ b/libs/partners/anthropic/langchain_anthropic/chat_models.py @@ -1125,19 +1125,19 @@ class ChatAnthropic(BaseChatModel): "get_num_tokens_from_messages does not yet support counting tokens " "in tool calls." ) - system, messages = _format_messages(messages) - if isinstance(system, str): + formatted_system, formatted_messages = _format_messages(messages) + if isinstance(formatted_system, str): response = self._client.beta.messages.count_tokens( betas=["token-counting-2024-11-01"], model=self.model, - system=system, - messages=messages, + system=formatted_system, + messages=formatted_messages, # type: ignore[arg-type] ) else: response = self._client.beta.messages.count_tokens( betas=["token-counting-2024-11-01"], model=self.model, - messages=messages, + messages=formatted_messages, # type: ignore[arg-type] ) return response.input_tokens diff --git a/libs/partners/anthropic/tests/integration_tests/test_chat_models.py b/libs/partners/anthropic/tests/integration_tests/test_chat_models.py index 5a7a1f780b9..47736880b25 100644 --- a/libs/partners/anthropic/tests/integration_tests/test_chat_models.py +++ b/libs/partners/anthropic/tests/integration_tests/test_chat_models.py @@ -317,7 +317,7 @@ async def test_anthropic_async_streaming_callback() -> None: def test_anthropic_multimodal() -> None: """Test that multimodal inputs are handled correctly.""" chat = ChatAnthropic(model=MODEL_NAME) # type: ignore[call-arg] - messages = [ + messages: list[BaseMessage] = [ HumanMessage( content=[ { diff --git a/libs/partners/anthropic/tests/unit_tests/test_chat_models.py b/libs/partners/anthropic/tests/unit_tests/test_chat_models.py index b37246e986e..dcdf0f10bf1 100644 --- a/libs/partners/anthropic/tests/unit_tests/test_chat_models.py +++ b/libs/partners/anthropic/tests/unit_tests/test_chat_models.py @@ -331,7 +331,7 @@ def dummy_tool() -> BaseTool: arg1: int = Field(..., description="foo") arg2: Literal["bar", "baz"] = Field(..., description="one of 'bar', 'baz'") - class DummyFunction(BaseTool): + class DummyFunction(BaseTool): # type: ignore[override] args_schema: Type[BaseModel] = Schema name: str = "dummy_function" description: str = "dummy function"