Skip to content

Commit a98430b

Browse files
jaycee-licopybara-github
authored andcommitted
chore: Internal cleanup
FUTURE_COPYBARA_INTEGRATE_REVIEW=https://github.com/google-gemini/private-dotnet-genai/pull/75 from google-gemini:vertex b423641c927b1c5e587c4ddb533afec002844b2d PiperOrigin-RevId: 896138222
1 parent 75b52c7 commit a98430b

File tree

40 files changed

+2480
-4045
lines changed

40 files changed

+2480
-4045
lines changed

Google.GenAI.E2E.Tests/EmbedContent/EmbedContentTest.cs

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ public void TestInit() {
7474
new Client(apiKey: apiKey, vertexAI: false, httpOptions: geminiClientHttpOptions);
7575

7676
// Specific setup for this test class
77-
modelName = "text-embedding-004";
78-
multimodalModelName = "gemini-embedding-2-exp-11-2025";
77+
modelName = "gemini-embedding-001";
78+
multimodalModelName = "gemini-embedding-2-preview";
7979
}
8080

8181
[TestMethod]
@@ -84,7 +84,7 @@ public async Task EmbedContentSimpleTextVertexTest() {
8484
new Content { Parts = new List<Part> { new Part { Text = "What is your name?" } } }
8585
};
8686
var vertexResponse = await vertexClient.Models.EmbedContentAsync(
87-
model: modelName, contents: contents, config: null);
87+
model: modelName, contents: contents, config: new EmbedContentConfig { OutputDimensionality = 10 });
8888

8989
Assert.IsNotNull(vertexResponse.Embeddings);
9090
}
@@ -95,23 +95,23 @@ public async Task EmbedContentSimpleTextGeminiTest() {
9595
new Content { Parts = new List<Part> { new Part { Text = "What is your name?" } } }
9696
};
9797
var geminiResponse = await geminiClient.Models.EmbedContentAsync(
98-
model: modelName, contents: contents, config: null);
98+
model: modelName, contents: contents, config: new EmbedContentConfig { OutputDimensionality = 10 });
9999

100100
Assert.IsNotNull(geminiResponse.Embeddings);
101101
}
102102

103103
[TestMethod]
104104
public async Task EmbedContentSingleStringVertexTest() {
105105
var vertexResponse = await vertexClient.Models.EmbedContentAsync(
106-
model: modelName, contents: "What is your name?", config: null);
106+
model: modelName, contents: "What is your name?", config: new EmbedContentConfig { OutputDimensionality = 10 });
107107

108108
Assert.IsNotNull(vertexResponse.Embeddings);
109109
}
110110

111111
[TestMethod]
112112
public async Task EmbedContentSingleStringGeminiTest() {
113113
var geminiResponse = await geminiClient.Models.EmbedContentAsync(
114-
model: modelName, contents: "What is your name?", config: null);
114+
model: modelName, contents: "What is your name?", config: new EmbedContentConfig { OutputDimensionality = 10 });
115115

116116
Assert.IsNotNull(geminiResponse.Embeddings);
117117
}
@@ -231,7 +231,7 @@ public async Task EmbedContentNewApiTextOnlyVertexTest()
231231
new Content { Parts = new List<Part> { new Part { Text = "What is your name?" } } }
232232
};
233233
var config = new EmbedContentConfig {
234-
OutputDimensionality = 100,
234+
OutputDimensionality = 10,
235235
};
236236
var vertexResponse = await vertexClient.Models.EmbedContentAsync(
237237
model: multimodalModelName, contents: contents, config: config);
@@ -247,7 +247,7 @@ public async Task EmbedContentNewApiMaasVertexTest()
247247
new Content { Parts = new List<Part> { new Part { Text = "What is your name?" } } }
248248
};
249249
var config = new EmbedContentConfig {
250-
OutputDimensionality = 100,
250+
OutputDimensionality = 10,
251251
};
252252
var vertexResponse = await vertexClient.Models.EmbedContentAsync(
253253
model: "publishers/intfloat/models/multilingual-e5-large-instruct-maas", contents: contents, config: config);
@@ -299,4 +299,40 @@ public async Task EmbedContentNewApiListOfContentsVertexTest()
299299

