Skip to content

Commit 76c5d6d

Browse files
yeesiancopybara-github
authored andcommitted
fix: Handle missing import for RunnableConfig when generating schema for LangChain templates
PiperOrigin-RevId: 627419996
1 parent 118826f commit 76c5d6d

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

setup.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@
140140

141141
reasoning_engine_extra_require = [
142142
"cloudpickle >= 2.2.1, < 3.0",
143-
"pydantic < 3",
143+
"pydantic >= 2.6.3, < 3",
144144
]
145145

146146
rapid_evaluation_extra_require = [
@@ -154,9 +154,13 @@
154154
"langchain-google-vertexai < 0.2",
155155
]
156156

157-
langchain_testing_extra_require = langchain_extra_require + [
158-
"pytest-xdist",
159-
]
157+
langchain_testing_extra_require = list(
158+
set(
159+
langchain_extra_require
160+
+ reasoning_engine_extra_require
161+
+ ["absl-py", "pytest-xdist"]
162+
)
163+
)
160164

161165
full_extra_require = list(
162166
set(
@@ -174,7 +178,6 @@
174178
+ autologging_extra_require
175179
+ preview_extra_require
176180
+ ray_extra_require
177-
+ reasoning_engine_extra_require
178181
+ rapid_evaluation_extra_require
179182
)
180183
)

vertexai/reasoning_engines/_utils.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@
2424
from google.protobuf import struct_pb2
2525
from google.protobuf import json_format
2626

27+
try:
28+
# For LangChain templates, they might not import langchain_core and get
29+
# PydanticUserError: `query` is not fully defined; you should define
30+
# `RunnableConfig`, then call `query.model_rebuild()`.
31+
import langchain_core.runnables.config
32+
RunnableConfig = langchain_core.runnables.config.RunnableConfig
33+
except ImportError:
34+
RunnableConfig = Any
35+
2736
JsonDict = Dict[str, Any]
2837

2938

@@ -214,11 +223,10 @@ def _import_cloudpickle_or_raise() -> types.ModuleType:
214223
def _import_pydantic_or_raise() -> types.ModuleType:
215224
"""Tries to import the pydantic module."""
216225
try:
217-
# For compatibility across Pydantic V1 and V2
218-
try:
219-
from pydantic import v1 as pydantic
220-
except ImportError:
221-
import pydantic
226+
import pydantic
227+
_ = pydantic.Field
228+
except AttributeError:
229+
from pydantic import v1 as pydantic
222230
except ImportError as e:
223231
raise ImportError(
224232
"pydantic is not installed. Please call "

0 commit comments

Comments
 (0)