Skip to content
Open
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
12 changes: 6 additions & 6 deletions libs/standard-tests/langchain_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class CustomSerializer:
"""

@staticmethod
def serialize(cassette_dict: dict) -> bytes:
def serialize(cassette_dict: dict[str, Any]) -> bytes:
"""Convert cassette to YAML and compress it."""
cassette_dict["requests"] = [
{
Expand All @@ -43,7 +43,7 @@ def serialize(cassette_dict: dict) -> bytes:
return gzip.compress(yml.encode("utf-8"))

@staticmethod
def deserialize(data: bytes) -> dict:
def deserialize(data: bytes) -> dict[str, Any]:
"""Decompress data and convert it from YAML."""
decoded_yaml = gzip.decompress(data).decode("utf-8")
cassette = cast("dict[str, Any]", yaml.safe_load(decoded_yaml))
Expand All @@ -59,7 +59,7 @@ def load_cassette(
cls,
cassette_path: str | PathLike[str],
serializer: CustomSerializer,
) -> tuple[dict, dict]:
) -> tuple[list[Any], list[Any]]:
"""Load a cassette from a file."""
# If cassette path is already Path this is a no-op
cassette_path = Path(cassette_path)
Expand All @@ -74,7 +74,7 @@ def load_cassette(
@staticmethod
def save_cassette(
cassette_path: str | PathLike[str],
cassette_dict: dict,
cassette_dict: dict[str, Any],
serializer: CustomSerializer,
) -> None:
"""Save a cassette to a file."""
Expand All @@ -99,7 +99,7 @@ def save_cassette(


@pytest.fixture(scope="session")
def _base_vcr_config() -> dict:
def _base_vcr_config() -> dict[str, Any]:
"""Return VCR configuration that every cassette will receive.

(Anything permitted by `vcr.VCR(**kwargs)` can be put here.)
Expand All @@ -116,6 +116,6 @@ def _base_vcr_config() -> dict:


@pytest.fixture(scope="session")
def vcr_config(_base_vcr_config: dict) -> dict:
def vcr_config(_base_vcr_config: dict[str, Any]) -> dict[str, Any]:
"""VCR config fixture."""
return _base_vcr_config
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def validate_joke_dict(result: Any) -> bool:


class _TestCallbackHandler(BaseCallbackHandler):
options: list[dict | None]
options: list[dict[str, Any] | None]

def __init__(self) -> None:
super().__init__()
Expand Down Expand Up @@ -761,7 +761,7 @@ def pytest_recording_configure(config: dict, vcr: VCR) -> None:
''' # noqa: E501

@property
def standard_chat_model_params(self) -> dict:
def standard_chat_model_params(self) -> dict[str, Any]:
"""Standard parameters for chat model."""
return {}

Expand Down Expand Up @@ -2962,7 +2962,7 @@ def supports_anthropic_inputs(self) -> bool:
"cache_control": {"type": "ephemeral"},
}

human_content: list[dict] = [
human_content = [
{
"type": "text",
"text": "what's your favorite color in this image",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Integration tests for retrievers."""

from abc import abstractmethod
from typing import Any

import pytest
from langchain_core.documents import Document
Expand All @@ -19,7 +20,7 @@ def retriever_constructor(self) -> type[BaseRetriever]:
...

@property
def retriever_constructor_params(self) -> dict:
def retriever_constructor_params(self) -> dict[str, Any]:
"""Returns a dictionary of parameters to pass to the retriever constructor."""
return {}

Expand Down
12 changes: 7 additions & 5 deletions libs/standard-tests/langchain_tests/unit_tests/chat_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ def chat_model_class(self) -> type[BaseChatModel]:
...

@property
def chat_model_params(self) -> dict:
def chat_model_params(self) -> dict[str, Any]:
"""Initialization parameters for the chat model."""
return {}

@property
def standard_chat_model_params(self) -> dict:
def standard_chat_model_params(self) -> dict[str, Any]:
"""Standard chat model parameters."""
return {
"temperature": 0,
Expand Down Expand Up @@ -117,7 +117,7 @@ def has_structured_output(self) -> bool:
) or self.has_tool_calling

@property
def structured_output_kwargs(self) -> dict:
def structured_output_kwargs(self) -> dict[str, Any]:
"""Additional kwargs to pass to `with_structured_output()` in tests.

Override this property to customize how structured output is generated
Expand Down Expand Up @@ -876,14 +876,16 @@ def init_from_env_params(self) -> Tuple[dict, dict, dict]:
''' # noqa: E501,D214

