Skip to content

Commit f693d9f

Browse files
sararobcopybara-github
authored andcommitted
chore: Update headers
PiperOrigin-RevId: 913858354
1 parent e4fdb7a commit f693d9f

8 files changed

Lines changed: 35 additions & 31 deletions

File tree

setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,7 @@
326326
"google-cloud-storage >= 3.10.0, < 4.0.0; python_version>='3.13'",
327327
"google-cloud-bigquery >= 1.15.0, < 4.0.0, !=3.20.0",
328328
"google-cloud-resource-manager >= 1.3.3, < 3.0.0",
329-
"google-genai >= 1.37.0, <2.0.0; python_version<'3.10'",
330-
"google-genai >= 1.66.0, <2.0.0; python_version>='3.10'",
329+
"google-genai >= 1.75.0, < 2.0.0",
331330
)
332331
+ genai_requires,
333332
extras_require={

testing/constraints-3.10.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# This constraints file is required for unit tests.
33
# List all library dependencies and extras in this file.
44
google-api-core==2.21.0 # Tests google-api-core with rest async support
5-
google-auth==2.47.0 # Tests google-auth with rest async support
5+
google-auth==2.49.0
66
proto-plus==1.22.3
77
protobuf
88
mock==4.0.2

testing/constraints-3.11.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# This constraints file is required for unit tests.
33
# List all library dependencies and extras in this file.
44
google-api-core==2.21.0 # Tests google-api-core with rest async support
5-
google-auth==2.47.0 # Tests google-auth with rest async support
5+
google-auth==2.49.0
66
proto-plus
77
protobuf
88
mock==4.0.2

testing/constraints-3.12.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# This constraints file is required for unit tests.
33
# List all library dependencies and extras in this file.
44
google-api-core==2.21.0 # Tests google-api-core with rest async support
5-
google-auth==2.47.0 # Tests google-auth with rest async support
5+
google-auth==2.49.0
66
proto-plus
77
mock==4.0.2
88
google-cloud-storage==3.0.0 # Updated to v3.x, backward compatible with v2.x via wrapper

testing/constraints-3.13.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# This constraints file is required for unit tests.
33
# List all library dependencies and extras in this file.
44
google-api-core==2.27.0 # Tests google-api-core with rest async support
5-
google-auth==2.47.0 # Tests google-auth with rest async support
5+
google-auth==2.49.0
66
proto-plus
77
mock==4.0.2
88
google-cloud-storage==3.10.0 # Updated to v3.x, backward compatible with v2.x via wrapper

testing/constraints-3.14.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# This constraints file is required for unit tests.
33
# List all library dependencies and extras in this file.
44
google-api-core==2.27.0
5-
google-auth==2.47.0 # Tests google-auth with rest async support
5+
google-auth==2.49.0
66
proto-plus
77
mock==4.0.2
88
google-cloud-storage==3.10.0 # Updated for Python 3.14 compatibility

tests/unit/vertexai/genai/replays/conftest.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@
2323
client as vertexai_genai_client_module,
2424
)
2525
from vertexai._genai import _agent_engines_utils
26-
from vertexai._genai.client import (
27-
_GENAI_MODULES_TELEMETRY_HEADER,
28-
)
29-
from google.cloud.aiplatform import version as aip_version
3026
from google.cloud import storage, bigquery
3127
from google.genai import _replay_api_client
3228
from google.genai import types as genai_types
@@ -265,10 +261,6 @@ def client(use_vertex, replays_prefix, http_options, request):
265261
if http_options.headers is None:
266262
http_options.headers = {}
267263

268-
tracking_label = f"{_GENAI_MODULES_TELEMETRY_HEADER}/{aip_version.__version__}"
269-
http_options.headers["user-agent"] = tracking_label
270-
http_options.headers["x-goog-api-client"] = tracking_label
271-
272264
replay_client = _replay_api_client.ReplayApiClient(
273265
mode=mode,
274266
replay_id=replay_id,

vertexai/_genai/client.py

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import asyncio
1717
import importlib
18+
import sys
1819
from typing import Optional, Union, TYPE_CHECKING
1920
from types import TracebackType, ModuleType
2021

@@ -23,6 +24,8 @@
2324
from google.genai import _common
2425
from google.genai import client as genai_client
2526
from google.genai import types
27+
from google.genai import version as genai_version
28+
from google.genai import _api_client as genai_api_client
2629
from . import live
2730

2831
if TYPE_CHECKING:
@@ -42,6 +45,32 @@
4245
_GENAI_MODULES_TELEMETRY_HEADER = "vertex-genai-modules"
4346

4447

48+
def _custom_append_library_version_headers(headers: dict[str, str]) -> None:
49+
"""Overridde GenAI SDK header injection to use custom vertex-genai-modules header."""
50+
genai_sdk_version = genai_version.__version__
51+
module_version = aip_version.__version__
52+
python_version = sys.version.split()[0]
53+
54+
combined_label = f"google-genai-sdk/{genai_sdk_version}+{_GENAI_MODULES_TELEMETRY_HEADER}/{module_version}"
55+
full_header = f"{combined_label} gl-python/{python_version}"
56+
57+
if "user-agent" not in headers or combined_label not in headers["user-agent"]:
58+
headers["user-agent"] = f"{full_header} " + headers.get("user-agent", "")
59+
headers["user-agent"] = headers["user-agent"].strip()
60+
61+
if (
62+
"x-goog-api-client" not in headers
63+
or combined_label not in headers["x-goog-api-client"]
64+
):
65+
headers["x-goog-api-client"] = f"{full_header} " + headers.get(
66+
"x-goog-api-client", ""
67+
)
68+
headers["x-goog-api-client"] = headers["x-goog-api-client"].strip()
69+
70+
71+
genai_api_client.append_library_version_headers = _custom_append_library_version_headers
72+
73+
4574
class AsyncClient:
4675
"""Async Gen AI Client for the Vertex SDK."""
4776

@@ -223,22 +252,6 @@ def __init__(
223252
if location in ["us", "eu"] and not http_options.base_url:
224253
http_options.base_url = f"https://aiplatform.{location}.rep.googleapis.com/"
225254

226-
tracking_label = f"{_GENAI_MODULES_TELEMETRY_HEADER}/{aip_version.__version__}"
227-
228-
if "user-agent" in http_options.headers:
229-
http_options.headers["user-agent"] = (
230-
f"{http_options.headers['user-agent']} {tracking_label}"
231-
)
232-
else:
233-
http_options.headers["user-agent"] = tracking_label
234-
235-
if "x-goog-api-client" in http_options.headers:
236-
http_options.headers["x-goog-api-client"] = (
237-
f"{http_options.headers['x-goog-api-client']} {tracking_label}"
238-
)
239-
else:
240-
http_options.headers["x-goog-api-client"] = tracking_label
241-
242255
self._api_client = genai_client.Client._get_api_client(
243256
vertexai=True,
244257
api_key=api_key,

0 commit comments

Comments
 (0)