From 310e643842961d1cbe30caca2e535a0167467626 Mon Sep 17 00:00:00 2001 From: Bagatur <22008038+baskaryan@users.noreply.github.com> Date: Tue, 3 Jun 2025 10:38:11 -0400 Subject: [PATCH] release[anthropic]: 0.3.15 (#31479) Co-authored-by: Eugene Yurtsev --- libs/partners/anthropic/pyproject.toml | 2 +- .../integration_tests/test_chat_models.py | 27 ++++++++++++++----- .../tests/integration_tests/test_standard.py | 7 +++-- libs/partners/anthropic/uv.lock | 3 ++- 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/libs/partners/anthropic/pyproject.toml b/libs/partners/anthropic/pyproject.toml index ae3a0d3fe95..be236e4b89a 100644 --- a/libs/partners/anthropic/pyproject.toml +++ b/libs/partners/anthropic/pyproject.toml @@ -12,7 +12,7 @@ dependencies = [ "pydantic<3.0.0,>=2.7.4", ] name = "langchain-anthropic" -version = "0.3.14" +version = "0.3.15" description = "An integration package connecting AnthropicMessages and LangChain" readme = "README.md" 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 de3e453af0b..46e95e6ea31 100644 --- a/libs/partners/anthropic/tests/integration_tests/test_chat_models.py +++ b/libs/partners/anthropic/tests/integration_tests/test_chat_models.py @@ -3,7 +3,7 @@ import json import os from base64 import b64encode -from typing import Optional +from typing import Optional, cast import httpx import pytest @@ -42,7 +42,10 @@ def test_stream() -> None: chunks_with_model_name = 0 for token in llm.stream("I'm Pickle Rick"): assert isinstance(token.content, str) - full = token if full is None else full + token + if full is None: + full = cast(BaseMessageChunk, token) + else: + full = full + token assert isinstance(token, AIMessageChunk) if token.usage_metadata is not None: if token.usage_metadata.get("input_tokens"): @@ -81,7 +84,10 @@ async def test_astream() -> None: chunks_with_output_token_counts = 0 async for token in llm.astream("I'm Pickle Rick"): assert isinstance(token.content, str) - full = token if full is None else full + token + if full is None: + full = cast(BaseMessageChunk, token) + else: + full = full + token assert isinstance(token, AIMessageChunk) if token.usage_metadata is not None: if token.usage_metadata.get("input_tokens"): @@ -697,7 +703,10 @@ def test_citations() -> None: # Test streaming full: Optional[BaseMessageChunk] = None for chunk in llm.stream(messages): - full = chunk if full is None else full + chunk + if full is None: + full = cast(BaseMessageChunk, chunk) + else: + full = full + chunk assert isinstance(full, AIMessageChunk) assert isinstance(full.content, list) assert any("citations" in block for block in full.content) @@ -722,7 +731,10 @@ def test_thinking() -> None: # Test streaming full: Optional[BaseMessageChunk] = None for chunk in llm.stream("Hello"): - full = chunk if full is None else full + chunk + if full is None: + full = cast(BaseMessageChunk, chunk) + else: + full = full + chunk assert isinstance(full, AIMessageChunk) assert isinstance(full.content, list) assert any("thinking" in block for block in full.content) @@ -756,7 +768,10 @@ def test_redacted_thinking() -> None: # Test streaming full: Optional[BaseMessageChunk] = None for chunk in llm.stream(query): - full = chunk if full is None else full + chunk + if full is None: + full = cast(BaseMessageChunk, chunk) + else: + full = full + chunk assert isinstance(full, AIMessageChunk) assert isinstance(full.content, list) stream_has_reasoning = False diff --git a/libs/partners/anthropic/tests/integration_tests/test_standard.py b/libs/partners/anthropic/tests/integration_tests/test_standard.py index f8c6823bb2d..6f4e3f4f986 100644 --- a/libs/partners/anthropic/tests/integration_tests/test_standard.py +++ b/libs/partners/anthropic/tests/integration_tests/test_standard.py @@ -4,7 +4,7 @@ from pathlib import Path from typing import Literal, cast from langchain_core.language_models import BaseChatModel -from langchain_core.messages import AIMessage +from langchain_core.messages import AIMessage, BaseMessageChunk from langchain_tests.integration_tests import ChatModelIntegrationTests from langchain_anthropic import ChatAnthropic @@ -146,7 +146,10 @@ def _invoke(llm: ChatAnthropic, input_: list, stream: bool) -> AIMessage: if stream: full = None for chunk in llm.stream(input_): - full = full + chunk if full else chunk # type: ignore[operator] + if full is None: + full = cast(BaseMessageChunk, chunk) + else: + full = full + chunk return cast(AIMessage, full) else: return cast(AIMessage, llm.invoke(input_)) diff --git a/libs/partners/anthropic/uv.lock b/libs/partners/anthropic/uv.lock index 60d0f20fd7a..6fb205cdd22 100644 --- a/libs/partners/anthropic/uv.lock +++ b/libs/partners/anthropic/uv.lock @@ -1,4 +1,5 @@ version = 1 +revision = 1 requires-python = ">=3.9" resolution-markers = [ "python_full_version >= '3.13' and platform_python_implementation == 'PyPy'", @@ -423,7 +424,7 @@ wheels = [ [[package]] name = "langchain-anthropic" -version = "0.3.14" +version = "0.3.15" source = { editable = "." } dependencies = [ { name = "anthropic" },