GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat: Support for CMEK, runtime controls, and PSC-I · googleapis/python-aiplatform@9d5ead1

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • tests/unit/vertexai/genai/replays
    • test_create_agent_engine.py
  • vertexai/_genai
    • _agent_engines_utils.py
    • agent_engines.py
    • types.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎tests/unit/vertexai/genai/replays/test_create_agent_engine.py‎

Copy file name to clipboardExpand all lines: tests/unit/vertexai/genai/replays/test_create_agent_engine.py
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,25 @@ def test_create_config_lightweight(client):
3838
}
3939

4040

41+
def test_create_config(client):
42+
agent_display_name = "test-display-name"
43+
agent_description = "my agent"
44+
45+
if not os.environ.get("GCS_BUCKET"):
46+
raise ValueError("GCS_BUCKET environment variable is not set.")
47+
48+
config = client.agent_engines._create_config(
49+
mode="create",
50+
staging_bucket=os.environ["GCS_BUCKET"],
51+
display_name=agent_display_name,
52+
description=agent_description,
53+
)
54+
assert config == {
55+
"display_name": agent_display_name,
56+
"description": agent_description,
57+
}
58+
59+
4160
def test_create_with_context_spec(client):
4261
project = "test-project"
4362
location = "us-central1"
Collapse file

‎vertexai/_genai/_agent_engines_utils.py‎

Copy file name to clipboardExpand all lines: vertexai/_genai/_agent_engines_utils.py
+71Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,3 +1445,74 @@ def _yield_parsed_json(http_response: google_genai_types.HttpResponse) -> Iterat
14451445
except Exception as e:
14461446
logger.warning(f"failed to parse json: {line}. Exception: {e}")
14471447
yield line
1448+
1449+
1450+
def _validate_resource_limits_or_raise(resource_limits: dict[str, str]) -> None:
1451+
"""Validates the resource limits.
1452+
1453+
Checks that the resource limits are a dict with 'cpu' and 'memory' keys.
1454+
Checks that the 'cpu' value is one of 1, 2, 4, 6, 8.
1455+
Checks that the 'memory' value is a string ending with 'Gi'.
1456+
Checks that the memory size is smaller than 32Gi.
1457+
Checks that the memory size requires at least the specified number of CPUs.
1458+
1459+
Args:
1460+
resource_limits: The resource limits to be validated.
1461+
1462+
Raises:
1463+
TypeError: If the resource limits are not a dict.
1464+
KeyError: If the resource limits do not contain 'cpu' and 'memory' keys.
1465+
ValueError: If the 'cpu' value is not one of 1, 2, 4, 6, 8.
1466+
ValueError: If the 'memory' value is not a string ending with 'Gi'.
1467+
ValueError: If the memory size is too large.
1468+
ValueError: If the memory size requires more CPUs than the specified
1469+
'cpu' value.
1470+
"""
1471+
if not isinstance(resource_limits, dict):
1472+
raise TypeError(f"resource_limits must be a dict. Got {type(resource_limits)}")
1473+
if "cpu" not in resource_limits or "memory" not in resource_limits:
1474+
raise KeyError("resource_limits must contain 'cpu' and 'memory' keys.")
1475+
1476+
cpu = int(resource_limits["cpu"])
1477+
memory_str = resource_limits["memory"]
1478+
1479+
if cpu not in [1, 2, 4, 6, 8]:
1480+
raise ValueError(
1481+
"resource_limits['cpu'] must be one of 1, 2, 4, 6, 8. Got" f" {cpu}"
1482+
)
1483+
1484+
if not isinstance(memory_str, str) or not memory_str.endswith("Gi"):
1485+
raise ValueError(
1486+
"resource_limits['memory'] must be a string ending with 'Gi'."
1487+
f" Got {memory_str}"
1488+
)
1489+
1490+
try:
1491+
memory_gb = int(memory_str[:-2])
1492+
except ValueError:
1493+
raise ValueError(
1494+
f"Invalid memory value: {memory_str}. Must be an integer"
1495+
" followed by 'Gi'."
1496+
)
1497+
1498+
# https://cloud.google.com/run/docs/configuring/memory-limits
1499+
if memory_gb > 32:
1500+
raise ValueError(
1501+
f"Memory size of {memory_str} is too large. Must be smaller than 32Gi."
1502+
)
1503+
if memory_gb > 24:
1504+
min_cpu = 8
1505+
elif memory_gb > 16:
1506+
min_cpu = 6
1507+
elif memory_gb > 8:
1508+
min_cpu = 4
1509+
elif memory_gb > 4:
1510+
min_cpu = 2
1511+
else:
1512+
min_cpu = 1
1513+
1514+
if cpu < min_cpu:
1515+
raise ValueError(
1516+
f"Memory size of {memory_str} requires at least {min_cpu} CPUs."
1517+
f" Got {cpu}"
1518+
)
Collapse file

