Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions api/OpenAI.net8.0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1511,6 +1511,8 @@ public class ChatCompletion : IJsonModel<ChatCompletion>, IPersistableModel<Chat
public string Refusal { get; }
public IReadOnlyList<ChatTokenLogProbabilityDetails> RefusalTokenLogProbabilities { get; }
public ChatMessageRole Role { get; }
[Experimental("OPENAI001")]
public ChatServiceTier? ServiceTier { get; }
public string SystemFingerprint { get; }
public IReadOnlyList<ChatToolCall> ToolCalls { get; }
public ChatTokenUsage Usage { get; }
Expand Down Expand Up @@ -1626,6 +1628,8 @@ public class ChatCompletionOptions : IJsonModel<ChatCompletionOptions>, IPersist
public ChatResponseModalities ResponseModalities { get; set; }
[Experimental("OPENAI001")]
public long? Seed { get; set; }
[Experimental("OPENAI001")]
public ChatServiceTier? ServiceTier { get; set; }
public IList<string> StopSequences { get; }
public bool? StoredOutputEnabled { get; set; }
public float? Temperature { get; set; }
Expand Down Expand Up @@ -1974,6 +1978,24 @@ public enum ChatResponseModalities {
Text = 1,
Audio = 2
}
[Experimental("OPENAI001")]
public readonly partial struct ChatServiceTier : IEquatable<ChatServiceTier> {
public ChatServiceTier(string value);
public static ChatServiceTier Auto { get; }
public static ChatServiceTier Default { get; }
public static ChatServiceTier Flex { get; }
public static ChatServiceTier Scale { get; }
public readonly bool Equals(ChatServiceTier other);
[EditorBrowsable(EditorBrowsableState.Never)]
public override readonly bool Equals(object obj);
[EditorBrowsable(EditorBrowsableState.Never)]
public override readonly int GetHashCode();
public static bool operator ==(ChatServiceTier left, ChatServiceTier right);
public static implicit operator ChatServiceTier(string value);
public static implicit operator ChatServiceTier?(string value);
public static bool operator !=(ChatServiceTier left, ChatServiceTier right);
public override readonly string ToString();
}
public class ChatTokenLogProbabilityDetails : IJsonModel<ChatTokenLogProbabilityDetails>, IPersistableModel<ChatTokenLogProbabilityDetails> {
public float LogProbability { get; }
public string Token { get; }
Expand Down Expand Up @@ -2143,6 +2165,8 @@ public class StreamingChatCompletionUpdate : IJsonModel<StreamingChatCompletionU
public IReadOnlyList<ChatTokenLogProbabilityDetails> RefusalTokenLogProbabilities { get; }
public string RefusalUpdate { get; }
public ChatMessageRole? Role { get; }
[Experimental("OPENAI001")]
public ChatServiceTier? ServiceTier { get; }
public string SystemFingerprint { get; }
public IReadOnlyList<StreamingChatToolCallUpdate> ToolCallUpdates { get; }
public ChatTokenUsage Usage { get; }
Expand Down Expand Up @@ -4772,6 +4796,7 @@ public class OpenAIResponse : IJsonModel<OpenAIResponse>, IPersistableModel<Open
public bool ParallelToolCallsEnabled { get; }
public string PreviousResponseId { get; }
public ResponseReasoningOptions ReasoningOptions { get; }
public ResponseServiceTier? ServiceTier { get; }
public ResponseStatus? Status { get; }
public float? Temperature { get; }
public ResponseTextOptions TextOptions { get; }
Expand Down Expand Up @@ -4926,6 +4951,7 @@ public class ResponseCreationOptions : IJsonModel<ResponseCreationOptions>, IPer
public bool? ParallelToolCallsEnabled { get; set; }
public string PreviousResponseId { get; set; }
public ResponseReasoningOptions ReasoningOptions { get; set; }
public ResponseServiceTier? ServiceTier { get; set; }
public bool? StoredOutputEnabled { get; set; }
public float? Temperature { get; set; }
public ResponseTextOptions TextOptions { get; set; }
Expand Down Expand Up @@ -5171,6 +5197,24 @@ public class ResponseReasoningOptions : IJsonModel<ResponseReasoningOptions>, IP
public override readonly string ToString();
}
[Experimental("OPENAI001")]
public readonly partial struct ResponseServiceTier : IEquatable<ResponseServiceTier> {
public ResponseServiceTier(string value);
public static ResponseServiceTier Auto { get; }
public static ResponseServiceTier Default { get; }
public static ResponseServiceTier Flex { get; }
public static ResponseServiceTier Scale { get; }
public readonly bool Equals(ResponseServiceTier other);
[EditorBrowsable(EditorBrowsableState.Never)]
public override readonly bool Equals(object obj);
[EditorBrowsable(EditorBrowsableState.Never)]
public override readonly int GetHashCode();
public static bool operator ==(ResponseServiceTier left, ResponseServiceTier right);
public static implicit operator ResponseServiceTier(string value);
public static implicit operator ResponseServiceTier?(string value);
public static bool operator !=(ResponseServiceTier left, ResponseServiceTier right);
public override readonly string ToString();
}
[Experimental("OPENAI001")]
public enum ResponseStatus {
InProgress = 0,
Completed = 1,
Expand Down
39 changes: 39 additions & 0 deletions api/OpenAI.netstandard2.0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1345,6 +1345,7 @@ public class ChatCompletion : IJsonModel<ChatCompletion>, IPersistableModel<Chat
public string Refusal { get; }
public IReadOnlyList<ChatTokenLogProbabilityDetails> RefusalTokenLogProbabilities { get; }
public ChatMessageRole Role { get; }
public ChatServiceTier? ServiceTier { get; }
public string SystemFingerprint { get; }
public IReadOnlyList<ChatToolCall> ToolCalls { get; }
public ChatTokenUsage Usage { get; }
Expand Down Expand Up @@ -1444,6 +1445,7 @@ public class ChatCompletionOptions : IJsonModel<ChatCompletionOptions>, IPersist
public ChatResponseFormat ResponseFormat { get; set; }
public ChatResponseModalities ResponseModalities { get; set; }
public long? Seed { get; set; }
public ChatServiceTier? ServiceTier { get; set; }
public IList<string> StopSequences { get; }
public bool? StoredOutputEnabled { get; set; }
public float? Temperature { get; set; }
Expand Down Expand Up @@ -1731,6 +1733,23 @@ public enum ChatResponseModalities {
Text = 1,
Audio = 2
}
public readonly partial struct ChatServiceTier : IEquatable<ChatServiceTier> {
public ChatServiceTier(string value);
public static ChatServiceTier Auto { get; }
public static ChatServiceTier Default { get; }
public static ChatServiceTier Flex { get; }
public static ChatServiceTier Scale { get; }
public readonly bool Equals(ChatServiceTier other);
[EditorBrowsable(EditorBrowsableState.Never)]
public override readonly bool Equals(object obj);
[EditorBrowsable(EditorBrowsableState.Never)]
public override readonly int GetHashCode();
public static bool operator ==(ChatServiceTier left, ChatServiceTier right);
public static implicit operator ChatServiceTier(string value);
public static implicit operator ChatServiceTier?(string value);
public static bool operator !=(ChatServiceTier left, ChatServiceTier right);
public override readonly string ToString();
}
public class ChatTokenLogProbabilityDetails : IJsonModel<ChatTokenLogProbabilityDetails>, IPersistableModel<ChatTokenLogProbabilityDetails> {
public float LogProbability { get; }
public string Token { get; }
Expand Down Expand Up @@ -1863,6 +1882,7 @@ public class StreamingChatCompletionUpdate : IJsonModel<StreamingChatCompletionU
public IReadOnlyList<ChatTokenLogProbabilityDetails> RefusalTokenLogProbabilities { get; }
public string RefusalUpdate { get; }
public ChatMessageRole? Role { get; }
public ChatServiceTier? ServiceTier { get; }
public string SystemFingerprint { get; }
public IReadOnlyList<StreamingChatToolCallUpdate> ToolCallUpdates { get; }
public ChatTokenUsage Usage { get; }
Expand Down Expand Up @@ -4207,6 +4227,7 @@ public class OpenAIResponse : IJsonModel<OpenAIResponse>, IPersistableModel<Open
public bool ParallelToolCallsEnabled { get; }
public string PreviousResponseId { get; }
public ResponseReasoningOptions ReasoningOptions { get; }
public ResponseServiceTier? ServiceTier { get; }
public ResponseStatus? Status { get; }
public float? Temperature { get; }
public ResponseTextOptions TextOptions { get; }
Expand Down Expand Up @@ -4351,6 +4372,7 @@ public class ResponseCreationOptions : IJsonModel<ResponseCreationOptions>, IPer
public bool? ParallelToolCallsEnabled { get; set; }
public string PreviousResponseId { get; set; }
public ResponseReasoningOptions ReasoningOptions { get; set; }
public ResponseServiceTier? ServiceTier { get; set; }
public bool? StoredOutputEnabled { get; set; }
public float? Temperature { get; set; }
public ResponseTextOptions TextOptions { get; set; }
Expand Down Expand Up @@ -4575,6 +4597,23 @@ public class ResponseReasoningOptions : IJsonModel<ResponseReasoningOptions>, IP
public static bool operator !=(ResponseReasoningSummaryVerbosity left, ResponseReasoningSummaryVerbosity right);
public override readonly string ToString();
}
public readonly partial struct ResponseServiceTier : IEquatable<ResponseServiceTier> {
public ResponseServiceTier(string value);
public static ResponseServiceTier Auto { get; }
public static ResponseServiceTier Default { get; }
public static ResponseServiceTier Flex { get; }
public static ResponseServiceTier Scale { get; }
public readonly bool Equals(ResponseServiceTier other);
[EditorBrowsable(EditorBrowsableState.Never)]
public override readonly bool Equals(object obj);
[EditorBrowsable(EditorBrowsableState.Never)]
public override readonly int GetHashCode();
public static bool operator ==(ResponseServiceTier left, ResponseServiceTier right);
public static implicit operator ResponseServiceTier(string value);
public static implicit operator ResponseServiceTier?(string value);
public static bool operator !=(ResponseServiceTier left, ResponseServiceTier right);
public override readonly string ToString();
}
public enum ResponseStatus {
InProgress = 0,
Completed = 1,
Expand Down
4 changes: 4 additions & 0 deletions specification/client/chat.client.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ using Azure.ClientGenerator.Core;
@@visibility(ChatCompletionStreamResponseDelta.tool_calls, Lifecycle.Read);

@@clientName(Chat.createChatCompletion, "CompleteChat");

@@alternateType(CreateChatCompletionRequest.service_tier, DotNetChatServiceTier);
@@alternateType(CreateChatCompletionResponse.service_tier, DotNetChatServiceTier);
@@alternateType(CreateChatCompletionStreamResponse.service_tier, DotNetChatServiceTier);
Comment on lines +22 to +24
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious - why did we have to do this versus only renaming InternalServiceTier and making it public?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking about it some more, this is so that we can have the differentiated type name for Chat and Responses. 😄

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the spec, ServiceTier is defined as a common type shared across multiple subclients (like Chat and Responses) but in the .NET SDK, we don’t share types between subclients. Instead, for common types we generate custom wrappers per subclient. That’s why we introduce subclient-specific types, see spec example here:

union DotNetChatServiceTier {
  ServiceTier
}

union DotNetResponseServiceTier {
  ServiceTier
}

This way each subclient gets its own strongly-typed version while still mapping back to the same spec definition.

10 changes: 9 additions & 1 deletion specification/client/models/common.models.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,12 @@ alias CollectionBeforeQueryParameter = {
* subsequent call can include before=obj_foo in order to fetch the previous page of the list.
*/
@query beforeId?: string;
};
};

union DotNetChatServiceTier {
ServiceTier
}

union DotNetResponseServiceTier {
ServiceTier
}
8 changes: 8 additions & 0 deletions specification/client/responses.client.tsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import "../base/typespec/responses/main.tsp";
import "@azure-tools/typespec-client-generator-core";

using OpenAI;
using Azure.ClientGenerator.Core;

@@alternateType(CreateResponse.service_tier, DotNetResponseServiceTier);
@@alternateType(Response.service_tier, DotNetResponseServiceTier);
1 change: 1 addition & 0 deletions specification/main.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import "./client/graders.client.tsp";
import "./client/images.client.tsp";
import "./client/messages.client.tsp";
import "./client/moderations.client.tsp";
import "./client/responses.client.tsp";
import "./client/runs.client.tsp";
import "./client/threads.client.tsp";
import "./client/vector-stores.client.tsp";
Expand Down
4 changes: 0 additions & 4 deletions src/Custom/Chat/ChatCompletion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ public partial class ChatCompletion
[CodeGenMember("Object")]
internal string Object { get; } = "chat.completion";

// CUSTOM: Made internal.
[CodeGenMember("ServiceTier")]
internal InternalServiceTier? ServiceTier { get; }

// CUSTOM: Made internal. We only get back a single choice, and instead we flatten the structure for usability.
[CodeGenMember("Choices")]
internal IReadOnlyList<InternalCreateChatCompletionResponseChoice> Choices { get; }
Expand Down
3 changes: 0 additions & 3 deletions src/Custom/Chat/ChatCompletionOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,6 @@ public partial class ChatCompletionOptions
[CodeGenMember("ParallelToolCalls")]
public bool? AllowParallelToolCalls { get; set; }

[CodeGenMember("ServiceTier")]
internal InternalServiceTier? _serviceTier;

// CUSTOM: Renamed.
/// <summary>
/// A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse.
Expand Down
7 changes: 7 additions & 0 deletions src/Custom/Chat/ChatServiceTier.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace OpenAI.Chat;

// CUSTOM: Renamed.
[CodeGenType("DotNetChatServiceTier")]
public readonly partial struct ChatServiceTier
{
}
4 changes: 2 additions & 2 deletions src/Custom/Chat/OpenAIChatModelFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ public static ChatCompletion ChatCompletion(
return new ChatCompletion(
id,
model,
serviceTier: null,
systemFingerprint,
usage,
"chat.completion",
serviceTier: null,
choices,
createdAt,
additionalBinaryDataProperties: null);
Expand Down Expand Up @@ -311,10 +311,10 @@ public static StreamingChatCompletionUpdate StreamingChatCompletionUpdate(

return new StreamingChatCompletionUpdate(
model,
serviceTier: null,
systemFingerprint,
"chat.completion.chunk",
completionId,
serviceTier: null,
choices,
createdAt,
usage,
Expand Down
4 changes: 0 additions & 4 deletions src/Custom/Chat/Streaming/StreamingChatCompletionUpdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ public partial class StreamingChatCompletionUpdate
[CodeGenMember("Id")]
public string CompletionId { get; }

// CUSTOM: Made internal.
[CodeGenMember("ServiceTier")]
internal InternalServiceTier? ServiceTier { get; }

// CUSTOM: Made internal.We only get back a single choice, and instead we flatten the structure for usability.
[CodeGenMember("Choices")]
internal IReadOnlyList<InternalCreateChatCompletionStreamResponseChoice> Choices { get; }
Expand Down
3 changes: 1 addition & 2 deletions src/Custom/Common/Internal/GeneratorStubs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ namespace OpenAI.Internal;
[CodeGenType("WebSearchContextSize")] internal readonly partial struct InternalWebSearchContextSize { }
[CodeGenType("LogProbProperties")] internal partial class InternalLogProbProperties { }
[CodeGenType("ModelIdsShared")] internal readonly partial struct InternalModelIdsShared { }
[CodeGenType("VoiceIdsShared")] internal readonly partial struct InternalVoiceIdsShared { }
[CodeGenType("ServiceTier")] internal readonly partial struct InternalServiceTier { }
[CodeGenType("VoiceIdsShared")] internal readonly partial struct InternalVoiceIdsShared { }
7 changes: 7 additions & 0 deletions src/Custom/Responses/ResponseServiceTier.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace OpenAI.Responses;

// CUSTOM: Renamed.
[CodeGenType("DotNetResponseServiceTier")]
public readonly partial struct ResponseServiceTier
{
}
36 changes: 17 additions & 19 deletions src/Generated/Models/Chat/ChatCompletion.Serialization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@
using System.Diagnostics.CodeAnalysis;
using System.Text.Json;
using OpenAI;
using OpenAI.Internal;

namespace OpenAI.Chat
{
public partial class ChatCompletion : IJsonModel<ChatCompletion>
{
internal ChatCompletion() : this(null, null, null, null, null, default, null, default, null)
internal ChatCompletion() : this(null, null, default, null, null, null, null, default, null)
{
}

Expand Down Expand Up @@ -44,6 +43,11 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit
writer.WritePropertyName("model"u8);
writer.WriteStringValue(Model);
}
if (Optional.IsDefined(ServiceTier) && _additionalBinaryDataProperties?.ContainsKey("service_tier") != true)
{
writer.WritePropertyName("service_tier"u8);
writer.WriteStringValue(ServiceTier.Value.ToString());
}
if (Optional.IsDefined(SystemFingerprint) && _additionalBinaryDataProperties?.ContainsKey("system_fingerprint") != true)
{
writer.WritePropertyName("system_fingerprint"u8);
Expand All @@ -59,11 +63,6 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit
writer.WritePropertyName("object"u8);
writer.WriteStringValue(Object);
}
if (Optional.IsDefined(ServiceTier) && _additionalBinaryDataProperties?.ContainsKey("service_tier") != true)
{
writer.WritePropertyName("service_tier"u8);
writer.WriteStringValue(ServiceTier.Value.ToString());
}
if (_additionalBinaryDataProperties?.ContainsKey("choices") != true)
{
writer.WritePropertyName("choices"u8);
Expand Down Expand Up @@ -123,10 +122,10 @@ internal static ChatCompletion DeserializeChatCompletion(JsonElement element, Mo
}
string id = default;
string model = default;
ChatServiceTier? serviceTier = default;
string systemFingerprint = default;
ChatTokenUsage usage = default;
string @object = default;
InternalServiceTier? serviceTier = default;
IReadOnlyList<InternalCreateChatCompletionResponseChoice> choices = default;
DateTimeOffset createdAt = default;
IDictionary<string, BinaryData> additionalBinaryDataProperties = new ChangeTrackingDictionary<string, BinaryData>();
Expand All @@ -142,6 +141,15 @@ internal static ChatCompletion DeserializeChatCompletion(JsonElement element, Mo
model = prop.Value.GetString();
continue;
}
if (prop.NameEquals("service_tier"u8))
{
if (prop.Value.ValueKind == JsonValueKind.Null)
{
continue;
}
serviceTier = new ChatServiceTier(prop.Value.GetString());
continue;
}
if (prop.NameEquals("system_fingerprint"u8))
{
systemFingerprint = prop.Value.GetString();
Expand All @@ -161,16 +169,6 @@ internal static ChatCompletion DeserializeChatCompletion(JsonElement element, Mo
@object = prop.Value.GetString();
continue;
}
if (prop.NameEquals("service_tier"u8))
{
if (prop.Value.ValueKind == JsonValueKind.Null)
{
serviceTier = null;
continue;
}
serviceTier = new InternalServiceTier(prop.Value.GetString());
continue;
}
if (prop.NameEquals("choices"u8))
{
List<InternalCreateChatCompletionResponseChoice> array = new List<InternalCreateChatCompletionResponseChoice>();
Expand All @@ -192,10 +190,10 @@ internal static ChatCompletion DeserializeChatCompletion(JsonElement element, Mo
return new ChatCompletion(
id,
model,
serviceTier,
systemFingerprint,
usage,
@object,
serviceTier,
choices,
createdAt,
additionalBinaryDataProperties);
Expand Down
Loading