Skip to content

Commit

Permalink
squashed merge for retarget
Browse files Browse the repository at this point in the history
  • Loading branch information
trrwilson committed Jan 16, 2025
1 parent 3c540dc commit f944259
Show file tree
Hide file tree
Showing 155 changed files with 12,402 additions and 2,811 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ internal partial class AzureOpenAIFile : OpenAIFile
internal AzureOpenAIFile(string id, int? bytes, DateTimeOffset createdAt, string filename, string purpose, AzureOpenAIFileStatus azureStatus)
: base(id, createdAt, filename, purpose.ToFilePurpose(), bytes, azureStatus.ToFileStatus())
{
_object = InternalListFilesResponseObject.List.ToString();
_object = "file";
_purpose = purpose;
_azureStatus = azureStatus;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ internal static AzureOpenAIFileCollection DeserializeAzureOpenAIFileCollection(J
return null;
}
IReadOnlyList<AzureOpenAIFile> data = default;
InternalListFilesResponseObject @object = default;
IDictionary<string, BinaryData> serializedAdditionalRawData = default;
string @object = default;
string firstId = default;
string lastId = default;
bool hasMore = false;
IDictionary<string, BinaryData> additionalBinaryDataProperties = default;
Dictionary<string, BinaryData> rawDataDictionary = new Dictionary<string, BinaryData>();
foreach (var property in element.EnumerateObject())
{
Expand All @@ -51,16 +54,31 @@ internal static AzureOpenAIFileCollection DeserializeAzureOpenAIFileCollection(J
}
if (property.NameEquals("object"u8))
{
@object = new InternalListFilesResponseObject(property.Value.GetString());
@object = property.Value.GetString();
continue;
}
if (property.NameEquals("first_id"u8))
{
firstId = property.Value.GetString();
continue;
}
if (property.NameEquals("last_id"u8))
{
lastId = property.Value.GetString();
continue;
}
if (property.NameEquals("has_more"u8))
{
hasMore = property.Value.GetBoolean();
continue;
}
if (true)
{
rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText()));
}
}
serializedAdditionalRawData = rawDataDictionary;
return new AzureOpenAIFileCollection(data, @object, serializedAdditionalRawData);
additionalBinaryDataProperties = rawDataDictionary;
return new AzureOpenAIFileCollection(data, @object, firstId, lastId, hasMore, additionalBinaryDataProperties);
}

void IJsonModel<AzureOpenAIFileCollection>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,25 @@ internal partial class AzureOpenAIFileCollection : OpenAIFileCollection
internal new IDictionary<string, BinaryData> SerializedAdditionalRawData { get; }
= new ChangeTrackingDictionary<string, BinaryData>();

internal InternalListFilesResponseObject Object { get; }
internal string Object { get; }

internal AzureOpenAIFileCollection()
: this(
new ChangeTrackingList<AzureOpenAIFile>(),
InternalListFilesResponseObject.List,
"list",
firstId: null,
lastId: null,
hasMore: false,
new ChangeTrackingDictionary<string, BinaryData>())
{ }

internal AzureOpenAIFileCollection(
IEnumerable<AzureOpenAIFile> files,
InternalListFilesResponseObject @object,
IDictionary<string, BinaryData> serializedAdditionalRawData)
: base(files.Cast<OpenAIFile>().ToList(), @object, serializedAdditionalRawData)
string @object,
string firstId,
string lastId,
bool hasMore,
IDictionary<string, BinaryData> additionalBinaryDataProperties)
: base(files.Cast<OpenAIFile>().ToList(), @object, firstId, lastId, hasMore, additionalBinaryDataProperties)
{ }
}
136 changes: 114 additions & 22 deletions .dotnet/api/OpenAI.netstandard2.0.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,11 @@ internal partial class InternalRunStepDeltaStepDetailsMessageCreationObject { }
internal partial class InternalRunStepDeltaStepDetailsToolCallsObject { }

[CodeGenModel("RunStepDeltaStepDetailsToolCallsFileSearchObject")]
internal partial class InternalRunStepDeltaStepDetailsToolCallsFileSearchObject { }
internal partial class InternalRunStepDeltaStepDetailsToolCallsFileSearchObject
{
[CodeGenMember("FileSearch")]
public InternalRunStepDetailsToolCallsFileSearchObjectFileSearch FileSearch { get; set; }
}

