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,700 @@
|
|
|
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 json
|
|
19
|
+
import logging
|
|
20
|
+
from typing import Any, Optional, Union
|
|
21
|
+
from urllib.parse import urlencode
|
|
22
|
+
|
|
23
|
+
from google.genai import _api_module
|
|
24
|
+
from google.genai import _common
|
|
25
|
+
from google.genai._common import get_value_by_path as getv
|
|
26
|
+
from google.genai._common import set_value_by_path as setv
|
|
27
|
+
|
|
28
|
+
from . import _agent_engines_utils
|
|
29
|
+
from . import types
|
|
30
|
+
|
|
31
|
+
logger = logging.getLogger("agentplatform_genai.feedbackcontexts")
|
|
32
|
+
|
|
33
|
+
logger.setLevel(logging.INFO)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _GetRuntimeFeedbackContextOperationParameters_to_vertex(
|
|
37
|
+
from_object: Union[dict[str, Any], object],
|
|
38
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
39
|
+
) -> dict[str, Any]:
|
|
40
|
+
to_object: dict[str, Any] = {}
|
|
41
|
+
if getv(from_object, ["operation_name"]) is not None:
|
|
42
|
+
setv(
|
|
43
|
+
to_object, ["_url", "operationName"], getv(from_object, ["operation_name"])
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
return to_object
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _GetRuntimeFeedbackContextRequestParameters_to_vertex(
|
|
50
|
+
from_object: Union[dict[str, Any], object],
|
|
51
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
52
|
+
) -> dict[str, Any]:
|
|
53
|
+
to_object: dict[str, Any] = {}
|
|
54
|
+
if getv(from_object, ["name"]) is not None:
|
|
55
|
+
setv(to_object, ["_url", "name"], getv(from_object, ["name"]))
|
|
56
|
+
|
|
57
|
+
return to_object
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def _UpdateRuntimeFeedbackContextConfig_to_vertex(
|
|
61
|
+
from_object: Union[dict[str, Any], object],
|
|
62
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
63
|
+
) -> dict[str, Any]:
|
|
64
|
+
to_object: dict[str, Any] = {}
|
|
65
|
+
|
|
66
|
+
if getv(from_object, ["update_mask"]) is not None:
|
|
67
|
+
setv(
|
|
68
|
+
parent_object, ["_query", "updateMask"], getv(from_object, ["update_mask"])
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
return to_object
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def _UpdateRuntimeFeedbackContextRequestParameters_to_vertex(
|
|
75
|
+
from_object: Union[dict[str, Any], object],
|
|
76
|
+
parent_object: Optional[dict[str, Any]] = None,
|
|
77
|
+
) -> dict[str, Any]:
|
|
78
|
+
to_object: dict[str, Any] = {}
|
|
79
|
+
if getv(from_object, ["name"]) is not None:
|
|
80
|
+
setv(to_object, ["_url", "name"], getv(from_object, ["name"]))
|
|
81
|
+
|
|
82
|
+
if getv(from_object, ["context_events"]) is not None:
|
|
83
|
+
setv(
|
|
84
|
+
to_object,
|
|
85
|
+
["contextEvents"],
|
|
86
|
+
[item for item in getv(from_object, ["context_events"])],
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
if getv(from_object, ["config"]) is not None:
|
|
90
|
+
_UpdateRuntimeFeedbackContextConfig_to_vertex(
|
|
91
|
+
getv(from_object, ["config"]), to_object
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
return to_object
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
class FeedbackContexts(_api_module.BaseModule):
|
|
98
|
+
|
|
99
|
+
def _get(
|
|
100
|
+
self,
|
|
101
|
+
*,
|
|
102
|
+
name: str,
|
|
103
|
+
config: Optional[types.GetRuntimeFeedbackContextConfigOrDict] = None,
|
|
104
|
+
) -> types.FeedbackContext:
|
|
105
|
+
"""
|
|
106
|
+
Gets a Runtime Feedback Context.
|
|
107
|
+
|
|
108
|
+
Args:
|
|
109
|
+
name (str): Required. The name of the Feedback Context to retrieve. Format:
|
|
110
|
+
`projects/{project}/locations/{location}/reasoningEngines/{resource_id}/feedbackEntries/{feedback_entry_id}/feedbackContext`.
|
|
111
|
+
config (GetRuntimeFeedbackContextConfig):
|
|
112
|
+
Optional. The configuration for getting the Feedback Context.
|
|
113
|
+
|
|
114
|
+
Returns:
|
|
115
|
+
FeedbackContext: The requested Feedback Context.
|
|
116
|
+
|
|
117
|
+
"""
|
|
118
|
+
|
|
119
|
+
parameter_model = types._GetRuntimeFeedbackContextRequestParameters(
|
|
120
|
+
name=name,
|
|
121
|
+
config=config,
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
request_url_dict: Optional[dict[str, str]]
|
|
125
|
+
if not self._api_client.vertexai:
|
|
126
|
+
raise ValueError(
|
|
127
|
+
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
|
|
128
|
+
)
|
|
129
|
+
else:
|
|
130
|
+
request_dict = _GetRuntimeFeedbackContextRequestParameters_to_vertex(
|
|
131
|
+
parameter_model
|
|
132
|
+
)
|
|
133
|
+
request_url_dict = request_dict.get("_url")
|
|
134
|
+
if request_url_dict:
|
|
135
|
+
path = "{name}".format_map(request_url_dict)
|
|
136
|
+
else:
|
|
137
|
+
path = "{name}"
|
|
138
|
+
|
|
139
|
+
query_params = request_dict.get("_query")
|
|
140
|
+
if query_params:
|
|
141
|
+
path = f"{path}?{urlencode(query_params)}"
|
|
142
|
+
# TODO: remove the hack that pops config.
|
|
143
|
+
request_dict.pop("config", None)
|
|
144
|
+
|
|
145
|
+
http_options: Optional[types.HttpOptions] = None
|
|
146
|
+
if (
|
|
147
|
+
parameter_model.config is not None
|
|
148
|
+
and parameter_model.config.http_options is not None
|
|
149
|
+
):
|
|
150
|
+
http_options = parameter_model.config.http_options
|
|
151
|
+
|
|
152
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
153
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
154
|
+
|
|
155
|
+
response = self._api_client.request("get", path, request_dict, http_options)
|
|
156
|
+
|
|
157
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
158
|
+
|
|
159
|
+
return_value = types.FeedbackContext._from_response(
|
|
160
|
+
response=response_dict,
|
|
161
|
+
kwargs=(
|
|
162
|
+
{
|
|
163
|
+
"config": {
|
|
164
|
+
"response_schema": getattr(
|
|
165
|
+
parameter_model.config, "response_schema", None
|
|
166
|
+
),
|
|
167
|
+
"response_json_schema": getattr(
|
|
168
|
+
parameter_model.config, "response_json_schema", None
|
|
169
|
+
),
|
|
170
|
+
"include_all_fields": getattr(
|
|
171
|
+
parameter_model.config, "include_all_fields", None
|
|
172
|
+
),
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if getattr(parameter_model, "config", None)
|
|
176
|
+
else {}
|
|
177
|
+
),
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
self._api_client._verify_response(return_value)
|
|
181
|
+
return return_value
|
|
182
|
+
|
|
183
|
+
def _get_feedback_context_operation(
|
|
184
|
+
self,
|
|
185
|
+
*,
|
|
186
|
+
operation_name: str,
|
|
187
|
+
config: Optional[types.GetRuntimeFeedbackContextOperationConfigOrDict] = None,
|
|
188
|
+
) -> types.RuntimeFeedbackContextOperation:
|
|
189
|
+
parameter_model = types._GetRuntimeFeedbackContextOperationParameters(
|
|
190
|
+
operation_name=operation_name,
|
|
191
|
+
config=config,
|
|
192
|
+
)
|
|
193
|
+
|
|
194
|
+
request_url_dict: Optional[dict[str, str]]
|
|
195
|
+
if not self._api_client.vertexai:
|
|
196
|
+
raise ValueError(
|
|
197
|
+
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
|
|
198
|
+
)
|
|
199
|
+
else:
|
|
200
|
+
request_dict = _GetRuntimeFeedbackContextOperationParameters_to_vertex(
|
|
201
|
+
parameter_model
|
|
202
|
+
)
|
|
203
|
+
request_url_dict = request_dict.get("_url")
|
|
204
|
+
if request_url_dict:
|
|
205
|
+
path = "{operation_name}".format_map(request_url_dict)
|
|
206
|
+
else:
|
|
207
|
+
path = "{operation_name}"
|
|
208
|
+
|
|
209
|
+
query_params = request_dict.get("_query")
|
|
210
|
+
if query_params:
|
|
211
|
+
path = f"{path}?{urlencode(query_params)}"
|
|
212
|
+
# TODO: remove the hack that pops config.
|
|
213
|
+
request_dict.pop("config", None)
|
|
214
|
+
|
|
215
|
+
http_options: Optional[types.HttpOptions] = None
|
|
216
|
+
if (
|
|
217
|
+
parameter_model.config is not None
|
|
218
|
+
and parameter_model.config.http_options is not None
|
|
219
|
+
):
|
|
220
|
+
http_options = parameter_model.config.http_options
|
|
221
|
+
|
|
222
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
223
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
224
|
+
|
|
225
|
+
response = self._api_client.request("get", path, request_dict, http_options)
|
|
226
|
+
|
|
227
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
228
|
+
|
|
229
|
+
return_value = types.RuntimeFeedbackContextOperation._from_response(
|
|
230
|
+
response=response_dict,
|
|
231
|
+
kwargs=(
|
|
232
|
+
{
|
|
233
|
+
"config": {
|
|
234
|
+
"response_schema": getattr(
|
|
235
|
+
parameter_model.config, "response_schema", None
|
|
236
|
+
),
|
|
237
|
+
"response_json_schema": getattr(
|
|
238
|
+
parameter_model.config, "response_json_schema", None
|
|
239
|
+
),
|
|
240
|
+
"include_all_fields": getattr(
|
|
241
|
+
parameter_model.config, "include_all_fields", None
|
|
242
|
+
),
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
if getattr(parameter_model, "config", None)
|
|
246
|
+
else {}
|
|
247
|
+
),
|
|
248
|
+
)
|
|
249
|
+
|
|
250
|
+
self._api_client._verify_response(return_value)
|
|
251
|
+
return return_value
|
|
252
|
+
|
|
253
|
+
def _update(
|
|
254
|
+
self,
|
|
255
|
+
*,
|
|
256
|
+
name: str,
|
|
257
|
+
context_events: Optional[list[types.SessionEventOrDict]] = None,
|
|
258
|
+
config: Optional[types.UpdateRuntimeFeedbackContextConfigOrDict] = None,
|
|
259
|
+
) -> types.RuntimeFeedbackContextOperation:
|
|
260
|
+
"""
|
|
261
|
+
Updates a Feedback Context.
|
|
262
|
+
"""
|
|
263
|
+
|
|
264
|
+
parameter_model = types._UpdateRuntimeFeedbackContextRequestParameters(
|
|
265
|
+
name=name,
|
|
266
|
+
context_events=context_events,
|
|
267
|
+
config=config,
|
|
268
|
+
)
|
|
269
|
+
|
|
270
|
+
request_url_dict: Optional[dict[str, str]]
|
|
271
|
+
if not self._api_client.vertexai:
|
|
272
|
+
raise ValueError(
|
|
273
|
+
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
|
|
274
|
+
)
|
|
275
|
+
else:
|
|
276
|
+
request_dict = _UpdateRuntimeFeedbackContextRequestParameters_to_vertex(
|
|
277
|
+
parameter_model
|
|
278
|
+
)
|
|
279
|
+
request_url_dict = request_dict.get("_url")
|
|
280
|
+
if request_url_dict:
|
|
281
|
+
path = "{name}".format_map(request_url_dict)
|
|
282
|
+
else:
|
|
283
|
+
path = "{name}"
|
|
284
|
+
|
|
285
|
+
query_params = request_dict.get("_query")
|
|
286
|
+
if query_params:
|
|
287
|
+
path = f"{path}?{urlencode(query_params)}"
|
|
288
|
+
# TODO: remove the hack that pops config.
|
|
289
|
+
request_dict.pop("config", None)
|
|
290
|
+
|
|
291
|
+
http_options: Optional[types.HttpOptions] = None
|
|
292
|
+
if (
|
|
293
|
+
parameter_model.config is not None
|
|
294
|
+
and parameter_model.config.http_options is not None
|
|
295
|
+
):
|
|
296
|
+
http_options = parameter_model.config.http_options
|
|
297
|
+
|
|
298
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
299
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
300
|
+
|
|
301
|
+
response = self._api_client.request("patch", path, request_dict, http_options)
|
|
302
|
+
|
|
303
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
304
|
+
|
|
305
|
+
return_value = types.RuntimeFeedbackContextOperation._from_response(
|
|
306
|
+
response=response_dict,
|
|
307
|
+
kwargs=(
|
|
308
|
+
{
|
|
309
|
+
"config": {
|
|
310
|
+
"response_schema": getattr(
|
|
311
|
+
parameter_model.config, "response_schema", None
|
|
312
|
+
),
|
|
313
|
+
"response_json_schema": getattr(
|
|
314
|
+
parameter_model.config, "response_json_schema", None
|
|
315
|
+
),
|
|
316
|
+
"include_all_fields": getattr(
|
|
317
|
+
parameter_model.config, "include_all_fields", None
|
|
318
|
+
),
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
if getattr(parameter_model, "config", None)
|
|
322
|
+
else {}
|
|
323
|
+
),
|
|
324
|
+
)
|
|
325
|
+
|
|
326
|
+
self._api_client._verify_response(return_value)
|
|
327
|
+
return return_value
|
|
328
|
+
|
|
329
|
+
def get(
|
|
330
|
+
self,
|
|
331
|
+
*,
|
|
332
|
+
parent: str,
|
|
333
|
+
config: Optional[types.GetRuntimeFeedbackContextConfigOrDict] = None,
|
|
334
|
+
) -> types.FeedbackContext:
|
|
335
|
+
"""Gets the Feedback Context from the Runtime.
|
|
336
|
+
|
|
337
|
+
Args:
|
|
338
|
+
parent (str): Required. Resource name of the parent Feedback Entry. Format:
|
|
339
|
+
`projects/{project}/locations/{location}/reasoningEngines/{resource_id}/feedbackEntries/{feedback_entry_id}`.
|
|
340
|
+
config (GetRuntimeFeedbackContextConfig):
|
|
341
|
+
Optional. Additional configurations for getting the Feedback Context.
|
|
342
|
+
|
|
343
|
+
Returns:
|
|
344
|
+
FeedbackContext: The requested Feedback Context.
|
|
345
|
+
"""
|
|
346
|
+
if config is None:
|
|
347
|
+
config = types.GetRuntimeFeedbackContextConfig()
|
|
348
|
+
elif isinstance(config, dict):
|
|
349
|
+
config = types.GetRuntimeFeedbackContextConfig.model_validate(config)
|
|
350
|
+
return self._get(
|
|
351
|
+
name=f"{parent}/feedbackContext",
|
|
352
|
+
config=config,
|
|
353
|
+
)
|
|
354
|
+
|
|
355
|
+
def update(
|
|
356
|
+
self,
|
|
357
|
+
*,
|
|
358
|
+
parent: str,
|
|
359
|
+
context_events: Optional[list[types.SessionEvent]] = None,
|
|
360
|
+
config: Optional[types.UpdateRuntimeFeedbackContextConfigOrDict] = None,
|
|
361
|
+
) -> types.RuntimeFeedbackContextOperation:
|
|
362
|
+
"""Updates a Feedback Context in the Runtime.
|
|
363
|
+
|
|
364
|
+
Args:
|
|
365
|
+
parent (str): Required. Resource name of the parent Feedback Entry. Format:
|
|
366
|
+
`projects/{project}/locations/{location}/reasoningEngines/{resource_id}/feedbackEntries/{feedback_entry_id}`.
|
|
367
|
+
context_events (list[SessionEvent]): Optional. Events from the conversation relevant to the parent Feedback Entry.
|
|
368
|
+
config (UpdateRuntimeFeedbackContextConfig):
|
|
369
|
+
Optional. Additional configurations for updating the Feedback Context.
|
|
370
|
+
|
|
371
|
+
Returns:
|
|
372
|
+
RuntimeFeedbackContextOperation: The operation for updating the Feedback Context.
|
|
373
|
+
"""
|
|
374
|
+
if config is None:
|
|
375
|
+
config = types.UpdateRuntimeFeedbackContextConfig()
|
|
376
|
+
elif isinstance(config, dict):
|
|
377
|
+
config = types.UpdateRuntimeFeedbackContextConfig.model_validate(config)
|
|
378
|
+
operation = self._update(
|
|
379
|
+
name=f"{parent}/feedbackContext",
|
|
380
|
+
context_events=context_events,
|
|
381
|
+
config=config,
|
|
382
|
+
)
|
|
383
|
+
if config.wait_for_completion:
|
|
384
|
+
if not operation.done:
|
|
385
|
+
operation = _agent_engines_utils._await_operation(
|
|
386
|
+
operation_name=operation.name,
|
|
387
|
+
get_operation_fn=self._get_feedback_context_operation,
|
|
388
|
+
poll_interval_seconds=0.5,
|
|
389
|
+
)
|
|
390
|
+
if operation.error:
|
|
391
|
+
raise RuntimeError(
|
|
392
|
+
f"Failed to update Feedback Context: {operation.error}"
|
|
393
|
+
)
|
|
394
|
+
return operation
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
class AsyncFeedbackContexts(_api_module.BaseModule):
|
|
398
|
+
|
|
399
|
+
async def _get(
|
|
400
|
+
self,
|
|
401
|
+
*,
|
|
402
|
+
name: str,
|
|
403
|
+
config: Optional[types.GetRuntimeFeedbackContextConfigOrDict] = None,
|
|
404
|
+
) -> types.FeedbackContext:
|
|
405
|
+
"""
|
|
406
|
+
Gets a Runtime Feedback Context.
|
|
407
|
+
|
|
408
|
+
Args:
|
|
409
|
+
name (str): Required. The name of the Feedback Context to retrieve. Format:
|
|
410
|
+
`projects/{project}/locations/{location}/reasoningEngines/{resource_id}/feedbackEntries/{feedback_entry_id}/feedbackContext`.
|
|
411
|
+
config (GetRuntimeFeedbackContextConfig):
|
|
412
|
+
Optional. The configuration for getting the Feedback Context.
|
|
413
|
+
|
|
414
|
+
Returns:
|
|
415
|
+
FeedbackContext: The requested Feedback Context.
|
|
416
|
+
|
|
417
|
+
"""
|
|
418
|
+
|
|
419
|
+
parameter_model = types._GetRuntimeFeedbackContextRequestParameters(
|
|
420
|
+
name=name,
|
|
421
|
+
config=config,
|
|
422
|
+
)
|
|
423
|
+
|
|
424
|
+
request_url_dict: Optional[dict[str, str]]
|
|
425
|
+
if not self._api_client.vertexai:
|
|
426
|
+
raise ValueError(
|
|
427
|
+
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
|
|
428
|
+
)
|
|
429
|
+
else:
|
|
430
|
+
request_dict = _GetRuntimeFeedbackContextRequestParameters_to_vertex(
|
|
431
|
+
parameter_model
|
|
432
|
+
)
|
|
433
|
+
request_url_dict = request_dict.get("_url")
|
|
434
|
+
if request_url_dict:
|
|
435
|
+
path = "{name}".format_map(request_url_dict)
|
|
436
|
+
else:
|
|
437
|
+
path = "{name}"
|
|
438
|
+
|
|
439
|
+
query_params = request_dict.get("_query")
|
|
440
|
+
if query_params:
|
|
441
|
+
path = f"{path}?{urlencode(query_params)}"
|
|
442
|
+
# TODO: remove the hack that pops config.
|
|
443
|
+
request_dict.pop("config", None)
|
|
444
|
+
|
|
445
|
+
http_options: Optional[types.HttpOptions] = None
|
|
446
|
+
if (
|
|
447
|
+
parameter_model.config is not None
|
|
448
|
+
and parameter_model.config.http_options is not None
|
|
449
|
+
):
|
|
450
|
+
http_options = parameter_model.config.http_options
|
|
451
|
+
|
|
452
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
453
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
454
|
+
|
|
455
|
+
response = await self._api_client.async_request(
|
|
456
|
+
"get", path, request_dict, http_options
|
|
457
|
+
)
|
|
458
|
+
|
|
459
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
460
|
+
|
|
461
|
+
return_value = types.FeedbackContext._from_response(
|
|
462
|
+
response=response_dict,
|
|
463
|
+
kwargs=(
|
|
464
|
+
{
|
|
465
|
+
"config": {
|
|
466
|
+
"response_schema": getattr(
|
|
467
|
+
parameter_model.config, "response_schema", None
|
|
468
|
+
),
|
|
469
|
+
"response_json_schema": getattr(
|
|
470
|
+
parameter_model.config, "response_json_schema", None
|
|
471
|
+
),
|
|
472
|
+
"include_all_fields": getattr(
|
|
473
|
+
parameter_model.config, "include_all_fields", None
|
|
474
|
+
),
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
if getattr(parameter_model, "config", None)
|
|
478
|
+
else {}
|
|
479
|
+
),
|
|
480
|
+
)
|
|
481
|
+
|
|
482
|
+
self._api_client._verify_response(return_value)
|
|
483
|
+
return return_value
|
|
484
|
+
|
|
485
|
+
async def _get_feedback_context_operation(
|
|
486
|
+
self,
|
|
487
|
+
*,
|
|
488
|
+
operation_name: str,
|
|
489
|
+
config: Optional[types.GetRuntimeFeedbackContextOperationConfigOrDict] = None,
|
|
490
|
+
) -> types.RuntimeFeedbackContextOperation:
|
|
491
|
+
parameter_model = types._GetRuntimeFeedbackContextOperationParameters(
|
|
492
|
+
operation_name=operation_name,
|
|
493
|
+
config=config,
|
|
494
|
+
)
|
|
495
|
+
|
|
496
|
+
request_url_dict: Optional[dict[str, str]]
|
|
497
|
+
if not self._api_client.vertexai:
|
|
498
|
+
raise ValueError(
|
|
499
|
+
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
|
|
500
|
+
)
|
|
501
|
+
else:
|
|
502
|
+
request_dict = _GetRuntimeFeedbackContextOperationParameters_to_vertex(
|
|
503
|
+
parameter_model
|
|
504
|
+
)
|
|
505
|
+
request_url_dict = request_dict.get("_url")
|
|
506
|
+
if request_url_dict:
|
|
507
|
+
path = "{operation_name}".format_map(request_url_dict)
|
|
508
|
+
else:
|
|
509
|
+
path = "{operation_name}"
|
|
510
|
+
|
|
511
|
+
query_params = request_dict.get("_query")
|
|
512
|
+
if query_params:
|
|
513
|
+
path = f"{path}?{urlencode(query_params)}"
|
|
514
|
+
# TODO: remove the hack that pops config.
|
|
515
|
+
request_dict.pop("config", None)
|
|
516
|
+
|
|
517
|
+
http_options: Optional[types.HttpOptions] = None
|
|
518
|
+
if (
|
|
519
|
+
parameter_model.config is not None
|
|
520
|
+
and parameter_model.config.http_options is not None
|
|
521
|
+
):
|
|
522
|
+
http_options = parameter_model.config.http_options
|
|
523
|
+
|
|
524
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
525
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
526
|
+
|
|
527
|
+
response = await self._api_client.async_request(
|
|
528
|
+
"get", path, request_dict, http_options
|
|
529
|
+
)
|
|
530
|
+
|
|
531
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
532
|
+
|
|
533
|
+
return_value = types.RuntimeFeedbackContextOperation._from_response(
|
|
534
|
+
response=response_dict,
|
|
535
|
+
kwargs=(
|
|
536
|
+
{
|
|
537
|
+
"config": {
|
|
538
|
+
"response_schema": getattr(
|
|
539
|
+
parameter_model.config, "response_schema", None
|
|
540
|
+
),
|
|
541
|
+
"response_json_schema": getattr(
|
|
542
|
+
parameter_model.config, "response_json_schema", None
|
|
543
|
+
),
|
|
544
|
+
"include_all_fields": getattr(
|
|
545
|
+
parameter_model.config, "include_all_fields", None
|
|
546
|
+
),
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
if getattr(parameter_model, "config", None)
|
|
550
|
+
else {}
|
|
551
|
+
),
|
|
552
|
+
)
|
|
553
|
+
|
|
554
|
+
self._api_client._verify_response(return_value)
|
|
555
|
+
return return_value
|
|
556
|
+
|
|
557
|
+
async def _update(
|
|
558
|
+
self,
|
|
559
|
+
*,
|
|
560
|
+
name: str,
|
|
561
|
+
context_events: Optional[list[types.SessionEventOrDict]] = None,
|
|
562
|
+
config: Optional[types.UpdateRuntimeFeedbackContextConfigOrDict] = None,
|
|
563
|
+
) -> types.RuntimeFeedbackContextOperation:
|
|
564
|
+
"""
|
|
565
|
+
Updates a Feedback Context.
|
|
566
|
+
"""
|
|
567
|
+
|
|
568
|
+
parameter_model = types._UpdateRuntimeFeedbackContextRequestParameters(
|
|
569
|
+
name=name,
|
|
570
|
+
context_events=context_events,
|
|
571
|
+
config=config,
|
|
572
|
+
)
|
|
573
|
+
|
|
574
|
+
request_url_dict: Optional[dict[str, str]]
|
|
575
|
+
if not self._api_client.vertexai:
|
|
576
|
+
raise ValueError(
|
|
577
|
+
"This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
|
|
578
|
+
)
|
|
579
|
+
else:
|
|
580
|
+
request_dict = _UpdateRuntimeFeedbackContextRequestParameters_to_vertex(
|
|
581
|
+
parameter_model
|
|
582
|
+
)
|
|
583
|
+
request_url_dict = request_dict.get("_url")
|
|
584
|
+
if request_url_dict:
|
|
585
|
+
path = "{name}".format_map(request_url_dict)
|
|
586
|
+
else:
|
|
587
|
+
path = "{name}"
|
|
588
|
+
|
|
589
|
+
query_params = request_dict.get("_query")
|
|
590
|
+
if query_params:
|
|
591
|
+
path = f"{path}?{urlencode(query_params)}"
|
|
592
|
+
# TODO: remove the hack that pops config.
|
|
593
|
+
request_dict.pop("config", None)
|
|
594
|
+
|
|
595
|
+
http_options: Optional[types.HttpOptions] = None
|
|
596
|
+
if (
|
|
597
|
+
parameter_model.config is not None
|
|
598
|
+
and parameter_model.config.http_options is not None
|
|
599
|
+
):
|
|
600
|
+
http_options = parameter_model.config.http_options
|
|
601
|
+
|
|
602
|
+
request_dict = _common.convert_to_dict(request_dict)
|
|
603
|
+
request_dict = _common.encode_unserializable_types(request_dict)
|
|
604
|
+
|
|
605
|
+
response = await self._api_client.async_request(
|
|
606
|
+
"patch", path, request_dict, http_options
|
|
607
|
+
)
|
|
608
|
+
|
|
609
|
+
response_dict = {} if not response.body else json.loads(response.body)
|
|
610
|
+
|
|
611
|
+
return_value = types.RuntimeFeedbackContextOperation._from_response(
|
|
612
|
+
response=response_dict,
|
|
613
|
+
kwargs=(
|
|
614
|
+
{
|
|
615
|
+
"config": {
|
|
616
|
+
"response_schema": getattr(
|
|
617
|
+
parameter_model.config, "response_schema", None
|
|
618
|
+
),
|
|
619
|
+
"response_json_schema": getattr(
|
|
620
|
+
parameter_model.config, "response_json_schema", None
|
|
621
|
+
),
|
|
622
|
+
"include_all_fields": getattr(
|
|
623
|
+
parameter_model.config, "include_all_fields", None
|
|
624
|
+
),
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
if getattr(parameter_model, "config", None)
|
|
628
|
+
else {}
|
|
629
|
+
),
|
|
630
|
+
)
|
|
631
|
+
|
|
632
|
+
self._api_client._verify_response(return_value)
|
|
633
|
+
return return_value
|
|
634
|
+
|
|
635
|
+
async def get(
|
|
636
|
+
self,
|
|
637
|
+
*,
|
|
638
|
+
parent: str,
|
|
639
|
+
config: Optional[types.GetRuntimeFeedbackContextConfigOrDict] = None,
|
|
640
|
+
) -> types.FeedbackContext:
|
|
641
|
+
"""Gets the Feedback Context from the Runtime.
|
|
642
|
+
|
|
643
|
+
Args:
|
|
644
|
+
parent (str): Required. Resource name of the parent Feedback Entry. Format:
|
|
645
|
+
`projects/{project}/locations/{location}/reasoningEngines/{resource_id}/feedbackEntries/{feedback_entry_id}`.
|
|
646
|
+
config (GetRuntimeFeedbackContextConfig):
|
|
647
|
+
Optional. Additional configurations for getting the Feedback Context.
|
|
648
|
+
|
|
649
|
+
Returns:
|
|
650
|
+
FeedbackContext: The requested Feedback Context.
|
|
651
|
+
"""
|
|
652
|
+
if config is None:
|
|
653
|
+
config = types.GetRuntimeFeedbackContextConfig()
|
|
654
|
+
elif isinstance(config, dict):
|
|
655
|
+
config = types.GetRuntimeFeedbackContextConfig.model_validate(config)
|
|
656
|
+
return await self._get(
|
|
657
|
+
name=f"{parent}/feedbackContext",
|
|
658
|
+
config=config,
|
|
659
|
+
)
|
|
660
|
+
|
|
661
|
+
async def update(
|
|
662
|
+
self,
|
|
663
|
+
*,
|
|
664
|
+
parent: str,
|
|
665
|
+
context_events: Optional[list[types.SessionEvent]] = None,
|
|
666
|
+
config: Optional[types.UpdateRuntimeFeedbackContextConfigOrDict] = None,
|
|
667
|
+
) -> types.RuntimeFeedbackContextOperation:
|
|
668
|
+
"""Updates a Feedback Context in the Runtime.
|
|
669
|
+
|
|
670
|
+
Args:
|
|
671
|
+
parent (str): Required. Resource name of the parent Feedback Entry. Format:
|
|
672
|
+
`projects/{project}/locations/{location}/reasoningEngines/{resource_id}/feedbackEntries/{feedback_entry_id}`.
|
|
673
|
+
context_events (list[SessionEvent]): Optional. Events from the conversation relevant to the parent Feedback Entry.
|
|
674
|
+
config (UpdateRuntimeFeedbackContextConfig):
|
|
675
|
+
Optional. Additional configurations for updating the Feedback Context.
|
|
676
|
+
|
|
677
|
+
Returns:
|
|
678
|
+
RuntimeFeedbackContextOperation: The operation for updating the Feedback Context.
|
|
679
|
+
"""
|
|
680
|
+
if config is None:
|
|
681
|
+
config = types.UpdateRuntimeFeedbackContextConfig()
|
|
682
|
+
elif isinstance(config, dict):
|
|
683
|
+
config = types.UpdateRuntimeFeedbackContextConfig.model_validate(config)
|
|
684
|
+
operation = await self._update(
|
|
685
|
+
name=f"{parent}/feedbackContext",
|
|
686
|
+
context_events=context_events,
|
|
687
|
+
config=config,
|
|
688
|
+
)
|
|
689
|
+
if config.wait_for_completion:
|
|
690
|
+
if not operation.done:
|
|
691
|
+
operation = await _agent_engines_utils._await_async_operation(
|
|
692
|
+
operation_name=operation.name,
|
|
693
|
+
get_operation_fn=self._get_feedback_context_operation,
|
|
694
|
+
poll_interval_seconds=0.5,
|
|
695
|
+
)
|
|
696
|
+
if operation.error:
|
|
697
|
+
raise RuntimeError(
|
|
698
|
+
f"Failed to update Feedback Context: {operation.error}"
|
|
699
|
+
)
|
|
700
|
+
return operation
|