‎vertexai/_genai/agent_engines.py‎

Copy file name to clipboardExpand all lines: vertexai/_genai/agent_engines.py
+89-2Lines changed: 89 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ def _ReasoningEngineSpec_to_vertex(
6060
if getv(from_object, ["package_spec"]) is not None:
6161
setv(to_object, ["packageSpec"], getv(from_object, ["package_spec"]))
6262

63+
if getv(from_object, ["service_account"]) is not None:
64+
setv(
65+
to_object,
66+
["serviceAccount"],
67+
getv(from_object, ["service_account"]),
68+
)
69+
6370
return to_object
6471

6572

@@ -861,6 +868,13 @@ def _ReasoningEngine_from_vertex(
861868
if getv(from_object, ["displayName"]) is not None:
862869
setv(to_object, ["display_name"], getv(from_object, ["displayName"]))
863870

871+
if getv(from_object, ["encryptionSpec"]) is not None:
872+
setv(
873+
to_object,
874+
["encryption_spec"],
875+
getv(from_object, ["encryptionSpec"]),
876+
)
877+
864878
if getv(from_object, ["etag"]) is not None:
865879
setv(to_object, ["etag"], getv(from_object, ["etag"]))
866880

@@ -970,12 +984,18 @@ def _Session_from_vertex(
970984
if getv(from_object, ["displayName"]) is not None:
971985
setv(to_object, ["display_name"], getv(from_object, ["displayName"]))
972986

987+
if getv(from_object, ["expireTime"]) is not None:
988+
setv(to_object, ["expire_time"], getv(from_object, ["expireTime"]))
989+
973990
if getv(from_object, ["name"]) is not None:
974991
setv(to_object, ["name"], getv(from_object, ["name"]))
975992

976993
if getv(from_object, ["sessionState"]) is not None:
977994
setv(to_object, ["session_state"], getv(from_object, ["sessionState"]))
978995

996+
if getv(from_object, ["ttl"]) is not None:
997+
setv(to_object, ["ttl"], getv(from_object, ["ttl"]))
998+
979999
if getv(from_object, ["updateTime"]) is not None:
9801000
setv(to_object, ["update_time"], getv(from_object, ["updateTime"]))
9811001

@@ -2722,6 +2742,11 @@ def create(
27222742
extra_packages=config.extra_packages,
27232743
env_vars=config.env_vars,
27242744
context_spec=context_spec,
2745+
psc_interface_config=config.psc_interface_config,
2746+
min_instances=config.min_instances,
2747+
max_instances=config.max_instances,
2748+
resource_limits=config.resource_limits,
2749+
container_concurrency=config.container_concurrency,
27252750
)
27262751
operation = self._create(config=api_config)
27272752
# TODO: Use a more specific link.
@@ -2769,6 +2794,11 @@ def _create_config(
27692794
extra_packages: Optional[Sequence[str]] = None,
27702795
env_vars: Optional[dict[str, Union[str, Any]]] = None,
27712796
context_spec: Optional[types.ReasoningEngineContextSpecDict] = None,
2797+
psc_interface_config: Optional[types.PscInterfaceConfigDict] = None,
2798+
min_instances: Optional[int] = None,
2799+
max_instances: Optional[int] = None,
2800+
resource_limits: Optional[dict[str, str]] = None,
2801+
container_concurrency: Optional[int] = None,
27722802
) -> types.UpdateAgentEngineConfigDict:
27732803
import sys
27742804

@@ -2853,11 +2883,25 @@ def _create_config(
28532883
agent_engine_spec: types.ReasoningEngineSpecDict = {
28542884
"package_spec": package_spec,
28552885
}
2856-
if env_vars is not None:
2886+
if (
2887+
env_vars is not None
2888+
or psc_interface_config is not None
2889+
or min_instances is not None
2890+
or max_instances is not None
2891+
or resource_limits is not None
2892+
or container_concurrency is not None
2893+
):
28572894
(
28582895
deployment_spec,
28592896
deployment_update_masks,
2860-
) = self._generate_deployment_spec_or_raise(env_vars=env_vars)
2897+
) = self._generate_deployment_spec_or_raise(
2898+
env_vars=env_vars,
2899+
psc_interface_config=psc_interface_config,
2900+
min_instances=min_instances,
2901+
max_instances=max_instances,
2902+
resource_limits=resource_limits,
2903+
container_concurrency=container_concurrency,
2904+
)
28612905
update_masks.extend(deployment_update_masks)
28622906
agent_engine_spec["deployment_spec"] = deployment_spec
28632907
class_methods = _agent_engines_utils._generate_class_methods_spec_or_raise(
@@ -2884,6 +2928,11 @@ def _generate_deployment_spec_or_raise(
28842928
self,
28852929
*,
28862930
env_vars: Optional[dict[str, Union[str, Any]]] = None,
2931+
psc_interface_config: Optional[types.PscInterfaceConfigDict] = None,
2932+
min_instances: Optional[int] = None,
2933+
max_instances: Optional[int] = None,
2934+
resource_limits: Optional[dict[str, str]] = None,
2935+
container_concurrency: Optional[int] = None,
28872936
) -> Tuple[dict[str, Any], Sequence[str]]:
28882937
deployment_spec: dict[str, Any] = {}
28892938
update_masks = []
@@ -2901,6 +2950,37 @@ def _generate_deployment_spec_or_raise(
29012950
update_masks.append("spec.deployment_spec.env")
29022951
if deployment_spec.get("secret_env"):
29032952
update_masks.append("spec.deployment_spec.secret_env")
2953+
if psc_interface_config:
2954+
deployment_spec["psc_interface_config"] = psc_interface_config
2955+
update_masks.append("spec.deployment_spec.psc_interface_config")
2956+
if min_instances is not None:
2957+
if not 0 <= min_instances <= 10:
2958+
raise ValueError(
2959+
"min_instances must be between 0 and 10. Got" f" {min_instances}"
2960+
)
2961+
deployment_spec["min_instances"] = min_instances
2962+
update_masks.append("spec.deployment_spec.min_instances")
2963+
if max_instances is not None:
2964+
if psc_interface_config and not 1 <= max_instances <= 100:
2965+
raise ValueError(
2966+
"max_instances must be between 1 and 100 when PSC-I is"
2967+
f" enabled. Got {max_instances}"
2968+
)
2969+
elif not psc_interface_config and not 1 <= max_instances <= 1000:
2970+
raise ValueError(
2971+
"max_instances must be between 1 and 1000. Got" f" {max_instances}"
2972+
)
2973+
deployment_spec["max_instances"] = max_instances
2974+
update_masks.append("spec.deployment_spec.max_instances")
2975+
if resource_limits:
2976+
_agent_engines_utils._validate_resource_limits_or_raise(
2977+
resource_limits=resource_limits
2978+
)
2979+
deployment_spec["resource_limits"] = resource_limits
2980+
update_masks.append("spec.deployment_spec.resource_limits")
2981+
if container_concurrency:
2982+
deployment_spec["container_concurrency"] = container_concurrency
2983+
update_masks.append("spec.deployment_spec.container_concurrency")
29042984
return deployment_spec, update_masks
29052985

29062986
def _update_deployment_spec_with_env_vars_dict_or_raise(
@@ -3073,6 +3153,11 @@ def update(
30733153
extra_packages=config.extra_packages,
30743154
env_vars=config.env_vars,
30753155
context_spec=context_spec,
3156+
psc_interface_config=config.psc_interface_config,
3157+
min_instances=config.min_instances,
3158+
max_instances=config.max_instances,
3159+
resource_limits=config.resource_limits,
3160+
container_concurrency=config.container_concurrency,
30763161
)
30773162
operation = self._update(name=name, config=api_config)
30783163
logger.info(
@@ -3128,6 +3213,8 @@ def _stream_query(
31283213
):
31293214
yield response
31303215

3216+
# TODO: b/436704146 - Replace with generated methods
3217+
# TODO: b/437129724 - Add replay test for async stream query
31313218
async def _async_stream_query(
31323219
self,
31333220
*,

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.