[CodeGenModel("RunStepDeltaStepDetailsToolCallsFunctionObject")]
internal partial class InternalRunStepDeltaStepDetailsToolCallsFunctionObject { }
Expand Down
37 changes: 37 additions & 0 deletions .dotnet/src/Custom/Chat/ChatCompletionOptions.Serialization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,41 @@ private static void DeserializeLogitBiasesValue(JsonProperty property, ref IDict
logitBias = dictionary;
}
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void SerializePredictedContentValue(Utf8JsonWriter writer, ModelReaderWriterOptions options)
{
if (PredictedContent is not null)
{
writer.WriteStartObject();
writer.WritePropertyName("type"u8);
writer.WriteStringValue(InternalPredictionContentType.Content.ToString());
writer.WritePropertyName("content"u8);
writer.WriteObjectValue(PredictedContent, options);
writer.WriteEndObject();
}
else
{
writer.WriteNullValue();
}
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void DeserializePredictedContentValue(JsonProperty property, ref ChatMessageContent predictedContent)
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
predictedContent = null;
}
else
{
foreach (JsonProperty predictionProperty in property.Value.EnumerateObject())
{
if (predictionProperty.NameEquals("content"u8))
{
ChatMessage.DeserializeContentValue(predictionProperty, ref predictedContent);
}
}
}
}
}
11 changes: 11 additions & 0 deletions .dotnet/src/Custom/Chat/ChatCompletionOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace OpenAI.Chat;
[CodeGenSerialization(nameof(Messages), SerializationValueHook = nameof(SerializeMessagesValue))]
[CodeGenSerialization(nameof(StopSequences), SerializationValueHook = nameof(SerializeStopSequencesValue), DeserializationValueHook = nameof(DeserializeStopSequencesValue))]
[CodeGenSerialization(nameof(LogitBiases), SerializationValueHook = nameof(SerializeLogitBiasesValue), DeserializationValueHook = nameof(DeserializeLogitBiasesValue))]
[CodeGenSerialization(nameof(PredictedContent), SerializationValueHook = nameof(SerializePredictedContentValue), DeserializationValueHook = nameof(DeserializePredictedContentValue))]
public partial class ChatCompletionOptions
{
// CUSTOM:
Expand Down Expand Up @@ -177,6 +178,13 @@ public ChatCompletionOptions()
[CodeGenMember("Store")]
public bool? StoredOutputEnabled { get; set; }

/// <summary>
/// (o1 and newer reasoning models only) Constrains effort on reasoning for reasoning models.
/// Currently supported values are <see cref="ChatReasoningEffort.Low"/>, <see cref="ChatReasoningEffort.Medium"/>, and <see cref="ChatReasoningEffort.High"/>.
/// Reducing reasoning effort can result in faster responses and fewer tokens used on reasoning in a response.
/// </summary>
public ChatReasoningEffort? ReasoningEffort { get; set; }

// CUSTOM: Made internal for automatic enablement via audio options.
[CodeGenMember("Modalities")]
private IList<InternalCreateChatCompletionRequestModality> _internalModalities = new ChangeTrackingList<InternalCreateChatCompletionRequestModality>();
Expand All @@ -196,4 +204,7 @@ public ChatAudioOptions AudioOptions
: [InternalCreateChatCompletionRequestModality.Text, InternalCreateChatCompletionRequestModality.Audio];
}
}

[CodeGenMember("Prediction")]
public ChatMessageContent PredictedContent { get; set; }
}
11 changes: 11 additions & 0 deletions .dotnet/src/Custom/Chat/ChatMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,17 @@ internal ChatMessage(ChatMessageRole role, string content = null) : this(role)
public static SystemChatMessage CreateSystemMessage(params ChatMessageContentPart[] contentParts) => new(contentParts);
#endregion

#region DeveloperChatMessage
/// <inheritdoc cref="DeveloperChatMessage(string)"/>
public static DeveloperChatMessage CreateDeveloperMessage(string content) => new(content);

/// <inheritdoc cref="DeveloperChatMessage(IEnumerable{ChatMessageContentPart})"/>
public static DeveloperChatMessage CreateDeveloperMessage(IEnumerable<ChatMessageContentPart> contentParts) => new(contentParts);

/// <inheritdoc cref="DeveloperChatMessage(ChatMessageContentPart[])"/>
public static DeveloperChatMessage CreateDeveloperMessage(params ChatMessageContentPart[] contentParts) => new(contentParts);
#endregion

