Skip to content

Commit e09abf8

Browse files
authored
anthropic[patch]: add benchmark (#31718)
Account for lazy loading of clients in init time benchmark
1 parent 9164e6f commit e09abf8

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

libs/partners/anthropic/tests/unit_tests/test_standard.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
"""Standard LangChain interface tests"""
22

3+
import pytest
34
from langchain_core.language_models import BaseChatModel
45
from langchain_tests.unit_tests import ChatModelUnitTests
6+
from pytest_benchmark.fixture import BenchmarkFixture # type: ignore[import-untyped]
57

68
from langchain_anthropic import ChatAnthropic
79

@@ -14,3 +16,16 @@ def chat_model_class(self) -> type[BaseChatModel]:
1416
@property
1517
def chat_model_params(self) -> dict:
1618
return {"model": "claude-3-haiku-20240307"}
19+
20+
21+
@pytest.mark.benchmark
22+
def test_init_time_with_client(benchmark: BenchmarkFixture) -> None:
23+
"""Test initialization time, accounting for lazy loading of client."""
24+
25+
def _init_in_loop_with_clients() -> None:
26+
for _ in range(10):
27+
llm = ChatAnthropic(model="claude-3-5-haiku-latest")
28+
_ = llm._client
29+
_ = llm._async_client
30+
31+
benchmark(_init_in_loop_with_clients)

0 commit comments

Comments
 (0)