mirror of
https://github.com/hwchase17/langchain.git
synced 2026-03-18 11:07:36 +00:00
Add a first-party `langchain-openrouter` partner package (`ChatOpenRouter`) that wraps the official `openrouter` Python SDK, providing native support for OpenRouter-specific features that `ChatOpenAI` intentionally does not handle. Also adds scope-clarifying docstrings to `ChatOpenAI` / `BaseChatOpenAI` warning users away from using `base_url` overrides with third-party providers. --- Closes #31325 Closes #32967 Closes #32977 Closes #32981 Closes #33643 Closes #33757 Closes #34056 Closes #34797 Closes #34962 Supersedes #33902, #34867 (thank you @elonfeng and @okamototk for your initial work on this!) --- Bugs with upstream sdk: - https://github.com/OpenRouterTeam/python-sdk/issues/38 - https://github.com/OpenRouterTeam/python-sdk/issues/51 - https://github.com/OpenRouterTeam/python-sdk/issues/52
40 lines
1.2 KiB
Python
40 lines
1.2 KiB
Python
"""Conftest for OpenRouter tests."""
|
|
|
|
from typing import Any
|
|
|
|
import pytest
|
|
from langchain_tests.conftest import CustomPersister, CustomSerializer, base_vcr_config
|
|
from vcr import VCR # type: ignore[import-untyped]
|
|
|
|
|
|
def remove_request_headers(request: Any) -> Any:
|
|
"""Redact all request headers to avoid leaking secrets."""
|
|
for k in request.headers:
|
|
request.headers[k] = "**REDACTED**"
|
|
return request
|
|
|
|
|
|
def remove_response_headers(response: dict) -> dict:
|
|
"""Redact all response headers."""
|
|
for k in response["headers"]:
|
|
response["headers"][k] = "**REDACTED**"
|
|
return response
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def vcr_config() -> dict:
|
|
"""Extend the default configuration coming from langchain_tests."""
|
|
config = base_vcr_config()
|
|
config["before_record_request"] = remove_request_headers
|
|
config["before_record_response"] = remove_response_headers
|
|
config["serializer"] = "yaml.gz"
|
|
config["path_transformer"] = VCR.ensure_suffix(".yaml.gz")
|
|
|
|
return config
|
|
|
|
|
|
def pytest_recording_configure(config: dict, vcr: VCR) -> None: # noqa: ARG001
|
|
"""Register custom VCR persister and serializer."""
|
|
vcr.register_persister(CustomPersister())
|
|
vcr.register_serializer("yaml.gz", CustomSerializer())
|