#region UserChatMessage
/// <inheritdoc cref="UserChatMessage(string)"/>
public static UserChatMessage CreateUserMessage(string content) => new(content);
Expand Down
15 changes: 15 additions & 0 deletions .dotnet/src/Custom/Chat/ChatMessageRole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ namespace OpenAI.Chat;
/// <note>Description</note>
/// </listheader>
/// <item>
/// <type><see cref="Developer"/> -</type>
/// <role><c>developer</c> -</role>
/// <note>Instructions to the model that guide the behavior of future <c>assistant</c> messages. Replaces <c>system</c> in o1 and newer models.</note>
/// </item>
/// <item>
/// <type><see cref="System"/> -</type>
/// <role><c>system</c> -</role>
/// <note>Instructions to the model that guide the behavior of future <c>assistant</c> messages.</note>
Expand Down Expand Up @@ -59,6 +64,16 @@ public enum ChatMessageRole
[CodeGenMember("System")]
System,

/// <summary>
/// The <c>developer</c> role, which provides instructions to the model that guide the behavior of future
/// <c>assistant</c> messages
/// </summary>
/// <remarks>
/// <c>developer</c> replaces <c>system</c> when using o1 and newer models.
/// </remarks>
[CodeGenMember("Developer")]
Developer,

/// <summary>
/// The <c>user</c> role that provides input from the caller as a prompt for model responses.
/// </summary>
Expand Down
6 changes: 6 additions & 0 deletions .dotnet/src/Custom/Chat/ChatOutputTokenUsageDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,10 @@ public partial class ChatOutputTokenUsageDetails
/// <summary> The number of audio tokens in the output. </summary>
[CodeGenMember("AudioTokens")]
public int AudioTokenCount { get; }

[CodeGenMember("AcceptedPredictionTokens")]
public int PredictionAcceptedTokenCount { get; }

[CodeGenMember("RejectedPredictionTokens")]
public int PredictionRejectedTokenCount { get; }
}
9 changes: 9 additions & 0 deletions .dotnet/src/Custom/Chat/ChatReasoningEffort.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;

namespace OpenAI.Chat;

[CodeGenModel("CreateChatCompletionRequestReasoningEffort")]
public readonly partial struct ChatReasoningEffort
{}
45 changes: 45 additions & 0 deletions .dotnet/src/Custom/Chat/DeveloperChatMessage.Serialization.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using System.ClientModel.Primitives;
using System.Text.Json;

namespace OpenAI.Chat;

[CodeGenSuppress("global::System.ClientModel.Primitives.IJsonModel<OpenAI.Chat.DeveloperChatMessage>.Write", typeof(Utf8JsonWriter), typeof(ModelReaderWriterOptions))]
public partial class DeveloperChatMessage : IJsonModel<DeveloperChatMessage>
{
void IJsonModel<DeveloperChatMessage>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options)
=> CustomSerializationHelpers.SerializeInstance(this, SerializeDeveloperChatMessage, writer, options);

internal static void SerializeDeveloperChatMessage(DeveloperChatMessage instance, Utf8JsonWriter writer, ModelReaderWriterOptions options)
=> instance.WriteCore(writer, options);

internal override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options)
{
writer.WriteStartObject();
writer.WritePropertyName("role"u8);
writer.WriteStringValue(Role.ToSerialString());

// Content is required, can be a single string or a collection of ChatMessageContentPart.
if (Optional.IsDefined(Content) && Content.IsInnerCollectionDefined())
{
writer.WritePropertyName("content"u8);
if (Content.Count == 1 && Content[0].Text != null)
{
writer.WriteStringValue(Content[0].Text);
}
else
{
writer.WriteStartArray();
foreach (ChatMessageContentPart part in Content)
{
writer.WriteObjectValue(part, options);
}
writer.WriteEndArray();
}
}

writer.WriteOptionalProperty("name"u8, ParticipantName, options);
writer.WriteSerializedAdditionalRawData(_additionalBinaryDataProperties, options);
writer.WriteEndObject();
}
}
59 changes: 59 additions & 0 deletions .dotnet/src/Custom/Chat/DeveloperChatMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System.Collections.Generic;

namespace OpenAI.Chat;

