Skip to content

Commit f105a15

Browse files
speedstorm1copybara-github
authored andcommitted
feat: Support Models.ListAsync(), quota project authentication, and URL filter handling for list methods
PiperOrigin-RevId: 835655670
1 parent dce6173 commit f105a15

26 files changed

+4289
-157
lines changed

Google.GenAI.E2E.Tests/Caches/ListCacheTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public async Task ListCacheVertexTest()
9999
[TestMethod]
100100
public async Task ListCacheGeminiTest()
101101
{
102-
var part = new Part { FileData = new FileData { MimeType = "application/pdf", FileUri = "https://generativelanguage.googleapis.com/v1beta/files/gwpix29tac28" } };
102+
var part = new Part { FileData = new FileData { MimeType = "application/pdf", FileUri = "https://generativelanguage.googleapis.com/v1beta/files/lnl2lhzkof4f" } };
103103
var config1 = new CreateCachedContentConfig
104104
{
105105
Contents = new List<Content> { new Content { Role = "user", Parts = Enumerable.Repeat(part, 5).ToList() } },

Google.GenAI.E2E.Tests/Models/GetModelTest.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,20 @@ public async Task GetModelTunedGeminiTest() {
9191

9292
Assert.IsNotNull(geminiResponse);
9393
}
94+
95+
[TestMethod]
96+
public async Task GetBaseModelVertexTest() {
97+
string baseModel = "gemini-3-pro-preview";
98+
var vertexResponse = await vertexClient.Models.GetAsync(model: baseModel, config: null);
99+
100+
Assert.IsNotNull(vertexResponse);
101+
}
102+
103+
[TestMethod]
104+
public async Task GetBaseModelGeminiTest() {
105+
string baseModel = "gemini-3-pro-preview";
106+
var geminiResponse = await geminiClient.Models.GetAsync(model: baseModel, config: null);
107+
108+
Assert.IsNotNull(geminiResponse);
109+
}
94110
}
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
using System;
18+
using System.Collections.Generic;
19+
using System.Linq;
20+
using System.Threading.Tasks;
21+
22+
using Google.GenAI;
23+
using Google.GenAI.Types;
24+
25+
using Microsoft.VisualStudio.TestTools.UnitTesting;
26+
27+
using TestServerSdk;
28+
29+
[TestClass]
30+
public class ListModelsTest
31+
{
32+
private static TestServerProcess? _server;
33+
private Client vertexClient;
34+
private Client geminiClient;
35+
public TestContext TestContext { get; set; }
36+
37+
[ClassInitialize]
38+
public static void ClassInit(TestContext _)
39+
{
40+
_server = TestServer.StartTestServer();
41+
}
42+
43+
[ClassCleanup]
44+
public static void ClassCleanup()
45+
{
46+
TestServer.StopTestServer(_server);
47+
}
48+
49+
[TestInitialize]
50+
public void TestInit()
51+
{
52+
// Test server specific setup.
53+
if (_server == null)
54+
{
55+
throw new InvalidOperationException("Test server is not initialized.");
56+
}
57+
var geminiClientHttpOptions = new HttpOptions
58+
{
59+
Headers = new Dictionary<string, string> { { "Test-Name",
60+
$"{GetType().Name}.{TestContext.TestName}" } },
61+
BaseUrl = "http://localhost:1453"
62+
};
63+
var vertexClientHttpOptions = new HttpOptions
64+
{
65+
Headers = new Dictionary<string, string> { { "Test-Name",
66+
$"{GetType().Name}.{TestContext.TestName}" } },
67+
BaseUrl = "http://localhost:1454"
68+
};
69+
70+
// Common setup for both clients.
71+
string project = System.Environment.GetEnvironmentVariable("GOOGLE_CLOUD_PROJECT");
72+
string location =
73+
System.Environment.GetEnvironmentVariable("GOOGLE_CLOUD_LOCATION") ?? "us-central1";
74+
string apiKey = System.Environment.GetEnvironmentVariable("GOOGLE_API_KEY");
75+
vertexClient = new Client(project: project, location: location, vertexAI: true,
76+
credential: TestServer.GetCredentialForTestMode(),
77+
httpOptions: vertexClientHttpOptions);
78+
geminiClient =
79+
new Client(apiKey: apiKey, vertexAI: false, httpOptions: geminiClientHttpOptions);
80+
}
81+
82+
[TestMethod]
83+
public async Task ListTunedModelsVertex()
84+
{
85+
var config = new ListModelsConfig { QueryBase = false, PageSize = 3 };
86+
var pager = await vertexClient.Models.ListAsync(config);
87+
Assert.IsNotNull(pager);
88+
89+
int count = 0;
90+
await foreach (var model in pager)
91+
{
92+
count++;
93+
if (count >= 4) break;
94+
}
95+
Assert.IsTrue(count >= 0);
96+
}
97+
98+
[TestMethod]
99+
public async Task ListTunedModelsGemini()
100+
{
101+
var config = new ListModelsConfig { QueryBase = false, PageSize = 3 };
102+
var pager = await geminiClient.Models.ListAsync(config);
103+
Assert.IsNotNull(pager);
104+
105+
int count = 0;
106+
await foreach (var model in pager)
107+
{
108+
count++;
109+
if (count >= 4) break;
110+
}
111+
Assert.IsTrue(count >= 0);
112+
}
113+
114+
[TestMethod]
115+
public async Task ListBaseModelsVertex()
116+
{
117+
// Page size set to avoid long output
118+
var config = new ListModelsConfig { PageSize = 5 };
119+
var pager = await vertexClient.Models.ListAsync(config);
120+
Assert.IsNotNull(pager);
121+
122+
int count = 0;
123+
await foreach (var model in pager)
124+
{
125+
count++;
126+
if (count >= 10) break;
127+
}
128+
Assert.IsTrue(count == 10);
129+
}
130+
131+
[TestMethod]
132+
public async Task ListBaseModelsGemini()
133+
{
134+
var pager = await geminiClient.Models.ListAsync();
135+
Assert.IsNotNull(pager);
136+
137+
int count = 0;
138+
await foreach (var model in pager)
139+
{
140+
count++;
141+
if (count >= 4) break;
142+
}
143+
Assert.IsTrue(count >= 0);
144+
}
145+
146+
[TestMethod]
147+
public async Task ListBaseModelsWithConfigVertex()
148+
{
149+
var config = new ListModelsConfig { QueryBase = true, PageSize = 10 };
150+
var pager = await vertexClient.Models.ListAsync(config);
151+
Assert.IsNotNull(pager);
152+
153+
int count = 0;
154+
await foreach (var model in pager)
155+
{
156+
count++;
157+
if (count >= 4) break;
158+
}
159+
Assert.IsTrue(count >= 0);
160+
}
161+
162+
[TestMethod]
163+
public async Task ListBaseModelsWithConfigGemini()
164+
{
165+
var config = new ListModelsConfig { QueryBase = true, PageSize = 5 };
166+
var pager = await geminiClient.Models.ListAsync(config);
167+
Assert.IsNotNull(pager);
168+
169+
int count = 0;
170+
await foreach (var model in pager)
171+
{
172+
count++;
173+
if (count >= 4) break;
174+
}
175+
Assert.IsTrue(count >= 0);
176+
}
177+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"recordID": "GetModelTest.GetBaseModelGeminiTest",
3+
"interactions": [
4+
{
5+
"request": {
6+
"method": "GET",
7+
"url": "/v1beta/models/gemini-3-pro-preview",
8+
"request": "GET /v1beta/models/gemini-3-pro-preview HTTP/1.1",
9+
"headers": {
10+
"Test-Name": "GetModelTest.GetBaseModelGeminiTest"
11+
},
12+
"bodySegments": [
13+
null
14+
],
15+
"previousRequest": "b4d6e60a9b97e7b98c63df9308728c5c88c0b40c398046772c63447b94608b4d",
16+
"serverAddress": "generativelanguage.googleapis.com",
17+
"port": 443,
18+
"protocol": "https"
19+
},
20+
"shaSum": "3aeeb3b1735b2216533db1fef09073048cfe00d413d4764a7ac3ae7a32dbfb82",
21+
"response": {
22+
"statusCode": 200,
23+
"headers": {
24+
"Content-Type": "application/json; charset=UTF-8",
25+
"Date": "Mon, 24 Nov 2025 19:24:16 GMT",
26+
"Server": "scaffolding on HTTPServer2",
27+
"Server-Timing": "gfet4t7; dur=272",
28+
"Vary": "Origin, X-Origin, Referer",
29+
"X-Content-Type-Options": "nosniff",
30+
"X-Frame-Options": "SAMEORIGIN",
31+
"X-Xss-Protection": "0"
32+
},
33+
"bodySegments": [
34+
{
35+
"description": "Gemini 3 Pro Preview",
36+
"displayName": "Gemini 3 Pro Preview",
37+
"inputTokenLimit": 1048576,
38+
"maxTemperature": 2,
39+
"name": "models/gemini-3-pro-preview",
40+
"outputTokenLimit": 65536,
41+
"supportedGenerationMethods": [
42+
"generateContent",
43+
"countTokens",
44+
"createCachedContent",
45+
"batchGenerateContent"
46+
],
47+
"temperature": 1,
48+
"thinking": true,
49+
"topK": 64,
50+
"topP": 0.95,
51+
"version": "3-pro-preview-11-2025"
52+
}
53+
]
54+
}
55+
}
56+
]
57+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"recordID": "GetModelTest.GetBaseModelVertexTest",
3+
"interactions": [
4+
{
5+
"request": {
6+
"method": "GET",
7+
"url": "/v1beta1/publishers/google/models/gemini-3-pro-preview",
8+
"request": "GET /v1beta1/publishers/google/models/gemini-3-pro-preview HTTP/1.1",
9+
"headers": {
10+
"Test-Name": "GetModelTest.GetBaseModelVertexTest"
11+
},
12+
"bodySegments": [
13+
null
14+
],
15+
"previousRequest": "b4d6e60a9b97e7b98c63df9308728c5c88c0b40c398046772c63447b94608b4d",
16+
"serverAddress": "us-central1-aiplatform.googleapis.com",
17+
"port": 443,
18+
"protocol": "https"
19+
},
20+
"shaSum": "832e318305aad4cec67fbea9c23e4e04ea3c279d6995ae0b45b377356b70bca6",
21+
"response": {
22+
"statusCode": 200,
23+
"headers": {
24+
"Content-Type": "application/json; charset=UTF-8",
25+
"Date": "Mon, 24 Nov 2025 19:24:05 GMT",
26+
"Server": "ESF",
27+
"Vary": "Origin, X-Origin, Referer",
28+
"X-Content-Type-Options": "nosniff",
29+
"X-Frame-Options": "SAMEORIGIN",
30+
"X-Xss-Protection": "0"
31+
},
32+
"bodySegments": [
33+
{
34+
"launchStage": "PUBLIC_PREVIEW",
35+
"name": "publishers/google/models/gemini-3-pro-preview",
36+
"publisherModelTemplate": "projects/{project}/locations/{location}/publishers/google/models/gemini-3-pro-preview@default",
37+
"supportedActions": {
38+
"openGenerationAiStudio": {
39+
"references": {
40+
"us-central1": {
41+
"uri": "https://console.cloud.google.com/vertex-ai/generative/multimodal/create/text?model=gemini-3-pro-preview"
42+
}
43+
}
44+
}
45+
},
46+
"versionId": "default"
47+
}
48+
]
49+
}
50+
}
51+
]
52+
}

0 commit comments

Comments
 (0)