Skip to content

Commit 1315df7

Browse files
vertex-sdk-botcopybara-github
authored andcommitted
feat: Provide docs for using invoke method.
PiperOrigin-RevId: 783904724
1 parent 7764d98 commit 1315df7

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import json
16+
from typing import Dict, Any
17+
18+
from google.cloud import aiplatform
19+
20+
21+
# [START aiplatform_sdk_invoke_direct_deployed_model_inference_tabular_sample]
22+
def invoke_direct_deployed_model_inference_tabular_sample(
23+
project: str,
24+
location: str,
25+
endpoint_id: str,
26+
request_path: str,
27+
http_request_body: Dict[str, Any],
28+
deployed_model_id: str,
29+
stream: bool = False,
30+
):
31+
aiplatform.init(project=project, location=location)
32+
33+
dedicated_endpoint = aiplatform.Endpoint(endpoint_id)
34+
if stream:
35+
for chunk in dedicated_endpoint.invoke(
36+
request_path=request_path,
37+
body=json.dumps(http_request_body).encode("utf-8"),
38+
headers={"Content-Type": "application/json"},
39+
deployed_model_id=deployed_model_id,
40+
stream=True,
41+
):
42+
print(chunk)
43+
else:
44+
response = dedicated_endpoint.invoke(
45+
request_path=request_path,
46+
body=json.dumps(http_request_body).encode("utf-8"),
47+
headers={"Content-Type": "application/json"},
48+
deployed_model_id=deployed_model_id,
49+
)
50+
print(response)
51+
52+
53+
# [END aiplatform_sdk_invoke_direct_deployed_model_inference_tabular_sample]
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import json
16+
from typing import Dict, Any
17+
18+
from google.cloud import aiplatform
19+
20+
21+
# [START aiplatform_sdk_invoke_tabular_sample]
22+
def invoke_tabular_sample(
23+
project: str,
24+
location: str,
25+
endpoint_id: str,
26+
request_path: str,
27+
http_request_body: Dict[str, Any],
28+
stream: bool = False,
29+
):
30+
aiplatform.init(project=project, location=location)
31+
32+
dedicated_endpoint = aiplatform.Endpoint(endpoint_id)
33+
if stream:
34+
for chunk in dedicated_endpoint.invoke(
35+
request_path=request_path,
36+
body=json.dumps(http_request_body).encode("utf-8"),
37+
headers={"Content-Type": "application/json"},
38+
stream=True,
39+
):
40+
print(chunk)
41+
else:
42+
response = dedicated_endpoint.invoke(
43+
request_path=request_path,
44+
body=json.dumps(http_request_body).encode("utf-8"),
45+
headers={"Content-Type": "application/json"},
46+
)
47+
print(response)
48+
49+
50+
# [END aiplatform_sdk_invoke_tabular_sample]

0 commit comments

Comments
 (0)