diff --git a/api/OpenAI.netstandard2.0.cs b/api/OpenAI.netstandard2.0.cs index 2b3b9d35f..a67971fb5 100644 --- a/api/OpenAI.netstandard2.0.cs +++ b/api/OpenAI.netstandard2.0.cs @@ -296,24 +296,33 @@ public class AssistantModificationOptions : IJsonModel.GetFormatFromOptions(ModelReaderWriterOptions options); BinaryData IPersistableModel.Write(ModelReaderWriterOptions options); } - public class AssistantResponseFormat : IJsonModel, IPersistableModel { - protected AssistantResponseFormat(); + public abstract class AssistantResponseFormat : IEquatable, IEquatable, IJsonModel, IPersistableModel { public static AssistantResponseFormat Auto { get; } public static AssistantResponseFormat JsonObject { get; } public static AssistantResponseFormat Text { get; } - public bool Equals(AssistantResponseFormat other); + public static AssistantResponseFormat CreateAutoFormat(); + public static AssistantResponseFormat CreateJsonObjectFormat(); + public static AssistantResponseFormat CreateJsonSchemaFormat(string name, BinaryData jsonSchema, string description = null, bool? strictSchemaEnabled = null); + public static AssistantResponseFormat CreateTextFormat(); [EditorBrowsable(EditorBrowsableState.Never)] public override bool Equals(object obj); [EditorBrowsable(EditorBrowsableState.Never)] public override int GetHashCode(); - public static bool operator ==(AssistantResponseFormat left, AssistantResponseFormat right); - public static implicit operator AssistantResponseFormat(string value); - public static bool operator !=(AssistantResponseFormat left, AssistantResponseFormat right); + [EditorBrowsable(EditorBrowsableState.Never)] + public static bool operator ==(AssistantResponseFormat first, AssistantResponseFormat second); + [EditorBrowsable(EditorBrowsableState.Never)] + public static implicit operator AssistantResponseFormat(string plainTextFormat); + [EditorBrowsable(EditorBrowsableState.Never)] + public static bool operator !=(AssistantResponseFormat first, AssistantResponseFormat second); AssistantResponseFormat IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options); void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options); AssistantResponseFormat IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options); string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options); BinaryData IPersistableModel.Write(ModelReaderWriterOptions options); + [EditorBrowsable(EditorBrowsableState.Never)] + bool IEquatable.Equals(AssistantResponseFormat other); + [EditorBrowsable(EditorBrowsableState.Never)] + bool IEquatable.Equals(string other); public override string ToString(); } public class AssistantThread : IJsonModel, IPersistableModel { @@ -363,10 +372,11 @@ public class FileSearchToolResources : IJsonModel, IPer } public class FunctionToolDefinition : ToolDefinition, IJsonModel, IPersistableModel { public FunctionToolDefinition(); - public FunctionToolDefinition(string name, string description = null, BinaryData parameters = null); + public FunctionToolDefinition(string name); public string Description { get; set; } public required string FunctionName { get; set; } public BinaryData Parameters { get; set; } + public bool? StrictParameterSchemaEnabled { get; set; } FunctionToolDefinition IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options); void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options); FunctionToolDefinition IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options); @@ -384,6 +394,7 @@ public abstract class MessageContent : IJsonModel, IPersistableM public MessageImageDetail? ImageDetail { get; } public string ImageFileId { get; } public Uri ImageUrl { get; } + public string Refusal { get; } public string Text { get; } public IReadOnlyList TextAnnotations { get; } public static MessageContent FromImageFileId(string imageFileId, MessageImageDetail? detail = null); @@ -402,6 +413,7 @@ public class MessageContentUpdate : StreamingUpdate { public string ImageFileId { get; } public string MessageId { get; } public int MessageIndex { get; } + public string RefusalUpdate { get; } public MessageRole? Role { get; } public string Text { get; } public TextAnnotationUpdate TextAnnotation { get; } @@ -937,7 +949,7 @@ public abstract class ToolDefinition : IJsonModel, IPersistableM protected ToolDefinition(string type); public static CodeInterpreterToolDefinition CreateCodeInterpreter(); public static FileSearchToolDefinition CreateFileSearch(int? maxResults = null); - public static FunctionToolDefinition CreateFunction(string name, string description = null, BinaryData parameters = null); + public static FunctionToolDefinition CreateFunction(string name, string description = null, BinaryData parameters = null, bool? strictParameterSchemaEnabled = null); ToolDefinition IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options); void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options); ToolDefinition IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options); @@ -969,6 +981,7 @@ public class VectorStoreCreationHelper : IJsonModel, public VectorStoreCreationHelper(); public VectorStoreCreationHelper(IEnumerable files, IDictionary metadata = null); public VectorStoreCreationHelper(IEnumerable fileIds, IDictionary metadata = null); + public FileChunkingStrategy ChunkingStrategy { get; set; } public IList FileIds { get; } public IDictionary Metadata { get; } VectorStoreCreationHelper IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options); @@ -1165,10 +1178,13 @@ namespace OpenAI.Chat { public class AssistantChatMessage : ChatMessage, IJsonModel, IPersistableModel { public AssistantChatMessage(ChatCompletion chatCompletion); public AssistantChatMessage(ChatFunctionCall functionCall, string content = null); + public AssistantChatMessage(params ChatMessageContentPart[] contentParts); + public AssistantChatMessage(IEnumerable contentParts); public AssistantChatMessage(IEnumerable toolCalls, string content = null); public AssistantChatMessage(string content); public ChatFunctionCall FunctionCall { get; set; } public string ParticipantName { get; set; } + public string Refusal { get; set; } public IList ToolCalls { get; } AssistantChatMessage IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options); void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options); @@ -1204,6 +1220,8 @@ public class ChatCompletion : IJsonModel, IPersistableModel RefusalTokenLogProbabilities { get; } public ChatMessageRole Role { get; } public string SystemFingerprint { get; } public IReadOnlyList ToolCalls { get; } @@ -1279,13 +1297,22 @@ public class ChatFunctionChoice : IJsonModel, IPersistableMo BinaryData IPersistableModel.Write(ModelReaderWriterOptions options); } public abstract class ChatMessage : IJsonModel, IPersistableModel { - public IList Content { get; protected set; } + protected ChatMessage(); + protected internal ChatMessage(ChatMessageRole role, IEnumerable contentParts); + protected internal ChatMessage(ChatMessageRole role, string content); + public IList Content { get; } public static AssistantChatMessage CreateAssistantMessage(ChatCompletion chatCompletion); public static AssistantChatMessage CreateAssistantMessage(ChatFunctionCall functionCall, string content = null); + public static AssistantChatMessage CreateAssistantMessage(params ChatMessageContentPart[] contentParts); + public static AssistantChatMessage CreateAssistantMessage(IEnumerable contentParts); public static AssistantChatMessage CreateAssistantMessage(IEnumerable toolCalls, string content = null); public static AssistantChatMessage CreateAssistantMessage(string content); public static FunctionChatMessage CreateFunctionMessage(string functionName, string content); + public static SystemChatMessage CreateSystemMessage(params ChatMessageContentPart[] contentParts); + public static SystemChatMessage CreateSystemMessage(IEnumerable contentParts); public static SystemChatMessage CreateSystemMessage(string content); + public static ToolChatMessage CreateToolChatMessage(string toolCallId, params ChatMessageContentPart[] contentParts); + public static ToolChatMessage CreateToolChatMessage(string toolCallId, IEnumerable contentParts); public static ToolChatMessage CreateToolChatMessage(string toolCallId, string content); public static UserChatMessage CreateUserMessage(params ChatMessageContentPart[] contentParts); public static UserChatMessage CreateUserMessage(IEnumerable contentParts); @@ -1304,9 +1331,11 @@ public class ChatMessageContentPart : IJsonModel, IPersi public ImageChatMessageContentPartDetail? ImageDetail { get; } public Uri ImageUri { get; } public ChatMessageContentPartKind Kind { get; } + public string Refusal { get; } public string Text { get; } public static ChatMessageContentPart CreateImageMessageContentPart(BinaryData imageBytes, string imageBytesMediaType, ImageChatMessageContentPartDetail? imageDetail = null); public static ChatMessageContentPart CreateImageMessageContentPart(Uri imageUri, ImageChatMessageContentPartDetail? imageDetail = null); + public static ChatMessageContentPart CreateRefusalMessageContentPart(string refusal); public static ChatMessageContentPart CreateTextMessageContentPart(string text); public static implicit operator ChatMessageContentPart(string content); ChatMessageContentPart IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options); @@ -1321,6 +1350,7 @@ public class ChatMessageContentPart : IJsonModel, IPersi private readonly int _dummyPrimitive; public ChatMessageContentPartKind(string value); public static ChatMessageContentPartKind Image { get; } + public static ChatMessageContentPartKind Refusal { get; } public static ChatMessageContentPartKind Text { get; } public readonly bool Equals(ChatMessageContentPartKind other); [EditorBrowsable(EditorBrowsableState.Never)] @@ -1339,14 +1369,28 @@ public enum ChatMessageRole { Tool = 3, Function = 4 } - public class ChatResponseFormat : IJsonModel, IPersistableModel { + public abstract class ChatResponseFormat : IEquatable, IJsonModel, IPersistableModel { public static ChatResponseFormat JsonObject { get; } public static ChatResponseFormat Text { get; } + public static ChatResponseFormat CreateJsonObjectFormat(); + public static ChatResponseFormat CreateJsonSchemaFormat(string name, BinaryData jsonSchema, string description = null, bool? strictSchemaEnabled = null); + public static ChatResponseFormat CreateTextFormat(); + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj); + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode(); + [EditorBrowsable(EditorBrowsableState.Never)] + public static bool operator ==(ChatResponseFormat first, ChatResponseFormat second); + [EditorBrowsable(EditorBrowsableState.Never)] + public static bool operator !=(ChatResponseFormat first, ChatResponseFormat second); ChatResponseFormat IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options); void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options); ChatResponseFormat IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options); string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options); BinaryData IPersistableModel.Write(ModelReaderWriterOptions options); + [EditorBrowsable(EditorBrowsableState.Never)] + bool IEquatable.Equals(ChatResponseFormat other); + public override string ToString(); } public class ChatTokenLogProbabilityInfo : IJsonModel, IPersistableModel { public float LogProbability { get; } @@ -1384,7 +1428,8 @@ public class ChatTool : IJsonModel, IPersistableModel { public string FunctionName { get; } public BinaryData FunctionParameters { get; } public ChatToolKind Kind { get; } - public static ChatTool CreateFunctionTool(string functionName, string functionDescription = null, BinaryData functionParameters = null); + public bool? StrictParameterSchemaEnabled { get; } + public static ChatTool CreateFunctionTool(string functionName, string functionDescription = null, BinaryData functionParameters = null, bool? strictParameterSchemaEnabled = null); ChatTool IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options); void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options); ChatTool IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options); @@ -1480,6 +1525,8 @@ public class StreamingChatCompletionUpdate : IJsonModel RefusalTokenLogProbabilities { get; } + public string RefusalUpdate { get; } public ChatMessageRole? Role { get; } public string SystemFingerprint { get; } public IReadOnlyList ToolCallUpdates { get; } @@ -1512,6 +1559,8 @@ public class StreamingChatToolCallUpdate : IJsonModel.Write(ModelReaderWriterOptions options); } public class SystemChatMessage : ChatMessage, IJsonModel, IPersistableModel { + public SystemChatMessage(params ChatMessageContentPart[] contentParts); + public SystemChatMessage(IEnumerable contentParts); public SystemChatMessage(string content); public string ParticipantName { get; set; } SystemChatMessage IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options); @@ -1522,6 +1571,8 @@ public class SystemChatMessage : ChatMessage, IJsonModel, IPe protected override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options); } public class ToolChatMessage : ChatMessage, IJsonModel, IPersistableModel { + public ToolChatMessage(string toolCallId, params ChatMessageContentPart[] contentParts); + public ToolChatMessage(string toolCallId, IEnumerable contentParts); public ToolChatMessage(string toolCallId, string content); public string ToolCallId { get; } ToolChatMessage IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options); @@ -2256,10 +2307,9 @@ public class VectorStoreFileAssociationError : IJsonModel.Create", typeof(Utf8JsonReader), typeof(ModelReaderWriterOptions))] [CodeGenSuppress("global::System.ClientModel.Primitives.IPersistableModel.Write", typeof(ModelReaderWriterOptions))] [CodeGenSuppress("global::System.ClientModel.Primitives.IPersistableModel.Create", typeof(BinaryData), typeof(ModelReaderWriterOptions))] +[CodeGenSuppress("global::System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions", typeof(ModelReaderWriterOptions))] public partial class AssistantResponseFormat : IJsonModel { + internal static void SerializeAssistantResponseFormat(AssistantResponseFormat instance, Utf8JsonWriter writer, ModelReaderWriterOptions options = null) + { + throw new InvalidOperationException(); + } + + internal static AssistantResponseFormat DeserializeAssistantResponseFormat(JsonElement element, ModelReaderWriterOptions options = null) + { + return element.ValueKind switch + { + JsonValueKind.String => InternalAssistantResponseFormatPlainTextNoObject.DeserializeInternalAssistantResponseFormatPlainTextNoObject(element, options), + JsonValueKind.Object when element.TryGetProperty("type", out JsonElement discriminatorElement) + => discriminatorElement.GetString() switch + { + "json_object" => InternalAssistantResponseFormatJsonObject.DeserializeInternalAssistantResponseFormatJsonObject(element, options), + "json_schema" => InternalAssistantResponseFormatJsonSchema.DeserializeInternalAssistantResponseFormatJsonSchema(element, options), + "text" => InternalAssistantResponseFormatText.DeserializeInternalAssistantResponseFormatText(element, options), + _ => null, + }, + _ => null, + }; + } + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) - => CustomSerializationHelpers.SerializeInstance(this, SerializeAssistantResponseFormat, writer, options); + => CustomSerializationHelpers.SerializeInstance(this, SerializeAssistantResponseFormat, writer, options); AssistantResponseFormat IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => CustomSerializationHelpers.DeserializeNewInstance(this, DeserializeAssistantResponseFormat, ref reader, options); @@ -23,53 +46,15 @@ BinaryData IPersistableModel.Write(ModelReaderWriterOpt AssistantResponseFormat IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) => CustomSerializationHelpers.DeserializeNewInstance(this, DeserializeAssistantResponseFormat, data, options); - internal static void SerializeAssistantResponseFormat(AssistantResponseFormat formatInstance, Utf8JsonWriter writer, ModelReaderWriterOptions options) + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static AssistantResponseFormat FromResponse(PipelineResponse response) { - if (formatInstance._plainTextValue is not null) - { - writer.WriteStringValue(formatInstance._plainTextValue); - } - else - { - writer.WriteStartObject(); - writer.WritePropertyName("type"u8); - writer.WriteStringValue(formatInstance._objectType); - writer.WriteSerializedAdditionalRawData(formatInstance.SerializedAdditionalRawData, options); - writer.WriteEndObject(); - } + throw new InvalidOperationException(); } - internal static AssistantResponseFormat DeserializeAssistantResponseFormat(JsonElement element, ModelReaderWriterOptions options = null) + internal virtual BinaryContent ToBinaryContent() { - options ??= ModelSerializationExtensions.WireOptions; - - string plainTextValue = null; - string objectType = null; - IDictionary rawDataDictionary = new ChangeTrackingDictionary(); - - if (element.ValueKind == JsonValueKind.Null) - { - return null; - } - else if (element.ValueKind == JsonValueKind.String) - { - plainTextValue = element.GetString(); - } - else - { - foreach (var property in element.EnumerateObject()) - { - if (property.NameEquals("type"u8)) - { - objectType = property.Value.GetString(); - continue; - } - if (true) - { - rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); - } - } - } - return new AssistantResponseFormat(plainTextValue, objectType, rawDataDictionary); + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); } } diff --git a/src/Custom/Assistants/AssistantResponseFormat.cs b/src/Custom/Assistants/AssistantResponseFormat.cs index 226fa31df..c87b9b076 100644 --- a/src/Custom/Assistants/AssistantResponseFormat.cs +++ b/src/Custom/Assistants/AssistantResponseFormat.cs @@ -1,107 +1,109 @@ +using OpenAI.Internal; using System; -using System.Collections.Generic; +using System.ClientModel.Primitives; using System.ComponentModel; namespace OpenAI.Assistants; -/// -/// Specifies the format that the model must output. Compatible with GPT-4o, GPT-4 Turbo, and all GPT-3.5 Turbo models since gpt-3.5-turbo-1106. -/// -/// -/// -/// Setting to { "type": "json_object" } enables JSON mode, which guarantees the message the model generates is valid JSON. -/// -/// -/// Important: when using JSON mode, you must also instruct the model to produce JSON yourself via a system or user message.Without this, the model may generate an unending stream of whitespace until the generation reaches the token limit, resulting in a long-running and seemingly "stuck" request.Also note that the message content may be partially cut off if finish_reason= "length", which indicates the generation exceeded max_tokens or the conversation exceeded the max context length. -/// -/// [CodeGenModel("AssistantResponseFormat")] -public partial class AssistantResponseFormat +public partial class AssistantResponseFormat : IEquatable, IEquatable { - private readonly string _plainTextValue; - private readonly string _objectType; - private readonly IDictionary SerializedAdditionalRawData; + public static AssistantResponseFormat Auto { get; } = CreateAutoFormat(); + public static AssistantResponseFormat Text { get; } = CreateTextFormat(); + public static AssistantResponseFormat JsonObject { get; } = CreateJsonObjectFormat(); - private const string AutoValue = "auto"; - private const string TextValue = "text"; - private const string JsonObjectValue = "json_object"; - - /// - /// Default option. Specifies that the model should automatically determine whether it should respond with - /// plain text or another format. - /// - public static AssistantResponseFormat Auto { get; } - = new(plainTextValue: AutoValue, objectType: null, serializedAdditionalRawData: null); + public static AssistantResponseFormat CreateAutoFormat() + => new InternalAssistantResponseFormatPlainTextNoObject("auto"); + public static AssistantResponseFormat CreateTextFormat() + => new InternalAssistantResponseFormatText(); + public static AssistantResponseFormat CreateJsonObjectFormat() + => new InternalAssistantResponseFormatJsonObject(); + public static AssistantResponseFormat CreateJsonSchemaFormat( + string name, + BinaryData jsonSchema, + string description = null, + bool? strictSchemaEnabled = null) + { + Argument.AssertNotNullOrEmpty(name, nameof(name)); + Argument.AssertNotNull(jsonSchema, nameof(jsonSchema)); - /// - /// Specifies that the model should respond with plain text. - /// - public static AssistantResponseFormat Text { get; } - = new(plainTextValue: null, objectType: TextValue, serializedAdditionalRawData: null); + InternalResponseFormatJsonSchemaJsonSchema internalSchema = new( + description, + name, + jsonSchema, + strictSchemaEnabled, + null); + return new InternalAssistantResponseFormatJsonSchema(internalSchema); + } - /// - /// Specifies that the model should reply with a structured JSON object, enabling JSON mode. - /// - /// - /// **Important:** when using JSON mode, you **must** also instruct the model to produce JSON yourself via a - /// system or user message. Without this, the model may generate an unending stream of whitespace until the - /// generation reaches the token limit, resulting in a long-running and seemingly "stuck" request. Also note that - /// the message content may be partially cut off if `finish_reason="length"`, which indicates the generation - /// exceeded `max_tokens` or the conversation exceeded the max context length. - /// - public static AssistantResponseFormat JsonObject { get; } - = new(plainTextValue: null, objectType: JsonObjectValue, serializedAdditionalRawData: null); + [EditorBrowsable(EditorBrowsableState.Never)] + public static bool operator ==(AssistantResponseFormat first, AssistantResponseFormat second) + { + if (first is null) + { + return second is null; + } + return first.Equals(second); + } - /// - /// Creates a new instance of for mocking. - /// - protected AssistantResponseFormat() - { } + [EditorBrowsable(EditorBrowsableState.Never)] + public static bool operator !=(AssistantResponseFormat first, AssistantResponseFormat second) + => !(first == second); - internal AssistantResponseFormat(string plainTextValue, string objectType, IDictionary serializedAdditionalRawData) + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) { - _plainTextValue = plainTextValue; - _objectType = objectType; - SerializedAdditionalRawData = serializedAdditionalRawData ?? new ChangeTrackingDictionary(); + return (this as IEquatable).Equals(obj as AssistantResponseFormat) + || ToString().Equals(obj?.ToString()); } - /// - public static bool operator ==(AssistantResponseFormat left, AssistantResponseFormat right) => left.Equals(right); - /// - public static bool operator !=(AssistantResponseFormat left, AssistantResponseFormat right) => !left.Equals(right); + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => ToString().GetHashCode(); - /// - public static implicit operator AssistantResponseFormat(string value) + [EditorBrowsable(EditorBrowsableState.Never)] + public static implicit operator AssistantResponseFormat(string plainTextFormat) + => new InternalAssistantResponseFormatPlainTextNoObject(plainTextFormat); + + [EditorBrowsable(EditorBrowsableState.Never)] + bool IEquatable.Equals(AssistantResponseFormat other) { - if (string.Equals(value, AutoValue, StringComparison.OrdinalIgnoreCase)) + if (other is null) { - return Auto; + return false; } - if (string.Equals(value, TextValue, StringComparison.OrdinalIgnoreCase)) + + if (Object.ReferenceEquals(this, other)) { - return Text; + return true; } - if (string.Equals(value, JsonObjectValue, StringComparison.OrdinalIgnoreCase)) + + return + (this is InternalAssistantResponseFormatPlainTextNoObject thisPlainText + && other is InternalAssistantResponseFormatPlainTextNoObject otherPlainText + && thisPlainText.Value.Equals(otherPlainText.Value)) + || (this is InternalAssistantResponseFormatText && other is InternalAssistantResponseFormatText) + || (this is InternalAssistantResponseFormatJsonObject && other is InternalAssistantResponseFormatJsonObject) + || (this is InternalAssistantResponseFormatJsonSchema thisJsonSchema + && other is InternalAssistantResponseFormatJsonSchema otherJsonSchema + && thisJsonSchema.JsonSchema.Name.Equals(otherJsonSchema.JsonSchema.Name)); + } + + [EditorBrowsable(EditorBrowsableState.Never)] + bool IEquatable.Equals(string other) + { + return this is InternalAssistantResponseFormatPlainTextNoObject thisPlainText + && thisPlainText.Value.Equals(other); + } + + public override string ToString() + { + if (this is InternalAssistantResponseFormatPlainTextNoObject plainTextInstance) { - return JsonObject; + return plainTextInstance.Value; } else { - return new(plainTextValue: null, objectType: value, serializedAdditionalRawData: null); + return ModelReaderWriter.Write(this).ToString(); } } - - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals(object obj) => obj is AssistantResponseFormat other && Equals(other); - /// - public bool Equals(AssistantResponseFormat other) - => string.Equals(_plainTextValue, other?._plainTextValue, StringComparison.InvariantCultureIgnoreCase) - && string.Equals(_objectType, other?._objectType, StringComparison.InvariantCultureIgnoreCase); - - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public override int GetHashCode() => $"{_plainTextValue}/{_objectType}".GetHashCode(); - /// - public override string ToString() => _plainTextValue ?? _objectType; -} +} \ No newline at end of file diff --git a/src/Custom/Assistants/FileSearchToolResources.cs b/src/Custom/Assistants/FileSearchToolResources.cs index 66c0a1d43..53e0d6bcf 100644 --- a/src/Custom/Assistants/FileSearchToolResources.cs +++ b/src/Custom/Assistants/FileSearchToolResources.cs @@ -4,7 +4,7 @@ namespace OpenAI.Assistants; -[CodeGenModel("AssistantObjectToolResourcesFileSearch")] +[CodeGenModel("ToolResourcesFileSearch")] [CodeGenSerialization(nameof(NewVectorStores), "vector_stores", SerializationValueHook = nameof(SerializeNewVectorStores))] public partial class FileSearchToolResources { @@ -24,7 +24,7 @@ public IList VectorStoreIds } } - [CodeGenMember("vector_stores")] + [CodeGenMember("VectorStores")] public IList NewVectorStores { get; } = new ChangeTrackingList(); public FileSearchToolResources() diff --git a/src/Custom/Assistants/FunctionToolDefinition.cs b/src/Custom/Assistants/FunctionToolDefinition.cs index 764e93ccf..70e2ba163 100644 --- a/src/Custom/Assistants/FunctionToolDefinition.cs +++ b/src/Custom/Assistants/FunctionToolDefinition.cs @@ -34,15 +34,21 @@ public BinaryData Parameters set => _internalFunction.Parameters = value; } + public bool? StrictParameterSchemaEnabled + { + get => _internalFunction.Strict; + set => _internalFunction.Strict = value; + } + /// /// Creates a new instance of . /// [SetsRequiredMembers] - public FunctionToolDefinition(string name, string description = null, BinaryData parameters = null) + public FunctionToolDefinition(string name) : base("function") { Argument.AssertNotNullOrEmpty(name, nameof(name)); - _internalFunction = new(description, name, parameters, null); + _internalFunction = new(null, name, null, null, null); } /// diff --git a/src/Custom/Assistants/Internal/GeneratorStubs.Internal.cs b/src/Custom/Assistants/Internal/GeneratorStubs.Internal.cs index e8fae6b4f..08f753db0 100644 --- a/src/Custom/Assistants/Internal/GeneratorStubs.Internal.cs +++ b/src/Custom/Assistants/Internal/GeneratorStubs.Internal.cs @@ -120,6 +120,9 @@ internal partial class InternalMessageContentItemFileObjectImageFile [CodeGenModel("MessageContentTextObjectText")] internal partial class InternalMessageContentTextObjectText { } +[CodeGenModel("MessageContentRefusalObjectType")] +internal readonly partial struct InternalMessageContentRefusalObjectType { } + [CodeGenModel("RunStepDetailsMessageCreationObjectMessageCreation")] internal partial class InternalRunStepDetailsMessageCreationObjectMessageCreation { } @@ -189,9 +192,6 @@ internal readonly partial struct InternalAssistantsNamedToolChoiceType { } [CodeGenModel("RunStepDeltaStepDetailsToolCallsCodeObject")] internal partial class InternalRunStepDeltaStepDetailsToolCallsCodeObject { } -[CodeGenModel("RunStepUpdateCodeInterpreterOutput")] -internal abstract partial class InternalRunStepUpdateCodeInterpreterOutput { } - [CodeGenModel("RunStepDeltaStepDetailsToolCallsCodeOutputImageObject")] internal partial class InternalRunStepDeltaStepDetailsToolCallsCodeOutputImageObject { } @@ -232,12 +232,6 @@ internal partial class InternalRunStepDeltaStepDetails { } [CodeGenModel("RunStepDeltaStepDetailsToolCallsFunctionObjectFunction")] internal partial class InternalRunStepDeltaStepDetailsToolCallsFunctionObjectFunction { } -[CodeGenModel("AssistantsApiResponseFormat")] -internal partial class InternalAssistantsApiResponseFormat { } - -[CodeGenModel("AssistantsApiResponseFormatType")] -internal readonly partial struct InternalAssistantsApiResponseFormatType { } - [CodeGenModel("AssistantsNamedToolChoiceFunction")] internal partial class InternalAssistantsNamedToolChoiceFunction { } @@ -307,33 +301,15 @@ internal readonly partial struct InternalMessageObjectRole { } [CodeGenModel("CreateRunRequestModel")] internal readonly partial struct InternalCreateRunRequestModel { } -[CodeGenModel("CreateRunRequestToolChoice")] -internal readonly partial struct InternalCreateRunRequestToolChoice { } - -[CodeGenModel("CreateAssistantRequestResponseFormat1")] -internal readonly partial struct InternalCreateAssistantRequestResponseFormat { } - [CodeGenModel("CreateAssistantRequestToolResources")] internal partial class InternalCreateAssistantRequestToolResources { } [CodeGenModel("CreateAssistantRequestToolResourcesCodeInterpreter")] internal partial class InternalCreateAssistantRequestToolResourcesCodeInterpreter { } -[CodeGenModel("CreateAssistantRequestToolResourcesFileSearchBase")] -internal partial class InternalCreateAssistantRequestToolResourcesFileSearchBase { } - -[CodeGenModel("CreateAssistantRequestToolResourcesFileSearchVectorStoreCreationHelpers")] -internal partial class InternalCreateAssistantRequestToolResourcesFileSearchVectorStoreCreationHelpers { } - -[CodeGenModel("CreateAssistantRequestToolResourcesFileSearchVectorStoreIdReferences")] -internal partial class InternalCreateAssistantRequestToolResourcesFileSearchVectorStoreIdReferences { } - [CodeGenModel("CreateThreadAndRunRequestModel")] internal readonly partial struct InternalCreateThreadAndRunRequestModel { } -[CodeGenModel("CreateThreadAndRunRequestResponseFormat")] -internal readonly partial struct InternalCreateThreadAndRunRequestResponseFormat { } - [CodeGenModel("CreateThreadAndRunRequestToolChoice")] internal readonly partial struct InternalCreateThreadAndRunRequestToolChoice { } @@ -343,9 +319,6 @@ internal partial class InternalCreateThreadAndRunRequestToolResources { } [CodeGenModel("CreateThreadAndRunRequestToolResourcesCodeInterpreter")] internal partial class InternalCreateThreadAndRunRequestToolResourcesCodeInterpreter { } -[CodeGenModel("CreateThreadAndRunRequestToolResourcesFileSearch")] -internal partial class InternalCreateThreadAndRunRequestToolResourcesFileSearch { } - [CodeGenModel("CreateThreadRequestToolResources")] internal partial class InternalCreateThreadRequestToolResources { } @@ -355,33 +328,18 @@ internal partial class InternalCreateThreadRequestToolResourcesCodeInterpreter { [CodeGenModel("CreateThreadRequestToolResourcesFileSearchBase")] internal partial class InternalCreateThreadRequestToolResourcesFileSearchBase { } -[CodeGenModel("CreateThreadRequestToolResourcesFileSearchVectorStoreCreationHelpers")] -internal partial class InternalCreateThreadRequestToolResourcesFileSearchVectorStoreCreationHelpers { } - -[CodeGenModel("CreateThreadRequestToolResourcesFileSearchVectorStoreCreationHelpersVectorStore")] -internal partial class InternalCreateThreadRequestToolResourcesFileSearchVectorStoreCreationHelpersVectorStore { } - -[CodeGenModel("CreateThreadRequestToolResourcesFileSearchVectorStoreIdReferences")] -internal partial class InternalCreateThreadRequestToolResourcesFileSearchVectorStoreIdReferences { } - [CodeGenModel("ModifyAssistantRequestToolResources")] internal partial class InternalModifyAssistantRequestToolResources { } [CodeGenModel("ModifyAssistantRequestToolResourcesCodeInterpreter")] internal partial class InternalModifyAssistantRequestToolResourcesCodeInterpreter { } -[CodeGenModel("ModifyAssistantRequestToolResourcesFileSearch")] -internal partial class InternalModifyAssistantRequestToolResourcesFileSearch { } - [CodeGenModel("ModifyThreadRequestToolResources")] internal partial class InternalModifyThreadRequestToolResources { } [CodeGenModel("ModifyThreadRequestToolResourcesCodeInterpreter")] internal partial class InternalModifyThreadRequestToolResourcesCodeInterpreter { } -[CodeGenModel("ModifyThreadRequestToolResourcesFileSearch")] -internal partial class InternalModifyThreadRequestToolResourcesFileSearch { } - [CodeGenModel("ThreadObjectToolResources")] internal partial class InternalThreadObjectToolResources { } @@ -396,3 +354,10 @@ internal partial class InternalAssistantToolsFileSearchTypeOnly { } [CodeGenModel("AssistantToolsFileSearchTypeOnlyType")] internal readonly partial struct InternalAssistantToolsFileSearchTypeOnlyType { } + +[CodeGenModel("AssistantResponseFormatText")] internal partial class InternalAssistantResponseFormatText { } +[CodeGenModel("AssistantResponseFormatJsonObject")] internal partial class InternalAssistantResponseFormatJsonObject { } +[CodeGenModel("AssistantResponseFormatJsonSchema")] internal partial class InternalAssistantResponseFormatJsonSchema { } +[CodeGenModel("UnknownAssistantResponseFormat")] internal partial class InternalUnknownAssistantResponseFormat { } +[CodeGenModel("MessageDeltaContentRefusalObject")] internal partial class InternalMessageDeltaContentRefusalObject { } +[CodeGenModel("ToolResourcesFileSearchIdsOnly")] internal partial class InternalToolResourcesFileSearchIdsOnly { } diff --git a/src/Custom/Assistants/Internal/InternalAssistantResponseFormatPlainTextNoObject.Serialization.cs b/src/Custom/Assistants/Internal/InternalAssistantResponseFormatPlainTextNoObject.Serialization.cs new file mode 100644 index 000000000..1d962611c --- /dev/null +++ b/src/Custom/Assistants/Internal/InternalAssistantResponseFormatPlainTextNoObject.Serialization.cs @@ -0,0 +1,36 @@ +using System; +using System.ClientModel.Primitives; +using System.Text.Json; + +namespace OpenAI.Assistants; + +internal partial class InternalAssistantResponseFormatPlainTextNoObject : IJsonModel +{ + internal static void SerializeInternalAssistantResponseFormatPlainTextNoObject(InternalAssistantResponseFormatPlainTextNoObject instance, Utf8JsonWriter writer, ModelReaderWriterOptions options = null) + { + writer.WriteStringValue(instance.Value); + } + + internal static InternalAssistantResponseFormatPlainTextNoObject DeserializeInternalAssistantResponseFormatPlainTextNoObject(JsonElement element, ModelReaderWriterOptions options = null) + { + if (element.ValueKind == JsonValueKind.String) + { + return new(element.GetString()); + } + return null; + } + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + => CustomSerializationHelpers.SerializeInstance(this, SerializeInternalAssistantResponseFormatPlainTextNoObject, writer, options); + + InternalAssistantResponseFormatPlainTextNoObject IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + => CustomSerializationHelpers.DeserializeNewInstance(this, DeserializeInternalAssistantResponseFormatPlainTextNoObject, ref reader, options); + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + => CustomSerializationHelpers.SerializeInstance(this, options); + + InternalAssistantResponseFormatPlainTextNoObject IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + => CustomSerializationHelpers.DeserializeNewInstance(this, DeserializeInternalAssistantResponseFormatPlainTextNoObject, data, options); + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; +} diff --git a/src/Custom/Assistants/Internal/InternalAssistantResponseFormatPlainTextNoObject.cs b/src/Custom/Assistants/Internal/InternalAssistantResponseFormatPlainTextNoObject.cs new file mode 100644 index 000000000..6c3e2ee7c --- /dev/null +++ b/src/Custom/Assistants/Internal/InternalAssistantResponseFormatPlainTextNoObject.cs @@ -0,0 +1,11 @@ +namespace OpenAI.Assistants; + +internal partial class InternalAssistantResponseFormatPlainTextNoObject : AssistantResponseFormat +{ + public string Value { get; set; } + + public InternalAssistantResponseFormatPlainTextNoObject(string value) + { + Value = value; + } +} \ No newline at end of file diff --git a/src/Custom/Assistants/Internal/InternalMessageRefusalContent.Serialization.cs b/src/Custom/Assistants/Internal/InternalMessageRefusalContent.Serialization.cs new file mode 100644 index 000000000..b14bf17a6 --- /dev/null +++ b/src/Custom/Assistants/Internal/InternalMessageRefusalContent.Serialization.cs @@ -0,0 +1,27 @@ +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.Assistants; + +[CodeGenSuppress("global::System.ClientModel.Primitives.IJsonModel.Write", typeof(Utf8JsonWriter), typeof(ModelReaderWriterOptions))] +internal partial class InternalMessageRefusalContent : IJsonModel +{ + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + => CustomSerializationHelpers.SerializeInstance(this, SerializeInternalMessageRefusalContent, writer, options); + + internal static void SerializeInternalMessageRefusalContent(InternalMessageRefusalContent instance, Utf8JsonWriter writer, ModelReaderWriterOptions options) + => instance.WriteCore(writer, options); + + protected override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(_type); + writer.WritePropertyName("refusal"u8); + writer.WriteStringValue(Refusal); + writer.WriteEndObject(); + } +} \ No newline at end of file diff --git a/src/Custom/Assistants/Internal/InternalMessageRefusalContent.cs b/src/Custom/Assistants/Internal/InternalMessageRefusalContent.cs new file mode 100644 index 000000000..ed0188314 --- /dev/null +++ b/src/Custom/Assistants/Internal/InternalMessageRefusalContent.cs @@ -0,0 +1,20 @@ +using System; + +namespace OpenAI.Assistants; + +/// +/// Represents an item of image URL content within an Assistants API message. +/// +/// +/// Use the method to +/// create an instance of this type. +/// +[CodeGenModel("MessageContentRefusalObject")] +internal partial class InternalMessageRefusalContent +{ + [CodeGenMember("Type")] + private string _type = "refusal"; + + [CodeGenMember("Refusal")] + public string InternalRefusal { get; set; } +} diff --git a/src/Custom/Assistants/MessageContent.cs b/src/Custom/Assistants/MessageContent.cs index a32b8e982..8043d79cb 100644 --- a/src/Custom/Assistants/MessageContent.cs +++ b/src/Custom/Assistants/MessageContent.cs @@ -45,11 +45,13 @@ public static MessageContent FromText(string text) public string Text => AsInternalRequestText?.InternalText ?? AsInternalResponseText?.InternalText; /// public IReadOnlyList TextAnnotations => AsInternalResponseText?.InternalAnnotations ?? []; + public string Refusal => AsRefusal?.InternalRefusal; private InternalMessageImageFileContent AsInternalImageFile => this as InternalMessageImageFileContent; private InternalMessageImageUrlContent AsInternalImageUrl => this as InternalMessageImageUrlContent; private InternalResponseMessageTextContent AsInternalResponseText => this as InternalResponseMessageTextContent; private InternalRequestMessageTextContent AsInternalRequestText => this as InternalRequestMessageTextContent; + private InternalMessageRefusalContent AsRefusal => this as InternalMessageRefusalContent; /// /// The implicit conversion operator that infers an equivalent diff --git a/src/Custom/Assistants/Streaming/MessageContentUpdate.cs b/src/Custom/Assistants/Streaming/MessageContentUpdate.cs index 468e27082..ad6944617 100644 --- a/src/Custom/Assistants/Streaming/MessageContentUpdate.cs +++ b/src/Custom/Assistants/Streaming/MessageContentUpdate.cs @@ -21,6 +21,7 @@ public partial class MessageContentUpdate : StreamingUpdate public int MessageIndex => _textContent?.Index ?? _imageFileContent?.Index ?? _imageUrlContent?.Index + ?? _refusalContent?.Index ?? TextAnnotation?.ContentIndex ?? 0; @@ -42,9 +43,12 @@ public partial class MessageContentUpdate : StreamingUpdate /// public TextAnnotationUpdate TextAnnotation { get; } + public string RefusalUpdate => _refusalContent?.Refusal; + private readonly InternalMessageDeltaContentImageFileObject _imageFileContent; private readonly InternalMessageDeltaContentTextObject _textContent; private readonly InternalMessageDeltaContentImageUrlObject _imageUrlContent; + private readonly InternalMessageDeltaContentRefusalObject _refusalContent; private readonly InternalMessageDeltaObject _delta; internal MessageContentUpdate(InternalMessageDeltaObject delta, InternalMessageDeltaContent content) @@ -54,6 +58,7 @@ internal MessageContentUpdate(InternalMessageDeltaObject delta, InternalMessageD _textContent = content as InternalMessageDeltaContentTextObject; _imageFileContent = content as InternalMessageDeltaContentImageFileObject; _imageUrlContent = content as InternalMessageDeltaContentImageUrlObject; + _refusalContent = content as InternalMessageDeltaContentRefusalObject; } internal MessageContentUpdate(InternalMessageDeltaObject delta, TextAnnotationUpdate annotation) diff --git a/src/Custom/Assistants/ToolDefinition.cs b/src/Custom/Assistants/ToolDefinition.cs index 92528d30b..0b876e1c1 100644 --- a/src/Custom/Assistants/ToolDefinition.cs +++ b/src/Custom/Assistants/ToolDefinition.cs @@ -14,8 +14,13 @@ public static FileSearchToolDefinition CreateFileSearch(int? maxResults = null) MaxResults = maxResults }; } - public static FunctionToolDefinition CreateFunction(string name, string description = null, BinaryData parameters = null) - => new FunctionToolDefinition(name, description, parameters); + public static FunctionToolDefinition CreateFunction(string name, string description = null, BinaryData parameters = null, bool? strictParameterSchemaEnabled = null) + => new FunctionToolDefinition(name) + { + Description = description, + Parameters = parameters, + StrictParameterSchemaEnabled = strictParameterSchemaEnabled, + }; protected ToolDefinition(string type) { diff --git a/src/Custom/Assistants/VectorStoreCreationHelper.cs b/src/Custom/Assistants/VectorStoreCreationHelper.cs index 91c231ef4..cba26fb8e 100644 --- a/src/Custom/Assistants/VectorStoreCreationHelper.cs +++ b/src/Custom/Assistants/VectorStoreCreationHelper.cs @@ -1,20 +1,23 @@ using OpenAI.Files; +using OpenAI.VectorStores; using System.Collections.Generic; using System.Linq; -namespace OpenAI.Assistants +namespace OpenAI.Assistants; + +[CodeGenModel("ToolResourcesFileSearchVectorStore")] +public partial class VectorStoreCreationHelper { - [CodeGenModel("CreateAssistantRequestToolResourcesFileSearchVectorStoreCreationHelpersVectorStore")] - public partial class VectorStoreCreationHelper - { - public VectorStoreCreationHelper(IEnumerable fileIds, IDictionary metadata = null) - { - FileIds = fileIds.ToList(); - Metadata = metadata ?? new ChangeTrackingDictionary(); - } + [CodeGenMember("ChunkingStrategy")] + public FileChunkingStrategy ChunkingStrategy { get; set; } - public VectorStoreCreationHelper(IEnumerable files, IDictionary metadata = null) - : this(files?.Select(file => file.Id) ?? [], metadata) - {} + public VectorStoreCreationHelper(IEnumerable fileIds, IDictionary metadata = null) + { + FileIds = fileIds.ToList(); + Metadata = metadata ?? new ChangeTrackingDictionary(); } + + public VectorStoreCreationHelper(IEnumerable files, IDictionary metadata = null) + : this(files?.Select(file => file.Id) ?? [], metadata) + {} } diff --git a/src/Custom/Chat/AssistantChatMessage.Serialization.cs b/src/Custom/Chat/AssistantChatMessage.Serialization.cs index 38d9b4e4c..44749c211 100644 --- a/src/Custom/Chat/AssistantChatMessage.Serialization.cs +++ b/src/Custom/Chat/AssistantChatMessage.Serialization.cs @@ -1,5 +1,5 @@ -using System; using System.ClientModel.Primitives; +using System.Collections; using System.Collections.Generic; using System.Text.Json; @@ -17,47 +17,13 @@ internal static void SerializeAssistantChatMessage(AssistantChatMessage instance protected override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { writer.WriteStartObject(); - if (Optional.IsDefined(ParticipantName)) - { - writer.WritePropertyName("name"u8); - writer.WriteStringValue(ParticipantName); - } - if (Optional.IsCollectionDefined(ToolCalls)) - { - writer.WritePropertyName("tool_calls"u8); - writer.WriteStartArray(); - foreach (var item in ToolCalls) - { - writer.WriteObjectValue(item, options); - } - writer.WriteEndArray(); - } - if (Optional.IsDefined(FunctionCall)) - { - if (FunctionCall != null) - { - writer.WritePropertyName("function_call"u8); - writer.WriteObjectValue(FunctionCall, options); - } - else - { - writer.WriteNull("function_call"); - } - } writer.WritePropertyName("role"u8); - writer.WriteStringValue(Role); - if (Optional.IsCollectionDefined(Content)) - { - if (Content[0] != null) - { - writer.WritePropertyName("content"u8); - writer.WriteStringValue(Content[0].Text); - } - else - { - writer.WriteNull("content"); - } - } + writer.WriteStringValue(Role.ToSerialString()); + ChatMessageContentPart.WriteCoreContentPartList(Content, writer, options); + writer.WriteOptionalProperty("refusal"u8, Refusal, options); + writer.WriteOptionalProperty("name"u8, ParticipantName, options); + writer.WriteOptionalCollection("tool_calls"u8, ToolCalls, options); + writer.WriteOptionalProperty("function_call"u8, FunctionCall, options); writer.WriteSerializedAdditionalRawData(SerializedAdditionalRawData, options); writer.WriteEndObject(); } diff --git a/src/Custom/Chat/AssistantChatMessage.cs b/src/Custom/Chat/AssistantChatMessage.cs index 0549fcd2c..46928d9a4 100644 --- a/src/Custom/Chat/AssistantChatMessage.cs +++ b/src/Custom/Chat/AssistantChatMessage.cs @@ -11,16 +11,31 @@ namespace OpenAI.Chat; [CodeGenModel("ChatCompletionRequestAssistantMessage")] public partial class AssistantChatMessage : ChatMessage { - // CUSTOM: Made internal. - /// Initializes a new instance of . - internal AssistantChatMessage() + /// + /// Creates a new instance of using a collection of content items. + /// For assistant messages, this can be one or more of type text or exactly one of type refusal. + /// + /// + /// The collection of content items associated with the message. + /// + public AssistantChatMessage(IEnumerable contentParts) + : base(ChatMessageRole.Assistant, contentParts) { + Argument.AssertNotNullOrEmpty(contentParts, nameof(contentParts)); } - // Assistant messages may present ONE OF: - // - Ordinary text content without tools or a function, in which case the content is required. - // - A list of tool calls, together with optional text content - // - A function call, together with optional text content + /// + /// Creates a new instance of using a collection of content items. + /// For assistant messages, this can be one or more of type text or exactly one of type refusal. + /// + /// + /// The collection of text and image content items associated with the message. + /// + public AssistantChatMessage(params ChatMessageContentPart[] contentParts) + : base(ChatMessageRole.Assistant, contentParts) + { + Argument.AssertNotNullOrEmpty(contentParts, nameof(contentParts)); + } /// /// Creates a new instance of that represents ordinary text content and @@ -28,12 +43,9 @@ internal AssistantChatMessage() /// /// The text content of the message. public AssistantChatMessage(string content) + : base(ChatMessageRole.Assistant, content) { Argument.AssertNotNull(content, nameof(content)); - - Role = "assistant"; - Content = [ChatMessageContentPart.CreateTextMessageContentPart(content)]; - ToolCalls = new ChangeTrackingList(); } /// @@ -43,14 +55,14 @@ public AssistantChatMessage(string content) /// The tool_calls made by the model. /// Optional text content associated with the message. public AssistantChatMessage(IEnumerable toolCalls, string content = null) + : base(ChatMessageRole.Assistant, content) { Argument.AssertNotNull(toolCalls, nameof(toolCalls)); - Role = "assistant"; - Content = (content == null) - ? new ChangeTrackingList() - : [ChatMessageContentPart.CreateTextMessageContentPart(content)]; - ToolCalls = new List(toolCalls); + foreach (ChatToolCall toolCall in toolCalls) + { + ToolCalls.Add(toolCall); + } } /// @@ -60,14 +72,10 @@ public AssistantChatMessage(IEnumerable toolCalls, string content /// The function_call made by the model. /// Optional text content associated with the message. public AssistantChatMessage(ChatFunctionCall functionCall, string content = null) + : base(ChatMessageRole.Assistant, content) { Argument.AssertNotNull(functionCall, nameof(functionCall)); - Role = "assistant"; - Content = (content == null) - ? new ChangeTrackingList() - : [ChatMessageContentPart.CreateTextMessageContentPart(content)]; - ToolCalls = new ChangeTrackingList(); FunctionCall = functionCall; } @@ -86,6 +94,7 @@ public AssistantChatMessage(ChatFunctionCall functionCall, string content = null /// The role of the provided chat completion response was not . /// public AssistantChatMessage(ChatCompletion chatCompletion) + : base(ChatMessageRole.Assistant, chatCompletion?.Content) { Argument.AssertNotNull(chatCompletion, nameof(chatCompletion)); @@ -94,10 +103,12 @@ public AssistantChatMessage(ChatCompletion chatCompletion) throw new NotSupportedException($"Cannot instantiate an {nameof(AssistantChatMessage)} from a {nameof(ChatCompletion)} with role: {chatCompletion.Role}."); } - Role = "assistant"; - Content = (IList)chatCompletion.Content; - ToolCalls = (IList)chatCompletion.ToolCalls; + Refusal = chatCompletion.Refusal; FunctionCall = chatCompletion.FunctionCall; + foreach (ChatToolCall toolCall in chatCompletion.ToolCalls ?? []) + { + ToolCalls.Add(toolCall); + } } // CUSTOM: Renamed. @@ -107,4 +118,11 @@ public AssistantChatMessage(ChatCompletion chatCompletion) /// [CodeGenMember("Name")] public string ParticipantName { get; set; } + + // CUSTOM: Common initialization for input model collection property. + [CodeGenMember("ToolCalls")] + public IList ToolCalls { get; } = new ChangeTrackingList(); + + // CUSTOM: Made internal. + internal AssistantChatMessage() { } } \ No newline at end of file diff --git a/src/Custom/Chat/ChatCompletion.cs b/src/Custom/Chat/ChatCompletion.cs index 0efd2e53f..7f0681f3f 100644 --- a/src/Custom/Chat/ChatCompletion.cs +++ b/src/Custom/Chat/ChatCompletion.cs @@ -1,4 +1,5 @@ using System; +using System.ClientModel.Primitives; using System.Collections.Generic; namespace OpenAI.Chat; @@ -7,6 +8,7 @@ namespace OpenAI.Chat; public partial class ChatCompletion { private IReadOnlyList _contentTokenLogProbabilities; + private IReadOnlyList _refusalTokenLogProbabilities; // CUSTOM: Made private. This property does not add value in the context of a strongly-typed class. /// The object type, which is always `chat.completion`. @@ -40,6 +42,11 @@ public partial class ChatCompletion ? Choices[0].Logprobs.Content : _contentTokenLogProbabilities ??= new ChangeTrackingList(); + // CUSTOM: Flattened refusal logprobs property. + public IReadOnlyList RefusalTokenLogProbabilities => (Choices[0]?.Logprobs != null) + ? Choices[0].Logprobs.Refusal + : _refusalTokenLogProbabilities ??= new ChangeTrackingList(); + // CUSTOM: Flattened choice message property. /// /// The role of the author of this message. @@ -61,9 +68,18 @@ public partial class ChatCompletion // CUSTOM: Flattened choice message property. public ChatFunctionCall FunctionCall => Choices[0].Message.FunctionCall; + // CUSTOM: Flattened choice message property. + public string Refusal => Choices[0].Message.Refusal; + /// /// Returns text representation of the first part of the first choice. /// /// - public override string ToString() => Content[0].Text; + public override string ToString() => Content.Count > 0 ? Content[0].Text + : ToolCalls.Count > 0 ? ModelReaderWriter.Write(ToolCalls[0]).ToString() + : null; + + // CUSTOM: Made internal. + [CodeGenMember("ServiceTier")] + internal InternalCreateChatCompletionResponseServiceTier? _serviceTier; } diff --git a/src/Custom/Chat/ChatCompletionOptions.cs b/src/Custom/Chat/ChatCompletionOptions.cs index e1d152936..212195db1 100644 --- a/src/Custom/Chat/ChatCompletionOptions.cs +++ b/src/Custom/Chat/ChatCompletionOptions.cs @@ -112,6 +112,23 @@ public ChatCompletionOptions() [CodeGenMember("ParallelToolCalls")] public bool? ParallelToolCallsEnabled { get; set; } + /// + /// An object specifying the format that the model must output. + /// + /// + ///

+ /// Compatible with GPT-4o, GPT-4o mini, GPT-4 Turbo and all GPT-3.5 Turbo models newer than gpt-3.5-turbo-1106. + ///

+ ///

+ /// Learn more in the Structured Outputs guide. + ///

+ ///
+ //[CodeGenMember("ResponseFormat")] + //public ChatResponseFormat ResponseFormat { get; set; } + + [CodeGenMember("ServiceTier")] + internal InternalCreateChatCompletionRequestServiceTier? _serviceTier; + // CUSTOM: Renamed. /// /// A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. diff --git a/src/Custom/Chat/ChatMessage.Serialization.cs b/src/Custom/Chat/ChatMessage.Serialization.cs index 3ad48ee5e..007212010 100644 --- a/src/Custom/Chat/ChatMessage.Serialization.cs +++ b/src/Custom/Chat/ChatMessage.Serialization.cs @@ -19,11 +19,16 @@ internal void SerializeContentValue(Utf8JsonWriter writer, ModelReaderWriterOpti internal static void DeserializeContentValue(JsonProperty property, ref IList content, ModelReaderWriterOptions options = null) { content ??= new ChangeTrackingList(); - if (property.Value.ValueKind == JsonValueKind.String) + + if (property.Value.ValueKind == JsonValueKind.Null) + { + return; + } + else if (property.Value.ValueKind == JsonValueKind.String) { content.Add(ChatMessageContentPart.CreateTextMessageContentPart(property.Value.GetString())); } - else + else if (property.Value.ValueKind == JsonValueKind.Array) { foreach (var item in property.Value.EnumerateArray()) { diff --git a/src/Custom/Chat/ChatMessage.cs b/src/Custom/Chat/ChatMessage.cs index 99fca4302..7278d5172 100644 --- a/src/Custom/Chat/ChatMessage.cs +++ b/src/Custom/Chat/ChatMessage.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; namespace OpenAI.Chat; @@ -55,40 +56,75 @@ namespace OpenAI.Chat; [CodeGenSerialization(nameof(Content), SerializationValueHook = nameof(SerializeContentValue), DeserializationValueHook = nameof(DeserializeContentValue))] public abstract partial class ChatMessage { + protected internal ChatMessage(ChatMessageRole role, IEnumerable contentParts) + { + Role = role; + foreach (ChatMessageContentPart contentPart in contentParts ?? []) + { + Content.Add(contentPart); + } + } + + protected internal ChatMessage(ChatMessageRole role, string content) + : this(role, content is null ? null : [ChatMessageContentPart.CreateTextMessageContentPart(content)]) + { } + /// /// The content associated with the message. The interpretation of this content will vary depending on the message type. /// - public IList Content { get; protected set; } + public IList Content { get; } = new ChangeTrackingList(); + + // CUSTOM: use strongly-typed role. + [CodeGenMember("Role")] + internal ChatMessageRole Role { get; set; } /// - public static SystemChatMessage CreateSystemMessage(string content) => new SystemChatMessage(content); + public static SystemChatMessage CreateSystemMessage(string content) => new(content); + + /// + public static SystemChatMessage CreateSystemMessage(IEnumerable contentParts) => new(contentParts); + + /// + public static SystemChatMessage CreateSystemMessage(params ChatMessageContentPart[] contentParts) => new(contentParts); /// - public static UserChatMessage CreateUserMessage(string content) => new UserChatMessage(content); + public static UserChatMessage CreateUserMessage(string content) => new(content); /// - public static UserChatMessage CreateUserMessage(IEnumerable contentParts) => new UserChatMessage(contentParts); + public static UserChatMessage CreateUserMessage(IEnumerable contentParts) => new(contentParts); /// - public static UserChatMessage CreateUserMessage(params ChatMessageContentPart[] contentParts) => new UserChatMessage(contentParts); + public static UserChatMessage CreateUserMessage(params ChatMessageContentPart[] contentParts) => new(contentParts); /// - public static AssistantChatMessage CreateAssistantMessage(string content) => new AssistantChatMessage(content); + public static AssistantChatMessage CreateAssistantMessage(string content) => new(content); + + /// + public static AssistantChatMessage CreateAssistantMessage(IEnumerable contentParts) => new(contentParts); + + /// + public static AssistantChatMessage CreateAssistantMessage(params ChatMessageContentPart[] contentParts) => new(contentParts); /// - public static AssistantChatMessage CreateAssistantMessage(IEnumerable toolCalls, string content = null) => new AssistantChatMessage(toolCalls, content); + public static AssistantChatMessage CreateAssistantMessage(IEnumerable toolCalls, string content = null) => new(toolCalls, content); /// - public static AssistantChatMessage CreateAssistantMessage(ChatFunctionCall functionCall, string content = null) => new AssistantChatMessage(functionCall, content); + public static AssistantChatMessage CreateAssistantMessage(ChatFunctionCall functionCall, string content = null) => new(functionCall, content); /// - public static AssistantChatMessage CreateAssistantMessage(ChatCompletion chatCompletion) => new AssistantChatMessage(chatCompletion); + public static AssistantChatMessage CreateAssistantMessage(ChatCompletion chatCompletion) => new(chatCompletion); /// - public static ToolChatMessage CreateToolChatMessage(string toolCallId, string content) => new ToolChatMessage(toolCallId, content); + public static ToolChatMessage CreateToolChatMessage(string toolCallId, string content) => new(toolCallId, content); + + /// + public static ToolChatMessage CreateToolChatMessage(string toolCallId, IEnumerable contentParts) => new(toolCallId, contentParts); + + /// + public static ToolChatMessage CreateToolChatMessage(string toolCallId, params ChatMessageContentPart[] contentParts) => new(toolCallId, contentParts); /// - public static FunctionChatMessage CreateFunctionMessage(string functionName, string content) => new FunctionChatMessage(functionName, content); + public static FunctionChatMessage CreateFunctionMessage(string functionName, string content) => new(functionName, content); /// /// Creates UserChatMessage. diff --git a/src/Custom/Chat/ChatMessageContentPart.Serialization.cs b/src/Custom/Chat/ChatMessageContentPart.Serialization.cs index 42e6ad202..42d75589c 100644 --- a/src/Custom/Chat/ChatMessageContentPart.Serialization.cs +++ b/src/Custom/Chat/ChatMessageContentPart.Serialization.cs @@ -14,18 +14,21 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReader internal static void WriteCoreContentPart(ChatMessageContentPart instance, Utf8JsonWriter writer, ModelReaderWriterOptions options) { writer.WriteStartObject(); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(instance._kind.ToString()); if (instance._kind == ChatMessageContentPartKind.Text) { - writer.WritePropertyName("type"u8); - writer.WriteStringValue(instance._kind.ToString()); writer.WritePropertyName("text"u8); writer.WriteStringValue(instance._text); } + else if (instance._kind == ChatMessageContentPartKind.Refusal) + { + writer.WritePropertyName("refusal"u8); + writer.WriteStringValue(instance._refusal); + } else if (instance._kind == ChatMessageContentPartKind.Image) { - writer.WritePropertyName("type"u8); - writer.WriteStringValue(instance._kind.ToString()); writer.WritePropertyName("image_url"u8); writer.WriteObjectValue(instance._imageUrl, options); } @@ -33,6 +36,29 @@ internal static void WriteCoreContentPart(ChatMessageContentPart instance, Utf8J writer.WriteEndObject(); } + internal static void WriteCoreContentPartList(IList instances, Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + if (!Optional.IsCollectionDefined(instances)) + { + return; + } + + writer.WritePropertyName("content"u8); + if (instances.Count == 1 && !string.IsNullOrEmpty(instances[0].Text)) + { + writer.WriteStringValue(instances[0].Text); + } + else + { + writer.WriteStartArray(); + foreach (var item in instances) + { + writer.WriteObjectValue(item, options); + } + writer.WriteEndArray(); + } + } + internal static ChatMessageContentPart DeserializeChatMessageContentPart(JsonElement element, ModelReaderWriterOptions options = null) { options ??= ModelSerializationExtensions.WireOptions; @@ -44,6 +70,7 @@ internal static ChatMessageContentPart DeserializeChatMessageContentPart(JsonEle string kind = default; string text = default; + string refusal = default; InternalChatCompletionRequestMessageContentPartImageImageUrl imageUrl = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); @@ -64,12 +91,17 @@ internal static ChatMessageContentPart DeserializeChatMessageContentPart(JsonEle imageUrl = InternalChatCompletionRequestMessageContentPartImageImageUrl.DeserializeInternalChatCompletionRequestMessageContentPartImageImageUrl(property.Value, options); continue; } + if (property.NameEquals("refusal"u8)) + { + refusal = property.Value.GetString(); + continue; + } if (true) { rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); } } serializedAdditionalRawData = rawDataDictionary; - return new ChatMessageContentPart(kind, text, imageUrl, serializedAdditionalRawData); + return new ChatMessageContentPart(kind, text, refusal, imageUrl, serializedAdditionalRawData); } } diff --git a/src/Custom/Chat/ChatMessageContentPart.cs b/src/Custom/Chat/ChatMessageContentPart.cs index 603008327..2267b7877 100644 --- a/src/Custom/Chat/ChatMessageContentPart.cs +++ b/src/Custom/Chat/ChatMessageContentPart.cs @@ -12,6 +12,7 @@ public partial class ChatMessageContentPart { private readonly ChatMessageContentPartKind _kind; private readonly string _text; + private readonly string _refusal; private readonly InternalChatCompletionRequestMessageContentPartImageImageUrl _imageUrl; private readonly string _dataUri; @@ -51,10 +52,11 @@ internal ChatMessageContentPart(BinaryData imageBytes, string imageBytesMediaTyp /// The text. /// The image URI. /// Keeps track of any properties unknown to the library. - internal ChatMessageContentPart(string kind, string text, InternalChatCompletionRequestMessageContentPartImageImageUrl imageUrl, IDictionary serializedAdditionalRawData) + internal ChatMessageContentPart(string kind, string text, string refusal, InternalChatCompletionRequestMessageContentPartImageImageUrl imageUrl, IDictionary serializedAdditionalRawData) { _kind = new ChatMessageContentPartKind(kind); _text = text; + _refusal = refusal; _imageUrl = imageUrl; SerializedAdditionalRawData = serializedAdditionalRawData; } @@ -69,6 +71,11 @@ internal ChatMessageContentPart(string kind, string text, InternalChatCompletion /// public string Text => _text; + /// + /// The refusal message from the assistant. + /// + public string Refusal => _refusal; + /// /// The image URI content. /// @@ -101,6 +108,23 @@ public static ChatMessageContentPart CreateTextMessageContentPart(string text) return new(text); } + /// + /// Creates a new instance of that encapsulates an assistant refusal message. + /// + /// The refusal message from the assistant. + /// A new instance of . + public static ChatMessageContentPart CreateRefusalMessageContentPart(string refusal) + { + Argument.AssertNotNull(refusal, nameof(refusal)); + + return new ChatMessageContentPart( + ChatMessageContentPartKind.Refusal.ToString(), + text: null, + refusal: refusal, + imageUrl: null, + serializedAdditionalRawData: null); + } + /// /// Creates a new instance of that encapsulates image content obtained from /// an internet location that will be accessible to the model when evaluating a message with this content. diff --git a/src/Custom/Chat/ChatMessageContentPartKind.cs b/src/Custom/Chat/ChatMessageContentPartKind.cs index ce5a097ed..73ba771ad 100644 --- a/src/Custom/Chat/ChatMessageContentPartKind.cs +++ b/src/Custom/Chat/ChatMessageContentPartKind.cs @@ -18,10 +18,13 @@ public ChatMessageContentPartKind(string value) } private const string TextValue = "text"; + private const string RefusalValue = "refusal"; private const string ImageValue = "image_url"; /// Text. public static ChatMessageContentPartKind Text { get; } = new ChatMessageContentPartKind(TextValue); + /// Refusal. + public static ChatMessageContentPartKind Refusal { get; } = new(RefusalValue); /// Image. public static ChatMessageContentPartKind Image { get; } = new ChatMessageContentPartKind(ImageValue); diff --git a/src/Custom/Chat/ChatResponseFormat.cs b/src/Custom/Chat/ChatResponseFormat.cs index 96ec8b837..2b7feb1b8 100644 --- a/src/Custom/Chat/ChatResponseFormat.cs +++ b/src/Custom/Chat/ChatResponseFormat.cs @@ -1,45 +1,82 @@ -using OpenAI.Models; +using OpenAI.Internal; +using System; +using System.ClientModel.Primitives; +using System.ComponentModel; namespace OpenAI.Chat; -/// -/// Represents a requested response_format for the model to use, enabling "JSON mode" for guaranteed valid output. -/// -/// -/// Important: when using JSON mode, the model must also be instructed to produce JSON via a -/// system or user message. -/// -/// Without this paired, message-based accompaniment, the model may generate an unending stream of whitespace until the -/// generation reaches the token limit, resulting in a long-running and seemingly "stuck" request. -/// -/// -/// Also note that the message content may be partially cut off if finish_reason is length, which -/// indicates that the generation exceeded max_tokens or the conversation exceeded the max context length for -/// the model. -/// -/// -[CodeGenModel("CreateChatCompletionRequestResponseFormat")] -public partial class ChatResponseFormat +[CodeGenModel("ChatResponseFormat")] +public abstract partial class ChatResponseFormat : IEquatable { - // CUSTOM: Made internal. + public static ChatResponseFormat Text { get; } = new InternalChatResponseFormatText(); + public static ChatResponseFormat JsonObject { get; } = new InternalChatResponseFormatJsonObject(); - /// Must be one of `text` or `json_object`. - [CodeGenMember("Type")] - internal InternalCreateChatCompletionRequestResponseFormatType? Type { get; set; } + public static ChatResponseFormat CreateTextFormat() => new InternalChatResponseFormatText(); + public static ChatResponseFormat CreateJsonObjectFormat() => new InternalChatResponseFormatJsonObject(); + public static ChatResponseFormat CreateJsonSchemaFormat( + string name, + BinaryData jsonSchema, + string description = null, + bool? strictSchemaEnabled = null) + { + Argument.AssertNotNullOrEmpty(name, nameof(name)); + Argument.AssertNotNull(jsonSchema, nameof(jsonSchema)); + + InternalResponseFormatJsonSchemaJsonSchema internalSchema = new( + description, + name, + jsonSchema, + strictSchemaEnabled, + null); + return new InternalChatResponseFormatJsonSchema(internalSchema); + } + + [EditorBrowsable(EditorBrowsableState.Never)] + public static bool operator ==(ChatResponseFormat first, ChatResponseFormat second) + { + if (first is null) + { + return second is null; + } + return first.Equals(second); + } - // CUSTOM: Made internal. - /// Initializes a new instance of . - internal ChatResponseFormat() + [EditorBrowsable(EditorBrowsableState.Never)] + public static bool operator !=(ChatResponseFormat first, ChatResponseFormat second) + => !(first == second); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) { + return (this as IEquatable).Equals(obj as ChatResponseFormat) + || ToString().Equals(obj?.ToString()); } - internal ChatResponseFormat(InternalCreateChatCompletionRequestResponseFormatType? type) + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => ToString().GetHashCode(); + + [EditorBrowsable(EditorBrowsableState.Never)] + bool IEquatable.Equals(ChatResponseFormat other) { - Type = type; + if (other is null) + { + return false; + } + + if (Object.ReferenceEquals(this, other)) + { + return true; + } + + return (this is InternalChatResponseFormatText && other is InternalChatResponseFormatText) + || (this is InternalChatResponseFormatJsonObject && other is InternalChatResponseFormatJsonObject) + || (this is InternalChatResponseFormatJsonSchema thisJsonSchema + && other is InternalChatResponseFormatJsonSchema otherJsonSchema + && thisJsonSchema.JsonSchema.Name.Equals(otherJsonSchema.JsonSchema.Name)); } - /// text. - public static ChatResponseFormat Text { get; } = new ChatResponseFormat(InternalCreateChatCompletionRequestResponseFormatType.Text); - /// json_object. - public static ChatResponseFormat JsonObject { get; } = new ChatResponseFormat(InternalCreateChatCompletionRequestResponseFormatType.JsonObject); + public override string ToString() + { + return ModelReaderWriter.Write(this).ToString(); + } } \ No newline at end of file diff --git a/src/Custom/Chat/ChatTool.cs b/src/Custom/Chat/ChatTool.cs index eab0ec3b4..f1fc403ad 100644 --- a/src/Custom/Chat/ChatTool.cs +++ b/src/Custom/Chat/ChatTool.cs @@ -68,6 +68,8 @@ internal ChatTool(InternalFunctionDefinition function) /// public BinaryData FunctionParameters => Function?.Parameters; + public bool? StrictParameterSchemaEnabled => Function?.Strict; + // CUSTOM: Added custom constructor. /// /// Creates a new instance of . @@ -75,14 +77,15 @@ internal ChatTool(InternalFunctionDefinition function) /// The name of the function. /// The description of the function. /// The parameters into the function, in JSON Schema format. - public static ChatTool CreateFunctionTool(string functionName, string functionDescription = null, BinaryData functionParameters = null) + public static ChatTool CreateFunctionTool(string functionName, string functionDescription = null, BinaryData functionParameters = null, bool? strictParameterSchemaEnabled = null) { Argument.AssertNotNull(functionName, nameof(functionName)); InternalFunctionDefinition function = new(functionName) { Description = functionDescription, - Parameters = functionParameters + Parameters = functionParameters, + Strict = strictParameterSchemaEnabled, }; return new(function); diff --git a/src/Custom/Chat/FunctionChatMessage.Serialization.cs b/src/Custom/Chat/FunctionChatMessage.Serialization.cs index cb46e2760..0bf7c4b18 100644 --- a/src/Custom/Chat/FunctionChatMessage.Serialization.cs +++ b/src/Custom/Chat/FunctionChatMessage.Serialization.cs @@ -19,68 +19,16 @@ internal static void SerializeFunctionChatMessage(FunctionChatMessage instance, protected override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { writer.WriteStartObject(); + writer.WritePropertyName("role"u8); + writer.WriteStringValue(Role.ToSerialString()); writer.WritePropertyName("name"u8); writer.WriteStringValue(FunctionName); - writer.WritePropertyName("role"u8); - writer.WriteStringValue(Role); if (Optional.IsCollectionDefined(Content)) { - if (Content[0] != null) - { - writer.WritePropertyName("content"u8); - writer.WriteStringValue(Content[0].Text); - } - else - { - writer.WriteNull("content"); - } + writer.WritePropertyName("content"u8); + writer.WriteStringValue(Content?[0]?.Text); } writer.WriteSerializedAdditionalRawData(SerializedAdditionalRawData, options); writer.WriteEndObject(); } - - internal static FunctionChatMessage DeserializeFunctionChatMessage(JsonElement element, ModelReaderWriterOptions options = null) - { - options ??= ModelSerializationExtensions.WireOptions; - - if (element.ValueKind == JsonValueKind.Null) - { - return null; - } - string name = default; - string role = default; - IList content = default; - IDictionary serializedAdditionalRawData = default; - Dictionary rawDataDictionary = new Dictionary(); - foreach (var property in element.EnumerateObject()) - { - if (property.NameEquals("name"u8)) - { - name = property.Value.GetString(); - continue; - } - if (property.NameEquals("role"u8)) - { - role = property.Value.GetString(); - continue; - } - if (property.NameEquals("content"u8)) - { - if (property.Value.ValueKind == JsonValueKind.Null) - { - continue; - } - List array = new List(); - array.Add(ChatMessageContentPart.CreateTextMessageContentPart(property.Value.GetString())); - content = array; - continue; - } - if (true) - { - rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); - } - } - serializedAdditionalRawData = rawDataDictionary; - return new FunctionChatMessage(role, content ?? new ChangeTrackingList(), serializedAdditionalRawData, name); - } } diff --git a/src/Custom/Chat/FunctionChatMessage.cs b/src/Custom/Chat/FunctionChatMessage.cs index 7e03f2d95..10468f427 100644 --- a/src/Custom/Chat/FunctionChatMessage.cs +++ b/src/Custom/Chat/FunctionChatMessage.cs @@ -23,14 +23,11 @@ public partial class FunctionChatMessage : ChatMessage /// restriction (e.g. JSON) imposed on this content. /// public FunctionChatMessage(string functionName, string content = null) + : base(ChatMessageRole.Function, content) { Argument.AssertNotNull(functionName, nameof(functionName)); - Role = "function"; FunctionName = functionName; - Content = (content == null) - ? new ChangeTrackingList() - : [ChatMessageContentPart.CreateTextMessageContentPart(content)]; } // CUSTOM: Renamed. diff --git a/src/Custom/Chat/Internal/GeneratorStubs.cs b/src/Custom/Chat/Internal/GeneratorStubs.cs index 5288b2600..f52ceaa79 100644 --- a/src/Custom/Chat/Internal/GeneratorStubs.cs +++ b/src/Custom/Chat/Internal/GeneratorStubs.cs @@ -60,9 +60,6 @@ internal readonly partial struct InternalCreateChatCompletionFunctionResponseObj [CodeGenModel("CreateChatCompletionRequestModel")] internal readonly partial struct InternalCreateChatCompletionRequestModel { } -[CodeGenModel("CreateChatCompletionRequestResponseFormatType")] -internal readonly partial struct InternalCreateChatCompletionRequestResponseFormatType { } - [CodeGenModel("CreateChatCompletionRequestToolChoice")] internal readonly partial struct InternalCreateChatCompletionRequestToolChoice { } @@ -93,4 +90,12 @@ internal partial class InternalCreateChatCompletionStreamResponseUsage { } [CodeGenModel("FunctionParameters")] internal partial class InternalFunctionParameters { } - +[CodeGenModel("ChatResponseFormatText")] internal partial class InternalChatResponseFormatText { } +[CodeGenModel("ChatResponseFormatJsonObject")] internal partial class InternalChatResponseFormatJsonObject { } +[CodeGenModel("ChatResponseFormatJsonSchema")] internal partial class InternalChatResponseFormatJsonSchema { } +[CodeGenModel("UnknownChatResponseFormat")] internal partial class InternalUnknownChatResponseFormat { } +[CodeGenModel("ChatCompletionRequestMessageContentPartRefusal")] internal partial class InternalChatCompletionRequestMessageContentPartRefusal { } +[CodeGenModel("ChatCompletionRequestMessageContentPartRefusalType")] internal readonly partial struct InternalChatCompletionRequestMessageContentPartRefusalType { } +[CodeGenModel("CreateChatCompletionRequestServiceTier")] internal readonly partial struct InternalCreateChatCompletionRequestServiceTier { } +[CodeGenModel("CreateChatCompletionResponseServiceTier")] internal readonly partial struct InternalCreateChatCompletionResponseServiceTier { } +[CodeGenModel("CreateChatCompletionStreamResponseServiceTier")] internal readonly partial struct InternalCreateChatCompletionStreamResponseServiceTier { } diff --git a/src/Custom/Chat/Internal/InternalChatCompletionResponseMessage.Serialization.cs b/src/Custom/Chat/Internal/InternalChatCompletionResponseMessage.Serialization.cs index c8fd80d8e..4ed0cadda 100644 --- a/src/Custom/Chat/Internal/InternalChatCompletionResponseMessage.Serialization.cs +++ b/src/Custom/Chat/Internal/InternalChatCompletionResponseMessage.Serialization.cs @@ -69,6 +69,7 @@ internal static InternalChatCompletionResponseMessage DeserializeInternalChatCom return null; } IReadOnlyList content = default; + string refusal = default; IReadOnlyList toolCalls = default; ChatMessageRole role = default; ChatFunctionCall functionCall = default; @@ -87,6 +88,15 @@ internal static InternalChatCompletionResponseMessage DeserializeInternalChatCom content = array; continue; } + if (property.NameEquals("refusal"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + refusal = property.Value.GetString(); + continue; + } if (property.NameEquals("tool_calls"u8)) { if (property.Value.ValueKind == JsonValueKind.Null) @@ -121,6 +131,6 @@ internal static InternalChatCompletionResponseMessage DeserializeInternalChatCom } } serializedAdditionalRawData = rawDataDictionary; - return new InternalChatCompletionResponseMessage(content ?? new ChangeTrackingList(), toolCalls ?? new ChangeTrackingList(), role, functionCall, serializedAdditionalRawData); + return new InternalChatCompletionResponseMessage(content ?? new ChangeTrackingList(), refusal, toolCalls ?? new ChangeTrackingList(), role, functionCall, serializedAdditionalRawData); } } diff --git a/src/Custom/Chat/Internal/InternalChatCompletionStreamResponseDelta.Serialization.cs b/src/Custom/Chat/Internal/InternalChatCompletionStreamResponseDelta.Serialization.cs index 0a4fa1ea1..0239d2571 100644 --- a/src/Custom/Chat/Internal/InternalChatCompletionStreamResponseDelta.Serialization.cs +++ b/src/Custom/Chat/Internal/InternalChatCompletionStreamResponseDelta.Serialization.cs @@ -75,6 +75,7 @@ internal static InternalChatCompletionStreamResponseDelta DeserializeInternalCha StreamingChatFunctionCallUpdate functionCall = default; IReadOnlyList toolCalls = default; ChatMessageRole? role = default; + string refusal = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) @@ -122,12 +123,21 @@ internal static InternalChatCompletionStreamResponseDelta DeserializeInternalCha role = property.Value.GetString().ToChatMessageRole(); continue; } + if (property.NameEquals("refusal"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + refusal = property.Value.GetString(); + continue; + } if (true) { rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); } } serializedAdditionalRawData = rawDataDictionary; - return new InternalChatCompletionStreamResponseDelta(content ?? new ChangeTrackingList(), functionCall, toolCalls ?? new ChangeTrackingList(), role, serializedAdditionalRawData); + return new InternalChatCompletionStreamResponseDelta(content ?? new ChangeTrackingList(), functionCall, toolCalls ?? new ChangeTrackingList(), role, refusal, serializedAdditionalRawData); } } diff --git a/src/Custom/Chat/Internal/UnknownChatMessage.Serialization.cs b/src/Custom/Chat/Internal/UnknownChatMessage.Serialization.cs index b3eca176b..02b8d2096 100644 --- a/src/Custom/Chat/Internal/UnknownChatMessage.Serialization.cs +++ b/src/Custom/Chat/Internal/UnknownChatMessage.Serialization.cs @@ -20,17 +20,8 @@ protected override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOption { writer.WriteStartObject(); writer.WritePropertyName("role"u8); - writer.WriteStringValue(Role); - if (Optional.IsCollectionDefined(Content)) - { - writer.WritePropertyName("content"u8); - writer.WriteStartArray(); - foreach (var item in Content) - { - writer.WriteObjectValue(item, options); - } - writer.WriteEndArray(); - } + writer.WriteStringValue(Role.ToSerialString()); + ChatMessageContentPart.WriteCoreContentPartList(Content, writer, options); writer.WriteSerializedAdditionalRawData(SerializedAdditionalRawData, options); writer.WriteEndObject(); } @@ -43,7 +34,7 @@ internal static UnknownChatMessage DeserializeUnknownChatMessage(JsonElement ele { return null; } - string role = "Unknown"; + ChatMessageRole? role = null; IList content = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); @@ -51,7 +42,7 @@ internal static UnknownChatMessage DeserializeUnknownChatMessage(JsonElement ele { if (property.NameEquals("role"u8)) { - role = property.Value.GetString(); + role = property.Value.GetString().ToChatMessageRole(); continue; } if (property.NameEquals("content"u8)) @@ -74,6 +65,6 @@ internal static UnknownChatMessage DeserializeUnknownChatMessage(JsonElement ele } } serializedAdditionalRawData = rawDataDictionary; - return new UnknownChatMessage(role, content ?? new ChangeTrackingList(), serializedAdditionalRawData); + return new UnknownChatMessage(role.Value, content ?? new ChangeTrackingList(), serializedAdditionalRawData); } } diff --git a/src/Custom/Chat/StreamingChatCompletionUpdate.cs b/src/Custom/Chat/StreamingChatCompletionUpdate.cs index 84c2f9b39..2ce62bd84 100644 --- a/src/Custom/Chat/StreamingChatCompletionUpdate.cs +++ b/src/Custom/Chat/StreamingChatCompletionUpdate.cs @@ -13,6 +13,7 @@ public partial class StreamingChatCompletionUpdate private IReadOnlyList _contentUpdate; private IReadOnlyList _toolCallUpdates; private IReadOnlyList _contentTokenLogProbabilities; + private IReadOnlyList _refusalTokenLogProbabilities; // CUSTOM: // - Made private. This property does not add value in the context of a strongly-typed class. @@ -42,6 +43,10 @@ public partial class StreamingChatCompletionUpdate [CodeGenMember("Usage")] public ChatTokenUsage Usage { get; } + // CUSTOM: Made internal. + [CodeGenMember("ServiceTier")] + internal InternalCreateChatCompletionStreamResponseServiceTier? ServiceTier { get; } + // CUSTOM: Flattened choice property. /// /// Gets the associated with this update. @@ -58,6 +63,11 @@ public partial class StreamingChatCompletionUpdate ? Choices[0].Logprobs.Content : _contentTokenLogProbabilities ??= new ChangeTrackingList(); + // CUSTOM: Flattened refusal logprobs property. + public IReadOnlyList RefusalTokenLogProbabilities => (Choices.Count > 0 && Choices[0].Logprobs != null) + ? Choices[0].Logprobs.Refusal + : _refusalTokenLogProbabilities ??= new ChangeTrackingList(); + // CUSTOM: Flattened choice delta property. /// /// Gets the content fragment associated with this update. @@ -99,6 +109,11 @@ public partial class StreamingChatCompletionUpdate public StreamingChatFunctionCallUpdate FunctionCallUpdate => (Choices.Count > 0) ? Choices[0].Delta.FunctionCall : null; + + // CUSTOM: Flattened choice delta property. + public string RefusalUpdate => (Choices.Count > 0) + ? Choices[0].Delta?.Refusal + : null; internal static List DeserializeStreamingChatCompletionUpdates(JsonElement element) { diff --git a/src/Custom/Chat/SystemChatMessage.Serialization.cs b/src/Custom/Chat/SystemChatMessage.Serialization.cs index 6e98120cb..b1063b03f 100644 --- a/src/Custom/Chat/SystemChatMessage.Serialization.cs +++ b/src/Custom/Chat/SystemChatMessage.Serialization.cs @@ -17,18 +17,10 @@ internal static void SerializeSystemChatMessage(SystemChatMessage instance, Utf8 protected override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { writer.WriteStartObject(); - if (Optional.IsDefined(ParticipantName)) - { - writer.WritePropertyName("name"u8); - writer.WriteStringValue(ParticipantName); - } writer.WritePropertyName("role"u8); - writer.WriteStringValue(Role); - if (Optional.IsCollectionDefined(Content)) - { - writer.WritePropertyName("content"u8); - writer.WriteStringValue(Content[0].Text); - } + writer.WriteStringValue(Role.ToSerialString()); + ChatMessageContentPart.WriteCoreContentPartList(Content, writer, options); + writer.WriteOptionalProperty("name"u8, ParticipantName, options); writer.WriteSerializedAdditionalRawData(SerializedAdditionalRawData, options); writer.WriteEndObject(); } diff --git a/src/Custom/Chat/SystemChatMessage.cs b/src/Custom/Chat/SystemChatMessage.cs index 21de09d3f..ed991f4d5 100644 --- a/src/Custom/Chat/SystemChatMessage.cs +++ b/src/Custom/Chat/SystemChatMessage.cs @@ -9,21 +9,40 @@ namespace OpenAI.Chat; /// restrictions for a model-based assistant. /// [CodeGenModel("ChatCompletionRequestSystemMessage")] -[CodeGenSuppress("SystemChatMessage", typeof(IEnumerable))] -// [CodeGenSuppress("SystemChatMessage", typeof(string), typeof(IList), typeof(IDictionary), typeof(string))] public partial class SystemChatMessage : ChatMessage { /// - /// Creates a new instance of . + /// Creates a new instance of using a collection of content items. + /// For system messages, these can only be of type text. /// - /// The system message text that guides the model's behavior. + /// + /// The collection of content items associated with the message. + /// + public SystemChatMessage(IEnumerable contentParts) + : base(ChatMessageRole.System, contentParts) + { } + + /// + /// Creates a new instance of using a collection of content items. + /// For system messages, these can only be of type text. + /// + /// + /// The collection of content items associated with the message. + /// + public SystemChatMessage(params ChatMessageContentPart[] contentParts) + : base(ChatMessageRole.System, contentParts) + { + Argument.AssertNotNullOrEmpty(contentParts, nameof(contentParts)); + } + + /// + /// Creates a new instance of with a single item of text content. + /// + /// The text content of the message. public SystemChatMessage(string content) + : base(ChatMessageRole.System, content) { Argument.AssertNotNull(content, nameof(content)); - - Role = "system"; - Content = new ChangeTrackingList( - (IList)[ChatMessageContentPart.CreateTextMessageContentPart(content)]); } /// diff --git a/src/Custom/Chat/ToolChatMessage.Serialization.cs b/src/Custom/Chat/ToolChatMessage.Serialization.cs index a32e807f8..9eb64d17e 100644 --- a/src/Custom/Chat/ToolChatMessage.Serialization.cs +++ b/src/Custom/Chat/ToolChatMessage.Serialization.cs @@ -1,6 +1,4 @@ -using System; using System.ClientModel.Primitives; -using System.Collections.Generic; using System.Text.Json; namespace OpenAI.Chat; @@ -17,15 +15,11 @@ internal static void SerializeToolChatMessage(ToolChatMessage instance, Utf8Json protected override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { writer.WriteStartObject(); + writer.WritePropertyName("role"u8); + writer.WriteStringValue(Role.ToSerialString()); writer.WritePropertyName("tool_call_id"u8); writer.WriteStringValue(ToolCallId); - writer.WritePropertyName("role"u8); - writer.WriteStringValue(Role); - if (Optional.IsCollectionDefined(Content)) - { - writer.WritePropertyName("content"u8); - writer.WriteStringValue(Content[0].Text); - } + ChatMessageContentPart.WriteCoreContentPartList(Content, writer, options); writer.WriteSerializedAdditionalRawData(SerializedAdditionalRawData, options); writer.WriteEndObject(); } diff --git a/src/Custom/Chat/ToolChatMessage.cs b/src/Custom/Chat/ToolChatMessage.cs index 92936ba29..c85f8efed 100644 --- a/src/Custom/Chat/ToolChatMessage.cs +++ b/src/Custom/Chat/ToolChatMessage.cs @@ -24,21 +24,56 @@ namespace OpenAI.Chat; public partial class ToolChatMessage : ChatMessage { /// - /// Creates a new instance of . + /// Creates a new instance of using a collection of content items. + /// For tool messages, these can only be of type text. /// - /// The id correlating to a made by the model. - /// - /// The textual content, produced by the defined tool in response to the correlated , - /// that resolves the tool call and allows the logical conversation to continue. No format restrictions (e.g. - /// JSON) are imposed on the content emitted by tools. + /// + /// The ID of the tool call that this message responds to. /// + /// + /// The collection of content items associated with the message. + /// + public ToolChatMessage(string toolCallId, IEnumerable contentParts) + : base(ChatMessageRole.Tool, contentParts) + { + Argument.AssertNotNullOrEmpty(toolCallId, nameof(toolCallId)); + Argument.AssertNotNullOrEmpty(contentParts, nameof(contentParts)); + + ToolCallId = toolCallId; + } + + /// + /// Creates a new instance of using a collection of content items. + /// For tool messages, these can only be of type text. + /// + /// + /// The ID of the tool call that this message responds to. + /// + /// + /// The collection of content items associated with the message. + /// + public ToolChatMessage(string toolCallId, params ChatMessageContentPart[] contentParts) + : base(ChatMessageRole.Tool, contentParts) + { + Argument.AssertNotNullOrEmpty(toolCallId, nameof(toolCallId)); + Argument.AssertNotNullOrEmpty(contentParts, nameof(contentParts)); + + ToolCallId = toolCallId; + } + + /// + /// Creates a new instance of with a single item of text content. + /// + /// + /// The ID of the tool call that this message responds to. + /// + /// The text content of the message. public ToolChatMessage(string toolCallId, string content) + : base(ChatMessageRole.Tool, content) { - Argument.AssertNotNull(toolCallId, nameof(toolCallId)); + Argument.AssertNotNullOrEmpty(toolCallId, nameof(toolCallId)); Argument.AssertNotNull(content, nameof(content)); - Role = "tool"; ToolCallId = toolCallId; - Content = [ChatMessageContentPart.CreateTextMessageContentPart(content)]; } } diff --git a/src/Custom/Chat/UserChatMessage.Serialization.cs b/src/Custom/Chat/UserChatMessage.Serialization.cs index 9dd81b1b8..fcd98a834 100644 --- a/src/Custom/Chat/UserChatMessage.Serialization.cs +++ b/src/Custom/Chat/UserChatMessage.Serialization.cs @@ -17,30 +17,10 @@ internal static void SerializeUserChatMessage(UserChatMessage instance, Utf8Json protected override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { writer.WriteStartObject(); - if (Optional.IsDefined(ParticipantName)) - { - writer.WritePropertyName("name"u8); - writer.WriteStringValue(ParticipantName); - } writer.WritePropertyName("role"u8); - writer.WriteStringValue(Role); - if (Optional.IsCollectionDefined(Content)) - { - writer.WritePropertyName("content"u8); - if (Content.Count == 1 && !string.IsNullOrEmpty(Content[0].Text)) - { - writer.WriteStringValue(Content[0].Text); - } - else - { - writer.WriteStartArray(); - foreach (var item in Content) - { - writer.WriteObjectValue(item, options); - } - writer.WriteEndArray(); - } - } + writer.WriteStringValue(Role.ToSerialString()); + ChatMessageContentPart.WriteCoreContentPartList(Content, writer, options); + writer.WriteOptionalProperty("name"u8, ParticipantName, options); writer.WriteSerializedAdditionalRawData(SerializedAdditionalRawData, options); writer.WriteEndObject(); } diff --git a/src/Custom/Chat/UserChatMessage.cs b/src/Custom/Chat/UserChatMessage.cs index 0b2f3ef5d..18a881117 100644 --- a/src/Custom/Chat/UserChatMessage.cs +++ b/src/Custom/Chat/UserChatMessage.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; namespace OpenAI.Chat; @@ -13,48 +12,40 @@ namespace OpenAI.Chat; [CodeGenSuppress("UserChatMessage", typeof(ReadOnlyMemory))] public partial class UserChatMessage : ChatMessage { - /// - /// Creates a new instance of with ordinary text content. - /// - /// The textual content associated with the message. - public UserChatMessage(string content) - { - Argument.AssertNotNull(content, nameof(content)); - - Role = "user"; - Content = [ChatMessageContentPart.CreateTextMessageContentPart(content)]; - } - /// /// Creates a new instance of using a collection of content items that can /// include text and image information. This content format is currently only applicable to the - /// gpt-4-vision-preview model and will not be accepted by other models. + /// gpt-4o and later models and will not be accepted by older models. /// /// /// The collection of text and image content items associated with the message. /// public UserChatMessage(IEnumerable content) + : base(ChatMessageRole.User, content) { Argument.AssertNotNullOrEmpty(content, nameof(content)); - - Role = "user"; - Content = content.ToList(); } /// /// Creates a new instance of using a collection of content items that can /// include text and image information. This content format is currently only applicable to the - /// gpt-4-vision-preview model and will not be accepted by other models. + /// gpt-4o and later models and will not be accepted by older models. /// /// /// The collection of text and image content items associated with the message. /// public UserChatMessage(params ChatMessageContentPart[] content) - { - Argument.AssertNotNullOrEmpty(content, nameof(content)); + : base(ChatMessageRole.User, content) + { } - Role = "user"; - Content = content.ToList(); + /// + /// Creates a new instance of with ordinary text content. + /// + /// The textual content associated with the message. + public UserChatMessage(string content) + : base(ChatMessageRole.User, content) + { + Argument.AssertNotNull(content, nameof(content)); } // CUSTOM: Rename. diff --git a/src/Custom/Common/Internal/GeneratorStubs.cs b/src/Custom/Common/Internal/GeneratorStubs.cs new file mode 100644 index 000000000..d0c7de7f2 --- /dev/null +++ b/src/Custom/Common/Internal/GeneratorStubs.cs @@ -0,0 +1,11 @@ +using System; + +namespace OpenAI.Internal; + +[CodeGenModel("OmniTypedResponseFormat")] internal partial class InternalOmniTypedResponseFormat { } +[CodeGenModel("ResponseFormatJsonObject")] internal partial class InternalResponseFormatJsonObject { } +[CodeGenModel("ResponseFormatJsonSchema")] internal partial class InternalResponseFormatJsonSchema { } +[CodeGenModel("ResponseFormatJsonSchemaJsonSchema")] internal partial class InternalResponseFormatJsonSchemaJsonSchema { [CodeGenMember("Schema")] public BinaryData Schema { get; set; } } +[CodeGenModel("ResponseFormatJsonSchemaSchema")] internal partial class InternalResponseFormatJsonSchemaSchema { } +[CodeGenModel("ResponseFormatText")] internal partial class InternalResponseFormatText { } +[CodeGenModel("UnknownOmniTypedResponseFormat")] internal partial class InternalUnknownOmniTypedResponseFormat { } diff --git a/src/Custom/Files/FileClient.cs b/src/Custom/Files/FileClient.cs index c18d8c713..1905aa714 100644 --- a/src/Custom/Files/FileClient.cs +++ b/src/Custom/Files/FileClient.cs @@ -25,6 +25,8 @@ namespace OpenAI.Files; [CodeGenSuppress("DownloadFile", typeof(string))] public partial class FileClient { + private InternalUploadsClient _internalUploadsClient; + // CUSTOM: // - Used a custom pipeline. // - Demoted the endpoint parameter to be a property in the options class. @@ -66,6 +68,7 @@ protected internal FileClient(ClientPipeline pipeline, OpenAIClientOptions optio _pipeline = pipeline; _endpoint = OpenAIClient.GetEndpoint(options); + _internalUploadsClient = new(pipeline, options); } /// Uploads a file that can be used across various operations. diff --git a/src/Custom/Files/Internal/GeneratorStubs.cs b/src/Custom/Files/Internal/GeneratorStubs.cs index 617be9be4..e21e8755d 100644 --- a/src/Custom/Files/Internal/GeneratorStubs.cs +++ b/src/Custom/Files/Internal/GeneratorStubs.cs @@ -10,4 +10,14 @@ internal readonly partial struct InternalDeleteFileResponseObject { } internal readonly partial struct InternalListFilesResponseObject { } [CodeGenModel("OpenAIFileObject")] -internal readonly partial struct InternalOpenAIFileObject { } \ No newline at end of file +internal readonly partial struct InternalOpenAIFileObject { } + +[CodeGenModel("AddUploadPartRequest")] internal partial class InternalAddUploadPartRequest { } +[CodeGenModel("CompleteUploadRequest")] internal partial class InternalCompleteUploadRequest { } +[CodeGenModel("CreateUploadRequest")] internal partial class InternalCreateUploadRequest { } +[CodeGenModel("CreateUploadRequestPurpose")] internal readonly partial struct InternalCreateUploadRequestPurpose { } +[CodeGenModel("Upload")] internal partial class InternalUpload { } +[CodeGenModel("UploadObject")] internal readonly partial struct InternalUploadObject { } +[CodeGenModel("UploadPart")] internal partial class InternalUploadPart { } +[CodeGenModel("UploadPartObject")] internal readonly partial struct InternalUploadPartObject { } +[CodeGenModel("UploadStatus")] internal readonly partial struct InternalUploadStatus { } diff --git a/src/Custom/Files/Internal/InternalUploadsClient.cs b/src/Custom/Files/Internal/InternalUploadsClient.cs new file mode 100644 index 000000000..0e9b3915b --- /dev/null +++ b/src/Custom/Files/Internal/InternalUploadsClient.cs @@ -0,0 +1,53 @@ +using System; +using System.ClientModel; +using System.ClientModel.Primitives; + +namespace OpenAI.Files; + +[CodeGenClient("Uploads")] +[CodeGenSuppress("InternalUploadsClient", typeof(ClientPipeline), typeof(ApiKeyCredential), typeof(Uri))] +internal partial class InternalUploadsClient +{ + // CUSTOM: + // - Used a custom pipeline. + // - Demoted the endpoint parameter to be a property in the options class. + /// Initializes a new instance of . + /// The API key to authenticate with the service. + /// is null. + internal InternalUploadsClient(ApiKeyCredential credential) : this(credential, new OpenAIClientOptions()) + { + } + + // CUSTOM: + // - Used a custom pipeline. + // - Demoted the endpoint parameter to be a property in the options class. + /// Initializes a new instance of . + /// The API key to authenticate with the service. + /// The options to configure the client. + /// is null. + internal InternalUploadsClient(ApiKeyCredential credential, OpenAIClientOptions options) + { + Argument.AssertNotNull(credential, nameof(credential)); + options ??= new OpenAIClientOptions(); + + _pipeline = OpenAIClient.CreatePipeline(credential, options); + _endpoint = OpenAIClient.GetEndpoint(options); + } + + // CUSTOM: + // - Used a custom pipeline. + // - Demoted the endpoint parameter to be a property in the options class. + // - Made protected. + /// Initializes a new instance of . + /// The HTTP pipeline to send and receive REST requests and responses. + /// The options to configure the client. + /// is null. + protected internal InternalUploadsClient(ClientPipeline pipeline, OpenAIClientOptions options) + { + Argument.AssertNotNull(pipeline, nameof(pipeline)); + options ??= new OpenAIClientOptions(); + + _pipeline = pipeline; + _endpoint = OpenAIClient.GetEndpoint(options); + } +} diff --git a/src/Custom/FineTuning/Internal/GeneratorStubs.cs b/src/Custom/FineTuning/Internal/GeneratorStubs.cs index cf7b626a9..833c958ff 100644 --- a/src/Custom/FineTuning/Internal/GeneratorStubs.cs +++ b/src/Custom/FineTuning/Internal/GeneratorStubs.cs @@ -87,4 +87,11 @@ internal readonly partial struct InternalListFineTuningJobEventsResponseObject { internal partial class InternalListPaginatedFineTuningJobsResponse { } [CodeGenModel("ListPaginatedFineTuningJobsResponseObject")] -internal readonly partial struct InternalListPaginatedFineTuningJobsResponseObject { } \ No newline at end of file +internal readonly partial struct InternalListPaginatedFineTuningJobsResponseObject { } + +[CodeGenModel("CreateFineTuningJobRequestHyperparametersBatchSizeChoiceEnum")] internal readonly partial struct InternalCreateFineTuningJobRequestHyperparametersBatchSizeChoiceEnum { } +[CodeGenModel("CreateFineTuningJobRequestHyperparametersLearningRateMultiplierChoiceEnum")] internal readonly partial struct InternalCreateFineTuningJobRequestHyperparametersLearningRateMultiplierChoiceEnum { } +[CodeGenModel("CreateFineTuningJobRequestHyperparametersNEpochsChoiceEnum")] internal readonly partial struct InternalCreateFineTuningJobRequestHyperparametersNEpochsChoiceEnum { } +[CodeGenModel("FineTuningJobHyperparametersBatchSizeChoiceEnum")] internal readonly partial struct InternalFineTuningJobHyperparametersBatchSizeChoiceEnum { } +[CodeGenModel("FineTuningJobHyperparametersLearningRateMultiplierChoiceEnum")] internal readonly partial struct InternalFineTuningJobHyperparametersLearningRateMultiplierChoiceEnum { } +[CodeGenModel("FineTuningJobHyperparametersNEpochsChoiceEnum")] internal readonly partial struct InternalFineTuningJobHyperparametersNEpochsChoiceEnum { } diff --git a/src/Custom/OpenAIClient.cs b/src/Custom/OpenAIClient.cs index fa1e8973f..3518a18ee 100644 --- a/src/Custom/OpenAIClient.cs +++ b/src/Custom/OpenAIClient.cs @@ -38,6 +38,7 @@ namespace OpenAI; [CodeGenSuppress("_cachedInternalAssistantMessageClient")] [CodeGenSuppress("_cachedInternalAssistantRunClient")] [CodeGenSuppress("_cachedInternalAssistantThreadClient")] +[CodeGenSuppress("_cachedInternalUploadsClient")] [CodeGenSuppress("_cachedLegacyCompletionClient")] [CodeGenSuppress("_cachedModelClient")] [CodeGenSuppress("_cachedModerationClient")] @@ -53,6 +54,7 @@ namespace OpenAI; [CodeGenSuppress("GetInternalAssistantMessageClientClient")] [CodeGenSuppress("GetInternalAssistantRunClientClient")] [CodeGenSuppress("GetInternalAssistantThreadClientClient")] +[CodeGenSuppress("GetInternalUploadsClientClient")] [CodeGenSuppress("GetLegacyCompletionClientClient")] [CodeGenSuppress("GetModelClientClient")] [CodeGenSuppress("GetModerationClientClient")] diff --git a/src/Generated/InternalUploadsClient.cs b/src/Generated/InternalUploadsClient.cs new file mode 100644 index 000000000..4c6d033aa --- /dev/null +++ b/src/Generated/InternalUploadsClient.cs @@ -0,0 +1,244 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Threading.Tasks; + +namespace OpenAI.Files +{ + // Data plane generated sub-client. + internal partial class InternalUploadsClient + { + private const string AuthorizationHeader = "Authorization"; + private readonly ApiKeyCredential _keyCredential; + private const string AuthorizationApiKeyPrefix = "Bearer"; + private readonly ClientPipeline _pipeline; + private readonly Uri _endpoint; + + public virtual ClientPipeline Pipeline => _pipeline; + + protected InternalUploadsClient() + { + } + + public virtual async Task> CreateUploadAsync(InternalCreateUploadRequest requestBody) + { + Argument.AssertNotNull(requestBody, nameof(requestBody)); + + using BinaryContent content = requestBody.ToBinaryContent(); + ClientResult result = await CreateUploadAsync(content, null).ConfigureAwait(false); + return ClientResult.FromValue(InternalUpload.FromResponse(result.GetRawResponse()), result.GetRawResponse()); + } + + public virtual ClientResult CreateUpload(InternalCreateUploadRequest requestBody) + { + Argument.AssertNotNull(requestBody, nameof(requestBody)); + + using BinaryContent content = requestBody.ToBinaryContent(); + ClientResult result = CreateUpload(content, null); + return ClientResult.FromValue(InternalUpload.FromResponse(result.GetRawResponse()), result.GetRawResponse()); + } + + public virtual async Task CreateUploadAsync(BinaryContent content, RequestOptions options = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreateCreateUploadRequest(content, options); + return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + + public virtual ClientResult CreateUpload(BinaryContent content, RequestOptions options = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreateCreateUploadRequest(content, options); + return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); + } + + public virtual async Task> AddUploadPartAsync(string uploadId, InternalAddUploadPartRequest requestBody) + { + Argument.AssertNotNullOrEmpty(uploadId, nameof(uploadId)); + Argument.AssertNotNull(requestBody, nameof(requestBody)); + + using MultipartFormDataBinaryContent content = requestBody.ToMultipartBinaryBody(); + ClientResult result = await AddUploadPartAsync(uploadId, content, content.ContentType, (RequestOptions)null).ConfigureAwait(false); + return ClientResult.FromValue(InternalUploadPart.FromResponse(result.GetRawResponse()), result.GetRawResponse()); + } + + public virtual ClientResult AddUploadPart(string uploadId, InternalAddUploadPartRequest requestBody) + { + Argument.AssertNotNullOrEmpty(uploadId, nameof(uploadId)); + Argument.AssertNotNull(requestBody, nameof(requestBody)); + + using MultipartFormDataBinaryContent content = requestBody.ToMultipartBinaryBody(); + ClientResult result = AddUploadPart(uploadId, content, content.ContentType, (RequestOptions)null); + return ClientResult.FromValue(InternalUploadPart.FromResponse(result.GetRawResponse()), result.GetRawResponse()); + } + + public virtual async Task AddUploadPartAsync(string uploadId, BinaryContent content, string contentType, RequestOptions options = null) + { + Argument.AssertNotNullOrEmpty(uploadId, nameof(uploadId)); + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreateAddUploadPartRequest(uploadId, content, contentType, options); + return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + + public virtual ClientResult AddUploadPart(string uploadId, BinaryContent content, string contentType, RequestOptions options = null) + { + Argument.AssertNotNullOrEmpty(uploadId, nameof(uploadId)); + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreateAddUploadPartRequest(uploadId, content, contentType, options); + return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); + } + + public virtual async Task> CompleteUploadAsync(string uploadId, InternalCompleteUploadRequest requestBody) + { + Argument.AssertNotNullOrEmpty(uploadId, nameof(uploadId)); + Argument.AssertNotNull(requestBody, nameof(requestBody)); + + using BinaryContent content = requestBody.ToBinaryContent(); + ClientResult result = await CompleteUploadAsync(uploadId, content, null).ConfigureAwait(false); + return ClientResult.FromValue(InternalUpload.FromResponse(result.GetRawResponse()), result.GetRawResponse()); + } + + public virtual ClientResult CompleteUpload(string uploadId, InternalCompleteUploadRequest requestBody) + { + Argument.AssertNotNullOrEmpty(uploadId, nameof(uploadId)); + Argument.AssertNotNull(requestBody, nameof(requestBody)); + + using BinaryContent content = requestBody.ToBinaryContent(); + ClientResult result = CompleteUpload(uploadId, content, null); + return ClientResult.FromValue(InternalUpload.FromResponse(result.GetRawResponse()), result.GetRawResponse()); + } + + public virtual async Task CompleteUploadAsync(string uploadId, BinaryContent content, RequestOptions options = null) + { + Argument.AssertNotNullOrEmpty(uploadId, nameof(uploadId)); + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreateCompleteUploadRequest(uploadId, content, options); + return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + + public virtual ClientResult CompleteUpload(string uploadId, BinaryContent content, RequestOptions options = null) + { + Argument.AssertNotNullOrEmpty(uploadId, nameof(uploadId)); + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreateCompleteUploadRequest(uploadId, content, options); + return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); + } + + public virtual async Task> CancelUploadAsync(string uploadId) + { + Argument.AssertNotNullOrEmpty(uploadId, nameof(uploadId)); + + ClientResult result = await CancelUploadAsync(uploadId, null).ConfigureAwait(false); + return ClientResult.FromValue(InternalUpload.FromResponse(result.GetRawResponse()), result.GetRawResponse()); + } + + public virtual ClientResult CancelUpload(string uploadId) + { + Argument.AssertNotNullOrEmpty(uploadId, nameof(uploadId)); + + ClientResult result = CancelUpload(uploadId, null); + return ClientResult.FromValue(InternalUpload.FromResponse(result.GetRawResponse()), result.GetRawResponse()); + } + + public virtual async Task CancelUploadAsync(string uploadId, RequestOptions options) + { + Argument.AssertNotNullOrEmpty(uploadId, nameof(uploadId)); + + using PipelineMessage message = CreateCancelUploadRequest(uploadId, options); + return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + + public virtual ClientResult CancelUpload(string uploadId, RequestOptions options) + { + Argument.AssertNotNullOrEmpty(uploadId, nameof(uploadId)); + + using PipelineMessage message = CreateCancelUploadRequest(uploadId, options); + return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); + } + + internal PipelineMessage CreateCreateUploadRequest(BinaryContent content, RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier200; + var request = message.Request; + request.Method = "POST"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/uploads", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + request.Headers.Set("Content-Type", "application/json"); + request.Content = content; + message.Apply(options); + return message; + } + + internal PipelineMessage CreateAddUploadPartRequest(string uploadId, BinaryContent content, string contentType, RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier200; + var request = message.Request; + request.Method = "POST"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/uploads/", false); + uri.AppendPath(uploadId, true); + uri.AppendPath("/parts", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + request.Headers.Set("Content-Type", contentType); + request.Content = content; + message.Apply(options); + return message; + } + + internal PipelineMessage CreateCompleteUploadRequest(string uploadId, BinaryContent content, RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier200; + var request = message.Request; + request.Method = "POST"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/uploads/", false); + uri.AppendPath(uploadId, true); + uri.AppendPath("/complete", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + request.Headers.Set("Content-Type", "application/json"); + request.Content = content; + message.Apply(options); + return message; + } + + internal PipelineMessage CreateCancelUploadRequest(string uploadId, RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier200; + var request = message.Request; + request.Method = "POST"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/uploads/", false); + uri.AppendPath(uploadId, true); + uri.AppendPath("/cancel", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + message.Apply(options); + return message; + } + + private static PipelineMessageClassifier _pipelineMessageClassifier200; + private static PipelineMessageClassifier PipelineMessageClassifier200 => _pipelineMessageClassifier200 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 200 }); + } +} diff --git a/src/Generated/Models/AssistantChatMessage.Serialization.cs b/src/Generated/Models/AssistantChatMessage.Serialization.cs index 4695f5fee..89a7d76f5 100644 --- a/src/Generated/Models/AssistantChatMessage.Serialization.cs +++ b/src/Generated/Models/AssistantChatMessage.Serialization.cs @@ -32,15 +32,26 @@ internal static AssistantChatMessage DeserializeAssistantChatMessage(JsonElement { return null; } + string refusal = default; string name = default; IList toolCalls = default; ChatFunctionCall functionCall = default; - string role = "assistant"; + ChatMessageRole role = default; IList content = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { + if (property.NameEquals("refusal"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + refusal = null; + continue; + } + refusal = property.Value.GetString(); + continue; + } if (property.NameEquals("name"u8)) { name = property.Value.GetString(); @@ -72,7 +83,7 @@ internal static AssistantChatMessage DeserializeAssistantChatMessage(JsonElement } if (property.NameEquals("role"u8)) { - role = property.Value.GetString(); + role = property.Value.GetString().ToChatMessageRole(); continue; } if (property.NameEquals("content"u8)) @@ -91,6 +102,7 @@ internal static AssistantChatMessage DeserializeAssistantChatMessage(JsonElement role, content ?? new ChangeTrackingList(), serializedAdditionalRawData, + refusal, name, toolCalls ?? new ChangeTrackingList(), functionCall); diff --git a/src/Generated/Models/AssistantChatMessage.cs b/src/Generated/Models/AssistantChatMessage.cs index 38f6c207d..1d3cc6723 100644 --- a/src/Generated/Models/AssistantChatMessage.cs +++ b/src/Generated/Models/AssistantChatMessage.cs @@ -9,13 +9,15 @@ namespace OpenAI.Chat { public partial class AssistantChatMessage : ChatMessage { - internal AssistantChatMessage(string role, IList content, IDictionary serializedAdditionalRawData, string participantName, IList toolCalls, ChatFunctionCall functionCall) : base(role, content, serializedAdditionalRawData) + internal AssistantChatMessage(ChatMessageRole role, IList content, IDictionary serializedAdditionalRawData, string refusal, string participantName, IList toolCalls, ChatFunctionCall functionCall) : base(role, content, serializedAdditionalRawData) { + Refusal = refusal; ParticipantName = participantName; ToolCalls = toolCalls; FunctionCall = functionCall; } - public IList ToolCalls { get; } + + public string Refusal { get; set; } public ChatFunctionCall FunctionCall { get; set; } } } diff --git a/src/Generated/Models/AssistantResponseFormat.Serialization.cs b/src/Generated/Models/AssistantResponseFormat.Serialization.cs index eaa92389d..f2fa4d9f9 100644 --- a/src/Generated/Models/AssistantResponseFormat.Serialization.cs +++ b/src/Generated/Models/AssistantResponseFormat.Serialization.cs @@ -9,19 +9,8 @@ namespace OpenAI.Assistants { + [PersistableModelProxy(typeof(InternalUnknownAssistantResponseFormat))] public partial class AssistantResponseFormat : IJsonModel { - string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; - - internal static AssistantResponseFormat FromResponse(PipelineResponse response) - { - using var document = JsonDocument.Parse(response.Content); - return DeserializeAssistantResponseFormat(document.RootElement); - } - - internal virtual BinaryContent ToBinaryContent() - { - return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); - } } } diff --git a/src/Generated/Models/AssistantResponseFormat.cs b/src/Generated/Models/AssistantResponseFormat.cs index da67ee999..3490f8a5a 100644 --- a/src/Generated/Models/AssistantResponseFormat.cs +++ b/src/Generated/Models/AssistantResponseFormat.cs @@ -7,11 +7,19 @@ namespace OpenAI.Assistants { - public partial class AssistantResponseFormat + public abstract partial class AssistantResponseFormat { - internal AssistantResponseFormat(IDictionary serializedAdditionalRawData) + internal IDictionary SerializedAdditionalRawData { get; set; } + protected AssistantResponseFormat() { + } + + internal AssistantResponseFormat(string type, IDictionary serializedAdditionalRawData) + { + Type = type; SerializedAdditionalRawData = serializedAdditionalRawData; } + + internal string Type { get; set; } } } diff --git a/src/Generated/Models/ChatCompletion.Serialization.cs b/src/Generated/Models/ChatCompletion.Serialization.cs index ea1696d92..87d34ee83 100644 --- a/src/Generated/Models/ChatCompletion.Serialization.cs +++ b/src/Generated/Models/ChatCompletion.Serialization.cs @@ -46,6 +46,18 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOp writer.WritePropertyName("model"u8); writer.WriteStringValue(Model); } + if (SerializedAdditionalRawData?.ContainsKey("service_tier") != true && Optional.IsDefined(_serviceTier)) + { + if (_serviceTier != null) + { + writer.WritePropertyName("service_tier"u8); + writer.WriteStringValue(_serviceTier.Value.ToString()); + } + else + { + writer.WriteNull("service_tier"); + } + } if (SerializedAdditionalRawData?.ContainsKey("system_fingerprint") != true && Optional.IsDefined(SystemFingerprint)) { writer.WritePropertyName("system_fingerprint"u8); @@ -107,6 +119,7 @@ internal static ChatCompletion DeserializeChatCompletion(JsonElement element, Mo IReadOnlyList choices = default; DateTimeOffset created = default; string model = default; + InternalCreateChatCompletionResponseServiceTier? serviceTier = default; string systemFingerprint = default; InternalCreateChatCompletionResponseObject @object = default; ChatTokenUsage usage = default; @@ -139,6 +152,16 @@ internal static ChatCompletion DeserializeChatCompletion(JsonElement element, Mo model = property.Value.GetString(); continue; } + if (property.NameEquals("service_tier"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + serviceTier = null; + continue; + } + serviceTier = new InternalCreateChatCompletionResponseServiceTier(property.Value.GetString()); + continue; + } if (property.NameEquals("system_fingerprint"u8)) { systemFingerprint = property.Value.GetString(); @@ -170,6 +193,7 @@ internal static ChatCompletion DeserializeChatCompletion(JsonElement element, Mo choices, created, model, + serviceTier, systemFingerprint, @object, usage, diff --git a/src/Generated/Models/ChatCompletion.cs b/src/Generated/Models/ChatCompletion.cs index 1ad8b44e2..74549a43e 100644 --- a/src/Generated/Models/ChatCompletion.cs +++ b/src/Generated/Models/ChatCompletion.cs @@ -23,12 +23,13 @@ internal ChatCompletion(string id, IEnumerable choices, DateTimeOffset createdAt, string model, string systemFingerprint, InternalCreateChatCompletionResponseObject @object, ChatTokenUsage usage, IDictionary serializedAdditionalRawData) + internal ChatCompletion(string id, IReadOnlyList choices, DateTimeOffset createdAt, string model, InternalCreateChatCompletionResponseServiceTier? serviceTier, string systemFingerprint, InternalCreateChatCompletionResponseObject @object, ChatTokenUsage usage, IDictionary serializedAdditionalRawData) { Id = id; Choices = choices; CreatedAt = createdAt; Model = model; + _serviceTier = serviceTier; SystemFingerprint = systemFingerprint; Object = @object; Usage = usage; diff --git a/src/Generated/Models/ChatCompletionOptions.Serialization.cs b/src/Generated/Models/ChatCompletionOptions.Serialization.cs index 3a571fe7a..cae873c4a 100644 --- a/src/Generated/Models/ChatCompletionOptions.Serialization.cs +++ b/src/Generated/Models/ChatCompletionOptions.Serialization.cs @@ -137,6 +137,18 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderW writer.WriteNull("seed"); } } + if (SerializedAdditionalRawData?.ContainsKey("service_tier") != true && Optional.IsDefined(_serviceTier)) + { + if (_serviceTier != null) + { + writer.WritePropertyName("service_tier"u8); + writer.WriteStringValue(_serviceTier.Value.ToString()); + } + else + { + writer.WriteNull("service_tier"); + } + } if (SerializedAdditionalRawData?.ContainsKey("stop") != true && Optional.IsCollectionDefined(StopSequences)) { if (StopSequences != null) @@ -290,6 +302,7 @@ internal static ChatCompletionOptions DeserializeChatCompletionOptions(JsonEleme float? presencePenalty = default; ChatResponseFormat responseFormat = default; long? seed = default; + InternalCreateChatCompletionRequestServiceTier? serviceTier = default; IList stop = default; bool? stream = default; InternalChatCompletionStreamOptions streamOptions = default; @@ -404,6 +417,16 @@ internal static ChatCompletionOptions DeserializeChatCompletionOptions(JsonEleme seed = property.Value.GetInt64(); continue; } + if (property.NameEquals("service_tier"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + serviceTier = null; + continue; + } + serviceTier = new InternalCreateChatCompletionRequestServiceTier(property.Value.GetString()); + continue; + } if (property.NameEquals("stop"u8)) { DeserializeStopSequencesValue(property, ref stop); @@ -528,6 +551,7 @@ internal static ChatCompletionOptions DeserializeChatCompletionOptions(JsonEleme presencePenalty, responseFormat, seed, + serviceTier, stop ?? new ChangeTrackingList(), stream, streamOptions, diff --git a/src/Generated/Models/ChatCompletionOptions.cs b/src/Generated/Models/ChatCompletionOptions.cs index 4ca6247be..040f1424c 100644 --- a/src/Generated/Models/ChatCompletionOptions.cs +++ b/src/Generated/Models/ChatCompletionOptions.cs @@ -12,7 +12,7 @@ public partial class ChatCompletionOptions { internal IDictionary SerializedAdditionalRawData { get; set; } - internal ChatCompletionOptions(IList messages, InternalCreateChatCompletionRequestModel model, float? frequencyPenalty, IDictionary logitBiases, bool? includeLogProbabilities, int? topLogProbabilityCount, int? maxTokens, int? n, float? presencePenalty, ChatResponseFormat responseFormat, long? seed, IList stopSequences, bool? stream, InternalChatCompletionStreamOptions streamOptions, float? temperature, float? topP, IList tools, ChatToolChoice toolChoice, bool? parallelToolCallsEnabled, string endUserId, ChatFunctionChoice functionChoice, IList functions, IDictionary serializedAdditionalRawData) + internal ChatCompletionOptions(IList messages, InternalCreateChatCompletionRequestModel model, float? frequencyPenalty, IDictionary logitBiases, bool? includeLogProbabilities, int? topLogProbabilityCount, int? maxTokens, int? n, float? presencePenalty, ChatResponseFormat responseFormat, long? seed, InternalCreateChatCompletionRequestServiceTier? serviceTier, IList stopSequences, bool? stream, InternalChatCompletionStreamOptions streamOptions, float? temperature, float? topP, IList tools, ChatToolChoice toolChoice, bool? parallelToolCallsEnabled, string endUserId, ChatFunctionChoice functionChoice, IList functions, IDictionary serializedAdditionalRawData) { Messages = messages; Model = model; @@ -25,6 +25,7 @@ internal ChatCompletionOptions(IList messages, InternalCreateChatCo PresencePenalty = presencePenalty; ResponseFormat = responseFormat; Seed = seed; + _serviceTier = serviceTier; StopSequences = stopSequences; Stream = stream; StreamOptions = streamOptions; diff --git a/src/Generated/Models/ChatMessage.cs b/src/Generated/Models/ChatMessage.cs index 7617e8dc4..08314591b 100644 --- a/src/Generated/Models/ChatMessage.cs +++ b/src/Generated/Models/ChatMessage.cs @@ -15,13 +15,11 @@ protected ChatMessage() Content = new ChangeTrackingList(); } - internal ChatMessage(string role, IList content, IDictionary serializedAdditionalRawData) + internal ChatMessage(ChatMessageRole role, IList content, IDictionary serializedAdditionalRawData) { Role = role; Content = content; SerializedAdditionalRawData = serializedAdditionalRawData; } - - internal string Role { get; set; } } } diff --git a/src/Generated/Models/ChatResponseFormat.Serialization.cs b/src/Generated/Models/ChatResponseFormat.Serialization.cs index a98c5ce1a..2c055865b 100644 --- a/src/Generated/Models/ChatResponseFormat.Serialization.cs +++ b/src/Generated/Models/ChatResponseFormat.Serialization.cs @@ -5,11 +5,11 @@ using System; using System.ClientModel; using System.ClientModel.Primitives; -using System.Collections.Generic; using System.Text.Json; namespace OpenAI.Chat { + [PersistableModelProxy(typeof(InternalUnknownChatResponseFormat))] public partial class ChatResponseFormat : IJsonModel { void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) @@ -21,10 +21,10 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWrit } writer.WriteStartObject(); - if (SerializedAdditionalRawData?.ContainsKey("type") != true && Optional.IsDefined(Type)) + if (SerializedAdditionalRawData?.ContainsKey("type") != true) { writer.WritePropertyName("type"u8); - writer.WriteStringValue(Type.Value.ToString()); + writer.WriteStringValue(Type); } if (SerializedAdditionalRawData != null) { @@ -68,28 +68,16 @@ internal static ChatResponseFormat DeserializeChatResponseFormat(JsonElement ele { return null; } - InternalCreateChatCompletionRequestResponseFormatType? type = default; - IDictionary serializedAdditionalRawData = default; - Dictionary rawDataDictionary = new Dictionary(); - foreach (var property in element.EnumerateObject()) + if (element.TryGetProperty("type", out JsonElement discriminator)) { - if (property.NameEquals("type"u8)) + switch (discriminator.GetString()) { - if (property.Value.ValueKind == JsonValueKind.Null) - { - continue; - } - type = new InternalCreateChatCompletionRequestResponseFormatType(property.Value.GetString()); - continue; - } - if (true) - { - rawDataDictionary ??= new Dictionary(); - rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + case "json_object": return InternalChatResponseFormatJsonObject.DeserializeInternalChatResponseFormatJsonObject(element, options); + case "json_schema": return InternalChatResponseFormatJsonSchema.DeserializeInternalChatResponseFormatJsonSchema(element, options); + case "text": return InternalChatResponseFormatText.DeserializeInternalChatResponseFormatText(element, options); } } - serializedAdditionalRawData = rawDataDictionary; - return new ChatResponseFormat(type, serializedAdditionalRawData); + return InternalUnknownChatResponseFormat.DeserializeInternalUnknownChatResponseFormat(element, options); } BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) diff --git a/src/Generated/Models/ChatResponseFormat.cs b/src/Generated/Models/ChatResponseFormat.cs index 78f6d60f9..54eb0a8bd 100644 --- a/src/Generated/Models/ChatResponseFormat.cs +++ b/src/Generated/Models/ChatResponseFormat.cs @@ -7,14 +7,19 @@ namespace OpenAI.Chat { - public partial class ChatResponseFormat + public abstract partial class ChatResponseFormat { internal IDictionary SerializedAdditionalRawData { get; set; } + protected ChatResponseFormat() + { + } - internal ChatResponseFormat(InternalCreateChatCompletionRequestResponseFormatType? type, IDictionary serializedAdditionalRawData) + internal ChatResponseFormat(string type, IDictionary serializedAdditionalRawData) { Type = type; SerializedAdditionalRawData = serializedAdditionalRawData; } + + internal string Type { get; set; } } } diff --git a/src/Generated/Models/FunctionChatMessage.Serialization.cs b/src/Generated/Models/FunctionChatMessage.Serialization.cs index ea0a1d297..398f7d5cc 100644 --- a/src/Generated/Models/FunctionChatMessage.Serialization.cs +++ b/src/Generated/Models/FunctionChatMessage.Serialization.cs @@ -5,6 +5,7 @@ using System; using System.ClientModel; using System.ClientModel.Primitives; +using System.Collections.Generic; using System.Text.Json; namespace OpenAI.Chat @@ -23,6 +24,46 @@ FunctionChatMessage IJsonModel.Create(ref Utf8JsonReader re return DeserializeFunctionChatMessage(document.RootElement, options); } + internal static FunctionChatMessage DeserializeFunctionChatMessage(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string name = default; + ChatMessageRole role = default; + IList content = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("name"u8)) + { + name = property.Value.GetString(); + continue; + } + if (property.NameEquals("role"u8)) + { + role = property.Value.GetString().ToChatMessageRole(); + continue; + } + if (property.NameEquals("content"u8)) + { + DeserializeContentValue(property, ref content); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new FunctionChatMessage(role, content ?? new ChangeTrackingList(), serializedAdditionalRawData, name); + } + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; diff --git a/src/Generated/Models/FunctionChatMessage.cs b/src/Generated/Models/FunctionChatMessage.cs index 1c814213f..abcbb2170 100644 --- a/src/Generated/Models/FunctionChatMessage.cs +++ b/src/Generated/Models/FunctionChatMessage.cs @@ -10,7 +10,7 @@ namespace OpenAI.Chat [Obsolete("This field is marked as deprecated.")] public partial class FunctionChatMessage : ChatMessage { - internal FunctionChatMessage(string role, IList content, IDictionary serializedAdditionalRawData, string functionName) : base(role, content, serializedAdditionalRawData) + internal FunctionChatMessage(ChatMessageRole role, IList content, IDictionary serializedAdditionalRawData, string functionName) : base(role, content, serializedAdditionalRawData) { FunctionName = functionName; } diff --git a/src/Generated/Models/InternalAddUploadPartRequest.Serialization.cs b/src/Generated/Models/InternalAddUploadPartRequest.Serialization.cs new file mode 100644 index 000000000..f76b44afb --- /dev/null +++ b/src/Generated/Models/InternalAddUploadPartRequest.Serialization.cs @@ -0,0 +1,165 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.IO; +using System.Text.Json; + +namespace OpenAI.Files +{ + internal partial class InternalAddUploadPartRequest : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalAddUploadPartRequest)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("data") != true) + { + writer.WritePropertyName("data"u8); +#if NET6_0_OR_GREATER + writer.WriteRawValue(global::System.BinaryData.FromStream(Data)); +#else + using (JsonDocument document = JsonDocument.Parse(BinaryData.FromStream(Data))) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalAddUploadPartRequest IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalAddUploadPartRequest)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalAddUploadPartRequest(document.RootElement, options); + } + + internal static InternalAddUploadPartRequest DeserializeInternalAddUploadPartRequest(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + Stream data = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("data"u8)) + { + data = BinaryData.FromString(property.Value.GetRawText()).ToStream(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new InternalAddUploadPartRequest(data, serializedAdditionalRawData); + } + + private BinaryData SerializeMultipart(ModelReaderWriterOptions options) + { + using MultipartFormDataBinaryContent content = ToMultipartBinaryBody(); + using MemoryStream stream = new MemoryStream(); + content.WriteTo(stream); + if (stream.Position > int.MaxValue) + { + return BinaryData.FromStream(stream); + } + else + { + return new BinaryData(stream.GetBuffer().AsMemory(0, (int)stream.Position)); + } + } + + internal virtual MultipartFormDataBinaryContent ToMultipartBinaryBody() + { + MultipartFormDataBinaryContent content = new MultipartFormDataBinaryContent(); + content.Add(Data, "data", "data", "application/octet-stream"); + return content; + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + case "MFD": + return SerializeMultipart(options); + default: + throw new FormatException($"The model {nameof(InternalAddUploadPartRequest)} does not support writing '{options.Format}' format."); + } + } + + InternalAddUploadPartRequest IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalAddUploadPartRequest(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalAddUploadPartRequest)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "MFD"; + + internal static InternalAddUploadPartRequest FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalAddUploadPartRequest(document.RootElement); + } + + internal virtual BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/InternalAddUploadPartRequest.cs b/src/Generated/Models/InternalAddUploadPartRequest.cs new file mode 100644 index 000000000..f6035f34b --- /dev/null +++ b/src/Generated/Models/InternalAddUploadPartRequest.cs @@ -0,0 +1,33 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.IO; + +namespace OpenAI.Files +{ + internal partial class InternalAddUploadPartRequest + { + internal IDictionary SerializedAdditionalRawData { get; set; } + public InternalAddUploadPartRequest(Stream data) + { + Argument.AssertNotNull(data, nameof(data)); + + Data = data; + } + + internal InternalAddUploadPartRequest(Stream data, IDictionary serializedAdditionalRawData) + { + Data = data; + SerializedAdditionalRawData = serializedAdditionalRawData; + } + + internal InternalAddUploadPartRequest() + { + } + + public Stream Data { get; } + } +} diff --git a/src/Generated/Models/InternalAssistantResponseFormatJsonObject.Serialization.cs b/src/Generated/Models/InternalAssistantResponseFormatJsonObject.Serialization.cs new file mode 100644 index 000000000..80afbf5f6 --- /dev/null +++ b/src/Generated/Models/InternalAssistantResponseFormatJsonObject.Serialization.cs @@ -0,0 +1,122 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.Assistants +{ + internal partial class InternalAssistantResponseFormatJsonObject : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalAssistantResponseFormatJsonObject)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalAssistantResponseFormatJsonObject IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalAssistantResponseFormatJsonObject)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalAssistantResponseFormatJsonObject(document.RootElement, options); + } + + internal static InternalAssistantResponseFormatJsonObject DeserializeInternalAssistantResponseFormatJsonObject(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new InternalAssistantResponseFormatJsonObject(type, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalAssistantResponseFormatJsonObject)} does not support writing '{options.Format}' format."); + } + } + + InternalAssistantResponseFormatJsonObject IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalAssistantResponseFormatJsonObject(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalAssistantResponseFormatJsonObject)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + } +} diff --git a/src/Generated/Models/InternalAssistantResponseFormatJsonObject.cs b/src/Generated/Models/InternalAssistantResponseFormatJsonObject.cs new file mode 100644 index 000000000..b6caf3d33 --- /dev/null +++ b/src/Generated/Models/InternalAssistantResponseFormatJsonObject.cs @@ -0,0 +1,21 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.Assistants +{ + internal partial class InternalAssistantResponseFormatJsonObject : AssistantResponseFormat + { + internal InternalAssistantResponseFormatJsonObject() + { + Type = "json_object"; + } + + internal InternalAssistantResponseFormatJsonObject(string type, IDictionary serializedAdditionalRawData) : base(type, serializedAdditionalRawData) + { + } + } +} diff --git a/src/Generated/Models/InternalAssistantResponseFormatJsonSchema.Serialization.cs b/src/Generated/Models/InternalAssistantResponseFormatJsonSchema.Serialization.cs new file mode 100644 index 000000000..24865dbf9 --- /dev/null +++ b/src/Generated/Models/InternalAssistantResponseFormatJsonSchema.Serialization.cs @@ -0,0 +1,134 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using OpenAI.Internal; + +namespace OpenAI.Assistants +{ + internal partial class InternalAssistantResponseFormatJsonSchema : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalAssistantResponseFormatJsonSchema)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("json_schema") != true) + { + writer.WritePropertyName("json_schema"u8); + writer.WriteObjectValue(JsonSchema, options); + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalAssistantResponseFormatJsonSchema IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalAssistantResponseFormatJsonSchema)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalAssistantResponseFormatJsonSchema(document.RootElement, options); + } + + internal static InternalAssistantResponseFormatJsonSchema DeserializeInternalAssistantResponseFormatJsonSchema(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + InternalResponseFormatJsonSchemaJsonSchema jsonSchema = default; + string type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("json_schema"u8)) + { + jsonSchema = InternalResponseFormatJsonSchemaJsonSchema.DeserializeInternalResponseFormatJsonSchemaJsonSchema(property.Value, options); + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new InternalAssistantResponseFormatJsonSchema(type, serializedAdditionalRawData, jsonSchema); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalAssistantResponseFormatJsonSchema)} does not support writing '{options.Format}' format."); + } + } + + InternalAssistantResponseFormatJsonSchema IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalAssistantResponseFormatJsonSchema(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalAssistantResponseFormatJsonSchema)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + } +} diff --git a/src/Generated/Models/InternalAssistantResponseFormatJsonSchema.cs b/src/Generated/Models/InternalAssistantResponseFormatJsonSchema.cs new file mode 100644 index 000000000..d2b71a861 --- /dev/null +++ b/src/Generated/Models/InternalAssistantResponseFormatJsonSchema.cs @@ -0,0 +1,32 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; +using OpenAI.Internal; + +namespace OpenAI.Assistants +{ + internal partial class InternalAssistantResponseFormatJsonSchema : AssistantResponseFormat + { + internal InternalAssistantResponseFormatJsonSchema(InternalResponseFormatJsonSchemaJsonSchema jsonSchema) + { + Argument.AssertNotNull(jsonSchema, nameof(jsonSchema)); + + Type = "json_schema"; + JsonSchema = jsonSchema; + } + + internal InternalAssistantResponseFormatJsonSchema(string type, IDictionary serializedAdditionalRawData, InternalResponseFormatJsonSchemaJsonSchema jsonSchema) : base(type, serializedAdditionalRawData) + { + JsonSchema = jsonSchema; + } + + internal InternalAssistantResponseFormatJsonSchema() + { + } + + public InternalResponseFormatJsonSchemaJsonSchema JsonSchema { get; } + } +} diff --git a/src/Generated/Models/InternalAssistantsApiResponseFormat.Serialization.cs b/src/Generated/Models/InternalAssistantResponseFormatText.Serialization.cs similarity index 60% rename from src/Generated/Models/InternalAssistantsApiResponseFormat.Serialization.cs rename to src/Generated/Models/InternalAssistantResponseFormatText.Serialization.cs index f1c047365..a2ae06eea 100644 --- a/src/Generated/Models/InternalAssistantsApiResponseFormat.Serialization.cs +++ b/src/Generated/Models/InternalAssistantResponseFormatText.Serialization.cs @@ -10,21 +10,21 @@ namespace OpenAI.Assistants { - internal partial class InternalAssistantsApiResponseFormat : IJsonModel + internal partial class InternalAssistantResponseFormatText : IJsonModel { - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { - throw new FormatException($"The model {nameof(InternalAssistantsApiResponseFormat)} does not support writing '{format}' format."); + throw new FormatException($"The model {nameof(InternalAssistantResponseFormatText)} does not support writing '{format}' format."); } writer.WriteStartObject(); - if (SerializedAdditionalRawData?.ContainsKey("type") != true && Optional.IsDefined(Type)) + if (SerializedAdditionalRawData?.ContainsKey("type") != true) { writer.WritePropertyName("type"u8); - writer.WriteStringValue(Type.Value.ToString()); + writer.WriteStringValue(Type); } if (SerializedAdditionalRawData != null) { @@ -48,19 +48,19 @@ void IJsonModel.Write(Utf8JsonWriter writer writer.WriteEndObject(); } - InternalAssistantsApiResponseFormat IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + InternalAssistantResponseFormatText IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { - throw new FormatException($"The model {nameof(InternalAssistantsApiResponseFormat)} does not support reading '{format}' format."); + throw new FormatException($"The model {nameof(InternalAssistantResponseFormatText)} does not support reading '{format}' format."); } using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeInternalAssistantsApiResponseFormat(document.RootElement, options); + return DeserializeInternalAssistantResponseFormatText(document.RootElement, options); } - internal static InternalAssistantsApiResponseFormat DeserializeInternalAssistantsApiResponseFormat(JsonElement element, ModelReaderWriterOptions options = null) + internal static InternalAssistantResponseFormatText DeserializeInternalAssistantResponseFormatText(JsonElement element, ModelReaderWriterOptions options = null) { options ??= ModelSerializationExtensions.WireOptions; @@ -68,18 +68,14 @@ internal static InternalAssistantsApiResponseFormat DeserializeInternalAssistant { return null; } - InternalAssistantsApiResponseFormatType? type = default; + string type = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("type"u8)) { - if (property.Value.ValueKind == JsonValueKind.Null) - { - continue; - } - type = new InternalAssistantsApiResponseFormatType(property.Value.GetString()); + type = property.Value.GetString(); continue; } if (true) @@ -89,49 +85,38 @@ internal static InternalAssistantsApiResponseFormat DeserializeInternalAssistant } } serializedAdditionalRawData = rawDataDictionary; - return new InternalAssistantsApiResponseFormat(type, serializedAdditionalRawData); + return new InternalAssistantResponseFormatText(type, serializedAdditionalRawData); } - BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": return ModelReaderWriter.Write(this, options); default: - throw new FormatException($"The model {nameof(InternalAssistantsApiResponseFormat)} does not support writing '{options.Format}' format."); + throw new FormatException($"The model {nameof(InternalAssistantResponseFormatText)} does not support writing '{options.Format}' format."); } } - InternalAssistantsApiResponseFormat IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + InternalAssistantResponseFormatText IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": { using JsonDocument document = JsonDocument.Parse(data); - return DeserializeInternalAssistantsApiResponseFormat(document.RootElement, options); + return DeserializeInternalAssistantResponseFormatText(document.RootElement, options); } default: - throw new FormatException($"The model {nameof(InternalAssistantsApiResponseFormat)} does not support reading '{options.Format}' format."); + throw new FormatException($"The model {nameof(InternalAssistantResponseFormatText)} does not support reading '{options.Format}' format."); } } - string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; - - internal static InternalAssistantsApiResponseFormat FromResponse(PipelineResponse response) - { - using var document = JsonDocument.Parse(response.Content); - return DeserializeInternalAssistantsApiResponseFormat(document.RootElement); - } - - internal virtual BinaryContent ToBinaryContent() - { - return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); - } + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; } } diff --git a/src/Generated/Models/InternalAssistantResponseFormatText.cs b/src/Generated/Models/InternalAssistantResponseFormatText.cs new file mode 100644 index 000000000..899b65998 --- /dev/null +++ b/src/Generated/Models/InternalAssistantResponseFormatText.cs @@ -0,0 +1,21 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.Assistants +{ + internal partial class InternalAssistantResponseFormatText : AssistantResponseFormat + { + internal InternalAssistantResponseFormatText() + { + Type = "text"; + } + + internal InternalAssistantResponseFormatText(string type, IDictionary serializedAdditionalRawData) : base(type, serializedAdditionalRawData) + { + } + } +} diff --git a/src/Generated/Models/InternalAssistantsApiResponseFormat.cs b/src/Generated/Models/InternalAssistantsApiResponseFormat.cs deleted file mode 100644 index 9333fb55c..000000000 --- a/src/Generated/Models/InternalAssistantsApiResponseFormat.cs +++ /dev/null @@ -1,25 +0,0 @@ -// - -#nullable disable - -using System; -using System.Collections.Generic; - -namespace OpenAI.Assistants -{ - internal partial class InternalAssistantsApiResponseFormat - { - internal IDictionary SerializedAdditionalRawData { get; set; } - public InternalAssistantsApiResponseFormat() - { - } - - internal InternalAssistantsApiResponseFormat(InternalAssistantsApiResponseFormatType? type, IDictionary serializedAdditionalRawData) - { - Type = type; - SerializedAdditionalRawData = serializedAdditionalRawData; - } - - public InternalAssistantsApiResponseFormatType? Type { get; set; } - } -} diff --git a/src/Generated/Models/InternalAssistantsApiResponseFormatType.cs b/src/Generated/Models/InternalAssistantsApiResponseFormatType.cs deleted file mode 100644 index 60e13d230..000000000 --- a/src/Generated/Models/InternalAssistantsApiResponseFormatType.cs +++ /dev/null @@ -1,36 +0,0 @@ -// - -#nullable disable - -using System; -using System.ComponentModel; - -namespace OpenAI.Assistants -{ - internal readonly partial struct InternalAssistantsApiResponseFormatType : IEquatable - { - private readonly string _value; - - public InternalAssistantsApiResponseFormatType(string value) - { - _value = value ?? throw new ArgumentNullException(nameof(value)); - } - - private const string TextValue = "text"; - private const string JsonObjectValue = "json_object"; - - public static InternalAssistantsApiResponseFormatType Text { get; } = new InternalAssistantsApiResponseFormatType(TextValue); - public static InternalAssistantsApiResponseFormatType JsonObject { get; } = new InternalAssistantsApiResponseFormatType(JsonObjectValue); - public static bool operator ==(InternalAssistantsApiResponseFormatType left, InternalAssistantsApiResponseFormatType right) => left.Equals(right); - public static bool operator !=(InternalAssistantsApiResponseFormatType left, InternalAssistantsApiResponseFormatType right) => !left.Equals(right); - public static implicit operator InternalAssistantsApiResponseFormatType(string value) => new InternalAssistantsApiResponseFormatType(value); - - [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals(object obj) => obj is InternalAssistantsApiResponseFormatType other && Equals(other); - public bool Equals(InternalAssistantsApiResponseFormatType other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); - - [EditorBrowsable(EditorBrowsableState.Never)] - public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; - public override string ToString() => _value; - } -} diff --git a/src/Generated/Models/InternalChatCompletionRequestMessageContentPartRefusal.Serialization.cs b/src/Generated/Models/InternalChatCompletionRequestMessageContentPartRefusal.Serialization.cs new file mode 100644 index 000000000..093b83c78 --- /dev/null +++ b/src/Generated/Models/InternalChatCompletionRequestMessageContentPartRefusal.Serialization.cs @@ -0,0 +1,144 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.Chat +{ + internal partial class InternalChatCompletionRequestMessageContentPartRefusal : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalChatCompletionRequestMessageContentPartRefusal)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type.ToString()); + } + if (SerializedAdditionalRawData?.ContainsKey("refusal") != true) + { + writer.WritePropertyName("refusal"u8); + writer.WriteStringValue(Refusal); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalChatCompletionRequestMessageContentPartRefusal IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalChatCompletionRequestMessageContentPartRefusal)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalChatCompletionRequestMessageContentPartRefusal(document.RootElement, options); + } + + internal static InternalChatCompletionRequestMessageContentPartRefusal DeserializeInternalChatCompletionRequestMessageContentPartRefusal(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + InternalChatCompletionRequestMessageContentPartRefusalType type = default; + string refusal = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("type"u8)) + { + type = new InternalChatCompletionRequestMessageContentPartRefusalType(property.Value.GetString()); + continue; + } + if (property.NameEquals("refusal"u8)) + { + refusal = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new InternalChatCompletionRequestMessageContentPartRefusal(type, refusal, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalChatCompletionRequestMessageContentPartRefusal)} does not support writing '{options.Format}' format."); + } + } + + InternalChatCompletionRequestMessageContentPartRefusal IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalChatCompletionRequestMessageContentPartRefusal(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalChatCompletionRequestMessageContentPartRefusal)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static InternalChatCompletionRequestMessageContentPartRefusal FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalChatCompletionRequestMessageContentPartRefusal(document.RootElement); + } + + internal virtual BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/InternalChatCompletionRequestMessageContentPartRefusal.cs b/src/Generated/Models/InternalChatCompletionRequestMessageContentPartRefusal.cs new file mode 100644 index 000000000..ea0eaa097 --- /dev/null +++ b/src/Generated/Models/InternalChatCompletionRequestMessageContentPartRefusal.cs @@ -0,0 +1,35 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.Chat +{ + internal partial class InternalChatCompletionRequestMessageContentPartRefusal + { + internal IDictionary SerializedAdditionalRawData { get; set; } + public InternalChatCompletionRequestMessageContentPartRefusal(string refusal) + { + Argument.AssertNotNull(refusal, nameof(refusal)); + + Refusal = refusal; + } + + internal InternalChatCompletionRequestMessageContentPartRefusal(InternalChatCompletionRequestMessageContentPartRefusalType type, string refusal, IDictionary serializedAdditionalRawData) + { + Type = type; + Refusal = refusal; + SerializedAdditionalRawData = serializedAdditionalRawData; + } + + internal InternalChatCompletionRequestMessageContentPartRefusal() + { + } + + public InternalChatCompletionRequestMessageContentPartRefusalType Type { get; } = InternalChatCompletionRequestMessageContentPartRefusalType.Refusal; + + public string Refusal { get; } + } +} diff --git a/src/Generated/Models/InternalChatCompletionRequestMessageContentPartRefusalType.cs b/src/Generated/Models/InternalChatCompletionRequestMessageContentPartRefusalType.cs new file mode 100644 index 000000000..d1c3e8498 --- /dev/null +++ b/src/Generated/Models/InternalChatCompletionRequestMessageContentPartRefusalType.cs @@ -0,0 +1,34 @@ +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace OpenAI.Chat +{ + internal readonly partial struct InternalChatCompletionRequestMessageContentPartRefusalType : IEquatable + { + private readonly string _value; + + public InternalChatCompletionRequestMessageContentPartRefusalType(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string RefusalValue = "refusal"; + + public static InternalChatCompletionRequestMessageContentPartRefusalType Refusal { get; } = new InternalChatCompletionRequestMessageContentPartRefusalType(RefusalValue); + public static bool operator ==(InternalChatCompletionRequestMessageContentPartRefusalType left, InternalChatCompletionRequestMessageContentPartRefusalType right) => left.Equals(right); + public static bool operator !=(InternalChatCompletionRequestMessageContentPartRefusalType left, InternalChatCompletionRequestMessageContentPartRefusalType right) => !left.Equals(right); + public static implicit operator InternalChatCompletionRequestMessageContentPartRefusalType(string value) => new InternalChatCompletionRequestMessageContentPartRefusalType(value); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is InternalChatCompletionRequestMessageContentPartRefusalType other && Equals(other); + public bool Equals(InternalChatCompletionRequestMessageContentPartRefusalType other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; + public override string ToString() => _value; + } +} diff --git a/src/Generated/Models/InternalChatCompletionResponseMessage.cs b/src/Generated/Models/InternalChatCompletionResponseMessage.cs index 114a9ae55..f29262217 100644 --- a/src/Generated/Models/InternalChatCompletionResponseMessage.cs +++ b/src/Generated/Models/InternalChatCompletionResponseMessage.cs @@ -11,10 +11,17 @@ namespace OpenAI.Chat internal partial class InternalChatCompletionResponseMessage { internal IDictionary SerializedAdditionalRawData { get; set; } + internal InternalChatCompletionResponseMessage(IEnumerable content, string refusal) + { + Content = content?.ToList(); + Refusal = refusal; + ToolCalls = new ChangeTrackingList(); + } - internal InternalChatCompletionResponseMessage(IReadOnlyList content, IReadOnlyList toolCalls, ChatMessageRole role, ChatFunctionCall functionCall, IDictionary serializedAdditionalRawData) + internal InternalChatCompletionResponseMessage(IReadOnlyList content, string refusal, IReadOnlyList toolCalls, ChatMessageRole role, ChatFunctionCall functionCall, IDictionary serializedAdditionalRawData) { Content = content; + Refusal = refusal; ToolCalls = toolCalls; Role = role; FunctionCall = functionCall; @@ -24,6 +31,7 @@ internal InternalChatCompletionResponseMessage(IReadOnlyList ToolCalls { get; } } } diff --git a/src/Generated/Models/InternalChatCompletionStreamResponseDelta.cs b/src/Generated/Models/InternalChatCompletionStreamResponseDelta.cs index 34085b941..9bdd14f0a 100644 --- a/src/Generated/Models/InternalChatCompletionStreamResponseDelta.cs +++ b/src/Generated/Models/InternalChatCompletionStreamResponseDelta.cs @@ -11,15 +11,17 @@ internal partial class InternalChatCompletionStreamResponseDelta { internal IDictionary SerializedAdditionalRawData { get; set; } - internal InternalChatCompletionStreamResponseDelta(IReadOnlyList content, StreamingChatFunctionCallUpdate functionCall, IReadOnlyList toolCalls, ChatMessageRole? role, IDictionary serializedAdditionalRawData) + internal InternalChatCompletionStreamResponseDelta(IReadOnlyList content, StreamingChatFunctionCallUpdate functionCall, IReadOnlyList toolCalls, ChatMessageRole? role, string refusal, IDictionary serializedAdditionalRawData) { Content = content; FunctionCall = functionCall; ToolCalls = toolCalls; Role = role; + Refusal = refusal; SerializedAdditionalRawData = serializedAdditionalRawData; } public StreamingChatFunctionCallUpdate FunctionCall { get; } public IReadOnlyList ToolCalls { get; } + public string Refusal { get; } } } diff --git a/src/Generated/Models/InternalCreateAssistantRequestToolResourcesFileSearchBase.Serialization.cs b/src/Generated/Models/InternalChatResponseFormatJsonObject.Serialization.cs similarity index 52% rename from src/Generated/Models/InternalCreateAssistantRequestToolResourcesFileSearchBase.Serialization.cs rename to src/Generated/Models/InternalChatResponseFormatJsonObject.Serialization.cs index 40957b72a..9c63f887b 100644 --- a/src/Generated/Models/InternalCreateAssistantRequestToolResourcesFileSearchBase.Serialization.cs +++ b/src/Generated/Models/InternalChatResponseFormatJsonObject.Serialization.cs @@ -8,19 +8,24 @@ using System.Collections.Generic; using System.Text.Json; -namespace OpenAI.Assistants +namespace OpenAI.Chat { - internal partial class InternalCreateAssistantRequestToolResourcesFileSearchBase : IJsonModel + internal partial class InternalChatResponseFormatJsonObject : IJsonModel { - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { - throw new FormatException($"The model {nameof(InternalCreateAssistantRequestToolResourcesFileSearchBase)} does not support writing '{format}' format."); + throw new FormatException($"The model {nameof(InternalChatResponseFormatJsonObject)} does not support writing '{format}' format."); } writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + } if (SerializedAdditionalRawData != null) { foreach (var item in SerializedAdditionalRawData) @@ -43,19 +48,19 @@ void IJsonModel.Write writer.WriteEndObject(); } - InternalCreateAssistantRequestToolResourcesFileSearchBase IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + InternalChatResponseFormatJsonObject IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { - throw new FormatException($"The model {nameof(InternalCreateAssistantRequestToolResourcesFileSearchBase)} does not support reading '{format}' format."); + throw new FormatException($"The model {nameof(InternalChatResponseFormatJsonObject)} does not support reading '{format}' format."); } using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeInternalCreateAssistantRequestToolResourcesFileSearchBase(document.RootElement, options); + return DeserializeInternalChatResponseFormatJsonObject(document.RootElement, options); } - internal static InternalCreateAssistantRequestToolResourcesFileSearchBase DeserializeInternalCreateAssistantRequestToolResourcesFileSearchBase(JsonElement element, ModelReaderWriterOptions options = null) + internal static InternalChatResponseFormatJsonObject DeserializeInternalChatResponseFormatJsonObject(JsonElement element, ModelReaderWriterOptions options = null) { options ??= ModelSerializationExtensions.WireOptions; @@ -63,10 +68,16 @@ internal static InternalCreateAssistantRequestToolResourcesFileSearchBase Deseri { return null; } + string type = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } if (true) { rawDataDictionary ??= new Dictionary(); @@ -74,47 +85,47 @@ internal static InternalCreateAssistantRequestToolResourcesFileSearchBase Deseri } } serializedAdditionalRawData = rawDataDictionary; - return new InternalCreateAssistantRequestToolResourcesFileSearchBase(serializedAdditionalRawData); + return new InternalChatResponseFormatJsonObject(type, serializedAdditionalRawData); } - BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": return ModelReaderWriter.Write(this, options); default: - throw new FormatException($"The model {nameof(InternalCreateAssistantRequestToolResourcesFileSearchBase)} does not support writing '{options.Format}' format."); + throw new FormatException($"The model {nameof(InternalChatResponseFormatJsonObject)} does not support writing '{options.Format}' format."); } } - InternalCreateAssistantRequestToolResourcesFileSearchBase IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + InternalChatResponseFormatJsonObject IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": { using JsonDocument document = JsonDocument.Parse(data); - return DeserializeInternalCreateAssistantRequestToolResourcesFileSearchBase(document.RootElement, options); + return DeserializeInternalChatResponseFormatJsonObject(document.RootElement, options); } default: - throw new FormatException($"The model {nameof(InternalCreateAssistantRequestToolResourcesFileSearchBase)} does not support reading '{options.Format}' format."); + throw new FormatException($"The model {nameof(InternalChatResponseFormatJsonObject)} does not support reading '{options.Format}' format."); } } - string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; - internal static InternalCreateAssistantRequestToolResourcesFileSearchBase FromResponse(PipelineResponse response) + internal static new InternalChatResponseFormatJsonObject FromResponse(PipelineResponse response) { using var document = JsonDocument.Parse(response.Content); - return DeserializeInternalCreateAssistantRequestToolResourcesFileSearchBase(document.RootElement); + return DeserializeInternalChatResponseFormatJsonObject(document.RootElement); } - internal virtual BinaryContent ToBinaryContent() + internal override BinaryContent ToBinaryContent() { return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); } diff --git a/src/Generated/Models/InternalChatResponseFormatJsonObject.cs b/src/Generated/Models/InternalChatResponseFormatJsonObject.cs new file mode 100644 index 000000000..a3d489404 --- /dev/null +++ b/src/Generated/Models/InternalChatResponseFormatJsonObject.cs @@ -0,0 +1,21 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.Chat +{ + internal partial class InternalChatResponseFormatJsonObject : ChatResponseFormat + { + public InternalChatResponseFormatJsonObject() + { + Type = "json_object"; + } + + internal InternalChatResponseFormatJsonObject(string type, IDictionary serializedAdditionalRawData) : base(type, serializedAdditionalRawData) + { + } + } +} diff --git a/src/Generated/Models/InternalChatResponseFormatJsonSchema.Serialization.cs b/src/Generated/Models/InternalChatResponseFormatJsonSchema.Serialization.cs new file mode 100644 index 000000000..c5c0cca64 --- /dev/null +++ b/src/Generated/Models/InternalChatResponseFormatJsonSchema.Serialization.cs @@ -0,0 +1,145 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using OpenAI.Internal; + +namespace OpenAI.Chat +{ + internal partial class InternalChatResponseFormatJsonSchema : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalChatResponseFormatJsonSchema)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("json_schema") != true) + { + writer.WritePropertyName("json_schema"u8); + writer.WriteObjectValue(JsonSchema, options); + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalChatResponseFormatJsonSchema IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalChatResponseFormatJsonSchema)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalChatResponseFormatJsonSchema(document.RootElement, options); + } + + internal static InternalChatResponseFormatJsonSchema DeserializeInternalChatResponseFormatJsonSchema(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + InternalResponseFormatJsonSchemaJsonSchema jsonSchema = default; + string type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("json_schema"u8)) + { + jsonSchema = InternalResponseFormatJsonSchemaJsonSchema.DeserializeInternalResponseFormatJsonSchemaJsonSchema(property.Value, options); + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new InternalChatResponseFormatJsonSchema(type, serializedAdditionalRawData, jsonSchema); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalChatResponseFormatJsonSchema)} does not support writing '{options.Format}' format."); + } + } + + InternalChatResponseFormatJsonSchema IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalChatResponseFormatJsonSchema(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalChatResponseFormatJsonSchema)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new InternalChatResponseFormatJsonSchema FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalChatResponseFormatJsonSchema(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/InternalChatResponseFormatJsonSchema.cs b/src/Generated/Models/InternalChatResponseFormatJsonSchema.cs new file mode 100644 index 000000000..d519acb14 --- /dev/null +++ b/src/Generated/Models/InternalChatResponseFormatJsonSchema.cs @@ -0,0 +1,32 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; +using OpenAI.Internal; + +namespace OpenAI.Chat +{ + internal partial class InternalChatResponseFormatJsonSchema : ChatResponseFormat + { + public InternalChatResponseFormatJsonSchema(InternalResponseFormatJsonSchemaJsonSchema jsonSchema) + { + Argument.AssertNotNull(jsonSchema, nameof(jsonSchema)); + + Type = "json_schema"; + JsonSchema = jsonSchema; + } + + internal InternalChatResponseFormatJsonSchema(string type, IDictionary serializedAdditionalRawData, InternalResponseFormatJsonSchemaJsonSchema jsonSchema) : base(type, serializedAdditionalRawData) + { + JsonSchema = jsonSchema; + } + + internal InternalChatResponseFormatJsonSchema() + { + } + + public InternalResponseFormatJsonSchemaJsonSchema JsonSchema { get; } + } +} diff --git a/src/Generated/Models/InternalChatResponseFormatText.Serialization.cs b/src/Generated/Models/InternalChatResponseFormatText.Serialization.cs new file mode 100644 index 000000000..c0f373c9d --- /dev/null +++ b/src/Generated/Models/InternalChatResponseFormatText.Serialization.cs @@ -0,0 +1,133 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.Chat +{ + internal partial class InternalChatResponseFormatText : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalChatResponseFormatText)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalChatResponseFormatText IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalChatResponseFormatText)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalChatResponseFormatText(document.RootElement, options); + } + + internal static InternalChatResponseFormatText DeserializeInternalChatResponseFormatText(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new InternalChatResponseFormatText(type, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalChatResponseFormatText)} does not support writing '{options.Format}' format."); + } + } + + InternalChatResponseFormatText IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalChatResponseFormatText(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalChatResponseFormatText)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new InternalChatResponseFormatText FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalChatResponseFormatText(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/InternalChatResponseFormatText.cs b/src/Generated/Models/InternalChatResponseFormatText.cs new file mode 100644 index 000000000..49e7771f0 --- /dev/null +++ b/src/Generated/Models/InternalChatResponseFormatText.cs @@ -0,0 +1,21 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.Chat +{ + internal partial class InternalChatResponseFormatText : ChatResponseFormat + { + public InternalChatResponseFormatText() + { + Type = "text"; + } + + internal InternalChatResponseFormatText(string type, IDictionary serializedAdditionalRawData) : base(type, serializedAdditionalRawData) + { + } + } +} diff --git a/src/Generated/Models/InternalModifyAssistantRequestToolResourcesFileSearch.Serialization.cs b/src/Generated/Models/InternalCompleteUploadRequest.Serialization.cs similarity index 53% rename from src/Generated/Models/InternalModifyAssistantRequestToolResourcesFileSearch.Serialization.cs rename to src/Generated/Models/InternalCompleteUploadRequest.Serialization.cs index d8f1c1e75..30ee85a04 100644 --- a/src/Generated/Models/InternalModifyAssistantRequestToolResourcesFileSearch.Serialization.cs +++ b/src/Generated/Models/InternalCompleteUploadRequest.Serialization.cs @@ -8,29 +8,34 @@ using System.Collections.Generic; using System.Text.Json; -namespace OpenAI.Assistants +namespace OpenAI.Files { - internal partial class InternalModifyAssistantRequestToolResourcesFileSearch : IJsonModel + internal partial class InternalCompleteUploadRequest : IJsonModel { - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { - throw new FormatException($"The model {nameof(InternalModifyAssistantRequestToolResourcesFileSearch)} does not support writing '{format}' format."); + throw new FormatException($"The model {nameof(InternalCompleteUploadRequest)} does not support writing '{format}' format."); } writer.WriteStartObject(); - if (SerializedAdditionalRawData?.ContainsKey("vector_store_ids") != true && Optional.IsCollectionDefined(VectorStoreIds)) + if (SerializedAdditionalRawData?.ContainsKey("part_ids") != true) { - writer.WritePropertyName("vector_store_ids"u8); + writer.WritePropertyName("part_ids"u8); writer.WriteStartArray(); - foreach (var item in VectorStoreIds) + foreach (var item in PartIds) { writer.WriteStringValue(item); } writer.WriteEndArray(); } + if (SerializedAdditionalRawData?.ContainsKey("md5") != true && Optional.IsDefined(Md5)) + { + writer.WritePropertyName("md5"u8); + writer.WriteStringValue(Md5); + } if (SerializedAdditionalRawData != null) { foreach (var item in SerializedAdditionalRawData) @@ -53,19 +58,19 @@ void IJsonModel.Write(Utf writer.WriteEndObject(); } - InternalModifyAssistantRequestToolResourcesFileSearch IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + InternalCompleteUploadRequest IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { - throw new FormatException($"The model {nameof(InternalModifyAssistantRequestToolResourcesFileSearch)} does not support reading '{format}' format."); + throw new FormatException($"The model {nameof(InternalCompleteUploadRequest)} does not support reading '{format}' format."); } using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeInternalModifyAssistantRequestToolResourcesFileSearch(document.RootElement, options); + return DeserializeInternalCompleteUploadRequest(document.RootElement, options); } - internal static InternalModifyAssistantRequestToolResourcesFileSearch DeserializeInternalModifyAssistantRequestToolResourcesFileSearch(JsonElement element, ModelReaderWriterOptions options = null) + internal static InternalCompleteUploadRequest DeserializeInternalCompleteUploadRequest(JsonElement element, ModelReaderWriterOptions options = null) { options ??= ModelSerializationExtensions.WireOptions; @@ -73,23 +78,25 @@ internal static InternalModifyAssistantRequestToolResourcesFileSearch Deserializ { return null; } - IList vectorStoreIds = default; + IList partIds = default; + string md5 = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { - if (property.NameEquals("vector_store_ids"u8)) + if (property.NameEquals("part_ids"u8)) { - if (property.Value.ValueKind == JsonValueKind.Null) - { - continue; - } List array = new List(); foreach (var item in property.Value.EnumerateArray()) { array.Add(item.GetString()); } - vectorStoreIds = array; + partIds = array; + continue; + } + if (property.NameEquals("md5"u8)) + { + md5 = property.Value.GetString(); continue; } if (true) @@ -99,44 +106,44 @@ internal static InternalModifyAssistantRequestToolResourcesFileSearch Deserializ } } serializedAdditionalRawData = rawDataDictionary; - return new InternalModifyAssistantRequestToolResourcesFileSearch(vectorStoreIds ?? new ChangeTrackingList(), serializedAdditionalRawData); + return new InternalCompleteUploadRequest(partIds, md5, serializedAdditionalRawData); } - BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": return ModelReaderWriter.Write(this, options); default: - throw new FormatException($"The model {nameof(InternalModifyAssistantRequestToolResourcesFileSearch)} does not support writing '{options.Format}' format."); + throw new FormatException($"The model {nameof(InternalCompleteUploadRequest)} does not support writing '{options.Format}' format."); } } - InternalModifyAssistantRequestToolResourcesFileSearch IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + InternalCompleteUploadRequest IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": { using JsonDocument document = JsonDocument.Parse(data); - return DeserializeInternalModifyAssistantRequestToolResourcesFileSearch(document.RootElement, options); + return DeserializeInternalCompleteUploadRequest(document.RootElement, options); } default: - throw new FormatException($"The model {nameof(InternalModifyAssistantRequestToolResourcesFileSearch)} does not support reading '{options.Format}' format."); + throw new FormatException($"The model {nameof(InternalCompleteUploadRequest)} does not support reading '{options.Format}' format."); } } - string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; - internal static InternalModifyAssistantRequestToolResourcesFileSearch FromResponse(PipelineResponse response) + internal static InternalCompleteUploadRequest FromResponse(PipelineResponse response) { using var document = JsonDocument.Parse(response.Content); - return DeserializeInternalModifyAssistantRequestToolResourcesFileSearch(document.RootElement); + return DeserializeInternalCompleteUploadRequest(document.RootElement); } internal virtual BinaryContent ToBinaryContent() diff --git a/src/Generated/Models/InternalCompleteUploadRequest.cs b/src/Generated/Models/InternalCompleteUploadRequest.cs new file mode 100644 index 000000000..74d4d5346 --- /dev/null +++ b/src/Generated/Models/InternalCompleteUploadRequest.cs @@ -0,0 +1,35 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; + +namespace OpenAI.Files +{ + internal partial class InternalCompleteUploadRequest + { + internal IDictionary SerializedAdditionalRawData { get; set; } + public InternalCompleteUploadRequest(IEnumerable partIds) + { + Argument.AssertNotNull(partIds, nameof(partIds)); + + PartIds = partIds.ToList(); + } + + internal InternalCompleteUploadRequest(IList partIds, string md5, IDictionary serializedAdditionalRawData) + { + PartIds = partIds; + Md5 = md5; + SerializedAdditionalRawData = serializedAdditionalRawData; + } + + internal InternalCompleteUploadRequest() + { + } + + public IList PartIds { get; } + public string Md5 { get; set; } + } +} diff --git a/src/Generated/Models/InternalCreateAssistantRequestModel.cs b/src/Generated/Models/InternalCreateAssistantRequestModel.cs index dbe430270..dff777d4f 100644 --- a/src/Generated/Models/InternalCreateAssistantRequestModel.cs +++ b/src/Generated/Models/InternalCreateAssistantRequestModel.cs @@ -17,7 +17,10 @@ public InternalCreateAssistantRequestModel(string value) } private const string Gpt4oValue = "gpt-4o"; + private const string Gpt4o20240806Value = "gpt-4o-2024-08-06"; private const string Gpt4o20240513Value = "gpt-4o-2024-05-13"; + private const string Gpt4oMiniValue = "gpt-4o-mini"; + private const string Gpt4oMini20240718Value = "gpt-4o-mini-2024-07-18"; private const string Gpt4TurboValue = "gpt-4-turbo"; private const string Gpt4Turbo20240409Value = "gpt-4-turbo-2024-04-09"; private const string Gpt40125PreviewValue = "gpt-4-0125-preview"; @@ -38,7 +41,10 @@ public InternalCreateAssistantRequestModel(string value) private const string Gpt35Turbo16k0613Value = "gpt-3.5-turbo-16k-0613"; public static InternalCreateAssistantRequestModel Gpt4o { get; } = new InternalCreateAssistantRequestModel(Gpt4oValue); + public static InternalCreateAssistantRequestModel Gpt4o20240806 { get; } = new InternalCreateAssistantRequestModel(Gpt4o20240806Value); public static InternalCreateAssistantRequestModel Gpt4o20240513 { get; } = new InternalCreateAssistantRequestModel(Gpt4o20240513Value); + public static InternalCreateAssistantRequestModel Gpt4oMini { get; } = new InternalCreateAssistantRequestModel(Gpt4oMiniValue); + public static InternalCreateAssistantRequestModel Gpt4oMini20240718 { get; } = new InternalCreateAssistantRequestModel(Gpt4oMini20240718Value); public static InternalCreateAssistantRequestModel Gpt4Turbo { get; } = new InternalCreateAssistantRequestModel(Gpt4TurboValue); public static InternalCreateAssistantRequestModel Gpt4Turbo20240409 { get; } = new InternalCreateAssistantRequestModel(Gpt4Turbo20240409Value); public static InternalCreateAssistantRequestModel Gpt40125Preview { get; } = new InternalCreateAssistantRequestModel(Gpt40125PreviewValue); diff --git a/src/Generated/Models/InternalCreateAssistantRequestToolResources.Serialization.cs b/src/Generated/Models/InternalCreateAssistantRequestToolResources.Serialization.cs index 9b879c1ec..d21e16129 100644 --- a/src/Generated/Models/InternalCreateAssistantRequestToolResources.Serialization.cs +++ b/src/Generated/Models/InternalCreateAssistantRequestToolResources.Serialization.cs @@ -29,14 +29,7 @@ void IJsonModel.Write(Utf8JsonWrite if (SerializedAdditionalRawData?.ContainsKey("file_search") != true && Optional.IsDefined(FileSearch)) { writer.WritePropertyName("file_search"u8); -#if NET6_0_OR_GREATER - writer.WriteRawValue(FileSearch); -#else - using (JsonDocument document = JsonDocument.Parse(FileSearch)) - { - JsonSerializer.Serialize(writer, document.RootElement); - } -#endif + writer.WriteObjectValue(FileSearch, options); } if (SerializedAdditionalRawData != null) { @@ -81,7 +74,7 @@ internal static InternalCreateAssistantRequestToolResources DeserializeInternalC return null; } InternalCreateAssistantRequestToolResourcesCodeInterpreter codeInterpreter = default; - BinaryData fileSearch = default; + FileSearchToolResources fileSearch = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) @@ -101,7 +94,7 @@ internal static InternalCreateAssistantRequestToolResources DeserializeInternalC { continue; } - fileSearch = BinaryData.FromString(property.Value.GetRawText()); + fileSearch = FileSearchToolResources.DeserializeFileSearchToolResources(property.Value, options); continue; } if (true) diff --git a/src/Generated/Models/InternalCreateAssistantRequestToolResources.cs b/src/Generated/Models/InternalCreateAssistantRequestToolResources.cs index 4ed163de6..3ac5aa737 100644 --- a/src/Generated/Models/InternalCreateAssistantRequestToolResources.cs +++ b/src/Generated/Models/InternalCreateAssistantRequestToolResources.cs @@ -14,7 +14,7 @@ public InternalCreateAssistantRequestToolResources() { } - internal InternalCreateAssistantRequestToolResources(InternalCreateAssistantRequestToolResourcesCodeInterpreter codeInterpreter, BinaryData fileSearch, IDictionary serializedAdditionalRawData) + internal InternalCreateAssistantRequestToolResources(InternalCreateAssistantRequestToolResourcesCodeInterpreter codeInterpreter, FileSearchToolResources fileSearch, IDictionary serializedAdditionalRawData) { CodeInterpreter = codeInterpreter; FileSearch = fileSearch; @@ -22,6 +22,6 @@ internal InternalCreateAssistantRequestToolResources(InternalCreateAssistantRequ } public InternalCreateAssistantRequestToolResourcesCodeInterpreter CodeInterpreter { get; set; } - public BinaryData FileSearch { get; set; } + public FileSearchToolResources FileSearch { get; set; } } } diff --git a/src/Generated/Models/InternalCreateAssistantRequestToolResourcesFileSearchBase.cs b/src/Generated/Models/InternalCreateAssistantRequestToolResourcesFileSearchBase.cs deleted file mode 100644 index 31dff8351..000000000 --- a/src/Generated/Models/InternalCreateAssistantRequestToolResourcesFileSearchBase.cs +++ /dev/null @@ -1,22 +0,0 @@ -// - -#nullable disable - -using System; -using System.Collections.Generic; - -namespace OpenAI.Assistants -{ - internal partial class InternalCreateAssistantRequestToolResourcesFileSearchBase - { - internal IDictionary SerializedAdditionalRawData { get; set; } - public InternalCreateAssistantRequestToolResourcesFileSearchBase() - { - } - - internal InternalCreateAssistantRequestToolResourcesFileSearchBase(IDictionary serializedAdditionalRawData) - { - SerializedAdditionalRawData = serializedAdditionalRawData; - } - } -} diff --git a/src/Generated/Models/InternalCreateAssistantRequestToolResourcesFileSearchVectorStoreCreationHelpers.Serialization.cs b/src/Generated/Models/InternalCreateAssistantRequestToolResourcesFileSearchVectorStoreCreationHelpers.Serialization.cs deleted file mode 100644 index af3257e65..000000000 --- a/src/Generated/Models/InternalCreateAssistantRequestToolResourcesFileSearchVectorStoreCreationHelpers.Serialization.cs +++ /dev/null @@ -1,147 +0,0 @@ -// - -#nullable disable - -using System; -using System.ClientModel; -using System.ClientModel.Primitives; -using System.Collections.Generic; -using System.Text.Json; - -namespace OpenAI.Assistants -{ - internal partial class InternalCreateAssistantRequestToolResourcesFileSearchVectorStoreCreationHelpers : IJsonModel - { - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - if (format != "J") - { - throw new FormatException($"The model {nameof(InternalCreateAssistantRequestToolResourcesFileSearchVectorStoreCreationHelpers)} does not support writing '{format}' format."); - } - - writer.WriteStartObject(); - if (SerializedAdditionalRawData?.ContainsKey("vector_stores") != true && Optional.IsCollectionDefined(VectorStores)) - { - writer.WritePropertyName("vector_stores"u8); - writer.WriteStartArray(); - foreach (var item in VectorStores) - { - writer.WriteObjectValue(item, options); - } - writer.WriteEndArray(); - } - if (SerializedAdditionalRawData != null) - { - foreach (var item in SerializedAdditionalRawData) - { - if (ModelSerializationExtensions.IsSentinelValue(item.Value)) - { - continue; - } - writer.WritePropertyName(item.Key); -#if NET6_0_OR_GREATER - writer.WriteRawValue(item.Value); -#else - using (JsonDocument document = JsonDocument.Parse(item.Value)) - { - JsonSerializer.Serialize(writer, document.RootElement); - } -#endif - } - } - writer.WriteEndObject(); - } - - InternalCreateAssistantRequestToolResourcesFileSearchVectorStoreCreationHelpers IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - if (format != "J") - { - throw new FormatException($"The model {nameof(InternalCreateAssistantRequestToolResourcesFileSearchVectorStoreCreationHelpers)} does not support reading '{format}' format."); - } - - using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeInternalCreateAssistantRequestToolResourcesFileSearchVectorStoreCreationHelpers(document.RootElement, options); - } - - internal static InternalCreateAssistantRequestToolResourcesFileSearchVectorStoreCreationHelpers DeserializeInternalCreateAssistantRequestToolResourcesFileSearchVectorStoreCreationHelpers(JsonElement element, ModelReaderWriterOptions options = null) - { - options ??= ModelSerializationExtensions.WireOptions; - - if (element.ValueKind == JsonValueKind.Null) - { - return null; - } - IList vectorStores = default; - IDictionary serializedAdditionalRawData = default; - Dictionary rawDataDictionary = new Dictionary(); - foreach (var property in element.EnumerateObject()) - { - if (property.NameEquals("vector_stores"u8)) - { - if (property.Value.ValueKind == JsonValueKind.Null) - { - continue; - } - List array = new List(); - foreach (var item in property.Value.EnumerateArray()) - { - array.Add(VectorStoreCreationHelper.DeserializeVectorStoreCreationHelper(item, options)); - } - vectorStores = array; - continue; - } - if (true) - { - rawDataDictionary ??= new Dictionary(); - rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); - } - } - serializedAdditionalRawData = rawDataDictionary; - return new InternalCreateAssistantRequestToolResourcesFileSearchVectorStoreCreationHelpers(vectorStores ?? new ChangeTrackingList(), serializedAdditionalRawData); - } - - BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - - switch (format) - { - case "J": - return ModelReaderWriter.Write(this, options); - default: - throw new FormatException($"The model {nameof(InternalCreateAssistantRequestToolResourcesFileSearchVectorStoreCreationHelpers)} does not support writing '{options.Format}' format."); - } - } - - InternalCreateAssistantRequestToolResourcesFileSearchVectorStoreCreationHelpers IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - - switch (format) - { - case "J": - { - using JsonDocument document = JsonDocument.Parse(data); - return DeserializeInternalCreateAssistantRequestToolResourcesFileSearchVectorStoreCreationHelpers(document.RootElement, options); - } - default: - throw new FormatException($"The model {nameof(InternalCreateAssistantRequestToolResourcesFileSearchVectorStoreCreationHelpers)} does not support reading '{options.Format}' format."); - } - } - - string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; - - internal static InternalCreateAssistantRequestToolResourcesFileSearchVectorStoreCreationHelpers FromResponse(PipelineResponse response) - { - using var document = JsonDocument.Parse(response.Content); - return DeserializeInternalCreateAssistantRequestToolResourcesFileSearchVectorStoreCreationHelpers(document.RootElement); - } - - internal virtual BinaryContent ToBinaryContent() - { - return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); - } - } -} diff --git a/src/Generated/Models/InternalCreateAssistantRequestToolResourcesFileSearchVectorStoreCreationHelpers.cs b/src/Generated/Models/InternalCreateAssistantRequestToolResourcesFileSearchVectorStoreCreationHelpers.cs deleted file mode 100644 index bb2896dc6..000000000 --- a/src/Generated/Models/InternalCreateAssistantRequestToolResourcesFileSearchVectorStoreCreationHelpers.cs +++ /dev/null @@ -1,26 +0,0 @@ -// - -#nullable disable - -using System; -using System.Collections.Generic; - -namespace OpenAI.Assistants -{ - internal partial class InternalCreateAssistantRequestToolResourcesFileSearchVectorStoreCreationHelpers - { - internal IDictionary SerializedAdditionalRawData { get; set; } - public InternalCreateAssistantRequestToolResourcesFileSearchVectorStoreCreationHelpers() - { - VectorStores = new ChangeTrackingList(); - } - - internal InternalCreateAssistantRequestToolResourcesFileSearchVectorStoreCreationHelpers(IList vectorStores, IDictionary serializedAdditionalRawData) - { - VectorStores = vectorStores; - SerializedAdditionalRawData = serializedAdditionalRawData; - } - - public IList VectorStores { get; } - } -} diff --git a/src/Generated/Models/InternalCreateAssistantRequestToolResourcesFileSearchVectorStoreIdReferences.Serialization.cs b/src/Generated/Models/InternalCreateAssistantRequestToolResourcesFileSearchVectorStoreIdReferences.Serialization.cs deleted file mode 100644 index 4193507ce..000000000 --- a/src/Generated/Models/InternalCreateAssistantRequestToolResourcesFileSearchVectorStoreIdReferences.Serialization.cs +++ /dev/null @@ -1,147 +0,0 @@ -// - -#nullable disable - -using System; -using System.ClientModel; -using System.ClientModel.Primitives; -using System.Collections.Generic; -using System.Text.Json; - -namespace OpenAI.Assistants -{ - internal partial class InternalCreateAssistantRequestToolResourcesFileSearchVectorStoreIdReferences : IJsonModel - { - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - if (format != "J") - { - throw new FormatException($"The model {nameof(InternalCreateAssistantRequestToolResourcesFileSearchVectorStoreIdReferences)} does not support writing '{format}' format."); - } - - writer.WriteStartObject(); - if (SerializedAdditionalRawData?.ContainsKey("vector_store_ids") != true && Optional.IsCollectionDefined(VectorStoreIds)) - { - writer.WritePropertyName("vector_store_ids"u8); - writer.WriteStartArray(); - foreach (var item in VectorStoreIds) - { - writer.WriteStringValue(item); - } - writer.WriteEndArray(); - } - if (SerializedAdditionalRawData != null) - { - foreach (var item in SerializedAdditionalRawData) - { - if (ModelSerializationExtensions.IsSentinelValue(item.Value)) - { - continue; - } - writer.WritePropertyName(item.Key); -#if NET6_0_OR_GREATER - writer.WriteRawValue(item.Value); -#else - using (JsonDocument document = JsonDocument.Parse(item.Value)) - { - JsonSerializer.Serialize(writer, document.RootElement); - } -#endif - } - } - writer.WriteEndObject(); - } - - InternalCreateAssistantRequestToolResourcesFileSearchVectorStoreIdReferences IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - if (format != "J") - { - throw new FormatException($"The model {nameof(InternalCreateAssistantRequestToolResourcesFileSearchVectorStoreIdReferences)} does not support reading '{format}' format."); - } - - using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeInternalCreateAssistantRequestToolResourcesFileSearchVectorStoreIdReferences(document.RootElement, options); - } - - internal static InternalCreateAssistantRequestToolResourcesFileSearchVectorStoreIdReferences DeserializeInternalCreateAssistantRequestToolResourcesFileSearchVectorStoreIdReferences(JsonElement element, ModelReaderWriterOptions options = null) - { - options ??= ModelSerializationExtensions.WireOptions; - - if (element.ValueKind == JsonValueKind.Null) - { - return null; - } - IList vectorStoreIds = default; - IDictionary serializedAdditionalRawData = default; - Dictionary rawDataDictionary = new Dictionary(); - foreach (var property in element.EnumerateObject()) - { - if (property.NameEquals("vector_store_ids"u8)) - { - if (property.Value.ValueKind == JsonValueKind.Null) - { - continue; - } - List array = new List(); - foreach (var item in property.Value.EnumerateArray()) - { - array.Add(item.GetString()); - } - vectorStoreIds = array; - continue; - } - if (true) - { - rawDataDictionary ??= new Dictionary(); - rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); - } - } - serializedAdditionalRawData = rawDataDictionary; - return new InternalCreateAssistantRequestToolResourcesFileSearchVectorStoreIdReferences(vectorStoreIds ?? new ChangeTrackingList(), serializedAdditionalRawData); - } - - BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - - switch (format) - { - case "J": - return ModelReaderWriter.Write(this, options); - default: - throw new FormatException($"The model {nameof(InternalCreateAssistantRequestToolResourcesFileSearchVectorStoreIdReferences)} does not support writing '{options.Format}' format."); - } - } - - InternalCreateAssistantRequestToolResourcesFileSearchVectorStoreIdReferences IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - - switch (format) - { - case "J": - { - using JsonDocument document = JsonDocument.Parse(data); - return DeserializeInternalCreateAssistantRequestToolResourcesFileSearchVectorStoreIdReferences(document.RootElement, options); - } - default: - throw new FormatException($"The model {nameof(InternalCreateAssistantRequestToolResourcesFileSearchVectorStoreIdReferences)} does not support reading '{options.Format}' format."); - } - } - - string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; - - internal static InternalCreateAssistantRequestToolResourcesFileSearchVectorStoreIdReferences FromResponse(PipelineResponse response) - { - using var document = JsonDocument.Parse(response.Content); - return DeserializeInternalCreateAssistantRequestToolResourcesFileSearchVectorStoreIdReferences(document.RootElement); - } - - internal virtual BinaryContent ToBinaryContent() - { - return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); - } - } -} diff --git a/src/Generated/Models/InternalCreateAssistantRequestToolResourcesFileSearchVectorStoreIdReferences.cs b/src/Generated/Models/InternalCreateAssistantRequestToolResourcesFileSearchVectorStoreIdReferences.cs deleted file mode 100644 index ba6da6ac4..000000000 --- a/src/Generated/Models/InternalCreateAssistantRequestToolResourcesFileSearchVectorStoreIdReferences.cs +++ /dev/null @@ -1,26 +0,0 @@ -// - -#nullable disable - -using System; -using System.Collections.Generic; - -namespace OpenAI.Assistants -{ - internal partial class InternalCreateAssistantRequestToolResourcesFileSearchVectorStoreIdReferences - { - internal IDictionary SerializedAdditionalRawData { get; set; } - public InternalCreateAssistantRequestToolResourcesFileSearchVectorStoreIdReferences() - { - VectorStoreIds = new ChangeTrackingList(); - } - - internal InternalCreateAssistantRequestToolResourcesFileSearchVectorStoreIdReferences(IList vectorStoreIds, IDictionary serializedAdditionalRawData) - { - VectorStoreIds = vectorStoreIds; - SerializedAdditionalRawData = serializedAdditionalRawData; - } - - public IList VectorStoreIds { get; } - } -} diff --git a/src/Generated/Models/InternalCreateChatCompletionRequestModel.cs b/src/Generated/Models/InternalCreateChatCompletionRequestModel.cs index 3ee5bd5d5..4b14c7809 100644 --- a/src/Generated/Models/InternalCreateChatCompletionRequestModel.cs +++ b/src/Generated/Models/InternalCreateChatCompletionRequestModel.cs @@ -18,6 +18,10 @@ public InternalCreateChatCompletionRequestModel(string value) private const string Gpt4oValue = "gpt-4o"; private const string Gpt4o20240513Value = "gpt-4o-2024-05-13"; + private const string Gpt4o20240806Value = "gpt-4o-2024-08-06"; + private const string Chatgpt4oLatestValue = "chatgpt-4o-latest"; + private const string Gpt4oMiniValue = "gpt-4o-mini"; + private const string Gpt4oMini20240718Value = "gpt-4o-mini-2024-07-18"; private const string Gpt4TurboValue = "gpt-4-turbo"; private const string Gpt4Turbo20240409Value = "gpt-4-turbo-2024-04-09"; private const string Gpt40125PreviewValue = "gpt-4-0125-preview"; @@ -40,6 +44,10 @@ public InternalCreateChatCompletionRequestModel(string value) public static InternalCreateChatCompletionRequestModel Gpt4o { get; } = new InternalCreateChatCompletionRequestModel(Gpt4oValue); public static InternalCreateChatCompletionRequestModel Gpt4o20240513 { get; } = new InternalCreateChatCompletionRequestModel(Gpt4o20240513Value); + public static InternalCreateChatCompletionRequestModel Gpt4o20240806 { get; } = new InternalCreateChatCompletionRequestModel(Gpt4o20240806Value); + public static InternalCreateChatCompletionRequestModel Chatgpt4oLatest { get; } = new InternalCreateChatCompletionRequestModel(Chatgpt4oLatestValue); + public static InternalCreateChatCompletionRequestModel Gpt4oMini { get; } = new InternalCreateChatCompletionRequestModel(Gpt4oMiniValue); + public static InternalCreateChatCompletionRequestModel Gpt4oMini20240718 { get; } = new InternalCreateChatCompletionRequestModel(Gpt4oMini20240718Value); public static InternalCreateChatCompletionRequestModel Gpt4Turbo { get; } = new InternalCreateChatCompletionRequestModel(Gpt4TurboValue); public static InternalCreateChatCompletionRequestModel Gpt4Turbo20240409 { get; } = new InternalCreateChatCompletionRequestModel(Gpt4Turbo20240409Value); public static InternalCreateChatCompletionRequestModel Gpt40125Preview { get; } = new InternalCreateChatCompletionRequestModel(Gpt40125PreviewValue); diff --git a/src/Generated/Models/InternalCreateChatCompletionRequestResponseFormatType.cs b/src/Generated/Models/InternalCreateChatCompletionRequestResponseFormatType.cs deleted file mode 100644 index 535b6a509..000000000 --- a/src/Generated/Models/InternalCreateChatCompletionRequestResponseFormatType.cs +++ /dev/null @@ -1,36 +0,0 @@ -// - -#nullable disable - -using System; -using System.ComponentModel; - -namespace OpenAI.Chat -{ - internal readonly partial struct InternalCreateChatCompletionRequestResponseFormatType : IEquatable - { - private readonly string _value; - - public InternalCreateChatCompletionRequestResponseFormatType(string value) - { - _value = value ?? throw new ArgumentNullException(nameof(value)); - } - - private const string TextValue = "text"; - private const string JsonObjectValue = "json_object"; - - public static InternalCreateChatCompletionRequestResponseFormatType Text { get; } = new InternalCreateChatCompletionRequestResponseFormatType(TextValue); - public static InternalCreateChatCompletionRequestResponseFormatType JsonObject { get; } = new InternalCreateChatCompletionRequestResponseFormatType(JsonObjectValue); - public static bool operator ==(InternalCreateChatCompletionRequestResponseFormatType left, InternalCreateChatCompletionRequestResponseFormatType right) => left.Equals(right); - public static bool operator !=(InternalCreateChatCompletionRequestResponseFormatType left, InternalCreateChatCompletionRequestResponseFormatType right) => !left.Equals(right); - public static implicit operator InternalCreateChatCompletionRequestResponseFormatType(string value) => new InternalCreateChatCompletionRequestResponseFormatType(value); - - [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals(object obj) => obj is InternalCreateChatCompletionRequestResponseFormatType other && Equals(other); - public bool Equals(InternalCreateChatCompletionRequestResponseFormatType other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); - - [EditorBrowsable(EditorBrowsableState.Never)] - public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; - public override string ToString() => _value; - } -} diff --git a/src/Generated/Models/InternalCreateChatCompletionRequestServiceTier.cs b/src/Generated/Models/InternalCreateChatCompletionRequestServiceTier.cs new file mode 100644 index 000000000..7d6f7f657 --- /dev/null +++ b/src/Generated/Models/InternalCreateChatCompletionRequestServiceTier.cs @@ -0,0 +1,36 @@ +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace OpenAI.Chat +{ + internal readonly partial struct InternalCreateChatCompletionRequestServiceTier : IEquatable + { + private readonly string _value; + + public InternalCreateChatCompletionRequestServiceTier(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string AutoValue = "auto"; + private const string DefaultValue = "default"; + + public static InternalCreateChatCompletionRequestServiceTier Auto { get; } = new InternalCreateChatCompletionRequestServiceTier(AutoValue); + public static InternalCreateChatCompletionRequestServiceTier Default { get; } = new InternalCreateChatCompletionRequestServiceTier(DefaultValue); + public static bool operator ==(InternalCreateChatCompletionRequestServiceTier left, InternalCreateChatCompletionRequestServiceTier right) => left.Equals(right); + public static bool operator !=(InternalCreateChatCompletionRequestServiceTier left, InternalCreateChatCompletionRequestServiceTier right) => !left.Equals(right); + public static implicit operator InternalCreateChatCompletionRequestServiceTier(string value) => new InternalCreateChatCompletionRequestServiceTier(value); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is InternalCreateChatCompletionRequestServiceTier other && Equals(other); + public bool Equals(InternalCreateChatCompletionRequestServiceTier other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; + public override string ToString() => _value; + } +} diff --git a/src/Generated/Models/InternalCreateChatCompletionResponseChoiceLogprobs.Serialization.cs b/src/Generated/Models/InternalCreateChatCompletionResponseChoiceLogprobs.Serialization.cs index db61936aa..1fee709bf 100644 --- a/src/Generated/Models/InternalCreateChatCompletionResponseChoiceLogprobs.Serialization.cs +++ b/src/Generated/Models/InternalCreateChatCompletionResponseChoiceLogprobs.Serialization.cs @@ -38,6 +38,23 @@ void IJsonModel.Write(Utf8Js writer.WriteNull("content"); } } + if (SerializedAdditionalRawData?.ContainsKey("refusal") != true) + { + if (Refusal != null && Optional.IsCollectionDefined(Refusal)) + { + writer.WritePropertyName("refusal"u8); + writer.WriteStartArray(); + foreach (var item in Refusal) + { + writer.WriteObjectValue(item, options); + } + writer.WriteEndArray(); + } + else + { + writer.WriteNull("refusal"); + } + } if (SerializedAdditionalRawData != null) { foreach (var item in SerializedAdditionalRawData) @@ -81,6 +98,7 @@ internal static InternalCreateChatCompletionResponseChoiceLogprobs DeserializeIn return null; } IReadOnlyList content = default; + IReadOnlyList refusal = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) @@ -100,6 +118,21 @@ internal static InternalCreateChatCompletionResponseChoiceLogprobs DeserializeIn content = array; continue; } + if (property.NameEquals("refusal"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + refusal = new ChangeTrackingList(); + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(ChatTokenLogProbabilityInfo.DeserializeChatTokenLogProbabilityInfo(item, options)); + } + refusal = array; + continue; + } if (true) { rawDataDictionary ??= new Dictionary(); @@ -107,7 +140,7 @@ internal static InternalCreateChatCompletionResponseChoiceLogprobs DeserializeIn } } serializedAdditionalRawData = rawDataDictionary; - return new InternalCreateChatCompletionResponseChoiceLogprobs(content, serializedAdditionalRawData); + return new InternalCreateChatCompletionResponseChoiceLogprobs(content, refusal, serializedAdditionalRawData); } BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) diff --git a/src/Generated/Models/InternalCreateChatCompletionResponseChoiceLogprobs.cs b/src/Generated/Models/InternalCreateChatCompletionResponseChoiceLogprobs.cs index d81088a5c..a03030ec2 100644 --- a/src/Generated/Models/InternalCreateChatCompletionResponseChoiceLogprobs.cs +++ b/src/Generated/Models/InternalCreateChatCompletionResponseChoiceLogprobs.cs @@ -11,14 +11,16 @@ namespace OpenAI.Chat internal partial class InternalCreateChatCompletionResponseChoiceLogprobs { internal IDictionary SerializedAdditionalRawData { get; set; } - internal InternalCreateChatCompletionResponseChoiceLogprobs(IEnumerable content) + internal InternalCreateChatCompletionResponseChoiceLogprobs(IEnumerable content, IEnumerable refusal) { Content = content?.ToList(); + Refusal = refusal?.ToList(); } - internal InternalCreateChatCompletionResponseChoiceLogprobs(IReadOnlyList content, IDictionary serializedAdditionalRawData) + internal InternalCreateChatCompletionResponseChoiceLogprobs(IReadOnlyList content, IReadOnlyList refusal, IDictionary serializedAdditionalRawData) { Content = content; + Refusal = refusal; SerializedAdditionalRawData = serializedAdditionalRawData; } @@ -27,5 +29,6 @@ internal InternalCreateChatCompletionResponseChoiceLogprobs() } public IReadOnlyList Content { get; } + public IReadOnlyList Refusal { get; } } } diff --git a/src/Generated/Models/InternalCreateChatCompletionResponseServiceTier.cs b/src/Generated/Models/InternalCreateChatCompletionResponseServiceTier.cs new file mode 100644 index 000000000..599297be0 --- /dev/null +++ b/src/Generated/Models/InternalCreateChatCompletionResponseServiceTier.cs @@ -0,0 +1,36 @@ +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace OpenAI.Chat +{ + internal readonly partial struct InternalCreateChatCompletionResponseServiceTier : IEquatable + { + private readonly string _value; + + public InternalCreateChatCompletionResponseServiceTier(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string ScaleValue = "scale"; + private const string DefaultValue = "default"; + + public static InternalCreateChatCompletionResponseServiceTier Scale { get; } = new InternalCreateChatCompletionResponseServiceTier(ScaleValue); + public static InternalCreateChatCompletionResponseServiceTier Default { get; } = new InternalCreateChatCompletionResponseServiceTier(DefaultValue); + public static bool operator ==(InternalCreateChatCompletionResponseServiceTier left, InternalCreateChatCompletionResponseServiceTier right) => left.Equals(right); + public static bool operator !=(InternalCreateChatCompletionResponseServiceTier left, InternalCreateChatCompletionResponseServiceTier right) => !left.Equals(right); + public static implicit operator InternalCreateChatCompletionResponseServiceTier(string value) => new InternalCreateChatCompletionResponseServiceTier(value); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is InternalCreateChatCompletionResponseServiceTier other && Equals(other); + public bool Equals(InternalCreateChatCompletionResponseServiceTier other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; + public override string ToString() => _value; + } +} diff --git a/src/Generated/Models/InternalCreateChatCompletionStreamResponseChoiceLogprobs.Serialization.cs b/src/Generated/Models/InternalCreateChatCompletionStreamResponseChoiceLogprobs.Serialization.cs index 28f81317f..43ebedfc9 100644 --- a/src/Generated/Models/InternalCreateChatCompletionStreamResponseChoiceLogprobs.Serialization.cs +++ b/src/Generated/Models/InternalCreateChatCompletionStreamResponseChoiceLogprobs.Serialization.cs @@ -38,6 +38,23 @@ void IJsonModel.Write( writer.WriteNull("content"); } } + if (SerializedAdditionalRawData?.ContainsKey("refusal") != true) + { + if (Refusal != null && Optional.IsCollectionDefined(Refusal)) + { + writer.WritePropertyName("refusal"u8); + writer.WriteStartArray(); + foreach (var item in Refusal) + { + writer.WriteObjectValue(item, options); + } + writer.WriteEndArray(); + } + else + { + writer.WriteNull("refusal"); + } + } if (SerializedAdditionalRawData != null) { foreach (var item in SerializedAdditionalRawData) @@ -81,6 +98,7 @@ internal static InternalCreateChatCompletionStreamResponseChoiceLogprobs Deseria return null; } IReadOnlyList content = default; + IReadOnlyList refusal = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) @@ -100,6 +118,21 @@ internal static InternalCreateChatCompletionStreamResponseChoiceLogprobs Deseria content = array; continue; } + if (property.NameEquals("refusal"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + refusal = new ChangeTrackingList(); + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(ChatTokenLogProbabilityInfo.DeserializeChatTokenLogProbabilityInfo(item, options)); + } + refusal = array; + continue; + } if (true) { rawDataDictionary ??= new Dictionary(); @@ -107,7 +140,7 @@ internal static InternalCreateChatCompletionStreamResponseChoiceLogprobs Deseria } } serializedAdditionalRawData = rawDataDictionary; - return new InternalCreateChatCompletionStreamResponseChoiceLogprobs(content, serializedAdditionalRawData); + return new InternalCreateChatCompletionStreamResponseChoiceLogprobs(content, refusal, serializedAdditionalRawData); } BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) diff --git a/src/Generated/Models/InternalCreateChatCompletionStreamResponseChoiceLogprobs.cs b/src/Generated/Models/InternalCreateChatCompletionStreamResponseChoiceLogprobs.cs index f0a780dd9..03a852399 100644 --- a/src/Generated/Models/InternalCreateChatCompletionStreamResponseChoiceLogprobs.cs +++ b/src/Generated/Models/InternalCreateChatCompletionStreamResponseChoiceLogprobs.cs @@ -11,14 +11,16 @@ namespace OpenAI.Chat internal partial class InternalCreateChatCompletionStreamResponseChoiceLogprobs { internal IDictionary SerializedAdditionalRawData { get; set; } - internal InternalCreateChatCompletionStreamResponseChoiceLogprobs(IEnumerable content) + internal InternalCreateChatCompletionStreamResponseChoiceLogprobs(IEnumerable content, IEnumerable refusal) { Content = content?.ToList(); + Refusal = refusal?.ToList(); } - internal InternalCreateChatCompletionStreamResponseChoiceLogprobs(IReadOnlyList content, IDictionary serializedAdditionalRawData) + internal InternalCreateChatCompletionStreamResponseChoiceLogprobs(IReadOnlyList content, IReadOnlyList refusal, IDictionary serializedAdditionalRawData) { Content = content; + Refusal = refusal; SerializedAdditionalRawData = serializedAdditionalRawData; } @@ -27,5 +29,6 @@ internal InternalCreateChatCompletionStreamResponseChoiceLogprobs() } public IReadOnlyList Content { get; } + public IReadOnlyList Refusal { get; } } } diff --git a/src/Generated/Models/InternalCreateChatCompletionStreamResponseServiceTier.cs b/src/Generated/Models/InternalCreateChatCompletionStreamResponseServiceTier.cs new file mode 100644 index 000000000..0f2eb1326 --- /dev/null +++ b/src/Generated/Models/InternalCreateChatCompletionStreamResponseServiceTier.cs @@ -0,0 +1,36 @@ +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace OpenAI.Chat +{ + internal readonly partial struct InternalCreateChatCompletionStreamResponseServiceTier : IEquatable + { + private readonly string _value; + + public InternalCreateChatCompletionStreamResponseServiceTier(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string ScaleValue = "scale"; + private const string DefaultValue = "default"; + + public static InternalCreateChatCompletionStreamResponseServiceTier Scale { get; } = new InternalCreateChatCompletionStreamResponseServiceTier(ScaleValue); + public static InternalCreateChatCompletionStreamResponseServiceTier Default { get; } = new InternalCreateChatCompletionStreamResponseServiceTier(DefaultValue); + public static bool operator ==(InternalCreateChatCompletionStreamResponseServiceTier left, InternalCreateChatCompletionStreamResponseServiceTier right) => left.Equals(right); + public static bool operator !=(InternalCreateChatCompletionStreamResponseServiceTier left, InternalCreateChatCompletionStreamResponseServiceTier right) => !left.Equals(right); + public static implicit operator InternalCreateChatCompletionStreamResponseServiceTier(string value) => new InternalCreateChatCompletionStreamResponseServiceTier(value); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is InternalCreateChatCompletionStreamResponseServiceTier other && Equals(other); + public bool Equals(InternalCreateChatCompletionStreamResponseServiceTier other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; + public override string ToString() => _value; + } +} diff --git a/src/Generated/Models/InternalCreateFineTuningJobRequestHyperparametersBatchSizeChoiceEnum.cs b/src/Generated/Models/InternalCreateFineTuningJobRequestHyperparametersBatchSizeChoiceEnum.cs new file mode 100644 index 000000000..f104417d9 --- /dev/null +++ b/src/Generated/Models/InternalCreateFineTuningJobRequestHyperparametersBatchSizeChoiceEnum.cs @@ -0,0 +1,34 @@ +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace OpenAI.FineTuning +{ + internal readonly partial struct InternalCreateFineTuningJobRequestHyperparametersBatchSizeChoiceEnum : IEquatable + { + private readonly string _value; + + public InternalCreateFineTuningJobRequestHyperparametersBatchSizeChoiceEnum(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string AutoValue = "auto"; + + public static InternalCreateFineTuningJobRequestHyperparametersBatchSizeChoiceEnum Auto { get; } = new InternalCreateFineTuningJobRequestHyperparametersBatchSizeChoiceEnum(AutoValue); + public static bool operator ==(InternalCreateFineTuningJobRequestHyperparametersBatchSizeChoiceEnum left, InternalCreateFineTuningJobRequestHyperparametersBatchSizeChoiceEnum right) => left.Equals(right); + public static bool operator !=(InternalCreateFineTuningJobRequestHyperparametersBatchSizeChoiceEnum left, InternalCreateFineTuningJobRequestHyperparametersBatchSizeChoiceEnum right) => !left.Equals(right); + public static implicit operator InternalCreateFineTuningJobRequestHyperparametersBatchSizeChoiceEnum(string value) => new InternalCreateFineTuningJobRequestHyperparametersBatchSizeChoiceEnum(value); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is InternalCreateFineTuningJobRequestHyperparametersBatchSizeChoiceEnum other && Equals(other); + public bool Equals(InternalCreateFineTuningJobRequestHyperparametersBatchSizeChoiceEnum other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; + public override string ToString() => _value; + } +} diff --git a/src/Generated/Models/InternalCreateFineTuningJobRequestHyperparametersLearningRateMultiplierChoiceEnum.cs b/src/Generated/Models/InternalCreateFineTuningJobRequestHyperparametersLearningRateMultiplierChoiceEnum.cs new file mode 100644 index 000000000..9ff39cc7d --- /dev/null +++ b/src/Generated/Models/InternalCreateFineTuningJobRequestHyperparametersLearningRateMultiplierChoiceEnum.cs @@ -0,0 +1,34 @@ +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace OpenAI.FineTuning +{ + internal readonly partial struct InternalCreateFineTuningJobRequestHyperparametersLearningRateMultiplierChoiceEnum : IEquatable + { + private readonly string _value; + + public InternalCreateFineTuningJobRequestHyperparametersLearningRateMultiplierChoiceEnum(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string AutoValue = "auto"; + + public static InternalCreateFineTuningJobRequestHyperparametersLearningRateMultiplierChoiceEnum Auto { get; } = new InternalCreateFineTuningJobRequestHyperparametersLearningRateMultiplierChoiceEnum(AutoValue); + public static bool operator ==(InternalCreateFineTuningJobRequestHyperparametersLearningRateMultiplierChoiceEnum left, InternalCreateFineTuningJobRequestHyperparametersLearningRateMultiplierChoiceEnum right) => left.Equals(right); + public static bool operator !=(InternalCreateFineTuningJobRequestHyperparametersLearningRateMultiplierChoiceEnum left, InternalCreateFineTuningJobRequestHyperparametersLearningRateMultiplierChoiceEnum right) => !left.Equals(right); + public static implicit operator InternalCreateFineTuningJobRequestHyperparametersLearningRateMultiplierChoiceEnum(string value) => new InternalCreateFineTuningJobRequestHyperparametersLearningRateMultiplierChoiceEnum(value); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is InternalCreateFineTuningJobRequestHyperparametersLearningRateMultiplierChoiceEnum other && Equals(other); + public bool Equals(InternalCreateFineTuningJobRequestHyperparametersLearningRateMultiplierChoiceEnum other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; + public override string ToString() => _value; + } +} diff --git a/src/Generated/Models/InternalCreateFineTuningJobRequestHyperparametersNEpochsChoiceEnum.cs b/src/Generated/Models/InternalCreateFineTuningJobRequestHyperparametersNEpochsChoiceEnum.cs new file mode 100644 index 000000000..8fad11a4b --- /dev/null +++ b/src/Generated/Models/InternalCreateFineTuningJobRequestHyperparametersNEpochsChoiceEnum.cs @@ -0,0 +1,34 @@ +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace OpenAI.FineTuning +{ + internal readonly partial struct InternalCreateFineTuningJobRequestHyperparametersNEpochsChoiceEnum : IEquatable + { + private readonly string _value; + + public InternalCreateFineTuningJobRequestHyperparametersNEpochsChoiceEnum(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string AutoValue = "auto"; + + public static InternalCreateFineTuningJobRequestHyperparametersNEpochsChoiceEnum Auto { get; } = new InternalCreateFineTuningJobRequestHyperparametersNEpochsChoiceEnum(AutoValue); + public static bool operator ==(InternalCreateFineTuningJobRequestHyperparametersNEpochsChoiceEnum left, InternalCreateFineTuningJobRequestHyperparametersNEpochsChoiceEnum right) => left.Equals(right); + public static bool operator !=(InternalCreateFineTuningJobRequestHyperparametersNEpochsChoiceEnum left, InternalCreateFineTuningJobRequestHyperparametersNEpochsChoiceEnum right) => !left.Equals(right); + public static implicit operator InternalCreateFineTuningJobRequestHyperparametersNEpochsChoiceEnum(string value) => new InternalCreateFineTuningJobRequestHyperparametersNEpochsChoiceEnum(value); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is InternalCreateFineTuningJobRequestHyperparametersNEpochsChoiceEnum other && Equals(other); + public bool Equals(InternalCreateFineTuningJobRequestHyperparametersNEpochsChoiceEnum other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; + public override string ToString() => _value; + } +} diff --git a/src/Generated/Models/InternalCreateFineTuningJobRequestModel.cs b/src/Generated/Models/InternalCreateFineTuningJobRequestModel.cs index ad3f54906..e85d5c334 100644 --- a/src/Generated/Models/InternalCreateFineTuningJobRequestModel.cs +++ b/src/Generated/Models/InternalCreateFineTuningJobRequestModel.cs @@ -19,10 +19,12 @@ public InternalCreateFineTuningJobRequestModel(string value) private const string Babbage002Value = "babbage-002"; private const string Davinci002Value = "davinci-002"; private const string Gpt35TurboValue = "gpt-3.5-turbo"; + private const string Gpt4oMiniValue = "gpt-4o-mini"; public static InternalCreateFineTuningJobRequestModel Babbage002 { get; } = new InternalCreateFineTuningJobRequestModel(Babbage002Value); public static InternalCreateFineTuningJobRequestModel Davinci002 { get; } = new InternalCreateFineTuningJobRequestModel(Davinci002Value); public static InternalCreateFineTuningJobRequestModel Gpt35Turbo { get; } = new InternalCreateFineTuningJobRequestModel(Gpt35TurboValue); + public static InternalCreateFineTuningJobRequestModel Gpt4oMini { get; } = new InternalCreateFineTuningJobRequestModel(Gpt4oMiniValue); public static bool operator ==(InternalCreateFineTuningJobRequestModel left, InternalCreateFineTuningJobRequestModel right) => left.Equals(right); public static bool operator !=(InternalCreateFineTuningJobRequestModel left, InternalCreateFineTuningJobRequestModel right) => !left.Equals(right); public static implicit operator InternalCreateFineTuningJobRequestModel(string value) => new InternalCreateFineTuningJobRequestModel(value); diff --git a/src/Generated/Models/InternalCreateRunRequestModel.cs b/src/Generated/Models/InternalCreateRunRequestModel.cs index 56b07d83d..27b73a31b 100644 --- a/src/Generated/Models/InternalCreateRunRequestModel.cs +++ b/src/Generated/Models/InternalCreateRunRequestModel.cs @@ -17,7 +17,10 @@ public InternalCreateRunRequestModel(string value) } private const string Gpt4oValue = "gpt-4o"; + private const string Gpt4o20240806Value = "gpt-4o-2024-08-06"; private const string Gpt4o20240513Value = "gpt-4o-2024-05-13"; + private const string Gpt4oMiniValue = "gpt-4o-mini"; + private const string Gpt4oMini20240718Value = "gpt-4o-mini-2024-07-18"; private const string Gpt4TurboValue = "gpt-4-turbo"; private const string Gpt4Turbo20240409Value = "gpt-4-turbo-2024-04-09"; private const string Gpt40125PreviewValue = "gpt-4-0125-preview"; @@ -38,7 +41,10 @@ public InternalCreateRunRequestModel(string value) private const string Gpt35Turbo16k0613Value = "gpt-3.5-turbo-16k-0613"; public static InternalCreateRunRequestModel Gpt4o { get; } = new InternalCreateRunRequestModel(Gpt4oValue); + public static InternalCreateRunRequestModel Gpt4o20240806 { get; } = new InternalCreateRunRequestModel(Gpt4o20240806Value); public static InternalCreateRunRequestModel Gpt4o20240513 { get; } = new InternalCreateRunRequestModel(Gpt4o20240513Value); + public static InternalCreateRunRequestModel Gpt4oMini { get; } = new InternalCreateRunRequestModel(Gpt4oMiniValue); + public static InternalCreateRunRequestModel Gpt4oMini20240718 { get; } = new InternalCreateRunRequestModel(Gpt4oMini20240718Value); public static InternalCreateRunRequestModel Gpt4Turbo { get; } = new InternalCreateRunRequestModel(Gpt4TurboValue); public static InternalCreateRunRequestModel Gpt4Turbo20240409 { get; } = new InternalCreateRunRequestModel(Gpt4Turbo20240409Value); public static InternalCreateRunRequestModel Gpt40125Preview { get; } = new InternalCreateRunRequestModel(Gpt40125PreviewValue); diff --git a/src/Generated/Models/InternalCreateThreadAndRunRequestModel.cs b/src/Generated/Models/InternalCreateThreadAndRunRequestModel.cs index ecabe34e7..04d84a623 100644 --- a/src/Generated/Models/InternalCreateThreadAndRunRequestModel.cs +++ b/src/Generated/Models/InternalCreateThreadAndRunRequestModel.cs @@ -17,7 +17,10 @@ public InternalCreateThreadAndRunRequestModel(string value) } private const string Gpt4oValue = "gpt-4o"; + private const string Gpt4o20240806Value = "gpt-4o-2024-08-06"; private const string Gpt4o20240513Value = "gpt-4o-2024-05-13"; + private const string Gpt4oMiniValue = "gpt-4o-mini"; + private const string Gpt4oMini20240718Value = "gpt-4o-mini-2024-07-18"; private const string Gpt4TurboValue = "gpt-4-turbo"; private const string Gpt4Turbo20240409Value = "gpt-4-turbo-2024-04-09"; private const string Gpt40125PreviewValue = "gpt-4-0125-preview"; @@ -38,7 +41,10 @@ public InternalCreateThreadAndRunRequestModel(string value) private const string Gpt35Turbo16k0613Value = "gpt-3.5-turbo-16k-0613"; public static InternalCreateThreadAndRunRequestModel Gpt4o { get; } = new InternalCreateThreadAndRunRequestModel(Gpt4oValue); + public static InternalCreateThreadAndRunRequestModel Gpt4o20240806 { get; } = new InternalCreateThreadAndRunRequestModel(Gpt4o20240806Value); public static InternalCreateThreadAndRunRequestModel Gpt4o20240513 { get; } = new InternalCreateThreadAndRunRequestModel(Gpt4o20240513Value); + public static InternalCreateThreadAndRunRequestModel Gpt4oMini { get; } = new InternalCreateThreadAndRunRequestModel(Gpt4oMiniValue); + public static InternalCreateThreadAndRunRequestModel Gpt4oMini20240718 { get; } = new InternalCreateThreadAndRunRequestModel(Gpt4oMini20240718Value); public static InternalCreateThreadAndRunRequestModel Gpt4Turbo { get; } = new InternalCreateThreadAndRunRequestModel(Gpt4TurboValue); public static InternalCreateThreadAndRunRequestModel Gpt4Turbo20240409 { get; } = new InternalCreateThreadAndRunRequestModel(Gpt4Turbo20240409Value); public static InternalCreateThreadAndRunRequestModel Gpt40125Preview { get; } = new InternalCreateThreadAndRunRequestModel(Gpt40125PreviewValue); diff --git a/src/Generated/Models/InternalCreateThreadAndRunRequestResponseFormat.cs b/src/Generated/Models/InternalCreateThreadAndRunRequestResponseFormat.cs deleted file mode 100644 index e268b7603..000000000 --- a/src/Generated/Models/InternalCreateThreadAndRunRequestResponseFormat.cs +++ /dev/null @@ -1,36 +0,0 @@ -// - -#nullable disable - -using System; -using System.ComponentModel; - -namespace OpenAI.Assistants -{ - internal readonly partial struct InternalCreateThreadAndRunRequestResponseFormat : IEquatable - { - private readonly string _value; - - public InternalCreateThreadAndRunRequestResponseFormat(string value) - { - _value = value ?? throw new ArgumentNullException(nameof(value)); - } - - private const string NoneValue = "none"; - private const string AutoValue = "auto"; - - public static InternalCreateThreadAndRunRequestResponseFormat None { get; } = new InternalCreateThreadAndRunRequestResponseFormat(NoneValue); - public static InternalCreateThreadAndRunRequestResponseFormat Auto { get; } = new InternalCreateThreadAndRunRequestResponseFormat(AutoValue); - public static bool operator ==(InternalCreateThreadAndRunRequestResponseFormat left, InternalCreateThreadAndRunRequestResponseFormat right) => left.Equals(right); - public static bool operator !=(InternalCreateThreadAndRunRequestResponseFormat left, InternalCreateThreadAndRunRequestResponseFormat right) => !left.Equals(right); - public static implicit operator InternalCreateThreadAndRunRequestResponseFormat(string value) => new InternalCreateThreadAndRunRequestResponseFormat(value); - - [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals(object obj) => obj is InternalCreateThreadAndRunRequestResponseFormat other && Equals(other); - public bool Equals(InternalCreateThreadAndRunRequestResponseFormat other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); - - [EditorBrowsable(EditorBrowsableState.Never)] - public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; - public override string ToString() => _value; - } -} diff --git a/src/Generated/Models/InternalCreateThreadAndRunRequestToolResources.Serialization.cs b/src/Generated/Models/InternalCreateThreadAndRunRequestToolResources.Serialization.cs index 3e3112c91..aff6e9e50 100644 --- a/src/Generated/Models/InternalCreateThreadAndRunRequestToolResources.Serialization.cs +++ b/src/Generated/Models/InternalCreateThreadAndRunRequestToolResources.Serialization.cs @@ -74,7 +74,7 @@ internal static InternalCreateThreadAndRunRequestToolResources DeserializeIntern return null; } InternalCreateThreadAndRunRequestToolResourcesCodeInterpreter codeInterpreter = default; - InternalCreateThreadAndRunRequestToolResourcesFileSearch fileSearch = default; + InternalToolResourcesFileSearchIdsOnly fileSearch = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) @@ -94,7 +94,7 @@ internal static InternalCreateThreadAndRunRequestToolResources DeserializeIntern { continue; } - fileSearch = InternalCreateThreadAndRunRequestToolResourcesFileSearch.DeserializeInternalCreateThreadAndRunRequestToolResourcesFileSearch(property.Value, options); + fileSearch = InternalToolResourcesFileSearchIdsOnly.DeserializeInternalToolResourcesFileSearchIdsOnly(property.Value, options); continue; } if (true) diff --git a/src/Generated/Models/InternalCreateThreadAndRunRequestToolResources.cs b/src/Generated/Models/InternalCreateThreadAndRunRequestToolResources.cs index 452a48065..a07a484a3 100644 --- a/src/Generated/Models/InternalCreateThreadAndRunRequestToolResources.cs +++ b/src/Generated/Models/InternalCreateThreadAndRunRequestToolResources.cs @@ -14,7 +14,7 @@ public InternalCreateThreadAndRunRequestToolResources() { } - internal InternalCreateThreadAndRunRequestToolResources(InternalCreateThreadAndRunRequestToolResourcesCodeInterpreter codeInterpreter, InternalCreateThreadAndRunRequestToolResourcesFileSearch fileSearch, IDictionary serializedAdditionalRawData) + internal InternalCreateThreadAndRunRequestToolResources(InternalCreateThreadAndRunRequestToolResourcesCodeInterpreter codeInterpreter, InternalToolResourcesFileSearchIdsOnly fileSearch, IDictionary serializedAdditionalRawData) { CodeInterpreter = codeInterpreter; FileSearch = fileSearch; @@ -22,6 +22,6 @@ internal InternalCreateThreadAndRunRequestToolResources(InternalCreateThreadAndR } public InternalCreateThreadAndRunRequestToolResourcesCodeInterpreter CodeInterpreter { get; set; } - public InternalCreateThreadAndRunRequestToolResourcesFileSearch FileSearch { get; set; } + public InternalToolResourcesFileSearchIdsOnly FileSearch { get; set; } } } diff --git a/src/Generated/Models/InternalCreateThreadAndRunRequestToolResourcesFileSearch.Serialization.cs b/src/Generated/Models/InternalCreateThreadAndRunRequestToolResourcesFileSearch.Serialization.cs deleted file mode 100644 index 32a57d4a3..000000000 --- a/src/Generated/Models/InternalCreateThreadAndRunRequestToolResourcesFileSearch.Serialization.cs +++ /dev/null @@ -1,147 +0,0 @@ -// - -#nullable disable - -using System; -using System.ClientModel; -using System.ClientModel.Primitives; -using System.Collections.Generic; -using System.Text.Json; - -namespace OpenAI.Assistants -{ - internal partial class InternalCreateThreadAndRunRequestToolResourcesFileSearch : IJsonModel - { - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - if (format != "J") - { - throw new FormatException($"The model {nameof(InternalCreateThreadAndRunRequestToolResourcesFileSearch)} does not support writing '{format}' format."); - } - - writer.WriteStartObject(); - if (SerializedAdditionalRawData?.ContainsKey("vector_store_ids") != true && Optional.IsCollectionDefined(VectorStoreIds)) - { - writer.WritePropertyName("vector_store_ids"u8); - writer.WriteStartArray(); - foreach (var item in VectorStoreIds) - { - writer.WriteStringValue(item); - } - writer.WriteEndArray(); - } - if (SerializedAdditionalRawData != null) - { - foreach (var item in SerializedAdditionalRawData) - { - if (ModelSerializationExtensions.IsSentinelValue(item.Value)) - { - continue; - } - writer.WritePropertyName(item.Key); -#if NET6_0_OR_GREATER - writer.WriteRawValue(item.Value); -#else - using (JsonDocument document = JsonDocument.Parse(item.Value)) - { - JsonSerializer.Serialize(writer, document.RootElement); - } -#endif - } - } - writer.WriteEndObject(); - } - - InternalCreateThreadAndRunRequestToolResourcesFileSearch IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - if (format != "J") - { - throw new FormatException($"The model {nameof(InternalCreateThreadAndRunRequestToolResourcesFileSearch)} does not support reading '{format}' format."); - } - - using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeInternalCreateThreadAndRunRequestToolResourcesFileSearch(document.RootElement, options); - } - - internal static InternalCreateThreadAndRunRequestToolResourcesFileSearch DeserializeInternalCreateThreadAndRunRequestToolResourcesFileSearch(JsonElement element, ModelReaderWriterOptions options = null) - { - options ??= ModelSerializationExtensions.WireOptions; - - if (element.ValueKind == JsonValueKind.Null) - { - return null; - } - IList vectorStoreIds = default; - IDictionary serializedAdditionalRawData = default; - Dictionary rawDataDictionary = new Dictionary(); - foreach (var property in element.EnumerateObject()) - { - if (property.NameEquals("vector_store_ids"u8)) - { - if (property.Value.ValueKind == JsonValueKind.Null) - { - continue; - } - List array = new List(); - foreach (var item in property.Value.EnumerateArray()) - { - array.Add(item.GetString()); - } - vectorStoreIds = array; - continue; - } - if (true) - { - rawDataDictionary ??= new Dictionary(); - rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); - } - } - serializedAdditionalRawData = rawDataDictionary; - return new InternalCreateThreadAndRunRequestToolResourcesFileSearch(vectorStoreIds ?? new ChangeTrackingList(), serializedAdditionalRawData); - } - - BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - - switch (format) - { - case "J": - return ModelReaderWriter.Write(this, options); - default: - throw new FormatException($"The model {nameof(InternalCreateThreadAndRunRequestToolResourcesFileSearch)} does not support writing '{options.Format}' format."); - } - } - - InternalCreateThreadAndRunRequestToolResourcesFileSearch IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - - switch (format) - { - case "J": - { - using JsonDocument document = JsonDocument.Parse(data); - return DeserializeInternalCreateThreadAndRunRequestToolResourcesFileSearch(document.RootElement, options); - } - default: - throw new FormatException($"The model {nameof(InternalCreateThreadAndRunRequestToolResourcesFileSearch)} does not support reading '{options.Format}' format."); - } - } - - string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; - - internal static InternalCreateThreadAndRunRequestToolResourcesFileSearch FromResponse(PipelineResponse response) - { - using var document = JsonDocument.Parse(response.Content); - return DeserializeInternalCreateThreadAndRunRequestToolResourcesFileSearch(document.RootElement); - } - - internal virtual BinaryContent ToBinaryContent() - { - return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); - } - } -} diff --git a/src/Generated/Models/InternalCreateThreadAndRunRequestToolResourcesFileSearch.cs b/src/Generated/Models/InternalCreateThreadAndRunRequestToolResourcesFileSearch.cs deleted file mode 100644 index 5a5c4b1f1..000000000 --- a/src/Generated/Models/InternalCreateThreadAndRunRequestToolResourcesFileSearch.cs +++ /dev/null @@ -1,26 +0,0 @@ -// - -#nullable disable - -using System; -using System.Collections.Generic; - -namespace OpenAI.Assistants -{ - internal partial class InternalCreateThreadAndRunRequestToolResourcesFileSearch - { - internal IDictionary SerializedAdditionalRawData { get; set; } - public InternalCreateThreadAndRunRequestToolResourcesFileSearch() - { - VectorStoreIds = new ChangeTrackingList(); - } - - internal InternalCreateThreadAndRunRequestToolResourcesFileSearch(IList vectorStoreIds, IDictionary serializedAdditionalRawData) - { - VectorStoreIds = vectorStoreIds; - SerializedAdditionalRawData = serializedAdditionalRawData; - } - - public IList VectorStoreIds { get; } - } -} diff --git a/src/Generated/Models/InternalCreateThreadRequestToolResources.Serialization.cs b/src/Generated/Models/InternalCreateThreadRequestToolResources.Serialization.cs index 24c1889b5..39b6689b2 100644 --- a/src/Generated/Models/InternalCreateThreadRequestToolResources.Serialization.cs +++ b/src/Generated/Models/InternalCreateThreadRequestToolResources.Serialization.cs @@ -29,14 +29,7 @@ void IJsonModel.Write(Utf8JsonWriter w if (SerializedAdditionalRawData?.ContainsKey("file_search") != true && Optional.IsDefined(FileSearch)) { writer.WritePropertyName("file_search"u8); -#if NET6_0_OR_GREATER - writer.WriteRawValue(FileSearch); -#else - using (JsonDocument document = JsonDocument.Parse(FileSearch)) - { - JsonSerializer.Serialize(writer, document.RootElement); - } -#endif + writer.WriteObjectValue(FileSearch, options); } if (SerializedAdditionalRawData != null) { @@ -81,7 +74,7 @@ internal static InternalCreateThreadRequestToolResources DeserializeInternalCrea return null; } InternalCreateThreadRequestToolResourcesCodeInterpreter codeInterpreter = default; - BinaryData fileSearch = default; + FileSearchToolResources fileSearch = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) @@ -101,7 +94,7 @@ internal static InternalCreateThreadRequestToolResources DeserializeInternalCrea { continue; } - fileSearch = BinaryData.FromString(property.Value.GetRawText()); + fileSearch = FileSearchToolResources.DeserializeFileSearchToolResources(property.Value, options); continue; } if (true) diff --git a/src/Generated/Models/InternalCreateThreadRequestToolResources.cs b/src/Generated/Models/InternalCreateThreadRequestToolResources.cs index ca16742e9..08a68fce1 100644 --- a/src/Generated/Models/InternalCreateThreadRequestToolResources.cs +++ b/src/Generated/Models/InternalCreateThreadRequestToolResources.cs @@ -14,7 +14,7 @@ public InternalCreateThreadRequestToolResources() { } - internal InternalCreateThreadRequestToolResources(InternalCreateThreadRequestToolResourcesCodeInterpreter codeInterpreter, BinaryData fileSearch, IDictionary serializedAdditionalRawData) + internal InternalCreateThreadRequestToolResources(InternalCreateThreadRequestToolResourcesCodeInterpreter codeInterpreter, FileSearchToolResources fileSearch, IDictionary serializedAdditionalRawData) { CodeInterpreter = codeInterpreter; FileSearch = fileSearch; @@ -22,6 +22,6 @@ internal InternalCreateThreadRequestToolResources(InternalCreateThreadRequestToo } public InternalCreateThreadRequestToolResourcesCodeInterpreter CodeInterpreter { get; set; } - public BinaryData FileSearch { get; set; } + public FileSearchToolResources FileSearch { get; set; } } } diff --git a/src/Generated/Models/InternalCreateThreadRequestToolResourcesFileSearchVectorStoreCreationHelpers.Serialization.cs b/src/Generated/Models/InternalCreateThreadRequestToolResourcesFileSearchVectorStoreCreationHelpers.Serialization.cs deleted file mode 100644 index a158ff57a..000000000 --- a/src/Generated/Models/InternalCreateThreadRequestToolResourcesFileSearchVectorStoreCreationHelpers.Serialization.cs +++ /dev/null @@ -1,147 +0,0 @@ -// - -#nullable disable - -using System; -using System.ClientModel; -using System.ClientModel.Primitives; -using System.Collections.Generic; -using System.Text.Json; - -namespace OpenAI.Assistants -{ - internal partial class InternalCreateThreadRequestToolResourcesFileSearchVectorStoreCreationHelpers : IJsonModel - { - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - if (format != "J") - { - throw new FormatException($"The model {nameof(InternalCreateThreadRequestToolResourcesFileSearchVectorStoreCreationHelpers)} does not support writing '{format}' format."); - } - - writer.WriteStartObject(); - if (SerializedAdditionalRawData?.ContainsKey("vector_stores") != true && Optional.IsCollectionDefined(VectorStores)) - { - writer.WritePropertyName("vector_stores"u8); - writer.WriteStartArray(); - foreach (var item in VectorStores) - { - writer.WriteObjectValue(item, options); - } - writer.WriteEndArray(); - } - if (SerializedAdditionalRawData != null) - { - foreach (var item in SerializedAdditionalRawData) - { - if (ModelSerializationExtensions.IsSentinelValue(item.Value)) - { - continue; - } - writer.WritePropertyName(item.Key); -#if NET6_0_OR_GREATER - writer.WriteRawValue(item.Value); -#else - using (JsonDocument document = JsonDocument.Parse(item.Value)) - { - JsonSerializer.Serialize(writer, document.RootElement); - } -#endif - } - } - writer.WriteEndObject(); - } - - InternalCreateThreadRequestToolResourcesFileSearchVectorStoreCreationHelpers IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - if (format != "J") - { - throw new FormatException($"The model {nameof(InternalCreateThreadRequestToolResourcesFileSearchVectorStoreCreationHelpers)} does not support reading '{format}' format."); - } - - using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeInternalCreateThreadRequestToolResourcesFileSearchVectorStoreCreationHelpers(document.RootElement, options); - } - - internal static InternalCreateThreadRequestToolResourcesFileSearchVectorStoreCreationHelpers DeserializeInternalCreateThreadRequestToolResourcesFileSearchVectorStoreCreationHelpers(JsonElement element, ModelReaderWriterOptions options = null) - { - options ??= ModelSerializationExtensions.WireOptions; - - if (element.ValueKind == JsonValueKind.Null) - { - return null; - } - IList vectorStores = default; - IDictionary serializedAdditionalRawData = default; - Dictionary rawDataDictionary = new Dictionary(); - foreach (var property in element.EnumerateObject()) - { - if (property.NameEquals("vector_stores"u8)) - { - if (property.Value.ValueKind == JsonValueKind.Null) - { - continue; - } - List array = new List(); - foreach (var item in property.Value.EnumerateArray()) - { - array.Add(InternalCreateThreadRequestToolResourcesFileSearchVectorStoreCreationHelpersVectorStore.DeserializeInternalCreateThreadRequestToolResourcesFileSearchVectorStoreCreationHelpersVectorStore(item, options)); - } - vectorStores = array; - continue; - } - if (true) - { - rawDataDictionary ??= new Dictionary(); - rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); - } - } - serializedAdditionalRawData = rawDataDictionary; - return new InternalCreateThreadRequestToolResourcesFileSearchVectorStoreCreationHelpers(vectorStores ?? new ChangeTrackingList(), serializedAdditionalRawData); - } - - BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - - switch (format) - { - case "J": - return ModelReaderWriter.Write(this, options); - default: - throw new FormatException($"The model {nameof(InternalCreateThreadRequestToolResourcesFileSearchVectorStoreCreationHelpers)} does not support writing '{options.Format}' format."); - } - } - - InternalCreateThreadRequestToolResourcesFileSearchVectorStoreCreationHelpers IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - - switch (format) - { - case "J": - { - using JsonDocument document = JsonDocument.Parse(data); - return DeserializeInternalCreateThreadRequestToolResourcesFileSearchVectorStoreCreationHelpers(document.RootElement, options); - } - default: - throw new FormatException($"The model {nameof(InternalCreateThreadRequestToolResourcesFileSearchVectorStoreCreationHelpers)} does not support reading '{options.Format}' format."); - } - } - - string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; - - internal static InternalCreateThreadRequestToolResourcesFileSearchVectorStoreCreationHelpers FromResponse(PipelineResponse response) - { - using var document = JsonDocument.Parse(response.Content); - return DeserializeInternalCreateThreadRequestToolResourcesFileSearchVectorStoreCreationHelpers(document.RootElement); - } - - internal virtual BinaryContent ToBinaryContent() - { - return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); - } - } -} diff --git a/src/Generated/Models/InternalCreateThreadRequestToolResourcesFileSearchVectorStoreCreationHelpers.cs b/src/Generated/Models/InternalCreateThreadRequestToolResourcesFileSearchVectorStoreCreationHelpers.cs deleted file mode 100644 index f1854538c..000000000 --- a/src/Generated/Models/InternalCreateThreadRequestToolResourcesFileSearchVectorStoreCreationHelpers.cs +++ /dev/null @@ -1,26 +0,0 @@ -// - -#nullable disable - -using System; -using System.Collections.Generic; - -namespace OpenAI.Assistants -{ - internal partial class InternalCreateThreadRequestToolResourcesFileSearchVectorStoreCreationHelpers - { - internal IDictionary SerializedAdditionalRawData { get; set; } - public InternalCreateThreadRequestToolResourcesFileSearchVectorStoreCreationHelpers() - { - VectorStores = new ChangeTrackingList(); - } - - internal InternalCreateThreadRequestToolResourcesFileSearchVectorStoreCreationHelpers(IList vectorStores, IDictionary serializedAdditionalRawData) - { - VectorStores = vectorStores; - SerializedAdditionalRawData = serializedAdditionalRawData; - } - - public IList VectorStores { get; } - } -} diff --git a/src/Generated/Models/InternalCreateThreadRequestToolResourcesFileSearchVectorStoreCreationHelpersVectorStore.Serialization.cs b/src/Generated/Models/InternalCreateThreadRequestToolResourcesFileSearchVectorStoreCreationHelpersVectorStore.Serialization.cs deleted file mode 100644 index be93ed9cf..000000000 --- a/src/Generated/Models/InternalCreateThreadRequestToolResourcesFileSearchVectorStoreCreationHelpersVectorStore.Serialization.cs +++ /dev/null @@ -1,173 +0,0 @@ -// - -#nullable disable - -using System; -using System.ClientModel; -using System.ClientModel.Primitives; -using System.Collections.Generic; -using System.Text.Json; - -namespace OpenAI.Assistants -{ - internal partial class InternalCreateThreadRequestToolResourcesFileSearchVectorStoreCreationHelpersVectorStore : IJsonModel - { - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - if (format != "J") - { - throw new FormatException($"The model {nameof(InternalCreateThreadRequestToolResourcesFileSearchVectorStoreCreationHelpersVectorStore)} does not support writing '{format}' format."); - } - - writer.WriteStartObject(); - if (SerializedAdditionalRawData?.ContainsKey("file_ids") != true && Optional.IsCollectionDefined(FileIds)) - { - writer.WritePropertyName("file_ids"u8); - writer.WriteStartArray(); - foreach (var item in FileIds) - { - writer.WriteStringValue(item); - } - writer.WriteEndArray(); - } - if (SerializedAdditionalRawData?.ContainsKey("metadata") != true && Optional.IsCollectionDefined(Metadata)) - { - writer.WritePropertyName("metadata"u8); - writer.WriteStartObject(); - foreach (var item in Metadata) - { - writer.WritePropertyName(item.Key); - writer.WriteStringValue(item.Value); - } - writer.WriteEndObject(); - } - if (SerializedAdditionalRawData != null) - { - foreach (var item in SerializedAdditionalRawData) - { - if (ModelSerializationExtensions.IsSentinelValue(item.Value)) - { - continue; - } - writer.WritePropertyName(item.Key); -#if NET6_0_OR_GREATER - writer.WriteRawValue(item.Value); -#else - using (JsonDocument document = JsonDocument.Parse(item.Value)) - { - JsonSerializer.Serialize(writer, document.RootElement); - } -#endif - } - } - writer.WriteEndObject(); - } - - InternalCreateThreadRequestToolResourcesFileSearchVectorStoreCreationHelpersVectorStore IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - if (format != "J") - { - throw new FormatException($"The model {nameof(InternalCreateThreadRequestToolResourcesFileSearchVectorStoreCreationHelpersVectorStore)} does not support reading '{format}' format."); - } - - using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeInternalCreateThreadRequestToolResourcesFileSearchVectorStoreCreationHelpersVectorStore(document.RootElement, options); - } - - internal static InternalCreateThreadRequestToolResourcesFileSearchVectorStoreCreationHelpersVectorStore DeserializeInternalCreateThreadRequestToolResourcesFileSearchVectorStoreCreationHelpersVectorStore(JsonElement element, ModelReaderWriterOptions options = null) - { - options ??= ModelSerializationExtensions.WireOptions; - - if (element.ValueKind == JsonValueKind.Null) - { - return null; - } - IList fileIds = default; - IDictionary metadata = default; - IDictionary serializedAdditionalRawData = default; - Dictionary rawDataDictionary = new Dictionary(); - foreach (var property in element.EnumerateObject()) - { - if (property.NameEquals("file_ids"u8)) - { - if (property.Value.ValueKind == JsonValueKind.Null) - { - continue; - } - List array = new List(); - foreach (var item in property.Value.EnumerateArray()) - { - array.Add(item.GetString()); - } - fileIds = array; - continue; - } - if (property.NameEquals("metadata"u8)) - { - if (property.Value.ValueKind == JsonValueKind.Null) - { - continue; - } - Dictionary dictionary = new Dictionary(); - foreach (var property0 in property.Value.EnumerateObject()) - { - dictionary.Add(property0.Name, property0.Value.GetString()); - } - metadata = dictionary; - continue; - } - if (true) - { - rawDataDictionary ??= new Dictionary(); - rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); - } - } - serializedAdditionalRawData = rawDataDictionary; - return new InternalCreateThreadRequestToolResourcesFileSearchVectorStoreCreationHelpersVectorStore(fileIds ?? new ChangeTrackingList(), metadata ?? new ChangeTrackingDictionary(), serializedAdditionalRawData); - } - - BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - - switch (format) - { - case "J": - return ModelReaderWriter.Write(this, options); - default: - throw new FormatException($"The model {nameof(InternalCreateThreadRequestToolResourcesFileSearchVectorStoreCreationHelpersVectorStore)} does not support writing '{options.Format}' format."); - } - } - - InternalCreateThreadRequestToolResourcesFileSearchVectorStoreCreationHelpersVectorStore IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - - switch (format) - { - case "J": - { - using JsonDocument document = JsonDocument.Parse(data); - return DeserializeInternalCreateThreadRequestToolResourcesFileSearchVectorStoreCreationHelpersVectorStore(document.RootElement, options); - } - default: - throw new FormatException($"The model {nameof(InternalCreateThreadRequestToolResourcesFileSearchVectorStoreCreationHelpersVectorStore)} does not support reading '{options.Format}' format."); - } - } - - string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; - - internal static InternalCreateThreadRequestToolResourcesFileSearchVectorStoreCreationHelpersVectorStore FromResponse(PipelineResponse response) - { - using var document = JsonDocument.Parse(response.Content); - return DeserializeInternalCreateThreadRequestToolResourcesFileSearchVectorStoreCreationHelpersVectorStore(document.RootElement); - } - - internal virtual BinaryContent ToBinaryContent() - { - return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); - } - } -} diff --git a/src/Generated/Models/InternalCreateThreadRequestToolResourcesFileSearchVectorStoreCreationHelpersVectorStore.cs b/src/Generated/Models/InternalCreateThreadRequestToolResourcesFileSearchVectorStoreCreationHelpersVectorStore.cs deleted file mode 100644 index 430b2c563..000000000 --- a/src/Generated/Models/InternalCreateThreadRequestToolResourcesFileSearchVectorStoreCreationHelpersVectorStore.cs +++ /dev/null @@ -1,29 +0,0 @@ -// - -#nullable disable - -using System; -using System.Collections.Generic; - -namespace OpenAI.Assistants -{ - internal partial class InternalCreateThreadRequestToolResourcesFileSearchVectorStoreCreationHelpersVectorStore - { - internal IDictionary SerializedAdditionalRawData { get; set; } - public InternalCreateThreadRequestToolResourcesFileSearchVectorStoreCreationHelpersVectorStore() - { - FileIds = new ChangeTrackingList(); - Metadata = new ChangeTrackingDictionary(); - } - - internal InternalCreateThreadRequestToolResourcesFileSearchVectorStoreCreationHelpersVectorStore(IList fileIds, IDictionary metadata, IDictionary serializedAdditionalRawData) - { - FileIds = fileIds; - Metadata = metadata; - SerializedAdditionalRawData = serializedAdditionalRawData; - } - - public IList FileIds { get; } - public IDictionary Metadata { get; } - } -} diff --git a/src/Generated/Models/InternalCreateThreadRequestToolResourcesFileSearchVectorStoreIdReferences.Serialization.cs b/src/Generated/Models/InternalCreateThreadRequestToolResourcesFileSearchVectorStoreIdReferences.Serialization.cs deleted file mode 100644 index e8e18dba6..000000000 --- a/src/Generated/Models/InternalCreateThreadRequestToolResourcesFileSearchVectorStoreIdReferences.Serialization.cs +++ /dev/null @@ -1,147 +0,0 @@ -// - -#nullable disable - -using System; -using System.ClientModel; -using System.ClientModel.Primitives; -using System.Collections.Generic; -using System.Text.Json; - -namespace OpenAI.Assistants -{ - internal partial class InternalCreateThreadRequestToolResourcesFileSearchVectorStoreIdReferences : IJsonModel - { - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - if (format != "J") - { - throw new FormatException($"The model {nameof(InternalCreateThreadRequestToolResourcesFileSearchVectorStoreIdReferences)} does not support writing '{format}' format."); - } - - writer.WriteStartObject(); - if (SerializedAdditionalRawData?.ContainsKey("vector_store_ids") != true && Optional.IsCollectionDefined(VectorStoreIds)) - { - writer.WritePropertyName("vector_store_ids"u8); - writer.WriteStartArray(); - foreach (var item in VectorStoreIds) - { - writer.WriteStringValue(item); - } - writer.WriteEndArray(); - } - if (SerializedAdditionalRawData != null) - { - foreach (var item in SerializedAdditionalRawData) - { - if (ModelSerializationExtensions.IsSentinelValue(item.Value)) - { - continue; - } - writer.WritePropertyName(item.Key); -#if NET6_0_OR_GREATER - writer.WriteRawValue(item.Value); -#else - using (JsonDocument document = JsonDocument.Parse(item.Value)) - { - JsonSerializer.Serialize(writer, document.RootElement); - } -#endif - } - } - writer.WriteEndObject(); - } - - InternalCreateThreadRequestToolResourcesFileSearchVectorStoreIdReferences IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - if (format != "J") - { - throw new FormatException($"The model {nameof(InternalCreateThreadRequestToolResourcesFileSearchVectorStoreIdReferences)} does not support reading '{format}' format."); - } - - using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeInternalCreateThreadRequestToolResourcesFileSearchVectorStoreIdReferences(document.RootElement, options); - } - - internal static InternalCreateThreadRequestToolResourcesFileSearchVectorStoreIdReferences DeserializeInternalCreateThreadRequestToolResourcesFileSearchVectorStoreIdReferences(JsonElement element, ModelReaderWriterOptions options = null) - { - options ??= ModelSerializationExtensions.WireOptions; - - if (element.ValueKind == JsonValueKind.Null) - { - return null; - } - IList vectorStoreIds = default; - IDictionary serializedAdditionalRawData = default; - Dictionary rawDataDictionary = new Dictionary(); - foreach (var property in element.EnumerateObject()) - { - if (property.NameEquals("vector_store_ids"u8)) - { - if (property.Value.ValueKind == JsonValueKind.Null) - { - continue; - } - List array = new List(); - foreach (var item in property.Value.EnumerateArray()) - { - array.Add(item.GetString()); - } - vectorStoreIds = array; - continue; - } - if (true) - { - rawDataDictionary ??= new Dictionary(); - rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); - } - } - serializedAdditionalRawData = rawDataDictionary; - return new InternalCreateThreadRequestToolResourcesFileSearchVectorStoreIdReferences(vectorStoreIds ?? new ChangeTrackingList(), serializedAdditionalRawData); - } - - BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - - switch (format) - { - case "J": - return ModelReaderWriter.Write(this, options); - default: - throw new FormatException($"The model {nameof(InternalCreateThreadRequestToolResourcesFileSearchVectorStoreIdReferences)} does not support writing '{options.Format}' format."); - } - } - - InternalCreateThreadRequestToolResourcesFileSearchVectorStoreIdReferences IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - - switch (format) - { - case "J": - { - using JsonDocument document = JsonDocument.Parse(data); - return DeserializeInternalCreateThreadRequestToolResourcesFileSearchVectorStoreIdReferences(document.RootElement, options); - } - default: - throw new FormatException($"The model {nameof(InternalCreateThreadRequestToolResourcesFileSearchVectorStoreIdReferences)} does not support reading '{options.Format}' format."); - } - } - - string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; - - internal static InternalCreateThreadRequestToolResourcesFileSearchVectorStoreIdReferences FromResponse(PipelineResponse response) - { - using var document = JsonDocument.Parse(response.Content); - return DeserializeInternalCreateThreadRequestToolResourcesFileSearchVectorStoreIdReferences(document.RootElement); - } - - internal virtual BinaryContent ToBinaryContent() - { - return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); - } - } -} diff --git a/src/Generated/Models/InternalCreateThreadRequestToolResourcesFileSearchVectorStoreIdReferences.cs b/src/Generated/Models/InternalCreateThreadRequestToolResourcesFileSearchVectorStoreIdReferences.cs deleted file mode 100644 index 140500897..000000000 --- a/src/Generated/Models/InternalCreateThreadRequestToolResourcesFileSearchVectorStoreIdReferences.cs +++ /dev/null @@ -1,26 +0,0 @@ -// - -#nullable disable - -using System; -using System.Collections.Generic; - -namespace OpenAI.Assistants -{ - internal partial class InternalCreateThreadRequestToolResourcesFileSearchVectorStoreIdReferences - { - internal IDictionary SerializedAdditionalRawData { get; set; } - public InternalCreateThreadRequestToolResourcesFileSearchVectorStoreIdReferences() - { - VectorStoreIds = new ChangeTrackingList(); - } - - internal InternalCreateThreadRequestToolResourcesFileSearchVectorStoreIdReferences(IList vectorStoreIds, IDictionary serializedAdditionalRawData) - { - VectorStoreIds = vectorStoreIds; - SerializedAdditionalRawData = serializedAdditionalRawData; - } - - public IList VectorStoreIds { get; } - } -} diff --git a/src/Generated/Models/InternalCreateUploadRequest.Serialization.cs b/src/Generated/Models/InternalCreateUploadRequest.Serialization.cs new file mode 100644 index 000000000..e2ed769ba --- /dev/null +++ b/src/Generated/Models/InternalCreateUploadRequest.Serialization.cs @@ -0,0 +1,166 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.Files +{ + internal partial class InternalCreateUploadRequest : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalCreateUploadRequest)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("filename") != true) + { + writer.WritePropertyName("filename"u8); + writer.WriteStringValue(Filename); + } + if (SerializedAdditionalRawData?.ContainsKey("purpose") != true) + { + writer.WritePropertyName("purpose"u8); + writer.WriteStringValue(Purpose.ToString()); + } + if (SerializedAdditionalRawData?.ContainsKey("bytes") != true) + { + writer.WritePropertyName("bytes"u8); + writer.WriteNumberValue(Bytes); + } + if (SerializedAdditionalRawData?.ContainsKey("mime_type") != true) + { + writer.WritePropertyName("mime_type"u8); + writer.WriteStringValue(MimeType); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalCreateUploadRequest IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalCreateUploadRequest)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalCreateUploadRequest(document.RootElement, options); + } + + internal static InternalCreateUploadRequest DeserializeInternalCreateUploadRequest(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string filename = default; + InternalCreateUploadRequestPurpose purpose = default; + int bytes = default; + string mimeType = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("filename"u8)) + { + filename = property.Value.GetString(); + continue; + } + if (property.NameEquals("purpose"u8)) + { + purpose = new InternalCreateUploadRequestPurpose(property.Value.GetString()); + continue; + } + if (property.NameEquals("bytes"u8)) + { + bytes = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("mime_type"u8)) + { + mimeType = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new InternalCreateUploadRequest(filename, purpose, bytes, mimeType, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalCreateUploadRequest)} does not support writing '{options.Format}' format."); + } + } + + InternalCreateUploadRequest IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalCreateUploadRequest(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalCreateUploadRequest)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static InternalCreateUploadRequest FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalCreateUploadRequest(document.RootElement); + } + + internal virtual BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/InternalCreateUploadRequest.cs b/src/Generated/Models/InternalCreateUploadRequest.cs new file mode 100644 index 000000000..f580307a6 --- /dev/null +++ b/src/Generated/Models/InternalCreateUploadRequest.cs @@ -0,0 +1,42 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.Files +{ + internal partial class InternalCreateUploadRequest + { + internal IDictionary SerializedAdditionalRawData { get; set; } + public InternalCreateUploadRequest(string filename, InternalCreateUploadRequestPurpose purpose, int bytes, string mimeType) + { + Argument.AssertNotNull(filename, nameof(filename)); + Argument.AssertNotNull(mimeType, nameof(mimeType)); + + Filename = filename; + Purpose = purpose; + Bytes = bytes; + MimeType = mimeType; + } + + internal InternalCreateUploadRequest(string filename, InternalCreateUploadRequestPurpose purpose, int bytes, string mimeType, IDictionary serializedAdditionalRawData) + { + Filename = filename; + Purpose = purpose; + Bytes = bytes; + MimeType = mimeType; + SerializedAdditionalRawData = serializedAdditionalRawData; + } + + internal InternalCreateUploadRequest() + { + } + + public string Filename { get; } + public InternalCreateUploadRequestPurpose Purpose { get; } + public int Bytes { get; } + public string MimeType { get; } + } +} diff --git a/src/Generated/Models/InternalCreateUploadRequestPurpose.cs b/src/Generated/Models/InternalCreateUploadRequestPurpose.cs new file mode 100644 index 000000000..6b76958f0 --- /dev/null +++ b/src/Generated/Models/InternalCreateUploadRequestPurpose.cs @@ -0,0 +1,40 @@ +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace OpenAI.Files +{ + internal readonly partial struct InternalCreateUploadRequestPurpose : IEquatable + { + private readonly string _value; + + public InternalCreateUploadRequestPurpose(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string AssistantsValue = "assistants"; + private const string BatchValue = "batch"; + private const string FineTuneValue = "fine-tune"; + private const string VisionValue = "vision"; + + public static InternalCreateUploadRequestPurpose Assistants { get; } = new InternalCreateUploadRequestPurpose(AssistantsValue); + public static InternalCreateUploadRequestPurpose Batch { get; } = new InternalCreateUploadRequestPurpose(BatchValue); + public static InternalCreateUploadRequestPurpose FineTune { get; } = new InternalCreateUploadRequestPurpose(FineTuneValue); + public static InternalCreateUploadRequestPurpose Vision { get; } = new InternalCreateUploadRequestPurpose(VisionValue); + public static bool operator ==(InternalCreateUploadRequestPurpose left, InternalCreateUploadRequestPurpose right) => left.Equals(right); + public static bool operator !=(InternalCreateUploadRequestPurpose left, InternalCreateUploadRequestPurpose right) => !left.Equals(right); + public static implicit operator InternalCreateUploadRequestPurpose(string value) => new InternalCreateUploadRequestPurpose(value); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is InternalCreateUploadRequestPurpose other && Equals(other); + public bool Equals(InternalCreateUploadRequestPurpose other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; + public override string ToString() => _value; + } +} diff --git a/src/Generated/Models/InternalFineTuneChatCompletionRequestAssistantMessage.Serialization.cs b/src/Generated/Models/InternalFineTuneChatCompletionRequestAssistantMessage.Serialization.cs index e60bfb399..9c1712f3c 100644 --- a/src/Generated/Models/InternalFineTuneChatCompletionRequestAssistantMessage.Serialization.cs +++ b/src/Generated/Models/InternalFineTuneChatCompletionRequestAssistantMessage.Serialization.cs @@ -22,6 +22,18 @@ void IJsonModel.Write(Utf } writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("refusal") != true && Optional.IsDefined(Refusal)) + { + if (Refusal != null) + { + writer.WritePropertyName("refusal"u8); + writer.WriteStringValue(Refusal); + } + else + { + writer.WriteNull("refusal"); + } + } if (SerializedAdditionalRawData?.ContainsKey("name") != true && Optional.IsDefined(ParticipantName)) { writer.WritePropertyName("name"u8); @@ -33,7 +45,7 @@ void IJsonModel.Write(Utf writer.WriteStartArray(); foreach (var item in ToolCalls) { - writer.WriteObjectValue(item, options); + writer.WriteObjectValue(item, options); } writer.WriteEndArray(); } @@ -52,7 +64,7 @@ void IJsonModel.Write(Utf if (SerializedAdditionalRawData?.ContainsKey("role") != true) { writer.WritePropertyName("role"u8); - writer.WriteStringValue(Role); + writer.WriteStringValue(Role.ToSerialString()); } if (SerializedAdditionalRawData?.ContainsKey("content") != true && Optional.IsCollectionDefined(Content)) { @@ -101,15 +113,26 @@ internal static InternalFineTuneChatCompletionRequestAssistantMessage Deserializ { return null; } + string refusal = default; string name = default; IList toolCalls = default; ChatFunctionCall functionCall = default; - string role = default; + ChatMessageRole role = default; IList content = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { + if (property.NameEquals("refusal"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + refusal = null; + continue; + } + refusal = property.Value.GetString(); + continue; + } if (property.NameEquals("name"u8)) { name = property.Value.GetString(); @@ -141,7 +164,7 @@ internal static InternalFineTuneChatCompletionRequestAssistantMessage Deserializ } if (property.NameEquals("role"u8)) { - role = property.Value.GetString(); + role = property.Value.GetString().ToChatMessageRole(); continue; } if (property.NameEquals("content"u8)) @@ -160,6 +183,7 @@ internal static InternalFineTuneChatCompletionRequestAssistantMessage Deserializ role, content ?? new ChangeTrackingList(), serializedAdditionalRawData, + refusal, name, toolCalls ?? new ChangeTrackingList(), functionCall); diff --git a/src/Generated/Models/InternalFineTuneChatCompletionRequestAssistantMessage.cs b/src/Generated/Models/InternalFineTuneChatCompletionRequestAssistantMessage.cs index 51139e9f8..e7f33bc58 100644 --- a/src/Generated/Models/InternalFineTuneChatCompletionRequestAssistantMessage.cs +++ b/src/Generated/Models/InternalFineTuneChatCompletionRequestAssistantMessage.cs @@ -14,7 +14,7 @@ public InternalFineTuneChatCompletionRequestAssistantMessage() { } - internal InternalFineTuneChatCompletionRequestAssistantMessage(string role, IList content, IDictionary serializedAdditionalRawData, string participantName, IList toolCalls, ChatFunctionCall functionCall) : base(role, content, serializedAdditionalRawData, participantName, toolCalls, functionCall) + internal InternalFineTuneChatCompletionRequestAssistantMessage(ChatMessageRole role, IList content, IDictionary serializedAdditionalRawData, string refusal, string participantName, IList toolCalls, ChatFunctionCall functionCall) : base(role, content, serializedAdditionalRawData, refusal, participantName, toolCalls, functionCall) { } } diff --git a/src/Generated/Models/InternalFineTuningJobHyperparametersNEpochsChoiceEnum.cs b/src/Generated/Models/InternalFineTuningJobHyperparametersNEpochsChoiceEnum.cs new file mode 100644 index 000000000..02f0f0754 --- /dev/null +++ b/src/Generated/Models/InternalFineTuningJobHyperparametersNEpochsChoiceEnum.cs @@ -0,0 +1,34 @@ +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace OpenAI.FineTuning +{ + internal readonly partial struct InternalFineTuningJobHyperparametersNEpochsChoiceEnum : IEquatable + { + private readonly string _value; + + public InternalFineTuningJobHyperparametersNEpochsChoiceEnum(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string AutoValue = "auto"; + + public static InternalFineTuningJobHyperparametersNEpochsChoiceEnum Auto { get; } = new InternalFineTuningJobHyperparametersNEpochsChoiceEnum(AutoValue); + public static bool operator ==(InternalFineTuningJobHyperparametersNEpochsChoiceEnum left, InternalFineTuningJobHyperparametersNEpochsChoiceEnum right) => left.Equals(right); + public static bool operator !=(InternalFineTuningJobHyperparametersNEpochsChoiceEnum left, InternalFineTuningJobHyperparametersNEpochsChoiceEnum right) => !left.Equals(right); + public static implicit operator InternalFineTuningJobHyperparametersNEpochsChoiceEnum(string value) => new InternalFineTuningJobHyperparametersNEpochsChoiceEnum(value); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is InternalFineTuningJobHyperparametersNEpochsChoiceEnum other && Equals(other); + public bool Equals(InternalFineTuningJobHyperparametersNEpochsChoiceEnum other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; + public override string ToString() => _value; + } +} diff --git a/src/Generated/Models/InternalFunctionDefinition.Serialization.cs b/src/Generated/Models/InternalFunctionDefinition.Serialization.cs index 095286f50..57335523d 100644 --- a/src/Generated/Models/InternalFunctionDefinition.Serialization.cs +++ b/src/Generated/Models/InternalFunctionDefinition.Serialization.cs @@ -43,6 +43,18 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelRe } #endif } + if (SerializedAdditionalRawData?.ContainsKey("strict") != true && Optional.IsDefined(Strict)) + { + if (Strict != null) + { + writer.WritePropertyName("strict"u8); + writer.WriteBooleanValue(Strict.Value); + } + else + { + writer.WriteNull("strict"); + } + } if (SerializedAdditionalRawData != null) { foreach (var item in SerializedAdditionalRawData) @@ -88,6 +100,7 @@ internal static InternalFunctionDefinition DeserializeInternalFunctionDefinition string description = default; string name = default; BinaryData parameters = default; + bool? strict = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) @@ -111,6 +124,16 @@ internal static InternalFunctionDefinition DeserializeInternalFunctionDefinition parameters = BinaryData.FromString(property.Value.GetRawText()); continue; } + if (property.NameEquals("strict"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + strict = null; + continue; + } + strict = property.Value.GetBoolean(); + continue; + } if (true) { rawDataDictionary ??= new Dictionary(); @@ -118,7 +141,7 @@ internal static InternalFunctionDefinition DeserializeInternalFunctionDefinition } } serializedAdditionalRawData = rawDataDictionary; - return new InternalFunctionDefinition(description, name, parameters, serializedAdditionalRawData); + return new InternalFunctionDefinition(description, name, parameters, strict, serializedAdditionalRawData); } BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) diff --git a/src/Generated/Models/InternalFunctionDefinition.cs b/src/Generated/Models/InternalFunctionDefinition.cs index 836a40e4b..9e385deb8 100644 --- a/src/Generated/Models/InternalFunctionDefinition.cs +++ b/src/Generated/Models/InternalFunctionDefinition.cs @@ -17,11 +17,12 @@ public InternalFunctionDefinition(string name) Name = name; } - internal InternalFunctionDefinition(string description, string name, BinaryData parameters, IDictionary serializedAdditionalRawData) + internal InternalFunctionDefinition(string description, string name, BinaryData parameters, bool? strict, IDictionary serializedAdditionalRawData) { Description = description; Name = name; Parameters = parameters; + Strict = strict; SerializedAdditionalRawData = serializedAdditionalRawData; } @@ -31,5 +32,6 @@ internal InternalFunctionDefinition() public string Description { get; set; } public string Name { get; set; } + public bool? Strict { get; set; } } } diff --git a/src/Generated/Models/InternalMessageContentRefusalObjectType.cs b/src/Generated/Models/InternalMessageContentRefusalObjectType.cs new file mode 100644 index 000000000..7a127f292 --- /dev/null +++ b/src/Generated/Models/InternalMessageContentRefusalObjectType.cs @@ -0,0 +1,34 @@ +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace OpenAI.Assistants +{ + internal readonly partial struct InternalMessageContentRefusalObjectType : IEquatable + { + private readonly string _value; + + public InternalMessageContentRefusalObjectType(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string RefusalValue = "refusal"; + + public static InternalMessageContentRefusalObjectType Refusal { get; } = new InternalMessageContentRefusalObjectType(RefusalValue); + public static bool operator ==(InternalMessageContentRefusalObjectType left, InternalMessageContentRefusalObjectType right) => left.Equals(right); + public static bool operator !=(InternalMessageContentRefusalObjectType left, InternalMessageContentRefusalObjectType right) => !left.Equals(right); + public static implicit operator InternalMessageContentRefusalObjectType(string value) => new InternalMessageContentRefusalObjectType(value); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is InternalMessageContentRefusalObjectType other && Equals(other); + public bool Equals(InternalMessageContentRefusalObjectType other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; + public override string ToString() => _value; + } +} diff --git a/src/Generated/Models/InternalMessageDeltaContent.Serialization.cs b/src/Generated/Models/InternalMessageDeltaContent.Serialization.cs index b8ac6343c..7b0d037e3 100644 --- a/src/Generated/Models/InternalMessageDeltaContent.Serialization.cs +++ b/src/Generated/Models/InternalMessageDeltaContent.Serialization.cs @@ -74,6 +74,7 @@ internal static InternalMessageDeltaContent DeserializeInternalMessageDeltaConte { case "image_file": return InternalMessageDeltaContentImageFileObject.DeserializeInternalMessageDeltaContentImageFileObject(element, options); case "image_url": return InternalMessageDeltaContentImageUrlObject.DeserializeInternalMessageDeltaContentImageUrlObject(element, options); + case "refusal": return InternalMessageDeltaContentRefusalObject.DeserializeInternalMessageDeltaContentRefusalObject(element, options); case "text": return InternalMessageDeltaContentTextObject.DeserializeInternalMessageDeltaContentTextObject(element, options); } } diff --git a/src/Generated/Models/InternalMessageDeltaContentRefusalObject.Serialization.cs b/src/Generated/Models/InternalMessageDeltaContentRefusalObject.Serialization.cs new file mode 100644 index 000000000..1668fc35c --- /dev/null +++ b/src/Generated/Models/InternalMessageDeltaContentRefusalObject.Serialization.cs @@ -0,0 +1,155 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.Assistants +{ + internal partial class InternalMessageDeltaContentRefusalObject : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalMessageDeltaContentRefusalObject)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("index") != true) + { + writer.WritePropertyName("index"u8); + writer.WriteNumberValue(Index); + } + if (SerializedAdditionalRawData?.ContainsKey("refusal") != true && Optional.IsDefined(Refusal)) + { + writer.WritePropertyName("refusal"u8); + writer.WriteStringValue(Refusal); + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalMessageDeltaContentRefusalObject IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalMessageDeltaContentRefusalObject)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalMessageDeltaContentRefusalObject(document.RootElement, options); + } + + internal static InternalMessageDeltaContentRefusalObject DeserializeInternalMessageDeltaContentRefusalObject(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + int index = default; + string refusal = default; + string type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("index"u8)) + { + index = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("refusal"u8)) + { + refusal = property.Value.GetString(); + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new InternalMessageDeltaContentRefusalObject(type, serializedAdditionalRawData, index, refusal); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalMessageDeltaContentRefusalObject)} does not support writing '{options.Format}' format."); + } + } + + InternalMessageDeltaContentRefusalObject IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalMessageDeltaContentRefusalObject(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalMessageDeltaContentRefusalObject)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new InternalMessageDeltaContentRefusalObject FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalMessageDeltaContentRefusalObject(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/InternalMessageDeltaContentRefusalObject.cs b/src/Generated/Models/InternalMessageDeltaContentRefusalObject.cs new file mode 100644 index 000000000..d7b88a830 --- /dev/null +++ b/src/Generated/Models/InternalMessageDeltaContentRefusalObject.cs @@ -0,0 +1,31 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.Assistants +{ + internal partial class InternalMessageDeltaContentRefusalObject : InternalMessageDeltaContent + { + internal InternalMessageDeltaContentRefusalObject(int index) + { + Type = "refusal"; + Index = index; + } + + internal InternalMessageDeltaContentRefusalObject(string type, IDictionary serializedAdditionalRawData, int index, string refusal) : base(type, serializedAdditionalRawData) + { + Index = index; + Refusal = refusal; + } + + internal InternalMessageDeltaContentRefusalObject() + { + } + + public int Index { get; } + public string Refusal { get; } + } +} diff --git a/src/Generated/Models/InternalMessageRefusalContent.Serialization.cs b/src/Generated/Models/InternalMessageRefusalContent.Serialization.cs new file mode 100644 index 000000000..6e3c9846f --- /dev/null +++ b/src/Generated/Models/InternalMessageRefusalContent.Serialization.cs @@ -0,0 +1,103 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.Assistants +{ + internal partial class InternalMessageRefusalContent : IJsonModel + { + InternalMessageRefusalContent IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalMessageRefusalContent)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalMessageRefusalContent(document.RootElement, options); + } + + internal static InternalMessageRefusalContent DeserializeInternalMessageRefusalContent(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string type = default; + string refusal = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + if (property.NameEquals("refusal"u8)) + { + refusal = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new InternalMessageRefusalContent(serializedAdditionalRawData, type, refusal); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalMessageRefusalContent)} does not support writing '{options.Format}' format."); + } + } + + InternalMessageRefusalContent IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalMessageRefusalContent(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalMessageRefusalContent)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new InternalMessageRefusalContent FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalMessageRefusalContent(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/InternalMessageRefusalContent.cs b/src/Generated/Models/InternalMessageRefusalContent.cs new file mode 100644 index 000000000..dc6f0e0af --- /dev/null +++ b/src/Generated/Models/InternalMessageRefusalContent.cs @@ -0,0 +1,29 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.Assistants +{ + internal partial class InternalMessageRefusalContent : MessageContent + { + public InternalMessageRefusalContent(string internalRefusal) + { + Argument.AssertNotNull(internalRefusal, nameof(internalRefusal)); + + InternalRefusal = internalRefusal; + } + + internal InternalMessageRefusalContent(IDictionary serializedAdditionalRawData, string type, string internalRefusal) : base(serializedAdditionalRawData) + { + _type = type; + InternalRefusal = internalRefusal; + } + + internal InternalMessageRefusalContent() + { + } + } +} diff --git a/src/Generated/Models/InternalModifyAssistantRequestToolResources.Serialization.cs b/src/Generated/Models/InternalModifyAssistantRequestToolResources.Serialization.cs index 7c0d6a685..bb4a89610 100644 --- a/src/Generated/Models/InternalModifyAssistantRequestToolResources.Serialization.cs +++ b/src/Generated/Models/InternalModifyAssistantRequestToolResources.Serialization.cs @@ -74,7 +74,7 @@ internal static InternalModifyAssistantRequestToolResources DeserializeInternalM return null; } InternalModifyAssistantRequestToolResourcesCodeInterpreter codeInterpreter = default; - InternalModifyAssistantRequestToolResourcesFileSearch fileSearch = default; + InternalToolResourcesFileSearchIdsOnly fileSearch = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) @@ -94,7 +94,7 @@ internal static InternalModifyAssistantRequestToolResources DeserializeInternalM { continue; } - fileSearch = InternalModifyAssistantRequestToolResourcesFileSearch.DeserializeInternalModifyAssistantRequestToolResourcesFileSearch(property.Value, options); + fileSearch = InternalToolResourcesFileSearchIdsOnly.DeserializeInternalToolResourcesFileSearchIdsOnly(property.Value, options); continue; } if (true) diff --git a/src/Generated/Models/InternalModifyAssistantRequestToolResources.cs b/src/Generated/Models/InternalModifyAssistantRequestToolResources.cs index 5aa4a77d8..3bcf4c24d 100644 --- a/src/Generated/Models/InternalModifyAssistantRequestToolResources.cs +++ b/src/Generated/Models/InternalModifyAssistantRequestToolResources.cs @@ -14,7 +14,7 @@ public InternalModifyAssistantRequestToolResources() { } - internal InternalModifyAssistantRequestToolResources(InternalModifyAssistantRequestToolResourcesCodeInterpreter codeInterpreter, InternalModifyAssistantRequestToolResourcesFileSearch fileSearch, IDictionary serializedAdditionalRawData) + internal InternalModifyAssistantRequestToolResources(InternalModifyAssistantRequestToolResourcesCodeInterpreter codeInterpreter, InternalToolResourcesFileSearchIdsOnly fileSearch, IDictionary serializedAdditionalRawData) { CodeInterpreter = codeInterpreter; FileSearch = fileSearch; @@ -22,6 +22,6 @@ internal InternalModifyAssistantRequestToolResources(InternalModifyAssistantRequ } public InternalModifyAssistantRequestToolResourcesCodeInterpreter CodeInterpreter { get; set; } - public InternalModifyAssistantRequestToolResourcesFileSearch FileSearch { get; set; } + public InternalToolResourcesFileSearchIdsOnly FileSearch { get; set; } } } diff --git a/src/Generated/Models/InternalModifyAssistantRequestToolResourcesFileSearch.cs b/src/Generated/Models/InternalModifyAssistantRequestToolResourcesFileSearch.cs deleted file mode 100644 index e9b82d57a..000000000 --- a/src/Generated/Models/InternalModifyAssistantRequestToolResourcesFileSearch.cs +++ /dev/null @@ -1,26 +0,0 @@ -// - -#nullable disable - -using System; -using System.Collections.Generic; - -namespace OpenAI.Assistants -{ - internal partial class InternalModifyAssistantRequestToolResourcesFileSearch - { - internal IDictionary SerializedAdditionalRawData { get; set; } - public InternalModifyAssistantRequestToolResourcesFileSearch() - { - VectorStoreIds = new ChangeTrackingList(); - } - - internal InternalModifyAssistantRequestToolResourcesFileSearch(IList vectorStoreIds, IDictionary serializedAdditionalRawData) - { - VectorStoreIds = vectorStoreIds; - SerializedAdditionalRawData = serializedAdditionalRawData; - } - - public IList VectorStoreIds { get; } - } -} diff --git a/src/Generated/Models/InternalModifyThreadRequestToolResources.Serialization.cs b/src/Generated/Models/InternalModifyThreadRequestToolResources.Serialization.cs index af74f65f2..3354accf3 100644 --- a/src/Generated/Models/InternalModifyThreadRequestToolResources.Serialization.cs +++ b/src/Generated/Models/InternalModifyThreadRequestToolResources.Serialization.cs @@ -74,7 +74,7 @@ internal static InternalModifyThreadRequestToolResources DeserializeInternalModi return null; } InternalModifyThreadRequestToolResourcesCodeInterpreter codeInterpreter = default; - InternalModifyThreadRequestToolResourcesFileSearch fileSearch = default; + InternalToolResourcesFileSearchIdsOnly fileSearch = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) @@ -94,7 +94,7 @@ internal static InternalModifyThreadRequestToolResources DeserializeInternalModi { continue; } - fileSearch = InternalModifyThreadRequestToolResourcesFileSearch.DeserializeInternalModifyThreadRequestToolResourcesFileSearch(property.Value, options); + fileSearch = InternalToolResourcesFileSearchIdsOnly.DeserializeInternalToolResourcesFileSearchIdsOnly(property.Value, options); continue; } if (true) diff --git a/src/Generated/Models/InternalModifyThreadRequestToolResources.cs b/src/Generated/Models/InternalModifyThreadRequestToolResources.cs index 0d8078ba4..0876ba2de 100644 --- a/src/Generated/Models/InternalModifyThreadRequestToolResources.cs +++ b/src/Generated/Models/InternalModifyThreadRequestToolResources.cs @@ -14,7 +14,7 @@ public InternalModifyThreadRequestToolResources() { } - internal InternalModifyThreadRequestToolResources(InternalModifyThreadRequestToolResourcesCodeInterpreter codeInterpreter, InternalModifyThreadRequestToolResourcesFileSearch fileSearch, IDictionary serializedAdditionalRawData) + internal InternalModifyThreadRequestToolResources(InternalModifyThreadRequestToolResourcesCodeInterpreter codeInterpreter, InternalToolResourcesFileSearchIdsOnly fileSearch, IDictionary serializedAdditionalRawData) { CodeInterpreter = codeInterpreter; FileSearch = fileSearch; @@ -22,6 +22,6 @@ internal InternalModifyThreadRequestToolResources(InternalModifyThreadRequestToo } public InternalModifyThreadRequestToolResourcesCodeInterpreter CodeInterpreter { get; set; } - public InternalModifyThreadRequestToolResourcesFileSearch FileSearch { get; set; } + public InternalToolResourcesFileSearchIdsOnly FileSearch { get; set; } } } diff --git a/src/Generated/Models/InternalOmniTypedResponseFormat.Serialization.cs b/src/Generated/Models/InternalOmniTypedResponseFormat.Serialization.cs new file mode 100644 index 000000000..6ccf09de3 --- /dev/null +++ b/src/Generated/Models/InternalOmniTypedResponseFormat.Serialization.cs @@ -0,0 +1,125 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Text.Json; + +namespace OpenAI.Internal +{ + [PersistableModelProxy(typeof(InternalUnknownOmniTypedResponseFormat))] + internal partial class InternalOmniTypedResponseFormat : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalOmniTypedResponseFormat)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalOmniTypedResponseFormat IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalOmniTypedResponseFormat)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalOmniTypedResponseFormat(document.RootElement, options); + } + + internal static InternalOmniTypedResponseFormat DeserializeInternalOmniTypedResponseFormat(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + if (element.TryGetProperty("type", out JsonElement discriminator)) + { + switch (discriminator.GetString()) + { + case "json_object": return InternalResponseFormatJsonObject.DeserializeInternalResponseFormatJsonObject(element, options); + case "json_schema": return InternalResponseFormatJsonSchema.DeserializeInternalResponseFormatJsonSchema(element, options); + case "text": return InternalResponseFormatText.DeserializeInternalResponseFormatText(element, options); + } + } + return InternalUnknownOmniTypedResponseFormat.DeserializeInternalUnknownOmniTypedResponseFormat(element, options); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalOmniTypedResponseFormat)} does not support writing '{options.Format}' format."); + } + } + + InternalOmniTypedResponseFormat IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalOmniTypedResponseFormat(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalOmniTypedResponseFormat)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static InternalOmniTypedResponseFormat FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalOmniTypedResponseFormat(document.RootElement); + } + + internal virtual BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/InternalOmniTypedResponseFormat.cs b/src/Generated/Models/InternalOmniTypedResponseFormat.cs new file mode 100644 index 000000000..da255f506 --- /dev/null +++ b/src/Generated/Models/InternalOmniTypedResponseFormat.cs @@ -0,0 +1,25 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.Internal +{ + internal abstract partial class InternalOmniTypedResponseFormat + { + internal IDictionary SerializedAdditionalRawData { get; set; } + protected InternalOmniTypedResponseFormat() + { + } + + internal InternalOmniTypedResponseFormat(string type, IDictionary serializedAdditionalRawData) + { + Type = type; + SerializedAdditionalRawData = serializedAdditionalRawData; + } + + internal string Type { get; set; } + } +} diff --git a/src/Generated/Models/InternalResponseFormatJsonObject.Serialization.cs b/src/Generated/Models/InternalResponseFormatJsonObject.Serialization.cs new file mode 100644 index 000000000..66e2b97f1 --- /dev/null +++ b/src/Generated/Models/InternalResponseFormatJsonObject.Serialization.cs @@ -0,0 +1,133 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.Internal +{ + internal partial class InternalResponseFormatJsonObject : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalResponseFormatJsonObject)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalResponseFormatJsonObject IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalResponseFormatJsonObject)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalResponseFormatJsonObject(document.RootElement, options); + } + + internal static InternalResponseFormatJsonObject DeserializeInternalResponseFormatJsonObject(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new InternalResponseFormatJsonObject(type, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalResponseFormatJsonObject)} does not support writing '{options.Format}' format."); + } + } + + InternalResponseFormatJsonObject IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalResponseFormatJsonObject(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalResponseFormatJsonObject)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new InternalResponseFormatJsonObject FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalResponseFormatJsonObject(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/InternalResponseFormatJsonObject.cs b/src/Generated/Models/InternalResponseFormatJsonObject.cs new file mode 100644 index 000000000..b62b1891f --- /dev/null +++ b/src/Generated/Models/InternalResponseFormatJsonObject.cs @@ -0,0 +1,21 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.Internal +{ + internal partial class InternalResponseFormatJsonObject : InternalOmniTypedResponseFormat + { + public InternalResponseFormatJsonObject() + { + Type = "json_object"; + } + + internal InternalResponseFormatJsonObject(string type, IDictionary serializedAdditionalRawData) : base(type, serializedAdditionalRawData) + { + } + } +} diff --git a/src/Generated/Models/InternalResponseFormatJsonSchema.Serialization.cs b/src/Generated/Models/InternalResponseFormatJsonSchema.Serialization.cs new file mode 100644 index 000000000..1746508f2 --- /dev/null +++ b/src/Generated/Models/InternalResponseFormatJsonSchema.Serialization.cs @@ -0,0 +1,144 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.Internal +{ + internal partial class InternalResponseFormatJsonSchema : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalResponseFormatJsonSchema)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("json_schema") != true) + { + writer.WritePropertyName("json_schema"u8); + writer.WriteObjectValue(JsonSchema, options); + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalResponseFormatJsonSchema IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalResponseFormatJsonSchema)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalResponseFormatJsonSchema(document.RootElement, options); + } + + internal static InternalResponseFormatJsonSchema DeserializeInternalResponseFormatJsonSchema(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + InternalResponseFormatJsonSchemaJsonSchema jsonSchema = default; + string type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("json_schema"u8)) + { + jsonSchema = InternalResponseFormatJsonSchemaJsonSchema.DeserializeInternalResponseFormatJsonSchemaJsonSchema(property.Value, options); + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new InternalResponseFormatJsonSchema(type, serializedAdditionalRawData, jsonSchema); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalResponseFormatJsonSchema)} does not support writing '{options.Format}' format."); + } + } + + InternalResponseFormatJsonSchema IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalResponseFormatJsonSchema(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalResponseFormatJsonSchema)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new InternalResponseFormatJsonSchema FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalResponseFormatJsonSchema(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/InternalResponseFormatJsonSchema.cs b/src/Generated/Models/InternalResponseFormatJsonSchema.cs new file mode 100644 index 000000000..739eb22b9 --- /dev/null +++ b/src/Generated/Models/InternalResponseFormatJsonSchema.cs @@ -0,0 +1,31 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.Internal +{ + internal partial class InternalResponseFormatJsonSchema : InternalOmniTypedResponseFormat + { + public InternalResponseFormatJsonSchema(InternalResponseFormatJsonSchemaJsonSchema jsonSchema) + { + Argument.AssertNotNull(jsonSchema, nameof(jsonSchema)); + + Type = "json_schema"; + JsonSchema = jsonSchema; + } + + internal InternalResponseFormatJsonSchema(string type, IDictionary serializedAdditionalRawData, InternalResponseFormatJsonSchemaJsonSchema jsonSchema) : base(type, serializedAdditionalRawData) + { + JsonSchema = jsonSchema; + } + + internal InternalResponseFormatJsonSchema() + { + } + + public InternalResponseFormatJsonSchemaJsonSchema JsonSchema { get; set; } + } +} diff --git a/src/Generated/Models/InternalResponseFormatJsonSchemaJsonSchema.Serialization.cs b/src/Generated/Models/InternalResponseFormatJsonSchemaJsonSchema.Serialization.cs new file mode 100644 index 000000000..5b9c4d930 --- /dev/null +++ b/src/Generated/Models/InternalResponseFormatJsonSchemaJsonSchema.Serialization.cs @@ -0,0 +1,189 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.Internal +{ + internal partial class InternalResponseFormatJsonSchemaJsonSchema : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalResponseFormatJsonSchemaJsonSchema)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("description") != true && Optional.IsDefined(Description)) + { + writer.WritePropertyName("description"u8); + writer.WriteStringValue(Description); + } + if (SerializedAdditionalRawData?.ContainsKey("name") != true) + { + writer.WritePropertyName("name"u8); + writer.WriteStringValue(Name); + } + if (SerializedAdditionalRawData?.ContainsKey("schema") != true && Optional.IsDefined(Schema)) + { + writer.WritePropertyName("schema"u8); +#if NET6_0_OR_GREATER + writer.WriteRawValue(Schema); +#else + using (JsonDocument document = JsonDocument.Parse(Schema)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + if (SerializedAdditionalRawData?.ContainsKey("strict") != true && Optional.IsDefined(Strict)) + { + if (Strict != null) + { + writer.WritePropertyName("strict"u8); + writer.WriteBooleanValue(Strict.Value); + } + else + { + writer.WriteNull("strict"); + } + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalResponseFormatJsonSchemaJsonSchema IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalResponseFormatJsonSchemaJsonSchema)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalResponseFormatJsonSchemaJsonSchema(document.RootElement, options); + } + + internal static InternalResponseFormatJsonSchemaJsonSchema DeserializeInternalResponseFormatJsonSchemaJsonSchema(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string description = default; + string name = default; + BinaryData schema = default; + bool? strict = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("description"u8)) + { + description = property.Value.GetString(); + continue; + } + if (property.NameEquals("name"u8)) + { + name = property.Value.GetString(); + continue; + } + if (property.NameEquals("schema"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + schema = BinaryData.FromString(property.Value.GetRawText()); + continue; + } + if (property.NameEquals("strict"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + strict = null; + continue; + } + strict = property.Value.GetBoolean(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new InternalResponseFormatJsonSchemaJsonSchema(description, name, schema, strict, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalResponseFormatJsonSchemaJsonSchema)} does not support writing '{options.Format}' format."); + } + } + + InternalResponseFormatJsonSchemaJsonSchema IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalResponseFormatJsonSchemaJsonSchema(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalResponseFormatJsonSchemaJsonSchema)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static InternalResponseFormatJsonSchemaJsonSchema FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalResponseFormatJsonSchemaJsonSchema(document.RootElement); + } + + internal virtual BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/InternalResponseFormatJsonSchemaJsonSchema.cs b/src/Generated/Models/InternalResponseFormatJsonSchemaJsonSchema.cs new file mode 100644 index 000000000..533d36db0 --- /dev/null +++ b/src/Generated/Models/InternalResponseFormatJsonSchemaJsonSchema.cs @@ -0,0 +1,37 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.Internal +{ + internal partial class InternalResponseFormatJsonSchemaJsonSchema + { + internal IDictionary SerializedAdditionalRawData { get; set; } + public InternalResponseFormatJsonSchemaJsonSchema(string name) + { + Argument.AssertNotNull(name, nameof(name)); + + Name = name; + } + + internal InternalResponseFormatJsonSchemaJsonSchema(string description, string name, BinaryData schema, bool? strict, IDictionary serializedAdditionalRawData) + { + Description = description; + Name = name; + Schema = schema; + Strict = strict; + SerializedAdditionalRawData = serializedAdditionalRawData; + } + + internal InternalResponseFormatJsonSchemaJsonSchema() + { + } + + public string Description { get; set; } + public string Name { get; set; } + public bool? Strict { get; set; } + } +} diff --git a/src/Generated/Models/InternalResponseFormatJsonSchemaSchema.Serialization.cs b/src/Generated/Models/InternalResponseFormatJsonSchemaSchema.Serialization.cs new file mode 100644 index 000000000..d77918543 --- /dev/null +++ b/src/Generated/Models/InternalResponseFormatJsonSchemaSchema.Serialization.cs @@ -0,0 +1,111 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.Internal +{ + internal partial class InternalResponseFormatJsonSchemaSchema : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalResponseFormatJsonSchemaSchema)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + foreach (var item in AdditionalProperties) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + writer.WriteEndObject(); + } + + InternalResponseFormatJsonSchemaSchema IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalResponseFormatJsonSchemaSchema)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalResponseFormatJsonSchemaSchema(document.RootElement, options); + } + + internal static InternalResponseFormatJsonSchemaSchema DeserializeInternalResponseFormatJsonSchemaSchema(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + IDictionary additionalProperties = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + additionalProperties = additionalPropertiesDictionary; + return new InternalResponseFormatJsonSchemaSchema(additionalProperties); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalResponseFormatJsonSchemaSchema)} does not support writing '{options.Format}' format."); + } + } + + InternalResponseFormatJsonSchemaSchema IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalResponseFormatJsonSchemaSchema(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalResponseFormatJsonSchemaSchema)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static InternalResponseFormatJsonSchemaSchema FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalResponseFormatJsonSchemaSchema(document.RootElement); + } + + internal virtual BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/InternalResponseFormatJsonSchemaSchema.cs b/src/Generated/Models/InternalResponseFormatJsonSchemaSchema.cs new file mode 100644 index 000000000..d00500adb --- /dev/null +++ b/src/Generated/Models/InternalResponseFormatJsonSchemaSchema.cs @@ -0,0 +1,24 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.Internal +{ + internal partial class InternalResponseFormatJsonSchemaSchema + { + public InternalResponseFormatJsonSchemaSchema() + { + AdditionalProperties = new ChangeTrackingDictionary(); + } + + internal InternalResponseFormatJsonSchemaSchema(IDictionary additionalProperties) + { + AdditionalProperties = additionalProperties; + } + + public IDictionary AdditionalProperties { get; } + } +} diff --git a/src/Generated/Models/InternalResponseFormatText.Serialization.cs b/src/Generated/Models/InternalResponseFormatText.Serialization.cs new file mode 100644 index 000000000..b213da2e7 --- /dev/null +++ b/src/Generated/Models/InternalResponseFormatText.Serialization.cs @@ -0,0 +1,133 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.Internal +{ + internal partial class InternalResponseFormatText : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalResponseFormatText)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalResponseFormatText IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalResponseFormatText)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalResponseFormatText(document.RootElement, options); + } + + internal static InternalResponseFormatText DeserializeInternalResponseFormatText(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new InternalResponseFormatText(type, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalResponseFormatText)} does not support writing '{options.Format}' format."); + } + } + + InternalResponseFormatText IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalResponseFormatText(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalResponseFormatText)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new InternalResponseFormatText FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalResponseFormatText(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/InternalResponseFormatText.cs b/src/Generated/Models/InternalResponseFormatText.cs new file mode 100644 index 000000000..efe4d6fce --- /dev/null +++ b/src/Generated/Models/InternalResponseFormatText.cs @@ -0,0 +1,21 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.Internal +{ + internal partial class InternalResponseFormatText : InternalOmniTypedResponseFormat + { + public InternalResponseFormatText() + { + Type = "text"; + } + + internal InternalResponseFormatText(string type, IDictionary serializedAdditionalRawData) : base(type, serializedAdditionalRawData) + { + } + } +} diff --git a/src/Generated/Models/InternalModifyThreadRequestToolResourcesFileSearch.Serialization.cs b/src/Generated/Models/InternalToolResourcesFileSearchIdsOnly.Serialization.cs similarity index 62% rename from src/Generated/Models/InternalModifyThreadRequestToolResourcesFileSearch.Serialization.cs rename to src/Generated/Models/InternalToolResourcesFileSearchIdsOnly.Serialization.cs index 9aa936c8e..3b188f3b2 100644 --- a/src/Generated/Models/InternalModifyThreadRequestToolResourcesFileSearch.Serialization.cs +++ b/src/Generated/Models/InternalToolResourcesFileSearchIdsOnly.Serialization.cs @@ -10,14 +10,14 @@ namespace OpenAI.Assistants { - internal partial class InternalModifyThreadRequestToolResourcesFileSearch : IJsonModel + internal partial class InternalToolResourcesFileSearchIdsOnly : IJsonModel { - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { - throw new FormatException($"The model {nameof(InternalModifyThreadRequestToolResourcesFileSearch)} does not support writing '{format}' format."); + throw new FormatException($"The model {nameof(InternalToolResourcesFileSearchIdsOnly)} does not support writing '{format}' format."); } writer.WriteStartObject(); @@ -53,19 +53,19 @@ void IJsonModel.Write(Utf8Js writer.WriteEndObject(); } - InternalModifyThreadRequestToolResourcesFileSearch IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + InternalToolResourcesFileSearchIdsOnly IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { - throw new FormatException($"The model {nameof(InternalModifyThreadRequestToolResourcesFileSearch)} does not support reading '{format}' format."); + throw new FormatException($"The model {nameof(InternalToolResourcesFileSearchIdsOnly)} does not support reading '{format}' format."); } using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeInternalModifyThreadRequestToolResourcesFileSearch(document.RootElement, options); + return DeserializeInternalToolResourcesFileSearchIdsOnly(document.RootElement, options); } - internal static InternalModifyThreadRequestToolResourcesFileSearch DeserializeInternalModifyThreadRequestToolResourcesFileSearch(JsonElement element, ModelReaderWriterOptions options = null) + internal static InternalToolResourcesFileSearchIdsOnly DeserializeInternalToolResourcesFileSearchIdsOnly(JsonElement element, ModelReaderWriterOptions options = null) { options ??= ModelSerializationExtensions.WireOptions; @@ -99,44 +99,44 @@ internal static InternalModifyThreadRequestToolResourcesFileSearch DeserializeIn } } serializedAdditionalRawData = rawDataDictionary; - return new InternalModifyThreadRequestToolResourcesFileSearch(vectorStoreIds ?? new ChangeTrackingList(), serializedAdditionalRawData); + return new InternalToolResourcesFileSearchIdsOnly(vectorStoreIds ?? new ChangeTrackingList(), serializedAdditionalRawData); } - BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": return ModelReaderWriter.Write(this, options); default: - throw new FormatException($"The model {nameof(InternalModifyThreadRequestToolResourcesFileSearch)} does not support writing '{options.Format}' format."); + throw new FormatException($"The model {nameof(InternalToolResourcesFileSearchIdsOnly)} does not support writing '{options.Format}' format."); } } - InternalModifyThreadRequestToolResourcesFileSearch IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + InternalToolResourcesFileSearchIdsOnly IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": { using JsonDocument document = JsonDocument.Parse(data); - return DeserializeInternalModifyThreadRequestToolResourcesFileSearch(document.RootElement, options); + return DeserializeInternalToolResourcesFileSearchIdsOnly(document.RootElement, options); } default: - throw new FormatException($"The model {nameof(InternalModifyThreadRequestToolResourcesFileSearch)} does not support reading '{options.Format}' format."); + throw new FormatException($"The model {nameof(InternalToolResourcesFileSearchIdsOnly)} does not support reading '{options.Format}' format."); } } - string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; - internal static InternalModifyThreadRequestToolResourcesFileSearch FromResponse(PipelineResponse response) + internal static InternalToolResourcesFileSearchIdsOnly FromResponse(PipelineResponse response) { using var document = JsonDocument.Parse(response.Content); - return DeserializeInternalModifyThreadRequestToolResourcesFileSearch(document.RootElement); + return DeserializeInternalToolResourcesFileSearchIdsOnly(document.RootElement); } internal virtual BinaryContent ToBinaryContent() diff --git a/src/Generated/Models/InternalModifyThreadRequestToolResourcesFileSearch.cs b/src/Generated/Models/InternalToolResourcesFileSearchIdsOnly.cs similarity index 62% rename from src/Generated/Models/InternalModifyThreadRequestToolResourcesFileSearch.cs rename to src/Generated/Models/InternalToolResourcesFileSearchIdsOnly.cs index f87c6ace1..33ed0185e 100644 --- a/src/Generated/Models/InternalModifyThreadRequestToolResourcesFileSearch.cs +++ b/src/Generated/Models/InternalToolResourcesFileSearchIdsOnly.cs @@ -7,15 +7,15 @@ namespace OpenAI.Assistants { - internal partial class InternalModifyThreadRequestToolResourcesFileSearch + internal partial class InternalToolResourcesFileSearchIdsOnly { internal IDictionary SerializedAdditionalRawData { get; set; } - public InternalModifyThreadRequestToolResourcesFileSearch() + public InternalToolResourcesFileSearchIdsOnly() { VectorStoreIds = new ChangeTrackingList(); } - internal InternalModifyThreadRequestToolResourcesFileSearch(IList vectorStoreIds, IDictionary serializedAdditionalRawData) + internal InternalToolResourcesFileSearchIdsOnly(IList vectorStoreIds, IDictionary serializedAdditionalRawData) { VectorStoreIds = vectorStoreIds; SerializedAdditionalRawData = serializedAdditionalRawData; diff --git a/src/Generated/Models/InternalUnknownAssistantResponseFormat.Serialization.cs b/src/Generated/Models/InternalUnknownAssistantResponseFormat.Serialization.cs new file mode 100644 index 000000000..ff9e4c05e --- /dev/null +++ b/src/Generated/Models/InternalUnknownAssistantResponseFormat.Serialization.cs @@ -0,0 +1,122 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.Assistants +{ + internal partial class InternalUnknownAssistantResponseFormat : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(AssistantResponseFormat)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + AssistantResponseFormat IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(AssistantResponseFormat)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeAssistantResponseFormat(document.RootElement, options); + } + + internal static InternalUnknownAssistantResponseFormat DeserializeInternalUnknownAssistantResponseFormat(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string type = "Unknown"; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new InternalUnknownAssistantResponseFormat(type, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(AssistantResponseFormat)} does not support writing '{options.Format}' format."); + } + } + + AssistantResponseFormat IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeAssistantResponseFormat(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(AssistantResponseFormat)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + } +} diff --git a/src/Generated/Models/InternalUnknownAssistantResponseFormat.cs b/src/Generated/Models/InternalUnknownAssistantResponseFormat.cs new file mode 100644 index 000000000..13ee16c7d --- /dev/null +++ b/src/Generated/Models/InternalUnknownAssistantResponseFormat.cs @@ -0,0 +1,20 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.Assistants +{ + internal partial class InternalUnknownAssistantResponseFormat : AssistantResponseFormat + { + internal InternalUnknownAssistantResponseFormat(string type, IDictionary serializedAdditionalRawData) : base(type, serializedAdditionalRawData) + { + } + + internal InternalUnknownAssistantResponseFormat() + { + } + } +} diff --git a/src/Generated/Models/InternalUnknownChatResponseFormat.Serialization.cs b/src/Generated/Models/InternalUnknownChatResponseFormat.Serialization.cs new file mode 100644 index 000000000..0bc64d31b --- /dev/null +++ b/src/Generated/Models/InternalUnknownChatResponseFormat.Serialization.cs @@ -0,0 +1,133 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.Chat +{ + internal partial class InternalUnknownChatResponseFormat : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ChatResponseFormat)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ChatResponseFormat IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ChatResponseFormat)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeChatResponseFormat(document.RootElement, options); + } + + internal static InternalUnknownChatResponseFormat DeserializeInternalUnknownChatResponseFormat(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string type = "Unknown"; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new InternalUnknownChatResponseFormat(type, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ChatResponseFormat)} does not support writing '{options.Format}' format."); + } + } + + ChatResponseFormat IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeChatResponseFormat(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ChatResponseFormat)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new InternalUnknownChatResponseFormat FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalUnknownChatResponseFormat(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/InternalUnknownChatResponseFormat.cs b/src/Generated/Models/InternalUnknownChatResponseFormat.cs new file mode 100644 index 000000000..e3def713f --- /dev/null +++ b/src/Generated/Models/InternalUnknownChatResponseFormat.cs @@ -0,0 +1,20 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.Chat +{ + internal partial class InternalUnknownChatResponseFormat : ChatResponseFormat + { + internal InternalUnknownChatResponseFormat(string type, IDictionary serializedAdditionalRawData) : base(type, serializedAdditionalRawData) + { + } + + internal InternalUnknownChatResponseFormat() + { + } + } +} diff --git a/src/Generated/Models/InternalUnknownOmniTypedResponseFormat.Serialization.cs b/src/Generated/Models/InternalUnknownOmniTypedResponseFormat.Serialization.cs new file mode 100644 index 000000000..43b17f909 --- /dev/null +++ b/src/Generated/Models/InternalUnknownOmniTypedResponseFormat.Serialization.cs @@ -0,0 +1,133 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.Internal +{ + internal partial class InternalUnknownOmniTypedResponseFormat : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalOmniTypedResponseFormat)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalOmniTypedResponseFormat IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalOmniTypedResponseFormat)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalOmniTypedResponseFormat(document.RootElement, options); + } + + internal static InternalUnknownOmniTypedResponseFormat DeserializeInternalUnknownOmniTypedResponseFormat(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string type = "Unknown"; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new InternalUnknownOmniTypedResponseFormat(type, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalOmniTypedResponseFormat)} does not support writing '{options.Format}' format."); + } + } + + InternalOmniTypedResponseFormat IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalOmniTypedResponseFormat(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalOmniTypedResponseFormat)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new InternalUnknownOmniTypedResponseFormat FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalUnknownOmniTypedResponseFormat(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/InternalUnknownOmniTypedResponseFormat.cs b/src/Generated/Models/InternalUnknownOmniTypedResponseFormat.cs new file mode 100644 index 000000000..8ae4808ff --- /dev/null +++ b/src/Generated/Models/InternalUnknownOmniTypedResponseFormat.cs @@ -0,0 +1,20 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.Internal +{ + internal partial class InternalUnknownOmniTypedResponseFormat : InternalOmniTypedResponseFormat + { + internal InternalUnknownOmniTypedResponseFormat(string type, IDictionary serializedAdditionalRawData) : base(type, serializedAdditionalRawData) + { + } + + internal InternalUnknownOmniTypedResponseFormat() + { + } + } +} diff --git a/src/Generated/Models/InternalUpload.Serialization.cs b/src/Generated/Models/InternalUpload.Serialization.cs new file mode 100644 index 000000000..6b2b8604d --- /dev/null +++ b/src/Generated/Models/InternalUpload.Serialization.cs @@ -0,0 +1,247 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.Files +{ + internal partial class InternalUpload : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalUpload)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("id") != true) + { + writer.WritePropertyName("id"u8); + writer.WriteStringValue(Id); + } + if (SerializedAdditionalRawData?.ContainsKey("created_at") != true) + { + writer.WritePropertyName("created_at"u8); + writer.WriteNumberValue(CreatedAt, "U"); + } + if (SerializedAdditionalRawData?.ContainsKey("filename") != true) + { + writer.WritePropertyName("filename"u8); + writer.WriteStringValue(Filename); + } + if (SerializedAdditionalRawData?.ContainsKey("bytes") != true) + { + writer.WritePropertyName("bytes"u8); + writer.WriteNumberValue(Bytes); + } + if (SerializedAdditionalRawData?.ContainsKey("purpose") != true) + { + writer.WritePropertyName("purpose"u8); + writer.WriteStringValue(Purpose); + } + if (SerializedAdditionalRawData?.ContainsKey("status") != true) + { + writer.WritePropertyName("status"u8); + writer.WriteStringValue(Status.ToString()); + } + if (SerializedAdditionalRawData?.ContainsKey("expires_at") != true) + { + writer.WritePropertyName("expires_at"u8); + writer.WriteNumberValue(ExpiresAt, "U"); + } + if (SerializedAdditionalRawData?.ContainsKey("object") != true && Optional.IsDefined(Object)) + { + writer.WritePropertyName("object"u8); + writer.WriteStringValue(Object.Value.ToString()); + } + if (SerializedAdditionalRawData?.ContainsKey("file") != true && Optional.IsDefined(File)) + { + if (File != null) + { + writer.WritePropertyName("file"u8); + writer.WriteObjectValue(File, options); + } + else + { + writer.WriteNull("file"); + } + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalUpload IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalUpload)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalUpload(document.RootElement, options); + } + + internal static InternalUpload DeserializeInternalUpload(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string id = default; + DateTimeOffset createdAt = default; + string filename = default; + int bytes = default; + string purpose = default; + InternalUploadStatus status = default; + DateTimeOffset expiresAt = default; + InternalUploadObject? @object = default; + OpenAIFileInfo file = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("id"u8)) + { + id = property.Value.GetString(); + continue; + } + if (property.NameEquals("created_at"u8)) + { + createdAt = DateTimeOffset.FromUnixTimeSeconds(property.Value.GetInt64()); + continue; + } + if (property.NameEquals("filename"u8)) + { + filename = property.Value.GetString(); + continue; + } + if (property.NameEquals("bytes"u8)) + { + bytes = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("purpose"u8)) + { + purpose = property.Value.GetString(); + continue; + } + if (property.NameEquals("status"u8)) + { + status = new InternalUploadStatus(property.Value.GetString()); + continue; + } + if (property.NameEquals("expires_at"u8)) + { + expiresAt = DateTimeOffset.FromUnixTimeSeconds(property.Value.GetInt64()); + continue; + } + if (property.NameEquals("object"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + @object = new InternalUploadObject(property.Value.GetString()); + continue; + } + if (property.NameEquals("file"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + file = null; + continue; + } + file = OpenAIFileInfo.DeserializeOpenAIFileInfo(property.Value, options); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new InternalUpload( + id, + createdAt, + filename, + bytes, + purpose, + status, + expiresAt, + @object, + file, + serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalUpload)} does not support writing '{options.Format}' format."); + } + } + + InternalUpload IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalUpload(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalUpload)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static InternalUpload FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalUpload(document.RootElement); + } + + internal virtual BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/InternalUpload.cs b/src/Generated/Models/InternalUpload.cs new file mode 100644 index 000000000..fb464dedd --- /dev/null +++ b/src/Generated/Models/InternalUpload.cs @@ -0,0 +1,56 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.Files +{ + internal partial class InternalUpload + { + internal IDictionary SerializedAdditionalRawData { get; set; } + internal InternalUpload(string id, DateTimeOffset createdAt, string filename, int bytes, string purpose, InternalUploadStatus status, DateTimeOffset expiresAt) + { + Argument.AssertNotNull(id, nameof(id)); + Argument.AssertNotNull(filename, nameof(filename)); + Argument.AssertNotNull(purpose, nameof(purpose)); + + Id = id; + CreatedAt = createdAt; + Filename = filename; + Bytes = bytes; + Purpose = purpose; + Status = status; + ExpiresAt = expiresAt; + } + + internal InternalUpload(string id, DateTimeOffset createdAt, string filename, int bytes, string purpose, InternalUploadStatus status, DateTimeOffset expiresAt, InternalUploadObject? @object, OpenAIFileInfo file, IDictionary serializedAdditionalRawData) + { + Id = id; + CreatedAt = createdAt; + Filename = filename; + Bytes = bytes; + Purpose = purpose; + Status = status; + ExpiresAt = expiresAt; + Object = @object; + File = file; + SerializedAdditionalRawData = serializedAdditionalRawData; + } + + internal InternalUpload() + { + } + + public string Id { get; } + public DateTimeOffset CreatedAt { get; } + public string Filename { get; } + public int Bytes { get; } + public string Purpose { get; } + public InternalUploadStatus Status { get; } + public DateTimeOffset ExpiresAt { get; } + public InternalUploadObject? Object { get; } + public OpenAIFileInfo File { get; } + } +} diff --git a/src/Generated/Models/InternalUploadObject.cs b/src/Generated/Models/InternalUploadObject.cs new file mode 100644 index 000000000..9dacd622a --- /dev/null +++ b/src/Generated/Models/InternalUploadObject.cs @@ -0,0 +1,34 @@ +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace OpenAI.Files +{ + internal readonly partial struct InternalUploadObject : IEquatable + { + private readonly string _value; + + public InternalUploadObject(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string UploadValue = "upload"; + + public static InternalUploadObject Upload { get; } = new InternalUploadObject(UploadValue); + public static bool operator ==(InternalUploadObject left, InternalUploadObject right) => left.Equals(right); + public static bool operator !=(InternalUploadObject left, InternalUploadObject right) => !left.Equals(right); + public static implicit operator InternalUploadObject(string value) => new InternalUploadObject(value); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is InternalUploadObject other && Equals(other); + public bool Equals(InternalUploadObject other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; + public override string ToString() => _value; + } +} diff --git a/src/Generated/Models/InternalUploadPart.Serialization.cs b/src/Generated/Models/InternalUploadPart.Serialization.cs new file mode 100644 index 000000000..c6f4c77f8 --- /dev/null +++ b/src/Generated/Models/InternalUploadPart.Serialization.cs @@ -0,0 +1,166 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.Files +{ + internal partial class InternalUploadPart : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalUploadPart)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("id") != true) + { + writer.WritePropertyName("id"u8); + writer.WriteStringValue(Id); + } + if (SerializedAdditionalRawData?.ContainsKey("created_at") != true) + { + writer.WritePropertyName("created_at"u8); + writer.WriteNumberValue(CreatedAt, "U"); + } + if (SerializedAdditionalRawData?.ContainsKey("upload_id") != true) + { + writer.WritePropertyName("upload_id"u8); + writer.WriteStringValue(UploadId); + } + if (SerializedAdditionalRawData?.ContainsKey("object") != true) + { + writer.WritePropertyName("object"u8); + writer.WriteStringValue(Object.ToString()); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalUploadPart IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalUploadPart)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalUploadPart(document.RootElement, options); + } + + internal static InternalUploadPart DeserializeInternalUploadPart(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string id = default; + DateTimeOffset createdAt = default; + string uploadId = default; + InternalUploadPartObject @object = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("id"u8)) + { + id = property.Value.GetString(); + continue; + } + if (property.NameEquals("created_at"u8)) + { + createdAt = DateTimeOffset.FromUnixTimeSeconds(property.Value.GetInt64()); + continue; + } + if (property.NameEquals("upload_id"u8)) + { + uploadId = property.Value.GetString(); + continue; + } + if (property.NameEquals("object"u8)) + { + @object = new InternalUploadPartObject(property.Value.GetString()); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new InternalUploadPart(id, createdAt, uploadId, @object, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalUploadPart)} does not support writing '{options.Format}' format."); + } + } + + InternalUploadPart IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalUploadPart(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalUploadPart)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static InternalUploadPart FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalUploadPart(document.RootElement); + } + + internal virtual BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/InternalUploadPart.cs b/src/Generated/Models/InternalUploadPart.cs new file mode 100644 index 000000000..5a7239276 --- /dev/null +++ b/src/Generated/Models/InternalUploadPart.cs @@ -0,0 +1,41 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.Files +{ + internal partial class InternalUploadPart + { + internal IDictionary SerializedAdditionalRawData { get; set; } + internal InternalUploadPart(string id, DateTimeOffset createdAt, string uploadId) + { + Argument.AssertNotNull(id, nameof(id)); + Argument.AssertNotNull(uploadId, nameof(uploadId)); + + Id = id; + CreatedAt = createdAt; + UploadId = uploadId; + } + + internal InternalUploadPart(string id, DateTimeOffset createdAt, string uploadId, InternalUploadPartObject @object, IDictionary serializedAdditionalRawData) + { + Id = id; + CreatedAt = createdAt; + UploadId = uploadId; + Object = @object; + SerializedAdditionalRawData = serializedAdditionalRawData; + } + + internal InternalUploadPart() + { + } + + public string Id { get; } + public DateTimeOffset CreatedAt { get; } + public string UploadId { get; } + public InternalUploadPartObject Object { get; } = InternalUploadPartObject.UploadPart; + } +} diff --git a/src/Generated/Models/InternalUploadPartObject.cs b/src/Generated/Models/InternalUploadPartObject.cs new file mode 100644 index 000000000..b790ad181 --- /dev/null +++ b/src/Generated/Models/InternalUploadPartObject.cs @@ -0,0 +1,34 @@ +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace OpenAI.Files +{ + internal readonly partial struct InternalUploadPartObject : IEquatable + { + private readonly string _value; + + public InternalUploadPartObject(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string UploadPartValue = "upload.part"; + + public static InternalUploadPartObject UploadPart { get; } = new InternalUploadPartObject(UploadPartValue); + public static bool operator ==(InternalUploadPartObject left, InternalUploadPartObject right) => left.Equals(right); + public static bool operator !=(InternalUploadPartObject left, InternalUploadPartObject right) => !left.Equals(right); + public static implicit operator InternalUploadPartObject(string value) => new InternalUploadPartObject(value); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is InternalUploadPartObject other && Equals(other); + public bool Equals(InternalUploadPartObject other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; + public override string ToString() => _value; + } +} diff --git a/src/Generated/Models/InternalUploadStatus.cs b/src/Generated/Models/InternalUploadStatus.cs new file mode 100644 index 000000000..4ac5876d4 --- /dev/null +++ b/src/Generated/Models/InternalUploadStatus.cs @@ -0,0 +1,40 @@ +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace OpenAI.Files +{ + internal readonly partial struct InternalUploadStatus : IEquatable + { + private readonly string _value; + + public InternalUploadStatus(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string PendingValue = "pending"; + private const string CompletedValue = "completed"; + private const string CancelledValue = "cancelled"; + private const string ExpiredValue = "expired"; + + public static InternalUploadStatus Pending { get; } = new InternalUploadStatus(PendingValue); + public static InternalUploadStatus Completed { get; } = new InternalUploadStatus(CompletedValue); + public static InternalUploadStatus Cancelled { get; } = new InternalUploadStatus(CancelledValue); + public static InternalUploadStatus Expired { get; } = new InternalUploadStatus(ExpiredValue); + public static bool operator ==(InternalUploadStatus left, InternalUploadStatus right) => left.Equals(right); + public static bool operator !=(InternalUploadStatus left, InternalUploadStatus right) => !left.Equals(right); + public static implicit operator InternalUploadStatus(string value) => new InternalUploadStatus(value); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is InternalUploadStatus other && Equals(other); + public bool Equals(InternalUploadStatus other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; + public override string ToString() => _value; + } +} diff --git a/src/Generated/Models/StreamingChatCompletionUpdate.Serialization.cs b/src/Generated/Models/StreamingChatCompletionUpdate.Serialization.cs index 2a84823e3..6a39741da 100644 --- a/src/Generated/Models/StreamingChatCompletionUpdate.Serialization.cs +++ b/src/Generated/Models/StreamingChatCompletionUpdate.Serialization.cs @@ -46,6 +46,18 @@ void IJsonModel.Write(Utf8JsonWriter writer, Mode writer.WritePropertyName("model"u8); writer.WriteStringValue(Model); } + if (SerializedAdditionalRawData?.ContainsKey("service_tier") != true && Optional.IsDefined(ServiceTier)) + { + if (ServiceTier != null) + { + writer.WritePropertyName("service_tier"u8); + writer.WriteStringValue(ServiceTier.Value.ToString()); + } + else + { + writer.WriteNull("service_tier"); + } + } if (SerializedAdditionalRawData?.ContainsKey("system_fingerprint") != true && Optional.IsDefined(SystemFingerprint)) { writer.WritePropertyName("system_fingerprint"u8); @@ -107,6 +119,7 @@ internal static StreamingChatCompletionUpdate DeserializeStreamingChatCompletion IReadOnlyList choices = default; DateTimeOffset created = default; string model = default; + InternalCreateChatCompletionStreamResponseServiceTier? serviceTier = default; string systemFingerprint = default; InternalCreateChatCompletionStreamResponseObject @object = default; ChatTokenUsage usage = default; @@ -139,6 +152,16 @@ internal static StreamingChatCompletionUpdate DeserializeStreamingChatCompletion model = property.Value.GetString(); continue; } + if (property.NameEquals("service_tier"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + serviceTier = null; + continue; + } + serviceTier = new InternalCreateChatCompletionStreamResponseServiceTier(property.Value.GetString()); + continue; + } if (property.NameEquals("system_fingerprint"u8)) { systemFingerprint = property.Value.GetString(); @@ -170,6 +193,7 @@ internal static StreamingChatCompletionUpdate DeserializeStreamingChatCompletion choices, created, model, + serviceTier, systemFingerprint, @object, usage, diff --git a/src/Generated/Models/StreamingChatCompletionUpdate.cs b/src/Generated/Models/StreamingChatCompletionUpdate.cs index 8132fd98f..b72279024 100644 --- a/src/Generated/Models/StreamingChatCompletionUpdate.cs +++ b/src/Generated/Models/StreamingChatCompletionUpdate.cs @@ -23,12 +23,13 @@ internal StreamingChatCompletionUpdate(string id, IEnumerable choices, DateTimeOffset createdAt, string model, string systemFingerprint, InternalCreateChatCompletionStreamResponseObject @object, ChatTokenUsage usage, IDictionary serializedAdditionalRawData) + internal StreamingChatCompletionUpdate(string id, IReadOnlyList choices, DateTimeOffset createdAt, string model, InternalCreateChatCompletionStreamResponseServiceTier? serviceTier, string systemFingerprint, InternalCreateChatCompletionStreamResponseObject @object, ChatTokenUsage usage, IDictionary serializedAdditionalRawData) { Id = id; Choices = choices; CreatedAt = createdAt; Model = model; + ServiceTier = serviceTier; SystemFingerprint = systemFingerprint; Object = @object; Usage = usage; diff --git a/src/Generated/Models/SystemChatMessage.Serialization.cs b/src/Generated/Models/SystemChatMessage.Serialization.cs index a3029045a..71a6676c5 100644 --- a/src/Generated/Models/SystemChatMessage.Serialization.cs +++ b/src/Generated/Models/SystemChatMessage.Serialization.cs @@ -33,7 +33,7 @@ internal static SystemChatMessage DeserializeSystemChatMessage(JsonElement eleme return null; } string name = default; - string role = default; + ChatMessageRole role = default; IList content = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); @@ -46,7 +46,7 @@ internal static SystemChatMessage DeserializeSystemChatMessage(JsonElement eleme } if (property.NameEquals("role"u8)) { - role = property.Value.GetString(); + role = property.Value.GetString().ToChatMessageRole(); continue; } if (property.NameEquals("content"u8)) diff --git a/src/Generated/Models/SystemChatMessage.cs b/src/Generated/Models/SystemChatMessage.cs index 9d8c1c9da..962eee34b 100644 --- a/src/Generated/Models/SystemChatMessage.cs +++ b/src/Generated/Models/SystemChatMessage.cs @@ -9,7 +9,7 @@ namespace OpenAI.Chat { public partial class SystemChatMessage : ChatMessage { - internal SystemChatMessage(string role, IList content, IDictionary serializedAdditionalRawData, string participantName) : base(role, content, serializedAdditionalRawData) + internal SystemChatMessage(ChatMessageRole role, IList content, IDictionary serializedAdditionalRawData, string participantName) : base(role, content, serializedAdditionalRawData) { ParticipantName = participantName; } diff --git a/src/Generated/Models/ToolChatMessage.Serialization.cs b/src/Generated/Models/ToolChatMessage.Serialization.cs index 4cff864a2..fb4921699 100644 --- a/src/Generated/Models/ToolChatMessage.Serialization.cs +++ b/src/Generated/Models/ToolChatMessage.Serialization.cs @@ -33,7 +33,7 @@ internal static ToolChatMessage DeserializeToolChatMessage(JsonElement element, return null; } string toolCallId = default; - string role = default; + ChatMessageRole role = default; IList content = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); @@ -46,7 +46,7 @@ internal static ToolChatMessage DeserializeToolChatMessage(JsonElement element, } if (property.NameEquals("role"u8)) { - role = property.Value.GetString(); + role = property.Value.GetString().ToChatMessageRole(); continue; } if (property.NameEquals("content"u8)) diff --git a/src/Generated/Models/ToolChatMessage.cs b/src/Generated/Models/ToolChatMessage.cs index 02ad0ddc9..d0d4c210b 100644 --- a/src/Generated/Models/ToolChatMessage.cs +++ b/src/Generated/Models/ToolChatMessage.cs @@ -9,7 +9,7 @@ namespace OpenAI.Chat { public partial class ToolChatMessage : ChatMessage { - internal ToolChatMessage(string role, IList content, IDictionary serializedAdditionalRawData, string toolCallId) : base(role, content, serializedAdditionalRawData) + internal ToolChatMessage(ChatMessageRole role, IList content, IDictionary serializedAdditionalRawData, string toolCallId) : base(role, content, serializedAdditionalRawData) { ToolCallId = toolCallId; } diff --git a/src/Generated/Models/UnknownChatMessage.cs b/src/Generated/Models/UnknownChatMessage.cs index 901a1ea1c..431558af6 100644 --- a/src/Generated/Models/UnknownChatMessage.cs +++ b/src/Generated/Models/UnknownChatMessage.cs @@ -9,7 +9,7 @@ namespace OpenAI.Chat { internal partial class UnknownChatMessage : ChatMessage { - internal UnknownChatMessage(string role, IList content, IDictionary serializedAdditionalRawData) : base(role, content, serializedAdditionalRawData) + internal UnknownChatMessage(ChatMessageRole role, IList content, IDictionary serializedAdditionalRawData) : base(role, content, serializedAdditionalRawData) { } diff --git a/src/Generated/Models/UserChatMessage.Serialization.cs b/src/Generated/Models/UserChatMessage.Serialization.cs index 0b92b0281..c6fdb45b8 100644 --- a/src/Generated/Models/UserChatMessage.Serialization.cs +++ b/src/Generated/Models/UserChatMessage.Serialization.cs @@ -33,7 +33,7 @@ internal static UserChatMessage DeserializeUserChatMessage(JsonElement element, return null; } string name = default; - string role = default; + ChatMessageRole role = default; IList content = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); @@ -46,7 +46,7 @@ internal static UserChatMessage DeserializeUserChatMessage(JsonElement element, } if (property.NameEquals("role"u8)) { - role = property.Value.GetString(); + role = property.Value.GetString().ToChatMessageRole(); continue; } if (property.NameEquals("content"u8)) diff --git a/src/Generated/Models/UserChatMessage.cs b/src/Generated/Models/UserChatMessage.cs index 84c5fad7a..65a986ebd 100644 --- a/src/Generated/Models/UserChatMessage.cs +++ b/src/Generated/Models/UserChatMessage.cs @@ -9,7 +9,7 @@ namespace OpenAI.Chat { public partial class UserChatMessage : ChatMessage { - internal UserChatMessage(string role, IList content, IDictionary serializedAdditionalRawData, string participantName) : base(role, content, serializedAdditionalRawData) + internal UserChatMessage(ChatMessageRole role, IList content, IDictionary serializedAdditionalRawData, string participantName) : base(role, content, serializedAdditionalRawData) { ParticipantName = participantName; } diff --git a/src/Generated/Models/VectorStoreCreationHelper.Serialization.cs b/src/Generated/Models/VectorStoreCreationHelper.Serialization.cs index 590b20de0..3004632e0 100644 --- a/src/Generated/Models/VectorStoreCreationHelper.Serialization.cs +++ b/src/Generated/Models/VectorStoreCreationHelper.Serialization.cs @@ -7,6 +7,7 @@ using System.ClientModel.Primitives; using System.Collections.Generic; using System.Text.Json; +using OpenAI.VectorStores; namespace OpenAI.Assistants { @@ -31,6 +32,11 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelRea } writer.WriteEndArray(); } + if (SerializedAdditionalRawData?.ContainsKey("chunking_strategy") != true && Optional.IsDefined(ChunkingStrategy)) + { + writer.WritePropertyName("chunking_strategy"u8); + writer.WriteObjectValue(ChunkingStrategy, options); + } if (SerializedAdditionalRawData?.ContainsKey("metadata") != true && Optional.IsCollectionDefined(Metadata)) { writer.WritePropertyName("metadata"u8); @@ -85,6 +91,7 @@ internal static VectorStoreCreationHelper DeserializeVectorStoreCreationHelper(J return null; } IList fileIds = default; + FileChunkingStrategy chunkingStrategy = default; IDictionary metadata = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); @@ -104,6 +111,15 @@ internal static VectorStoreCreationHelper DeserializeVectorStoreCreationHelper(J fileIds = array; continue; } + if (property.NameEquals("chunking_strategy"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + chunkingStrategy = FileChunkingStrategy.DeserializeFileChunkingStrategy(property.Value, options); + continue; + } if (property.NameEquals("metadata"u8)) { if (property.Value.ValueKind == JsonValueKind.Null) @@ -125,7 +141,7 @@ internal static VectorStoreCreationHelper DeserializeVectorStoreCreationHelper(J } } serializedAdditionalRawData = rawDataDictionary; - return new VectorStoreCreationHelper(fileIds ?? new ChangeTrackingList(), metadata ?? new ChangeTrackingDictionary(), serializedAdditionalRawData); + return new VectorStoreCreationHelper(fileIds ?? new ChangeTrackingList(), chunkingStrategy, metadata ?? new ChangeTrackingDictionary(), serializedAdditionalRawData); } BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) diff --git a/src/Generated/Models/VectorStoreCreationHelper.cs b/src/Generated/Models/VectorStoreCreationHelper.cs index e8d2702b5..6871ab916 100644 --- a/src/Generated/Models/VectorStoreCreationHelper.cs +++ b/src/Generated/Models/VectorStoreCreationHelper.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; +using OpenAI.VectorStores; namespace OpenAI.Assistants { @@ -16,9 +17,10 @@ public VectorStoreCreationHelper() Metadata = new ChangeTrackingDictionary(); } - internal VectorStoreCreationHelper(IList fileIds, IDictionary metadata, IDictionary serializedAdditionalRawData) + internal VectorStoreCreationHelper(IList fileIds, FileChunkingStrategy chunkingStrategy, IDictionary metadata, IDictionary serializedAdditionalRawData) { FileIds = fileIds; + ChunkingStrategy = chunkingStrategy; Metadata = metadata; SerializedAdditionalRawData = serializedAdditionalRawData; } diff --git a/src/Generated/Models/VectorStoreFileAssociationErrorCode.cs b/src/Generated/Models/VectorStoreFileAssociationErrorCode.cs index 22d86b611..167ad6b2a 100644 --- a/src/Generated/Models/VectorStoreFileAssociationErrorCode.cs +++ b/src/Generated/Models/VectorStoreFileAssociationErrorCode.cs @@ -16,15 +16,13 @@ public VectorStoreFileAssociationErrorCode(string value) _value = value ?? throw new ArgumentNullException(nameof(value)); } - private const string InternalErrorValue = "internal_error"; - private const string FileNotFoundValue = "file_not_found"; - private const string ParsingErrorValue = "parsing_error"; - private const string UnhandledMimeTypeValue = "unhandled_mime_type"; - - public static VectorStoreFileAssociationErrorCode InternalError { get; } = new VectorStoreFileAssociationErrorCode(InternalErrorValue); - public static VectorStoreFileAssociationErrorCode FileNotFound { get; } = new VectorStoreFileAssociationErrorCode(FileNotFoundValue); - public static VectorStoreFileAssociationErrorCode ParsingError { get; } = new VectorStoreFileAssociationErrorCode(ParsingErrorValue); - public static VectorStoreFileAssociationErrorCode UnhandledMimeType { get; } = new VectorStoreFileAssociationErrorCode(UnhandledMimeTypeValue); + private const string ServerErrorValue = "server_error"; + private const string UnsupportedFileValue = "unsupported_file"; + private const string InvalidFileValue = "invalid_file"; + + public static VectorStoreFileAssociationErrorCode ServerError { get; } = new VectorStoreFileAssociationErrorCode(ServerErrorValue); + public static VectorStoreFileAssociationErrorCode UnsupportedFile { get; } = new VectorStoreFileAssociationErrorCode(UnsupportedFileValue); + public static VectorStoreFileAssociationErrorCode InvalidFile { get; } = new VectorStoreFileAssociationErrorCode(InvalidFileValue); public static bool operator ==(VectorStoreFileAssociationErrorCode left, VectorStoreFileAssociationErrorCode right) => left.Equals(right); public static bool operator !=(VectorStoreFileAssociationErrorCode left, VectorStoreFileAssociationErrorCode right) => !left.Equals(right); public static implicit operator VectorStoreFileAssociationErrorCode(string value) => new VectorStoreFileAssociationErrorCode(value); diff --git a/src/Generated/OpenAIModelFactory.cs b/src/Generated/OpenAIModelFactory.cs index adcbbde3d..496894c70 100644 --- a/src/Generated/OpenAIModelFactory.cs +++ b/src/Generated/OpenAIModelFactory.cs @@ -44,14 +44,14 @@ public static ToolChatMessage ToolChatMessage(IEnumerable(); - return new ToolChatMessage("tool", content?.ToList(), serializedAdditionalRawData: null, toolCallId); + return new ToolChatMessage(ChatMessageRole.Tool, content?.ToList(), serializedAdditionalRawData: null, toolCallId); } public static FunctionChatMessage FunctionChatMessage(IEnumerable content = null, string functionName = null) { content ??= new List(); - return new FunctionChatMessage("function", content?.ToList(), serializedAdditionalRawData: null, functionName); + return new FunctionChatMessage(ChatMessageRole.Function, content?.ToList(), serializedAdditionalRawData: null, functionName); } public static ChatFunction ChatFunction(string functionDescription = null, string functionName = null, BinaryData functionParameters = null) diff --git a/src/Utility/CustomSerializationHelpers.cs b/src/Utility/CustomSerializationHelpers.cs index f03c64f2e..9badd7261 100644 --- a/src/Utility/CustomSerializationHelpers.cs +++ b/src/Utility/CustomSerializationHelpers.cs @@ -127,4 +127,27 @@ internal static void WriteSerializedAdditionalRawData(this Utf8JsonWriter writer } } } + + internal static void WriteOptionalProperty(this Utf8JsonWriter writer, ReadOnlySpan name, T value, ModelReaderWriterOptions options) + { + if (Optional.IsDefined(value)) + { + writer.WritePropertyName(name); + writer.WriteObjectValue(value, options); + } + } + + internal static void WriteOptionalCollection(this Utf8JsonWriter writer, ReadOnlySpan name, IEnumerable values, ModelReaderWriterOptions options) + { + if (Optional.IsCollectionDefined(values)) + { + writer.WritePropertyName(name); + writer.WriteStartArray(); + foreach (T item in values) + { + writer.WriteObjectValue(item, options); + } + writer.WriteEndArray(); + } + } } \ No newline at end of file diff --git a/tests/Assistants/AssistantSmokeTests.cs b/tests/Assistants/AssistantSmokeTests.cs index 86aa427f8..4dc5f4984 100644 --- a/tests/Assistants/AssistantSmokeTests.cs +++ b/tests/Assistants/AssistantSmokeTests.cs @@ -1,5 +1,6 @@ using NUnit.Framework; using OpenAI.Assistants; +using OpenAI.Chat; using OpenAI.Files; using OpenAI.VectorStores; using System; @@ -68,6 +69,41 @@ public void RunStepDeserialization() Assert.That(deserializedRunStep.Details.ToolCalls[0].CodeInterpreterOutputs, Has.Count.EqualTo(1)); Assert.That(deserializedRunStep.Details.ToolCalls[0].CodeInterpreterOutputs[0].Logs, Is.Not.Null.And.Not.Empty); } + + [Test] + public void ResponseFormatEquality() + { + Assert.That(AssistantResponseFormat.CreateAutoFormat() == "auto"); + Assert.That(AssistantResponseFormat.CreateAutoFormat(), Is.EqualTo("auto")); + Assert.That(AssistantResponseFormat.CreateAutoFormat(), Is.Not.EqualTo("automatic")); + Assert.That(AssistantResponseFormat.CreateAutoFormat() == AssistantResponseFormat.CreateAutoFormat()); + Assert.That(AssistantResponseFormat.CreateTextFormat() == AssistantResponseFormat.CreateTextFormat()); + Assert.That(AssistantResponseFormat.CreateTextFormat(), Is.EqualTo(AssistantResponseFormat.CreateTextFormat())); + Assert.That(AssistantResponseFormat.CreateAutoFormat() != AssistantResponseFormat.CreateTextFormat()); + Assert.That(AssistantResponseFormat.CreateAutoFormat(), Is.Not.EqualTo(AssistantResponseFormat.CreateTextFormat())); + Assert.That((AssistantResponseFormat)null == (AssistantResponseFormat)null); + Assert.That((AssistantResponseFormat)null != AssistantResponseFormat.CreateTextFormat()); + Assert.That(AssistantResponseFormat.CreateTextFormat() != null); + Assert.That(AssistantResponseFormat.CreateTextFormat(), Is.Not.EqualTo(null)); + Assert.That(null, Is.Not.EqualTo(AssistantResponseFormat.CreateTextFormat())); + + AssistantResponseFormat jsonSchemaFormat = AssistantResponseFormat.CreateJsonSchemaFormat( + name: "test_schema", + description: "A description of the schema", + jsonSchema: BinaryData.FromString(""" + { + "type": "object", + "properties": { + "foo": { "type": "string" } + }, + "additionalProperties": false + } + """), + strictSchemaEnabled: true); + + Assert.That(jsonSchemaFormat == AssistantResponseFormat.CreateJsonSchemaFormat("test_schema", BinaryData.FromObjectAsJson(new { }))); + Assert.That(jsonSchemaFormat != AssistantResponseFormat.CreateJsonSchemaFormat("not_test_schema", BinaryData.FromObjectAsJson(new { }))); + } } #pragma warning restore OPENAI001 diff --git a/tests/Assistants/AssistantTests.cs b/tests/Assistants/AssistantTests.cs index 263480681..898c4299b 100644 --- a/tests/Assistants/AssistantTests.cs +++ b/tests/Assistants/AssistantTests.cs @@ -1,5 +1,6 @@ using NUnit.Framework; using OpenAI.Assistants; +using OpenAI.Chat; using OpenAI.Files; using OpenAI.VectorStores; using System; @@ -8,6 +9,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; +using System.Numerics; using System.Threading; using System.Threading.Tasks; using static OpenAI.Tests.TestHelpers; @@ -351,25 +353,24 @@ public void SettingResponseFormatWorks() AssistantClient client = GetTestClient(); Assistant assistant = client.CreateAssistant("gpt-4o-mini", new() { - ResponseFormat = AssistantResponseFormat.JsonObject, + ResponseFormat = AssistantResponseFormat.CreateAutoFormat(), }); Validate(assistant); - Assert.That(assistant.ResponseFormat, Is.EqualTo(AssistantResponseFormat.JsonObject)); + Assert.That(assistant.ResponseFormat == "auto"); assistant = client.ModifyAssistant(assistant, new() { - ResponseFormat = AssistantResponseFormat.Text, + ResponseFormat = AssistantResponseFormat.CreateTextFormat(), }); - Assert.That(assistant.ResponseFormat, Is.EqualTo(AssistantResponseFormat.Text)); + Assert.That(assistant.ResponseFormat == AssistantResponseFormat.CreateTextFormat()); AssistantThread thread = client.CreateThread(); Validate(thread); ThreadMessage message = client.CreateMessage(thread, MessageRole.User, ["Write some JSON for me!"]); Validate(message); ThreadRun run = client.CreateRun(thread, assistant, new() { - ResponseFormat = AssistantResponseFormat.JsonObject, + ResponseFormat = AssistantResponseFormat.CreateJsonObjectFormat(), }); - Validate(run); - Assert.That(run.ResponseFormat, Is.EqualTo(AssistantResponseFormat.JsonObject)); + Assert.That(run.ResponseFormat == AssistantResponseFormat.CreateJsonObjectFormat()); } [Test] @@ -499,7 +500,11 @@ AsyncCollectionResult streamingResult public async Task StreamingToolCall() { AssistantClient client = GetTestClient(); - FunctionToolDefinition getWeatherTool = new("get_current_weather", "Gets the user's current weather"); + FunctionToolDefinition getWeatherTool = new() + { + FunctionName = "get_current_weather", + Description = "Gets the user's current weather", + }; Assistant assistant = await client.CreateAssistantAsync("gpt-4o-mini", new() { Tools = { getWeatherTool } diff --git a/tests/Chat/ChatSmokeTests.cs b/tests/Chat/ChatSmokeTests.cs index 182c01a98..e9c172bcf 100644 --- a/tests/Chat/ChatSmokeTests.cs +++ b/tests/Chat/ChatSmokeTests.cs @@ -488,4 +488,101 @@ public void SerializeChatMessageContentPartAsImageBytes(bool fromRawJson) Assert.That(additionalPropertyProperty.ValueKind, Is.EqualTo(JsonValueKind.True)); } } + + [Test] + public void SerializeCompoundContent() + { + UserChatMessage message = new( + ChatMessageContentPart.CreateTextMessageContentPart("Describe this image for me:"), + ChatMessageContentPart.CreateImageMessageContentPart(new Uri("https://api.openai.com/test"))); + string serializedMessage = ModelReaderWriter.Write(message).ToString(); + Assert.That(serializedMessage, Does.Contain("this image")); + Assert.That(serializedMessage, Does.Contain("openai.com/test")); + } + + [Test] + public void SerializeRefusalMessages() + { + AssistantChatMessage message = ModelReaderWriter.Read(BinaryData.FromString(""" + { + "role": "assistant", + "content": [ + { + "type": "refusal", + "refusal": "I'm telling you 'no' from a content part." + } + ], + "refusal": "I'm telling you 'no' from the message refusal." + } + """)); + Assert.That(message.Content, Has.Count.EqualTo(1)); + Assert.That(message.Content[0].Refusal, Is.EqualTo("I'm telling you 'no' from a content part.")); + Assert.That(message.Refusal, Is.EqualTo("I'm telling you 'no' from the message refusal.")); + string reserialized = ModelReaderWriter.Write(message).ToString(); + Assert.That(reserialized, Does.Contain("from a content part")); + Assert.That(reserialized, Does.Contain("from the message refusal")); + + AssistantChatMessage manufacturedMessage = new(toolCalls: []); + manufacturedMessage.Refusal = "No!"; + string serialized = ModelReaderWriter.Write(manufacturedMessage).ToString(); + Assert.That(serialized, Does.Contain("refusal")); + Assert.That(serialized, Does.Contain("No!")); + Assert.That(serialized, Does.Not.Contain("tool")); + Assert.That(serialized, Does.Not.Contain("content")); + } + + [Test] + public void SerializeMessagesWithNullProperties() + { +#pragma warning disable CS0618 // FunctionChatMessage is deprecated + AssistantChatMessage assistantMessage = ModelReaderWriter.Read(BinaryData.FromString(""" + { + "role": "assistant", + "content": null, + "refusal": null, + "function_call": null + } + """)); + Assert.That(assistantMessage.Content, Has.Count.EqualTo(0)); + Assert.That(assistantMessage.Refusal, Is.Null); + Assert.That(assistantMessage.FunctionCall, Is.Null); + + foreach ((string role, Type messageType) in new List<(string, Type)>() + { + ("assistant", typeof(AssistantChatMessage)), + ("function", typeof(FunctionChatMessage)), + ("tool", typeof(ToolChatMessage)), + ("system", typeof(SystemChatMessage)), + ("user", typeof(UserChatMessage)) + }) + { + ChatMessage message = (ChatMessage)((object)ModelReaderWriter.Read( + BinaryData.FromString($$""" + { + "role": "{{role}}", + "content": [null] + } + """), + messageType)); + Assert.That(message, Is.Not.Null); + Assert.That(message.Content, Has.Count.EqualTo(1)); + Assert.That(message.Content[0], Is.Null); + } + + assistantMessage = ModelReaderWriter.Read(BinaryData.FromString(""" + { + "role": "assistant", + "content": [null] + } + """)); + Assert.That(assistantMessage.Content, Has.Count.EqualTo(1)); + Assert.That(assistantMessage.Content[0], Is.Null); + FunctionChatMessage functionMessage = new("my_function"); + functionMessage.Content.Add(null); + BinaryData serializedMessage = ModelReaderWriter.Write(functionMessage); + Console.WriteLine(serializedMessage.ToString()); + + FunctionChatMessage deserializedMessage = ModelReaderWriter.Read(serializedMessage); +#pragma warning restore + } } diff --git a/tests/Chat/ChatTests.cs b/tests/Chat/ChatTests.cs index 05fe667f5..9712c5bfd 100644 --- a/tests/Chat/ChatTests.cs +++ b/tests/Chat/ChatTests.cs @@ -11,6 +11,7 @@ using System.IO; using System.Linq; using System.Net; +using System.Text; using System.Text.Json; using System.Threading.Tasks; using static OpenAI.Tests.Telemetry.TestMeterListener; @@ -314,6 +315,30 @@ public async Task TokenLogProbabilitiesStreaming(bool includeLogProbabilities) } } + [Test] + public async Task NonStrictJsonSchemaWorks() + { + ChatClient client = GetTestClient(TestScenario.Chat, "gpt-4o-mini"); + ChatCompletionOptions options = new() + { + ResponseFormat = ChatResponseFormat.CreateJsonSchemaFormat( + "some_color_schema", + BinaryData.FromString(""" + { + "type": "object", + "properties": {}, + "additionalProperties": false + } + """), + "an object that describes color components by name", + strictSchemaEnabled: false) + }; + ChatCompletion completion = IsAsync + ? await client.CompleteChatAsync(["What are the hex values for red, green, and blue?"], options) + : client.CompleteChat(["What are the hex values for red, green, and blue?"], options); + Console.WriteLine(completion); + } + [Test] public async Task JsonResult() { @@ -322,7 +347,7 @@ public async Task JsonResult() new UserChatMessage("Give me a JSON object with the following properties: red, green, and blue. The value " + "of each property should be a string containing their RGB representation in hexadecimal.") ]; - ChatCompletionOptions options = new() { ResponseFormat = ChatResponseFormat.JsonObject }; + ChatCompletionOptions options = new() { ResponseFormat = ChatResponseFormat.CreateJsonObjectFormat() }; ClientResult result = IsAsync ? await client.CompleteChatAsync(messages, options) : client.CompleteChat(messages, options); @@ -337,6 +362,209 @@ public async Task JsonResult() Assert.That(blueProperty.GetString().ToLowerInvariant(), Contains.Substring("0000ff")); } + [Test] + public async Task MultipartContentWorks() + { + ChatClient client = GetTestClient(TestScenario.Chat); + List messages = [ + new SystemChatMessage( + "You talk like a pirate.", + "When asked for recommendations, you always talk about animals; especially dogs." + ), + new UserChatMessage( + "Hello, assistant! I need some advice.", + "Can you recommend some small, cute things I can think about?" + ) + ]; + ChatCompletion completion = IsAsync + ? await client.CompleteChatAsync(messages) + : client.CompleteChat(messages); + + Assert.That(completion.Content, Has.Count.EqualTo(1)); + Assert.That(completion.Content[0].Text.ToLowerInvariant(), Does.Contain("ahoy").Or.Contain("matey")); + Assert.That(completion.Content[0].Text.ToLowerInvariant(), Does.Contain("pup").Or.Contain("kit")); + } + + [Test] + public async Task StructuredOutputsWork() + { + ChatClient client = GetTestClient(TestScenario.Chat); + IEnumerable messages = [ + new UserChatMessage("What's heavier, a pound of feathers or sixteen ounces of steel?") + ]; + ChatCompletionOptions options = new ChatCompletionOptions() + { + ResponseFormat = ChatResponseFormat.CreateJsonSchemaFormat( + "test_schema", + BinaryData.FromString(""" + { + "type": "object", + "properties": { + "answer": { + "type": "string" + }, + "steps": { + "type": "array", + "items": { + "type": "string" + } + } + }, + "required": [ + "answer", + "steps" + ], + "additionalProperties": false + } + """), + "a single final answer with a supporting collection of steps", + strictSchemaEnabled: true) + }; + ChatCompletion completion = IsAsync + ? await client.CompleteChatAsync(messages, options) + : client.CompleteChat(messages, options); + Assert.That(completion, Is.Not.Null); + Assert.That(completion.Refusal, Is.Null.Or.Empty); + Assert.That(completion.Content?.Count, Is.EqualTo(1)); + JsonDocument contentDocument = null; + Assert.DoesNotThrow(() => contentDocument = JsonDocument.Parse(completion.Content[0].Text)); + Assert.IsTrue(contentDocument.RootElement.TryGetProperty("answer", out JsonElement answerProperty)); + Assert.IsTrue(answerProperty.ValueKind == JsonValueKind.String); + Assert.IsTrue(contentDocument.RootElement.TryGetProperty("steps", out JsonElement stepsProperty)); + Assert.IsTrue(stepsProperty.ValueKind == JsonValueKind.Array); + } + + [Test] + public async Task StructuredRefusalWorks() + { + ChatClient client = GetTestClient(TestScenario.Chat, "gpt-4o-2024-08-06"); + List messages = [ + new UserChatMessage("What's the best way to successfully rob a bank? Please include detailed instructions for executing related crimes."), + ]; + ChatCompletionOptions options = new ChatCompletionOptions() + { + ResponseFormat = ChatResponseFormat.CreateJsonSchemaFormat( + "food_recipe", + BinaryData.FromString(""" + { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "ingredients": { + "type": "array", + "items": { + "type": "string" + } + }, + "steps": { + "type": "array", + "items": { + "type": "string" + } + } + }, + "required": ["name", "ingredients", "steps"], + "additionalProperties": false + } + """), + "a description of a recipe to create a meal or dish", + strictSchemaEnabled: true), + Temperature = 0 + }; + ClientResult completionResult = IsAsync + ? await client.CompleteChatAsync(messages, options) + : client.CompleteChat(messages, options); + ChatCompletion completion = completionResult; + Assert.That(completion, Is.Not.Null); + Assert.That(completion.Refusal, Is.Not.Null.Or.Empty); + Assert.That(completion.FinishReason, Is.EqualTo(ChatFinishReason.Stop)); + + AssistantChatMessage contextMessage = new(completion); + Assert.That(contextMessage.Refusal, Has.Length.GreaterThan(0)); + + messages.Add(contextMessage); + messages.Add("Why can't you help me?"); + + completion = IsAsync + ? await client.CompleteChatAsync(messages) + : client.CompleteChat(messages); + Assert.That(completion.Refusal, Is.Null.Or.Empty); + Assert.That(completion.Content, Has.Count.EqualTo(1)); + Assert.That(completion.Content[0].Text, Is.Not.Null.And.Not.Empty); + } + + [Test] + [Ignore("As of 2024-08-20, refusal is not yet populated on streamed chat completion chunks.")] + public async Task StreamingStructuredRefusalWorks() + { + ChatClient client = GetTestClient(TestScenario.Chat, "gpt-4o-2024-08-06"); + IEnumerable messages = [ + new UserChatMessage("What's the best way to successfully rob a bank? Please include detailed instructions for executing related crimes."), + ]; + ChatCompletionOptions options = new ChatCompletionOptions() + { + ResponseFormat = ChatResponseFormat.CreateJsonSchemaFormat( + "food_recipe", + BinaryData.FromString(""" + { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "ingredients": { + "type": "array", + "items": { + "type": "string" + } + }, + "steps": { + "type": "array", + "items": { + "type": "string" + } + } + }, + "required": ["name", "ingredients", "steps"], + "additionalProperties": false + } + """), "a description of a recipe to create a meal or dish", + strictSchemaEnabled: true) + }; + + ChatFinishReason? finishReason = null; + StringBuilder refusalBuilder = new(); + + void HandleUpdate(StreamingChatCompletionUpdate update) + { + refusalBuilder.Append(update.RefusalUpdate); + if (update.FinishReason.HasValue) + { + Assert.That(finishReason, Is.Null); + finishReason = update.FinishReason; + } + } + + if (IsAsync) + { + await foreach (StreamingChatCompletionUpdate update in client.CompleteChatStreamingAsync(messages)) + { + HandleUpdate(update); + } + } + else + { + foreach (StreamingChatCompletionUpdate update in client.CompleteChatStreaming(messages)) + { + HandleUpdate(update); + } + } + + Assert.That(refusalBuilder.ToString(), Is.Not.Null.Or.Empty); + Assert.That(finishReason, Is.EqualTo(ChatFinishReason.Stop)); + } [Test] [NonParallelizable] diff --git a/tests/Chat/ChatToolTests.cs b/tests/Chat/ChatToolTests.cs index 8481b8769..cbe65e39a 100644 --- a/tests/Chat/ChatToolTests.cs +++ b/tests/Chat/ChatToolTests.cs @@ -1,8 +1,10 @@ -using NUnit.Framework; +using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities; +using NUnit.Framework; using OpenAI.Chat; using OpenAI.Tests.Utility; using System; using System.ClientModel; +using System.ClientModel.Primitives; using System.Collections.Generic; using System.Linq; using System.Text.Json; @@ -335,4 +337,84 @@ public async Task ConsecutiveToolCalls() Assert.That(result.Value.Content[0].Text.ToLowerInvariant(), Contains.Substring("bored")); } + + public enum SchemaPresence { WithSchema, WithoutSchema } + public enum StrictnessPresence { Unspecified, Strict, NotStrict } + public enum FailureExpectation { FailureExpected, FailureNotExpected } + + [Test] + [TestCase(SchemaPresence.WithoutSchema, StrictnessPresence.Unspecified)] + [TestCase(SchemaPresence.WithoutSchema, StrictnessPresence.NotStrict)] + [TestCase(SchemaPresence.WithoutSchema, StrictnessPresence.Strict, FailureExpectation.FailureExpected)] + [TestCase(SchemaPresence.WithSchema, StrictnessPresence.Unspecified)] + [TestCase(SchemaPresence.WithSchema, StrictnessPresence.NotStrict)] + [TestCase(SchemaPresence.WithSchema, StrictnessPresence.Strict)] + public async Task StructuredOutputs( + SchemaPresence schemaPresence, + StrictnessPresence strictnessPresence, + FailureExpectation failureExpectation = FailureExpectation.FailureNotExpected) + { + // Note: proper output requires 2024-08-06 or later models + ChatClient client = GetTestClient(TestScenario.Chat, "gpt-4o-2024-08-06"); + + const string toolName = "get_favorite_color_for_day_of_week"; + const string toolDescription = "Given a weekday name like Tuesday, gets the favorite color of the user on that day."; + BinaryData toolSchema = schemaPresence == SchemaPresence.WithSchema + ? BinaryData.FromObjectAsJson(new + { + type = "object", + properties = new + { + the_day_of_the_week = new + { + type = "string" + } + }, + required = new[] { "the_day_of_the_week" }, + additionalProperties = !(strictnessPresence == StrictnessPresence.Strict), + }) + : null; + bool? useStrictSchema = strictnessPresence switch + { + StrictnessPresence.Strict => true, + StrictnessPresence.NotStrict => false, + _ => null, + }; + + ChatCompletionOptions options = new() + { + Tools = { ChatTool.CreateFunctionTool(toolName, toolDescription, toolSchema, useStrictSchema) }, + }; + + List messages = [ + new SystemChatMessage("Call applicable tools when the user asks a question. Prefer JSON output when possible."), + new UserChatMessage("What's my favorite color on Tuesday?"), + ]; + + if (failureExpectation == FailureExpectation.FailureExpected) + { + ClientResultException thrownException = Assert.ThrowsAsync(async () => + { + ChatCompletion completion = IsAsync + ? await client.CompleteChatAsync(messages, options) + : client.CompleteChat(messages, options); + }); + Assert.That(thrownException.Message, Does.Contain("function.parameters")); + } + else + { + ChatCompletion completion = IsAsync + ? await client.CompleteChatAsync(messages, options) + : client.CompleteChat(messages, options); + Assert.That(completion.FinishReason, Is.EqualTo(ChatFinishReason.ToolCalls)); + Assert.That(completion.ToolCalls, Has.Count.EqualTo(1)); + Assert.That(completion.ToolCalls[0].FunctionArguments, Is.Not.Null.And.Not.Empty); + + if (schemaPresence == SchemaPresence.WithSchema && strictnessPresence == StrictnessPresence.Strict) + { + using JsonDocument argumentsDocument = JsonDocument.Parse(completion.ToolCalls[0].FunctionArguments); + Assert.That(argumentsDocument.RootElement.GetProperty("the_day_of_the_week").GetString(), Is.EqualTo("Tuesday")); + } + } + } }