300300
Assert.IsTrue(exception.Message.Contains("The embedContent API for this model only supports one content at a time."));
301301
}
302+
303+
[TestMethod]
304+
public async Task EmbedContentInlinePdfDocumentOcrVertexTest()
305+
{
306+
byte[] fileBytes = await System.IO.File.ReadAllBytesAsync("TestAssets/story.pdf");
307+
var contents = new List<Content> {
308+
new Content { Parts = new List<Part> { Part.FromBytes(fileBytes, "application/pdf") } }
309+
};
310+
var config = new EmbedContentConfig {
311+
OutputDimensionality = 10,
312+
DocumentOcr = true
313+
};
314+
var vertexResponse = await vertexClient.Models.EmbedContentAsync(
315+
model: multimodalModelName, contents: contents, config: config);
316+
317+
Assert.IsNotNull(vertexResponse);
318+
Assert.IsNotNull(vertexResponse.Embeddings);
319+
}
320+
321+
[TestMethod]
322+
public async Task EmbedContentInlineVideoAudioTrackExtractionVertexTest()
323+
{
324+
byte[] fileBytes = await System.IO.File.ReadAllBytesAsync("TestAssets/animal.mp4");
325+
var contents = new List<Content> {
326+
new Content { Parts = new List<Part> { Part.FromBytes(fileBytes, "video/mp4") } }
327+
};
328+
var config = new EmbedContentConfig {
329+
OutputDimensionality = 10,
330+
AudioTrackExtraction = true
331+
};
332+
var vertexResponse = await vertexClient.Models.EmbedContentAsync(
333+
model: multimodalModelName, contents: contents, config: config);
334+
335+
Assert.IsNotNull(vertexResponse);
336+
Assert.IsNotNull(vertexResponse.Embeddings);
337+
}
302338
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
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.Net.Http;
21+
using System.Threading.Tasks;
22+
23+
using Google.GenAI;
24+
using Google.GenAI.Types;
25+
26+
using Microsoft.VisualStudio.TestTools.UnitTesting;
27+
28+
using TestServerSdk;
29+
30+
[TestClass]
31+
public class GenerateContentSimpleTestCustomClient {
32+
private static TestServerProcess? _server;
33+
private Client vertexClient;
34+
private Client geminiClient;
35+
private string modelName;
36+
public TestContext TestContext { get; set; }
37+
38+
[ClassInitialize]
39+
public static void ClassInit(TestContext _) {
40+
_server = TestServer.StartTestServer();
41+
}
42+
43+
[ClassCleanup]
44+
public static void ClassCleanup() {
45+
TestServer.StopTestServer(_server);
46+
}
47+
48+
[TestInitialize]
49+
public void TestInit() {
50+
// Test server specific setup.
51+
if (_server == null) {
52+
throw new InvalidOperationException("Test server is not initialized.");
53+
}
54+
var geminiClientHttpOptions = new HttpOptions {
55+
Headers = new Dictionary<string, string> { { "Test-Name",
56+
$"{GetType().Name}.{TestContext.TestName}" } },
57+
BaseUrl = "http://localhost:1453"
58+
};
59+
var vertexClientHttpOptions = new HttpOptions {
60+
Headers = new Dictionary<string, string> { { "Test-Name",
61+
$"{GetType().Name}.{TestContext.TestName}" } },
62+
BaseUrl = "http://localhost:1454"
63+
};
64+
65+
// Common setup for both clients.
66+
string project = System.Environment.GetEnvironmentVariable("GOOGLE_CLOUD_PROJECT");
67+
string location =
68+
System.Environment.GetEnvironmentVariable("GOOGLE_CLOUD_LOCATION") ?? "us-central1";
69+
string apiKey = System.Environment.GetEnvironmentVariable("GOOGLE_API_KEY");
70+
vertexClient = new Client(project: project, location: location, vertexAI: true,
71+
credential: TestServer.GetCredentialForTestMode(),
72+
httpOptions: vertexClientHttpOptions,
73+
clientOptions: new ClientOptions {
74+
HttpClientFactory = () => new HttpClient(new HttpClientHandler()) {
75+
Timeout = TimeSpan.FromMinutes(5)
76+
}
77+
});
78+
geminiClient =
79+
new Client(apiKey: apiKey, vertexAI: false, httpOptions: geminiClientHttpOptions,
80+
clientOptions: new ClientOptions {
81+
HttpClientFactory = () => new HttpClient(new HttpClientHandler()) {
82+
Timeout = TimeSpan.FromMinutes(5)
83+
}
84+
});
85+
86+
// Specific setup for this test class
87+
modelName = "gemini-2.5-flash";
88+
}
89+
90+
[TestMethod]
91+
public async Task GenerateContentSimpleTextVertexTest() {
92+
var vertexResponse = await vertexClient.Models.GenerateContentAsync(
93+
model: modelName, contents: "What is the capital of France?");
94+
95+
Assert.IsNotNull(vertexResponse.Candidates);
96+
StringAssert.Contains(vertexResponse.Text, "Paris");
97+
}
98+
99+
[TestMethod]
100+
public async Task GenerateContentSimpleTextGeminiTest() {
101+
var geminiResponse = await geminiClient.Models.GenerateContentAsync(
102+
model: modelName, contents: "What is the capital of France?");
103+
104+
Assert.IsNotNull(geminiResponse.Candidates);
105+
StringAssert.Contains(geminiResponse.Text, "Paris");
106+
}
107+
}

