Skip to content

Commit 36b7049

Browse files
yyyu-googlecopybara-github
authored andcommitted
chore: update formatting of Google.GenAI
PiperOrigin-RevId: 833665222
1 parent 7bda1e0 commit 36b7049

File tree

233 files changed

+10814
-7208
lines changed

Some content is hidden

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

233 files changed

+10814
-7208
lines changed

Google.GenAI/ApiClient.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
using System.Collections.Immutable;
1818
using System.Reflection;
1919
using System.Runtime.CompilerServices;
20-
using System.Threading;
2120

2221
using Google.Apis.Auth.OAuth2;
2322
using Google.GenAI.Types;
@@ -289,24 +288,24 @@ protected virtual void Dispose(bool disposing)
289288
/// <returns>A <see cref="ValueTask"/> that represents the asynchronous dispose operation.</returns>
290289
public virtual ValueTask DisposeAsync()
291290
{
292-
Dispose();
291+
Dispose();
293292
#if NETSTANDARD2_1
294-
return new ValueTask(Task.CompletedTask);
293+
return new ValueTask(Task.CompletedTask);
295294
#else
296295
return ValueTask.CompletedTask;
297296
#endif
298297
}
299298

300299
private static string GetSdkVersion()
301300
{
302-
// This reads AssemblyInformationalVersionAttribute from the assembly,
303-
// which is generated during build from the <Version> property.
304-
// Google.GenAI.csproj imports ReleaseVersion.xml to set <Version>,
305-
// so this effectively reads the version from ReleaseVersion.xml.
306-
return typeof(ApiClient)
307-
.Assembly
308-
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()
309-
?.InformationalVersion ?? "";
301+
// This reads AssemblyInformationalVersionAttribute from the assembly,
302+
// which is generated during build from the <Version> property.
303+
// Google.GenAI.csproj imports ReleaseVersion.xml to set <Version>,
304+
// so this effectively reads the version from ReleaseVersion.xml.
305+
return typeof(ApiClient)
306+
.Assembly
307+
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()
308+
?.InformationalVersion ?? "";
310309
}
311310
}
312311
}

Google.GenAI/ApiResponse.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,17 @@ public void Dispose()
5454
/// resources; false to release only unmanaged resources.</param>
5555
protected void Dispose(bool disposing)
5656
{
57-
// This atomic check now happens FIRST, guaranteeing it runs only once.
58-
if (Interlocked.CompareExchange(ref _disposed, 1, 0) != 0)
59-
{
60-
return;
61-
}
57+
// This atomic check now happens FIRST, guaranteeing it runs only once.
58+
if (Interlocked.CompareExchange(ref _disposed, 1, 0) != 0)
59+
{
60+
return;
61+
}
6262

63-
if (disposing)
64-
{
65-
// This is the new "hook" for derived classes.
66-
DisposeManagedResources();
67-
}
63+
if (disposing)
64+
{
65+
// This is the new "hook" for derived classes.
66+
DisposeManagedResources();
67+
}
6868
}
6969
protected virtual void DisposeManagedResources() { }
7070

