Skip to content

Commit ef3afa0

Browse files
authored
Gemini Vertex Testing (#1719)
* Enable VertexAi client and tests * Add recorded responses for embeddings * Update to gemini-2.5-flash and record tests
1 parent 6e429d2 commit ef3afa0

100 files changed

Lines changed: 37558 additions & 3076 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

tests/mlmodel_gemini/conftest.py

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646

4747

4848
@pytest.fixture
49-
def gemini_clients(replay_id):
49+
def gemini_client(replay_id, is_vertex):
5050
"""
5151
This configures the Gemini client to use a ReplayApiClient which will either record or replay responses depending
5252
on the mode. The mode can be controlled by setting NEW_RELIC_TESTING_RECORD_GEMINI_RESPONSES=1 as an environment
@@ -75,19 +75,12 @@ def gemini_clients(replay_id):
7575
# Monkeypatch the Gemini client to use the replay client which will either record or replay responses depending on the mode.
7676
replay_client = google.genai._replay_api_client.ReplayApiClient(mode=replay_client_mode, replay_id=replay_id)
7777
google.genai.client.Client._get_api_client = lambda self, *args, **kwargs: replay_client
78-
gemini_dev_client = google.genai.Client(api_key=google_api_key)
78+
gemini_client = google.genai.Client(api_key=google_api_key, vertexai=is_vertex)
7979

80-
yield gemini_dev_client
80+
yield gemini_client
8181

82-
gemini_dev_client._api_client.close()
83-
gemini_dev_client.close()
84-
85-
86-
@pytest.fixture
87-
def gemini_dev_client(gemini_clients):
88-
# Once VertexAI is enabled, gemini_clients() will yield two different clients up that will be unpacked here
89-
gemini_dev_client = gemini_clients
90-
return gemini_dev_client
82+
gemini_client._api_client.close()
83+
gemini_client.close()
9184

9285

9386
@pytest.fixture
@@ -108,9 +101,8 @@ def replay_id():
108101
return f"{test_module}/{test_name}/{test_params_suffix}"
109102

110103

111-
@pytest.fixture(scope="session", params=["standard"]) # "vertex" to be added
104+
@pytest.fixture(scope="session", params=["standard", "vertex"])
112105
def is_vertex(request):
113-
# This is a placeholder for when we want to test against both the standard Gemini API and the Vertex AI Gemini API.
114106
return request.param == "vertex"
115107

116108

@@ -130,9 +122,9 @@ def is_chat(request):
130122

131123

132124
@pytest.fixture
133-
def exercise_text_model(loop, gemini_dev_client, is_async, is_chat, is_streaming):
125+
def exercise_text_model(loop, gemini_client, is_async, is_chat, is_streaming):
134126
# Pick the sync or async client before we make the chat object for convenience
135-
client = gemini_dev_client.aio if is_async else gemini_dev_client
127+
client = gemini_client.aio if is_async else gemini_client
136128

137129
def _exercise_text_model(*args, **kwargs):
138130
if is_chat:
@@ -173,9 +165,9 @@ async def _exercise_agen():
173165

174166

175167
@pytest.fixture
176-
def exercise_embedding_model(loop, gemini_dev_client, is_async):
168+
def exercise_embedding_model(loop, gemini_client, is_async):
177169
# Pick the sync or async client for convenience
178-
client = gemini_dev_client.aio if is_async else gemini_dev_client
170+
client = gemini_client.aio if is_async else gemini_client
179171

180172
def _exercise_embedding_model(*args, **kwargs):
181173
if not is_async:

tests/mlmodel_gemini/replays/test_embeddings/test_gemini_embedding/invoke-model-standard.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@
3535
"content-type": "application/json; charset=UTF-8",
3636
"vary": "Origin, X-Origin, Referer",
3737
"content-encoding": "gzip",
38-
"date": "Fri, 27 Mar 2026 20:00:21 GMT",
38+
"date": "Thu, 30 Apr 2026 19:47:49 GMT",
3939
"server": "scaffolding on HTTPServer2",
4040
"x-xss-protection": "0",
4141
"x-frame-options": "SAMEORIGIN",
4242
"x-content-type-options": "nosniff",
43-
"server-timing": "gfet4t7; dur=178",
43+
"server-timing": "gfet4t7; dur=200",
4444
"alt-svc": "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000",
4545
"transfer-encoding": "chunked"
4646
},
@@ -3134,12 +3134,12 @@
31343134
"content-type": "application/json; charset=UTF-8",
31353135
"vary": "Origin, X-Origin, Referer",
31363136
"content-encoding": "gzip",
3137-
"date": "Fri, 27 Mar 2026 20:00:21 GMT",
3137+
"date": "Thu, 30 Apr 2026 19:47:49 GMT",
31383138
"server": "scaffolding on HTTPServer2",
31393139
"x-xss-protection": "0",
31403140
"x-frame-options": "SAMEORIGIN",
31413141
"x-content-type-options": "nosniff",
3142-
"server-timing": "gfet4t7; dur=178",
3142+
"server-timing": "gfet4t7; dur=200",
31433143
"alt-svc": "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000",
31443144
"transfer-encoding": "chunked"
31453145
}

0 commit comments

Comments
 (0)