Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

anthropic[patch]: update models for integration tests #29938

Merged
merged 9 commits into from
Feb 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libs/partners/anthropic/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ TEST_FILE ?= tests/unit_tests/
integration_test integration_tests: TEST_FILE=tests/integration_tests/

test tests:
uv run --group test pytest -vvv --timeout 30 --disable-socket --allow-unix-socket $(TEST_FILE)
uv run --group test pytest -vvv --disable-socket --allow-unix-socket $(TEST_FILE)

integration_test integration_tests:
uv run --group test --group test_integration pytest -vvv --timeout 30 $(TEST_FILE)
Expand Down
37 changes: 20 additions & 17 deletions libs/partners/anthropic/tests/integration_tests/test_chat_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
from langchain_anthropic import ChatAnthropic, ChatAnthropicMessages
from tests.unit_tests._utils import FakeCallbackHandler

MODEL_NAME = "claude-3-5-sonnet-20240620"
MODEL_NAME = "claude-3-5-haiku-latest"
IMAGE_MODEL_NAME = "claude-3-5-sonnet-latest"


def test_stream() -> None:
Expand Down Expand Up @@ -98,22 +99,10 @@ async def test_astream() -> None:
assert "stop_reason" in full.response_metadata
assert "stop_sequence" in full.response_metadata

# test usage metadata can be excluded
model = ChatAnthropic(model_name=MODEL_NAME, stream_usage=False) # type: ignore[call-arg]
async for token in model.astream("hi"):
assert isinstance(token, AIMessageChunk)
assert token.usage_metadata is None
# check we override with kwarg
model = ChatAnthropic(model_name=MODEL_NAME) # type: ignore[call-arg]
assert model.stream_usage
async for token in model.astream("hi", stream_usage=False):
assert isinstance(token, AIMessageChunk)
assert token.usage_metadata is None

# Check expected raw API output
async_client = model._async_client
async_client = llm._async_client
params: dict = {
"model": "claude-3-haiku-20240307",
"model": MODEL_NAME,
"max_tokens": 1024,
"messages": [{"role": "user", "content": "hi"}],
"temperature": 0.0,
Expand All @@ -132,6 +121,20 @@ async def test_astream() -> None:
pass


async def test_stream_usage() -> None:
"""Test usage metadata can be excluded."""
model = ChatAnthropic(model_name=MODEL_NAME, stream_usage=False) # type: ignore[call-arg]
async for token in model.astream("hi"):
assert isinstance(token, AIMessageChunk)
assert token.usage_metadata is None
# check we override with kwarg
model = ChatAnthropic(model_name=MODEL_NAME) # type: ignore[call-arg]
assert model.stream_usage
async for token in model.astream("hi", stream_usage=False):
assert isinstance(token, AIMessageChunk)
assert token.usage_metadata is None


async def test_abatch() -> None:
"""Test streaming tokens from ChatAnthropicMessages."""
llm = ChatAnthropicMessages(model_name=MODEL_NAME) # type: ignore[call-arg, call-arg]
Expand Down Expand Up @@ -318,7 +321,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)
chat = ChatAnthropic(model=IMAGE_MODEL_NAME)
messages: list[BaseMessage] = [
HumanMessage(
content=[
Expand Down Expand Up @@ -602,7 +605,7 @@ def test_pdf_document_input() -> None:
url = "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"
data = b64encode(requests.get(url).content).decode()

result = ChatAnthropic(model=MODEL_NAME).invoke(
result = ChatAnthropic(model=IMAGE_MODEL_NAME).invoke(
[
HumanMessage(
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def chat_model_class(self) -> Type[BaseChatModel]:

@property
def chat_model_params(self) -> dict:
return {"model": "claude-3-haiku-20240307"}
return {"model": "claude-3-5-sonnet-latest"}

@property
def supports_image_inputs(self) -> bool:
Expand Down
Loading