google-cloud-agentplatform 1.165.1.dev0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- agentplatform/__init__.py +72 -0
- agentplatform/_genai/__init__.py +43 -0
- agentplatform/_genai/_agent_engines_utils.py +2341 -0
- agentplatform/_genai/_bigquery_utils.py +49 -0
- agentplatform/_genai/_datasets_utils.py +344 -0
- agentplatform/_genai/_evals_builtin_tools.py +209 -0
- agentplatform/_genai/_evals_common.py +4268 -0
- agentplatform/_genai/_evals_constant.py +122 -0
- agentplatform/_genai/_evals_data_converters.py +926 -0
- agentplatform/_genai/_evals_metric_handlers.py +1783 -0
- agentplatform/_genai/_evals_metric_loaders.py +401 -0
- agentplatform/_genai/_evals_utils.py +1043 -0
- agentplatform/_genai/_evals_visualization.py +2070 -0
- agentplatform/_genai/_gcs_utils.py +262 -0
- agentplatform/_genai/_logging_utils.py +47 -0
- agentplatform/_genai/_memory_bank_utils.py +206 -0
- agentplatform/_genai/_observability_data_converter.py +186 -0
- agentplatform/_genai/_operations_utils.py +94 -0
- agentplatform/_genai/_prompt_management_utils.py +147 -0
- agentplatform/_genai/_prompt_optimizer_utils.py +215 -0
- agentplatform/_genai/_skills_utils.py +69 -0
- agentplatform/_genai/_transformers.py +628 -0
- agentplatform/_genai/a2a_task_events.py +509 -0
- agentplatform/_genai/a2a_tasks.py +861 -0
- agentplatform/_genai/agent_engines.py +3931 -0
- agentplatform/_genai/client.py +519 -0
- agentplatform/_genai/datasets.py +3045 -0
- agentplatform/_genai/endpoints.py +1149 -0
- agentplatform/_genai/evals.py +6883 -0
- agentplatform/_genai/example_stores.py +1445 -0
- agentplatform/_genai/feedback_contexts.py +700 -0
- agentplatform/_genai/feedback_entries.py +1644 -0
- agentplatform/_genai/live.py +64 -0
- agentplatform/_genai/live_agent_engines.py +179 -0
- agentplatform/_genai/memories.py +2962 -0
- agentplatform/_genai/memory_banks.py +1927 -0
- agentplatform/_genai/memory_revisions.py +465 -0
- agentplatform/_genai/model_garden.py +2638 -0
- agentplatform/_genai/prompt_optimizer.py +995 -0
- agentplatform/_genai/prompts.py +4515 -0
- agentplatform/_genai/rag.py +4961 -0
- agentplatform/_genai/runtime_revisions.py +1257 -0
- agentplatform/_genai/runtimes.py +78 -0
- agentplatform/_genai/sandbox_snapshots.py +1015 -0
- agentplatform/_genai/sandbox_templates.py +1088 -0
- agentplatform/_genai/sandboxes.py +1604 -0
- agentplatform/_genai/session_events.py +543 -0
- agentplatform/_genai/sessions.py +1449 -0
- agentplatform/_genai/skill_revisions.py +377 -0
- agentplatform/_genai/skills.py +1708 -0
- agentplatform/_genai/types/__init__.py +4695 -0
- agentplatform/_genai/types/agent_engines.py +16 -0
- agentplatform/_genai/types/common.py +32784 -0
- agentplatform/_genai/types/evals.py +1031 -0
- agentplatform/_genai/types/prompt_optimizer.py +107 -0
- agentplatform/_genai/types/prompts.py +107 -0
- agentplatform/version.py +17 -0
- google_cloud_agentplatform-1.165.1.dev0.dist-info/METADATA +79 -0
- google_cloud_agentplatform-1.165.1.dev0.dist-info/RECORD +62 -0
- google_cloud_agentplatform-1.165.1.dev0.dist-info/WHEEL +5 -0
- google_cloud_agentplatform-1.165.1.dev0.dist-info/licenses/LICENSE +202 -0
- google_cloud_agentplatform-1.165.1.dev0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,1644 @@
|
|
|
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
|
+
# http://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
|
+
|
|
16
|
+
# Code generated by the Google Gen AI SDK generator DO NOT EDIT.
|
|
17
|
+
|
|
18
|
+
import functools
|
|
19
|
+
import importlib
|
|
20
|
+
import json
|
|
21
|
+
import logging
|
|
22
|
+
import typing
|
|
23
|
+
from typing import Any, AsyncIterator, Iterator, Optional, Union
|
|
24
|
+
from urllib.parse import urlencode
|
|
25
|
+
|
|
26
|
+
from google.genai import _api_module
|
|
27
|
+
from google.genai import _common
|
|
28
|
+
from google.genai._common import get_value_by_path as getv
|
|
29
|
+
from google.genai._common import set_value_by_path as setv
|
|
30
|
+
from google.genai.pagers import AsyncPager, Pager
|
|
31
|
+
|
|
32
|
+
from . import _agent_engines_utils
|
|
33
|
+
from . import types
|
|
34
|
+
|
|
35
|
+
if typing.TYPE_CHECKING:
|
|
36
|
+
from . import feedback_contexts as feedback_contexts_module
|
|
37
|
+
|
|
38
|
+
_ = feedback_contexts_module
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
logger = logging.getLogger("agentplatform_genai.feedbackentries")
|
|
42
|
+
|
|
43
|
+
logger.setLevel(logging.INFO)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _CreateRuntimeFeedbackEntryConfig_to_vertex(
|
|
47
|
+
from_object: Union[dict[str, Any], object],
|
|
48
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
49
|
+
) -> dict[str, Any]:
|
|
50
|
+
to_object: dict[str, Any] = {}
|
|
51
|
+
|
|
52
|
+
if getv(from_object, ["feedback_labels"]) is not None:
|
|
53
|
+
setv(parent_object, ["feedbackLabels"], getv(from_object, ["feedback_labels"]))
|
|
54
|
+
|
|
55
|
+
if getv(from_object, ["feedback_text"]) is not None:
|
|
56
|
+
setv(parent_object, ["feedbackText"], getv(from_object, ["feedback_text"]))
|
|
57
|
+
|
|
58
|
+
if getv(from_object, ["user_id"]) is not None:
|
|
59
|
+
setv(parent_object, ["userId"], getv(from_object, ["user_id"]))
|
|
60
|
+
|
|
61
|
+
if getv(from_object, ["source"]) is not None:
|
|
62
|
+
setv(parent_object, ["source"], getv(from_object, ["source"]))
|
|
63
|
+
|
|
64
|
+
if getv(from_object, ["custom_metadata"]) is not None:
|
|
65
|
+
setv(parent_object, ["customMetadata"], getv(from_object, ["custom_metadata"]))
|
|
66
|
+
|
|
67
|
+
return to_object
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def _CreateRuntimeFeedbackEntryRequestParameters_to_vertex(
|
|
71
|
+
from_object: Union[dict[str, Any], object],
|
|
72
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
73
|
+
) -> dict[str, Any]:
|
|
74
|
+
to_object: dict[str, Any] = {}
|
|
75
|
+
if getv(from_object, ["name"]) is not None:
|
|
76
|
+
setv(to_object, ["_url", "parent"], getv(from_object, ["name"]))
|
|
77
|
+
|
|
78
|
+
if getv(from_object, ["feedback_type"]) is not None:
|
|
79
|
+
setv(to_object, ["feedbackType"], getv(from_object, ["feedback_type"]))
|
|
80
|
+
|
|
81
|
+
if getv(from_object, ["session_id"]) is not None:
|
|
82
|
+
setv(to_object, ["sessionId"], getv(from_object, ["session_id"]))
|
|
83
|
+
|
|
84
|
+
if getv(from_object, ["event_id"]) is not None:
|
|
85
|
+
setv(to_object, ["eventId"], getv(from_object, ["event_id"]))
|
|
86
|
+
|
|
87
|
+
if getv(from_object, ["config"]) is not None:
|
|
88
|
+
_CreateRuntimeFeedbackEntryConfig_to_vertex(
|
|
89
|
+
getv(from_object, ["config"]), to_object
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
return to_object
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def _DeleteRuntimeFeedbackEntryRequestParameters_to_vertex(
|
|
96
|
+
from_object: Union[dict[str, Any], object],
|
|
97
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
98
|
+
) -> dict[str, Any]:
|
|
99
|
+
to_object: dict[str, Any] = {}
|
|
100
|
+
if getv(from_object, ["name"]) is not None:
|
|
101
|
+
setv(to_object, ["_url", "name"], getv(from_object, ["name"]))
|
|
102
|
+
|
|
103
|
+
return to_object
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def _GetRuntimeFeedbackOperationParameters_to_vertex(
|
|
107
|
+
from_object: Union[dict[str, Any], object],
|
|
108
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
109
|
+
) -> dict[str, Any]:
|
|
110
|
+
to_object: dict[str, Any] = {}
|
|
111
|
+
if getv(from_object, ["operation_name"]) is not None:
|
|
112
|
+
setv(
|
|
113
|
+
to_object, ["_url", "operationName"], getv(from_object, ["operation_name"])
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
return to_object
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def _GetRuntimeFeedbackRequestParameters_to_vertex(
|
|
120
|
+
from_object: Union[dict[str, Any], object],
|
|
121
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
122
|
+
) -> dict[str, Any]:
|
|
123
|
+
to_object: dict[str, Any] = {}
|
|
124
|
+
if getv(from_object, ["name"]) is not None:
|
|
125
|
+
setv(to_object, ["_url", "name"], getv(from_object, ["name"]))
|
|
126
|
+
|
|
127
|
+
return to_object
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def _ListRuntimeFeedbackEntriesConfig_to_vertex(
|
|
131
|
+
from_object: Union[dict[str, Any], object],
|
|
132
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
133
|
+
) -> dict[str, Any]:
|
|
134
|
+
to_object: dict[str, Any] = {}
|
|
135
|
+
|
|
136
|
+
if getv(from_object, ["page_size"]) is not None:
|
|
137
|
+
setv(parent_object, ["_query", "pageSize"], getv(from_object, ["page_size"]))
|
|
138
|
+
|
|
139
|
+
if getv(from_object, ["page_token"]) is not None:
|
|
140
|
+
setv(parent_object, ["_query", "pageToken"], getv(from_object, ["page_token"]))
|
|
141
|
+
|
|
142
|
+
if getv(from_object, ["filter"]) is not None:
|
|
143
|
+
setv(parent_object, ["_query", "filter"], getv(from_object, ["filter"]))
|
|
144
|
+
|
|
145
|
+
if getv(from_object, ["order_by"]) is not None:
|
|
146
|
+
setv(parent_object, ["_query", "orderBy"], getv(from_object, ["order_by"]))
|
|
147
|
+
|
|
148
|
+
return to_object
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def _ListRuntimeFeedbackEntriesRequestParameters_to_vertex(
|
|
152
|
+
from_object: Union[dict[str, Any], object],
|
|
153
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
154
|
+
) -> dict[str, Any]:
|
|
155
|
+
to_object: dict[str, Any] = {}
|
|
156
|
+
if getv(from_object, ["parent"]) is not None:
|
|
157
|
+
setv(to_object, ["_url", "parent"], getv(from_object, ["parent"]))
|
|
158
|
+
|
|
159
|
+
if getv(from_object, ["config"]) is not None:
|
|
160
|
+
_ListRuntimeFeedbackEntriesConfig_to_vertex(
|
|
161
|
+
getv(from_object, ["config"]), to_object
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
return to_object
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def _UpdateRuntimeFeedbackEntryConfig_to_vertex(
|
|
168
|
+
from_object: Union[dict[str, Any], object],
|
|
169
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
170
|
+
) -> dict[str, Any]:
|
|
171
|
+
to_object: dict[str, Any] = {}
|
|
172
|
+
|
|
173
|
+
if getv(from_object, ["update_mask"]) is not None:
|
|
174
|
+
setv(
|
|
175
|
+
parent_object, ["_query", "updateMask"], getv(from_object, ["update_mask"])
|
|
176
|
+
)
|
|
177
|
+
|
|
178
|
+
if getv(from_object, ["feedback_type"]) is not None:
|
|
179
|
+
setv(parent_object, ["feedbackType"], getv(from_object, ["feedback_type"]))
|
|
180
|
+
|
|
181
|
+
if getv(from_object, ["session_id"]) is not None:
|
|
182
|
+
setv(parent_object, ["sessionId"], getv(from_object, ["session_id"]))
|
|
183
|
+
|
|
184
|
+
if getv(from_object, ["event_id"]) is not None:
|
|
185
|
+
setv(parent_object, ["eventId"], getv(from_object, ["event_id"]))
|
|
186
|
+
|
|
187
|
+
if getv(from_object, ["feedback_labels"]) is not None:
|
|
188
|
+
setv(parent_object, ["feedbackLabels"], getv(from_object, ["feedback_labels"]))
|
|
189
|
+
|
|
190
|
+
if getv(from_object, ["feedback_text"]) is not None:
|
|
191
|
+
setv(parent_object, ["feedbackText"], getv(from_object, ["feedback_text"]))
|
|
192
|
+
|
|
193
|
+
if getv(from_object, ["user_id"]) is not None:
|
|
194
|
+
setv(parent_object, ["userId"], getv(from_object, ["user_id"]))
|
|
195
|
+
|
|
196
|
+
if getv(from_object, ["source"]) is not None:
|
|
197
|
+
setv(parent_object, ["source"], getv(from_object, ["source"]))
|
|
198
|
+
|
|
199
|
+
if getv(from_object, ["custom_metadata"]) is not None:
|
|
200
|
+
setv(parent_object, ["customMetadata"], getv(from_object, ["custom_metadata"]))
|
|
201
|
+
|
|
202
|
+
return to_object
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
def _UpdateRuntimeFeedbackEntryRequestParameters_to_vertex(
|
|
206
|
+
from_object: Union[dict[str, Any], object],
|
|
207
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
208
|
+
) -> dict[str, Any]:
|
|
209
|
+
to_object: dict[str, Any] = {}
|
|
210
|
+
if getv(from_object, ["name"]) is not None:
|
|
211
|
+
setv(to_object, ["_url", "name"], getv(from_object, ["name"]))
|
|
212
|
+
|
|
213
|
+
if getv(from_object, ["config"]) is not None:
|
|
214
|
+
_UpdateRuntimeFeedbackEntryConfig_to_vertex(
|
|
215
|
+
getv(from_object, ["config"]), to_object
|
|
216
|
+
)
|
|
217
|
+
|
|
218
|
+
return to_object
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
class FeedbackEntries(_api_module.BaseModule):
|
|
222
|
+
|
|
223
|
+
def _create(
|
|
224
|
+
self,
|
|
225
|
+
*,
|
|
226
|
+
name: str,
|
|
227
|
+
feedback_type: types.FeedbackType,
|
|
228
|
+
session_id: str,
|
|
229
|
+
event_id: str,
|
|
230
|
+
config: Optional[types.CreateRuntimeFeedbackEntryConfigOrDict] = None,
|
|
231
|
+
) -> types.RuntimeFeedbackEntryOperation:
|
|
232
|
+
parameter_model = types._CreateRuntimeFeedbackEntryRequestParameters(
|
|
233
|
+
name=name,
|
|
234
|
+
feedback_type=feedback_type,
|
|
235
|
+
session_id=session_id,
|
|
236
|
+
event_id=event_id,
|
|
237
|
+
config=config,
|
|
238
|
+
)
|
|
239
|
+
|
|
240
|
+
request_url_dict: Optional[dict[str, str]]
|
|
241
|
+
if not self._api_client.vertexai:
|
|
242
|
+
raise ValueError(
|
|
243
|
+
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
|
|
244
|
+
)
|
|
245
|
+
else:
|
|
246
|
+
request_dict = _CreateRuntimeFeedbackEntryRequestParameters_to_vertex(
|
|
247
|
+
parameter_model
|
|
248
|
+
)
|
|
249
|
+
request_url_dict = request_dict.get("_url")
|
|
250
|
+
if request_url_dict:
|
|
251
|
+
path = "{parent}/feedbackEntries".format_map(request_url_dict)
|
|
252
|
+
else:
|
|
253
|
+
path = "{parent}/feedbackEntries"
|
|
254
|
+
|
|
255
|
+
query_params = request_dict.get("_query")
|
|
256
|
+
if query_params:
|
|
257
|
+
path = f"{path}?{urlencode(query_params)}"
|
|
258
|
+
# TODO: remove the hack that pops config.
|
|
259
|
+
request_dict.pop("config", None)
|
|
260
|
+
|
|
261
|
+
http_options: Optional[types.HttpOptions] = None
|
|
262
|
+
if (
|
|
263
|
+
parameter_model.config is not None
|
|
264
|
+
and parameter_model.config.http_options is not None
|
|
265
|
+
):
|
|
266
|
+
http_options = parameter_model.config.http_options
|
|
267
|
+
|
|
268
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
269
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
270
|
+
|
|
271
|
+
response = self._api_client.request("post", path, request_dict, http_options)
|
|
272
|
+
|
|
273
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
274
|
+
|
|
275
|
+
return_value = types.RuntimeFeedbackEntryOperation._from_response(
|
|
276
|
+
response=response_dict,
|
|
277
|
+
kwargs=(
|
|
278
|
+
{
|
|
279
|
+
"config": {
|
|
280
|
+
"response_schema": getattr(
|
|
281
|
+
parameter_model.config, "response_schema", None
|
|
282
|
+
),
|
|
283
|
+
"response_json_schema": getattr(
|
|
284
|
+
parameter_model.config, "response_json_schema", None
|
|
285
|
+
),
|
|
286
|
+
"include_all_fields": getattr(
|
|
287
|
+
parameter_model.config, "include_all_fields", None
|
|
288
|
+
),
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
if getattr(parameter_model, "config", None)
|
|
292
|
+
else {}
|
|
293
|
+
),
|
|
294
|
+
)
|
|
295
|
+
|
|
296
|
+
self._api_client._verify_response(return_value)
|
|
297
|
+
return return_value
|
|
298
|
+
|
|
299
|
+
def _delete(
|
|
300
|
+
self,
|
|
301
|
+
*,
|
|
302
|
+
name: str,
|
|
303
|
+
config: Optional[types.DeleteRuntimeFeedbackEntryConfigOrDict] = None,
|
|
304
|
+
) -> types.DeleteRuntimeFeedbackEntryOperation:
|
|
305
|
+
parameter_model = types._DeleteRuntimeFeedbackEntryRequestParameters(
|
|
306
|
+
name=name,
|
|
307
|
+
config=config,
|
|
308
|
+
)
|
|
309
|
+
|
|
310
|
+
request_url_dict: Optional[dict[str, str]]
|
|
311
|
+
if not self._api_client.vertexai:
|
|
312
|
+
raise ValueError(
|
|
313
|
+
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
|
|
314
|
+
)
|
|
315
|
+
else:
|
|
316
|
+
request_dict = _DeleteRuntimeFeedbackEntryRequestParameters_to_vertex(
|
|
317
|
+
parameter_model
|
|
318
|
+
)
|
|
319
|
+
request_url_dict = request_dict.get("_url")
|
|
320
|
+
if request_url_dict:
|
|
321
|
+
path = "{name}".format_map(request_url_dict)
|
|
322
|
+
else:
|
|
323
|
+
path = "{name}"
|
|
324
|
+
|
|
325
|
+
query_params = request_dict.get("_query")
|
|
326
|
+
if query_params:
|
|
327
|
+
path = f"{path}?{urlencode(query_params)}"
|
|
328
|
+
# TODO: remove the hack that pops config.
|
|
329
|
+
request_dict.pop("config", None)
|
|
330
|
+
|
|
331
|
+
http_options: Optional[types.HttpOptions] = None
|
|
332
|
+
if (
|
|
333
|
+
parameter_model.config is not None
|
|
334
|
+
and parameter_model.config.http_options is not None
|
|
335
|
+
):
|
|
336
|
+
http_options = parameter_model.config.http_options
|
|
337
|
+
|
|
338
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
339
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
340
|
+
|
|
341
|
+
response = self._api_client.request("delete", path, request_dict, http_options)
|
|
342
|
+
|
|
343
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
344
|
+
|
|
345
|
+
return_value = types.DeleteRuntimeFeedbackEntryOperation._from_response(
|
|
346
|
+
response=response_dict,
|
|
347
|
+
kwargs=(
|
|
348
|
+
{
|
|
349
|
+
"config": {
|
|
350
|
+
"response_schema": getattr(
|
|
351
|
+
parameter_model.config, "response_schema", None
|
|
352
|
+
),
|
|
353
|
+
"response_json_schema": getattr(
|
|
354
|
+
parameter_model.config, "response_json_schema", None
|
|
355
|
+
),
|
|
356
|
+
"include_all_fields": getattr(
|
|
357
|
+
parameter_model.config, "include_all_fields", None
|
|
358
|
+
),
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
if getattr(parameter_model, "config", None)
|
|
362
|
+
else {}
|
|
363
|
+
),
|
|
364
|
+
)
|
|
365
|
+
|
|
366
|
+
self._api_client._verify_response(return_value)
|
|
367
|
+
return return_value
|
|
368
|
+
|
|
369
|
+
def get(
|
|
370
|
+
self,
|
|
371
|
+
*,
|
|
372
|
+
name: str,
|
|
373
|
+
config: Optional[types.GetRuntimeFeedbackConfigOrDict] = None,
|
|
374
|
+
) -> types.FeedbackEntry:
|
|
375
|
+
"""
|
|
376
|
+
Gets a Runtime Feedback Entry.
|
|
377
|
+
|
|
378
|
+
Args:
|
|
379
|
+
name (str): Required. The name of the Feedback Entry to retrieve. Format:
|
|
380
|
+
`projects/{project}/locations/{location}/reasoningEngines/{resource_id}/feedbackEntries/{feedback_entry_id}`.
|
|
381
|
+
config (GetRuntimeFeedbackConfig):
|
|
382
|
+
Optional. The configuration for getting the Feedback Entry.
|
|
383
|
+
|
|
384
|
+
Returns:
|
|
385
|
+
FeedbackEntry: The requested Feedback Entry.
|
|
386
|
+
|
|
387
|
+
"""
|
|
388
|
+
|
|
389
|
+
parameter_model = types._GetRuntimeFeedbackRequestParameters(
|
|
390
|
+
name=name,
|
|
391
|
+
config=config,
|
|
392
|
+
)
|
|
393
|
+
|
|
394
|
+
request_url_dict: Optional[dict[str, str]]
|
|
395
|
+
if not self._api_client.vertexai:
|
|
396
|
+
raise ValueError(
|
|
397
|
+
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
|
|
398
|
+
)
|
|
399
|
+
else:
|
|
400
|
+
request_dict = _GetRuntimeFeedbackRequestParameters_to_vertex(
|
|
401
|
+
parameter_model
|
|
402
|
+
)
|
|
403
|
+
request_url_dict = request_dict.get("_url")
|
|
404
|
+
if request_url_dict:
|
|
405
|
+
path = "{name}".format_map(request_url_dict)
|
|
406
|
+
else:
|
|
407
|
+
path = "{name}"
|
|
408
|
+
|
|
409
|
+
query_params = request_dict.get("_query")
|
|
410
|
+
if query_params:
|
|
411
|
+
path = f"{path}?{urlencode(query_params)}"
|
|
412
|
+
# TODO: remove the hack that pops config.
|
|
413
|
+
request_dict.pop("config", None)
|
|
414
|
+
|
|
415
|
+
http_options: Optional[types.HttpOptions] = None
|
|
416
|
+
if (
|
|
417
|
+
parameter_model.config is not None
|
|
418
|
+
and parameter_model.config.http_options is not None
|
|
419
|
+
):
|
|
420
|
+
http_options = parameter_model.config.http_options
|
|
421
|
+
|
|
422
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
423
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
424
|
+
|
|
425
|
+
response = self._api_client.request("get", path, request_dict, http_options)
|
|
426
|
+
|
|
427
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
428
|
+
|
|
429
|
+
return_value = types.FeedbackEntry._from_response(
|
|
430
|
+
response=response_dict,
|
|
431
|
+
kwargs=(
|
|
432
|
+
{
|
|
433
|
+
"config": {
|
|
434
|
+
"response_schema": getattr(
|
|
435
|
+
parameter_model.config, "response_schema", None
|
|
436
|
+
),
|
|
437
|
+
"response_json_schema": getattr(
|
|
438
|
+
parameter_model.config, "response_json_schema", None
|
|
439
|
+
),
|
|
440
|
+
"include_all_fields": getattr(
|
|
441
|
+
parameter_model.config, "include_all_fields", None
|
|
442
|
+
),
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
if getattr(parameter_model, "config", None)
|
|
446
|
+
else {}
|
|
447
|
+
),
|
|
448
|
+
)
|
|
449
|
+
|
|
450
|
+
self._api_client._verify_response(return_value)
|
|
451
|
+
return return_value
|
|
452
|
+
|
|
453
|
+
def _list(
|
|
454
|
+
self,
|
|
455
|
+
*,
|
|
456
|
+
parent: str,
|
|
457
|
+
config: Optional[types.ListRuntimeFeedbackEntriesConfigOrDict] = None,
|
|
458
|
+
) -> types.ListRuntimeFeedbackEntriesResponse:
|
|
459
|
+
parameter_model = types._ListRuntimeFeedbackEntriesRequestParameters(
|
|
460
|
+
parent=parent,
|
|
461
|
+
config=config,
|
|
462
|
+
)
|
|
463
|
+
|
|
464
|
+
request_url_dict: Optional[dict[str, str]]
|
|
465
|
+
if not self._api_client.vertexai:
|
|
466
|
+
raise ValueError(
|
|
467
|
+
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
|
|
468
|
+
)
|
|
469
|
+
else:
|
|
470
|
+
request_dict = _ListRuntimeFeedbackEntriesRequestParameters_to_vertex(
|
|
471
|
+
parameter_model
|
|
472
|
+
)
|
|
473
|
+
request_url_dict = request_dict.get("_url")
|
|
474
|
+
if request_url_dict:
|
|
475
|
+
path = "{parent}/feedbackEntries".format_map(request_url_dict)
|
|
476
|
+
else:
|
|
477
|
+
path = "{parent}/feedbackEntries"
|
|
478
|
+
|
|
479
|
+
query_params = request_dict.get("_query")
|
|
480
|
+
if query_params:
|
|
481
|
+
path = f"{path}?{urlencode(query_params)}"
|
|
482
|
+
# TODO: remove the hack that pops config.
|
|
483
|
+
request_dict.pop("config", None)
|
|
484
|
+
|
|
485
|
+
http_options: Optional[types.HttpOptions] = None
|
|
486
|
+
if (
|
|
487
|
+
parameter_model.config is not None
|
|
488
|
+
and parameter_model.config.http_options is not None
|
|
489
|
+
):
|
|
490
|
+
http_options = parameter_model.config.http_options
|
|
491
|
+
|
|
492
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
493
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
494
|
+
|
|
495
|
+
response = self._api_client.request("get", path, request_dict, http_options)
|
|
496
|
+
|
|
497
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
498
|
+
|
|
499
|
+
return_value = types.ListRuntimeFeedbackEntriesResponse._from_response(
|
|
500
|
+
response=response_dict,
|
|
501
|
+
kwargs=(
|
|
502
|
+
{
|
|
503
|
+
"config": {
|
|
504
|
+
"response_schema": getattr(
|
|
505
|
+
parameter_model.config, "response_schema", None
|
|
506
|
+
),
|
|
507
|
+
"response_json_schema": getattr(
|
|
508
|
+
parameter_model.config, "response_json_schema", None
|
|
509
|
+
),
|
|
510
|
+
"include_all_fields": getattr(
|
|
511
|
+
parameter_model.config, "include_all_fields", None
|
|
512
|
+
),
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
if getattr(parameter_model, "config", None)
|
|
516
|
+
else {}
|
|
517
|
+
),
|
|
518
|
+
)
|
|
519
|
+
|
|
520
|
+
self._api_client._verify_response(return_value)
|
|
521
|
+
return return_value
|
|
522
|
+
|
|
523
|
+
def _update(
|
|
524
|
+
self,
|
|
525
|
+
*,
|
|
526
|
+
name: str,
|
|
527
|
+
config: Optional[types.UpdateRuntimeFeedbackEntryConfigOrDict] = None,
|
|
528
|
+
) -> types.RuntimeFeedbackEntryOperation:
|
|
529
|
+
"""
|
|
530
|
+
Updates a Feedback Entry.
|
|
531
|
+
|
|
532
|
+
Args:
|
|
533
|
+
name (str): Required. Name of the Feedback Entry to update. Format:
|
|
534
|
+
`projects/{project}/locations/{location}/reasoningEngines/{resource_id}/feedbackEntries/{feedback_entry_id}`.
|
|
535
|
+
feedback_type (shared.FeedbackType): Optional. The type of feedback provided.
|
|
536
|
+
config (UpdateRuntimeFeedbackEntryConfig): Optional. The configuration for updating the Feedback Entry.
|
|
537
|
+
|
|
538
|
+
Returns:
|
|
539
|
+
RuntimeFeedbackEntryOperation: Operation for updating a Feedback Entry.
|
|
540
|
+
|
|
541
|
+
"""
|
|
542
|
+
|
|
543
|
+
parameter_model = types._UpdateRuntimeFeedbackEntryRequestParameters(
|
|
544
|
+
name=name,
|
|
545
|
+
config=config,
|
|
546
|
+
)
|
|
547
|
+
|
|
548
|
+
request_url_dict: Optional[dict[str, str]]
|
|
549
|
+
if not self._api_client.vertexai:
|
|
550
|
+
raise ValueError(
|
|
551
|
+
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
|
|
552
|
+
)
|
|
553
|
+
else:
|
|
554
|
+
request_dict = _UpdateRuntimeFeedbackEntryRequestParameters_to_vertex(
|
|
555
|
+
parameter_model
|
|
556
|
+
)
|
|
557
|
+
request_url_dict = request_dict.get("_url")
|
|
558
|
+
if request_url_dict:
|
|
559
|
+
path = "{name}".format_map(request_url_dict)
|
|
560
|
+
else:
|
|
561
|
+
path = "{name}"
|
|
562
|
+
|
|
563
|
+
query_params = request_dict.get("_query")
|
|
564
|
+
if query_params:
|
|
565
|
+
path = f"{path}?{urlencode(query_params)}"
|
|
566
|
+
# TODO: remove the hack that pops config.
|
|
567
|
+
request_dict.pop("config", None)
|
|
568
|
+
|
|
569
|
+
http_options: Optional[types.HttpOptions] = None
|
|
570
|
+
if (
|
|
571
|
+
parameter_model.config is not None
|
|
572
|
+
and parameter_model.config.http_options is not None
|
|
573
|
+
):
|
|
574
|
+
http_options = parameter_model.config.http_options
|
|
575
|
+
|
|
576
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
577
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
578
|
+
|
|
579
|
+
response = self._api_client.request("patch", path, request_dict, http_options)
|
|
580
|
+
|
|
581
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
582
|
+
|
|
583
|
+
return_value = types.RuntimeFeedbackEntryOperation._from_response(
|
|
584
|
+
response=response_dict,
|
|
585
|
+
kwargs=(
|
|
586
|
+
{
|
|
587
|
+
"config": {
|
|
588
|
+
"response_schema": getattr(
|
|
589
|
+
parameter_model.config, "response_schema", None
|
|
590
|
+
),
|
|
591
|
+
"response_json_schema": getattr(
|
|
592
|
+
parameter_model.config, "response_json_schema", None
|
|
593
|
+
),
|
|
594
|
+
"include_all_fields": getattr(
|
|
595
|
+
parameter_model.config, "include_all_fields", None
|
|
596
|
+
),
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
if getattr(parameter_model, "config", None)
|
|
600
|
+
else {}
|
|
601
|
+
),
|
|
602
|
+
)
|
|
603
|
+
|
|
604
|
+
self._api_client._verify_response(return_value)
|
|
605
|
+
return return_value
|
|
606
|
+
|
|
607
|
+
def _get_feedback_entry_operation(
|
|
608
|
+
self,
|
|
609
|
+
*,
|
|
610
|
+
operation_name: str,
|
|
611
|
+
config: Optional[types.GetRuntimeFeedbackEntryConfigOrDict] = None,
|
|
612
|
+
) -> types.RuntimeFeedbackEntryOperation:
|
|
613
|
+
parameter_model = types._GetRuntimeFeedbackOperationParameters(
|
|
614
|
+
operation_name=operation_name,
|
|
615
|
+
config=config,
|
|
616
|
+
)
|
|
617
|
+
|
|
618
|
+
request_url_dict: Optional[dict[str, str]]
|
|
619
|
+
if not self._api_client.vertexai:
|
|
620
|
+
raise ValueError(
|
|
621
|
+
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
|
|
622
|
+
)
|
|
623
|
+
else:
|
|
624
|
+
request_dict = _GetRuntimeFeedbackOperationParameters_to_vertex(
|
|
625
|
+
parameter_model
|
|
626
|
+
)
|
|
627
|
+
request_url_dict = request_dict.get("_url")
|
|
628
|
+
if request_url_dict:
|
|
629
|
+
path = "{operationName}".format_map(request_url_dict)
|
|
630
|
+
else:
|
|
631
|
+
path = "{operationName}"
|
|
632
|
+
|
|
633
|
+
query_params = request_dict.get("_query")
|
|
634
|
+
if query_params:
|
|
635
|
+
path = f"{path}?{urlencode(query_params)}"
|
|
636
|
+
# TODO: remove the hack that pops config.
|
|
637
|
+
request_dict.pop("config", None)
|
|
638
|
+
|
|
639
|
+
http_options: Optional[types.HttpOptions] = None
|
|
640
|
+
if (
|
|
641
|
+
parameter_model.config is not None
|
|
642
|
+
and parameter_model.config.http_options is not None
|
|
643
|
+
):
|
|
644
|
+
http_options = parameter_model.config.http_options
|
|
645
|
+
|
|
646
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
647
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
648
|
+
|
|
649
|
+
response = self._api_client.request("get", path, request_dict, http_options)
|
|
650
|
+
|
|
651
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
652
|
+
|
|
653
|
+
return_value = types.RuntimeFeedbackEntryOperation._from_response(
|
|
654
|
+
response=response_dict,
|
|
655
|
+
kwargs=(
|
|
656
|
+
{
|
|
657
|
+
"config": {
|
|
658
|
+
"response_schema": getattr(
|
|
659
|
+
parameter_model.config, "response_schema", None
|
|
660
|
+
),
|
|
661
|
+
"response_json_schema": getattr(
|
|
662
|
+
parameter_model.config, "response_json_schema", None
|
|
663
|
+
),
|
|
664
|
+
"include_all_fields": getattr(
|
|
665
|
+
parameter_model.config, "include_all_fields", None
|
|
666
|
+
),
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
if getattr(parameter_model, "config", None)
|
|
670
|
+
else {}
|
|
671
|
+
),
|
|
672
|
+
)
|
|
673
|
+
|
|
674
|
+
self._api_client._verify_response(return_value)
|
|
675
|
+
return return_value
|
|
676
|
+
|
|
677
|
+
def _get_delete_feedback_entry_operation(
|
|
678
|
+
self,
|
|
679
|
+
*,
|
|
680
|
+
operation_name: str,
|
|
681
|
+
config: Optional[types.GetRuntimeFeedbackEntryConfigOrDict] = None,
|
|
682
|
+
) -> types.DeleteRuntimeFeedbackEntryOperation:
|
|
683
|
+
parameter_model = types._GetRuntimeFeedbackOperationParameters(
|
|
684
|
+
operation_name=operation_name,
|
|
685
|
+
config=config,
|
|
686
|
+
)
|
|
687
|
+
|
|
688
|
+
request_url_dict: Optional[dict[str, str]]
|
|
689
|
+
if not self._api_client.vertexai:
|
|
690
|
+
raise ValueError(
|
|
691
|
+
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
|
|
692
|
+
)
|
|
693
|
+
else:
|
|
694
|
+
request_dict = _GetRuntimeFeedbackOperationParameters_to_vertex(
|
|
695
|
+
parameter_model
|
|
696
|
+
)
|
|
697
|
+
request_url_dict = request_dict.get("_url")
|
|
698
|
+
if request_url_dict:
|
|
699
|
+
path = "{operationName}".format_map(request_url_dict)
|
|
700
|
+
else:
|
|
701
|
+
path = "{operationName}"
|
|
702
|
+
|
|
703
|
+
query_params = request_dict.get("_query")
|
|
704
|
+
if query_params:
|
|
705
|
+
path = f"{path}?{urlencode(query_params)}"
|
|
706
|
+
# TODO: remove the hack that pops config.
|
|
707
|
+
request_dict.pop("config", None)
|
|
708
|
+
|
|
709
|
+
http_options: Optional[types.HttpOptions] = None
|
|
710
|
+
if (
|
|
711
|
+
parameter_model.config is not None
|
|
712
|
+
and parameter_model.config.http_options is not None
|
|
713
|
+
):
|
|
714
|
+
http_options = parameter_model.config.http_options
|
|
715
|
+
|
|
716
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
717
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
718
|
+
|
|
719
|
+
response = self._api_client.request("get", path, request_dict, http_options)
|
|
720
|
+
|
|
721
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
722
|
+
|
|
723
|
+
return_value = types.DeleteRuntimeFeedbackEntryOperation._from_response(
|
|
724
|
+
response=response_dict,
|
|
725
|
+
kwargs=(
|
|
726
|
+
{
|
|
727
|
+
"config": {
|
|
728
|
+
"response_schema": getattr(
|
|
729
|
+
parameter_model.config, "response_schema", None
|
|
730
|
+
),
|
|
731
|
+
"response_json_schema": getattr(
|
|
732
|
+
parameter_model.config, "response_json_schema", None
|
|
733
|
+
),
|
|
734
|
+
"include_all_fields": getattr(
|
|
735
|
+
parameter_model.config, "include_all_fields", None
|
|
736
|
+
),
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
if getattr(parameter_model, "config", None)
|
|
740
|
+
else {}
|
|
741
|
+
),
|
|
742
|
+
)
|
|
743
|
+
|
|
744
|
+
self._api_client._verify_response(return_value)
|
|
745
|
+
return return_value
|
|
746
|
+
|
|
747
|
+
_feedback_contexts = None
|
|
748
|
+
|
|
749
|
+
@property
|
|
750
|
+
def feedback_contexts(self) -> "feedback_contexts_module.FeedbackContexts":
|
|
751
|
+
if self._feedback_contexts is None:
|
|
752
|
+
try:
|
|
753
|
+
# We need to lazy load the feedback_contexts module to handle the
|
|
754
|
+
# possibility of ImportError when dependencies are not installed.
|
|
755
|
+
self._feedback_contexts = importlib.import_module(
|
|
756
|
+
".feedback_contexts", __package__
|
|
757
|
+
)
|
|
758
|
+
except ImportError as e:
|
|
759
|
+
raise ImportError(
|
|
760
|
+
"The 'feedback_entries.feedback_contexts' module requires additional "
|
|
761
|
+
"packages. Please install them using pip install "
|
|
762
|
+
"google-cloud-aiplatform[agent_engines]"
|
|
763
|
+
) from e
|
|
764
|
+
return self._feedback_contexts.FeedbackContexts(
|
|
765
|
+
self._api_client
|
|
766
|
+
) # type: ignore[no-any-return]
|
|
767
|
+
|
|
768
|
+
def create(
|
|
769
|
+
self,
|
|
770
|
+
*,
|
|
771
|
+
name: str,
|
|
772
|
+
feedback_type: str,
|
|
773
|
+
session_id: str,
|
|
774
|
+
event_id: str,
|
|
775
|
+
config: Optional[types.CreateRuntimeFeedbackEntryConfigOrDict] = None,
|
|
776
|
+
) -> types.RuntimeFeedbackEntryOperation:
|
|
777
|
+
"""Creates a new Feedback Entry in the Runtime.
|
|
778
|
+
|
|
779
|
+
Args:
|
|
780
|
+
name (str): Required. Resource name of the Runtime to create the
|
|
781
|
+
Feedback Entry in. Format:
|
|
782
|
+
`projects/{project}/locations/{location}/reasoningEngines/{resource_id}`.
|
|
783
|
+
feedback_type (FeedbackType): Required. The type of feedback provided.
|
|
784
|
+
session_id (str): Required. The ID of the session to which the feedback
|
|
785
|
+
relates to.
|
|
786
|
+
event_id (str): Required. The ID of the event to which the feedback
|
|
787
|
+
relates to.
|
|
788
|
+
config (CreateRuntimeFeedbackEntryConfig):
|
|
789
|
+
Optional. Additional configurations for creating the Feedback Entry.
|
|
790
|
+
|
|
791
|
+
Returns:
|
|
792
|
+
RuntimeFeedbackEntryOperation: The operation for creating the
|
|
793
|
+
Feedback Entry.
|
|
794
|
+
"""
|
|
795
|
+
if config is None:
|
|
796
|
+
config = types.CreateRuntimeFeedbackEntryConfig()
|
|
797
|
+
elif isinstance(config, dict):
|
|
798
|
+
config = types.CreateRuntimeFeedbackEntryConfig.model_validate(config)
|
|
799
|
+
operation = self._create(
|
|
800
|
+
name=name,
|
|
801
|
+
session_id=session_id,
|
|
802
|
+
event_id=event_id,
|
|
803
|
+
feedback_type=feedback_type,
|
|
804
|
+
config=config,
|
|
805
|
+
)
|
|
806
|
+
if config.wait_for_completion:
|
|
807
|
+
if not operation.done:
|
|
808
|
+
operation = _agent_engines_utils._await_operation(
|
|
809
|
+
operation_name=operation.name,
|
|
810
|
+
get_operation_fn=self._get_feedback_entry_operation,
|
|
811
|
+
poll_interval_seconds=0.5,
|
|
812
|
+
)
|
|
813
|
+
if operation.error:
|
|
814
|
+
raise RuntimeError(
|
|
815
|
+
f"Failed to create Feedback Entry: {operation.error}"
|
|
816
|
+
)
|
|
817
|
+
return operation
|
|
818
|
+
|
|
819
|
+
def list(
|
|
820
|
+
self,
|
|
821
|
+
*,
|
|
822
|
+
parent: str,
|
|
823
|
+
config: Optional[types.ListRuntimeFeedbackEntriesConfigOrDict] = None,
|
|
824
|
+
) -> Iterator[types.FeedbackEntry]:
|
|
825
|
+
"""
|
|
826
|
+
Lists Feedback Entries in the Runtime.
|
|
827
|
+
|
|
828
|
+
Args:
|
|
829
|
+
parent (str): Required. Resource name of the Runtime to list the
|
|
830
|
+
Feedback Entries from. Format:
|
|
831
|
+
`projects/{project}/locations/{location}/reasoningEngines/{resource_id}`.
|
|
832
|
+
config (ListRuntimeFeedbackEntriesConfig):
|
|
833
|
+
Optional. The configuration for listing Feedback Entries.
|
|
834
|
+
|
|
835
|
+
Returns:
|
|
836
|
+
Iterable[FeedbackEntry]: A pager of Feedback Entries.
|
|
837
|
+
""",
|
|
838
|
+
|
|
839
|
+
return Pager(
|
|
840
|
+
"feedback_entries",
|
|
841
|
+
functools.partial(self._list, parent=parent),
|
|
842
|
+
self._list(parent=parent, config=config),
|
|
843
|
+
config,
|
|
844
|
+
)
|
|
845
|
+
|
|
846
|
+
def update(
|
|
847
|
+
self,
|
|
848
|
+
*,
|
|
849
|
+
name: str,
|
|
850
|
+
config: Optional[types.UpdateRuntimeFeedbackEntryConfigOrDict] = None,
|
|
851
|
+
) -> types.RuntimeFeedbackEntryOperation:
|
|
852
|
+
"""Updates a Feedback Entry in the Runtime.
|
|
853
|
+
|
|
854
|
+
Args:
|
|
855
|
+
name (str): Required. Name of the Feedback Entry. Format:
|
|
856
|
+
`projects/{project}/locations/{location}/reasoningEngines/{resource_id}/feedbackEntries/{feedback_entry_id}`.
|
|
857
|
+
feedback_type (str): Optional. The type of feedback provided.
|
|
858
|
+
config (UpdateRuntimeFeedbackEntryConfig):
|
|
859
|
+
Optional. Additional configurations for updating the Feedback Entry.
|
|
860
|
+
|
|
861
|
+
Returns:
|
|
862
|
+
RuntimeFeedbackEntryOperation: The operation for updating
|
|
863
|
+
the Feedback Entry.
|
|
864
|
+
"""
|
|
865
|
+
if config is None:
|
|
866
|
+
config = types.UpdateRuntimeFeedbackEntryConfig()
|
|
867
|
+
elif isinstance(config, dict):
|
|
868
|
+
config = types.UpdateRuntimeFeedbackEntryConfig.model_validate(config)
|
|
869
|
+
operation = self._update(
|
|
870
|
+
name=name,
|
|
871
|
+
config=config,
|
|
872
|
+
)
|
|
873
|
+
if config.wait_for_completion:
|
|
874
|
+
if not operation.done:
|
|
875
|
+
operation = _agent_engines_utils._await_operation(
|
|
876
|
+
operation_name=operation.name,
|
|
877
|
+
get_operation_fn=self._get_feedback_entry_operation,
|
|
878
|
+
poll_interval_seconds=0.5,
|
|
879
|
+
)
|
|
880
|
+
if operation.error:
|
|
881
|
+
raise RuntimeError(
|
|
882
|
+
f"Failed to update Feedback Entry: {operation.error}"
|
|
883
|
+
)
|
|
884
|
+
return operation
|
|
885
|
+
|
|
886
|
+
def delete(
|
|
887
|
+
self,
|
|
888
|
+
*,
|
|
889
|
+
name: str,
|
|
890
|
+
config: Optional[types.DeleteRuntimeFeedbackEntryConfigOrDict] = None,
|
|
891
|
+
) -> types.DeleteRuntimeFeedbackEntryOperation:
|
|
892
|
+
"""Deletes a Feedback Entry from the Runtime.
|
|
893
|
+
|
|
894
|
+
Args:
|
|
895
|
+
name (str): Required. Name of the Feedback Entry to delete. Format:
|
|
896
|
+
`projects/{project}/locations/{location}/reasoningEngines/{resource_id}/feedbackEntries/{feedback_entry_id}`.
|
|
897
|
+
config (DeleteRuntimeFeedbackEntryConfig):
|
|
898
|
+
Optional. The configuration for deleting the Feedback Entry.
|
|
899
|
+
|
|
900
|
+
Returns:
|
|
901
|
+
DeleteRuntimeFeedbackEntryOperation: The operation for deleting
|
|
902
|
+
the Feedback Entry.
|
|
903
|
+
"""
|
|
904
|
+
if config is None:
|
|
905
|
+
config = types.DeleteRuntimeFeedbackEntryConfig()
|
|
906
|
+
elif isinstance(config, dict):
|
|
907
|
+
config = types.DeleteRuntimeFeedbackEntryConfig.model_validate(config)
|
|
908
|
+
operation = self._delete(
|
|
909
|
+
name=name,
|
|
910
|
+
config=config,
|
|
911
|
+
)
|
|
912
|
+
if config.wait_for_completion:
|
|
913
|
+
if not operation.done:
|
|
914
|
+
operation = _agent_engines_utils._await_operation(
|
|
915
|
+
operation_name=operation.name,
|
|
916
|
+
get_operation_fn=self._get_delete_feedback_entry_operation,
|
|
917
|
+
poll_interval_seconds=0.5,
|
|
918
|
+
)
|
|
919
|
+
if operation.error:
|
|
920
|
+
raise RuntimeError(
|
|
921
|
+
f"Failed to delete Feedback Entry: {operation.error}"
|
|
922
|
+
)
|
|
923
|
+
return operation
|
|
924
|
+
|
|
925
|
+
|
|
926
|
+
class AsyncFeedbackEntries(_api_module.BaseModule):
|
|
927
|
+
|
|
928
|
+
async def _create(
|
|
929
|
+
self,
|
|
930
|
+
*,
|
|
931
|
+
name: str,
|
|
932
|
+
feedback_type: types.FeedbackType,
|
|
933
|
+
session_id: str,
|
|
934
|
+
event_id: str,
|
|
935
|
+
config: Optional[types.CreateRuntimeFeedbackEntryConfigOrDict] = None,
|
|
936
|
+
) -> types.RuntimeFeedbackEntryOperation:
|
|
937
|
+
parameter_model = types._CreateRuntimeFeedbackEntryRequestParameters(
|
|
938
|
+
name=name,
|
|
939
|
+
feedback_type=feedback_type,
|
|
940
|
+
session_id=session_id,
|
|
941
|
+
event_id=event_id,
|
|
942
|
+
config=config,
|
|
943
|
+
)
|
|
944
|
+
|
|
945
|
+
request_url_dict: Optional[dict[str, str]]
|
|
946
|
+
if not self._api_client.vertexai:
|
|
947
|
+
raise ValueError(
|
|
948
|
+
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
|
|
949
|
+
)
|
|
950
|
+
else:
|
|
951
|
+
request_dict = _CreateRuntimeFeedbackEntryRequestParameters_to_vertex(
|
|
952
|
+
parameter_model
|
|
953
|
+
)
|
|
954
|
+
request_url_dict = request_dict.get("_url")
|
|
955
|
+
if request_url_dict:
|
|
956
|
+
path = "{parent}/feedbackEntries".format_map(request_url_dict)
|
|
957
|
+
else:
|
|
958
|
+
path = "{parent}/feedbackEntries"
|
|
959
|
+
|
|
960
|
+
query_params = request_dict.get("_query")
|
|
961
|
+
if query_params:
|
|
962
|
+
path = f"{path}?{urlencode(query_params)}"
|
|
963
|
+
# TODO: remove the hack that pops config.
|
|
964
|
+
request_dict.pop("config", None)
|
|
965
|
+
|
|
966
|
+
http_options: Optional[types.HttpOptions] = None
|
|
967
|
+
if (
|
|
968
|
+
parameter_model.config is not None
|
|
969
|
+
and parameter_model.config.http_options is not None
|
|
970
|
+
):
|
|
971
|
+
http_options = parameter_model.config.http_options
|
|
972
|
+
|
|
973
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
974
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
975
|
+
|
|
976
|
+
response = await self._api_client.async_request(
|
|
977
|
+
"post", path, request_dict, http_options
|
|
978
|
+
)
|
|
979
|
+
|
|
980
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
981
|
+
|
|
982
|
+
return_value = types.RuntimeFeedbackEntryOperation._from_response(
|
|
983
|
+
response=response_dict,
|
|
984
|
+
kwargs=(
|
|
985
|
+
{
|
|
986
|
+
"config": {
|
|
987
|
+
"response_schema": getattr(
|
|
988
|
+
parameter_model.config, "response_schema", None
|
|
989
|
+
),
|
|
990
|
+
"response_json_schema": getattr(
|
|
991
|
+
parameter_model.config, "response_json_schema", None
|
|
992
|
+
),
|
|
993
|
+
"include_all_fields": getattr(
|
|
994
|
+
parameter_model.config, "include_all_fields", None
|
|
995
|
+
),
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
if getattr(parameter_model, "config", None)
|
|
999
|
+
else {}
|
|
1000
|
+
),
|
|
1001
|
+
)
|
|
1002
|
+
|
|
1003
|
+
self._api_client._verify_response(return_value)
|
|
1004
|
+
return return_value
|
|
1005
|
+
|
|
1006
|
+
async def _delete(
|
|
1007
|
+
self,
|
|
1008
|
+
*,
|
|
1009
|
+
name: str,
|
|
1010
|
+
config: Optional[types.DeleteRuntimeFeedbackEntryConfigOrDict] = None,
|
|
1011
|
+
) -> types.DeleteRuntimeFeedbackEntryOperation:
|
|
1012
|
+
parameter_model = types._DeleteRuntimeFeedbackEntryRequestParameters(
|
|
1013
|
+
name=name,
|
|
1014
|
+
config=config,
|
|
1015
|
+
)
|
|
1016
|
+
|
|
1017
|
+
request_url_dict: Optional[dict[str, str]]
|
|
1018
|
+
if not self._api_client.vertexai:
|
|
1019
|
+
raise ValueError(
|
|
1020
|
+
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
|
|
1021
|
+
)
|
|
1022
|
+
else:
|
|
1023
|
+
request_dict = _DeleteRuntimeFeedbackEntryRequestParameters_to_vertex(
|
|
1024
|
+
parameter_model
|
|
1025
|
+
)
|
|
1026
|
+
request_url_dict = request_dict.get("_url")
|
|
1027
|
+
if request_url_dict:
|
|
1028
|
+
path = "{name}".format_map(request_url_dict)
|
|
1029
|
+
else:
|
|
1030
|
+
path = "{name}"
|
|
1031
|
+
|
|
1032
|
+
query_params = request_dict.get("_query")
|
|
1033
|
+
if query_params:
|
|
1034
|
+
path = f"{path}?{urlencode(query_params)}"
|
|
1035
|
+
# TODO: remove the hack that pops config.
|
|
1036
|
+
request_dict.pop("config", None)
|
|
1037
|
+
|
|
1038
|
+
http_options: Optional[types.HttpOptions] = None
|
|
1039
|
+
if (
|
|
1040
|
+
parameter_model.config is not None
|
|
1041
|
+
and parameter_model.config.http_options is not None
|
|
1042
|
+
):
|
|
1043
|
+
http_options = parameter_model.config.http_options
|
|
1044
|
+
|
|
1045
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
1046
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
1047
|
+
|
|
1048
|
+
response = await self._api_client.async_request(
|
|
1049
|
+
"delete", path, request_dict, http_options
|
|
1050
|
+
)
|
|
1051
|
+
|
|
1052
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
1053
|
+
|
|
1054
|
+
return_value = types.DeleteRuntimeFeedbackEntryOperation._from_response(
|
|
1055
|
+
response=response_dict,
|
|
1056
|
+
kwargs=(
|
|
1057
|
+
{
|
|
1058
|
+
"config": {
|
|
1059
|
+
"response_schema": getattr(
|
|
1060
|
+
parameter_model.config, "response_schema", None
|
|
1061
|
+
),
|
|
1062
|
+
"response_json_schema": getattr(
|
|
1063
|
+
parameter_model.config, "response_json_schema", None
|
|
1064
|
+
),
|
|
1065
|
+
"include_all_fields": getattr(
|
|
1066
|
+
parameter_model.config, "include_all_fields", None
|
|
1067
|
+
),
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
if getattr(parameter_model, "config", None)
|
|
1071
|
+
else {}
|
|
1072
|
+
),
|
|
1073
|
+
)
|
|
1074
|
+
|
|
1075
|
+
self._api_client._verify_response(return_value)
|
|
1076
|
+
return return_value
|
|
1077
|
+
|
|
1078
|
+
async def get(
|
|
1079
|
+
self,
|
|
1080
|
+
*,
|
|
1081
|
+
name: str,
|
|
1082
|
+
config: Optional[types.GetRuntimeFeedbackConfigOrDict] = None,
|
|
1083
|
+
) -> types.FeedbackEntry:
|
|
1084
|
+
"""
|
|
1085
|
+
Gets a Runtime Feedback Entry.
|
|
1086
|
+
|
|
1087
|
+
Args:
|
|
1088
|
+
name (str): Required. The name of the Feedback Entry to retrieve. Format:
|
|
1089
|
+
`projects/{project}/locations/{location}/reasoningEngines/{resource_id}/feedbackEntries/{feedback_entry_id}`.
|
|
1090
|
+
config (GetRuntimeFeedbackConfig):
|
|
1091
|
+
Optional. The configuration for getting the Feedback Entry.
|
|
1092
|
+
|
|
1093
|
+
Returns:
|
|
1094
|
+
FeedbackEntry: The requested Feedback Entry.
|
|
1095
|
+
|
|
1096
|
+
"""
|
|
1097
|
+
|
|
1098
|
+
parameter_model = types._GetRuntimeFeedbackRequestParameters(
|
|
1099
|
+
name=name,
|
|
1100
|
+
config=config,
|
|
1101
|
+
)
|
|
1102
|
+
|
|
1103
|
+
request_url_dict: Optional[dict[str, str]]
|
|
1104
|
+
if not self._api_client.vertexai:
|
|
1105
|
+
raise ValueError(
|
|
1106
|
+
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
|
|
1107
|
+
)
|
|
1108
|
+
else:
|
|
1109
|
+
request_dict = _GetRuntimeFeedbackRequestParameters_to_vertex(
|
|
1110
|
+
parameter_model
|
|
1111
|
+
)
|
|
1112
|
+
request_url_dict = request_dict.get("_url")
|
|
1113
|
+
if request_url_dict:
|
|
1114
|
+
path = "{name}".format_map(request_url_dict)
|
|
1115
|
+
else:
|
|
1116
|
+
path = "{name}"
|
|
1117
|
+
|
|
1118
|
+
query_params = request_dict.get("_query")
|
|
1119
|
+
if query_params:
|
|
1120
|
+
path = f"{path}?{urlencode(query_params)}"
|
|
1121
|
+
# TODO: remove the hack that pops config.
|
|
1122
|
+
request_dict.pop("config", None)
|
|
1123
|
+
|
|
1124
|
+
http_options: Optional[types.HttpOptions] = None
|
|
1125
|
+
if (
|
|
1126
|
+
parameter_model.config is not None
|
|
1127
|
+
and parameter_model.config.http_options is not None
|
|
1128
|
+
):
|
|
1129
|
+
http_options = parameter_model.config.http_options
|
|
1130
|
+
|
|
1131
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
1132
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
1133
|
+
|
|
1134
|
+
response = await self._api_client.async_request(
|
|
1135
|
+
"get", path, request_dict, http_options
|
|
1136
|
+
)
|
|
1137
|
+
|
|
1138
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
1139
|
+
|
|
1140
|
+
return_value = types.FeedbackEntry._from_response(
|
|
1141
|
+
response=response_dict,
|
|
1142
|
+
kwargs=(
|
|
1143
|
+
{
|
|
1144
|
+
"config": {
|
|
1145
|
+
"response_schema": getattr(
|
|
1146
|
+
parameter_model.config, "response_schema", None
|
|
1147
|
+
),
|
|
1148
|
+
"response_json_schema": getattr(
|
|
1149
|
+
parameter_model.config, "response_json_schema", None
|
|
1150
|
+
),
|
|
1151
|
+
"include_all_fields": getattr(
|
|
1152
|
+
parameter_model.config, "include_all_fields", None
|
|
1153
|
+
),
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1156
|
+
if getattr(parameter_model, "config", None)
|
|
1157
|
+
else {}
|
|
1158
|
+
),
|
|
1159
|
+
)
|
|
1160
|
+
|
|
1161
|
+
self._api_client._verify_response(return_value)
|
|
1162
|
+
return return_value
|
|
1163
|
+
|
|
1164
|
+
async def _list(
|
|
1165
|
+
self,
|
|
1166
|
+
*,
|
|
1167
|
+
parent: str,
|
|
1168
|
+
config: Optional[types.ListRuntimeFeedbackEntriesConfigOrDict] = None,
|
|
1169
|
+
) -> types.ListRuntimeFeedbackEntriesResponse:
|
|
1170
|
+
parameter_model = types._ListRuntimeFeedbackEntriesRequestParameters(
|
|
1171
|
+
parent=parent,
|
|
1172
|
+
config=config,
|
|
1173
|
+
)
|
|
1174
|
+
|
|
1175
|
+
request_url_dict: Optional[dict[str, str]]
|
|
1176
|
+
if not self._api_client.vertexai:
|
|
1177
|
+
raise ValueError(
|
|
1178
|
+
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
|
|
1179
|
+
)
|
|
1180
|
+
else:
|
|
1181
|
+
request_dict = _ListRuntimeFeedbackEntriesRequestParameters_to_vertex(
|
|
1182
|
+
parameter_model
|
|
1183
|
+
)
|
|
1184
|
+
request_url_dict = request_dict.get("_url")
|
|
1185
|
+
if request_url_dict:
|
|
1186
|
+
path = "{parent}/feedbackEntries".format_map(request_url_dict)
|
|
1187
|
+
else:
|
|
1188
|
+
path = "{parent}/feedbackEntries"
|
|
1189
|
+
|
|
1190
|
+
query_params = request_dict.get("_query")
|
|
1191
|
+
if query_params:
|
|
1192
|
+
path = f"{path}?{urlencode(query_params)}"
|
|
1193
|
+
# TODO: remove the hack that pops config.
|
|
1194
|
+
request_dict.pop("config", None)
|
|
1195
|
+
|
|
1196
|
+
http_options: Optional[types.HttpOptions] = None
|
|
1197
|
+
if (
|
|
1198
|
+
parameter_model.config is not None
|
|
1199
|
+
and parameter_model.config.http_options is not None
|
|
1200
|
+
):
|
|
1201
|
+
http_options = parameter_model.config.http_options
|
|
1202
|
+
|
|
1203
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
1204
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
1205
|
+
|
|
1206
|
+
response = await self._api_client.async_request(
|
|
1207
|
+
"get", path, request_dict, http_options
|
|
1208
|
+
)
|
|
1209
|
+
|
|
1210
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
1211
|
+
|
|
1212
|
+
return_value = types.ListRuntimeFeedbackEntriesResponse._from_response(
|
|
1213
|
+
response=response_dict,
|
|
1214
|
+
kwargs=(
|
|
1215
|
+
{
|
|
1216
|
+
"config": {
|
|
1217
|
+
"response_schema": getattr(
|
|
1218
|
+
parameter_model.config, "response_schema", None
|
|
1219
|
+
),
|
|
1220
|
+
"response_json_schema": getattr(
|
|
1221
|
+
parameter_model.config, "response_json_schema", None
|
|
1222
|
+
),
|
|
1223
|
+
"include_all_fields": getattr(
|
|
1224
|
+
parameter_model.config, "include_all_fields", None
|
|
1225
|
+
),
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
if getattr(parameter_model, "config", None)
|
|
1229
|
+
else {}
|
|
1230
|
+
),
|
|
1231
|
+
)
|
|
1232
|
+
|
|
1233
|
+
self._api_client._verify_response(return_value)
|
|
1234
|
+
return return_value
|
|
1235
|
+
|
|
1236
|
+
async def _update(
|
|
1237
|
+
self,
|
|
1238
|
+
*,
|
|
1239
|
+
name: str,
|
|
1240
|
+
config: Optional[types.UpdateRuntimeFeedbackEntryConfigOrDict] = None,
|
|
1241
|
+
) -> types.RuntimeFeedbackEntryOperation:
|
|
1242
|
+
"""
|
|
1243
|
+
Updates a Feedback Entry.
|
|
1244
|
+
|
|
1245
|
+
Args:
|
|
1246
|
+
name (str): Required. Name of the Feedback Entry to update. Format:
|
|
1247
|
+
`projects/{project}/locations/{location}/reasoningEngines/{resource_id}/feedbackEntries/{feedback_entry_id}`.
|
|
1248
|
+
feedback_type (shared.FeedbackType): Optional. The type of feedback provided.
|
|
1249
|
+
config (UpdateRuntimeFeedbackEntryConfig): Optional. The configuration for updating the Feedback Entry.
|
|
1250
|
+
|
|
1251
|
+
Returns:
|
|
1252
|
+
RuntimeFeedbackEntryOperation: Operation for updating a Feedback Entry.
|
|
1253
|
+
|
|
1254
|
+
"""
|
|
1255
|
+
|
|
1256
|
+
parameter_model = types._UpdateRuntimeFeedbackEntryRequestParameters(
|
|
1257
|
+
name=name,
|
|
1258
|
+
config=config,
|
|
1259
|
+
)
|
|
1260
|
+
|
|
1261
|
+
request_url_dict: Optional[dict[str, str]]
|
|
1262
|
+
if not self._api_client.vertexai:
|
|
1263
|
+
raise ValueError(
|
|
1264
|
+
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
|
|
1265
|
+
)
|
|
1266
|
+
else:
|
|
1267
|
+
request_dict = _UpdateRuntimeFeedbackEntryRequestParameters_to_vertex(
|
|
1268
|
+
parameter_model
|
|
1269
|
+
)
|
|
1270
|
+
request_url_dict = request_dict.get("_url")
|
|
1271
|
+
if request_url_dict:
|
|
1272
|
+
path = "{name}".format_map(request_url_dict)
|
|
1273
|
+
else:
|
|
1274
|
+
path = "{name}"
|
|
1275
|
+
|
|
1276
|
+
query_params = request_dict.get("_query")
|
|
1277
|
+
if query_params:
|
|
1278
|
+
path = f"{path}?{urlencode(query_params)}"
|
|
1279
|
+
# TODO: remove the hack that pops config.
|
|
1280
|
+
request_dict.pop("config", None)
|
|
1281
|
+
|
|
1282
|
+
http_options: Optional[types.HttpOptions] = None
|
|
1283
|
+
if (
|
|
1284
|
+
parameter_model.config is not None
|
|
1285
|
+
and parameter_model.config.http_options is not None
|
|
1286
|
+
):
|
|
1287
|
+
http_options = parameter_model.config.http_options
|
|
1288
|
+
|
|
1289
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
1290
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
1291
|
+
|
|
1292
|
+
response = await self._api_client.async_request(
|
|
1293
|
+
"patch", path, request_dict, http_options
|
|
1294
|
+
)
|
|
1295
|
+
|
|
1296
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
1297
|
+
|
|
1298
|
+
return_value = types.RuntimeFeedbackEntryOperation._from_response(
|
|
1299
|
+
response=response_dict,
|
|
1300
|
+
kwargs=(
|
|
1301
|
+
{
|
|
1302
|
+
"config": {
|
|
1303
|
+
"response_schema": getattr(
|
|
1304
|
+
parameter_model.config, "response_schema", None
|
|
1305
|
+
),
|
|
1306
|
+
"response_json_schema": getattr(
|
|
1307
|
+
parameter_model.config, "response_json_schema", None
|
|
1308
|
+
),
|
|
1309
|
+
"include_all_fields": getattr(
|
|
1310
|
+
parameter_model.config, "include_all_fields", None
|
|
1311
|
+
),
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1314
|
+
if getattr(parameter_model, "config", None)
|
|
1315
|
+
else {}
|
|
1316
|
+
),
|
|
1317
|
+
)
|
|
1318
|
+
|
|
1319
|
+
self._api_client._verify_response(return_value)
|
|
1320
|
+
return return_value
|
|
1321
|
+
|
|
1322
|
+
async def _get_feedback_entry_operation(
|
|
1323
|
+
self,
|
|
1324
|
+
*,
|
|
1325
|
+
operation_name: str,
|
|
1326
|
+
config: Optional[types.GetRuntimeFeedbackEntryConfigOrDict] = None,
|
|
1327
|
+
) -> types.RuntimeFeedbackEntryOperation:
|
|
1328
|
+
parameter_model = types._GetRuntimeFeedbackOperationParameters(
|
|
1329
|
+
operation_name=operation_name,
|
|
1330
|
+
config=config,
|
|
1331
|
+
)
|
|
1332
|
+
|
|
1333
|
+
request_url_dict: Optional[dict[str, str]]
|
|
1334
|
+
if not self._api_client.vertexai:
|
|
1335
|
+
raise ValueError(
|
|
1336
|
+
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
|
|
1337
|
+
)
|
|
1338
|
+
else:
|
|
1339
|
+
request_dict = _GetRuntimeFeedbackOperationParameters_to_vertex(
|
|
1340
|
+
parameter_model
|
|
1341
|
+
)
|
|
1342
|
+
request_url_dict = request_dict.get("_url")
|
|
1343
|
+
if request_url_dict:
|
|
1344
|
+
path = "{operationName}".format_map(request_url_dict)
|
|
1345
|
+
else:
|
|
1346
|
+
path = "{operationName}"
|
|
1347
|
+
|
|
1348
|
+
query_params = request_dict.get("_query")
|
|
1349
|
+
if query_params:
|
|
1350
|
+
path = f"{path}?{urlencode(query_params)}"
|
|
1351
|
+
# TODO: remove the hack that pops config.
|
|
1352
|
+
request_dict.pop("config", None)
|
|
1353
|
+
|
|
1354
|
+
http_options: Optional[types.HttpOptions] = None
|
|
1355
|
+
if (
|
|
1356
|
+
parameter_model.config is not None
|
|
1357
|
+
and parameter_model.config.http_options is not None
|
|
1358
|
+
):
|
|
1359
|
+
http_options = parameter_model.config.http_options
|
|
1360
|
+
|
|
1361
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
1362
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
1363
|
+
|
|
1364
|
+
response = await self._api_client.async_request(
|
|
1365
|
+
"get", path, request_dict, http_options
|
|
1366
|
+
)
|
|
1367
|
+
|
|
1368
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
1369
|
+
|
|
1370
|
+
return_value = types.RuntimeFeedbackEntryOperation._from_response(
|
|
1371
|
+
response=response_dict,
|
|
1372
|
+
kwargs=(
|
|
1373
|
+
{
|
|
1374
|
+
"config": {
|
|
1375
|
+
"response_schema": getattr(
|
|
1376
|
+
parameter_model.config, "response_schema", None
|
|
1377
|
+
),
|
|
1378
|
+
"response_json_schema": getattr(
|
|
1379
|
+
parameter_model.config, "response_json_schema", None
|
|
1380
|
+
),
|
|
1381
|
+
"include_all_fields": getattr(
|
|
1382
|
+
parameter_model.config, "include_all_fields", None
|
|
1383
|
+
),
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1386
|
+
if getattr(parameter_model, "config", None)
|
|
1387
|
+
else {}
|
|
1388
|
+
),
|
|
1389
|
+
)
|
|
1390
|
+
|
|
1391
|
+
self._api_client._verify_response(return_value)
|
|
1392
|
+
return return_value
|
|
1393
|
+
|
|
1394
|
+
async def _get_delete_feedback_entry_operation(
|
|
1395
|
+
self,
|
|
1396
|
+
*,
|
|
1397
|
+
operation_name: str,
|
|
1398
|
+
config: Optional[types.GetRuntimeFeedbackEntryConfigOrDict] = None,
|
|
1399
|
+
) -> types.DeleteRuntimeFeedbackEntryOperation:
|
|
1400
|
+
parameter_model = types._GetRuntimeFeedbackOperationParameters(
|
|
1401
|
+
operation_name=operation_name,
|
|
1402
|
+
config=config,
|
|
1403
|
+
)
|
|
1404
|
+
|
|
1405
|
+
request_url_dict: Optional[dict[str, str]]
|
|
1406
|
+
if not self._api_client.vertexai:
|
|
1407
|
+
raise ValueError(
|
|
1408
|
+
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
|
|
1409
|
+
)
|
|
1410
|
+
else:
|
|
1411
|
+
request_dict = _GetRuntimeFeedbackOperationParameters_to_vertex(
|
|
1412
|
+
parameter_model
|
|
1413
|
+
)
|
|
1414
|
+
request_url_dict = request_dict.get("_url")
|
|
1415
|
+
if request_url_dict:
|
|
1416
|
+
path = "{operationName}".format_map(request_url_dict)
|
|
1417
|
+
else:
|
|
1418
|
+
path = "{operationName}"
|
|
1419
|
+
|
|
1420
|
+
query_params = request_dict.get("_query")
|
|
1421
|
+
if query_params:
|
|
1422
|
+
path = f"{path}?{urlencode(query_params)}"
|
|
1423
|
+
# TODO: remove the hack that pops config.
|
|
1424
|
+
request_dict.pop("config", None)
|
|
1425
|
+
|
|
1426
|
+
http_options: Optional[types.HttpOptions] = None
|
|
1427
|
+
if (
|
|
1428
|
+
parameter_model.config is not None
|
|
1429
|
+
and parameter_model.config.http_options is not None
|
|
1430
|
+
):
|
|
1431
|
+
http_options = parameter_model.config.http_options
|
|
1432
|
+
|
|
1433
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
1434
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
1435
|
+
|
|
1436
|
+
response = await self._api_client.async_request(
|
|
1437
|
+
"get", path, request_dict, http_options
|
|
1438
|
+
)
|
|
1439
|
+
|
|
1440
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
1441
|
+
|
|
1442
|
+
return_value = types.DeleteRuntimeFeedbackEntryOperation._from_response(
|
|
1443
|
+
response=response_dict,
|
|
1444
|
+
kwargs=(
|
|
1445
|
+
{
|
|
1446
|
+
"config": {
|
|
1447
|
+
"response_schema": getattr(
|
|
1448
|
+
parameter_model.config, "response_schema", None
|
|
1449
|
+
),
|
|
1450
|
+
"response_json_schema": getattr(
|
|
1451
|
+
parameter_model.config, "response_json_schema", None
|
|
1452
|
+
),
|
|
1453
|
+
"include_all_fields": getattr(
|
|
1454
|
+
parameter_model.config, "include_all_fields", None
|
|
1455
|
+
),
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1458
|
+
if getattr(parameter_model, "config", None)
|
|
1459
|
+
else {}
|
|
1460
|
+
),
|
|
1461
|
+
)
|
|
1462
|
+
|
|
1463
|
+
self._api_client._verify_response(return_value)
|
|
1464
|
+
return return_value
|
|
1465
|
+
|
|
1466
|
+
_feedback_contexts = None
|
|
1467
|
+
|
|
1468
|
+
@property
|
|
1469
|
+
def feedback_contexts(self) -> "feedback_contexts_module.FeedbackContexts":
|
|
1470
|
+
if self._feedback_contexts is None:
|
|
1471
|
+
try:
|
|
1472
|
+
# We need to lazy load the feedback_contexts module to handle the
|
|
1473
|
+
# possibility of ImportError when dependencies are not installed.
|
|
1474
|
+
self._feedback_contexts = importlib.import_module(
|
|
1475
|
+
".feedback_contexts", __package__
|
|
1476
|
+
)
|
|
1477
|
+
except ImportError as e:
|
|
1478
|
+
raise ImportError(
|
|
1479
|
+
"The 'feedback_entries.feedback_contexts' module requires additional "
|
|
1480
|
+
"packages. Please install them using pip install "
|
|
1481
|
+
"google-cloud-aiplatform[agent_engines]"
|
|
1482
|
+
) from e
|
|
1483
|
+
return self._feedback_contexts.AsyncFeedbackContexts(
|
|
1484
|
+
self._api_client
|
|
1485
|
+
) # type: ignore[no-any-return]
|
|
1486
|
+
|
|
1487
|
+
async def create(
|
|
1488
|
+
self,
|
|
1489
|
+
*,
|
|
1490
|
+
name: str,
|
|
1491
|
+
feedback_type: types.FeedbackType,
|
|
1492
|
+
session_id: str,
|
|
1493
|
+
event_id: str,
|
|
1494
|
+
config: Optional[types.CreateRuntimeFeedbackEntryConfigOrDict] = None,
|
|
1495
|
+
) -> types.RuntimeFeedbackEntryOperation:
|
|
1496
|
+
"""
|
|
1497
|
+
Creates a new Feedback Entry in the Runtime.
|
|
1498
|
+
|
|
1499
|
+
Args:
|
|
1500
|
+
name (str): Required. Resource name of the Runtime to create
|
|
1501
|
+
the Feedback Entry in. Format:
|
|
1502
|
+
`projects/{project}/locations/{location}/reasoningEngines/{resource_id}`.
|
|
1503
|
+
feedback_type (FeedbackType): Required. The type of feedback provided.
|
|
1504
|
+
session_id (str): Required. The ID of the session to which the feedback
|
|
1505
|
+
relates to.
|
|
1506
|
+
event_id (str): Required. The ID of the event to which the feedback
|
|
1507
|
+
relates to.
|
|
1508
|
+
config (CreateRuntimeFeedbackEntryConfig):
|
|
1509
|
+
Optional. Additional configurations for creating the Feedback Entry.
|
|
1510
|
+
|
|
1511
|
+
Returns:
|
|
1512
|
+
RuntimeFeedbackEntryOperation: The operation for creating the
|
|
1513
|
+
Feedback Entry.
|
|
1514
|
+
|
|
1515
|
+
"""
|
|
1516
|
+
if config is None:
|
|
1517
|
+
config = types.CreateRuntimeFeedbackEntryConfig()
|
|
1518
|
+
elif isinstance(config, dict):
|
|
1519
|
+
config = types.CreateRuntimeFeedbackEntryConfig.model_validate(config)
|
|
1520
|
+
operation = await self._create(
|
|
1521
|
+
name=name,
|
|
1522
|
+
session_id=session_id,
|
|
1523
|
+
event_id=event_id,
|
|
1524
|
+
feedback_type=feedback_type,
|
|
1525
|
+
config=config,
|
|
1526
|
+
)
|
|
1527
|
+
if config.wait_for_completion:
|
|
1528
|
+
if not operation.done:
|
|
1529
|
+
operation = await _agent_engines_utils._await_async_operation(
|
|
1530
|
+
operation_name=operation.name,
|
|
1531
|
+
get_operation_fn=self._get_feedback_entry_operation,
|
|
1532
|
+
poll_interval_seconds=0.5,
|
|
1533
|
+
)
|
|
1534
|
+
if operation.error:
|
|
1535
|
+
raise RuntimeError(
|
|
1536
|
+
f"Failed to create Feedback Entry: {operation.error}"
|
|
1537
|
+
)
|
|
1538
|
+
return operation
|
|
1539
|
+
|
|
1540
|
+
async def list(
|
|
1541
|
+
self,
|
|
1542
|
+
*,
|
|
1543
|
+
parent: str,
|
|
1544
|
+
config: Optional[types.ListRuntimeFeedbackEntriesConfigOrDict] = None,
|
|
1545
|
+
) -> AsyncIterator[types.FeedbackEntry]:
|
|
1546
|
+
"""
|
|
1547
|
+
Lists Feedback Entries in the Runtime.
|
|
1548
|
+
|
|
1549
|
+
Args:
|
|
1550
|
+
parent (str): Required. Resource name of the Runtime to list the
|
|
1551
|
+
Feedback Entries from. Format:
|
|
1552
|
+
`projects/{project}/locations/{location}/reasoningEngines/{resource_id}`.
|
|
1553
|
+
config (ListRuntimeFeedbackEntriesConfigOrDict):
|
|
1554
|
+
Optional. The configuration for listing Feedback Entries.
|
|
1555
|
+
|
|
1556
|
+
Returns:
|
|
1557
|
+
AsyncPager[FeedbackEntry]: An async pager of Feedback Entries.
|
|
1558
|
+
""",
|
|
1559
|
+
|
|
1560
|
+
return AsyncPager(
|
|
1561
|
+
"feedback_entries",
|
|
1562
|
+
functools.partial(self._list, parent=parent),
|
|
1563
|
+
await self._list(parent=parent, config=config),
|
|
1564
|
+
config,
|
|
1565
|
+
)
|
|
1566
|
+
|
|
1567
|
+
async def update(
|
|
1568
|
+
self,
|
|
1569
|
+
*,
|
|
1570
|
+
name: str,
|
|
1571
|
+
config: Optional[types.UpdateRuntimeFeedbackEntryConfigOrDict] = None,
|
|
1572
|
+
) -> types.RuntimeFeedbackEntryOperation:
|
|
1573
|
+
"""Updates a Feedback Entry in the Runtime.
|
|
1574
|
+
|
|
1575
|
+
Args:
|
|
1576
|
+
name (str): Required. Name of the Feedback Entry. Format:
|
|
1577
|
+
`projects/{project}/locations/{location}/reasoningEngines/{resource_id}/feedbackEntries/{feedback_entry_id}`.
|
|
1578
|
+
feedback_type (str): Optional. The type of feedback provided.
|
|
1579
|
+
config (UpdateRuntimeFeedbackEntryConfig):
|
|
1580
|
+
Optional. Additional configurations for updating the Feedback Entry.
|
|
1581
|
+
|
|
1582
|
+
Returns:
|
|
1583
|
+
RuntimeFeedbackEntryOperation: The operation for updating
|
|
1584
|
+
the Feedback Entry.
|
|
1585
|
+
"""
|
|
1586
|
+
if config is None:
|
|
1587
|
+
config = types.UpdateRuntimeFeedbackEntryConfig()
|
|
1588
|
+
elif isinstance(config, dict):
|
|
1589
|
+
config = types.UpdateRuntimeFeedbackEntryConfig.model_validate(config)
|
|
1590
|
+
operation = await self._update(
|
|
1591
|
+
name=name,
|
|
1592
|
+
config=config,
|
|
1593
|
+
)
|
|
1594
|
+
if config.wait_for_completion:
|
|
1595
|
+
if not operation.done:
|
|
1596
|
+
operation = await _agent_engines_utils._await_async_operation(
|
|
1597
|
+
operation_name=operation.name,
|
|
1598
|
+
get_operation_fn=self._get_feedback_entry_operation,
|
|
1599
|
+
poll_interval_seconds=0.5,
|
|
1600
|
+
)
|
|
1601
|
+
if operation.error:
|
|
1602
|
+
raise RuntimeError(
|
|
1603
|
+
f"Failed to update Feedback Entry: {operation.error}"
|
|
1604
|
+
)
|
|
1605
|
+
return operation
|
|
1606
|
+
|
|
1607
|
+
async def delete(
|
|
1608
|
+
self,
|
|
1609
|
+
*,
|
|
1610
|
+
name: str,
|
|
1611
|
+
config: Optional[types.DeleteRuntimeFeedbackEntryConfigOrDict] = None,
|
|
1612
|
+
) -> types.DeleteRuntimeFeedbackEntryOperation:
|
|
1613
|
+
"""Deletes a Feedback Entry from the Runtime.
|
|
1614
|
+
|
|
1615
|
+
Args:
|
|
1616
|
+
name (str): Required. Name of the Feedback Entry to delete. Format:
|
|
1617
|
+
`projects/{project}/locations/{location}/reasoningEngines/{resource_id}/feedbackEntries/{feedback_entry_id}`.
|
|
1618
|
+
config (DeleteRuntimeFeedbackEntryConfig):
|
|
1619
|
+
Optional. The configuration for deleting the Feedback Entry.
|
|
1620
|
+
|
|
1621
|
+
Returns:
|
|
1622
|
+
DeleteRuntimeFeedbackEntryOperation: The operation for deleting
|
|
1623
|
+
the Feedback Entry.
|
|
1624
|
+
"""
|
|
1625
|
+
if config is None:
|
|
1626
|
+
config = types.DeleteRuntimeFeedbackEntryConfig()
|
|
1627
|
+
elif isinstance(config, dict):
|
|
1628
|
+
config = types.DeleteRuntimeFeedbackEntryConfig.model_validate(config)
|
|
1629
|
+
operation = await self._delete(
|
|
1630
|
+
name=name,
|
|
1631
|
+
config=config,
|
|
1632
|
+
)
|
|
1633
|
+
if config.wait_for_completion:
|
|
1634
|
+
if not operation.done:
|
|
1635
|
+
operation = await _agent_engines_utils._await_async_operation(
|
|
1636
|
+
operation_name=operation.name,
|
|
1637
|
+
get_operation_fn=self._get_delete_feedback_entry_operation,
|
|
1638
|
+
poll_interval_seconds=0.5,
|
|
1639
|
+
)
|
|
1640
|
+
if operation.error:
|
|
1641
|
+
raise RuntimeError(
|
|
1642
|
+
f"Failed to delete Feedback Entry: {operation.error}"
|
|
1643
|
+
)
|
|
1644
|
+
return operation
|