Google.GenAI.E2E.Tests/Recordings/EmbedContentTest.EmbedContentInlinePdfDocumentOcrVertexTest.json

Lines changed: 80 additions & 0 deletions
Large diffs are not rendered by default.

Google.GenAI.E2E.Tests/Recordings/EmbedContentTest.EmbedContentInlineVideoAudioTrackExtractionVertexTest.json

Lines changed: 80 additions & 0 deletions
Large diffs are not rendered by default.

Google.GenAI.E2E.Tests/Recordings/EmbedContentTest.EmbedContentMultiTextGeminiTest.json

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
{
55
"request": {
66
"method": "POST",
7-
"url": "/v1beta/models/text-embedding-004:batchEmbedContents",
8-
"request": "POST /v1beta/models/text-embedding-004:batchEmbedContents HTTP/1.1",
7+
"url": "/v1beta/models/gemini-embedding-001:batchEmbedContents",
8+
"request": "POST /v1beta/models/gemini-embedding-001:batchEmbedContents HTTP/1.1",
99
"headers": {
10-
"Content-Length": "347",
10+
"Content-Length": "351",
1111
"Content-Type": "application/json; charset=utf-8",
1212
"Test-Name": "EmbedContentTest.EmbedContentMultiTextGeminiTest"
1313
},
@@ -22,7 +22,7 @@
2222
}
2323
]
2424
},
25-
"model": "models/text-embedding-004",
25+
"model": "models/gemini-embedding-001",
2626
"outputDimensionality": 10,
2727
"taskType": "RETRIEVAL_DOCUMENT",
2828
"title": "test_title"
@@ -35,7 +35,7 @@
3535
}
3636
]
3737
},
38-
"model": "models/text-embedding-004",
38+
"model": "models/gemini-embedding-001",
3939
"outputDimensionality": 10,
4040
"taskType": "RETRIEVAL_DOCUMENT",
4141
"title": "test_title"
@@ -48,14 +48,14 @@
4848
"port": 443,
4949
"protocol": "https"
5050
},
51-
"shaSum": "50128cd8a28c44e38af1b0551cc25ebf7c7af1c59953d49db45899a450dbb1bc",
51+
"shaSum": "2da9e795ef60e639f9f070fea9a6736bd1be0d0358809e2b5510e4c63466fa48",
5252
"response": {
5353
"statusCode": 200,
5454
"headers": {
5555
"Content-Type": "application/json; charset=UTF-8",
56-
"Date": "Tue, 09 Dec 2025 00:42:46 GMT",
56+
"Date": "Thu, 09 Apr 2026 18:58:31 GMT",
5757
"Server": "scaffolding on HTTPServer2",
58-
"Server-Timing": "gfet4t7; dur=179",
58+
"Server-Timing": "gfet4t7; dur=150",
5959
"Vary": "Origin, X-Origin, Referer",
6060
"X-Content-Type-Options": "nosniff",
6161
"X-Frame-Options": "SAMEORIGIN",
@@ -66,33 +66,34 @@
6666
"embeddings": [
6767
{
6868
"values": [
69-
0.0062209684,
70-
-0.00016352482,
71-
-0.04497254,
72-
-0.024360893,
73-
0.024183987,
74-
0.027219841,
75-
0.036644667,
76-
0.028461628,
77-
-0.04021491,
78-
0.03328241
69+
-0.03950208,
70+
0.0007256423,
71+
0.036894154,
72+
-0.06420937,
73+
0.007837503,
74+
0.0070161745,
75+
-0.013046161,
76+
0.0040008393,
77+
0.019140515,
78+
-0.0029148892
7979
]
8080
},
8181
{
8282
"values": [
83-
-0.02997993,
84-
-0.031975683,
85-
-0.041643385,
86-
-0.01656822,
87-
0.031309083,
88-
0.025444405,
89-
0.0028291983,
90-
0.05965454,
91-
-0.014440891,
92-
0.024713816
83+
-0.037093285,
84+
0.010633466,
85+
0.022869334,
86+
-0.066629514,
87+
-0.0067563136,
88+
0.012390815,
89+
-0.0096923895,
90+
-0.0016614407,
91+
-0.0002718712,
92+
-0.010780795
9393
]
9494
}
95-
]
95+
],
96+
"tokenCount": "10"
9697
}
9798
]
9899
}

0 commit comments

Comments
 (0)