From 04bc5f3b1807af6d13d781d1edf7b11427ebb008 Mon Sep 17 00:00:00 2001 From: Eugene Yurtsev Date: Mon, 14 Aug 2023 11:26:45 -0400 Subject: [PATCH] Conditionally add pydantic v1 to namespace (#9202) Conditionally add pydantic_v1 to namespace. --- libs/langchain/langchain/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libs/langchain/langchain/__init__.py b/libs/langchain/langchain/__init__.py index fe82bc343f..04f7e4cae9 100644 --- a/libs/langchain/langchain/__init__.py +++ b/libs/langchain/langchain/__init__.py @@ -21,7 +21,11 @@ try: except ImportError: pydantic_v1 = importlib.import_module("pydantic") -sys.modules["pydantic_v1"] = pydantic_v1 +if "pydantic_v1" not in sys.modules: + # Use a conditional because langchain experimental + # will use the same strategy to add pydantic_v1 to sys.modules + # and may run prior to langchain core package. + sys.modules["pydantic_v1"] = pydantic_v1 from langchain.agents import MRKLChain, ReActChain, SelfAskWithSearchChain from langchain.cache import BaseCache