From e7a549237fde180c60c8ccbe9e6386f471217d76 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 26 Oct 2026 03:22:10 +0000 Subject: [PATCH] feat: Updated OpenAPI spec --- src/cli/AsyncAI.CLI/CliRuntime.cs | 115 +++--- ...ncAI.ITextToSpeechClient.StreamSpeech.g.cs | 18 + ....ITextToSpeechClient.SynthesizeSpeech.g.cs | 18 + .../Generated/AsyncAI.ResponseStream.g.cs | 66 ++- ...yncAI.TextToSpeechClient.StreamSpeech.g.cs | 386 ++++++++++++++++++ ...I.TextToSpeechClient.SynthesizeSpeech.g.cs | 386 ++++++++++++++++++ 6 files changed, 908 insertions(+), 81 deletions(-) diff --git a/src/cli/AsyncAI.CLI/CliRuntime.cs b/src/cli/AsyncAI.CLI/CliRuntime.cs index 087edaf..d5e0ed0 100644 --- a/src/cli/AsyncAI.CLI/CliRuntime.cs +++ b/src/cli/AsyncAI.CLI/CliRuntime.cs @@ -4,9 +4,6 @@ using System.CommandLine.Parsing; using System.Globalization; using System.Text; -using System.Text.Json; -using System.Text.Json.Nodes; -using System.Text.Json.Serialization; namespace AsyncAI.CLI; @@ -131,7 +128,7 @@ internal static class CliRuntime var values = await ReadUserSecretsAsync(cancellationToken).ConfigureAwait(false); values[name] = value; - var json = PrettyJson(JsonSerializer.Serialize(values, UserSecretsJsonContext.Default.DictionaryStringString)); + var json = PrettyJson(global::System.Text.Json.JsonSerializer.Serialize(values, UserSecretsJsonContext.Default.DictionaryStringString)); await File.WriteAllTextAsync(path, json, cancellationToken).ConfigureAwait(false); } @@ -149,7 +146,7 @@ internal static class CliRuntime return; } - var json = PrettyJson(JsonSerializer.Serialize(values, UserSecretsJsonContext.Default.DictionaryStringString)); + var json = PrettyJson(global::System.Text.Json.JsonSerializer.Serialize(values, UserSecretsJsonContext.Default.DictionaryStringString)); await File.WriteAllTextAsync(path, json, cancellationToken).ConfigureAwait(false); } @@ -311,7 +308,7 @@ public static TimeSpan ParseDuration(string value, string optionName) Option inputOption, Option requestJsonOption, Option requestFileOption, - JsonSerializerContext context, + global::System.Text.Json.Serialization.JsonSerializerContext context, CancellationToken cancellationToken = default) { var requestJson = await ReadInputAsync( @@ -322,7 +319,7 @@ public static TimeSpan ParseDuration(string value, string optionName) required: true, cancellationToken).ConfigureAwait(false); - var value = JsonSerializer.Deserialize(requestJson ?? throw new CliException("Request input is required."), typeof(T), context); + var value = global::System.Text.Json.JsonSerializer.Deserialize(requestJson ?? throw new CliException("Request input is required."), typeof(T), context); return value is T typed ? typed : throw new CliException($"Unable to deserialize request JSON as {typeof(T).Name}."); @@ -333,7 +330,7 @@ public static TimeSpan ParseDuration(string value, string optionName) Option inputOption, Option requestJsonOption, Option requestFileOption, - JsonSerializerContext context, + global::System.Text.Json.Serialization.JsonSerializerContext context, CancellationToken cancellationToken = default) { var requestJson = await ReadInputAsync( @@ -347,15 +344,15 @@ public static TimeSpan ParseDuration(string value, string optionName) return default; } - var value = JsonSerializer.Deserialize(requestJson!, typeof(T), context); + var value = global::System.Text.Json.JsonSerializer.Deserialize(requestJson!, typeof(T), context); return value is T typed ? typed : throw new CliException($"Unable to deserialize request JSON as {typeof(T).Name}."); } - public static T DeserializeJsonValue(string json, JsonSerializerContext context) + public static T DeserializeJsonValue(string json, global::System.Text.Json.Serialization.JsonSerializerContext context) { - var value = JsonSerializer.Deserialize(json, typeof(T), context); + var value = global::System.Text.Json.JsonSerializer.Deserialize(json, typeof(T), context); return value is T typed ? typed : throw new CliException($"Unable to deserialize generated CLI value as {typeof(T).Name}."); @@ -363,7 +360,7 @@ public static T DeserializeJsonValue(string json, JsonSerializerContext conte public static string SerializeKeyValuePairs(IEnumerable pairs) { - var objectNode = new JsonObject(); + var objectNode = new global::System.Text.Json.Nodes.JsonObject(); foreach (var pair in pairs) { var separatorIndex = pair.IndexOf('=', StringComparison.Ordinal); @@ -387,32 +384,32 @@ public static string SerializeKeyValuePairs(IEnumerable pairs) public static string SerializeStringArray(IEnumerable values) { - var array = new JsonArray(); + var array = new global::System.Text.Json.Nodes.JsonArray(); foreach (var value in values) { - array.Add((JsonNode?)JsonValue.Create(value)); + array.Add((global::System.Text.Json.Nodes.JsonNode?)global::System.Text.Json.Nodes.JsonValue.Create(value)); } return array.ToJsonString(); } - public static async global::System.Threading.Tasks.Task WriteJsonAsync(ParseResult parseResult, T value, JsonSerializerContext context, CancellationToken cancellationToken = default) + public static async global::System.Threading.Tasks.Task WriteJsonAsync(ParseResult parseResult, T value, global::System.Text.Json.Serialization.JsonSerializerContext context, CancellationToken cancellationToken = default) { - var json = JsonSerializer.Serialize(value, typeof(T), context); + var json = global::System.Text.Json.JsonSerializer.Serialize(value, typeof(T), context); await WriteTextAsync(parseResult, PrettyJson(json), cancellationToken: cancellationToken).ConfigureAwait(false); } - public static async global::System.Threading.Tasks.Task WriteJsonLineAsync(ParseResult parseResult, T value, JsonSerializerContext context, CancellationToken cancellationToken = default) + public static async global::System.Threading.Tasks.Task WriteJsonLineAsync(ParseResult parseResult, T value, global::System.Text.Json.Serialization.JsonSerializerContext context, CancellationToken cancellationToken = default) { - var json = JsonSerializer.Serialize(value, typeof(T), context); + var json = global::System.Text.Json.JsonSerializer.Serialize(value, typeof(T), context); await WriteTextAsync(parseResult, json + Environment.NewLine, append: true, cancellationToken: cancellationToken).ConfigureAwait(false); } public static async global::System.Threading.Tasks.Task WriteResponseAsync( ParseResult parseResult, T value, - JsonSerializerContext context, - Func? formatter = null, + global::System.Text.Json.Serialization.JsonSerializerContext context, + Func? formatter = null, CancellationToken cancellationToken = default) { if (parseResult.GetValue(CliOptions.Json)) @@ -431,8 +428,8 @@ public static string SerializeStringArray(IEnumerable values) public static async global::System.Threading.Tasks.Task WriteResponseLineAsync( ParseResult parseResult, T value, - JsonSerializerContext context, - Func? formatter = null, + global::System.Text.Json.Serialization.JsonSerializerContext context, + Func? formatter = null, CancellationToken cancellationToken = default) { if (parseResult.GetValue(CliOptions.Json)) @@ -451,7 +448,7 @@ public static string SerializeStringArray(IEnumerable values) public static async global::System.Threading.Tasks.Task TryWriteOutputDirectoryAsync( ParseResult parseResult, T value, - JsonSerializerContext context, + global::System.Text.Json.Serialization.JsonSerializerContext context, string itemsPropertyName, CancellationToken cancellationToken = default) { @@ -463,8 +460,8 @@ public static string SerializeStringArray(IEnumerable values) var rootNode = ToJsonNode(value, typeof(T), context); var items = itemsPropertyName == "$self" - ? rootNode as JsonArray - : rootNode?[itemsPropertyName] as JsonArray; + ? rootNode as global::System.Text.Json.Nodes.JsonArray + : rootNode?[itemsPropertyName] as global::System.Text.Json.Nodes.JsonArray; if (items is null) { throw new CliException("The response does not contain a writable item collection for --output-dir."); @@ -565,7 +562,7 @@ public static string MaskSecret(string secret) return new Dictionary(StringComparer.Ordinal); } - return JsonSerializer.Deserialize(json, UserSecretsJsonContext.Default.DictionaryStringString) ?? + return global::System.Text.Json.JsonSerializer.Deserialize(json, UserSecretsJsonContext.Default.DictionaryStringString) ?? new Dictionary(StringComparer.Ordinal); } @@ -656,22 +653,22 @@ private static bool EndsWithUnit(string value, char unit) return await File.ReadAllTextAsync(pathOrDash, cancellationToken).ConfigureAwait(false); } - private static JsonNode? ToJsonNode(T value, Type type, JsonSerializerContext context) + private static global::System.Text.Json.Nodes.JsonNode? ToJsonNode(T value, Type type, global::System.Text.Json.Serialization.JsonSerializerContext context) { - var json = JsonSerializer.Serialize(value, type, context); - return JsonNode.Parse(json); + var json = global::System.Text.Json.JsonSerializer.Serialize(value, type, context); + return global::System.Text.Json.Nodes.JsonNode.Parse(json); } - private static JsonElement ToJsonElement(T value, JsonSerializerContext context) + private static global::System.Text.Json.JsonElement ToJsonElement(T value, global::System.Text.Json.Serialization.JsonSerializerContext context) { - var json = JsonSerializer.Serialize(value, typeof(T), context); - using var document = JsonDocument.Parse(json); + var json = global::System.Text.Json.JsonSerializer.Serialize(value, typeof(T), context); + using var document = global::System.Text.Json.JsonDocument.Parse(json); return document.RootElement.Clone(); } public static string FormatHumanReadable( T value, - JsonSerializerContext context, + global::System.Text.Json.Serialization.JsonSerializerContext context, bool truncateLongStrings, IReadOnlyDictionary? formatHints = null) { @@ -684,7 +681,7 @@ public static string FormatHumanReadable( private static void AppendFormattedValue( StringBuilder builder, string? name, - JsonElement element, + global::System.Text.Json.JsonElement element, int indent, bool truncateLongStrings, IReadOnlyDictionary? formatHints, @@ -695,7 +692,7 @@ private static void AppendFormattedValue( return; } - if (element.ValueKind == JsonValueKind.String && + if (element.ValueKind == global::System.Text.Json.JsonValueKind.String && HasFormatHint(path, CliFormatHint.Code, formatHints)) { AppendCodeBlock(builder, name, element.GetString() ?? string.Empty, indent); @@ -704,10 +701,10 @@ private static void AppendFormattedValue( switch (element.ValueKind) { - case JsonValueKind.Object: + case global::System.Text.Json.JsonValueKind.Object: AppendFormattedObject(builder, name, element, indent, truncateLongStrings, formatHints, path); break; - case JsonValueKind.Array: + case global::System.Text.Json.JsonValueKind.Array: AppendFormattedArray(builder, name, element, indent, truncateLongStrings, formatHints, path); break; default: @@ -719,7 +716,7 @@ private static void AppendFormattedValue( private static void AppendFormattedObject( StringBuilder builder, string? name, - JsonElement element, + global::System.Text.Json.JsonElement element, int indent, bool truncateLongStrings, IReadOnlyDictionary? formatHints, @@ -751,7 +748,7 @@ private static void AppendFormattedObject( private static void AppendFormattedArray( StringBuilder builder, string? name, - JsonElement element, + global::System.Text.Json.JsonElement element, int indent, bool truncateLongStrings, IReadOnlyDictionary? formatHints, @@ -770,7 +767,7 @@ private static void AppendFormattedArray( return; } - if (items.All(static item => item.ValueKind is not JsonValueKind.Object and not JsonValueKind.Array)) + if (items.All(static item => item.ValueKind is not global::System.Text.Json.JsonValueKind.Object and not global::System.Text.Json.JsonValueKind.Array)) { foreach (var item in items) { @@ -787,15 +784,15 @@ private static void AppendFormattedArray( } } - private static string FormatScalar(JsonElement element, bool truncateLongStrings) + private static string FormatScalar(global::System.Text.Json.JsonElement element, bool truncateLongStrings) { return element.ValueKind switch { - JsonValueKind.String => FormatStringScalar(element.GetString() ?? string.Empty, truncateLongStrings), - JsonValueKind.True => "true", - JsonValueKind.False => "false", - JsonValueKind.Number => element.GetRawText(), - JsonValueKind.Null => "null", + global::System.Text.Json.JsonValueKind.String => FormatStringScalar(element.GetString() ?? string.Empty, truncateLongStrings), + global::System.Text.Json.JsonValueKind.True => "true", + global::System.Text.Json.JsonValueKind.False => "false", + global::System.Text.Json.JsonValueKind.Number => element.GetRawText(), + global::System.Text.Json.JsonValueKind.Null => "null", _ => element.GetRawText(), }; } @@ -859,18 +856,18 @@ private static void AppendLine(StringBuilder builder, int indent, string value) builder.AppendLine(value); } - private static async global::System.Threading.Tasks.Task WriteItemFilesAsync(string outputDirectory, JsonArray items, CancellationToken cancellationToken = default) + private static async global::System.Threading.Tasks.Task WriteItemFilesAsync(string outputDirectory, global::System.Text.Json.Nodes.JsonArray items, CancellationToken cancellationToken = default) { Directory.CreateDirectory(outputDirectory); for (var index = 0; index < items.Count; index++) { - if (items[index] is not JsonNode itemNode) + if (items[index] is not global::System.Text.Json.Nodes.JsonNode itemNode) { continue; } - var itemObject = itemNode as JsonObject; + var itemObject = itemNode as global::System.Text.Json.Nodes.JsonObject; var baseName = itemObject is null ? $"{index + 1:000}" : SanitizeFileName(GetOutputItemName(itemObject) ?? $"{index + 1:000}"); @@ -884,7 +881,7 @@ private static void AppendLine(StringBuilder builder, int indent, string value) wroteStructuredFile |= await TryWriteTextPropertyAsync(itemObject, outputDirectory, baseName, "raw_html", ".raw.html", cancellationToken).ConfigureAwait(false); wroteStructuredFile |= await TryWriteTextPropertyAsync(itemObject, outputDirectory, baseName, "text", ".txt", cancellationToken).ConfigureAwait(false); - if (TryGetNamedNode(itemObject, out var linksNode, "links") && linksNode is JsonArray links) + if (TryGetNamedNode(itemObject, out var linksNode, "links") && linksNode is global::System.Text.Json.Nodes.JsonArray links) { var linkLines = links .Select(static node => node?.GetValue()) @@ -901,7 +898,7 @@ await File.WriteAllTextAsync( } } - var json = itemNode.ToJsonString(new JsonSerializerOptions { WriteIndented = true }); + var json = itemNode.ToJsonString(new global::System.Text.Json.JsonSerializerOptions { WriteIndented = true }); var fileName = wroteStructuredFile ? $"{baseName}.metadata.json" : $"{baseName}.json"; @@ -910,7 +907,7 @@ await File.WriteAllTextAsync( } private static async global::System.Threading.Tasks.Task TryWriteTextPropertyAsync( - JsonObject item, + global::System.Text.Json.Nodes.JsonObject item, string outputDirectory, string baseName, string propertyName, @@ -935,7 +932,7 @@ await File.WriteAllTextAsync( return true; } - private static string? GetOutputItemName(JsonObject item) + private static string? GetOutputItemName(global::System.Text.Json.Nodes.JsonObject item) { if (TryGetNamedNode(item, out var node, "url", "sourceUrl", "source_url", "id")) { @@ -945,7 +942,7 @@ await File.WriteAllTextAsync( return null; } - private static bool TryGetNamedNode(JsonObject item, out JsonNode? node, params string[] names) + private static bool TryGetNamedNode(global::System.Text.Json.Nodes.JsonObject item, out global::System.Text.Json.Nodes.JsonNode? node, params string[] names) { foreach (var property in item) { @@ -993,9 +990,9 @@ private static string SanitizeFileName(string value) private static string PrettyJson(string json) { - using var document = JsonDocument.Parse(json); + using var document = global::System.Text.Json.JsonDocument.Parse(json); using var stream = new MemoryStream(); - using (var writer = new Utf8JsonWriter(stream, new JsonWriterOptions { Indented = true })) + using (var writer = new global::System.Text.Json.Utf8JsonWriter(stream, new global::System.Text.Json.JsonWriterOptions { Indented = true })) { document.WriteTo(writer); } @@ -1072,6 +1069,6 @@ internal sealed record AuthSourceProbe(string Source, string DisplayName, string public bool Present => !string.IsNullOrWhiteSpace(RawValue); } -[JsonSerializable(typeof(AuthStatusInfo))] -[JsonSerializable(typeof(Dictionary))] -internal sealed partial class UserSecretsJsonContext : JsonSerializerContext; \ No newline at end of file +[global::System.Text.Json.Serialization.JsonSerializable(typeof(AuthStatusInfo))] +[global::System.Text.Json.Serialization.JsonSerializable(typeof(Dictionary))] +internal sealed partial class UserSecretsJsonContext : global::System.Text.Json.Serialization.JsonSerializerContext; \ No newline at end of file diff --git a/src/libs/AsyncAI/Generated/AsyncAI.ITextToSpeechClient.StreamSpeech.g.cs b/src/libs/AsyncAI/Generated/AsyncAI.ITextToSpeechClient.StreamSpeech.g.cs index 29bc74c..12db06a 100644 --- a/src/libs/AsyncAI/Generated/AsyncAI.ITextToSpeechClient.StreamSpeech.g.cs +++ b/src/libs/AsyncAI/Generated/AsyncAI.ITextToSpeechClient.StreamSpeech.g.cs @@ -46,6 +46,24 @@ public partial interface ITextToSpeechClient /// Default Value: v1 /// /// + /// The response metadata and an unbuffered body stream. The caller must dispose Body to release the HTTP response. + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + global::System.Threading.Tasks.Task> StreamSpeechAsStreamAsResponseAsync( + + global::AsyncAI.TextToSpeechRequest request, + string? version = default, + global::AsyncAI.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default); + /// + /// Text to speech stream
+ /// Generates speech from text and streams audio in the response body. + ///
+ /// + /// Default Value: v1 + /// + /// /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// diff --git a/src/libs/AsyncAI/Generated/AsyncAI.ITextToSpeechClient.SynthesizeSpeech.g.cs b/src/libs/AsyncAI/Generated/AsyncAI.ITextToSpeechClient.SynthesizeSpeech.g.cs index 33aab9e..5684f6d 100644 --- a/src/libs/AsyncAI/Generated/AsyncAI.ITextToSpeechClient.SynthesizeSpeech.g.cs +++ b/src/libs/AsyncAI/Generated/AsyncAI.ITextToSpeechClient.SynthesizeSpeech.g.cs @@ -46,6 +46,24 @@ public partial interface ITextToSpeechClient /// Default Value: v1 /// /// + /// The response metadata and an unbuffered body stream. The caller must dispose Body to release the HTTP response. + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + global::System.Threading.Tasks.Task> SynthesizeSpeechAsStreamAsResponseAsync( + + global::AsyncAI.TextToSpeechRequest request, + string? version = default, + global::AsyncAI.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default); + /// + /// Text to speech
+ /// Generates speech from text and returns complete audio. + ///
+ /// + /// Default Value: v1 + /// + /// /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// diff --git a/src/libs/AsyncAI/Generated/AsyncAI.ResponseStream.g.cs b/src/libs/AsyncAI/Generated/AsyncAI.ResponseStream.g.cs index e8dff96..69b2ab0 100644 --- a/src/libs/AsyncAI/Generated/AsyncAI.ResponseStream.g.cs +++ b/src/libs/AsyncAI/Generated/AsyncAI.ResponseStream.g.cs @@ -7,7 +7,7 @@ internal sealed class ResponseStream : global::System.IO.Stream { private readonly global::System.Net.Http.HttpResponseMessage _response; private readonly global::System.IO.Stream _stream; - private bool _disposed; + private int _disposed; public ResponseStream( global::System.Net.Http.HttpResponseMessage response, @@ -47,21 +47,51 @@ public override int WriteTimeout global::System.Threading.CancellationToken cancellationToken) => _stream.FlushAsync(cancellationToken); - public override int Read(byte[] buffer, int offset, int count) => - _stream.Read(buffer, offset, count); + public override int Read(byte[] buffer, int offset, int count) + { + try + { + return _stream.Read(buffer, offset, count); + } + catch + { + Dispose(); + throw; + } + } - public override global::System.Threading.Tasks.Task ReadAsync( + public override async global::System.Threading.Tasks.Task ReadAsync( byte[] buffer, int offset, int count, - global::System.Threading.CancellationToken cancellationToken) => - _stream.ReadAsync(buffer, offset, count, cancellationToken); + global::System.Threading.CancellationToken cancellationToken) + { + try + { + return await _stream.ReadAsync(buffer, offset, count, cancellationToken).ConfigureAwait(false); + } + catch + { + Dispose(); + throw; + } + } #if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_0_OR_GREATER || NET5_0_OR_GREATER - public override global::System.Threading.Tasks.ValueTask ReadAsync( + public override async global::System.Threading.Tasks.ValueTask ReadAsync( global::System.Memory buffer, - global::System.Threading.CancellationToken cancellationToken = default) => - _stream.ReadAsync(buffer, cancellationToken); + global::System.Threading.CancellationToken cancellationToken = default) + { + try + { + return await _stream.ReadAsync(buffer, cancellationToken).ConfigureAwait(false); + } + catch + { + Dispose(); + throw; + } + } #endif public override long Seek(long offset, global::System.IO.SeekOrigin origin) => @@ -89,10 +119,9 @@ public override void Write(byte[] buffer, int offset, int count) => protected override void Dispose(bool disposing) { - if (!_disposed && disposing) + if (disposing && global::System.Threading.Interlocked.Exchange(ref _disposed, 1) == 0) { - _disposed = true; - _stream.Dispose(); + // The response content owns the underlying stream; disposing both would close it twice. _response.Dispose(); } @@ -100,17 +129,10 @@ protected override void Dispose(bool disposing) } #if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_0_OR_GREATER || NET5_0_OR_GREATER - public override async global::System.Threading.Tasks.ValueTask DisposeAsync() + public override global::System.Threading.Tasks.ValueTask DisposeAsync() { - if (_disposed) - { - return; - } - - _disposed = true; - await _stream.DisposeAsync().ConfigureAwait(false); - _response.Dispose(); - await base.DisposeAsync().ConfigureAwait(false); + Dispose(); + return default; } #endif } diff --git a/src/libs/AsyncAI/Generated/AsyncAI.TextToSpeechClient.StreamSpeech.g.cs b/src/libs/AsyncAI/Generated/AsyncAI.TextToSpeechClient.StreamSpeech.g.cs index ffc5743..0e42ec7 100644 --- a/src/libs/AsyncAI/Generated/AsyncAI.TextToSpeechClient.StreamSpeech.g.cs +++ b/src/libs/AsyncAI/Generated/AsyncAI.TextToSpeechClient.StreamSpeech.g.cs @@ -406,6 +406,392 @@ partial void ProcessStreamSpeechResponseContent( return new global::AsyncAI.ResponseStream(__response, __content); } + catch (global::System.OperationCanceledException) + { + throw; + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw global::AsyncAI.ApiException.Create( + statusCode: __response.StatusCode, + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + responseBody: __content, + responseHeaders: global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value)); + } + + } + catch + { + __response.Dispose(); + throw; + } + } + finally + { + __httpRequest?.Dispose(); + } + } + /// + /// Text to speech stream
+ /// Generates speech from text and streams audio in the response body. + ///
+ /// + /// Default Value: v1 + /// + /// + /// The response metadata and an unbuffered body stream. The caller must dispose Body to release the HTTP response. + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + public async global::System.Threading.Tasks.Task> StreamSpeechAsStreamAsResponseAsync( + + global::AsyncAI.TextToSpeechRequest request, + string? version = default, + global::AsyncAI.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default) + { + request = request ?? throw new global::System.ArgumentNullException(nameof(request)); + + PrepareArguments( + client: HttpClient); + PrepareStreamSpeechArguments( + httpClient: HttpClient, + version: ref version, + request: request); + + + var __authorizations = global::AsyncAI.EndPointSecurityResolver.ResolveAuthorizations( + availableAuthorizations: Authorizations, + securityRequirements: s_StreamSpeechSecurityRequirements, + operationName: "StreamSpeechAsync"); + + using var __timeoutCancellationTokenSource = global::AsyncAI.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::AsyncAI.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::AsyncAI.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + + var __pathBuilder = new global::AsyncAI.PathBuilder( + path: "/text_to_speech/streaming", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::AsyncAI.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); +#if NET6_0_OR_GREATER + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; +#endif + + foreach (var __authorization in __authorizations) + { + if (__authorization.Type == "Http" || + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") + { + __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( + scheme: __authorization.Name, + parameter: __authorization.Value); + } + else if (__authorization.Type == "ApiKey" && + __authorization.Location == "Header") + { + __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); + } + } + + if (version != default) + { + __httpRequest.Headers.TryAddWithoutValidation("version", version.ToString()); + } + + var __httpRequestContentBody = request.ToJson(JsonSerializerContext); + var __httpRequestContent = new global::System.Net.Http.StringContent( + content: __httpRequestContentBody, + encoding: global::System.Text.Encoding.UTF8, + mediaType: "application/json"); + __httpRequest.Content = __httpRequestContent; + global::AsyncAI.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareStreamSpeechRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + version: version, + request: request); + + return __httpRequest; + } + + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try + { + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::AsyncAI.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::AsyncAI.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "StreamSpeech", + methodName: "StreamSpeechAsync", + pathTemplate: "\"/text_to_speech/streaming\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest ?? throw new global::System.InvalidOperationException("The HTTP request was not created before invoking a request hook."), + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try + { + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseHeadersRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + } + catch (global::System.Net.Http.HttpRequestException __exception) + { + var __retryDelay = global::AsyncAI.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: null, + attempt: __attempt); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::AsyncAI.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::AsyncAI.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "StreamSpeech", + methodName: "StreamSpeechAsync", + pathTemplate: "\"/text_to_speech/streaming\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest ?? throw new global::System.InvalidOperationException("The HTTP request was not created before invoking a request hook."), + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + retryDelay: __willRetry ? __retryDelay : (global::System.TimeSpan?)null, + retryReason: "exception", + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::AsyncAI.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + retryDelay: __retryDelay, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; + } + + if (__response != null && + __attempt < __maxAttempts && + global::AsyncAI.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) + { + var __retryDelay = global::AsyncAI.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: __response, + attempt: __attempt); + await global::AsyncAI.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::AsyncAI.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "StreamSpeech", + methodName: "StreamSpeechAsync", + pathTemplate: "\"/text_to_speech/streaming\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest ?? throw new global::System.InvalidOperationException("The HTTP request was not created before invoking a request hook."), + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + retryDelay: __retryDelay, + retryReason: "status:" + ((int)__response.StatusCode).ToString(global::System.Globalization.CultureInfo.InvariantCulture), + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::AsyncAI.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + retryDelay: __retryDelay, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; + } + + break; + } + + if (__response == null) + { + throw new global::System.InvalidOperationException("No response received."); + } + + try + { + + ProcessResponse( + client: HttpClient, + response: __response); + ProcessStreamSpeechResponse( + httpClient: HttpClient, + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::AsyncAI.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::AsyncAI.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "StreamSpeech", + methodName: "StreamSpeechAsync", + pathTemplate: "\"/text_to_speech/streaming\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest ?? throw new global::System.InvalidOperationException("The HTTP request was not created before invoking a request hook."), + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + else + { + await global::AsyncAI.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::AsyncAI.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "StreamSpeech", + methodName: "StreamSpeechAsync", + pathTemplate: "\"/text_to_speech/streaming\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest ?? throw new global::System.InvalidOperationException("The HTTP request was not created before invoking a request hook."), + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + // Error response. + if (!__response.IsSuccessStatusCode) + { + string? __content_default = null; + global::System.Exception? __exception_default = null; + global::AsyncAI.ErrorResponse? __value_default = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_default = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_default = global::AsyncAI.ErrorResponse.FromJson(__content_default, JsonSerializerContext); + } + else + { + __content_default = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_default = global::AsyncAI.ErrorResponse.FromJson(__content_default, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_default = __ex; + } + + + throw global::AsyncAI.ApiException.Create( + statusCode: __response.StatusCode, + message: __content_default ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_default, + responseBody: __content_default, + responseObject: __value_default, + responseHeaders: global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value)); + } + + try + { + __response.EnsureSuccessStatusCode(); + + var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + return new global::AsyncAI.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::AsyncAI.AutoSDKHttpResponse.CreateHeaders(__response), + requestUri: __response.RequestMessage?.RequestUri, + body: new global::AsyncAI.ResponseStream(__response, __content)); + } + catch (global::System.OperationCanceledException) + { + throw; + } catch (global::System.Exception __ex) { string? __content = null; diff --git a/src/libs/AsyncAI/Generated/AsyncAI.TextToSpeechClient.SynthesizeSpeech.g.cs b/src/libs/AsyncAI/Generated/AsyncAI.TextToSpeechClient.SynthesizeSpeech.g.cs index b11a8ae..89cd972 100644 --- a/src/libs/AsyncAI/Generated/AsyncAI.TextToSpeechClient.SynthesizeSpeech.g.cs +++ b/src/libs/AsyncAI/Generated/AsyncAI.TextToSpeechClient.SynthesizeSpeech.g.cs @@ -406,6 +406,392 @@ partial void ProcessSynthesizeSpeechResponseContent( return new global::AsyncAI.ResponseStream(__response, __content); } + catch (global::System.OperationCanceledException) + { + throw; + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw global::AsyncAI.ApiException.Create( + statusCode: __response.StatusCode, + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + responseBody: __content, + responseHeaders: global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value)); + } + + } + catch + { + __response.Dispose(); + throw; + } + } + finally + { + __httpRequest?.Dispose(); + } + } + /// + /// Text to speech
+ /// Generates speech from text and returns complete audio. + ///
+ /// + /// Default Value: v1 + /// + /// + /// The response metadata and an unbuffered body stream. The caller must dispose Body to release the HTTP response. + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. + /// The token to cancel the operation with + /// + public async global::System.Threading.Tasks.Task> SynthesizeSpeechAsStreamAsResponseAsync( + + global::AsyncAI.TextToSpeechRequest request, + string? version = default, + global::AsyncAI.AutoSDKRequestOptions? requestOptions = default, + global::System.Threading.CancellationToken cancellationToken = default) + { + request = request ?? throw new global::System.ArgumentNullException(nameof(request)); + + PrepareArguments( + client: HttpClient); + PrepareSynthesizeSpeechArguments( + httpClient: HttpClient, + version: ref version, + request: request); + + + var __authorizations = global::AsyncAI.EndPointSecurityResolver.ResolveAuthorizations( + availableAuthorizations: Authorizations, + securityRequirements: s_SynthesizeSpeechSecurityRequirements, + operationName: "SynthesizeSpeechAsync"); + + using var __timeoutCancellationTokenSource = global::AsyncAI.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::AsyncAI.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::AsyncAI.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + + var __pathBuilder = new global::AsyncAI.PathBuilder( + path: "/text_to_speech", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::AsyncAI.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); +#if NET6_0_OR_GREATER + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; +#endif + + foreach (var __authorization in __authorizations) + { + if (__authorization.Type == "Http" || + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") + { + __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( + scheme: __authorization.Name, + parameter: __authorization.Value); + } + else if (__authorization.Type == "ApiKey" && + __authorization.Location == "Header") + { + __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); + } + } + + if (version != default) + { + __httpRequest.Headers.TryAddWithoutValidation("version", version.ToString()); + } + + var __httpRequestContentBody = request.ToJson(JsonSerializerContext); + var __httpRequestContent = new global::System.Net.Http.StringContent( + content: __httpRequestContentBody, + encoding: global::System.Text.Encoding.UTF8, + mediaType: "application/json"); + __httpRequest.Content = __httpRequestContent; + global::AsyncAI.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareSynthesizeSpeechRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + version: version, + request: request); + + return __httpRequest; + } + + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try + { + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::AsyncAI.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::AsyncAI.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "SynthesizeSpeech", + methodName: "SynthesizeSpeechAsync", + pathTemplate: "\"/text_to_speech\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest ?? throw new global::System.InvalidOperationException("The HTTP request was not created before invoking a request hook."), + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try + { + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseHeadersRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + } + catch (global::System.Net.Http.HttpRequestException __exception) + { + var __retryDelay = global::AsyncAI.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: null, + attempt: __attempt); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::AsyncAI.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::AsyncAI.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "SynthesizeSpeech", + methodName: "SynthesizeSpeechAsync", + pathTemplate: "\"/text_to_speech\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest ?? throw new global::System.InvalidOperationException("The HTTP request was not created before invoking a request hook."), + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + retryDelay: __willRetry ? __retryDelay : (global::System.TimeSpan?)null, + retryReason: "exception", + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::AsyncAI.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + retryDelay: __retryDelay, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; + } + + if (__response != null && + __attempt < __maxAttempts && + global::AsyncAI.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) + { + var __retryDelay = global::AsyncAI.AutoSDKRequestOptionsSupport.GetRetryDelay( + clientOptions: Options, + requestOptions: requestOptions, + response: __response, + attempt: __attempt); + await global::AsyncAI.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::AsyncAI.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "SynthesizeSpeech", + methodName: "SynthesizeSpeechAsync", + pathTemplate: "\"/text_to_speech\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest ?? throw new global::System.InvalidOperationException("The HTTP request was not created before invoking a request hook."), + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + retryDelay: __retryDelay, + retryReason: "status:" + ((int)__response.StatusCode).ToString(global::System.Globalization.CultureInfo.InvariantCulture), + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::AsyncAI.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + retryDelay: __retryDelay, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; + } + + break; + } + + if (__response == null) + { + throw new global::System.InvalidOperationException("No response received."); + } + + try + { + + ProcessResponse( + client: HttpClient, + response: __response); + ProcessSynthesizeSpeechResponse( + httpClient: HttpClient, + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::AsyncAI.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::AsyncAI.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "SynthesizeSpeech", + methodName: "SynthesizeSpeechAsync", + pathTemplate: "\"/text_to_speech\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest ?? throw new global::System.InvalidOperationException("The HTTP request was not created before invoking a request hook."), + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + else + { + await global::AsyncAI.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::AsyncAI.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "SynthesizeSpeech", + methodName: "SynthesizeSpeechAsync", + pathTemplate: "\"/text_to_speech\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest ?? throw new global::System.InvalidOperationException("The HTTP request was not created before invoking a request hook."), + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + retryDelay: null, + retryReason: global::System.String.Empty, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + // Error response. + if (!__response.IsSuccessStatusCode) + { + string? __content_default = null; + global::System.Exception? __exception_default = null; + global::AsyncAI.ErrorResponse? __value_default = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_default = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_default = global::AsyncAI.ErrorResponse.FromJson(__content_default, JsonSerializerContext); + } + else + { + __content_default = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_default = global::AsyncAI.ErrorResponse.FromJson(__content_default, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_default = __ex; + } + + + throw global::AsyncAI.ApiException.Create( + statusCode: __response.StatusCode, + message: __content_default ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_default, + responseBody: __content_default, + responseObject: __value_default, + responseHeaders: global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value)); + } + + try + { + __response.EnsureSuccessStatusCode(); + + var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + return new global::AsyncAI.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::AsyncAI.AutoSDKHttpResponse.CreateHeaders(__response), + requestUri: __response.RequestMessage?.RequestUri, + body: new global::AsyncAI.ResponseStream(__response, __content)); + } + catch (global::System.OperationCanceledException) + { + throw; + } catch (global::System.Exception __ex) { string? __content = null;