@property
def standard_chat_model_params(self) -> dict:
def standard_chat_model_params(self) -> dict[str, Any]:
"""Standard chat model parameters."""
params = super().standard_chat_model_params
params["api_key"] = "test"
return params

@property
def init_from_env_params(self) -> tuple[dict, dict, dict]:
def init_from_env_params(
self,
) -> tuple[dict[str, str], dict[str, Any], dict[str, Any]]:
"""Init from env params.

Environment variables, additional initialization args, and expected instance
Expand Down
7 changes: 5 additions & 2 deletions libs/standard-tests/langchain_tests/unit_tests/embeddings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import os
from abc import abstractmethod
from typing import Any
from unittest import mock

import pytest
Expand All @@ -20,7 +21,7 @@ def embeddings_class(self) -> type[Embeddings]:
"""Embeddings class."""

@property
def embedding_model_params(self) -> dict:
def embedding_model_params(self) -> dict[str, Any]:
"""Embeddings model parameters."""
return {}

Expand Down Expand Up @@ -100,7 +101,9 @@ def test_init(self) -> None:
assert model is not None

@property
def init_from_env_params(self) -> tuple[dict, dict, dict]:
def init_from_env_params(
self,
) -> tuple[dict[str, str], dict[str, Any], dict[str, Any]]:
"""Init from env params.

This property is used in unit tests to test initialization from environment
Expand Down
9 changes: 6 additions & 3 deletions libs/standard-tests/langchain_tests/unit_tests/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import os
from abc import abstractmethod
from typing import Any
from unittest import mock

import pytest
Expand All @@ -27,12 +28,12 @@ def tool_constructor(self) -> type[BaseTool] | BaseTool:
...

@property
def tool_constructor_params(self) -> dict:
def tool_constructor_params(self) -> dict[str, Any]:
"""Returns a dictionary of parameters to pass to the tool constructor."""
return {}

@property
def tool_invoke_params_example(self) -> dict:
def tool_invoke_params_example(self) -> dict[str, Any]:
"""Returns a dictionary representing the "args" of an example tool call.

This should NOT be a `ToolCall` dict - it should not have
Expand All @@ -58,7 +59,9 @@ class ToolsUnitTests(ToolsTests):
"""Base class for tools unit tests."""

@property
def init_from_env_params(self) -> tuple[dict, dict, dict]:
def init_from_env_params(
self,
) -> tuple[dict[str, str], dict[str, Any], dict[str, Any]]:
"""Init from env params.

Return env vars, init args, and expected instance attrs for initializing
Expand Down
4 changes: 0 additions & 4 deletions libs/standard-tests/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ strict = true
enable_error_code = "deprecated"
warn_unreachable = true

# TODO: activate for 'strict' checking
disallow_any_generics = false

[[tool.mypy.overrides]]
module = ["vcr.*",]
ignore_missing_imports = true
Expand Down Expand Up @@ -97,7 +94,6 @@ flake8-annotations.allow-star-arg-any = true
flake8-annotations.mypy-init-return = true
flake8-type-checking.runtime-evaluated-base-classes = ["pydantic.BaseModel","langchain_core.load.serializable.Serializable","langchain_core.runnables.base.RunnableSerializable"]
pep8-naming.classmethod-decorators = [ "classmethod", "langchain_core.utils.pydantic.pre_init", "pydantic.field_validator", "pydantic.v1.root_validator",]
pyupgrade.keep-runtime-typing = true

[tool.ruff.lint.pydocstyle]
convention = "google"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def retriever_constructor(self) -> type[ParrotRetriever]:
return ParrotRetriever

@property
def retriever_constructor_params(self) -> dict:
def retriever_constructor_params(self) -> dict[str, Any]:
return {"parrot_name": "Polly"}

@property
Expand Down
14 changes: 7 additions & 7 deletions libs/standard-tests/tests/unit_tests/test_basic_tool.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Literal
from typing import Any, Literal

from langchain_core.tools import BaseTool
from typing_extensions import override
Expand Down Expand Up @@ -36,14 +36,14 @@ def tool_constructor(self) -> type[ParrotMultiplyTool]:
return ParrotMultiplyTool

@property
def tool_constructor_params(self) -> dict:
def tool_constructor_params(self) -> dict[str, Any]:
# if your tool constructor instead required initialization arguments like
# `def __init__(self, some_arg: int):`, you would return those here
# as a dictionary, e.g.: `return {'some_arg': 42}`
return {}

