Compare commits

...

52 Commits

Author SHA1 Message Date
Sydney Runkle
722c1fbf6e Merge branch 'master' into sr/init_multiple_times 2025-05-29 11:27:37 -04:00
Sydney Runkle
0098f0c953 init in loop 2025-05-29 11:26:32 -04:00
Sydney Runkle
dcad123c31 benchmarks name 2025-05-29 11:09:15 -04:00
Sydney Runkle
dd29d34939 rename codspeed actions 2025-05-29 11:05:12 -04:00
Chester Curme
615239ff6f Merge branch 'cc/benchmarks' of github.com:langchain-ai/langchain into cc/benchmarks 2025-05-29 10:59:09 -04:00
Chester Curme
5e2a456b18 redact all headers 2025-05-29 10:58:59 -04:00
Sydney Runkle
65e78374ad Merge branch 'cc/benchmarks' of https://github.com/langchain-ai/langchain into cc/benchmarks 2025-05-29 10:10:25 -04:00
Sydney Runkle
064c00e641 working dir oops 2025-05-29 10:10:18 -04:00
Chester Curme
87847dd912 Merge branch 'cc/benchmarks' of github.com:langchain-ai/langchain into cc/benchmarks 2025-05-29 10:09:01 -04:00
Chester Curme
429ee7d035 add command to makefile 2025-05-29 10:08:12 -04:00
Sydney Runkle
7cfb6a6d6a set codspeed output whoops 2025-05-29 10:07:35 -04:00
Sydney Runkle
f08e4f1274 set codspeed output whoops 2025-05-29 10:06:57 -04:00
Chester Curme
86879be2fe add option to compress cassettes 2025-05-29 10:04:02 -04:00
Sydney Runkle
5c05e6e5e1 debugging 2025-05-29 10:03:27 -04:00
Sydney Runkle
d01d670308 add conditional 2025-05-29 09:59:51 -04:00
Sydney Runkle
3fddb50df8 tweak input 2025-05-29 09:56:18 -04:00
Sydney Runkle
b6da2d293e uv venv 2025-05-29 09:54:59 -04:00
Sydney Runkle
bfeab8e2b5 using check diffs output 2025-05-29 09:52:44 -04:00
Sydney Runkle
a2988c6f0b remove other codspeed workflow 2025-05-29 09:44:36 -04:00
Sydney Runkle
7c5af3a84b try top level codspeed workflow 2025-05-29 09:39:40 -04:00
Sydney Runkle
0c8bb4381e remove conditional 2025-05-29 09:21:35 -04:00
Chester Curme
f7efd89e70 document vcr tests 2025-05-28 10:56:32 -04:00
Chester Curme
0f2a8961ce update 2025-05-28 09:12:29 -04:00
Chester Curme
f48aa0f200 remove extraneous comments 2025-05-27 16:14:34 -04:00
Chester Curme
53bd808aa5 format 2025-05-27 16:13:10 -04:00
Chester Curme
005897a165 lock 2025-05-27 16:12:42 -04:00
Chester Curme
62d84be951 Merge branch 'master' into cc/benchmarks 2025-05-27 16:09:27 -04:00
Chester Curme
412899b352 fix check_diff script 2025-05-21 10:59:41 -04:00
Chester Curme
bde0bf2569 fixes 2025-05-21 10:53:47 -04:00
Chester Curme
ec6e7d4f29 fixes 2025-05-21 10:23:17 -04:00
Chester Curme
f4480569e2 🦍 2025-05-21 10:13:51 -04:00
Chester Curme
92161763b8 lock core 2025-05-21 09:59:19 -04:00
Chester Curme
6564669a14 lint 2025-05-21 09:58:17 -04:00
Chester Curme
0f4a4c9f86 lock partner packages 2025-05-21 09:56:19 -04:00
Chester Curme
d896b05255 fix codspeed command 2025-05-21 09:54:02 -04:00
Chester Curme
b895a18e6d set some azure env vars 2025-05-21 09:44:43 -04:00
Chester Curme
04f2f6c896 update workflows 2025-05-21 09:30:13 -04:00
Chester Curme
272efba5b9 explicitly enable test 2025-05-21 09:27:16 -04:00
Chester Curme
7285b173b8 update makefiles 2025-05-21 09:26:33 -04:00
Chester Curme
82a7f11c32 temporarily subset integration tests 2025-05-20 14:13:11 -04:00
Chester Curme
be39842019 update 2025-05-20 14:12:57 -04:00
Chester Curme
5e804316c9 lock 2025-05-20 14:04:57 -04:00
Chester Curme
460ee6aa32 rename cassette 2025-05-20 11:34:38 -04:00
Chester Curme
587af4af7c delete image 2025-05-20 11:14:46 -04:00
Chester Curme
15f69254b5 uv lock 2025-05-20 11:13:40 -04:00
Chester Curme
0f28c5ca18 lint 2025-05-20 11:13:16 -04:00
Chester Curme
44bbdab6a6 add conftest for anthropic 2025-05-20 11:12:33 -04:00
Chester Curme
cc102f0593 add cassette for oai 2025-05-19 16:23:06 -04:00
Chester Curme
bd4a96dc50 add conftests 2025-05-19 15:57:26 -04:00
Chester Curme
f504062687 start on pytest-vcr 2025-05-19 15:03:09 -04:00
Chester Curme
0ba7d1f8d9 add simple benchmark for init 2025-05-19 14:10:21 -04:00
Chester Curme
46c08d26c3 add pytest-benchmark and codspeed to standard-test deps 2025-05-19 12:58:09 -04:00

View File

