From 85403bfa9971f28c8fe76af03315dc9f3c48732b Mon Sep 17 00:00:00 2001 From: ccurme Date: Fri, 3 Jan 2025 14:38:53 -0500 Subject: [PATCH] core[patch]: substantially speed up @deprecated (#29016) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Resolves https://github.com/langchain-ai/langchain/issues/26918 Unit tests don't raise any additional `LangChainDeprecationWarning`. Would like guidance on how to test this more thoroughly if needed. Note: speed up for `bind_tools` path is shown below. This is **redundant** with the speedup in https://github.com/langchain-ai/langchain/pull/29015. I include it for demonstration purposes. Before: ![Screenshot 2025-01-03 at 12 54 50 PM](https://github.com/user-attachments/assets/87f289eb-4cad-4304-85f7-5c58c59080f1) After: ![Screenshot 2025-01-03 at 12 55 35 PM](https://github.com/user-attachments/assets/95ad0506-e1d1-4c5c-bb27-6a634d8810c9) --- libs/core/langchain_core/_api/internal.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/libs/core/langchain_core/_api/internal.py b/libs/core/langchain_core/_api/internal.py index 0dca40ad668..e5ef4300ff6 100644 --- a/libs/core/langchain_core/_api/internal.py +++ b/libs/core/langchain_core/_api/internal.py @@ -14,10 +14,9 @@ def is_caller_internal(depth: int = 2) -> bool: frame = frame.f_back if frame is None: return False - caller_module = inspect.getmodule(frame) - if caller_module is None: - return False - caller_module_name = caller_module.__name__ + # Directly access the module name from the frame's global variables + module_globals = frame.f_globals + caller_module_name = module_globals.get("__name__", "") return caller_module_name.startswith("langchain") finally: del frame