Skip to content

Commit 5eb885e

Browse files
yeesiancopybara-github
authored andcommitted
feat: Add support for BaseModels in LangChain templates
PiperOrigin-RevId: 630232213
1 parent d1e2012 commit 5eb885e

File tree

28 files changed

+183
-288
lines changed

28 files changed

+183
-288
lines changed

.release-please-manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
".": "1.50.0"
2+
".": "1.49.0"
33
}

CHANGELOG.md

-24
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,5 @@
11
# Changelog
22

3-
## [1.50.0](https://github.com/googleapis/python-aiplatform/compare/v1.49.0...v1.50.0) (2024-05-02)
4-
5-
6-
### Features
7-
8-
* Add `Candidate.grounding_metadata` property ([b22a8b8](https://github.com/googleapis/python-aiplatform/commit/b22a8b847e3b299b828e37405e3678093486de28))
9-
* Add option to not include time_series_metrics in get_experiment_df call. This will improve execution time for Experiments with large number of runs. ([78a95c5](https://github.com/googleapis/python-aiplatform/commit/78a95c52d0e7bd9ec5b656ce67044b2f01677156))
10-
* Add tune_model and deploy_tuned_model for TextEmbeddingModel. ([42f5d6f](https://github.com/googleapis/python-aiplatform/commit/42f5d6f7cd13d51c4a73113c59e8b3c728cfc08b))
11-
* Automatically populate parents for full resource name in Vertex RAG SDK ([26657ff](https://github.com/googleapis/python-aiplatform/commit/26657ffd25ecb91882ca764e513c2e952833257f))
12-
* Deploy a tuned text embedding model -- it doesn't matter, if it's tuned using Node.js, or curl. ([8ca9cdf](https://github.com/googleapis/python-aiplatform/commit/8ca9cdf3576e3ce3b373ace4cd6ab0e9c54aa9f2))
13-
* Make get_embeddings work both for foundational & tuned models. ([b8b589c](https://github.com/googleapis/python-aiplatform/commit/b8b589ce9fff29d1721450d32b4a84a7f69413c3))
14-
* Python SDK for Vertex Model Monitoring V2. ([021d59f](https://github.com/googleapis/python-aiplatform/commit/021d59f1487e4e16c847d4135899d6845c0210aa))
15-
* Support public endpoint for Ray Client ([57a5f78](https://github.com/googleapis/python-aiplatform/commit/57a5f7815ffb8523e91d900da4ff7cfd0c344fe4))
16-
17-
18-
### Bug Fixes
19-
20-
* Add deprecation warnings when using Ray v2.4 ([3a36784](https://github.com/googleapis/python-aiplatform/commit/3a367843840513e3257610c8ab38e9f79d3bcea0))
21-
* Append allowed_plugins in tb-gcp-uploader to default allowed plugins ([aab9c3e](https://github.com/googleapis/python-aiplatform/commit/aab9c3e41b92a1d60090e3d1d594390a5e9f3ff6))
22-
* LLM - Added missing parameters to the no-op `_TunableTextEmbeddingModelMixin.get_tuned_model` method ([eb05ac4](https://github.com/googleapis/python-aiplatform/commit/eb05ac421f186441a92c6e3b6a010d74caf14782))
23-
* LVM - Fixed the typo in the VisionModel aspect ratio type annotation ([2d19137](https://github.com/googleapis/python-aiplatform/commit/2d1913773cf9f4a4f8a2c8c8f45680c3ea97f68e))
24-
* Move torch import ([e6d34df](https://github.com/googleapis/python-aiplatform/commit/e6d34df7da7508c655eb17ee694e1ab2160fc8aa))
25-
* Ray - Fixed exception when using Ray 2.4 ([2661f52](https://github.com/googleapis/python-aiplatform/commit/2661f52fd08169e5d29b58f2afce9702b30101ae))
26-
273
## [1.49.0](https://github.com/googleapis/python-aiplatform/compare/v1.48.0...v1.49.0) (2024-04-27)
284

295

google/cloud/aiplatform/gapic_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16-
__version__ = "1.50.0" # {x-release-please-version}
16+
__version__ = "1.49.0" # {x-release-please-version}

google/cloud/aiplatform/v1/schema/predict/instance/gapic_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16-
__version__ = "1.50.0" # {x-release-please-version}
16+
__version__ = "1.49.0" # {x-release-please-version}

google/cloud/aiplatform/v1/schema/predict/instance_v1/gapic_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16-
__version__ = "1.50.0" # {x-release-please-version}
16+
__version__ = "1.49.0" # {x-release-please-version}

google/cloud/aiplatform/v1/schema/predict/params/gapic_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16-
__version__ = "1.50.0" # {x-release-please-version}
16+
__version__ = "1.49.0" # {x-release-please-version}

google/cloud/aiplatform/v1/schema/predict/params_v1/gapic_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16-
__version__ = "1.50.0" # {x-release-please-version}
16+
__version__ = "1.49.0" # {x-release-please-version}

google/cloud/aiplatform/v1/schema/predict/prediction/gapic_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16-
__version__ = "1.50.0" # {x-release-please-version}
16+
__version__ = "1.49.0" # {x-release-please-version}

google/cloud/aiplatform/v1/schema/predict/prediction_v1/gapic_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16-
__version__ = "1.50.0" # {x-release-please-version}
16+
__version__ = "1.49.0" # {x-release-please-version}

google/cloud/aiplatform/v1/schema/trainingjob/definition/gapic_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16-
__version__ = "1.50.0" # {x-release-please-version}
16+
__version__ = "1.49.0" # {x-release-please-version}

google/cloud/aiplatform/v1/schema/trainingjob/definition_v1/gapic_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16-
__version__ = "1.50.0" # {x-release-please-version}
16+
__version__ = "1.49.0" # {x-release-please-version}

google/cloud/aiplatform/v1beta1/schema/predict/instance/gapic_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16-
__version__ = "1.50.0" # {x-release-please-version}
16+
__version__ = "1.49.0" # {x-release-please-version}

google/cloud/aiplatform/v1beta1/schema/predict/instance_v1beta1/gapic_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16-
__version__ = "1.50.0" # {x-release-please-version}
16+
__version__ = "1.49.0" # {x-release-please-version}

google/cloud/aiplatform/v1beta1/schema/predict/params/gapic_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16-
__version__ = "1.50.0" # {x-release-please-version}
16+
__version__ = "1.49.0" # {x-release-please-version}

google/cloud/aiplatform/v1beta1/schema/predict/params_v1beta1/gapic_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16-
__version__ = "1.50.0" # {x-release-please-version}
16+
__version__ = "1.49.0" # {x-release-please-version}

google/cloud/aiplatform/v1beta1/schema/predict/prediction/gapic_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16-
__version__ = "1.50.0" # {x-release-please-version}
16+
__version__ = "1.49.0" # {x-release-please-version}

google/cloud/aiplatform/v1beta1/schema/predict/prediction_v1beta1/gapic_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16-
__version__ = "1.50.0" # {x-release-please-version}
16+
__version__ = "1.49.0" # {x-release-please-version}

google/cloud/aiplatform/v1beta1/schema/trainingjob/definition/gapic_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16-
__version__ = "1.50.0" # {x-release-please-version}
16+
__version__ = "1.49.0" # {x-release-please-version}

google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/gapic_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16-
__version__ = "1.50.0" # {x-release-please-version}
16+
__version__ = "1.49.0" # {x-release-please-version}

google/cloud/aiplatform/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@
1515
# limitations under the License.
1616
#
1717

18-
__version__ = "1.50.0"
18+
__version__ = "1.49.0"

google/cloud/aiplatform_v1/gapic_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16-
__version__ = "1.50.0" # {x-release-please-version}
16+
__version__ = "1.49.0" # {x-release-please-version}

google/cloud/aiplatform_v1beta1/gapic_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16-
__version__ = "1.50.0" # {x-release-please-version}
16+
__version__ = "1.49.0" # {x-release-please-version}

pypi/_vertex_ai_placeholder/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@
1515
# limitations under the License.
1616
#
1717

18-
__version__ = "1.50.0"
18+
__version__ = "1.49.0"

samples/generated_samples/snippet_metadata_google.cloud.aiplatform.v1.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
],
99
"language": "PYTHON",
1010
"name": "google-cloud-aiplatform",
11-
"version": "1.50.0"
11+
"version": "1.49.0"
1212
},
1313
"snippets": [
1414
{

samples/generated_samples/snippet_metadata_google.cloud.aiplatform.v1beta1.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
],
99
"language": "PYTHON",
1010
"name": "google-cloud-aiplatform",
11-
"version": "1.50.0"
11+
"version": "1.49.0"
1212
},
1313
"snippets": [
1414
{

setup.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,9 @@
149149
]
150150

151151
langchain_extra_require = [
152-
"langchain >= 0.1.13, < 0.2",
152+
"langchain >= 0.1.16, < 0.2",
153153
"langchain-core < 0.2",
154-
"langchain-google-vertexai < 0.2",
154+
"langchain-google-vertexai < 2",
155155
]
156156

157157
langchain_testing_extra_require = list(

tests/unit/vertex_langchain/test_reasoning_engine_templates_langchain.py

+31-70
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
# limitations under the License.
1414
#
1515
import importlib
16-
import json
1716
from typing import Optional
1817
from unittest import mock
1918

@@ -25,11 +24,9 @@
2524
import pytest
2625

2726

28-
from langchain_core import agents
29-
from langchain_core import messages
30-
from langchain_core import outputs
31-
from langchain_core import tools as lc_tools
27+
from langchain_core import prompts
3228
from langchain.load import dump as langchain_load_dump
29+
from langchain.agents.format_scratchpad import format_to_openai_function_messages
3330
from langchain.tools.base import StructuredTool
3431

3532

@@ -93,6 +90,18 @@ def setup_method(self):
9390
project=_TEST_PROJECT,
9491
location=_TEST_LOCATION,
9592
)
93+
self.prompt = {
94+
"input": lambda x: x["input"],
95+
"agent_scratchpad": (
96+
lambda x: format_to_openai_function_messages(x["intermediate_steps"])
97+
),
98+
} | prompts.ChatPromptTemplate.from_messages(
99+
[
100+
("user", "{input}"),
101+
prompts.MessagesPlaceholder(variable_name="agent_scratchpad"),
102+
]
103+
)
104+
self.output_parser = mock.Mock()
96105

97106
def teardown_method(self):
98107
initializer.global_pool.shutdown(wait=True)
@@ -105,24 +114,33 @@ def test_initialization(self):
105114
assert agent._runnable is None
106115

107116
def test_initialization_with_tools(self):
117+
tools = [
118+
place_tool_query,
119+
StructuredTool.from_function(place_photo_query),
120+
]
108121
agent = reasoning_engines.LangchainAgent(
109122
model=_TEST_MODEL,
110-
tools=[
111-
place_tool_query,
112-
StructuredTool.from_function(place_photo_query),
113-
],
123+
tools=tools,
114124
)
115-
for tool in agent._tools:
116-
assert isinstance(tool, lc_tools.BaseTool)
125+
for tool, agent_tool in zip(tools, agent._tools):
126+
assert isinstance(agent_tool, type(tool))
117127

118128
def test_set_up(self, vertexai_init_mock):
119-
agent = reasoning_engines.LangchainAgent(model=_TEST_MODEL)
129+
agent = reasoning_engines.LangchainAgent(
130+
model=_TEST_MODEL,
131+
prompt=self.prompt,
132+
output_parser=self.output_parser,
133+
)
120134
assert agent._runnable is None
121135
agent.set_up()
122136
assert agent._runnable is not None
123137

124138
def test_query(self, langchain_dump_mock):
125-
agent = reasoning_engines.LangchainAgent(model=_TEST_MODEL)
139+
agent = reasoning_engines.LangchainAgent(
140+
model=_TEST_MODEL,
141+
prompt=self.prompt,
142+
output_parser=self.output_parser,
143+
)
126144
agent._runnable = mock.Mock()
127145
mocks = mock.Mock()
128146
mocks.attach_mock(mock=agent._runnable, attribute="invoke")
@@ -132,63 +150,6 @@ def test_query(self, langchain_dump_mock):
132150
)
133151

134152

135-
class TestDefaultOutputParser:
136-
def test_parse_result_function_call(self, vertexai_init_mock):
137-
agent = reasoning_engines.LangchainAgent(model=_TEST_MODEL)
138-
agent.set_up()
139-
tool_input = {
140-
"photo_reference": "abcd1234",
141-
"maxwidth": _DEFAULT_PLACE_PHOTO_MAXWIDTH,
142-
}
143-
result = agent._output_parser.parse_result(
144-
[
145-
outputs.ChatGeneration(
146-
message=messages.AIMessage(
147-
content="",
148-
additional_kwargs={
149-
"function_call": {
150-
"name": "place_tool_query",
151-
"arguments": json.dumps(tool_input),
152-
},
153-
},
154-
)
155-
)
156-
]
157-
)
158-
assert isinstance(result, agents.AgentActionMessageLog)
159-
assert result.tool == "place_tool_query"
160-
assert result.tool_input == tool_input
161-
162-
def test_parse_result_not_function_call(self, vertexai_init_mock):
163-
agent = reasoning_engines.LangchainAgent(model=_TEST_MODEL)
164-
agent.set_up()
165-
content = "test content"
166-
result = agent._output_parser.parse_result(
167-
[
168-
outputs.ChatGeneration(
169-
message=messages.AIMessage(content=content),
170-
)
171-
]
172-
)
173-
assert isinstance(result, agents.AgentFinish)
174-
assert result.return_values == {"output": content}
175-
assert result.log == content
176-
177-
178-
class TestDefaultOutputParserErrors:
179-
def test_parse_result_non_chat_generation_errors(self, vertexai_init_mock):
180-
agent = reasoning_engines.LangchainAgent(model=_TEST_MODEL)
181-
agent.set_up()
182-
with pytest.raises(ValueError, match=r"only works on ChatGeneration"):
183-
agent._output_parser.parse_result(["text"])
184-
185-
def test_parse_text_errors(self, vertexai_init_mock):
186-
agent = reasoning_engines.LangchainAgent(model=_TEST_MODEL)
187-
agent.set_up()
188-
with pytest.raises(ValueError, match=r"Can only parse messages"):
189-
agent._output_parser.parse("text")
190-
191-
192153
class TestConvertToolsOrRaise:
193154
def test_convert_tools_or_raise(self, vertexai_init_mock):
194155
pass

0 commit comments

Comments
 (0)