@property
def tool_invoke_params_example(self) -> dict:
def tool_invoke_params_example(self) -> dict[str, Any]:
"""Returns a dictionary representing the "args" of an example tool call.

This should NOT be a ToolCall dict - i.e. it should not
Expand All @@ -58,14 +58,14 @@ def tool_constructor(self) -> type[ParrotMultiplyTool]:
return ParrotMultiplyTool

@property
def tool_constructor_params(self) -> dict:
def tool_constructor_params(self) -> dict[str, Any]:
# if your tool constructor instead required initialization arguments like
# `def __init__(self, some_arg: int):`, you would return those here
# as a dictionary, e.g.: `return {'some_arg': 42}`
return {}

@property
def tool_invoke_params_example(self) -> dict:
def tool_invoke_params_example(self) -> dict[str, Any]:
"""Returns a dictionary representing the "args" of an example tool call.

This should NOT be a ToolCall dict - i.e. it should not
Expand All @@ -80,14 +80,14 @@ def tool_constructor(self) -> type[ParrotMultiplyArtifactTool]:
return ParrotMultiplyArtifactTool

@property
def tool_constructor_params(self) -> dict:
def tool_constructor_params(self) -> dict[str, Any]:
# if your tool constructor instead required initialization arguments like
# `def __init__(self, some_arg: int):`, you would return those here
# as a dictionary, e.g.: `return {'some_arg': 42}`
return {}

@property
def tool_invoke_params_example(self) -> dict:
def tool_invoke_params_example(self) -> dict[str, Any]:
"""Returns a dictionary representing the "args" of an example tool call.

This should NOT be a ToolCall dict - i.e. it should not
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Any

import pytest

Expand All @@ -21,7 +21,7 @@ def chat_model_class(self) -> type[ChatParrotLink]:
return ChatParrotLink

@property
def chat_model_params(self) -> dict:
def chat_model_params(self) -> dict[str, Any]:
return {"model": "bird-brain-001", "temperature": 0, "parrot_buffer_length": 50}


Expand All @@ -31,7 +31,7 @@ def chat_model_class(self) -> type[ChatParrotLink]:
return ChatParrotLink

@property
def chat_model_params(self) -> dict:
def chat_model_params(self) -> dict[str, Any]:
return {"model": "bird-brain-001", "temperature": 0, "parrot_buffer_length": 50}

@pytest.mark.xfail(reason="ChatParrotLink doesn't implement bind_tools method")
Expand Down
6 changes: 4 additions & 2 deletions libs/standard-tests/tests/unit_tests/test_decorated_tool.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Any

from langchain_core.tools import BaseTool, tool

from langchain_tests.integration_tests import ToolsIntegrationTests
Expand All @@ -16,7 +18,7 @@ def tool_constructor(self) -> BaseTool:
return parrot_multiply_tool

@property
def tool_invoke_params_example(self) -> dict:
def tool_invoke_params_example(self) -> dict[str, Any]:
"""Returns a dictionary representing the "args" of an example tool call.

This should NOT be a ToolCall dict - i.e. it should not
Expand All @@ -31,7 +33,7 @@ def tool_constructor(self) -> BaseTool:
return parrot_multiply_tool

@property
def tool_invoke_params_example(self) -> dict:
def tool_invoke_params_example(self) -> dict[str, Any]:
"""Returns a dictionary representing the "args" of an example tool call.

This should NOT be a ToolCall dict - i.e. it should not
Expand Down
6 changes: 4 additions & 2 deletions libs/standard-tests/tests/unit_tests/test_embeddings.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Any

from langchain_core.embeddings import DeterministicFakeEmbedding, Embeddings

from langchain_tests.integration_tests import EmbeddingsIntegrationTests
Expand All @@ -10,7 +12,7 @@ def embeddings_class(self) -> type[Embeddings]:
return DeterministicFakeEmbedding

@property
def embedding_model_params(self) -> dict:
def embedding_model_params(self) -> dict[str, Any]:
return {"size": 6} # embedding dimension


Expand All @@ -20,5 +22,5 @@ def embeddings_class(self) -> type[Embeddings]:
return DeterministicFakeEmbedding

@property
def embedding_model_params(self) -> dict:
def embedding_model_params(self) -> dict[str, Any]:
return {"size": 6}
Loading