/// <summary>
/// Represents a chat message of the <c>developer</c> role as supplied to a chat completion request. A developer message is
/// generally supplied as the first message to a chat completion request and guides the model's behavior across future
/// <c>assistant</c> role response messages. These messages may help control behavior, style, tone, and
/// restrictions for a model-based assistant. Developer messages replace system messages for o1 models and newer.
/// </summary>
[CodeGenModel("ChatCompletionRequestDeveloperMessage")]
[CodeGenSuppress("DeveloperChatMessage", typeof(ChatMessageContent))]
public partial class DeveloperChatMessage : ChatMessage
{
/// <summary>
/// Creates a new instance of <see cref="DeveloperChatMessage"/> using a collection of content items.
/// For <c>system</c> messages, these can only be of type <c>text</c>.
/// </summary>
/// <param name="contentParts">
/// The collection of content items associated with the message.
/// </param>
public DeveloperChatMessage(IEnumerable<ChatMessageContentPart> contentParts)
: base(ChatMessageRole.System, contentParts)
{ }

/// <summary>
/// Creates a new instance of <see cref="DeveloperChatMessage"/> using a collection of content items.
/// For <c>system</c> messages, these can only be of type <c>text</c>.
/// </summary>
/// <param name="contentParts">
/// The collection of content items associated with the message.
/// </param>
public DeveloperChatMessage(params ChatMessageContentPart[] contentParts)
: base(ChatMessageRole.Developer, contentParts)
{
Argument.AssertNotNullOrEmpty(contentParts, nameof(contentParts));
}

/// <summary>
/// Creates a new instance of <see cref="DeveloperChatMessage"/> with a single item of text content.
/// </summary>
/// <param name="content"> The text content of the message. </param>
public DeveloperChatMessage(string content)
: base(ChatMessageRole.Developer, content)
{
Argument.AssertNotNull(content, nameof(content));
}

// CUSTOM: Hide the default constructor.
internal DeveloperChatMessage()
{
}

/// <summary>
/// An optional <c>name</c> for the participant.
/// </summary>
[CodeGenMember("Name")]
public string ParticipantName { get; set; }
}
5 changes: 5 additions & 0 deletions .dotnet/src/Custom/Chat/Internal/GeneratorStubs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,8 @@ internal readonly partial struct InternalChatCompletionRequestMessageContentPart
[CodeGenModel("ChatCompletionMessageAudioChunk")]
internal partial class InternalChatCompletionMessageAudioChunk { }

[CodeGenModel("PredictionContent")]
internal partial class InternalPredictionContent { }

[CodeGenModel("PredictionContentType")]
internal readonly partial struct InternalPredictionContentType { }
9 changes: 7 additions & 2 deletions .dotnet/src/Custom/Chat/OpenAIChatModelFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,14 @@ public static ChatInputTokenUsageDetails ChatInputTokenUsageDetails(int audioTok

/// <summary> Initializes a new instance of <see cref="OpenAI.Chat.ChatOutputTokenUsageDetails"/>. </summary>
/// <returns> A new <see cref="OpenAI.Chat.ChatOutputTokenusageDetails"/> instance for mocking. </returns>
public static ChatOutputTokenUsageDetails ChatOutputTokenUsageDetails(int reasoningTokenCount = default, int audioTokenCount = default)
public static ChatOutputTokenUsageDetails ChatOutputTokenUsageDetails(int reasoningTokenCount = default, int audioTokenCount = default, int predictionAcceptedTokenCount = default, int predictionRejectedTokenCount = 0)
{
return new ChatOutputTokenUsageDetails(reasoningTokenCount, audioTokenCount, additionalBinaryDataProperties: null);
return new ChatOutputTokenUsageDetails(
audioTokenCount: audioTokenCount,
reasoningTokenCount: reasoningTokenCount,
predictionAcceptedTokenCount: predictionAcceptedTokenCount,
predictionRejectedTokenCount: predictionRejectedTokenCount,
additionalBinaryDataProperties: null);
}

public static ChatResponseAudio ChatResponseAudio(BinaryData data, string id = null, string transcript = null, DateTimeOffset expiresAt = default)
Expand Down
3 changes: 0 additions & 3 deletions .dotnet/src/Custom/Files/Internal/GeneratorStubs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ namespace OpenAI.Files;
[CodeGenModel("DeleteFileResponseObject")]
internal readonly partial struct InternalDeleteFileResponseObject { }

[CodeGenModel("ListFilesResponseObject")]
internal readonly partial struct InternalListFilesResponseObject { }

[CodeGenModel("OpenAIFileObject")]
internal readonly partial struct InternalOpenAIFileObject { }

Expand Down
Loading

0 comments on commit f944259

Please sign in to comment.