From 8b40258e72fdb2fb6dd22d6e080e18c34f7b576c Mon Sep 17 00:00:00 2001 From: Mason Daugherty Date: Wed, 16 Jul 2025 11:03:32 -0400 Subject: [PATCH] fix: update `response_metadata` to use correct `model` attribute --- .../langchain_tests/unit_tests/chat_models.py | 8 ++++---- libs/standard-tests/tests/unit_tests/custom_chat_model.py | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libs/standard-tests/langchain_tests/unit_tests/chat_models.py b/libs/standard-tests/langchain_tests/unit_tests/chat_models.py index 6466c8974fe..b6c7e27e0f4 100644 --- a/libs/standard-tests/langchain_tests/unit_tests/chat_models.py +++ b/libs/standard-tests/langchain_tests/unit_tests/chat_models.py @@ -837,8 +837,8 @@ class ChatModelUnitTests(ChatModelTests): assert model is not None def test_model_param_name(self) -> None: - """Tests model initialization with a ``model=`` parameter. This should pass for all - integrations. + """Tests model initialization with a ``model=`` parameter. This should pass for + all integrations. .. dropdown:: Troubleshooting @@ -851,7 +851,7 @@ class ChatModelUnitTests(ChatModelTests): ``model_config`` class attribute to your model class: .. code-block:: python - + class MyChatModel(BaseChatModel): model: str = Field(alias="model_name") model_config = ConfigDict(populate_by_name=True) @@ -873,7 +873,7 @@ class ChatModelUnitTests(ChatModelTests): model = self.chat_model_class(**params) assert model is not None - assert model.model == params["model"] + assert model.model == params["model"] # type: ignore[attr-defined] def test_init_from_env(self) -> None: """Test initialization from environment variables. Relies on the diff --git a/libs/standard-tests/tests/unit_tests/custom_chat_model.py b/libs/standard-tests/tests/unit_tests/custom_chat_model.py index fb1a6f0d597..3a9475a60ef 100644 --- a/libs/standard-tests/tests/unit_tests/custom_chat_model.py +++ b/libs/standard-tests/tests/unit_tests/custom_chat_model.py @@ -81,7 +81,7 @@ class ChatParrotLink(BaseChatModel): additional_kwargs={}, # Used to add additional payload to the message response_metadata={ # Use for response metadata "time_in_seconds": 3, - "model_name": self.model_name, + "model_name": self.model, }, usage_metadata={ "input_tokens": ct_input_tokens, @@ -146,7 +146,7 @@ class ChatParrotLink(BaseChatModel): chunk = ChatGenerationChunk( message=AIMessageChunk( content="", - response_metadata={"time_in_sec": 3, "model_name": self.model_name}, + response_metadata={"time_in_sec": 3, "model_name": self.model}, ) ) if run_manager: