Skip to content

Commit

Permalink
all the powershell fixup is gone
Browse files Browse the repository at this point in the history
  • Loading branch information
trrwilson committed Jan 15, 2025
1 parent a71adc6 commit 3352fd2
Show file tree
Hide file tree
Showing 398 changed files with 1,159 additions and 1,947 deletions.
195 changes: 195 additions & 0 deletions .dotnet/src/Generated/Internal/MultiPartFormDataBinaryContent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
// <auto-generated/>

#nullable disable

using System;
using System.ClientModel;
using System.Globalization;
using System.IO;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading;
using System.Threading.Tasks;

namespace OpenAI
{
internal partial class MultiPartFormDataBinaryContent : BinaryContent
{
private readonly MultipartFormDataContent _multipartContent;
private static readonly Random _random = new Random();
private static readonly char[] _boundaryValues = "0123456789=ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz".ToCharArray();

public MultiPartFormDataBinaryContent()
{
_multipartContent = new MultipartFormDataContent(CreateBoundary());
}

public string ContentType
{
get
{
return _multipartContent.Headers.ContentType.ToString();
}
}

internal HttpContent HttpContent => _multipartContent;

private static string CreateBoundary()
{
Span<char> chars = new char[70];
byte[] random = new byte[70];
_random.NextBytes(random);
int mask = 255 >> 2;
int i = 0;
for (; i < 70; i++)
{
chars[i] = _boundaryValues[random[i] & mask];
}
return chars.ToString();
}

public void Add(string content, string name, string filename = default, string contentType = default)
{
Argument.AssertNotNull(content, nameof(content));
Argument.AssertNotNullOrEmpty(name, nameof(name));

Add(new StringContent(content), name, filename, contentType);
}

public void Add(int content, string name, string filename = default, string contentType = default)
{
Argument.AssertNotNull(content, nameof(content));
Argument.AssertNotNullOrEmpty(name, nameof(name));

string value = content.ToString("G", CultureInfo.InvariantCulture);
Add(new StringContent(value), name, filename, contentType);
}

public void Add(long content, string name, string filename = default, string contentType = default)
{
Argument.AssertNotNull(content, nameof(content));
Argument.AssertNotNullOrEmpty(name, nameof(name));

string value = content.ToString("G", CultureInfo.InvariantCulture);
Add(new StringContent(value), name, filename, contentType);
}

public void Add(float content, string name, string filename = default, string contentType = default)
{
Argument.AssertNotNull(content, nameof(content));
Argument.AssertNotNullOrEmpty(name, nameof(name));

string value = content.ToString("G", CultureInfo.InvariantCulture);
Add(new StringContent(value), name, filename, contentType);
}

public void Add(double content, string name, string filename = default, string contentType = default)
{
Argument.AssertNotNull(content, nameof(content));
Argument.AssertNotNullOrEmpty(name, nameof(name));

string value = content.ToString("G", CultureInfo.InvariantCulture);
Add(new StringContent(value), name, filename, contentType);
}

public void Add(decimal content, string name, string filename = default, string contentType = default)
{
Argument.AssertNotNull(content, nameof(content));
Argument.AssertNotNullOrEmpty(name, nameof(name));

string value = content.ToString("G", CultureInfo.InvariantCulture);
Add(new StringContent(value), name, filename, contentType);
}

public void Add(bool content, string name, string filename = default, string contentType = default)
{
Argument.AssertNotNull(content, nameof(content));
Argument.AssertNotNullOrEmpty(name, nameof(name));

string value = content ? "true" : "false";
Add(new StringContent(value), name, filename, contentType);
}

public void Add(Stream content, string name, string filename = default, string contentType = default)
{
Argument.AssertNotNull(content, nameof(content));
Argument.AssertNotNullOrEmpty(name, nameof(name));

Add(new StreamContent(content), name, filename, contentType);
}

public void Add(byte[] content, string name, string filename = default, string contentType = default)
{
Argument.AssertNotNull(content, nameof(content));
Argument.AssertNotNullOrEmpty(name, nameof(name));

Add(new ByteArrayContent(content), name, filename, contentType);
}

public void Add(BinaryData content, string name, string filename = default, string contentType = default)
{
Argument.AssertNotNull(content, nameof(content));
Argument.AssertNotNullOrEmpty(name, nameof(name));

Add(new ByteArrayContent(content.ToArray()), name, filename, contentType);
}

private void Add(HttpContent content, string name, string filename, string contentType)
{
if (contentType != null)
{
Argument.AssertNotNullOrEmpty(contentType, nameof(contentType));
AddContentTypeHeader(content, contentType);
}
if (filename != null)
{
Argument.AssertNotNullOrEmpty(filename, nameof(filename));
_multipartContent.Add(content, name, filename);
}
else
{
_multipartContent.Add(content, name);
}
}

public static void AddContentTypeHeader(HttpContent content, string contentType)
{
MediaTypeHeaderValue header = new MediaTypeHeaderValue(contentType);
content.Headers.ContentType = header;
}

public override bool TryComputeLength(out long length)
{
if (_multipartContent.Headers.ContentLength is long contentLength)
{
length = contentLength;
return true;
}
length = 0;
return false;
}

public override void WriteTo(Stream stream, CancellationToken cancellationToken = default)
{
#if NET6_0_OR_GREATER
_multipartContent.CopyTo(stream, default, cancellationToken);
#else
_multipartContent.CopyToAsync(stream).GetAwaiter().GetResult();
#endif
}

public override async Task WriteToAsync(Stream stream, CancellationToken cancellationToken = default)
{
#if NET6_0_OR_GREATER
await _multipartContent.CopyToAsync(stream).ConfigureAwait(false);
#else
await _multipartContent.CopyToAsync(stream).ConfigureAwait(false);
#endif
}

public override void Dispose()
{
_multipartContent.Dispose();
}
}
}
11 changes: 4 additions & 7 deletions .dotnet/src/Generated/Models/Assistant.Serialization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit
writer.WriteNull("instructions"u8);
}
}
if (true && _additionalBinaryDataProperties?.ContainsKey("tools") != true)
if (_additionalBinaryDataProperties?.ContainsKey("tools") != true)
{
writer.WritePropertyName("tools"u8);
writer.WriteStartArray();
Expand All @@ -104,7 +104,7 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit
writer.WriteNull("toolResources"u8);
}
}
if (true && _additionalBinaryDataProperties?.ContainsKey("metadata") != true)
if (_additionalBinaryDataProperties?.ContainsKey("metadata") != true)
{
if (Metadata != null && Optional.IsCollectionDefined(Metadata))
{
Expand Down Expand Up @@ -168,7 +168,7 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit
writer.WriteNull("topP"u8);
}
}
if (true && _additionalBinaryDataProperties != null)
if (_additionalBinaryDataProperties != null)
{
foreach (var item in _additionalBinaryDataProperties)
{
Expand Down Expand Up @@ -346,10 +346,7 @@ internal static Assistant DeserializeAssistant(JsonElement element, ModelReaderW
nucleusSamplingFactor = prop.Value.GetSingle();
continue;
}
if (true)
{
additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText()));
}
additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText()));
}
return new Assistant(
id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,7 @@ internal static AssistantChatMessage DeserializeAssistantChatMessage(JsonElement
functionCall = ChatFunctionCall.DeserializeChatFunctionCall(prop.Value, options);
continue;
}
if (true)
{
additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText()));
}
additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText()));
}
return new AssistantChatMessage(
role,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit
writer.WriteNull("topP"u8);
}
}
if (true && _additionalBinaryDataProperties != null)
if (_additionalBinaryDataProperties != null)
{
foreach (var item in _additionalBinaryDataProperties)
{
Expand Down Expand Up @@ -312,10 +312,7 @@ internal static AssistantCreationOptions DeserializeAssistantCreationOptions(Jso
nucleusSamplingFactor = prop.Value.GetSingle();
continue;
}
if (true)
{
additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText()));
}
additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText()));
}
return new AssistantCreationOptions(
name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit
writer.WritePropertyName("object"u8);
writer.WriteStringValue(this.Object.ToString());
}
if (true && _additionalBinaryDataProperties != null)
if (_additionalBinaryDataProperties != null)
{
foreach (var item in _additionalBinaryDataProperties)
{
Expand Down Expand Up @@ -107,10 +107,7 @@ internal static AssistantDeletionResult DeserializeAssistantDeletionResult(JsonE
@object = new InternalDeleteAssistantResponseObject(prop.Value.GetString());
continue;
}
if (true)
{
additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText()));
}
additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText()));
}
return new AssistantDeletionResult(deleted, assistantId, @object, additionalBinaryDataProperties);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit
writer.WriteNull("topP"u8);
}
}
if (true && _additionalBinaryDataProperties != null)
if (_additionalBinaryDataProperties != null)
{
foreach (var item in _additionalBinaryDataProperties)
{
Expand Down Expand Up @@ -312,10 +312,7 @@ internal static AssistantModificationOptions DeserializeAssistantModificationOpt
nucleusSamplingFactor = prop.Value.GetSingle();
continue;
}
if (true)
{
additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText()));
}
additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText()));
}
return new AssistantModificationOptions(
name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit
writer.WritePropertyName("type"u8);
writer.WriteStringValue(Type);
}
if (true && _additionalBinaryDataProperties != null)
if (_additionalBinaryDataProperties != null)
{
foreach (var item in _additionalBinaryDataProperties)
{
Expand Down
9 changes: 3 additions & 6 deletions .dotnet/src/Generated/Models/AssistantThread.Serialization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit
writer.WritePropertyName("created_at"u8);
writer.WriteNumberValue(CreatedAt, "U");
}
if (true && _additionalBinaryDataProperties?.ContainsKey("metadata") != true)
if (_additionalBinaryDataProperties?.ContainsKey("metadata") != true)
{
if (Metadata != null && Optional.IsCollectionDefined(Metadata))
{
Expand Down Expand Up @@ -81,7 +81,7 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit
writer.WriteNull("toolResources"u8);
}
}
if (true && _additionalBinaryDataProperties != null)
if (_additionalBinaryDataProperties != null)
{
foreach (var item in _additionalBinaryDataProperties)
{
Expand Down Expand Up @@ -176,10 +176,7 @@ internal static AssistantThread DeserializeAssistantThread(JsonElement element,
toolResources = ToolResources.DeserializeToolResources(prop.Value, options);
continue;
}
if (true)
{
additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText()));
}
additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText()));
}
return new AssistantThread(
id,
Expand Down
11 changes: 4 additions & 7 deletions .dotnet/src/Generated/Models/AudioTranscription.Serialization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit
writer.WritePropertyName("text"u8);
writer.WriteStringValue(Text);
}
if (true && Optional.IsCollectionDefined(Words) && _additionalBinaryDataProperties?.ContainsKey("words") != true)
if (Optional.IsCollectionDefined(Words) && _additionalBinaryDataProperties?.ContainsKey("words") != true)
{
writer.WritePropertyName("words"u8);
writer.WriteStartArray();
Expand All @@ -51,7 +51,7 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit
}
writer.WriteEndArray();
}
if (true && Optional.IsCollectionDefined(Segments) && _additionalBinaryDataProperties?.ContainsKey("segments") != true)
if (Optional.IsCollectionDefined(Segments) && _additionalBinaryDataProperties?.ContainsKey("segments") != true)
{
writer.WritePropertyName("segments"u8);
writer.WriteStartArray();
Expand All @@ -71,7 +71,7 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit
writer.WritePropertyName("duration"u8);
writer.WriteNumberValue(Convert.ToDouble(Duration.Value.ToString("s\\.FFF")));
}
if (true && _additionalBinaryDataProperties != null)
if (_additionalBinaryDataProperties != null)
{
foreach (var item in _additionalBinaryDataProperties)
{
Expand Down Expand Up @@ -168,10 +168,7 @@ internal static AudioTranscription DeserializeAudioTranscription(JsonElement ele
duration = TimeSpan.FromSeconds(prop.Value.GetDouble());
continue;
}
if (true)
{
additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText()));
}
additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText()));
}
return new AudioTranscription(
language,
Expand Down
Loading

0 comments on commit 3352fd2

Please sign in to comment.