@@ -74,9 +74,9 @@ protected virtual void DisposeManagedResources() { }
7474
/// <returns>A <see cref="ValueTask"/> that represents the asynchronous dispose operation.</returns>
7575
public virtual ValueTask DisposeAsync()
7676
{
77-
Dispose();
77+
Dispose();
7878
#if NETSTANDARD2_1
79-
return new ValueTask(Task.CompletedTask);
79+
return new ValueTask(Task.CompletedTask);
8080
#else
8181
return ValueTask.CompletedTask;
8282
#endif

Google.GenAI/Client.cs

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@
1616

1717
using Google.Apis.Auth.OAuth2;
1818

19-
namespace Google.GenAI {
19+
namespace Google.GenAI
20+
{
2021
/// <summary>
2122
/// Client for making synchronous requests.
2223
/// Using this client to make a request to Gemini Developer API or Vertex AI API.
2324
/// </summary>
24-
public sealed class Client : IDisposable, IAsyncDisposable {
25+
public sealed class Client : IDisposable, IAsyncDisposable
26+
{
2527
private static string? geminiBaseUrl = null;
2628
private static string? vertexBaseUrl = null;
2729
internal readonly ApiClient _apiClient;
@@ -49,11 +51,15 @@ public sealed class Client : IDisposable, IAsyncDisposable {
4951
/// project/location and API key are set together.</exception>
5052
public Client(bool? vertexAI = null, string? apiKey = null, ICredential? credential = null,
5153
string? project = null, string? location = null,
52-
Types.HttpOptions? httpOptions = null) {
54+
Types.HttpOptions? httpOptions = null)
55+
{
5356
bool resolvedVertexAI;
54-
if (vertexAI.HasValue) {
57+
if (vertexAI.HasValue)
58+
{
5559
resolvedVertexAI = vertexAI.Value;
56-
} else {
60+
}
61+
else
62+
{
5763
string? vertexAIEnv = Environment.GetEnvironmentVariable("GOOGLE_GENAI_USE_VERTEXAI");
5864
resolvedVertexAI = vertexAIEnv != null && vertexAIEnv.ToLower() == "true";
5965
}
@@ -63,7 +69,8 @@ public Client(bool? vertexAI = null, string? apiKey = null, ICredential? credent
6369
project = project ?? projectEnv;
6470
location = location ?? locationEnv;
6571
apiKey = apiKey ?? apiKeyEnv;
66-
if (project != null || location != null) {
72+
if (project != null || location != null)
73+
{
6774
if (apiKey != null && projectEnv == null && apiKeyEnv == null)
6875
throw new ArgumentException(
6976
"Project/location and API key are mutually exclusive in the client initializer.");
@@ -86,7 +93,8 @@ public Client(bool? vertexAI = null, string? apiKey = null, ICredential? credent
8693
Models = new Models(_apiClient);
8794
}
8895

89-
static string? inferBaseUrl(bool vertexAI, Types.HttpOptions? httpOptions) {
96+
static string? inferBaseUrl(bool vertexAI, Types.HttpOptions? httpOptions)
97+
{
9098
if (httpOptions?.BaseUrl != null)
9199
return httpOptions.BaseUrl;
92100
if (vertexAI)
@@ -95,7 +103,8 @@ public Client(bool? vertexAI = null, string? apiKey = null, ICredential? credent
95103
return geminiBaseUrl ?? Environment.GetEnvironmentVariable("GOOGLE_GEMINI_BASE_URL");
96104
}
97105

98-
public static void setDefaultBaseUrl(string? vertexBaseUrl, string? geminiBaseUrl) {
106+
public static void setDefaultBaseUrl(string? vertexBaseUrl, string? geminiBaseUrl)
107+
{
99108
Client.vertexBaseUrl = vertexBaseUrl;
100109
Client.geminiBaseUrl = geminiBaseUrl;
101110
}
@@ -105,21 +114,21 @@ public static void setDefaultBaseUrl(string? vertexBaseUrl, string? geminiBaseUr
105114
/// </summary>
106115
public void Dispose()
107116
{
108-
Dispose(true);
109-
GC.SuppressFinalize(this);
117+
Dispose(true);
118+
GC.SuppressFinalize(this);
110119
}
111120

112121
private void Dispose(bool disposing)
113122
{
114-
if (Interlocked.CompareExchange(ref _disposed, 1, 0) != 0)
115-
{
116-
return;
117-
}
123+
if (Interlocked.CompareExchange(ref _disposed, 1, 0) != 0)
124+
{
125+
return;
126+
}
118127

119-
if (disposing)
120-
{
121-
_apiClient.Dispose();
122-
}
128+
if (disposing)
129+
{
130+
_apiClient.Dispose();
131+
}
123132
}
124133

125134
/// <summary>
@@ -128,12 +137,12 @@ private void Dispose(bool disposing)
128137
/// <returns>A <see cref="ValueTask"/> that represents the asynchronous dispose operation.</returns>
129138
public async ValueTask DisposeAsync()
130139
{
131-
if (Interlocked.CompareExchange(ref _disposed, 1, 0) != 0)
132-
{
133-
return;
134-
}
135-
await _apiClient.DisposeAsync();
136-
GC.SuppressFinalize(this);
140+
if (Interlocked.CompareExchange(ref _disposed, 1, 0) != 0)
141+
{
142+
return;
143+
}
144+
await _apiClient.DisposeAsync();
145+
GC.SuppressFinalize(this);
137146
}
138147
}
139148
}

Google.GenAI/HttpApiClient.cs

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,18 @@
1414
* limitations under the License.
1515
*/
1616

17+
18+
/* Unmerged change from project 'Google.GenAI(net8.0)'
19+
Before:
1720
using System.Collections.Generic;
1821
using System.IO;
22+
using System.Net.Http.Headers;
23+
After:
24+
using System.Net.Http.Headers;
25+
*/
1926
using System.Net.Http.Headers;
2027
using System.Runtime.CompilerServices;
2128
using System.Text;
22-
using System.Threading;
2329
using System.Text.Json;
2430
using System.Text.Json.Nodes;
2531
using System.Text.RegularExpressions;
@@ -165,32 +171,32 @@ public override async IAsyncEnumerable<ApiResponse> RequestStreamAsync(
165171
private async Task<HttpRequestMessage> CreateHttpRequestAsync(HttpMethod httpMethod, string path,
166172
string requestJson, Types.HttpOptions? requestHttpOptions)
167173
{
168-
bool queryBaseModel = httpMethod.Equals("GET") && path.StartsWith("publishers/google/models");
169-
if (this.VertexAI && !path.StartsWith("projects/") && !queryBaseModel)
170-
{
171-
path = $"projects/{Project}/locations/{Location}/{path}";
172-
}
174+
bool queryBaseModel = httpMethod.Equals("GET") && path.StartsWith("publishers/google/models");
175+
if (this.VertexAI && !path.StartsWith("projects/") && !queryBaseModel)
176+
{
177+
path = $"projects/{Project}/locations/{Location}/{path}";
178+
}
173179

174-
Types.HttpOptions mergedHttpOptions = MergeHttpOptions(requestHttpOptions);
175-
string requestUrl;
176-
if (string.IsNullOrEmpty(mergedHttpOptions.ApiVersion))
177-
{
178-
requestUrl = $"{mergedHttpOptions.BaseUrl}/{path}";
179-
}
180-
else
181-
{
182-
requestUrl = $"{mergedHttpOptions.BaseUrl}/{mergedHttpOptions.ApiVersion}/{path}";
183-
}
180+
Types.HttpOptions mergedHttpOptions = MergeHttpOptions(requestHttpOptions);
181+
string requestUrl;
182+
if (string.IsNullOrEmpty(mergedHttpOptions.ApiVersion))
183+
{
184+
requestUrl = $"{mergedHttpOptions.BaseUrl}/{path}";
185+
}
186+
else
187+
{
188+
requestUrl = $"{mergedHttpOptions.BaseUrl}/{mergedHttpOptions.ApiVersion}/{path}";
189+
}
184190

185-
var request = new HttpRequestMessage(httpMethod, requestUrl);
186-
await SetHeadersAsync(request, mergedHttpOptions);
191+
var request = new HttpRequestMessage(httpMethod, requestUrl);
192+
await SetHeadersAsync(request, mergedHttpOptions);
187193

188-
if (httpMethod.Method.Equals("POST", StringComparison.OrdinalIgnoreCase) ||
189-
httpMethod.Method.Equals("PATCH", StringComparison.OrdinalIgnoreCase))
190-
{
191-
request.Content = new StringContent(requestJson, System.Text.Encoding.UTF8, "application/json");
192-
}
193-
return request;
194+
if (httpMethod.Method.Equals("POST", StringComparison.OrdinalIgnoreCase) ||
195+
httpMethod.Method.Equals("PATCH", StringComparison.OrdinalIgnoreCase))
196+
{
197+
request.Content = new StringContent(requestJson, System.Text.Encoding.UTF8, "application/json");
198+
}
199+
return request;
194200
}
195201

196202
private static async Task ThrowFromErrorResponse(HttpResponseMessage response)

Google.GenAI/HttpApiResponse.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public override HttpResponseHeaders GetHeaders()
5656
/// </summary>
5757
protected override void DisposeManagedResources()
5858
{
59-
_response?.Dispose();
59+
_response?.Dispose();
6060
}
6161
}
6262
}

Google.GenAI/Live.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
using System.Text;
1919
using System.Text.Json;
2020
using System.Text.Json.Nodes;
21-
using System.Threading;
2221

2322
using Google.GenAI.Types;
2423

@@ -111,20 +110,20 @@ private Uri GetServerUri()
111110
var baseUri = new Uri(baseUrl);
112111
var uriBuilder = new UriBuilder(baseUri)
113112
{
114-
Scheme = baseUri.Scheme == "http" ? "ws" : "wss"
113+
Scheme = baseUri.Scheme == "http" ? "ws" : "wss"
115114
};
116115

117116
string wsBaseUrl = uriBuilder.Uri.ToString().TrimEnd('/');
118117

119118
if (_apiClient.VertexAI)
120119
{
121-
string apiVersion = _apiClient.HttpOptions?.ApiVersion ?? "v1beta1";
122-
return new Uri($"{wsBaseUrl}/ws/google.cloud.aiplatform.{apiVersion}.LlmBidiService/BidiGenerateContent");
120+
string apiVersion = _apiClient.HttpOptions?.ApiVersion ?? "v1beta1";
121+
return new Uri($"{wsBaseUrl}/ws/google.cloud.aiplatform.{apiVersion}.LlmBidiService/BidiGenerateContent");
123122
}
124123
else
125124
{
126-
string apiVersion = _apiClient.HttpOptions?.ApiVersion ?? "v1beta";
127-
return new Uri($"{wsBaseUrl}/ws/google.ai.generativelanguage.{apiVersion}.GenerativeService.BidiGenerateContent");
125+
string apiVersion = _apiClient.HttpOptions?.ApiVersion ?? "v1beta";
126+
return new Uri($"{wsBaseUrl}/ws/google.ai.generativelanguage.{apiVersion}.GenerativeService.BidiGenerateContent");
128127
}
129128
}
130129
catch (UriFormatException e)

0 commit comments

Comments
 (0)