@@ -24,6 +24,7 @@ from pydantic.v1 import (
ValidationError as ValidationErrorV1,
)
from pytest_benchmark.fixture import BenchmarkFixture # type: ignore[import-untyped]
from pytest_benchmark.fixture import BenchmarkFixture # type: ignore[import-untyped]
from syrupy import SnapshotAssertion
from langchain_tests.base import BaseStandardTests
@@ -211,6 +212,16 @@ class ChatModelTests(BaseStandardTests):
"""
return False
@property
def enable_vcr_tests(self) -> bool:
"""(bool) whether to enable VCR tests for the chat model.
.. important::
See ``enable_vcr_tests`` dropdown :class:`above <ChatModelTests>` for more
information.
"""
return False
@property
def supported_usage_metadata_details(
self,
@@ -768,6 +779,151 @@ class ChatModelUnitTests(ChatModelTests):
Makefile commands).
.. dropdown:: enable_vcr_tests
Property controlling whether to enable select tests that rely on
`VCR <https://vcrpy.readthedocs.io/en/latest/>`_ caching of HTTP calls, such
as benchmarking tests.
To enable these tests, follow these steps:
1. Override the ``enable_vcr_tests`` property to return ``True``:
.. code-block:: python
@property
def enable_vcr_tests(self) -> bool:
return True
2. Configure VCR to exclude sensitive headers and other information from cassettes.
.. important::
VCR will by default record authentication headers and other sensitive
information in cassettes. Read below for how to configure what
information is recorded in cassettes.
To add configuration to VCR, add a ``conftest.py`` file to the ``tests/``
directory and implement the ``vcr_config`` fixture there.
``langchain-tests`` excludes the headers ``"authorization"``,
``"x-api-key"``, and ``"api-key"`` from VCR cassettes. To pick up this
configuration, you will need to add ``conftest.py`` as shown below. You can
also exclude additional headers, override the default exclusions, or apply
other customizations to the VCR configuration. See example below:
.. code-block:: python
:caption: tests/conftest.py
import pytest
from langchain_tests.conftest import _base_vcr_config as _base_vcr_config
_EXTRA_HEADERS = [
# Specify additional headers to redact
("user-agent", "PLACEHOLDER"),
]
def remove_response_headers(response: dict) -> dict:
# If desired, remove or modify headers in the response.
response["headers"] = {}
return response
@pytest.fixture(scope="session")
def vcr_config(_base_vcr_config: dict) -> dict: # noqa: F811
\"\"\"Extend the default configuration from langchain_tests.\"\"\"
config = _base_vcr_config.copy()
config.setdefault("filter_headers", []).extend(_EXTRA_HEADERS)
config["before_record_response"] = remove_response_headers
return config
.. dropdown:: Compressing cassettes
``langchain-tests`` includes a custom VCR serializer that compresses
cassettes using gzip. To use it, register the ``"yaml.gz"`` serializer
to your VCR fixture and enable this serializer in the config. See
example below:
.. code-block:: python
:caption: tests/conftest.py
import pytest
from langchain_tests.conftest import YamlGzipSerializer
from langchain_tests.conftest import _base_vcr_config as _base_vcr_config
from vcr import VCR
_EXTRA_HEADERS = [
# Specify additional headers to redact
("user-agent", "PLACEHOLDER"),
]
def remove_response_headers(response: dict) -> dict:
# If desired, remove or modify headers in the response.
response["headers"] = {}
return response
@pytest.fixture(scope="session")
def vcr_config(_base_vcr_config: dict) -> dict: # noqa: F811
\"\"\"Extend the default configuration from langchain_tests.\"\"\"
config = _base_vcr_config.copy()
config.setdefault("filter_headers", []).extend(_EXTRA_HEADERS)
config["before_record_response"] = remove_response_headers
# New: enable serializer and set file extension
config["serializer"] = "yaml.gz"
config["path_transformer"] = VCR.ensure_suffix(".yaml.gz")
return config
@pytest.fixture
def vcr(vcr_config: dict) -> VCR:
\"\"\"Override the default vcr fixture to include custom serializers\"\"\"
my_vcr = VCR(**vcr_config)
my_vcr.register_serializer("yaml.gz", YamlGzipSerializer)
return my_vcr
You can inspect the contents of the compressed cassettes (e.g., to
ensure no sensitive information is recorded) using the serializer:
.. code-block:: python
from langchain_tests.conftest import YamlGzipSerializer
with open("/path/to/tests/cassettes/TestClass_test.yaml.gz", "r") as f:
data = f.read()
YamlGzipSerializer.deserialize(data)
3. Run tests to generate VCR cassettes.
Example:
.. code-block:: bash
uv run python -m pytest tests/integration_tests/test_chat_models.py::TestMyModel::test_stream_time
This will generate a VCR cassette for the test in
``tests/integration_tests/cassettes/``.
.. important::
You should inspect the generated cassette to ensure that it does not
contain sensitive information. If it does, you can modify the
``vcr_config`` fixture to exclude headers or modify the response
before it is recorded.
You can then commit the cassette to your repository. Subsequent test runs
will use the cassette instead of making HTTP calls.
.. tip::
Adding ``--vcr-record=none`` to the pytest command will ensure that
no new cassettes are recorded, and only existing cassettes are used.
Consider adding this to your CI configuration (e.g., modify relevant
Makefile commands).
Testing initialization from environment variables
Some unit tests may require testing initialization from environment variables.
These tests can be enabled by overriding the ``init_from_env_params``
@@ -1012,4 +1168,7 @@ class ChatModelUnitTests(ChatModelTests):
"""Test initialization time of the chat model. If this test fails, check that
we are not introducing undue overhead in the model's initialization.
"""
_ = benchmark(self.chat_model_class, **self.chat_model_params)
def _init_in_loop() -> None:
for _ in range(10):
self.chat_model_class(**self.chat_model_params)
benchmark(_init_in_loop)