diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ApiResponseFormat.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ApiResponseFormat.cs new file mode 100644 index 000000000000..a9d6dc151976 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ApiResponseFormat.cs @@ -0,0 +1,54 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Possible API response formats. + internal readonly partial struct ApiResponseFormat : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public ApiResponseFormat(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string TextValue = "text"; + private const string JsonObjectValue = "json_object"; + private const string JsonSchemaValue = "json_schema"; + + /// `text` format should be used for requests involving any sort of ToolCall. + public static ApiResponseFormat Text { get; } = new ApiResponseFormat(TextValue); + /// Using `json_object` format will limit the usage of ToolCall to only functions. + public static ApiResponseFormat JsonObject { get; } = new ApiResponseFormat(JsonObjectValue); + /// Using `json_schema` format will ensure the model matches the supplied JSON schema. + public static ApiResponseFormat JsonSchema { get; } = new ApiResponseFormat(JsonSchemaValue); + /// Determines if two values are the same. + public static bool operator ==(ApiResponseFormat left, ApiResponseFormat right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(ApiResponseFormat left, ApiResponseFormat right) => !left.Equals(right); + /// Converts a to a . + public static implicit operator ApiResponseFormat(string value) => new ApiResponseFormat(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is ApiResponseFormat other && Equals(other); + /// + public bool Equals(ApiResponseFormat 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/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/Assistant.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/Assistant.Serialization.cs index 54d84a05db04..590f2636f4bb 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/Assistant.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/Assistant.Serialization.cs @@ -76,13 +76,52 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit writer.WriteObjectValue(item, options); } writer.WriteEndArray(); - writer.WritePropertyName("file_ids"u8); - writer.WriteStartArray(); - foreach (var item in FileIds) + if (ToolResources != null) { - writer.WriteStringValue(item); + writer.WritePropertyName("tool_resources"u8); + writer.WriteObjectValue(ToolResources, options); + } + else + { + writer.WriteNull("tool_resources"); + } + if (Temperature != null) + { + writer.WritePropertyName("temperature"u8); + writer.WriteNumberValue(Temperature.Value); + } + else + { + writer.WriteNull("temperature"); + } + if (TopP != null) + { + writer.WritePropertyName("top_p"u8); + writer.WriteNumberValue(TopP.Value); + } + else + { + writer.WriteNull("top_p"); + } + if (Optional.IsDefined(ResponseFormat)) + { + if (ResponseFormat != null) + { + writer.WritePropertyName("response_format"u8); +#if NET6_0_OR_GREATER + writer.WriteRawValue(ResponseFormat); +#else + using (JsonDocument document = JsonDocument.Parse(ResponseFormat, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + else + { + writer.WriteNull("response_format"); + } } - writer.WriteEndArray(); if (Metadata != null && Optional.IsCollectionDefined(Metadata)) { writer.WritePropertyName("metadata"u8); @@ -143,7 +182,10 @@ internal static Assistant DeserializeAssistant(JsonElement element, ModelReaderW string model = default; string instructions = default; IReadOnlyList tools = default; - IReadOnlyList fileIds = default; + ToolResources toolResources = default; + float? temperature = default; + float? topP = default; + BinaryData responseFormat = default; IReadOnlyDictionary metadata = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); @@ -209,14 +251,44 @@ internal static Assistant DeserializeAssistant(JsonElement element, ModelReaderW tools = array; continue; } - if (property.NameEquals("file_ids"u8)) + if (property.NameEquals("tool_resources"u8)) { - List array = new List(); - foreach (var item in property.Value.EnumerateArray()) + if (property.Value.ValueKind == JsonValueKind.Null) { - array.Add(item.GetString()); + toolResources = null; + continue; + } + toolResources = ToolResources.DeserializeToolResources(property.Value, options); + continue; + } + if (property.NameEquals("temperature"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + temperature = null; + continue; + } + temperature = property.Value.GetSingle(); + continue; + } + if (property.NameEquals("top_p"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + topP = null; + continue; + } + topP = property.Value.GetSingle(); + continue; + } + if (property.NameEquals("response_format"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + responseFormat = null; + continue; } - fileIds = array; + responseFormat = BinaryData.FromString(property.Value.GetRawText()); continue; } if (property.NameEquals("metadata"u8)) @@ -249,7 +321,10 @@ internal static Assistant DeserializeAssistant(JsonElement element, ModelReaderW model, instructions, tools, - fileIds, + toolResources, + temperature, + topP, + responseFormat, metadata, serializedAdditionalRawData); } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/Assistant.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/Assistant.cs index 34402e5480d9..09b938b95c0e 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/Assistant.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/Assistant.cs @@ -56,17 +56,29 @@ public partial class Assistant /// /// The collection of tools enabled for the assistant. /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. - /// The available derived classes include , and . + /// The available derived classes include , and . + /// + /// + /// A set of resources that are used by the assistant's tools. The resources are specific to the type of tool. For example, the `code_interpreter` + /// tool requires a list of file IDs, while the `file_search` tool requires a list of vector store IDs. + /// + /// + /// What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, + /// while lower values like 0.2 will make it more focused and deterministic. + /// + /// + /// An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. + /// So 0.1 means only the tokens comprising the top 10% probability mass are considered. + /// + /// We generally recommend altering this or temperature but not both. /// - /// A list of attached file IDs, ordered by creation date in ascending order. /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. - /// , , or is null. - internal Assistant(string id, DateTimeOffset createdAt, string name, string description, string model, string instructions, IEnumerable tools, IEnumerable fileIds, IReadOnlyDictionary metadata) + /// , or is null. + internal Assistant(string id, DateTimeOffset createdAt, string name, string description, string model, string instructions, IEnumerable tools, ToolResources toolResources, float? temperature, float? topP, IReadOnlyDictionary metadata) { Argument.AssertNotNull(id, nameof(id)); Argument.AssertNotNull(model, nameof(model)); Argument.AssertNotNull(tools, nameof(tools)); - Argument.AssertNotNull(fileIds, nameof(fileIds)); Id = id; CreatedAt = createdAt; @@ -75,7 +87,9 @@ internal Assistant(string id, DateTimeOffset createdAt, string name, string desc Model = model; Instructions = instructions; Tools = tools.ToList(); - FileIds = fileIds.ToList(); + ToolResources = toolResources; + Temperature = temperature; + TopP = topP; Metadata = metadata; } @@ -90,12 +104,26 @@ internal Assistant(string id, DateTimeOffset createdAt, string name, string desc /// /// The collection of tools enabled for the assistant. /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. - /// The available derived classes include , and . + /// The available derived classes include , and . + /// + /// + /// A set of resources that are used by the assistant's tools. The resources are specific to the type of tool. For example, the `code_interpreter` + /// tool requires a list of file IDs, while the `file_search` tool requires a list of vector store IDs. + /// + /// + /// What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, + /// while lower values like 0.2 will make it more focused and deterministic. + /// + /// + /// An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. + /// So 0.1 means only the tokens comprising the top 10% probability mass are considered. + /// + /// We generally recommend altering this or temperature but not both. /// - /// A list of attached file IDs, ordered by creation date in ascending order. + /// The response format of the tool calls used by this assistant. /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. /// Keeps track of any properties unknown to the library. - internal Assistant(string id, string @object, DateTimeOffset createdAt, string name, string description, string model, string instructions, IReadOnlyList tools, IReadOnlyList fileIds, IReadOnlyDictionary metadata, IDictionary serializedAdditionalRawData) + internal Assistant(string id, string @object, DateTimeOffset createdAt, string name, string description, string model, string instructions, IReadOnlyList tools, ToolResources toolResources, float? temperature, float? topP, BinaryData responseFormat, IReadOnlyDictionary metadata, IDictionary serializedAdditionalRawData) { Id = id; Object = @object; @@ -105,7 +133,10 @@ internal Assistant(string id, string @object, DateTimeOffset createdAt, string n Model = model; Instructions = instructions; Tools = tools; - FileIds = fileIds; + ToolResources = toolResources; + Temperature = temperature; + TopP = topP; + ResponseFormat = responseFormat; Metadata = metadata; _serializedAdditionalRawData = serializedAdditionalRawData; } @@ -131,11 +162,71 @@ internal Assistant() /// /// The collection of tools enabled for the assistant. /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. - /// The available derived classes include , and . + /// The available derived classes include , and . /// public IReadOnlyList Tools { get; } - /// A list of attached file IDs, ordered by creation date in ascending order. - public IReadOnlyList FileIds { get; } + /// + /// A set of resources that are used by the assistant's tools. The resources are specific to the type of tool. For example, the `code_interpreter` + /// tool requires a list of file IDs, while the `file_search` tool requires a list of vector store IDs. + /// + public ToolResources ToolResources { get; } + /// + /// What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, + /// while lower values like 0.2 will make it more focused and deterministic. + /// + public float? Temperature { get; } + /// + /// An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. + /// So 0.1 means only the tokens comprising the top 10% probability mass are considered. + /// + /// We generally recommend altering this or temperature but not both. + /// + public float? TopP { get; } + /// + /// The response format of the tool calls used by this assistant. + /// + /// To assign an object to this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// + /// Supported types: + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + public BinaryData ResponseFormat { get; } /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. public IReadOnlyDictionary Metadata { get; } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantCreationOptions.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantCreationOptions.Serialization.cs index d0f8a38f8d29..3e54e193e53e 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantCreationOptions.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantCreationOptions.Serialization.cs @@ -82,15 +82,60 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit } writer.WriteEndArray(); } - if (Optional.IsCollectionDefined(FileIds)) + if (Optional.IsDefined(ToolResources)) { - writer.WritePropertyName("file_ids"u8); - writer.WriteStartArray(); - foreach (var item in FileIds) + if (ToolResources != null) { - writer.WriteStringValue(item); + writer.WritePropertyName("tool_resources"u8); + writer.WriteObjectValue(ToolResources, options); + } + else + { + writer.WriteNull("tool_resources"); + } + } + if (Optional.IsDefined(Temperature)) + { + if (Temperature != null) + { + writer.WritePropertyName("temperature"u8); + writer.WriteNumberValue(Temperature.Value); + } + else + { + writer.WriteNull("temperature"); + } + } + if (Optional.IsDefined(TopP)) + { + if (TopP != null) + { + writer.WritePropertyName("top_p"u8); + writer.WriteNumberValue(TopP.Value); + } + else + { + writer.WriteNull("top_p"); + } + } + if (Optional.IsDefined(ResponseFormat)) + { + if (ResponseFormat != null) + { + writer.WritePropertyName("response_format"u8); +#if NET6_0_OR_GREATER + writer.WriteRawValue(ResponseFormat); +#else + using (JsonDocument document = JsonDocument.Parse(ResponseFormat, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + else + { + writer.WriteNull("response_format"); } - writer.WriteEndArray(); } if (Optional.IsCollectionDefined(Metadata)) { @@ -152,7 +197,10 @@ internal static AssistantCreationOptions DeserializeAssistantCreationOptions(Jso string description = default; string instructions = default; IList tools = default; - IList fileIds = default; + CreateToolResourcesOptions toolResources = default; + float? temperature = default; + float? topP = default; + BinaryData responseFormat = default; IDictionary metadata = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); @@ -207,18 +255,44 @@ internal static AssistantCreationOptions DeserializeAssistantCreationOptions(Jso tools = array; continue; } - if (property.NameEquals("file_ids"u8)) + if (property.NameEquals("tool_resources"u8)) { if (property.Value.ValueKind == JsonValueKind.Null) { + toolResources = null; continue; } - List array = new List(); - foreach (var item in property.Value.EnumerateArray()) + toolResources = CreateToolResourcesOptions.DeserializeCreateToolResourcesOptions(property.Value, options); + continue; + } + if (property.NameEquals("temperature"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + temperature = null; + continue; + } + temperature = property.Value.GetSingle(); + continue; + } + if (property.NameEquals("top_p"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) { - array.Add(item.GetString()); + topP = null; + continue; + } + topP = property.Value.GetSingle(); + continue; + } + if (property.NameEquals("response_format"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + responseFormat = null; + continue; } - fileIds = array; + responseFormat = BinaryData.FromString(property.Value.GetRawText()); continue; } if (property.NameEquals("metadata"u8)) @@ -247,7 +321,10 @@ internal static AssistantCreationOptions DeserializeAssistantCreationOptions(Jso description, instructions, tools ?? new ChangeTrackingList(), - fileIds ?? new ChangeTrackingList(), + toolResources, + temperature, + topP, + responseFormat, metadata ?? new ChangeTrackingDictionary(), serializedAdditionalRawData); } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantCreationOptions.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantCreationOptions.cs index 34372f563399..87275c6b0976 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantCreationOptions.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantCreationOptions.cs @@ -54,7 +54,6 @@ public AssistantCreationOptions(string model) Model = model; Tools = new ChangeTrackingList(); - FileIds = new ChangeTrackingList(); Metadata = new ChangeTrackingDictionary(); } @@ -66,19 +65,36 @@ public AssistantCreationOptions(string model) /// /// The collection of tools to enable for the new assistant. /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. - /// The available derived classes include , and . + /// The available derived classes include , and . /// - /// A list of previously uploaded file IDs to attach to the assistant. + /// + /// A set of resources that are used by the assistant's tools. The resources are specific to the type of tool. For example, the `code_interpreter` + /// tool requires a list of file IDs, while the `file_search` tool requires a list of vector store IDs. + /// + /// + /// What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, + /// while lower values like 0.2 will make it more focused and deterministic. + /// + /// + /// An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. + /// So 0.1 means only the tokens comprising the top 10% probability mass are considered. + /// + /// We generally recommend altering this or temperature but not both. + /// + /// The response format of the tool calls used by this assistant. /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. /// Keeps track of any properties unknown to the library. - internal AssistantCreationOptions(string model, string name, string description, string instructions, IList tools, IList fileIds, IDictionary metadata, IDictionary serializedAdditionalRawData) + internal AssistantCreationOptions(string model, string name, string description, string instructions, IList tools, CreateToolResourcesOptions toolResources, float? temperature, float? topP, BinaryData responseFormat, IDictionary metadata, IDictionary serializedAdditionalRawData) { Model = model; Name = name; Description = description; Instructions = instructions; Tools = tools; - FileIds = fileIds; + ToolResources = toolResources; + Temperature = temperature; + TopP = topP; + ResponseFormat = responseFormat; Metadata = metadata; _serializedAdditionalRawData = serializedAdditionalRawData; } @@ -99,11 +115,71 @@ internal AssistantCreationOptions() /// /// The collection of tools to enable for the new assistant. /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. - /// The available derived classes include , and . + /// The available derived classes include , and . /// public IList Tools { get; } - /// A list of previously uploaded file IDs to attach to the assistant. - public IList FileIds { get; } + /// + /// A set of resources that are used by the assistant's tools. The resources are specific to the type of tool. For example, the `code_interpreter` + /// tool requires a list of file IDs, while the `file_search` tool requires a list of vector store IDs. + /// + public CreateToolResourcesOptions ToolResources { get; set; } + /// + /// What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, + /// while lower values like 0.2 will make it more focused and deterministic. + /// + public float? Temperature { get; set; } + /// + /// An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. + /// So 0.1 means only the tokens comprising the top 10% probability mass are considered. + /// + /// We generally recommend altering this or temperature but not both. + /// + public float? TopP { get; set; } + /// + /// The response format of the tool calls used by this assistant. + /// + /// To assign an object to this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// + /// Supported types: + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + public BinaryData ResponseFormat { get; set; } /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. public IDictionary Metadata { get; set; } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantStreamEvent.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantStreamEvent.cs new file mode 100644 index 000000000000..3c35b2590d78 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantStreamEvent.cs @@ -0,0 +1,134 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.OpenAI.Assistants +{ + /// + /// Each event in a server-sent events stream has an `event` and `data` property: + /// + /// ``` + /// event: thread.created + /// data: {"id": "thread_123", "object": "thread", ...} + /// ``` + /// + /// We emit events whenever a new object is created, transitions to a new state, or is being + /// streamed in parts (deltas). For example, we emit `thread.run.created` when a new run + /// is created, `thread.run.completed` when a run completes, and so on. When an Assistant chooses + /// to create a message during a run, we emit a `thread.message.created event`, a + /// `thread.message.in_progress` event, many `thread.message.delta` events, and finally a + /// `thread.message.completed` event. + /// + /// We may add additional events over time, so we recommend handling unknown events gracefully + /// in your code. + /// + public readonly partial struct AssistantStreamEvent : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public AssistantStreamEvent(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string ThreadCreatedValue = "thread.created"; + private const string ThreadRunCreatedValue = "thread.run.created"; + private const string ThreadRunQueuedValue = "thread.run.queued"; + private const string ThreadRunInProgressValue = "thread.run.in_progress"; + private const string ThreadRunRequiresActionValue = "thread.run.requires_action"; + private const string ThreadRunCompletedValue = "thread.run.completed"; + private const string ThreadRunFailedValue = "thread.run.failed"; + private const string ThreadRunCancellingValue = "thread.run.cancelling"; + private const string ThreadRunCancelledValue = "thread.run.cancelled"; + private const string ThreadRunExpiredValue = "thread.run.expired"; + private const string ThreadRunStepCreatedValue = "thread.run.step.created"; + private const string ThreadRunStepInProgressValue = "thread.run.step.in_progress"; + private const string ThreadRunStepDeltaValue = "thread.run.step.delta"; + private const string ThreadRunStepCompletedValue = "thread.run.step.completed"; + private const string ThreadRunStepFailedValue = "thread.run.step.failed"; + private const string ThreadRunStepCancelledValue = "thread.run.step.cancelled"; + private const string ThreadRunStepExpiredValue = "thread.run.step.expired"; + private const string ThreadMessageCreatedValue = "thread.message.created"; + private const string ThreadMessageInProgressValue = "thread.message.in_progress"; + private const string ThreadMessageDeltaValue = "thread.message.delta"; + private const string ThreadMessageCompletedValue = "thread.message.completed"; + private const string ThreadMessageIncompleteValue = "thread.message.incomplete"; + private const string ErrorValue = "error"; + private const string DoneValue = "done"; + + /// Event sent when a new thread is created. The data of this event is of type AssistantThread. + public static AssistantStreamEvent ThreadCreated { get; } = new AssistantStreamEvent(ThreadCreatedValue); + /// Event sent when a new run is created. The data of this event is of type ThreadRun. + public static AssistantStreamEvent ThreadRunCreated { get; } = new AssistantStreamEvent(ThreadRunCreatedValue); + /// Event sent when a run moves to `queued` status. The data of this event is of type ThreadRun. + public static AssistantStreamEvent ThreadRunQueued { get; } = new AssistantStreamEvent(ThreadRunQueuedValue); + /// Event sent when a run moves to `in_progress` status. The data of this event is of type ThreadRun. + public static AssistantStreamEvent ThreadRunInProgress { get; } = new AssistantStreamEvent(ThreadRunInProgressValue); + /// Event sent when a run moves to `requires_action` status. The data of this event is of type ThreadRun. + public static AssistantStreamEvent ThreadRunRequiresAction { get; } = new AssistantStreamEvent(ThreadRunRequiresActionValue); + /// Event sent when a run is completed. The data of this event is of type ThreadRun. + public static AssistantStreamEvent ThreadRunCompleted { get; } = new AssistantStreamEvent(ThreadRunCompletedValue); + /// Event sent when a run fails. The data of this event is of type ThreadRun. + public static AssistantStreamEvent ThreadRunFailed { get; } = new AssistantStreamEvent(ThreadRunFailedValue); + /// Event sent when a run moves to `cancelling` status. The data of this event is of type ThreadRun. + public static AssistantStreamEvent ThreadRunCancelling { get; } = new AssistantStreamEvent(ThreadRunCancellingValue); + /// Event sent when a run is cancelled. The data of this event is of type ThreadRun. + public static AssistantStreamEvent ThreadRunCancelled { get; } = new AssistantStreamEvent(ThreadRunCancelledValue); + /// Event sent when a run is expired. The data of this event is of type ThreadRun. + public static AssistantStreamEvent ThreadRunExpired { get; } = new AssistantStreamEvent(ThreadRunExpiredValue); + /// Event sent when a new thread run step is created. The data of this event is of type RunStep. + public static AssistantStreamEvent ThreadRunStepCreated { get; } = new AssistantStreamEvent(ThreadRunStepCreatedValue); + /// Event sent when a run step moves to `in_progress` status. The data of this event is of type RunStep. + public static AssistantStreamEvent ThreadRunStepInProgress { get; } = new AssistantStreamEvent(ThreadRunStepInProgressValue); + /// Event sent when a run stepis being streamed. The data of this event is of type RunStepDeltaChunk. + public static AssistantStreamEvent ThreadRunStepDelta { get; } = new AssistantStreamEvent(ThreadRunStepDeltaValue); + /// Event sent when a run step is completed. The data of this event is of type RunStep. + public static AssistantStreamEvent ThreadRunStepCompleted { get; } = new AssistantStreamEvent(ThreadRunStepCompletedValue); + /// Event sent when a run step fails. The data of this event is of type RunStep. + public static AssistantStreamEvent ThreadRunStepFailed { get; } = new AssistantStreamEvent(ThreadRunStepFailedValue); + /// Event sent when a run step is cancelled. The data of this event is of type RunStep. + public static AssistantStreamEvent ThreadRunStepCancelled { get; } = new AssistantStreamEvent(ThreadRunStepCancelledValue); + /// Event sent when a run step is expired. The data of this event is of type RunStep. + public static AssistantStreamEvent ThreadRunStepExpired { get; } = new AssistantStreamEvent(ThreadRunStepExpiredValue); + /// Event sent when a new message is created. The data of this event is of type ThreadMessage. + public static AssistantStreamEvent ThreadMessageCreated { get; } = new AssistantStreamEvent(ThreadMessageCreatedValue); + /// Event sent when a message moves to `in_progress` status. The data of this event is of type ThreadMessage. + public static AssistantStreamEvent ThreadMessageInProgress { get; } = new AssistantStreamEvent(ThreadMessageInProgressValue); + /// Event sent when a message is being streamed. The data of this event is of type MessageDeltaChunk. + public static AssistantStreamEvent ThreadMessageDelta { get; } = new AssistantStreamEvent(ThreadMessageDeltaValue); + /// Event sent when a message is completed. The data of this event is of type ThreadMessage. + public static AssistantStreamEvent ThreadMessageCompleted { get; } = new AssistantStreamEvent(ThreadMessageCompletedValue); + /// Event sent before a message is completed. The data of this event is of type ThreadMessage. + public static AssistantStreamEvent ThreadMessageIncomplete { get; } = new AssistantStreamEvent(ThreadMessageIncompleteValue); + /// Event sent when an error occurs, such as an internal server error or a timeout. + public static AssistantStreamEvent Error { get; } = new AssistantStreamEvent(ErrorValue); + /// Event sent when the stream is done. + public static AssistantStreamEvent Done { get; } = new AssistantStreamEvent(DoneValue); + /// Determines if two values are the same. + public static bool operator ==(AssistantStreamEvent left, AssistantStreamEvent right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(AssistantStreamEvent left, AssistantStreamEvent right) => !left.Equals(right); + /// Converts a to a . + public static implicit operator AssistantStreamEvent(string value) => new AssistantStreamEvent(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is AssistantStreamEvent other && Equals(other); + /// + public bool Equals(AssistantStreamEvent 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/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThread.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThread.Serialization.cs index 568e554f63ce..0c33c423a7cb 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThread.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThread.Serialization.cs @@ -40,6 +40,15 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit writer.WriteStringValue(Object); writer.WritePropertyName("created_at"u8); writer.WriteNumberValue(CreatedAt, "U"); + if (ToolResources != null) + { + writer.WritePropertyName("tool_resources"u8); + writer.WriteObjectValue(ToolResources, options); + } + else + { + writer.WriteNull("tool_resources"); + } if (Metadata != null && Optional.IsCollectionDefined(Metadata)) { writer.WritePropertyName("metadata"u8); @@ -95,6 +104,7 @@ internal static AssistantThread DeserializeAssistantThread(JsonElement element, string id = default; string @object = default; DateTimeOffset createdAt = default; + ToolResources toolResources = default; IReadOnlyDictionary metadata = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); @@ -115,6 +125,16 @@ internal static AssistantThread DeserializeAssistantThread(JsonElement element, createdAt = DateTimeOffset.FromUnixTimeSeconds(property.Value.GetInt64()); continue; } + if (property.NameEquals("tool_resources"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + toolResources = null; + continue; + } + toolResources = ToolResources.DeserializeToolResources(property.Value, options); + continue; + } if (property.NameEquals("metadata"u8)) { if (property.Value.ValueKind == JsonValueKind.Null) @@ -136,7 +156,13 @@ internal static AssistantThread DeserializeAssistantThread(JsonElement element, } } serializedAdditionalRawData = rawDataDictionary; - return new AssistantThread(id, @object, createdAt, metadata, serializedAdditionalRawData); + return new AssistantThread( + id, + @object, + createdAt, + toolResources, + metadata, + serializedAdditionalRawData); } BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThread.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThread.cs index 55fb2ac9a88e..11820b0ed0b6 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThread.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThread.cs @@ -48,14 +48,20 @@ public partial class AssistantThread /// Initializes a new instance of . /// The identifier, which can be referenced in API endpoints. /// The Unix timestamp, in seconds, representing when this object was created. + /// + /// A set of resources that are made available to the assistant's tools in this thread. The resources are specific to the type + /// of tool. For example, the `code_interpreter` tool requires a list of file IDs, while the `file_search` tool requires a list + /// of vector store IDs. + /// /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. /// is null. - internal AssistantThread(string id, DateTimeOffset createdAt, IReadOnlyDictionary metadata) + internal AssistantThread(string id, DateTimeOffset createdAt, ToolResources toolResources, IReadOnlyDictionary metadata) { Argument.AssertNotNull(id, nameof(id)); Id = id; CreatedAt = createdAt; + ToolResources = toolResources; Metadata = metadata; } @@ -63,13 +69,19 @@ internal AssistantThread(string id, DateTimeOffset createdAt, IReadOnlyDictionar /// The identifier, which can be referenced in API endpoints. /// The object type, which is always 'thread'. /// The Unix timestamp, in seconds, representing when this object was created. + /// + /// A set of resources that are made available to the assistant's tools in this thread. The resources are specific to the type + /// of tool. For example, the `code_interpreter` tool requires a list of file IDs, while the `file_search` tool requires a list + /// of vector store IDs. + /// /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. /// Keeps track of any properties unknown to the library. - internal AssistantThread(string id, string @object, DateTimeOffset createdAt, IReadOnlyDictionary metadata, IDictionary serializedAdditionalRawData) + internal AssistantThread(string id, string @object, DateTimeOffset createdAt, ToolResources toolResources, IReadOnlyDictionary metadata, IDictionary serializedAdditionalRawData) { Id = id; Object = @object; CreatedAt = createdAt; + ToolResources = toolResources; Metadata = metadata; _serializedAdditionalRawData = serializedAdditionalRawData; } @@ -84,6 +96,12 @@ internal AssistantThread() /// The Unix timestamp, in seconds, representing when this object was created. public DateTimeOffset CreatedAt { get; } + /// + /// A set of resources that are made available to the assistant's tools in this thread. The resources are specific to the type + /// of tool. For example, the `code_interpreter` tool requires a list of file IDs, while the `file_search` tool requires a list + /// of vector store IDs. + /// + public ToolResources ToolResources { get; } /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. public IReadOnlyDictionary Metadata { get; } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThreadCreationOptions.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThreadCreationOptions.Serialization.cs index 4c346f4c5b45..14aac63b59ed 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThreadCreationOptions.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThreadCreationOptions.Serialization.cs @@ -44,6 +44,18 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit } writer.WriteEndArray(); } + if (Optional.IsDefined(ToolResources)) + { + if (ToolResources != null) + { + writer.WritePropertyName("tool_resources"u8); + writer.WriteObjectValue(ToolResources, options); + } + else + { + writer.WriteNull("tool_resources"); + } + } if (Optional.IsCollectionDefined(Metadata)) { if (Metadata != null) @@ -99,7 +111,8 @@ internal static AssistantThreadCreationOptions DeserializeAssistantThreadCreatio { return null; } - IList messages = default; + IList messages = default; + CreateToolResourcesOptions toolResources = default; IDictionary metadata = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); @@ -111,14 +124,24 @@ internal static AssistantThreadCreationOptions DeserializeAssistantThreadCreatio { continue; } - List array = new List(); + List array = new List(); foreach (var item in property.Value.EnumerateArray()) { - array.Add(ThreadInitializationMessage.DeserializeThreadInitializationMessage(item, options)); + array.Add(ThreadMessageOptions.DeserializeThreadMessageOptions(item, options)); } messages = array; continue; } + if (property.NameEquals("tool_resources"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + toolResources = null; + continue; + } + toolResources = CreateToolResourcesOptions.DeserializeCreateToolResourcesOptions(property.Value, options); + continue; + } if (property.NameEquals("metadata"u8)) { if (property.Value.ValueKind == JsonValueKind.Null) @@ -139,7 +162,7 @@ internal static AssistantThreadCreationOptions DeserializeAssistantThreadCreatio } } serializedAdditionalRawData = rawDataDictionary; - return new AssistantThreadCreationOptions(messages ?? new ChangeTrackingList(), metadata ?? new ChangeTrackingDictionary(), serializedAdditionalRawData); + return new AssistantThreadCreationOptions(messages ?? new ChangeTrackingList(), toolResources, metadata ?? new ChangeTrackingDictionary(), serializedAdditionalRawData); } BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThreadCreationOptions.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThreadCreationOptions.cs index 2df216a2c7e8..086af4d9dc8a 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThreadCreationOptions.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantThreadCreationOptions.cs @@ -48,23 +48,35 @@ public partial class AssistantThreadCreationOptions /// Initializes a new instance of . public AssistantThreadCreationOptions() { - Messages = new ChangeTrackingList(); + Messages = new ChangeTrackingList(); Metadata = new ChangeTrackingDictionary(); } /// Initializes a new instance of . /// The initial messages to associate with the new thread. + /// + /// A set of resources that are made available to the assistant's tools in this thread. The resources are specific to the + /// type of tool. For example, the `code_interpreter` tool requires a list of file IDs, while the `file_search` tool requires + /// a list of vector store IDs. + /// /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. /// Keeps track of any properties unknown to the library. - internal AssistantThreadCreationOptions(IList messages, IDictionary metadata, IDictionary serializedAdditionalRawData) + internal AssistantThreadCreationOptions(IList messages, CreateToolResourcesOptions toolResources, IDictionary metadata, IDictionary serializedAdditionalRawData) { Messages = messages; + ToolResources = toolResources; Metadata = metadata; _serializedAdditionalRawData = serializedAdditionalRawData; } /// The initial messages to associate with the new thread. - public IList Messages { get; } + public IList Messages { get; } + /// + /// A set of resources that are made available to the assistant's tools in this thread. The resources are specific to the + /// type of tool. For example, the `code_interpreter` tool requires a list of file IDs, while the `file_search` tool requires + /// a list of vector store IDs. + /// + public CreateToolResourcesOptions ToolResources { get; set; } /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. public IDictionary Metadata { get; set; } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsApiResponseFormat.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsApiResponseFormat.Serialization.cs new file mode 100644 index 000000000000..3deab8002cf1 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsApiResponseFormat.Serialization.cs @@ -0,0 +1,138 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + [PersistableModelProxy(typeof(UnknownAssistantsApiResponseFormat))] + public partial class AssistantsApiResponseFormat : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(AssistantsApiResponseFormat)} does not support writing '{format}' format."); + } + + if (Optional.IsDefined(Type)) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type.Value.ToString()); + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + AssistantsApiResponseFormat 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(AssistantsApiResponseFormat)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeAssistantsApiResponseFormat(document.RootElement, options); + } + + internal static AssistantsApiResponseFormat DeserializeAssistantsApiResponseFormat(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 AssistantsApiResponseFormatJsonObject.DeserializeAssistantsApiResponseFormatJsonObject(element, options); + case "json_schema": return AssistantsApiResponseFormatJsonSchema.DeserializeAssistantsApiResponseFormatJsonSchema(element, options); + case "text": return AssistantsApiResponseFormatText.DeserializeAssistantsApiResponseFormatText(element, options); + } + } + return UnknownAssistantsApiResponseFormat.DeserializeUnknownAssistantsApiResponseFormat(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(AssistantsApiResponseFormat)} does not support writing '{options.Format}' format."); + } + } + + AssistantsApiResponseFormat 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeAssistantsApiResponseFormat(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(AssistantsApiResponseFormat)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static AssistantsApiResponseFormat FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeAssistantsApiResponseFormat(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsApiResponseFormat.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsApiResponseFormat.cs new file mode 100644 index 000000000000..85723ba24c31 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsApiResponseFormat.cs @@ -0,0 +1,70 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// + /// An object describing the expected output of the model. If `json_object` only `function` type `tools` are allowed to be passed to the Run. + /// If `text` the model can return text or any value needed. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include , and . + /// + public abstract partial class AssistantsApiResponseFormat + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private protected IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + protected AssistantsApiResponseFormat() + { + } + + /// Initializes a new instance of . + /// Must be one of `text`, `json_object` or `json_schema` . + /// Keeps track of any properties unknown to the library. + internal AssistantsApiResponseFormat(ApiResponseFormat? type, IDictionary serializedAdditionalRawData) + { + Type = type; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Must be one of `text`, `json_object` or `json_schema` . + internal ApiResponseFormat? Type { get; set; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsApiResponseFormatJsonObject.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsApiResponseFormatJsonObject.Serialization.cs new file mode 100644 index 000000000000..2a0cb536541a --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsApiResponseFormatJsonObject.Serialization.cs @@ -0,0 +1,130 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class AssistantsApiResponseFormatJsonObject : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(AssistantsApiResponseFormatJsonObject)} does not support writing '{format}' format."); + } + + base.JsonModelWriteCore(writer, options); + } + + AssistantsApiResponseFormatJsonObject 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(AssistantsApiResponseFormatJsonObject)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeAssistantsApiResponseFormatJsonObject(document.RootElement, options); + } + + internal static AssistantsApiResponseFormatJsonObject DeserializeAssistantsApiResponseFormatJsonObject(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + ApiResponseFormat? 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 ApiResponseFormat(property.Value.GetString()); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new AssistantsApiResponseFormatJsonObject(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(AssistantsApiResponseFormatJsonObject)} does not support writing '{options.Format}' format."); + } + } + + AssistantsApiResponseFormatJsonObject 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeAssistantsApiResponseFormatJsonObject(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(AssistantsApiResponseFormatJsonObject)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new AssistantsApiResponseFormatJsonObject FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeAssistantsApiResponseFormatJsonObject(document.RootElement); + } + + /// Convert into a . + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsApiResponseFormatJsonObject.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsApiResponseFormatJsonObject.cs new file mode 100644 index 000000000000..596e3ead3c16 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsApiResponseFormatJsonObject.cs @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// An object describing expected output of the model as a JSON object. + public partial class AssistantsApiResponseFormatJsonObject : AssistantsApiResponseFormat + { + /// Initializes a new instance of . + public AssistantsApiResponseFormatJsonObject() + { + Type = Assistants.ApiResponseFormat?.JsonObject; + } + + /// Initializes a new instance of . + /// Must be one of `text`, `json_object` or `json_schema` . + /// Keeps track of any properties unknown to the library. + internal AssistantsApiResponseFormatJsonObject(ApiResponseFormat? type, IDictionary serializedAdditionalRawData) : base(type, serializedAdditionalRawData) + { + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsApiResponseFormatJsonSchema.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsApiResponseFormatJsonSchema.Serialization.cs new file mode 100644 index 000000000000..ab75f3e95e18 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsApiResponseFormatJsonSchema.Serialization.cs @@ -0,0 +1,138 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class AssistantsApiResponseFormatJsonSchema : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(AssistantsApiResponseFormatJsonSchema)} does not support writing '{format}' format."); + } + + base.JsonModelWriteCore(writer, options); + writer.WritePropertyName("json_schema"u8); + writer.WriteObjectValue(JsonSchema, options); + } + + AssistantsApiResponseFormatJsonSchema 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(AssistantsApiResponseFormatJsonSchema)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeAssistantsApiResponseFormatJsonSchema(document.RootElement, options); + } + + internal static AssistantsApiResponseFormatJsonSchema DeserializeAssistantsApiResponseFormatJsonSchema(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + AssistantsApiResponseFormatJsonSchemaJsonSchema jsonSchema = default; + ApiResponseFormat? type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("json_schema"u8)) + { + jsonSchema = AssistantsApiResponseFormatJsonSchemaJsonSchema.DeserializeAssistantsApiResponseFormatJsonSchemaJsonSchema(property.Value, options); + continue; + } + if (property.NameEquals("type"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + type = new ApiResponseFormat(property.Value.GetString()); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new AssistantsApiResponseFormatJsonSchema(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(AssistantsApiResponseFormatJsonSchema)} does not support writing '{options.Format}' format."); + } + } + + AssistantsApiResponseFormatJsonSchema 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeAssistantsApiResponseFormatJsonSchema(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(AssistantsApiResponseFormatJsonSchema)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new AssistantsApiResponseFormatJsonSchema FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeAssistantsApiResponseFormatJsonSchema(document.RootElement); + } + + /// Convert into a . + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsApiResponseFormatJsonSchema.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsApiResponseFormatJsonSchema.cs new file mode 100644 index 000000000000..1b9f510138e2 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsApiResponseFormatJsonSchema.cs @@ -0,0 +1,44 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// An object describing expected output of the model to match a JSON schema. + public partial class AssistantsApiResponseFormatJsonSchema : AssistantsApiResponseFormat + { + /// Initializes a new instance of . + /// The JSON schema that the model must output. + /// is null. + public AssistantsApiResponseFormatJsonSchema(AssistantsApiResponseFormatJsonSchemaJsonSchema jsonSchema) + { + Argument.AssertNotNull(jsonSchema, nameof(jsonSchema)); + + Type = Assistants.ApiResponseFormat?.JsonSchema; + JsonSchema = jsonSchema; + } + + /// Initializes a new instance of . + /// Must be one of `text`, `json_object` or `json_schema` . + /// Keeps track of any properties unknown to the library. + /// The JSON schema that the model must output. + internal AssistantsApiResponseFormatJsonSchema(ApiResponseFormat? type, IDictionary serializedAdditionalRawData, AssistantsApiResponseFormatJsonSchemaJsonSchema jsonSchema) : base(type, serializedAdditionalRawData) + { + JsonSchema = jsonSchema; + } + + /// Initializes a new instance of for deserialization. + internal AssistantsApiResponseFormatJsonSchema() + { + } + + /// The JSON schema that the model must output. + public AssistantsApiResponseFormatJsonSchemaJsonSchema JsonSchema { get; set; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsApiResponseFormatJsonSchemaJsonSchema.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsApiResponseFormatJsonSchemaJsonSchema.Serialization.cs new file mode 100644 index 000000000000..3ce87ee9a38f --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsApiResponseFormatJsonSchemaJsonSchema.Serialization.cs @@ -0,0 +1,183 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class AssistantsApiResponseFormatJsonSchemaJsonSchema : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(AssistantsApiResponseFormatJsonSchemaJsonSchema)} does not support writing '{format}' format."); + } + + if (Optional.IsDefined(Description)) + { + writer.WritePropertyName("description"u8); + writer.WriteStringValue(Description); + } + writer.WritePropertyName("name"u8); + writer.WriteStringValue(Name); + writer.WritePropertyName("schema"u8); +#if NET6_0_OR_GREATER + writer.WriteRawValue(Schema); +#else + using (JsonDocument document = JsonDocument.Parse(Schema, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + if (Optional.IsDefined(Strict)) + { + writer.WritePropertyName("strict"u8); + writer.WriteBooleanValue(Strict.Value); + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + AssistantsApiResponseFormatJsonSchemaJsonSchema 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(AssistantsApiResponseFormatJsonSchemaJsonSchema)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeAssistantsApiResponseFormatJsonSchemaJsonSchema(document.RootElement, options); + } + + internal static AssistantsApiResponseFormatJsonSchemaJsonSchema DeserializeAssistantsApiResponseFormatJsonSchemaJsonSchema(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)) + { + schema = BinaryData.FromString(property.Value.GetRawText()); + continue; + } + if (property.NameEquals("strict"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + strict = property.Value.GetBoolean(); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new AssistantsApiResponseFormatJsonSchemaJsonSchema(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(AssistantsApiResponseFormatJsonSchemaJsonSchema)} does not support writing '{options.Format}' format."); + } + } + + AssistantsApiResponseFormatJsonSchemaJsonSchema 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeAssistantsApiResponseFormatJsonSchemaJsonSchema(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(AssistantsApiResponseFormatJsonSchemaJsonSchema)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static AssistantsApiResponseFormatJsonSchemaJsonSchema FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeAssistantsApiResponseFormatJsonSchemaJsonSchema(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsApiResponseFormatJsonSchemaJsonSchema.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsApiResponseFormatJsonSchemaJsonSchema.cs new file mode 100644 index 000000000000..ce281b777a78 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsApiResponseFormatJsonSchemaJsonSchema.cs @@ -0,0 +1,119 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The AssistantsApiResponseFormatJsonSchemaJsonSchema. + public partial class AssistantsApiResponseFormatJsonSchemaJsonSchema + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + /// The name of the response format. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 64. + /// The schema for the response format, described as a JSON Schema object. + /// or is null. + public AssistantsApiResponseFormatJsonSchemaJsonSchema(string name, BinaryData schema) + { + Argument.AssertNotNull(name, nameof(name)); + Argument.AssertNotNull(schema, nameof(schema)); + + Name = name; + Schema = schema; + } + + /// Initializes a new instance of . + /// A description of what the response format is for, used by the model to determine how to respond in the format. + /// The name of the response format. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 64. + /// The schema for the response format, described as a JSON Schema object. + /// Whether to enable strict schema adherence when generating the output. If set to true, the model will always follow the exact schema defined in the `schema` field. Only a subset of JSON Schema is supported when `strict` is `true`. To learn more, read the Structured Outputs guide. + /// Keeps track of any properties unknown to the library. + internal AssistantsApiResponseFormatJsonSchemaJsonSchema(string description, string name, BinaryData schema, bool? strict, IDictionary serializedAdditionalRawData) + { + Description = description; + Name = name; + Schema = schema; + Strict = strict; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal AssistantsApiResponseFormatJsonSchemaJsonSchema() + { + } + + /// A description of what the response format is for, used by the model to determine how to respond in the format. + public string Description { get; set; } + /// The name of the response format. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 64. + public string Name { get; set; } + /// + /// The schema for the response format, described as a JSON Schema object. + /// + /// To assign an object to this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + public BinaryData Schema { get; set; } + /// Whether to enable strict schema adherence when generating the output. If set to true, the model will always follow the exact schema defined in the `schema` field. Only a subset of JSON Schema is supported when `strict` is `true`. To learn more, read the Structured Outputs guide. + public bool? Strict { get; set; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsApiResponseFormatMode.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsApiResponseFormatMode.cs new file mode 100644 index 000000000000..56e7d3f9a04b --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsApiResponseFormatMode.cs @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Represents the mode in which the model will handle the return format of a tool call. + public readonly partial struct AssistantsApiResponseFormatMode : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public AssistantsApiResponseFormatMode(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string AutoValue = "auto"; + + /// Default value. Let the model handle the return format. + public static AssistantsApiResponseFormatMode Auto { get; } = new AssistantsApiResponseFormatMode(AutoValue); + /// Determines if two values are the same. + public static bool operator ==(AssistantsApiResponseFormatMode left, AssistantsApiResponseFormatMode right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(AssistantsApiResponseFormatMode left, AssistantsApiResponseFormatMode right) => !left.Equals(right); + /// Converts a to a . + public static implicit operator AssistantsApiResponseFormatMode(string value) => new AssistantsApiResponseFormatMode(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is AssistantsApiResponseFormatMode other && Equals(other); + /// + public bool Equals(AssistantsApiResponseFormatMode 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/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsApiResponseFormatText.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsApiResponseFormatText.Serialization.cs new file mode 100644 index 000000000000..b1fc00fadf3b --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsApiResponseFormatText.Serialization.cs @@ -0,0 +1,130 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class AssistantsApiResponseFormatText : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(AssistantsApiResponseFormatText)} does not support writing '{format}' format."); + } + + base.JsonModelWriteCore(writer, options); + } + + AssistantsApiResponseFormatText 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(AssistantsApiResponseFormatText)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeAssistantsApiResponseFormatText(document.RootElement, options); + } + + internal static AssistantsApiResponseFormatText DeserializeAssistantsApiResponseFormatText(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + ApiResponseFormat? 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 ApiResponseFormat(property.Value.GetString()); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new AssistantsApiResponseFormatText(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(AssistantsApiResponseFormatText)} does not support writing '{options.Format}' format."); + } + } + + AssistantsApiResponseFormatText 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeAssistantsApiResponseFormatText(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(AssistantsApiResponseFormatText)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new AssistantsApiResponseFormatText FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeAssistantsApiResponseFormatText(document.RootElement); + } + + /// Convert into a . + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsApiResponseFormatText.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsApiResponseFormatText.cs new file mode 100644 index 000000000000..d0a8845001f6 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsApiResponseFormatText.cs @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// An object describing expected output of the model as text. + public partial class AssistantsApiResponseFormatText : AssistantsApiResponseFormat + { + /// Initializes a new instance of . + public AssistantsApiResponseFormatText() + { + Type = Assistants.ApiResponseFormat?.Text; + } + + /// Initializes a new instance of . + /// Must be one of `text`, `json_object` or `json_schema` . + /// Keeps track of any properties unknown to the library. + internal AssistantsApiResponseFormatText(ApiResponseFormat? type, IDictionary serializedAdditionalRawData) : base(type, serializedAdditionalRawData) + { + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsApiToolChoiceOptionMode.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsApiToolChoiceOptionMode.cs new file mode 100644 index 000000000000..89f7812a7ae0 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsApiToolChoiceOptionMode.cs @@ -0,0 +1,51 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Specifies how the tool choice will be used. + public readonly partial struct AssistantsApiToolChoiceOptionMode : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public AssistantsApiToolChoiceOptionMode(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string NoneValue = "none"; + private const string AutoValue = "auto"; + + /// The model will not call a function and instead generates a message. + public static AssistantsApiToolChoiceOptionMode None { get; } = new AssistantsApiToolChoiceOptionMode(NoneValue); + /// The model can pick between generating a message or calling a function. + public static AssistantsApiToolChoiceOptionMode Auto { get; } = new AssistantsApiToolChoiceOptionMode(AutoValue); + /// Determines if two values are the same. + public static bool operator ==(AssistantsApiToolChoiceOptionMode left, AssistantsApiToolChoiceOptionMode right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(AssistantsApiToolChoiceOptionMode left, AssistantsApiToolChoiceOptionMode right) => !left.Equals(right); + /// Converts a to a . + public static implicit operator AssistantsApiToolChoiceOptionMode(string value) => new AssistantsApiToolChoiceOptionMode(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is AssistantsApiToolChoiceOptionMode other && Equals(other); + /// + public bool Equals(AssistantsApiToolChoiceOptionMode 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/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsClient.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsClient.cs index b8455f85ccc2..e101178cbf3b 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsClient.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsClient.cs @@ -38,7 +38,7 @@ protected AssistantsClient() } /// Creates a new assistant. - /// Body parameter. + /// The request details to use when creating a new assistant. /// The cancellation token to use. /// is null. public virtual async Task> CreateAssistantAsync(AssistantCreationOptions body, CancellationToken cancellationToken = default) @@ -52,7 +52,7 @@ public virtual async Task> CreateAssistantAsync(AssistantCre } /// Creates a new assistant. - /// Body parameter. + /// The request details to use when creating a new assistant. /// The cancellation token to use. /// is null. public virtual Response CreateAssistant(AssistantCreationOptions body, CancellationToken cancellationToken = default) @@ -135,7 +135,7 @@ internal virtual Response CreateAssistant(RequestContent content, RequestContext /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. - /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. + /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, starting with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. /// The cancellation token to use. internal virtual async Task> InternalGetAssistantsAsync(int? limit = null, ListSortOrder? order = null, string after = null, string before = null, CancellationToken cancellationToken = default) { @@ -148,7 +148,7 @@ internal virtual async Task> Int /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. - /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. + /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, starting with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. /// The cancellation token to use. internal virtual Response InternalGetAssistants(int? limit = null, ListSortOrder? order = null, string after = null, string before = null, CancellationToken cancellationToken = default) { @@ -175,7 +175,7 @@ internal virtual Response InternalGetAssi /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. Allowed values: "asc" | "desc". /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. - /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. + /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, starting with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. /// Service returned a non-success status code. /// The response returned from the service. @@ -213,7 +213,7 @@ internal virtual async Task InternalGetAssistantsAsync(int? limit, str /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. Allowed values: "asc" | "desc". /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. - /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. + /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, starting with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. /// Service returned a non-success status code. /// The response returned from the service. @@ -331,7 +331,7 @@ internal virtual Response GetAssistant(string assistantId, RequestContext contex /// Modifies an existing assistant. /// The ID of the assistant to modify. - /// Body parameter. + /// The request details to use when modifying an existing assistant. /// The cancellation token to use. /// or is null. /// is an empty string, and was expected to be non-empty. @@ -348,7 +348,7 @@ public virtual async Task> UpdateAssistantAsync(string assis /// Modifies an existing assistant. /// The ID of the assistant to modify. - /// Body parameter. + /// The request details to use when modifying an existing assistant. /// The cancellation token to use. /// or is null. /// is an empty string, and was expected to be non-empty. @@ -541,42 +541,36 @@ internal virtual Response InternalDeleteAssistant(string assistantId, RequestCon } } - /// Attaches a previously uploaded file to an assistant for use by tools that can read files. - /// The ID of the assistant to attach the file to. - /// The ID of the previously uploaded file to attach. + /// Creates a new thread. Threads contain messages and can be run by assistants. + /// The details used to create a new assistant thread. /// The cancellation token to use. - /// or is null. - /// is an empty string, and was expected to be non-empty. - public virtual async Task> LinkAssistantFileAsync(string assistantId, string fileId, CancellationToken cancellationToken = default) + /// is null. + public virtual async Task> CreateThreadAsync(AssistantThreadCreationOptions body, CancellationToken cancellationToken = default) { - Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId)); - Argument.AssertNotNull(fileId, nameof(fileId)); + Argument.AssertNotNull(body, nameof(body)); - CreateAssistantFileRequest createAssistantFileRequest = new CreateAssistantFileRequest(fileId, null); + using RequestContent content = body.ToRequestContent(); RequestContext context = FromCancellationToken(cancellationToken); - Response response = await LinkAssistantFileAsync(assistantId, createAssistantFileRequest.ToRequestContent(), context).ConfigureAwait(false); - return Response.FromValue(AssistantFile.FromResponse(response), response); + Response response = await CreateThreadAsync(content, context).ConfigureAwait(false); + return Response.FromValue(AssistantThread.FromResponse(response), response); } - /// Attaches a previously uploaded file to an assistant for use by tools that can read files. - /// The ID of the assistant to attach the file to. - /// The ID of the previously uploaded file to attach. + /// Creates a new thread. Threads contain messages and can be run by assistants. + /// The details used to create a new assistant thread. /// The cancellation token to use. - /// or is null. - /// is an empty string, and was expected to be non-empty. - public virtual Response LinkAssistantFile(string assistantId, string fileId, CancellationToken cancellationToken = default) + /// is null. + public virtual Response CreateThread(AssistantThreadCreationOptions body, CancellationToken cancellationToken = default) { - Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId)); - Argument.AssertNotNull(fileId, nameof(fileId)); + Argument.AssertNotNull(body, nameof(body)); - CreateAssistantFileRequest createAssistantFileRequest = new CreateAssistantFileRequest(fileId, null); + using RequestContent content = body.ToRequestContent(); RequestContext context = FromCancellationToken(cancellationToken); - Response response = LinkAssistantFile(assistantId, createAssistantFileRequest.ToRequestContent(), context); - return Response.FromValue(AssistantFile.FromResponse(response), response); + Response response = CreateThread(content, context); + return Response.FromValue(AssistantThread.FromResponse(response), response); } /// - /// [Protocol Method] Attaches a previously uploaded file to an assistant for use by tools that can read files. + /// [Protocol Method] Creates a new thread. Threads contain messages and can be run by assistants. /// /// /// @@ -585,23 +579,20 @@ public virtual Response LinkAssistantFile(string assistantId, str /// /// /// - /// The ID of the assistant to attach the file to. /// The content to send as the body of the request. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. - /// or is null. - /// is an empty string, and was expected to be non-empty. + /// is null. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual async Task LinkAssistantFileAsync(string assistantId, RequestContent content, RequestContext context = null) + internal virtual async Task CreateThreadAsync(RequestContent content, RequestContext context = null) { - Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId)); Argument.AssertNotNull(content, nameof(content)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.LinkAssistantFile"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.CreateThread"); scope.Start(); try { - using HttpMessage message = CreateLinkAssistantFileRequest(assistantId, content, context); + using HttpMessage message = CreateCreateThreadRequest(content, context); return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); } catch (Exception e) @@ -612,7 +603,7 @@ internal virtual async Task LinkAssistantFileAsync(string assistantId, } /// - /// [Protocol Method] Attaches a previously uploaded file to an assistant for use by tools that can read files. + /// [Protocol Method] Creates a new thread. Threads contain messages and can be run by assistants. /// /// /// @@ -621,23 +612,20 @@ internal virtual async Task LinkAssistantFileAsync(string assistantId, /// /// /// - /// The ID of the assistant to attach the file to. /// The content to send as the body of the request. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. - /// or is null. - /// is an empty string, and was expected to be non-empty. + /// is null. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual Response LinkAssistantFile(string assistantId, RequestContent content, RequestContext context = null) + internal virtual Response CreateThread(RequestContent content, RequestContext context = null) { - Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId)); Argument.AssertNotNull(content, nameof(content)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.LinkAssistantFile"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.CreateThread"); scope.Start(); try { - using HttpMessage message = CreateLinkAssistantFileRequest(assistantId, content, context); + using HttpMessage message = CreateCreateThreadRequest(content, context); return _pipeline.ProcessMessage(message, context); } catch (Exception e) @@ -647,76 +635,59 @@ internal virtual Response LinkAssistantFile(string assistantId, RequestContent c } } - /// Gets a list of files attached to a specific assistant, as used by tools that can read files. - /// The ID of the assistant to retrieve the list of attached files for. - /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. - /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. - /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. - /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. + /// Gets information about an existing thread. + /// The ID of the thread to retrieve information about. /// The cancellation token to use. - /// is null. - /// is an empty string, and was expected to be non-empty. - internal virtual async Task> InternalGetAssistantFilesAsync(string assistantId, int? limit = null, ListSortOrder? order = null, string after = null, string before = null, CancellationToken cancellationToken = default) + /// is null. + /// is an empty string, and was expected to be non-empty. + public virtual async Task> GetThreadAsync(string threadId, CancellationToken cancellationToken = default) { - Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId)); + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); RequestContext context = FromCancellationToken(cancellationToken); - Response response = await InternalGetAssistantFilesAsync(assistantId, limit, order?.ToString(), after, before, context).ConfigureAwait(false); - return Response.FromValue(InternalOpenAIPageableListOfAssistantFile.FromResponse(response), response); + Response response = await GetThreadAsync(threadId, context).ConfigureAwait(false); + return Response.FromValue(AssistantThread.FromResponse(response), response); } - /// Gets a list of files attached to a specific assistant, as used by tools that can read files. - /// The ID of the assistant to retrieve the list of attached files for. - /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. - /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. - /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. - /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. + /// Gets information about an existing thread. + /// The ID of the thread to retrieve information about. /// The cancellation token to use. - /// is null. - /// is an empty string, and was expected to be non-empty. - internal virtual Response InternalGetAssistantFiles(string assistantId, int? limit = null, ListSortOrder? order = null, string after = null, string before = null, CancellationToken cancellationToken = default) + /// is null. + /// is an empty string, and was expected to be non-empty. + public virtual Response GetThread(string threadId, CancellationToken cancellationToken = default) { - Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId)); + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); RequestContext context = FromCancellationToken(cancellationToken); - Response response = InternalGetAssistantFiles(assistantId, limit, order?.ToString(), after, before, context); - return Response.FromValue(InternalOpenAIPageableListOfAssistantFile.FromResponse(response), response); + Response response = GetThread(threadId, context); + return Response.FromValue(AssistantThread.FromResponse(response), response); } /// - /// [Protocol Method] Gets a list of files attached to a specific assistant, as used by tools that can read files. + /// [Protocol Method] Gets information about an existing thread. /// /// /// /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. /// /// - /// - /// - /// Please try the simpler convenience overload with strongly typed models first. - /// - /// /// /// - /// The ID of the assistant to retrieve the list of attached files for. - /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. - /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. Allowed values: "asc" | "desc". - /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. - /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. + /// The ID of the thread to retrieve information about. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. - /// is null. - /// is an empty string, and was expected to be non-empty. + /// is null. + /// is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual async Task InternalGetAssistantFilesAsync(string assistantId, int? limit, string order, string after, string before, RequestContext context) + internal virtual async Task GetThreadAsync(string threadId, RequestContext context) { - Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId)); + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.InternalGetAssistantFiles"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.GetThread"); scope.Start(); try { - using HttpMessage message = CreateInternalGetAssistantFilesRequest(assistantId, limit, order, after, before, context); + using HttpMessage message = CreateGetThreadRequest(threadId, context); return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); } catch (Exception e) @@ -727,39 +698,30 @@ internal virtual async Task InternalGetAssistantFilesAsync(string assi } /// - /// [Protocol Method] Gets a list of files attached to a specific assistant, as used by tools that can read files. + /// [Protocol Method] Gets information about an existing thread. /// /// /// /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. /// /// - /// - /// - /// Please try the simpler convenience overload with strongly typed models first. - /// - /// /// /// - /// The ID of the assistant to retrieve the list of attached files for. - /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. - /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. Allowed values: "asc" | "desc". - /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. - /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. + /// The ID of the thread to retrieve information about. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. - /// is null. - /// is an empty string, and was expected to be non-empty. + /// is null. + /// is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual Response InternalGetAssistantFiles(string assistantId, int? limit, string order, string after, string before, RequestContext context) + internal virtual Response GetThread(string threadId, RequestContext context) { - Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId)); + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.InternalGetAssistantFiles"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.GetThread"); scope.Start(); try { - using HttpMessage message = CreateInternalGetAssistantFilesRequest(assistantId, limit, order, after, before, context); + using HttpMessage message = CreateGetThreadRequest(threadId, context); return _pipeline.ProcessMessage(message, context); } catch (Exception e) @@ -769,40 +731,42 @@ internal virtual Response InternalGetAssistantFiles(string assistantId, int? lim } } - /// Retrieves a file attached to an assistant. - /// The ID of the assistant associated with the attached file. - /// The ID of the file to retrieve. + /// Modifies an existing thread. + /// The ID of the thread to modify. + /// The details used to update an existing assistant thread. /// The cancellation token to use. - /// or is null. - /// or is an empty string, and was expected to be non-empty. - public virtual async Task> GetAssistantFileAsync(string assistantId, string fileId, CancellationToken cancellationToken = default) + /// or is null. + /// is an empty string, and was expected to be non-empty. + public virtual async Task> UpdateThreadAsync(string threadId, UpdateAssistantThreadOptions body, CancellationToken cancellationToken = default) { - Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId)); - Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNull(body, nameof(body)); + using RequestContent content = body.ToRequestContent(); RequestContext context = FromCancellationToken(cancellationToken); - Response response = await GetAssistantFileAsync(assistantId, fileId, context).ConfigureAwait(false); - return Response.FromValue(AssistantFile.FromResponse(response), response); + Response response = await UpdateThreadAsync(threadId, content, context).ConfigureAwait(false); + return Response.FromValue(AssistantThread.FromResponse(response), response); } - /// Retrieves a file attached to an assistant. - /// The ID of the assistant associated with the attached file. - /// The ID of the file to retrieve. + /// Modifies an existing thread. + /// The ID of the thread to modify. + /// The details used to update an existing assistant thread. /// The cancellation token to use. - /// or is null. - /// or is an empty string, and was expected to be non-empty. - public virtual Response GetAssistantFile(string assistantId, string fileId, CancellationToken cancellationToken = default) + /// or is null. + /// is an empty string, and was expected to be non-empty. + public virtual Response UpdateThread(string threadId, UpdateAssistantThreadOptions body, CancellationToken cancellationToken = default) { - Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId)); - Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNull(body, nameof(body)); + using RequestContent content = body.ToRequestContent(); RequestContext context = FromCancellationToken(cancellationToken); - Response response = GetAssistantFile(assistantId, fileId, context); - return Response.FromValue(AssistantFile.FromResponse(response), response); + Response response = UpdateThread(threadId, content, context); + return Response.FromValue(AssistantThread.FromResponse(response), response); } /// - /// [Protocol Method] Retrieves a file attached to an assistant. + /// [Protocol Method] Modifies an existing thread. /// /// /// @@ -811,23 +775,23 @@ public virtual Response GetAssistantFile(string assistantId, stri /// /// /// - /// The ID of the assistant associated with the attached file. - /// The ID of the file to retrieve. + /// The ID of the thread to modify. + /// The content to send as the body of the request. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. - /// or is null. - /// or is an empty string, and was expected to be non-empty. + /// or is null. + /// is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual async Task GetAssistantFileAsync(string assistantId, string fileId, RequestContext context) + internal virtual async Task UpdateThreadAsync(string threadId, RequestContent content, RequestContext context = null) { - Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId)); - Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNull(content, nameof(content)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.GetAssistantFile"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.UpdateThread"); scope.Start(); try { - using HttpMessage message = CreateGetAssistantFileRequest(assistantId, fileId, context); + using HttpMessage message = CreateUpdateThreadRequest(threadId, content, context); return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); } catch (Exception e) @@ -838,7 +802,7 @@ internal virtual async Task GetAssistantFileAsync(string assistantId, } /// - /// [Protocol Method] Retrieves a file attached to an assistant. + /// [Protocol Method] Modifies an existing thread. /// /// /// @@ -847,23 +811,23 @@ internal virtual async Task GetAssistantFileAsync(string assistantId, /// /// /// - /// The ID of the assistant associated with the attached file. - /// The ID of the file to retrieve. + /// The ID of the thread to modify. + /// The content to send as the body of the request. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. - /// or is null. - /// or is an empty string, and was expected to be non-empty. + /// or is null. + /// is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual Response GetAssistantFile(string assistantId, string fileId, RequestContext context) + internal virtual Response UpdateThread(string threadId, RequestContent content, RequestContext context = null) { - Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId)); - Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNull(content, nameof(content)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.GetAssistantFile"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.UpdateThread"); scope.Start(); try { - using HttpMessage message = CreateGetAssistantFileRequest(assistantId, fileId, context); + using HttpMessage message = CreateUpdateThreadRequest(threadId, content, context); return _pipeline.ProcessMessage(message, context); } catch (Exception e) @@ -873,47 +837,36 @@ internal virtual Response GetAssistantFile(string assistantId, string fileId, Re } } - /// - /// Unlinks a previously attached file from an assistant, rendering it unavailable for use by tools that can read - /// files. - /// - /// The ID of the assistant from which the specified file should be unlinked. - /// The ID of the file to unlink from the specified assistant. + /// Deletes an existing thread. + /// The ID of the thread to delete. /// The cancellation token to use. - /// or is null. - /// or is an empty string, and was expected to be non-empty. - internal virtual async Task> InternalUnlinkAssistantFileAsync(string assistantId, string fileId, CancellationToken cancellationToken = default) + /// is null. + /// is an empty string, and was expected to be non-empty. + internal virtual async Task> InternalDeleteThreadAsync(string threadId, CancellationToken cancellationToken = default) { - Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId)); - Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); RequestContext context = FromCancellationToken(cancellationToken); - Response response = await InternalUnlinkAssistantFileAsync(assistantId, fileId, context).ConfigureAwait(false); - return Response.FromValue(InternalAssistantFileDeletionStatus.FromResponse(response), response); + Response response = await InternalDeleteThreadAsync(threadId, context).ConfigureAwait(false); + return Response.FromValue(ThreadDeletionStatus.FromResponse(response), response); } - /// - /// Unlinks a previously attached file from an assistant, rendering it unavailable for use by tools that can read - /// files. - /// - /// The ID of the assistant from which the specified file should be unlinked. - /// The ID of the file to unlink from the specified assistant. + /// Deletes an existing thread. + /// The ID of the thread to delete. /// The cancellation token to use. - /// or is null. - /// or is an empty string, and was expected to be non-empty. - internal virtual Response InternalUnlinkAssistantFile(string assistantId, string fileId, CancellationToken cancellationToken = default) + /// is null. + /// is an empty string, and was expected to be non-empty. + internal virtual Response InternalDeleteThread(string threadId, CancellationToken cancellationToken = default) { - Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId)); - Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); RequestContext context = FromCancellationToken(cancellationToken); - Response response = InternalUnlinkAssistantFile(assistantId, fileId, context); - return Response.FromValue(InternalAssistantFileDeletionStatus.FromResponse(response), response); + Response response = InternalDeleteThread(threadId, context); + return Response.FromValue(ThreadDeletionStatus.FromResponse(response), response); } /// - /// [Protocol Method] Unlinks a previously attached file from an assistant, rendering it unavailable for use by tools that can read - /// files. + /// [Protocol Method] Deletes an existing thread. /// /// /// @@ -922,28 +875,26 @@ internal virtual Response InternalUnlinkAss /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// /// - /// The ID of the assistant from which the specified file should be unlinked. - /// The ID of the file to unlink from the specified assistant. + /// The ID of the thread to delete. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. - /// or is null. - /// or is an empty string, and was expected to be non-empty. + /// is null. + /// is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual async Task InternalUnlinkAssistantFileAsync(string assistantId, string fileId, RequestContext context) + internal virtual async Task InternalDeleteThreadAsync(string threadId, RequestContext context) { - Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId)); - Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.InternalUnlinkAssistantFile"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.InternalDeleteThread"); scope.Start(); try { - using HttpMessage message = CreateInternalUnlinkAssistantFileRequest(assistantId, fileId, context); + using HttpMessage message = CreateInternalDeleteThreadRequest(threadId, context); return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); } catch (Exception e) @@ -954,8 +905,7 @@ internal virtual async Task InternalUnlinkAssistantFileAsync(string as } /// - /// [Protocol Method] Unlinks a previously attached file from an assistant, rendering it unavailable for use by tools that can read - /// files. + /// [Protocol Method] Deletes an existing thread. /// /// /// @@ -964,28 +914,26 @@ internal virtual async Task InternalUnlinkAssistantFileAsync(string as /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// /// - /// The ID of the assistant from which the specified file should be unlinked. - /// The ID of the file to unlink from the specified assistant. + /// The ID of the thread to delete. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. - /// or is null. - /// or is an empty string, and was expected to be non-empty. + /// is null. + /// is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual Response InternalUnlinkAssistantFile(string assistantId, string fileId, RequestContext context) + internal virtual Response InternalDeleteThread(string threadId, RequestContext context) { - Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId)); - Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.InternalUnlinkAssistantFile"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.InternalDeleteThread"); scope.Start(); try { - using HttpMessage message = CreateInternalUnlinkAssistantFileRequest(assistantId, fileId, context); + using HttpMessage message = CreateInternalDeleteThreadRequest(threadId, context); return _pipeline.ProcessMessage(message, context); } catch (Exception e) @@ -995,36 +943,42 @@ internal virtual Response InternalUnlinkAssistantFile(string assistantId, string } } - /// Creates a new thread. Threads contain messages and can be run by assistants. - /// Body parameter. + /// Creates a new message on a specified thread. + /// The ID of the thread to create the new message on. + /// A single message within an assistant thread, as provided during that thread's creation for its initial state. /// The cancellation token to use. - /// is null. - public virtual async Task> CreateThreadAsync(AssistantThreadCreationOptions body, CancellationToken cancellationToken = default) + /// or is null. + /// is an empty string, and was expected to be non-empty. + public virtual async Task> CreateMessageAsync(string threadId, ThreadMessageOptions body, CancellationToken cancellationToken = default) { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); Argument.AssertNotNull(body, nameof(body)); using RequestContent content = body.ToRequestContent(); RequestContext context = FromCancellationToken(cancellationToken); - Response response = await CreateThreadAsync(content, context).ConfigureAwait(false); - return Response.FromValue(AssistantThread.FromResponse(response), response); + Response response = await CreateMessageAsync(threadId, content, context).ConfigureAwait(false); + return Response.FromValue(ThreadMessage.FromResponse(response), response); } - /// Creates a new thread. Threads contain messages and can be run by assistants. - /// Body parameter. + /// Creates a new message on a specified thread. + /// The ID of the thread to create the new message on. + /// A single message within an assistant thread, as provided during that thread's creation for its initial state. /// The cancellation token to use. - /// is null. - public virtual Response CreateThread(AssistantThreadCreationOptions body, CancellationToken cancellationToken = default) + /// or is null. + /// is an empty string, and was expected to be non-empty. + public virtual Response CreateMessage(string threadId, ThreadMessageOptions body, CancellationToken cancellationToken = default) { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); Argument.AssertNotNull(body, nameof(body)); using RequestContent content = body.ToRequestContent(); RequestContext context = FromCancellationToken(cancellationToken); - Response response = CreateThread(content, context); - return Response.FromValue(AssistantThread.FromResponse(response), response); + Response response = CreateMessage(threadId, content, context); + return Response.FromValue(ThreadMessage.FromResponse(response), response); } /// - /// [Protocol Method] Creates a new thread. Threads contain messages and can be run by assistants. + /// [Protocol Method] Creates a new message on a specified thread. /// /// /// @@ -1033,20 +987,23 @@ public virtual Response CreateThread(AssistantThreadCreationOpt /// /// /// + /// The ID of the thread to create the new message on. /// The content to send as the body of the request. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. - /// is null. + /// or is null. + /// is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual async Task CreateThreadAsync(RequestContent content, RequestContext context = null) + internal virtual async Task CreateMessageAsync(string threadId, RequestContent content, RequestContext context = null) { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); Argument.AssertNotNull(content, nameof(content)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.CreateThread"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.CreateMessage"); scope.Start(); try { - using HttpMessage message = CreateCreateThreadRequest(content, context); + using HttpMessage message = CreateCreateMessageRequest(threadId, content, context); return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); } catch (Exception e) @@ -1057,7 +1014,7 @@ internal virtual async Task CreateThreadAsync(RequestContent content, } /// - /// [Protocol Method] Creates a new thread. Threads contain messages and can be run by assistants. + /// [Protocol Method] Creates a new message on a specified thread. /// /// /// @@ -1066,20 +1023,23 @@ internal virtual async Task CreateThreadAsync(RequestContent content, /// /// /// + /// The ID of the thread to create the new message on. /// The content to send as the body of the request. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. - /// is null. + /// or is null. + /// is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual Response CreateThread(RequestContent content, RequestContext context = null) + internal virtual Response CreateMessage(string threadId, RequestContent content, RequestContext context = null) { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); Argument.AssertNotNull(content, nameof(content)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.CreateThread"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.CreateMessage"); scope.Start(); try { - using HttpMessage message = CreateCreateThreadRequest(content, context); + using HttpMessage message = CreateCreateMessageRequest(threadId, content, context); return _pipeline.ProcessMessage(message, context); } catch (Exception e) @@ -1089,59 +1049,79 @@ internal virtual Response CreateThread(RequestContent content, RequestContext co } } - /// Gets information about an existing thread. - /// The ID of the thread to retrieve information about. + /// Gets a list of messages that exist on a thread. + /// The ID of the thread to list messages from. + /// Filter messages by the run ID that generated them. + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. + /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. + /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, starting with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. /// The cancellation token to use. /// is null. /// is an empty string, and was expected to be non-empty. - public virtual async Task> GetThreadAsync(string threadId, CancellationToken cancellationToken = default) + internal virtual async Task> InternalGetMessagesAsync(string threadId, string runId = null, int? limit = null, ListSortOrder? order = null, string after = null, string before = null, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); RequestContext context = FromCancellationToken(cancellationToken); - Response response = await GetThreadAsync(threadId, context).ConfigureAwait(false); - return Response.FromValue(AssistantThread.FromResponse(response), response); + Response response = await InternalGetMessagesAsync(threadId, runId, limit, order?.ToString(), after, before, context).ConfigureAwait(false); + return Response.FromValue(InternalOpenAIPageableListOfThreadMessage.FromResponse(response), response); } - /// Gets information about an existing thread. - /// The ID of the thread to retrieve information about. + /// Gets a list of messages that exist on a thread. + /// The ID of the thread to list messages from. + /// Filter messages by the run ID that generated them. + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. + /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. + /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, starting with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. /// The cancellation token to use. /// is null. /// is an empty string, and was expected to be non-empty. - public virtual Response GetThread(string threadId, CancellationToken cancellationToken = default) + internal virtual Response InternalGetMessages(string threadId, string runId = null, int? limit = null, ListSortOrder? order = null, string after = null, string before = null, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); RequestContext context = FromCancellationToken(cancellationToken); - Response response = GetThread(threadId, context); - return Response.FromValue(AssistantThread.FromResponse(response), response); + Response response = InternalGetMessages(threadId, runId, limit, order?.ToString(), after, before, context); + return Response.FromValue(InternalOpenAIPageableListOfThreadMessage.FromResponse(response), response); } /// - /// [Protocol Method] Gets information about an existing thread. + /// [Protocol Method] Gets a list of messages that exist on a thread. /// /// /// /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. /// /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// /// /// - /// The ID of the thread to retrieve information about. + /// The ID of the thread to list messages from. + /// Filter messages by the run ID that generated them. + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. Allowed values: "asc" | "desc". + /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. + /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, starting with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. /// is null. /// is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual async Task GetThreadAsync(string threadId, RequestContext context) + internal virtual async Task InternalGetMessagesAsync(string threadId, string runId, int? limit, string order, string after, string before, RequestContext context) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.GetThread"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.InternalGetMessages"); scope.Start(); try { - using HttpMessage message = CreateGetThreadRequest(threadId, context); + using HttpMessage message = CreateInternalGetMessagesRequest(threadId, runId, limit, order, after, before, context); return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); } catch (Exception e) @@ -1152,30 +1132,40 @@ internal virtual async Task GetThreadAsync(string threadId, RequestCon } /// - /// [Protocol Method] Gets information about an existing thread. + /// [Protocol Method] Gets a list of messages that exist on a thread. /// /// /// /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. /// /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// /// /// - /// The ID of the thread to retrieve information about. + /// The ID of the thread to list messages from. + /// Filter messages by the run ID that generated them. + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. Allowed values: "asc" | "desc". + /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. + /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, starting with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. /// is null. /// is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual Response GetThread(string threadId, RequestContext context) + internal virtual Response InternalGetMessages(string threadId, string runId, int? limit, string order, string after, string before, RequestContext context) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.GetThread"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.InternalGetMessages"); scope.Start(); try { - using HttpMessage message = CreateGetThreadRequest(threadId, context); + using HttpMessage message = CreateInternalGetMessagesRequest(threadId, runId, limit, order, after, before, context); return _pipeline.ProcessMessage(message, context); } catch (Exception e) @@ -1185,40 +1175,40 @@ internal virtual Response GetThread(string threadId, RequestContext context) } } - /// Modifies an existing thread. - /// The ID of the thread to modify. - /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + /// Gets an existing message from an existing thread. + /// The ID of the thread to retrieve the specified message from. + /// The ID of the message to retrieve from the specified thread. /// The cancellation token to use. - /// is null. - /// is an empty string, and was expected to be non-empty. - public virtual async Task> UpdateThreadAsync(string threadId, IReadOnlyDictionary metadata = null, CancellationToken cancellationToken = default) + /// or is null. + /// or is an empty string, and was expected to be non-empty. + public virtual async Task> GetMessageAsync(string threadId, string messageId, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); - UpdateThreadRequest updateThreadRequest = new UpdateThreadRequest(metadata ?? new ChangeTrackingDictionary(), null); RequestContext context = FromCancellationToken(cancellationToken); - Response response = await UpdateThreadAsync(threadId, updateThreadRequest.ToRequestContent(), context).ConfigureAwait(false); - return Response.FromValue(AssistantThread.FromResponse(response), response); + Response response = await GetMessageAsync(threadId, messageId, context).ConfigureAwait(false); + return Response.FromValue(ThreadMessage.FromResponse(response), response); } - /// Modifies an existing thread. - /// The ID of the thread to modify. - /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + /// Gets an existing message from an existing thread. + /// The ID of the thread to retrieve the specified message from. + /// The ID of the message to retrieve from the specified thread. /// The cancellation token to use. - /// is null. - /// is an empty string, and was expected to be non-empty. - public virtual Response UpdateThread(string threadId, IReadOnlyDictionary metadata = null, CancellationToken cancellationToken = default) + /// or is null. + /// or is an empty string, and was expected to be non-empty. + public virtual Response GetMessage(string threadId, string messageId, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); - UpdateThreadRequest updateThreadRequest = new UpdateThreadRequest(metadata ?? new ChangeTrackingDictionary(), null); RequestContext context = FromCancellationToken(cancellationToken); - Response response = UpdateThread(threadId, updateThreadRequest.ToRequestContent(), context); - return Response.FromValue(AssistantThread.FromResponse(response), response); + Response response = GetMessage(threadId, messageId, context); + return Response.FromValue(ThreadMessage.FromResponse(response), response); } /// - /// [Protocol Method] Modifies an existing thread. + /// [Protocol Method] Gets an existing message from an existing thread. /// /// /// @@ -1227,23 +1217,23 @@ public virtual Response UpdateThread(string threadId, IReadOnly /// /// /// - /// The ID of the thread to modify. - /// The content to send as the body of the request. + /// The ID of the thread to retrieve the specified message from. + /// The ID of the message to retrieve from the specified thread. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. - /// or is null. - /// is an empty string, and was expected to be non-empty. + /// or is null. + /// or is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual async Task UpdateThreadAsync(string threadId, RequestContent content, RequestContext context = null) + internal virtual async Task GetMessageAsync(string threadId, string messageId, RequestContext context) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - Argument.AssertNotNull(content, nameof(content)); + Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.UpdateThread"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.GetMessage"); scope.Start(); try { - using HttpMessage message = CreateUpdateThreadRequest(threadId, content, context); + using HttpMessage message = CreateGetMessageRequest(threadId, messageId, context); return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); } catch (Exception e) @@ -1254,7 +1244,7 @@ internal virtual async Task UpdateThreadAsync(string threadId, Request } /// - /// [Protocol Method] Modifies an existing thread. + /// [Protocol Method] Gets an existing message from an existing thread. /// /// /// @@ -1263,23 +1253,23 @@ internal virtual async Task UpdateThreadAsync(string threadId, Request /// /// /// - /// The ID of the thread to modify. - /// The content to send as the body of the request. + /// The ID of the thread to retrieve the specified message from. + /// The ID of the message to retrieve from the specified thread. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. - /// or is null. - /// is an empty string, and was expected to be non-empty. + /// or is null. + /// or is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual Response UpdateThread(string threadId, RequestContent content, RequestContext context = null) + internal virtual Response GetMessage(string threadId, string messageId, RequestContext context) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - Argument.AssertNotNull(content, nameof(content)); + Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.UpdateThread"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.GetMessage"); scope.Start(); try { - using HttpMessage message = CreateUpdateThreadRequest(threadId, content, context); + using HttpMessage message = CreateGetMessageRequest(threadId, messageId, context); return _pipeline.ProcessMessage(message, context); } catch (Exception e) @@ -1289,64 +1279,71 @@ internal virtual Response UpdateThread(string threadId, RequestContent content, } } - /// Deletes an existing thread. - /// The ID of the thread to delete. + /// Modifies an existing message on an existing thread. + /// The ID of the thread containing the specified message to modify. + /// The ID of the message to modify on the specified thread. + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. /// The cancellation token to use. - /// is null. - /// is an empty string, and was expected to be non-empty. - internal virtual async Task> InternalDeleteThreadAsync(string threadId, CancellationToken cancellationToken = default) + /// or is null. + /// or is an empty string, and was expected to be non-empty. + public virtual async Task> UpdateMessageAsync(string threadId, string messageId, IReadOnlyDictionary metadata = null, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); + UpdateMessageRequest updateMessageRequest = new UpdateMessageRequest(metadata ?? new ChangeTrackingDictionary(), null); RequestContext context = FromCancellationToken(cancellationToken); - Response response = await InternalDeleteThreadAsync(threadId, context).ConfigureAwait(false); - return Response.FromValue(ThreadDeletionStatus.FromResponse(response), response); + Response response = await UpdateMessageAsync(threadId, messageId, updateMessageRequest.ToRequestContent(), context).ConfigureAwait(false); + return Response.FromValue(ThreadMessage.FromResponse(response), response); } - /// Deletes an existing thread. - /// The ID of the thread to delete. + /// Modifies an existing message on an existing thread. + /// The ID of the thread containing the specified message to modify. + /// The ID of the message to modify on the specified thread. + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. /// The cancellation token to use. - /// is null. - /// is an empty string, and was expected to be non-empty. - internal virtual Response InternalDeleteThread(string threadId, CancellationToken cancellationToken = default) + /// or is null. + /// or is an empty string, and was expected to be non-empty. + public virtual Response UpdateMessage(string threadId, string messageId, IReadOnlyDictionary metadata = null, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); + UpdateMessageRequest updateMessageRequest = new UpdateMessageRequest(metadata ?? new ChangeTrackingDictionary(), null); RequestContext context = FromCancellationToken(cancellationToken); - Response response = InternalDeleteThread(threadId, context); - return Response.FromValue(ThreadDeletionStatus.FromResponse(response), response); + Response response = UpdateMessage(threadId, messageId, updateMessageRequest.ToRequestContent(), context); + return Response.FromValue(ThreadMessage.FromResponse(response), response); } /// - /// [Protocol Method] Deletes an existing thread. + /// [Protocol Method] Modifies an existing message on an existing thread. /// /// /// /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. /// /// - /// - /// - /// Please try the simpler convenience overload with strongly typed models first. - /// - /// /// /// - /// The ID of the thread to delete. + /// The ID of the thread containing the specified message to modify. + /// The ID of the message to modify on the specified thread. + /// The content to send as the body of the request. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. - /// is null. - /// is an empty string, and was expected to be non-empty. + /// , or is null. + /// or is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual async Task InternalDeleteThreadAsync(string threadId, RequestContext context) + internal virtual async Task UpdateMessageAsync(string threadId, string messageId, RequestContent content, RequestContext context = null) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); + Argument.AssertNotNull(content, nameof(content)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.InternalDeleteThread"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.UpdateMessage"); scope.Start(); try { - using HttpMessage message = CreateInternalDeleteThreadRequest(threadId, context); + using HttpMessage message = CreateUpdateMessageRequest(threadId, messageId, content, context); return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); } catch (Exception e) @@ -1357,35 +1354,34 @@ internal virtual async Task InternalDeleteThreadAsync(string threadId, } /// - /// [Protocol Method] Deletes an existing thread. + /// [Protocol Method] Modifies an existing message on an existing thread. /// /// /// /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. /// /// - /// - /// - /// Please try the simpler convenience overload with strongly typed models first. - /// - /// /// /// - /// The ID of the thread to delete. + /// The ID of the thread containing the specified message to modify. + /// The ID of the message to modify on the specified thread. + /// The content to send as the body of the request. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. - /// is null. - /// is an empty string, and was expected to be non-empty. + /// , or is null. + /// or is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual Response InternalDeleteThread(string threadId, RequestContext context) + internal virtual Response UpdateMessage(string threadId, string messageId, RequestContent content, RequestContext context = null) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); + Argument.AssertNotNull(content, nameof(content)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.InternalDeleteThread"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.UpdateMessage"); scope.Start(); try { - using HttpMessage message = CreateInternalDeleteThreadRequest(threadId, context); + using HttpMessage message = CreateUpdateMessageRequest(threadId, messageId, content, context); return _pipeline.ProcessMessage(message, context); } catch (Exception e) @@ -1395,48 +1391,44 @@ internal virtual Response InternalDeleteThread(string threadId, RequestContext c } } - /// Creates a new message on a specified thread. - /// The ID of the thread to create the new message on. - /// The role to associate with the new message. - /// The textual content for the new message. - /// A list of up to 10 file IDs to associate with the message, as used by tools like 'code_interpreter' or 'retrieval' that can read files. - /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + /// Creates a new run for an assistant thread. + /// The ID of the thread to run. + /// The details used when creating a new run of an assistant thread. + /// A list of additional fields to include in the response. /// The cancellation token to use. - /// or is null. + /// or is null. /// is an empty string, and was expected to be non-empty. - public virtual async Task> CreateMessageAsync(string threadId, MessageRole role, string content, IEnumerable fileIds = null, IReadOnlyDictionary metadata = null, CancellationToken cancellationToken = default) + public virtual async Task> CreateRunAsync(string threadId, CreateRunOptions body, IEnumerable runInclude = null, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - Argument.AssertNotNull(content, nameof(content)); + Argument.AssertNotNull(body, nameof(body)); - CreateMessageRequest createMessageRequest = new CreateMessageRequest(role, content, fileIds?.ToList() as IReadOnlyList ?? new ChangeTrackingList(), metadata ?? new ChangeTrackingDictionary(), null); + using RequestContent content = body.ToRequestContent(); RequestContext context = FromCancellationToken(cancellationToken); - Response response = await CreateMessageAsync(threadId, createMessageRequest.ToRequestContent(), context).ConfigureAwait(false); - return Response.FromValue(ThreadMessage.FromResponse(response), response); + Response response = await CreateRunAsync(threadId, content, runInclude, context).ConfigureAwait(false); + return Response.FromValue(ThreadRun.FromResponse(response), response); } - /// Creates a new message on a specified thread. - /// The ID of the thread to create the new message on. - /// The role to associate with the new message. - /// The textual content for the new message. - /// A list of up to 10 file IDs to associate with the message, as used by tools like 'code_interpreter' or 'retrieval' that can read files. - /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + /// Creates a new run for an assistant thread. + /// The ID of the thread to run. + /// The details used when creating a new run of an assistant thread. + /// A list of additional fields to include in the response. /// The cancellation token to use. - /// or is null. + /// or is null. /// is an empty string, and was expected to be non-empty. - public virtual Response CreateMessage(string threadId, MessageRole role, string content, IEnumerable fileIds = null, IReadOnlyDictionary metadata = null, CancellationToken cancellationToken = default) + public virtual Response CreateRun(string threadId, CreateRunOptions body, IEnumerable runInclude = null, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - Argument.AssertNotNull(content, nameof(content)); + Argument.AssertNotNull(body, nameof(body)); - CreateMessageRequest createMessageRequest = new CreateMessageRequest(role, content, fileIds?.ToList() as IReadOnlyList ?? new ChangeTrackingList(), metadata ?? new ChangeTrackingDictionary(), null); + using RequestContent content = body.ToRequestContent(); RequestContext context = FromCancellationToken(cancellationToken); - Response response = CreateMessage(threadId, createMessageRequest.ToRequestContent(), context); - return Response.FromValue(ThreadMessage.FromResponse(response), response); + Response response = CreateRun(threadId, content, runInclude, context); + return Response.FromValue(ThreadRun.FromResponse(response), response); } /// - /// [Protocol Method] Creates a new message on a specified thread. + /// [Protocol Method] Creates a new run for an assistant thread. /// /// /// @@ -1445,23 +1437,24 @@ public virtual Response CreateMessage(string threadId, MessageRol /// /// /// - /// The ID of the thread to create the new message on. + /// The ID of the thread to run. /// The content to send as the body of the request. + /// A list of additional fields to include in the response. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. /// or is null. /// is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual async Task CreateMessageAsync(string threadId, RequestContent content, RequestContext context = null) + internal virtual async Task CreateRunAsync(string threadId, RequestContent content, IEnumerable runInclude = null, RequestContext context = null) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); Argument.AssertNotNull(content, nameof(content)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.CreateMessage"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.CreateRun"); scope.Start(); try { - using HttpMessage message = CreateCreateMessageRequest(threadId, content, context); + using HttpMessage message = CreateCreateRunRequest(threadId, content, runInclude, context); return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); } catch (Exception e) @@ -1472,7 +1465,7 @@ internal virtual async Task CreateMessageAsync(string threadId, Reques } /// - /// [Protocol Method] Creates a new message on a specified thread. + /// [Protocol Method] Creates a new run for an assistant thread. /// /// /// @@ -1481,23 +1474,24 @@ internal virtual async Task CreateMessageAsync(string threadId, Reques /// /// /// - /// The ID of the thread to create the new message on. + /// The ID of the thread to run. /// The content to send as the body of the request. + /// A list of additional fields to include in the response. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. /// or is null. /// is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual Response CreateMessage(string threadId, RequestContent content, RequestContext context = null) + internal virtual Response CreateRun(string threadId, RequestContent content, IEnumerable runInclude = null, RequestContext context = null) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); Argument.AssertNotNull(content, nameof(content)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.CreateMessage"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.CreateRun"); scope.Start(); try { - using HttpMessage message = CreateCreateMessageRequest(threadId, content, context); + using HttpMessage message = CreateCreateRunRequest(threadId, content, runInclude, context); return _pipeline.ProcessMessage(message, context); } catch (Exception e) @@ -1507,44 +1501,44 @@ internal virtual Response CreateMessage(string threadId, RequestContent content, } } - /// Gets a list of messages that exist on a thread. - /// The ID of the thread to list messages from. + /// Gets a list of runs for a specified thread. + /// The ID of the thread to list runs from. /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. - /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. + /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, starting with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. /// The cancellation token to use. /// is null. /// is an empty string, and was expected to be non-empty. - internal virtual async Task> InternalGetMessagesAsync(string threadId, int? limit = null, ListSortOrder? order = null, string after = null, string before = null, CancellationToken cancellationToken = default) + internal virtual async Task> InternalGetRunsAsync(string threadId, int? limit = null, ListSortOrder? order = null, string after = null, string before = null, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); RequestContext context = FromCancellationToken(cancellationToken); - Response response = await InternalGetMessagesAsync(threadId, limit, order?.ToString(), after, before, context).ConfigureAwait(false); - return Response.FromValue(InternalOpenAIPageableListOfThreadMessage.FromResponse(response), response); + Response response = await InternalGetRunsAsync(threadId, limit, order?.ToString(), after, before, context).ConfigureAwait(false); + return Response.FromValue(InternalOpenAIPageableListOfThreadRun.FromResponse(response), response); } - /// Gets a list of messages that exist on a thread. - /// The ID of the thread to list messages from. + /// Gets a list of runs for a specified thread. + /// The ID of the thread to list runs from. /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. - /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. + /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, starting with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. /// The cancellation token to use. /// is null. /// is an empty string, and was expected to be non-empty. - internal virtual Response InternalGetMessages(string threadId, int? limit = null, ListSortOrder? order = null, string after = null, string before = null, CancellationToken cancellationToken = default) + internal virtual Response InternalGetRuns(string threadId, int? limit = null, ListSortOrder? order = null, string after = null, string before = null, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); RequestContext context = FromCancellationToken(cancellationToken); - Response response = InternalGetMessages(threadId, limit, order?.ToString(), after, before, context); - return Response.FromValue(InternalOpenAIPageableListOfThreadMessage.FromResponse(response), response); + Response response = InternalGetRuns(threadId, limit, order?.ToString(), after, before, context); + return Response.FromValue(InternalOpenAIPageableListOfThreadRun.FromResponse(response), response); } /// - /// [Protocol Method] Gets a list of messages that exist on a thread. + /// [Protocol Method] Gets a list of runs for a specified thread. /// /// /// @@ -1553,30 +1547,30 @@ internal virtual Response InternalGet /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// /// - /// The ID of the thread to list messages from. + /// The ID of the thread to list runs from. /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. Allowed values: "asc" | "desc". /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. - /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. + /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, starting with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. /// is null. /// is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual async Task InternalGetMessagesAsync(string threadId, int? limit, string order, string after, string before, RequestContext context) + internal virtual async Task InternalGetRunsAsync(string threadId, int? limit, string order, string after, string before, RequestContext context) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.InternalGetMessages"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.InternalGetRuns"); scope.Start(); try { - using HttpMessage message = CreateInternalGetMessagesRequest(threadId, limit, order, after, before, context); + using HttpMessage message = CreateInternalGetRunsRequest(threadId, limit, order, after, before, context); return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); } catch (Exception e) @@ -1587,7 +1581,7 @@ internal virtual async Task InternalGetMessagesAsync(string threadId, } /// - /// [Protocol Method] Gets a list of messages that exist on a thread. + /// [Protocol Method] Gets a list of runs for a specified thread. /// /// /// @@ -1596,30 +1590,30 @@ internal virtual async Task InternalGetMessagesAsync(string threadId, /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// /// - /// The ID of the thread to list messages from. + /// The ID of the thread to list runs from. /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. Allowed values: "asc" | "desc". /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. - /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. + /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, starting with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. /// is null. /// is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual Response InternalGetMessages(string threadId, int? limit, string order, string after, string before, RequestContext context) + internal virtual Response InternalGetRuns(string threadId, int? limit, string order, string after, string before, RequestContext context) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.InternalGetMessages"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.InternalGetRuns"); scope.Start(); try { - using HttpMessage message = CreateInternalGetMessagesRequest(threadId, limit, order, after, before, context); + using HttpMessage message = CreateInternalGetRunsRequest(threadId, limit, order, after, before, context); return _pipeline.ProcessMessage(message, context); } catch (Exception e) @@ -1629,40 +1623,40 @@ internal virtual Response InternalGetMessages(string threadId, int? limit, strin } } - /// Gets an existing message from an existing thread. - /// The ID of the thread to retrieve the specified message from. - /// The ID of the message to retrieve from the specified thread. + /// Gets an existing run from an existing thread. + /// The ID of the thread to retrieve run information from. + /// The ID of the thread to retrieve information about. /// The cancellation token to use. - /// or is null. - /// or is an empty string, and was expected to be non-empty. - public virtual async Task> GetMessageAsync(string threadId, string messageId, CancellationToken cancellationToken = default) + /// or is null. + /// or is an empty string, and was expected to be non-empty. + public virtual async Task> GetRunAsync(string threadId, string runId, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); + Argument.AssertNotNullOrEmpty(runId, nameof(runId)); RequestContext context = FromCancellationToken(cancellationToken); - Response response = await GetMessageAsync(threadId, messageId, context).ConfigureAwait(false); - return Response.FromValue(ThreadMessage.FromResponse(response), response); + Response response = await GetRunAsync(threadId, runId, context).ConfigureAwait(false); + return Response.FromValue(ThreadRun.FromResponse(response), response); } - /// Gets an existing message from an existing thread. - /// The ID of the thread to retrieve the specified message from. - /// The ID of the message to retrieve from the specified thread. + /// Gets an existing run from an existing thread. + /// The ID of the thread to retrieve run information from. + /// The ID of the thread to retrieve information about. /// The cancellation token to use. - /// or is null. - /// or is an empty string, and was expected to be non-empty. - public virtual Response GetMessage(string threadId, string messageId, CancellationToken cancellationToken = default) + /// or is null. + /// or is an empty string, and was expected to be non-empty. + public virtual Response GetRun(string threadId, string runId, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); + Argument.AssertNotNullOrEmpty(runId, nameof(runId)); RequestContext context = FromCancellationToken(cancellationToken); - Response response = GetMessage(threadId, messageId, context); - return Response.FromValue(ThreadMessage.FromResponse(response), response); + Response response = GetRun(threadId, runId, context); + return Response.FromValue(ThreadRun.FromResponse(response), response); } /// - /// [Protocol Method] Gets an existing message from an existing thread. + /// [Protocol Method] Gets an existing run from an existing thread. /// /// /// @@ -1671,23 +1665,23 @@ public virtual Response GetMessage(string threadId, string messag /// /// /// - /// The ID of the thread to retrieve the specified message from. - /// The ID of the message to retrieve from the specified thread. + /// The ID of the thread to retrieve run information from. + /// The ID of the thread to retrieve information about. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. - /// or is null. - /// or is an empty string, and was expected to be non-empty. + /// or is null. + /// or is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual async Task GetMessageAsync(string threadId, string messageId, RequestContext context) + internal virtual async Task GetRunAsync(string threadId, string runId, RequestContext context) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); + Argument.AssertNotNullOrEmpty(runId, nameof(runId)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.GetMessage"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.GetRun"); scope.Start(); try { - using HttpMessage message = CreateGetMessageRequest(threadId, messageId, context); + using HttpMessage message = CreateGetRunRequest(threadId, runId, context); return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); } catch (Exception e) @@ -1698,7 +1692,7 @@ internal virtual async Task GetMessageAsync(string threadId, string me } /// - /// [Protocol Method] Gets an existing message from an existing thread. + /// [Protocol Method] Gets an existing run from an existing thread. /// /// /// @@ -1707,23 +1701,23 @@ internal virtual async Task GetMessageAsync(string threadId, string me /// /// /// - /// The ID of the thread to retrieve the specified message from. - /// The ID of the message to retrieve from the specified thread. + /// The ID of the thread to retrieve run information from. + /// The ID of the thread to retrieve information about. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. - /// or is null. - /// or is an empty string, and was expected to be non-empty. + /// or is null. + /// or is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual Response GetMessage(string threadId, string messageId, RequestContext context) + internal virtual Response GetRun(string threadId, string runId, RequestContext context) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); + Argument.AssertNotNullOrEmpty(runId, nameof(runId)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.GetMessage"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.GetRun"); scope.Start(); try { - using HttpMessage message = CreateGetMessageRequest(threadId, messageId, context); + using HttpMessage message = CreateGetRunRequest(threadId, runId, context); return _pipeline.ProcessMessage(message, context); } catch (Exception e) @@ -1733,44 +1727,44 @@ internal virtual Response GetMessage(string threadId, string messageId, RequestC } } - /// Modifies an existing message on an existing thread. - /// The ID of the thread containing the specified message to modify. - /// The ID of the message to modify on the specified thread. + /// Modifies an existing thread run. + /// The ID of the thread associated with the specified run. + /// The ID of the run to modify. /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. /// The cancellation token to use. - /// or is null. - /// or is an empty string, and was expected to be non-empty. - public virtual async Task> UpdateMessageAsync(string threadId, string messageId, IReadOnlyDictionary metadata = null, CancellationToken cancellationToken = default) + /// or is null. + /// or is an empty string, and was expected to be non-empty. + public virtual async Task> UpdateRunAsync(string threadId, string runId, IReadOnlyDictionary metadata = null, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); + Argument.AssertNotNullOrEmpty(runId, nameof(runId)); - UpdateMessageRequest updateMessageRequest = new UpdateMessageRequest(metadata ?? new ChangeTrackingDictionary(), null); + UpdateRunRequest updateRunRequest = new UpdateRunRequest(metadata ?? new ChangeTrackingDictionary(), null); RequestContext context = FromCancellationToken(cancellationToken); - Response response = await UpdateMessageAsync(threadId, messageId, updateMessageRequest.ToRequestContent(), context).ConfigureAwait(false); - return Response.FromValue(ThreadMessage.FromResponse(response), response); + Response response = await UpdateRunAsync(threadId, runId, updateRunRequest.ToRequestContent(), context).ConfigureAwait(false); + return Response.FromValue(ThreadRun.FromResponse(response), response); } - /// Modifies an existing message on an existing thread. - /// The ID of the thread containing the specified message to modify. - /// The ID of the message to modify on the specified thread. + /// Modifies an existing thread run. + /// The ID of the thread associated with the specified run. + /// The ID of the run to modify. /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. /// The cancellation token to use. - /// or is null. - /// or is an empty string, and was expected to be non-empty. - public virtual Response UpdateMessage(string threadId, string messageId, IReadOnlyDictionary metadata = null, CancellationToken cancellationToken = default) + /// or is null. + /// or is an empty string, and was expected to be non-empty. + public virtual Response UpdateRun(string threadId, string runId, IReadOnlyDictionary metadata = null, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); + Argument.AssertNotNullOrEmpty(runId, nameof(runId)); - UpdateMessageRequest updateMessageRequest = new UpdateMessageRequest(metadata ?? new ChangeTrackingDictionary(), null); + UpdateRunRequest updateRunRequest = new UpdateRunRequest(metadata ?? new ChangeTrackingDictionary(), null); RequestContext context = FromCancellationToken(cancellationToken); - Response response = UpdateMessage(threadId, messageId, updateMessageRequest.ToRequestContent(), context); - return Response.FromValue(ThreadMessage.FromResponse(response), response); + Response response = UpdateRun(threadId, runId, updateRunRequest.ToRequestContent(), context); + return Response.FromValue(ThreadRun.FromResponse(response), response); } /// - /// [Protocol Method] Modifies an existing message on an existing thread. + /// [Protocol Method] Modifies an existing thread run. /// /// /// @@ -1779,25 +1773,25 @@ public virtual Response UpdateMessage(string threadId, string mes /// /// /// - /// The ID of the thread containing the specified message to modify. - /// The ID of the message to modify on the specified thread. + /// The ID of the thread associated with the specified run. + /// The ID of the run to modify. /// The content to send as the body of the request. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. - /// , or is null. - /// or is an empty string, and was expected to be non-empty. + /// , or is null. + /// or is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual async Task UpdateMessageAsync(string threadId, string messageId, RequestContent content, RequestContext context = null) + internal virtual async Task UpdateRunAsync(string threadId, string runId, RequestContent content, RequestContext context = null) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); + Argument.AssertNotNullOrEmpty(runId, nameof(runId)); Argument.AssertNotNull(content, nameof(content)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.UpdateMessage"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.UpdateRun"); scope.Start(); try { - using HttpMessage message = CreateUpdateMessageRequest(threadId, messageId, content, context); + using HttpMessage message = CreateUpdateRunRequest(threadId, runId, content, context); return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); } catch (Exception e) @@ -1808,7 +1802,7 @@ internal virtual async Task UpdateMessageAsync(string threadId, string } /// - /// [Protocol Method] Modifies an existing message on an existing thread. + /// [Protocol Method] Modifies an existing thread run. /// /// /// @@ -1817,25 +1811,25 @@ internal virtual async Task UpdateMessageAsync(string threadId, string /// /// /// - /// The ID of the thread containing the specified message to modify. - /// The ID of the message to modify on the specified thread. + /// The ID of the thread associated with the specified run. + /// The ID of the run to modify. /// The content to send as the body of the request. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. - /// , or is null. - /// or is an empty string, and was expected to be non-empty. + /// , or is null. + /// or is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual Response UpdateMessage(string threadId, string messageId, RequestContent content, RequestContext context = null) + internal virtual Response UpdateRun(string threadId, string runId, RequestContent content, RequestContext context = null) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); + Argument.AssertNotNullOrEmpty(runId, nameof(runId)); Argument.AssertNotNull(content, nameof(content)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.UpdateMessage"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.UpdateRun"); scope.Start(); try { - using HttpMessage message = CreateUpdateMessageRequest(threadId, messageId, content, context); + using HttpMessage message = CreateUpdateRunRequest(threadId, runId, content, context); return _pipeline.ProcessMessage(message, context); } catch (Exception e) @@ -1845,48 +1839,786 @@ internal virtual Response UpdateMessage(string threadId, string messageId, Reque } } - /// Gets a list of previously uploaded files associated with a message from a thread. - /// The ID of the thread containing the message to list files from. - /// The ID of the message to list files from. - /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. - /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. - /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. - /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. + /// Submits outputs from tools as requested by tool calls in a run. Runs that need submitted tool outputs will have a status of 'requires_action' with a required_action.type of 'submit_tool_outputs'. + /// The ID of the thread that was run. + /// The ID of the run that requires tool outputs. + /// A list of tools for which the outputs are being submitted. + /// If `true`, returns a stream of events that happen during the Run as server-sent events, terminating when the Run enters a terminal state with a `data: [DONE]` message. /// The cancellation token to use. - /// or is null. - /// or is an empty string, and was expected to be non-empty. - internal virtual async Task> InternalGetMessageFilesAsync(string threadId, string messageId, int? limit = null, ListSortOrder? order = null, string after = null, string before = null, CancellationToken cancellationToken = default) + /// , or is null. + /// or is an empty string, and was expected to be non-empty. + public virtual async Task> SubmitToolOutputsToRunAsync(string threadId, string runId, IEnumerable toolOutputs, bool? stream = null, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); + Argument.AssertNotNullOrEmpty(runId, nameof(runId)); + Argument.AssertNotNull(toolOutputs, nameof(toolOutputs)); + SubmitToolOutputsToRunRequest submitToolOutputsToRunRequest = new SubmitToolOutputsToRunRequest(toolOutputs.ToList(), stream, null); RequestContext context = FromCancellationToken(cancellationToken); - Response response = await InternalGetMessageFilesAsync(threadId, messageId, limit, order?.ToString(), after, before, context).ConfigureAwait(false); - return Response.FromValue(InternalOpenAIPageableListOfMessageFile.FromResponse(response), response); + Response response = await SubmitToolOutputsToRunAsync(threadId, runId, submitToolOutputsToRunRequest.ToRequestContent(), context).ConfigureAwait(false); + return Response.FromValue(ThreadRun.FromResponse(response), response); } - /// Gets a list of previously uploaded files associated with a message from a thread. - /// The ID of the thread containing the message to list files from. - /// The ID of the message to list files from. - /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. - /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. - /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. - /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. + /// Submits outputs from tools as requested by tool calls in a run. Runs that need submitted tool outputs will have a status of 'requires_action' with a required_action.type of 'submit_tool_outputs'. + /// The ID of the thread that was run. + /// The ID of the run that requires tool outputs. + /// A list of tools for which the outputs are being submitted. + /// If `true`, returns a stream of events that happen during the Run as server-sent events, terminating when the Run enters a terminal state with a `data: [DONE]` message. /// The cancellation token to use. - /// or is null. - /// or is an empty string, and was expected to be non-empty. - internal virtual Response InternalGetMessageFiles(string threadId, string messageId, int? limit = null, ListSortOrder? order = null, string after = null, string before = null, CancellationToken cancellationToken = default) + /// , or is null. + /// or is an empty string, and was expected to be non-empty. + public virtual Response SubmitToolOutputsToRun(string threadId, string runId, IEnumerable toolOutputs, bool? stream = null, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(runId, nameof(runId)); + Argument.AssertNotNull(toolOutputs, nameof(toolOutputs)); + + SubmitToolOutputsToRunRequest submitToolOutputsToRunRequest = new SubmitToolOutputsToRunRequest(toolOutputs.ToList(), stream, null); + RequestContext context = FromCancellationToken(cancellationToken); + Response response = SubmitToolOutputsToRun(threadId, runId, submitToolOutputsToRunRequest.ToRequestContent(), context); + return Response.FromValue(ThreadRun.FromResponse(response), response); + } + + /// + /// [Protocol Method] Submits outputs from tools as requested by tool calls in a run. Runs that need submitted tool outputs will have a status of 'requires_action' with a required_action.type of 'submit_tool_outputs'. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The ID of the thread that was run. + /// The ID of the run that requires tool outputs. + /// The content to send as the body of the request. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// , or is null. + /// or is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual async Task SubmitToolOutputsToRunAsync(string threadId, string runId, RequestContent content, RequestContext context = null) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(runId, nameof(runId)); + Argument.AssertNotNull(content, nameof(content)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.SubmitToolOutputsToRun"); + scope.Start(); + try + { + using HttpMessage message = CreateSubmitToolOutputsToRunRequest(threadId, runId, content, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Submits outputs from tools as requested by tool calls in a run. Runs that need submitted tool outputs will have a status of 'requires_action' with a required_action.type of 'submit_tool_outputs'. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The ID of the thread that was run. + /// The ID of the run that requires tool outputs. + /// The content to send as the body of the request. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// , or is null. + /// or is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual Response SubmitToolOutputsToRun(string threadId, string runId, RequestContent content, RequestContext context = null) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(runId, nameof(runId)); + Argument.AssertNotNull(content, nameof(content)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.SubmitToolOutputsToRun"); + scope.Start(); + try + { + using HttpMessage message = CreateSubmitToolOutputsToRunRequest(threadId, runId, content, context); + return _pipeline.ProcessMessage(message, context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Cancels a run of an in progress thread. + /// The ID of the thread being run. + /// The ID of the run to cancel. + /// The cancellation token to use. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + public virtual async Task> CancelRunAsync(string threadId, string runId, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(runId, nameof(runId)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = await CancelRunAsync(threadId, runId, context).ConfigureAwait(false); + return Response.FromValue(ThreadRun.FromResponse(response), response); + } + + /// Cancels a run of an in progress thread. + /// The ID of the thread being run. + /// The ID of the run to cancel. + /// The cancellation token to use. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + public virtual Response CancelRun(string threadId, string runId, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(runId, nameof(runId)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = CancelRun(threadId, runId, context); + return Response.FromValue(ThreadRun.FromResponse(response), response); + } + + /// + /// [Protocol Method] Cancels a run of an in progress thread. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The ID of the thread being run. + /// The ID of the run to cancel. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual async Task CancelRunAsync(string threadId, string runId, RequestContext context) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(runId, nameof(runId)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.CancelRun"); + scope.Start(); + try + { + using HttpMessage message = CreateCancelRunRequest(threadId, runId, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Cancels a run of an in progress thread. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The ID of the thread being run. + /// The ID of the run to cancel. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual Response CancelRun(string threadId, string runId, RequestContext context) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(runId, nameof(runId)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.CancelRun"); + scope.Start(); + try + { + using HttpMessage message = CreateCancelRunRequest(threadId, runId, context); + return _pipeline.ProcessMessage(message, context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Creates a new assistant thread and immediately starts a run using that new thread. + /// The details used when creating and immediately running a new assistant thread. + /// The cancellation token to use. + /// is null. + public virtual async Task> CreateThreadAndRunAsync(CreateAndRunThreadOptions body, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(body, nameof(body)); + + using RequestContent content = body.ToRequestContent(); + RequestContext context = FromCancellationToken(cancellationToken); + Response response = await CreateThreadAndRunAsync(content, context).ConfigureAwait(false); + return Response.FromValue(ThreadRun.FromResponse(response), response); + } + + /// Creates a new assistant thread and immediately starts a run using that new thread. + /// The details used when creating and immediately running a new assistant thread. + /// The cancellation token to use. + /// is null. + public virtual Response CreateThreadAndRun(CreateAndRunThreadOptions body, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(body, nameof(body)); + + using RequestContent content = body.ToRequestContent(); + RequestContext context = FromCancellationToken(cancellationToken); + Response response = CreateThreadAndRun(content, context); + return Response.FromValue(ThreadRun.FromResponse(response), response); + } + + /// + /// [Protocol Method] Creates a new assistant thread and immediately starts a run using that new thread. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual async Task CreateThreadAndRunAsync(RequestContent content, RequestContext context = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.CreateThreadAndRun"); + scope.Start(); + try + { + using HttpMessage message = CreateCreateThreadAndRunRequest(content, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Creates a new assistant thread and immediately starts a run using that new thread. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual Response CreateThreadAndRun(RequestContent content, RequestContext context = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.CreateThreadAndRun"); + scope.Start(); + try + { + using HttpMessage message = CreateCreateThreadAndRunRequest(content, context); + return _pipeline.ProcessMessage(message, context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Gets a single run step from a thread run. + /// The ID of the thread that was run. + /// The ID of the specific run to retrieve the step from. + /// The ID of the step to retrieve information about. + /// A list of additional fields to include in the response. + /// The cancellation token to use. + /// , or is null. + /// , or is an empty string, and was expected to be non-empty. + public virtual async Task> GetRunStepAsync(string threadId, string runId, string stepId, IEnumerable runInclude = null, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(runId, nameof(runId)); + Argument.AssertNotNullOrEmpty(stepId, nameof(stepId)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = await GetRunStepAsync(threadId, runId, stepId, runInclude, context).ConfigureAwait(false); + return Response.FromValue(RunStep.FromResponse(response), response); + } + + /// Gets a single run step from a thread run. + /// The ID of the thread that was run. + /// The ID of the specific run to retrieve the step from. + /// The ID of the step to retrieve information about. + /// A list of additional fields to include in the response. + /// The cancellation token to use. + /// , or is null. + /// , or is an empty string, and was expected to be non-empty. + public virtual Response GetRunStep(string threadId, string runId, string stepId, IEnumerable runInclude = null, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(runId, nameof(runId)); + Argument.AssertNotNullOrEmpty(stepId, nameof(stepId)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = GetRunStep(threadId, runId, stepId, runInclude, context); + return Response.FromValue(RunStep.FromResponse(response), response); + } + + /// + /// [Protocol Method] Gets a single run step from a thread run. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The ID of the thread that was run. + /// The ID of the specific run to retrieve the step from. + /// The ID of the step to retrieve information about. + /// A list of additional fields to include in the response. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// , or is null. + /// , or is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual async Task GetRunStepAsync(string threadId, string runId, string stepId, IEnumerable runInclude, RequestContext context) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(runId, nameof(runId)); + Argument.AssertNotNullOrEmpty(stepId, nameof(stepId)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.GetRunStep"); + scope.Start(); + try + { + using HttpMessage message = CreateGetRunStepRequest(threadId, runId, stepId, runInclude, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Gets a single run step from a thread run. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The ID of the thread that was run. + /// The ID of the specific run to retrieve the step from. + /// The ID of the step to retrieve information about. + /// A list of additional fields to include in the response. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// , or is null. + /// , or is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual Response GetRunStep(string threadId, string runId, string stepId, IEnumerable runInclude, RequestContext context) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(runId, nameof(runId)); + Argument.AssertNotNullOrEmpty(stepId, nameof(stepId)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.GetRunStep"); + scope.Start(); + try + { + using HttpMessage message = CreateGetRunStepRequest(threadId, runId, stepId, runInclude, context); + return _pipeline.ProcessMessage(message, context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Gets a list of run steps from a thread run. + /// The ID of the thread that was run. + /// The ID of the run to list steps from. + /// A list of additional fields to include in the response. + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. + /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. + /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, starting with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. + /// The cancellation token to use. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + internal virtual async Task> InternalGetRunStepsAsync(string threadId, string runId, IEnumerable runInclude = null, int? limit = null, ListSortOrder? order = null, string after = null, string before = null, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(runId, nameof(runId)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = await InternalGetRunStepsAsync(threadId, runId, runInclude, limit, order?.ToString(), after, before, context).ConfigureAwait(false); + return Response.FromValue(InternalOpenAIPageableListOfRunStep.FromResponse(response), response); + } + + /// Gets a list of run steps from a thread run. + /// The ID of the thread that was run. + /// The ID of the run to list steps from. + /// A list of additional fields to include in the response. + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. + /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. + /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, starting with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. + /// The cancellation token to use. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + internal virtual Response InternalGetRunSteps(string threadId, string runId, IEnumerable runInclude = null, int? limit = null, ListSortOrder? order = null, string after = null, string before = null, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(runId, nameof(runId)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = InternalGetRunSteps(threadId, runId, runInclude, limit, order?.ToString(), after, before, context); + return Response.FromValue(InternalOpenAIPageableListOfRunStep.FromResponse(response), response); + } + + /// + /// [Protocol Method] Gets a list of run steps from a thread run. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The ID of the thread that was run. + /// The ID of the run to list steps from. + /// A list of additional fields to include in the response. + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. Allowed values: "asc" | "desc". + /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. + /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, starting with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual async Task InternalGetRunStepsAsync(string threadId, string runId, IEnumerable runInclude, int? limit, string order, string after, string before, RequestContext context) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(runId, nameof(runId)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.InternalGetRunSteps"); + scope.Start(); + try + { + using HttpMessage message = CreateInternalGetRunStepsRequest(threadId, runId, runInclude, limit, order, after, before, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Gets a list of run steps from a thread run. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The ID of the thread that was run. + /// The ID of the run to list steps from. + /// A list of additional fields to include in the response. + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. Allowed values: "asc" | "desc". + /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. + /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, starting with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual Response InternalGetRunSteps(string threadId, string runId, IEnumerable runInclude, int? limit, string order, string after, string before, RequestContext context) + { + Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); + Argument.AssertNotNullOrEmpty(runId, nameof(runId)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.InternalGetRunSteps"); + scope.Start(); + try + { + using HttpMessage message = CreateInternalGetRunStepsRequest(threadId, runId, runInclude, limit, order, after, before, context); + return _pipeline.ProcessMessage(message, context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Gets a list of previously uploaded files. + /// A value that, when provided, limits list results to files matching the corresponding purpose. + /// The cancellation token to use. + internal virtual async Task> InternalListFilesAsync(OpenAIFilePurpose? purpose = null, CancellationToken cancellationToken = default) + { + RequestContext context = FromCancellationToken(cancellationToken); + Response response = await InternalListFilesAsync(purpose?.ToString(), context).ConfigureAwait(false); + return Response.FromValue(InternalFileListResponse.FromResponse(response), response); + } + + /// Gets a list of previously uploaded files. + /// A value that, when provided, limits list results to files matching the corresponding purpose. + /// The cancellation token to use. + internal virtual Response InternalListFiles(OpenAIFilePurpose? purpose = null, CancellationToken cancellationToken = default) + { + RequestContext context = FromCancellationToken(cancellationToken); + Response response = InternalListFiles(purpose?.ToString(), context); + return Response.FromValue(InternalFileListResponse.FromResponse(response), response); + } + + /// + /// [Protocol Method] Gets a list of previously uploaded files. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// A value that, when provided, limits list results to files matching the corresponding purpose. Allowed values: "fine-tune" | "fine-tune-results" | "assistants" | "assistants_output" | "batch" | "batch_output" | "vision". + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual async Task InternalListFilesAsync(string purpose, RequestContext context) + { + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.InternalListFiles"); + scope.Start(); + try + { + using HttpMessage message = CreateInternalListFilesRequest(purpose, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Gets a list of previously uploaded files. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// A value that, when provided, limits list results to files matching the corresponding purpose. Allowed values: "fine-tune" | "fine-tune-results" | "assistants" | "assistants_output" | "batch" | "batch_output" | "vision". + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual Response InternalListFiles(string purpose, RequestContext context) + { + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.InternalListFiles"); + scope.Start(); + try + { + using HttpMessage message = CreateInternalListFilesRequest(purpose, context); + return _pipeline.ProcessMessage(message, context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Uploads a file for use by other operations. + /// The file data to upload and its purpose. + /// The cancellation token to use. + /// is null. + public virtual async Task> UploadFileAsync(UploadFileRequest file, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(file, nameof(file)); + + using MultipartFormDataRequestContent content = file.ToMultipartRequestContent(); + RequestContext context = FromCancellationToken(cancellationToken); + Response response = await UploadFileAsync(content, content.ContentType, context).ConfigureAwait(false); + return Response.FromValue(OpenAIFile.FromResponse(response), response); + } + + /// Uploads a file for use by other operations. + /// The file data to upload and its purpose. + /// The cancellation token to use. + /// is null. + public virtual Response UploadFile(UploadFileRequest file, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(file, nameof(file)); + + using MultipartFormDataRequestContent content = file.ToMultipartRequestContent(); + RequestContext context = FromCancellationToken(cancellationToken); + Response response = UploadFile(content, content.ContentType, context); + return Response.FromValue(OpenAIFile.FromResponse(response), response); + } + + /// + /// [Protocol Method] Uploads a file for use by other operations. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The 'content-type' header value, always 'multipart/format-data' for this operation. Allowed values: "multipart/form-data". + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual async Task UploadFileAsync(RequestContent content, string contentType, RequestContext context = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.UploadFile"); + scope.Start(); + try + { + using HttpMessage message = CreateUploadFileRequest(content, contentType, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] Uploads a file for use by other operations. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The 'content-type' header value, always 'multipart/format-data' for this operation. Allowed values: "multipart/form-data". + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + internal virtual Response UploadFile(RequestContent content, string contentType, RequestContext context = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.UploadFile"); + scope.Start(); + try + { + using HttpMessage message = CreateUploadFileRequest(content, contentType, context); + return _pipeline.ProcessMessage(message, context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// Delete a previously uploaded file. + /// The ID of the file to delete. + /// The cancellation token to use. + /// is null. + /// is an empty string, and was expected to be non-empty. + internal virtual async Task> InternalDeleteFileAsync(string fileId, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); + + RequestContext context = FromCancellationToken(cancellationToken); + Response response = await InternalDeleteFileAsync(fileId, context).ConfigureAwait(false); + return Response.FromValue(InternalFileDeletionStatus.FromResponse(response), response); + } + + /// Delete a previously uploaded file. + /// The ID of the file to delete. + /// The cancellation token to use. + /// is null. + /// is an empty string, and was expected to be non-empty. + internal virtual Response InternalDeleteFile(string fileId, CancellationToken cancellationToken = default) { - Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); + Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); RequestContext context = FromCancellationToken(cancellationToken); - Response response = InternalGetMessageFiles(threadId, messageId, limit, order?.ToString(), after, before, context); - return Response.FromValue(InternalOpenAIPageableListOfMessageFile.FromResponse(response), response); + Response response = InternalDeleteFile(fileId, context); + return Response.FromValue(InternalFileDeletionStatus.FromResponse(response), response); } /// - /// [Protocol Method] Gets a list of previously uploaded files associated with a message from a thread. + /// [Protocol Method] Delete a previously uploaded file. /// /// /// @@ -1895,32 +2627,26 @@ internal virtual Response InternalGetMe /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// /// - /// The ID of the thread containing the message to list files from. - /// The ID of the message to list files from. - /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. - /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. Allowed values: "asc" | "desc". - /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. - /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. + /// The ID of the file to delete. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. - /// or is null. - /// or is an empty string, and was expected to be non-empty. + /// is null. + /// is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual async Task InternalGetMessageFilesAsync(string threadId, string messageId, int? limit, string order, string after, string before, RequestContext context) + internal virtual async Task InternalDeleteFileAsync(string fileId, RequestContext context) { - Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); + Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.InternalGetMessageFiles"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.InternalDeleteFile"); scope.Start(); try { - using HttpMessage message = CreateInternalGetMessageFilesRequest(threadId, messageId, limit, order, after, before, context); + using HttpMessage message = CreateInternalDeleteFileRequest(fileId, context); return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); } catch (Exception e) @@ -1931,7 +2657,7 @@ internal virtual async Task InternalGetMessageFilesAsync(string thread } /// - /// [Protocol Method] Gets a list of previously uploaded files associated with a message from a thread. + /// [Protocol Method] Delete a previously uploaded file. /// /// /// @@ -1940,32 +2666,26 @@ internal virtual async Task InternalGetMessageFilesAsync(string thread /// /// /// - /// Please try the simpler convenience overload with strongly typed models first. + /// Please try the simpler convenience overload with strongly typed models first. /// /// /// /// - /// The ID of the thread containing the message to list files from. - /// The ID of the message to list files from. - /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. - /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. Allowed values: "asc" | "desc". - /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. - /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. + /// The ID of the file to delete. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. - /// or is null. - /// or is an empty string, and was expected to be non-empty. + /// is null. + /// is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual Response InternalGetMessageFiles(string threadId, string messageId, int? limit, string order, string after, string before, RequestContext context) + internal virtual Response InternalDeleteFile(string fileId, RequestContext context) { - Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); + Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.InternalGetMessageFiles"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.InternalDeleteFile"); scope.Start(); try { - using HttpMessage message = CreateInternalGetMessageFilesRequest(threadId, messageId, limit, order, after, before, context); + using HttpMessage message = CreateInternalDeleteFileRequest(fileId, context); return _pipeline.ProcessMessage(message, context); } catch (Exception e) @@ -1975,44 +2695,36 @@ internal virtual Response InternalGetMessageFiles(string threadId, string messag } } - /// Gets information about a file attachment to a message within a thread. - /// The ID of the thread containing the message to get information from. - /// The ID of the message to get information from. - /// The ID of the file to get information about. + /// Returns information about a specific file. Does not retrieve file content. + /// The ID of the file to retrieve. /// The cancellation token to use. - /// , or is null. - /// , or is an empty string, and was expected to be non-empty. - public virtual async Task> GetMessageFileAsync(string threadId, string messageId, string fileId, CancellationToken cancellationToken = default) + /// is null. + /// is an empty string, and was expected to be non-empty. + public virtual async Task> GetFileAsync(string fileId, CancellationToken cancellationToken = default) { - Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); RequestContext context = FromCancellationToken(cancellationToken); - Response response = await GetMessageFileAsync(threadId, messageId, fileId, context).ConfigureAwait(false); - return Response.FromValue(MessageFile.FromResponse(response), response); + Response response = await GetFileAsync(fileId, context).ConfigureAwait(false); + return Response.FromValue(OpenAIFile.FromResponse(response), response); } - /// Gets information about a file attachment to a message within a thread. - /// The ID of the thread containing the message to get information from. - /// The ID of the message to get information from. - /// The ID of the file to get information about. + /// Returns information about a specific file. Does not retrieve file content. + /// The ID of the file to retrieve. /// The cancellation token to use. - /// , or is null. - /// , or is an empty string, and was expected to be non-empty. - public virtual Response GetMessageFile(string threadId, string messageId, string fileId, CancellationToken cancellationToken = default) + /// is null. + /// is an empty string, and was expected to be non-empty. + public virtual Response GetFile(string fileId, CancellationToken cancellationToken = default) { - Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); RequestContext context = FromCancellationToken(cancellationToken); - Response response = GetMessageFile(threadId, messageId, fileId, context); - return Response.FromValue(MessageFile.FromResponse(response), response); + Response response = GetFile(fileId, context); + return Response.FromValue(OpenAIFile.FromResponse(response), response); } /// - /// [Protocol Method] Gets information about a file attachment to a message within a thread. + /// [Protocol Method] Returns information about a specific file. Does not retrieve file content. /// /// /// @@ -2021,25 +2733,21 @@ public virtual Response GetMessageFile(string threadId, string mess /// /// /// - /// The ID of the thread containing the message to get information from. - /// The ID of the message to get information from. - /// The ID of the file to get information about. + /// The ID of the file to retrieve. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. - /// , or is null. - /// , or is an empty string, and was expected to be non-empty. + /// is null. + /// is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual async Task GetMessageFileAsync(string threadId, string messageId, string fileId, RequestContext context) + internal virtual async Task GetFileAsync(string fileId, RequestContext context) { - Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.GetMessageFile"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.GetFile"); scope.Start(); try { - using HttpMessage message = CreateGetMessageFileRequest(threadId, messageId, fileId, context); + using HttpMessage message = CreateGetFileRequest(fileId, context); return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); } catch (Exception e) @@ -2050,7 +2758,7 @@ internal virtual async Task GetMessageFileAsync(string threadId, strin } /// - /// [Protocol Method] Gets information about a file attachment to a message within a thread. + /// [Protocol Method] Returns information about a specific file. Does not retrieve file content. /// /// /// @@ -2059,25 +2767,21 @@ internal virtual async Task GetMessageFileAsync(string threadId, strin /// /// /// - /// The ID of the thread containing the message to get information from. - /// The ID of the message to get information from. - /// The ID of the file to get information about. + /// The ID of the file to retrieve. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. - /// , or is null. - /// , or is an empty string, and was expected to be non-empty. + /// is null. + /// is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual Response GetMessageFile(string threadId, string messageId, string fileId, RequestContext context) + internal virtual Response GetFile(string fileId, RequestContext context) { - Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.GetMessageFile"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.GetFile"); scope.Start(); try { - using HttpMessage message = CreateGetMessageFileRequest(threadId, messageId, fileId, context); + using HttpMessage message = CreateGetFileRequest(fileId, context); return _pipeline.ProcessMessage(message, context); } catch (Exception e) @@ -2087,42 +2791,36 @@ internal virtual Response GetMessageFile(string threadId, string messageId, stri } } - /// Creates a new run for an assistant thread. - /// The ID of the thread to run. - /// The details for the run to create. + /// Returns information about a specific file. Does not retrieve file content. + /// The ID of the file to retrieve. /// The cancellation token to use. - /// or is null. - /// is an empty string, and was expected to be non-empty. - public virtual async Task> CreateRunAsync(string threadId, CreateRunOptions createRunOptions, CancellationToken cancellationToken = default) + /// is null. + /// is an empty string, and was expected to be non-empty. + public virtual async Task> GetFileContentAsync(string fileId, CancellationToken cancellationToken = default) { - Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - Argument.AssertNotNull(createRunOptions, nameof(createRunOptions)); + Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); - using RequestContent content = createRunOptions.ToRequestContent(); RequestContext context = FromCancellationToken(cancellationToken); - Response response = await CreateRunAsync(threadId, content, context).ConfigureAwait(false); - return Response.FromValue(ThreadRun.FromResponse(response), response); + Response response = await GetFileContentAsync(fileId, context).ConfigureAwait(false); + return Response.FromValue(response.Content, response); } - /// Creates a new run for an assistant thread. - /// The ID of the thread to run. - /// The details for the run to create. + /// Returns information about a specific file. Does not retrieve file content. + /// The ID of the file to retrieve. /// The cancellation token to use. - /// or is null. - /// is an empty string, and was expected to be non-empty. - public virtual Response CreateRun(string threadId, CreateRunOptions createRunOptions, CancellationToken cancellationToken = default) + /// is null. + /// is an empty string, and was expected to be non-empty. + public virtual Response GetFileContent(string fileId, CancellationToken cancellationToken = default) { - Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - Argument.AssertNotNull(createRunOptions, nameof(createRunOptions)); + Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); - using RequestContent content = createRunOptions.ToRequestContent(); RequestContext context = FromCancellationToken(cancellationToken); - Response response = CreateRun(threadId, content, context); - return Response.FromValue(ThreadRun.FromResponse(response), response); + Response response = GetFileContent(fileId, context); + return Response.FromValue(response.Content, response); } /// - /// [Protocol Method] Creates a new run for an assistant thread. + /// [Protocol Method] Returns information about a specific file. Does not retrieve file content. /// /// /// @@ -2131,23 +2829,21 @@ public virtual Response CreateRun(string threadId, CreateRunOptions c /// /// /// - /// The ID of the thread to run. - /// The content to send as the body of the request. + /// The ID of the file to retrieve. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. - /// or is null. - /// is an empty string, and was expected to be non-empty. + /// is null. + /// is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual async Task CreateRunAsync(string threadId, RequestContent content, RequestContext context = null) + internal virtual async Task GetFileContentAsync(string fileId, RequestContext context) { - Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - Argument.AssertNotNull(content, nameof(content)); + Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.CreateRun"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.GetFileContent"); scope.Start(); try { - using HttpMessage message = CreateCreateRunRequest(threadId, content, context); + using HttpMessage message = CreateGetFileContentRequest(fileId, context); return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); } catch (Exception e) @@ -2158,7 +2854,7 @@ internal virtual async Task CreateRunAsync(string threadId, RequestCon } /// - /// [Protocol Method] Creates a new run for an assistant thread. + /// [Protocol Method] Returns information about a specific file. Does not retrieve file content. /// /// /// @@ -2167,23 +2863,21 @@ internal virtual async Task CreateRunAsync(string threadId, RequestCon /// /// /// - /// The ID of the thread to run. - /// The content to send as the body of the request. + /// The ID of the file to retrieve. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. - /// or is null. - /// is an empty string, and was expected to be non-empty. + /// is null. + /// is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual Response CreateRun(string threadId, RequestContent content, RequestContext context = null) + internal virtual Response GetFileContent(string fileId, RequestContext context) { - Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - Argument.AssertNotNull(content, nameof(content)); + Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.CreateRun"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.GetFileContent"); scope.Start(); try { - using HttpMessage message = CreateCreateRunRequest(threadId, content, context); + using HttpMessage message = CreateGetFileContentRequest(fileId, context); return _pipeline.ProcessMessage(message, context); } catch (Exception e) @@ -2193,76 +2887,56 @@ internal virtual Response CreateRun(string threadId, RequestContent content, Req } } - /// Gets a list of runs for a specified thread. - /// The ID of the thread to list runs from. + /// Returns a list of vector stores. /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. - /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. + /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, starting with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. /// The cancellation token to use. - /// is null. - /// is an empty string, and was expected to be non-empty. - internal virtual async Task> InternalGetRunsAsync(string threadId, int? limit = null, ListSortOrder? order = null, string after = null, string before = null, CancellationToken cancellationToken = default) + public virtual async Task> GetVectorStoresAsync(int? limit = null, ListSortOrder? order = null, string after = null, string before = null, CancellationToken cancellationToken = default) { - Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - RequestContext context = FromCancellationToken(cancellationToken); - Response response = await InternalGetRunsAsync(threadId, limit, order?.ToString(), after, before, context).ConfigureAwait(false); - return Response.FromValue(InternalOpenAIPageableListOfThreadRun.FromResponse(response), response); + Response response = await GetVectorStoresAsync(limit, order?.ToString(), after, before, context).ConfigureAwait(false); + return Response.FromValue(OpenAIPageableListOfVectorStore.FromResponse(response), response); } - /// Gets a list of runs for a specified thread. - /// The ID of the thread to list runs from. + /// Returns a list of vector stores. /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. - /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. + /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, starting with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. /// The cancellation token to use. - /// is null. - /// is an empty string, and was expected to be non-empty. - internal virtual Response InternalGetRuns(string threadId, int? limit = null, ListSortOrder? order = null, string after = null, string before = null, CancellationToken cancellationToken = default) + public virtual Response GetVectorStores(int? limit = null, ListSortOrder? order = null, string after = null, string before = null, CancellationToken cancellationToken = default) { - Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - RequestContext context = FromCancellationToken(cancellationToken); - Response response = InternalGetRuns(threadId, limit, order?.ToString(), after, before, context); - return Response.FromValue(InternalOpenAIPageableListOfThreadRun.FromResponse(response), response); + Response response = GetVectorStores(limit, order?.ToString(), after, before, context); + return Response.FromValue(OpenAIPageableListOfVectorStore.FromResponse(response), response); } /// - /// [Protocol Method] Gets a list of runs for a specified thread. + /// [Protocol Method] Returns a list of vector stores. /// /// /// /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. /// /// - /// - /// - /// Please try the simpler convenience overload with strongly typed models first. - /// - /// /// /// - /// The ID of the thread to list runs from. /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. Allowed values: "asc" | "desc". /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. - /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. + /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, starting with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. - /// is null. - /// is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual async Task InternalGetRunsAsync(string threadId, int? limit, string order, string after, string before, RequestContext context) + internal virtual async Task GetVectorStoresAsync(int? limit, string order, string after, string before, RequestContext context) { - Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.InternalGetRuns"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.GetVectorStores"); scope.Start(); try { - using HttpMessage message = CreateInternalGetRunsRequest(threadId, limit, order, after, before, context); + using HttpMessage message = CreateGetVectorStoresRequest(limit, order, after, before, context); return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); } catch (Exception e) @@ -2273,39 +2947,29 @@ internal virtual async Task InternalGetRunsAsync(string threadId, int? } /// - /// [Protocol Method] Gets a list of runs for a specified thread. + /// [Protocol Method] Returns a list of vector stores. /// /// /// /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. /// /// - /// - /// - /// Please try the simpler convenience overload with strongly typed models first. - /// - /// /// /// - /// The ID of the thread to list runs from. /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. Allowed values: "asc" | "desc". /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. - /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. + /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, starting with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. - /// is null. - /// is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual Response InternalGetRuns(string threadId, int? limit, string order, string after, string before, RequestContext context) + internal virtual Response GetVectorStores(int? limit, string order, string after, string before, RequestContext context) { - Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.InternalGetRuns"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.GetVectorStores"); scope.Start(); try { - using HttpMessage message = CreateInternalGetRunsRequest(threadId, limit, order, after, before, context); + using HttpMessage message = CreateGetVectorStoresRequest(limit, order, after, before, context); return _pipeline.ProcessMessage(message, context); } catch (Exception e) @@ -2315,40 +2979,36 @@ internal virtual Response InternalGetRuns(string threadId, int? limit, string or } } - /// Gets an existing run from an existing thread. - /// The ID of the thread to retrieve run information from. - /// The ID of the thread to retrieve information about. + /// Creates a vector store. + /// Request object for creating a vector store. /// The cancellation token to use. - /// or is null. - /// or is an empty string, and was expected to be non-empty. - public virtual async Task> GetRunAsync(string threadId, string runId, CancellationToken cancellationToken = default) + /// is null. + public virtual async Task> CreateVectorStoreAsync(VectorStoreOptions body, CancellationToken cancellationToken = default) { - Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - Argument.AssertNotNullOrEmpty(runId, nameof(runId)); + Argument.AssertNotNull(body, nameof(body)); + using RequestContent content = body.ToRequestContent(); RequestContext context = FromCancellationToken(cancellationToken); - Response response = await GetRunAsync(threadId, runId, context).ConfigureAwait(false); - return Response.FromValue(ThreadRun.FromResponse(response), response); + Response response = await CreateVectorStoreAsync(content, context).ConfigureAwait(false); + return Response.FromValue(VectorStore.FromResponse(response), response); } - /// Gets an existing run from an existing thread. - /// The ID of the thread to retrieve run information from. - /// The ID of the thread to retrieve information about. + /// Creates a vector store. + /// Request object for creating a vector store. /// The cancellation token to use. - /// or is null. - /// or is an empty string, and was expected to be non-empty. - public virtual Response GetRun(string threadId, string runId, CancellationToken cancellationToken = default) + /// is null. + public virtual Response CreateVectorStore(VectorStoreOptions body, CancellationToken cancellationToken = default) { - Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - Argument.AssertNotNullOrEmpty(runId, nameof(runId)); + Argument.AssertNotNull(body, nameof(body)); + using RequestContent content = body.ToRequestContent(); RequestContext context = FromCancellationToken(cancellationToken); - Response response = GetRun(threadId, runId, context); - return Response.FromValue(ThreadRun.FromResponse(response), response); + Response response = CreateVectorStore(content, context); + return Response.FromValue(VectorStore.FromResponse(response), response); } /// - /// [Protocol Method] Gets an existing run from an existing thread. + /// [Protocol Method] Creates a vector store. /// /// /// @@ -2357,23 +3017,20 @@ public virtual Response GetRun(string threadId, string runId, Cancell /// /// /// - /// The ID of the thread to retrieve run information from. - /// The ID of the thread to retrieve information about. + /// The content to send as the body of the request. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. - /// or is null. - /// or is an empty string, and was expected to be non-empty. + /// is null. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual async Task GetRunAsync(string threadId, string runId, RequestContext context) + internal virtual async Task CreateVectorStoreAsync(RequestContent content, RequestContext context = null) { - Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - Argument.AssertNotNullOrEmpty(runId, nameof(runId)); + Argument.AssertNotNull(content, nameof(content)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.GetRun"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.CreateVectorStore"); scope.Start(); try { - using HttpMessage message = CreateGetRunRequest(threadId, runId, context); + using HttpMessage message = CreateCreateVectorStoreRequest(content, context); return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); } catch (Exception e) @@ -2384,7 +3041,7 @@ internal virtual async Task GetRunAsync(string threadId, string runId, } /// - /// [Protocol Method] Gets an existing run from an existing thread. + /// [Protocol Method] Creates a vector store. /// /// /// @@ -2393,23 +3050,20 @@ internal virtual async Task GetRunAsync(string threadId, string runId, /// /// /// - /// The ID of the thread to retrieve run information from. - /// The ID of the thread to retrieve information about. + /// The content to send as the body of the request. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. - /// or is null. - /// or is an empty string, and was expected to be non-empty. + /// is null. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual Response GetRun(string threadId, string runId, RequestContext context) + internal virtual Response CreateVectorStore(RequestContent content, RequestContext context = null) { - Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - Argument.AssertNotNullOrEmpty(runId, nameof(runId)); + Argument.AssertNotNull(content, nameof(content)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.GetRun"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.CreateVectorStore"); scope.Start(); try { - using HttpMessage message = CreateGetRunRequest(threadId, runId, context); + using HttpMessage message = CreateCreateVectorStoreRequest(content, context); return _pipeline.ProcessMessage(message, context); } catch (Exception e) @@ -2419,44 +3073,36 @@ internal virtual Response GetRun(string threadId, string runId, RequestContext c } } - /// Modifies an existing thread run. - /// The ID of the thread associated with the specified run. - /// The ID of the run to modify. - /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + /// Returns the vector store object matching the specified ID. + /// The ID of the vector store to retrieve. /// The cancellation token to use. - /// or is null. - /// or is an empty string, and was expected to be non-empty. - public virtual async Task> UpdateRunAsync(string threadId, string runId, IReadOnlyDictionary metadata = null, CancellationToken cancellationToken = default) + /// is null. + /// is an empty string, and was expected to be non-empty. + public virtual async Task> GetVectorStoreAsync(string vectorStoreId, CancellationToken cancellationToken = default) { - Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - Argument.AssertNotNullOrEmpty(runId, nameof(runId)); + Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); - UpdateRunRequest updateRunRequest = new UpdateRunRequest(metadata ?? new ChangeTrackingDictionary(), null); RequestContext context = FromCancellationToken(cancellationToken); - Response response = await UpdateRunAsync(threadId, runId, updateRunRequest.ToRequestContent(), context).ConfigureAwait(false); - return Response.FromValue(ThreadRun.FromResponse(response), response); + Response response = await GetVectorStoreAsync(vectorStoreId, context).ConfigureAwait(false); + return Response.FromValue(VectorStore.FromResponse(response), response); } - /// Modifies an existing thread run. - /// The ID of the thread associated with the specified run. - /// The ID of the run to modify. - /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + /// Returns the vector store object matching the specified ID. + /// The ID of the vector store to retrieve. /// The cancellation token to use. - /// or is null. - /// or is an empty string, and was expected to be non-empty. - public virtual Response UpdateRun(string threadId, string runId, IReadOnlyDictionary metadata = null, CancellationToken cancellationToken = default) + /// is null. + /// is an empty string, and was expected to be non-empty. + public virtual Response GetVectorStore(string vectorStoreId, CancellationToken cancellationToken = default) { - Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - Argument.AssertNotNullOrEmpty(runId, nameof(runId)); + Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); - UpdateRunRequest updateRunRequest = new UpdateRunRequest(metadata ?? new ChangeTrackingDictionary(), null); RequestContext context = FromCancellationToken(cancellationToken); - Response response = UpdateRun(threadId, runId, updateRunRequest.ToRequestContent(), context); - return Response.FromValue(ThreadRun.FromResponse(response), response); + Response response = GetVectorStore(vectorStoreId, context); + return Response.FromValue(VectorStore.FromResponse(response), response); } /// - /// [Protocol Method] Modifies an existing thread run. + /// [Protocol Method] Returns the vector store object matching the specified ID. /// /// /// @@ -2465,25 +3111,21 @@ public virtual Response UpdateRun(string threadId, string runId, IRea /// /// /// - /// The ID of the thread associated with the specified run. - /// The ID of the run to modify. - /// The content to send as the body of the request. + /// The ID of the vector store to retrieve. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. - /// , or is null. - /// or is an empty string, and was expected to be non-empty. + /// is null. + /// is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual async Task UpdateRunAsync(string threadId, string runId, RequestContent content, RequestContext context = null) + internal virtual async Task GetVectorStoreAsync(string vectorStoreId, RequestContext context) { - Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - Argument.AssertNotNullOrEmpty(runId, nameof(runId)); - Argument.AssertNotNull(content, nameof(content)); + Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.UpdateRun"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.GetVectorStore"); scope.Start(); try { - using HttpMessage message = CreateUpdateRunRequest(threadId, runId, content, context); + using HttpMessage message = CreateGetVectorStoreRequest(vectorStoreId, context); return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); } catch (Exception e) @@ -2494,7 +3136,7 @@ internal virtual async Task UpdateRunAsync(string threadId, string run } /// - /// [Protocol Method] Modifies an existing thread run. + /// [Protocol Method] Returns the vector store object matching the specified ID. /// /// /// @@ -2503,25 +3145,21 @@ internal virtual async Task UpdateRunAsync(string threadId, string run /// /// /// - /// The ID of the thread associated with the specified run. - /// The ID of the run to modify. - /// The content to send as the body of the request. + /// The ID of the vector store to retrieve. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. - /// , or is null. - /// or is an empty string, and was expected to be non-empty. + /// is null. + /// is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual Response UpdateRun(string threadId, string runId, RequestContent content, RequestContext context = null) + internal virtual Response GetVectorStore(string vectorStoreId, RequestContext context) { - Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - Argument.AssertNotNullOrEmpty(runId, nameof(runId)); - Argument.AssertNotNull(content, nameof(content)); + Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.UpdateRun"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.GetVectorStore"); scope.Start(); try { - using HttpMessage message = CreateUpdateRunRequest(threadId, runId, content, context); + using HttpMessage message = CreateGetVectorStoreRequest(vectorStoreId, context); return _pipeline.ProcessMessage(message, context); } catch (Exception e) @@ -2531,46 +3169,42 @@ internal virtual Response UpdateRun(string threadId, string runId, RequestConten } } - /// Submits outputs from tools as requested by tool calls in a run. Runs that need submitted tool outputs will have a status of 'requires_action' with a required_action.type of 'submit_tool_outputs'. - /// The ID of the thread that was run. - /// The ID of the run that requires tool outputs. - /// The list of tool outputs requested by tool calls from the specified run. + /// The ID of the vector store to modify. + /// The ID of the vector store to modify. + /// Request object for updating a vector store. /// The cancellation token to use. - /// , or is null. - /// or is an empty string, and was expected to be non-empty. - public virtual async Task> SubmitToolOutputsToRunAsync(string threadId, string runId, IEnumerable toolOutputs, CancellationToken cancellationToken = default) + /// or is null. + /// is an empty string, and was expected to be non-empty. + public virtual async Task> ModifyVectorStoreAsync(string vectorStoreId, VectorStoreUpdateOptions body, CancellationToken cancellationToken = default) { - Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - Argument.AssertNotNullOrEmpty(runId, nameof(runId)); - Argument.AssertNotNull(toolOutputs, nameof(toolOutputs)); + Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); + Argument.AssertNotNull(body, nameof(body)); - SubmitToolOutputsToRunRequest submitToolOutputsToRunRequest = new SubmitToolOutputsToRunRequest(toolOutputs.ToList(), null); + using RequestContent content = body.ToRequestContent(); RequestContext context = FromCancellationToken(cancellationToken); - Response response = await SubmitToolOutputsToRunAsync(threadId, runId, submitToolOutputsToRunRequest.ToRequestContent(), context).ConfigureAwait(false); - return Response.FromValue(ThreadRun.FromResponse(response), response); + Response response = await ModifyVectorStoreAsync(vectorStoreId, content, context).ConfigureAwait(false); + return Response.FromValue(VectorStore.FromResponse(response), response); } - /// Submits outputs from tools as requested by tool calls in a run. Runs that need submitted tool outputs will have a status of 'requires_action' with a required_action.type of 'submit_tool_outputs'. - /// The ID of the thread that was run. - /// The ID of the run that requires tool outputs. - /// The list of tool outputs requested by tool calls from the specified run. + /// The ID of the vector store to modify. + /// The ID of the vector store to modify. + /// Request object for updating a vector store. /// The cancellation token to use. - /// , or is null. - /// or is an empty string, and was expected to be non-empty. - public virtual Response SubmitToolOutputsToRun(string threadId, string runId, IEnumerable toolOutputs, CancellationToken cancellationToken = default) + /// or is null. + /// is an empty string, and was expected to be non-empty. + public virtual Response ModifyVectorStore(string vectorStoreId, VectorStoreUpdateOptions body, CancellationToken cancellationToken = default) { - Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - Argument.AssertNotNullOrEmpty(runId, nameof(runId)); - Argument.AssertNotNull(toolOutputs, nameof(toolOutputs)); + Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); + Argument.AssertNotNull(body, nameof(body)); - SubmitToolOutputsToRunRequest submitToolOutputsToRunRequest = new SubmitToolOutputsToRunRequest(toolOutputs.ToList(), null); + using RequestContent content = body.ToRequestContent(); RequestContext context = FromCancellationToken(cancellationToken); - Response response = SubmitToolOutputsToRun(threadId, runId, submitToolOutputsToRunRequest.ToRequestContent(), context); - return Response.FromValue(ThreadRun.FromResponse(response), response); + Response response = ModifyVectorStore(vectorStoreId, content, context); + return Response.FromValue(VectorStore.FromResponse(response), response); } /// - /// [Protocol Method] Submits outputs from tools as requested by tool calls in a run. Runs that need submitted tool outputs will have a status of 'requires_action' with a required_action.type of 'submit_tool_outputs'. + /// [Protocol Method] The ID of the vector store to modify. /// /// /// @@ -2579,25 +3213,23 @@ public virtual Response SubmitToolOutputsToRun(string threadId, strin /// /// /// - /// The ID of the thread that was run. - /// The ID of the run that requires tool outputs. + /// The ID of the vector store to modify. /// The content to send as the body of the request. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. - /// , or is null. - /// or is an empty string, and was expected to be non-empty. + /// or is null. + /// is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual async Task SubmitToolOutputsToRunAsync(string threadId, string runId, RequestContent content, RequestContext context = null) + internal virtual async Task ModifyVectorStoreAsync(string vectorStoreId, RequestContent content, RequestContext context = null) { - Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - Argument.AssertNotNullOrEmpty(runId, nameof(runId)); + Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); Argument.AssertNotNull(content, nameof(content)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.SubmitToolOutputsToRun"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.ModifyVectorStore"); scope.Start(); try { - using HttpMessage message = CreateSubmitToolOutputsToRunRequest(threadId, runId, content, context); + using HttpMessage message = CreateModifyVectorStoreRequest(vectorStoreId, content, context); return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); } catch (Exception e) @@ -2608,7 +3240,7 @@ internal virtual async Task SubmitToolOutputsToRunAsync(string threadI } /// - /// [Protocol Method] Submits outputs from tools as requested by tool calls in a run. Runs that need submitted tool outputs will have a status of 'requires_action' with a required_action.type of 'submit_tool_outputs'. + /// [Protocol Method] The ID of the vector store to modify. /// /// /// @@ -2617,25 +3249,23 @@ internal virtual async Task SubmitToolOutputsToRunAsync(string threadI /// /// /// - /// The ID of the thread that was run. - /// The ID of the run that requires tool outputs. + /// The ID of the vector store to modify. /// The content to send as the body of the request. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. - /// , or is null. - /// or is an empty string, and was expected to be non-empty. + /// or is null. + /// is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual Response SubmitToolOutputsToRun(string threadId, string runId, RequestContent content, RequestContext context = null) + internal virtual Response ModifyVectorStore(string vectorStoreId, RequestContent content, RequestContext context = null) { - Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - Argument.AssertNotNullOrEmpty(runId, nameof(runId)); + Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); Argument.AssertNotNull(content, nameof(content)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.SubmitToolOutputsToRun"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.ModifyVectorStore"); scope.Start(); try { - using HttpMessage message = CreateSubmitToolOutputsToRunRequest(threadId, runId, content, context); + using HttpMessage message = CreateModifyVectorStoreRequest(vectorStoreId, content, context); return _pipeline.ProcessMessage(message, context); } catch (Exception e) @@ -2645,40 +3275,36 @@ internal virtual Response SubmitToolOutputsToRun(string threadId, string runId, } } - /// Cancels a run of an in progress thread. - /// The ID of the thread being run. - /// The ID of the run to cancel. + /// Deletes the vector store object matching the specified ID. + /// The ID of the vector store to delete. /// The cancellation token to use. - /// or is null. - /// or is an empty string, and was expected to be non-empty. - public virtual async Task> CancelRunAsync(string threadId, string runId, CancellationToken cancellationToken = default) + /// is null. + /// is an empty string, and was expected to be non-empty. + public virtual async Task> DeleteVectorStoreAsync(string vectorStoreId, CancellationToken cancellationToken = default) { - Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - Argument.AssertNotNullOrEmpty(runId, nameof(runId)); + Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); RequestContext context = FromCancellationToken(cancellationToken); - Response response = await CancelRunAsync(threadId, runId, context).ConfigureAwait(false); - return Response.FromValue(ThreadRun.FromResponse(response), response); + Response response = await DeleteVectorStoreAsync(vectorStoreId, context).ConfigureAwait(false); + return Response.FromValue(VectorStoreDeletionStatus.FromResponse(response), response); } - /// Cancels a run of an in progress thread. - /// The ID of the thread being run. - /// The ID of the run to cancel. + /// Deletes the vector store object matching the specified ID. + /// The ID of the vector store to delete. /// The cancellation token to use. - /// or is null. - /// or is an empty string, and was expected to be non-empty. - public virtual Response CancelRun(string threadId, string runId, CancellationToken cancellationToken = default) + /// is null. + /// is an empty string, and was expected to be non-empty. + public virtual Response DeleteVectorStore(string vectorStoreId, CancellationToken cancellationToken = default) { - Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - Argument.AssertNotNullOrEmpty(runId, nameof(runId)); + Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); RequestContext context = FromCancellationToken(cancellationToken); - Response response = CancelRun(threadId, runId, context); - return Response.FromValue(ThreadRun.FromResponse(response), response); + Response response = DeleteVectorStore(vectorStoreId, context); + return Response.FromValue(VectorStoreDeletionStatus.FromResponse(response), response); } /// - /// [Protocol Method] Cancels a run of an in progress thread. + /// [Protocol Method] Deletes the vector store object matching the specified ID. /// /// /// @@ -2687,23 +3313,21 @@ public virtual Response CancelRun(string threadId, string runId, Canc /// /// /// - /// The ID of the thread being run. - /// The ID of the run to cancel. + /// The ID of the vector store to delete. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. - /// or is null. - /// or is an empty string, and was expected to be non-empty. + /// is null. + /// is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual async Task CancelRunAsync(string threadId, string runId, RequestContext context) + internal virtual async Task DeleteVectorStoreAsync(string vectorStoreId, RequestContext context) { - Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - Argument.AssertNotNullOrEmpty(runId, nameof(runId)); + Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.CancelRun"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.DeleteVectorStore"); scope.Start(); try { - using HttpMessage message = CreateCancelRunRequest(threadId, runId, context); + using HttpMessage message = CreateDeleteVectorStoreRequest(vectorStoreId, context); return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); } catch (Exception e) @@ -2714,7 +3338,7 @@ internal virtual async Task CancelRunAsync(string threadId, string run } /// - /// [Protocol Method] Cancels a run of an in progress thread. + /// [Protocol Method] Deletes the vector store object matching the specified ID. /// /// /// @@ -2723,23 +3347,21 @@ internal virtual async Task CancelRunAsync(string threadId, string run /// /// /// - /// The ID of the thread being run. - /// The ID of the run to cancel. + /// The ID of the vector store to delete. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. - /// or is null. - /// or is an empty string, and was expected to be non-empty. + /// is null. + /// is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual Response CancelRun(string threadId, string runId, RequestContext context) + internal virtual Response DeleteVectorStore(string vectorStoreId, RequestContext context) { - Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - Argument.AssertNotNullOrEmpty(runId, nameof(runId)); + Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.CancelRun"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.DeleteVectorStore"); scope.Start(); try { - using HttpMessage message = CreateCancelRunRequest(threadId, runId, context); + using HttpMessage message = CreateDeleteVectorStoreRequest(vectorStoreId, context); return _pipeline.ProcessMessage(message, context); } catch (Exception e) @@ -2749,36 +3371,46 @@ internal virtual Response CancelRun(string threadId, string runId, RequestContex } } - /// Creates a new assistant thread and immediately starts a run using that new thread. - /// Body parameter. + /// Returns a list of vector store files. + /// The ID of the vector store that the files belong to. + /// Filter by file status. + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. + /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. + /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, starting with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. /// The cancellation token to use. - /// is null. - public virtual async Task> CreateThreadAndRunAsync(CreateAndRunThreadOptions body, CancellationToken cancellationToken = default) + /// is null. + /// is an empty string, and was expected to be non-empty. + public virtual async Task> GetVectorStoreFilesAsync(string vectorStoreId, VectorStoreFileStatusFilter? filter = null, int? limit = null, ListSortOrder? order = null, string after = null, string before = null, CancellationToken cancellationToken = default) { - Argument.AssertNotNull(body, nameof(body)); + Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); - using RequestContent content = body.ToRequestContent(); RequestContext context = FromCancellationToken(cancellationToken); - Response response = await CreateThreadAndRunAsync(content, context).ConfigureAwait(false); - return Response.FromValue(ThreadRun.FromResponse(response), response); + Response response = await GetVectorStoreFilesAsync(vectorStoreId, filter?.ToString(), limit, order?.ToString(), after, before, context).ConfigureAwait(false); + return Response.FromValue(OpenAIPageableListOfVectorStoreFile.FromResponse(response), response); } - /// Creates a new assistant thread and immediately starts a run using that new thread. - /// Body parameter. + /// Returns a list of vector store files. + /// The ID of the vector store that the files belong to. + /// Filter by file status. + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. + /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. + /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, starting with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. /// The cancellation token to use. - /// is null. - public virtual Response CreateThreadAndRun(CreateAndRunThreadOptions body, CancellationToken cancellationToken = default) + /// is null. + /// is an empty string, and was expected to be non-empty. + public virtual Response GetVectorStoreFiles(string vectorStoreId, VectorStoreFileStatusFilter? filter = null, int? limit = null, ListSortOrder? order = null, string after = null, string before = null, CancellationToken cancellationToken = default) { - Argument.AssertNotNull(body, nameof(body)); + Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); - using RequestContent content = body.ToRequestContent(); RequestContext context = FromCancellationToken(cancellationToken); - Response response = CreateThreadAndRun(content, context); - return Response.FromValue(ThreadRun.FromResponse(response), response); + Response response = GetVectorStoreFiles(vectorStoreId, filter?.ToString(), limit, order?.ToString(), after, before, context); + return Response.FromValue(OpenAIPageableListOfVectorStoreFile.FromResponse(response), response); } /// - /// [Protocol Method] Creates a new assistant thread and immediately starts a run using that new thread. + /// [Protocol Method] Returns a list of vector store files. /// /// /// @@ -2787,20 +3419,26 @@ public virtual Response CreateThreadAndRun(CreateAndRunThreadOptions /// /// /// - /// The content to send as the body of the request. + /// The ID of the vector store that the files belong to. + /// Filter by file status. Allowed values: "in_progress" | "completed" | "failed" | "cancelled". + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. Allowed values: "asc" | "desc". + /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. + /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, starting with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. - /// is null. + /// is null. + /// is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual async Task CreateThreadAndRunAsync(RequestContent content, RequestContext context = null) + internal virtual async Task GetVectorStoreFilesAsync(string vectorStoreId, string filter, int? limit, string order, string after, string before, RequestContext context) { - Argument.AssertNotNull(content, nameof(content)); + Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.CreateThreadAndRun"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.GetVectorStoreFiles"); scope.Start(); try { - using HttpMessage message = CreateCreateThreadAndRunRequest(content, context); + using HttpMessage message = CreateGetVectorStoreFilesRequest(vectorStoreId, filter, limit, order, after, before, context); return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); } catch (Exception e) @@ -2811,7 +3449,7 @@ internal virtual async Task CreateThreadAndRunAsync(RequestContent con } /// - /// [Protocol Method] Creates a new assistant thread and immediately starts a run using that new thread. + /// [Protocol Method] Returns a list of vector store files. /// /// /// @@ -2820,20 +3458,26 @@ internal virtual async Task CreateThreadAndRunAsync(RequestContent con /// /// /// - /// The content to send as the body of the request. + /// The ID of the vector store that the files belong to. + /// Filter by file status. Allowed values: "in_progress" | "completed" | "failed" | "cancelled". + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. Allowed values: "asc" | "desc". + /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. + /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, starting with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. - /// is null. + /// is null. + /// is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual Response CreateThreadAndRun(RequestContent content, RequestContext context = null) + internal virtual Response GetVectorStoreFiles(string vectorStoreId, string filter, int? limit, string order, string after, string before, RequestContext context) { - Argument.AssertNotNull(content, nameof(content)); + Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.CreateThreadAndRun"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.GetVectorStoreFiles"); scope.Start(); try { - using HttpMessage message = CreateCreateThreadAndRunRequest(content, context); + using HttpMessage message = CreateGetVectorStoreFilesRequest(vectorStoreId, filter, limit, order, after, before, context); return _pipeline.ProcessMessage(message, context); } catch (Exception e) @@ -2843,44 +3487,44 @@ internal virtual Response CreateThreadAndRun(RequestContent content, RequestCont } } - /// Gets a single run step from a thread run. - /// The ID of the thread that was run. - /// The ID of the specific run to retrieve the step from. - /// The ID of the step to retrieve information about. + /// Create a vector store file by attaching a file to a vector store. + /// The ID of the vector store for which to create a File. + /// A File ID that the vector store should use. Useful for tools like `file_search` that can access files. + /// The chunking strategy used to chunk the file(s). If not set, will use the auto strategy. /// The cancellation token to use. - /// , or is null. - /// , or is an empty string, and was expected to be non-empty. - public virtual async Task> GetRunStepAsync(string threadId, string runId, string stepId, CancellationToken cancellationToken = default) + /// or is null. + /// is an empty string, and was expected to be non-empty. + public virtual async Task> CreateVectorStoreFileAsync(string vectorStoreId, string fileId, VectorStoreChunkingStrategyRequest chunkingStrategy = null, CancellationToken cancellationToken = default) { - Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - Argument.AssertNotNullOrEmpty(runId, nameof(runId)); - Argument.AssertNotNullOrEmpty(stepId, nameof(stepId)); + Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); + Argument.AssertNotNull(fileId, nameof(fileId)); + CreateVectorStoreFileRequest createVectorStoreFileRequest = new CreateVectorStoreFileRequest(fileId, chunkingStrategy, null); RequestContext context = FromCancellationToken(cancellationToken); - Response response = await GetRunStepAsync(threadId, runId, stepId, context).ConfigureAwait(false); - return Response.FromValue(RunStep.FromResponse(response), response); + Response response = await CreateVectorStoreFileAsync(vectorStoreId, createVectorStoreFileRequest.ToRequestContent(), context).ConfigureAwait(false); + return Response.FromValue(VectorStoreFile.FromResponse(response), response); } - /// Gets a single run step from a thread run. - /// The ID of the thread that was run. - /// The ID of the specific run to retrieve the step from. - /// The ID of the step to retrieve information about. + /// Create a vector store file by attaching a file to a vector store. + /// The ID of the vector store for which to create a File. + /// A File ID that the vector store should use. Useful for tools like `file_search` that can access files. + /// The chunking strategy used to chunk the file(s). If not set, will use the auto strategy. /// The cancellation token to use. - /// , or is null. - /// , or is an empty string, and was expected to be non-empty. - public virtual Response GetRunStep(string threadId, string runId, string stepId, CancellationToken cancellationToken = default) + /// or is null. + /// is an empty string, and was expected to be non-empty. + public virtual Response CreateVectorStoreFile(string vectorStoreId, string fileId, VectorStoreChunkingStrategyRequest chunkingStrategy = null, CancellationToken cancellationToken = default) { - Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - Argument.AssertNotNullOrEmpty(runId, nameof(runId)); - Argument.AssertNotNullOrEmpty(stepId, nameof(stepId)); + Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); + Argument.AssertNotNull(fileId, nameof(fileId)); + CreateVectorStoreFileRequest createVectorStoreFileRequest = new CreateVectorStoreFileRequest(fileId, chunkingStrategy, null); RequestContext context = FromCancellationToken(cancellationToken); - Response response = GetRunStep(threadId, runId, stepId, context); - return Response.FromValue(RunStep.FromResponse(response), response); + Response response = CreateVectorStoreFile(vectorStoreId, createVectorStoreFileRequest.ToRequestContent(), context); + return Response.FromValue(VectorStoreFile.FromResponse(response), response); } /// - /// [Protocol Method] Gets a single run step from a thread run. + /// [Protocol Method] Create a vector store file by attaching a file to a vector store. /// /// /// @@ -2889,25 +3533,23 @@ public virtual Response GetRunStep(string threadId, string runId, strin /// /// /// - /// The ID of the thread that was run. - /// The ID of the specific run to retrieve the step from. - /// The ID of the step to retrieve information about. + /// The ID of the vector store for which to create a File. + /// The content to send as the body of the request. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. - /// , or is null. - /// , or is an empty string, and was expected to be non-empty. + /// or is null. + /// is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual async Task GetRunStepAsync(string threadId, string runId, string stepId, RequestContext context) + internal virtual async Task CreateVectorStoreFileAsync(string vectorStoreId, RequestContent content, RequestContext context = null) { - Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - Argument.AssertNotNullOrEmpty(runId, nameof(runId)); - Argument.AssertNotNullOrEmpty(stepId, nameof(stepId)); + Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); + Argument.AssertNotNull(content, nameof(content)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.GetRunStep"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.CreateVectorStoreFile"); scope.Start(); try { - using HttpMessage message = CreateGetRunStepRequest(threadId, runId, stepId, context); + using HttpMessage message = CreateCreateVectorStoreFileRequest(vectorStoreId, content, context); return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); } catch (Exception e) @@ -2918,7 +3560,7 @@ internal virtual async Task GetRunStepAsync(string threadId, string ru } /// - /// [Protocol Method] Gets a single run step from a thread run. + /// [Protocol Method] Create a vector store file by attaching a file to a vector store. /// /// /// @@ -2927,25 +3569,23 @@ internal virtual async Task GetRunStepAsync(string threadId, string ru /// /// /// - /// The ID of the thread that was run. - /// The ID of the specific run to retrieve the step from. - /// The ID of the step to retrieve information about. + /// The ID of the vector store for which to create a File. + /// The content to send as the body of the request. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. - /// , or is null. - /// , or is an empty string, and was expected to be non-empty. + /// or is null. + /// is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual Response GetRunStep(string threadId, string runId, string stepId, RequestContext context) + internal virtual Response CreateVectorStoreFile(string vectorStoreId, RequestContent content, RequestContext context = null) { - Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - Argument.AssertNotNullOrEmpty(runId, nameof(runId)); - Argument.AssertNotNullOrEmpty(stepId, nameof(stepId)); + Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); + Argument.AssertNotNull(content, nameof(content)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.GetRunStep"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.CreateVectorStoreFile"); scope.Start(); try { - using HttpMessage message = CreateGetRunStepRequest(threadId, runId, stepId, context); + using HttpMessage message = CreateCreateVectorStoreFileRequest(vectorStoreId, content, context); return _pipeline.ProcessMessage(message, context); } catch (Exception e) @@ -2955,82 +3595,65 @@ internal virtual Response GetRunStep(string threadId, string runId, string stepI } } - /// Gets a list of run steps from a thread run. - /// The ID of the thread that was run. - /// The ID of the run to list steps from. - /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. - /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. - /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. - /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. + /// Retrieves a vector store file. + /// The ID of the vector store that the file belongs to. + /// The ID of the file being retrieved. /// The cancellation token to use. - /// or is null. - /// or is an empty string, and was expected to be non-empty. - internal virtual async Task> InternalGetRunStepsAsync(string threadId, string runId, int? limit = null, ListSortOrder? order = null, string after = null, string before = null, CancellationToken cancellationToken = default) + /// or is null. + /// or is an empty string, and was expected to be non-empty. + public virtual async Task> GetVectorStoreFileAsync(string vectorStoreId, string fileId, CancellationToken cancellationToken = default) { - Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - Argument.AssertNotNullOrEmpty(runId, nameof(runId)); + Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); + Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); RequestContext context = FromCancellationToken(cancellationToken); - Response response = await InternalGetRunStepsAsync(threadId, runId, limit, order?.ToString(), after, before, context).ConfigureAwait(false); - return Response.FromValue(InternalOpenAIPageableListOfRunStep.FromResponse(response), response); + Response response = await GetVectorStoreFileAsync(vectorStoreId, fileId, context).ConfigureAwait(false); + return Response.FromValue(VectorStoreFile.FromResponse(response), response); } - /// Gets a list of run steps from a thread run. - /// The ID of the thread that was run. - /// The ID of the run to list steps from. - /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. - /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. - /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. - /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. + /// Retrieves a vector store file. + /// The ID of the vector store that the file belongs to. + /// The ID of the file being retrieved. /// The cancellation token to use. - /// or is null. - /// or is an empty string, and was expected to be non-empty. - internal virtual Response InternalGetRunSteps(string threadId, string runId, int? limit = null, ListSortOrder? order = null, string after = null, string before = null, CancellationToken cancellationToken = default) + /// or is null. + /// or is an empty string, and was expected to be non-empty. + public virtual Response GetVectorStoreFile(string vectorStoreId, string fileId, CancellationToken cancellationToken = default) { - Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - Argument.AssertNotNullOrEmpty(runId, nameof(runId)); + Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); + Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); RequestContext context = FromCancellationToken(cancellationToken); - Response response = InternalGetRunSteps(threadId, runId, limit, order?.ToString(), after, before, context); - return Response.FromValue(InternalOpenAIPageableListOfRunStep.FromResponse(response), response); + Response response = GetVectorStoreFile(vectorStoreId, fileId, context); + return Response.FromValue(VectorStoreFile.FromResponse(response), response); } /// - /// [Protocol Method] Gets a list of run steps from a thread run. + /// [Protocol Method] Retrieves a vector store file. /// /// /// /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. /// /// - /// - /// - /// Please try the simpler convenience overload with strongly typed models first. - /// - /// /// /// - /// The ID of the thread that was run. - /// The ID of the run to list steps from. - /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. - /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. Allowed values: "asc" | "desc". - /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. - /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. + /// The ID of the vector store that the file belongs to. + /// The ID of the file being retrieved. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. - /// or is null. - /// or is an empty string, and was expected to be non-empty. + /// or is null. + /// or is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual async Task InternalGetRunStepsAsync(string threadId, string runId, int? limit, string order, string after, string before, RequestContext context) + internal virtual async Task GetVectorStoreFileAsync(string vectorStoreId, string fileId, RequestContext context) { - Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - Argument.AssertNotNullOrEmpty(runId, nameof(runId)); + Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); + Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.InternalGetRunSteps"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.GetVectorStoreFile"); scope.Start(); try { - using HttpMessage message = CreateInternalGetRunStepsRequest(threadId, runId, limit, order, after, before, context); + using HttpMessage message = CreateGetVectorStoreFileRequest(vectorStoreId, fileId, context); return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); } catch (Exception e) @@ -3041,41 +3664,32 @@ internal virtual async Task InternalGetRunStepsAsync(string threadId, } /// - /// [Protocol Method] Gets a list of run steps from a thread run. + /// [Protocol Method] Retrieves a vector store file. /// /// /// /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. /// /// - /// - /// - /// Please try the simpler convenience overload with strongly typed models first. - /// - /// /// /// - /// The ID of the thread that was run. - /// The ID of the run to list steps from. - /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. - /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. Allowed values: "asc" | "desc". - /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. - /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. + /// The ID of the vector store that the file belongs to. + /// The ID of the file being retrieved. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. - /// or is null. - /// or is an empty string, and was expected to be non-empty. + /// or is null. + /// or is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual Response InternalGetRunSteps(string threadId, string runId, int? limit, string order, string after, string before, RequestContext context) + internal virtual Response GetVectorStoreFile(string vectorStoreId, string fileId, RequestContext context) { - Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); - Argument.AssertNotNullOrEmpty(runId, nameof(runId)); + Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); + Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.InternalGetRunSteps"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.GetVectorStoreFile"); scope.Start(); try { - using HttpMessage message = CreateInternalGetRunStepsRequest(threadId, runId, limit, order, after, before, context); + using HttpMessage message = CreateGetVectorStoreFileRequest(vectorStoreId, fileId, context); return _pipeline.ProcessMessage(message, context); } catch (Exception e) @@ -3085,52 +3699,72 @@ internal virtual Response InternalGetRunSteps(string threadId, string runId, int } } - /// Gets a list of previously uploaded files. - /// A value that, when provided, limits list results to files matching the corresponding purpose. + /// + /// Delete a vector store file. This will remove the file from the vector store but the file itself will not be deleted. + /// To delete the file, use the delete file endpoint. + /// + /// The ID of the vector store that the file belongs to. + /// The ID of the file to delete its relationship to the vector store. /// The cancellation token to use. - internal virtual async Task> InternalListFilesAsync(OpenAIFilePurpose? purpose = null, CancellationToken cancellationToken = default) + /// or is null. + /// or is an empty string, and was expected to be non-empty. + public virtual async Task> DeleteVectorStoreFileAsync(string vectorStoreId, string fileId, CancellationToken cancellationToken = default) { + Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); + Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); + RequestContext context = FromCancellationToken(cancellationToken); - Response response = await InternalListFilesAsync(purpose?.ToString(), context).ConfigureAwait(false); - return Response.FromValue(InternalFileListResponse.FromResponse(response), response); + Response response = await DeleteVectorStoreFileAsync(vectorStoreId, fileId, context).ConfigureAwait(false); + return Response.FromValue(VectorStoreFileDeletionStatus.FromResponse(response), response); } - /// Gets a list of previously uploaded files. - /// A value that, when provided, limits list results to files matching the corresponding purpose. + /// + /// Delete a vector store file. This will remove the file from the vector store but the file itself will not be deleted. + /// To delete the file, use the delete file endpoint. + /// + /// The ID of the vector store that the file belongs to. + /// The ID of the file to delete its relationship to the vector store. /// The cancellation token to use. - internal virtual Response InternalListFiles(OpenAIFilePurpose? purpose = null, CancellationToken cancellationToken = default) + /// or is null. + /// or is an empty string, and was expected to be non-empty. + public virtual Response DeleteVectorStoreFile(string vectorStoreId, string fileId, CancellationToken cancellationToken = default) { + Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); + Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); + RequestContext context = FromCancellationToken(cancellationToken); - Response response = InternalListFiles(purpose?.ToString(), context); - return Response.FromValue(InternalFileListResponse.FromResponse(response), response); + Response response = DeleteVectorStoreFile(vectorStoreId, fileId, context); + return Response.FromValue(VectorStoreFileDeletionStatus.FromResponse(response), response); } /// - /// [Protocol Method] Gets a list of previously uploaded files. + /// [Protocol Method] Delete a vector store file. This will remove the file from the vector store but the file itself will not be deleted. + /// To delete the file, use the delete file endpoint. /// /// /// /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. /// /// - /// - /// - /// Please try the simpler convenience overload with strongly typed models first. - /// - /// /// /// - /// A value that, when provided, limits list results to files matching the corresponding purpose. Allowed values: "fine-tune" | "fine-tune-results" | "assistants" | "assistants_output". + /// The ID of the vector store that the file belongs to. + /// The ID of the file to delete its relationship to the vector store. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// or is null. + /// or is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual async Task InternalListFilesAsync(string purpose, RequestContext context) + internal virtual async Task DeleteVectorStoreFileAsync(string vectorStoreId, string fileId, RequestContext context) { - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.InternalListFiles"); + Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); + Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.DeleteVectorStoreFile"); scope.Start(); try { - using HttpMessage message = CreateInternalListFilesRequest(purpose, context); + using HttpMessage message = CreateDeleteVectorStoreFileRequest(vectorStoreId, fileId, context); return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); } catch (Exception e) @@ -3141,31 +3775,33 @@ internal virtual async Task InternalListFilesAsync(string purpose, Req } /// - /// [Protocol Method] Gets a list of previously uploaded files. + /// [Protocol Method] Delete a vector store file. This will remove the file from the vector store but the file itself will not be deleted. + /// To delete the file, use the delete file endpoint. /// /// /// /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. /// /// - /// - /// - /// Please try the simpler convenience overload with strongly typed models first. - /// - /// /// /// - /// A value that, when provided, limits list results to files matching the corresponding purpose. Allowed values: "fine-tune" | "fine-tune-results" | "assistants" | "assistants_output". + /// The ID of the vector store that the file belongs to. + /// The ID of the file to delete its relationship to the vector store. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// or is null. + /// or is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual Response InternalListFiles(string purpose, RequestContext context) + internal virtual Response DeleteVectorStoreFile(string vectorStoreId, string fileId, RequestContext context) { - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.InternalListFiles"); + Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); + Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); + + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.DeleteVectorStoreFile"); scope.Start(); try { - using HttpMessage message = CreateInternalListFilesRequest(purpose, context); + using HttpMessage message = CreateDeleteVectorStoreFileRequest(vectorStoreId, fileId, context); return _pipeline.ProcessMessage(message, context); } catch (Exception e) @@ -3175,36 +3811,44 @@ internal virtual Response InternalListFiles(string purpose, RequestContext conte } } - /// Uploads a file for use by other operations. - /// The file data (not filename) to upload. + /// Create a vector store file batch. + /// The ID of the vector store for which to create a File Batch. + /// A list of File IDs that the vector store should use. Useful for tools like `file_search` that can access files. + /// The chunking strategy used to chunk the file(s). If not set, will use the auto strategy. /// The cancellation token to use. - /// is null. - public virtual async Task> UploadFileAsync(UploadFileRequest file, CancellationToken cancellationToken = default) + /// or is null. + /// is an empty string, and was expected to be non-empty. + public virtual async Task> CreateVectorStoreFileBatchAsync(string vectorStoreId, IEnumerable fileIds, VectorStoreChunkingStrategyRequest chunkingStrategy = null, CancellationToken cancellationToken = default) { - Argument.AssertNotNull(file, nameof(file)); + Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); + Argument.AssertNotNull(fileIds, nameof(fileIds)); - using MultipartFormDataRequestContent content = file.ToMultipartRequestContent(); + CreateVectorStoreFileBatchRequest createVectorStoreFileBatchRequest = new CreateVectorStoreFileBatchRequest(fileIds.ToList(), chunkingStrategy, null); RequestContext context = FromCancellationToken(cancellationToken); - Response response = await UploadFileAsync(content, content.ContentType, context).ConfigureAwait(false); - return Response.FromValue(OpenAIFile.FromResponse(response), response); + Response response = await CreateVectorStoreFileBatchAsync(vectorStoreId, createVectorStoreFileBatchRequest.ToRequestContent(), context).ConfigureAwait(false); + return Response.FromValue(VectorStoreFileBatch.FromResponse(response), response); } - /// Uploads a file for use by other operations. - /// The file data (not filename) to upload. + /// Create a vector store file batch. + /// The ID of the vector store for which to create a File Batch. + /// A list of File IDs that the vector store should use. Useful for tools like `file_search` that can access files. + /// The chunking strategy used to chunk the file(s). If not set, will use the auto strategy. /// The cancellation token to use. - /// is null. - public virtual Response UploadFile(UploadFileRequest file, CancellationToken cancellationToken = default) + /// or is null. + /// is an empty string, and was expected to be non-empty. + public virtual Response CreateVectorStoreFileBatch(string vectorStoreId, IEnumerable fileIds, VectorStoreChunkingStrategyRequest chunkingStrategy = null, CancellationToken cancellationToken = default) { - Argument.AssertNotNull(file, nameof(file)); + Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); + Argument.AssertNotNull(fileIds, nameof(fileIds)); - using MultipartFormDataRequestContent content = file.ToMultipartRequestContent(); + CreateVectorStoreFileBatchRequest createVectorStoreFileBatchRequest = new CreateVectorStoreFileBatchRequest(fileIds.ToList(), chunkingStrategy, null); RequestContext context = FromCancellationToken(cancellationToken); - Response response = UploadFile(content, content.ContentType, context); - return Response.FromValue(OpenAIFile.FromResponse(response), response); + Response response = CreateVectorStoreFileBatch(vectorStoreId, createVectorStoreFileBatchRequest.ToRequestContent(), context); + return Response.FromValue(VectorStoreFileBatch.FromResponse(response), response); } /// - /// [Protocol Method] Uploads a file for use by other operations. + /// [Protocol Method] Create a vector store file batch. /// /// /// @@ -3213,21 +3857,23 @@ public virtual Response UploadFile(UploadFileRequest file, Cancellat /// /// /// + /// The ID of the vector store for which to create a File Batch. /// The content to send as the body of the request. - /// The 'content-type' header value, always 'multipart/format-data' for this operation. Allowed values: "multipart/form-data". /// The request context, which can override default behaviors of the client pipeline on a per-call basis. - /// is null. + /// or is null. + /// is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual async Task UploadFileAsync(RequestContent content, string contentType, RequestContext context = null) + internal virtual async Task CreateVectorStoreFileBatchAsync(string vectorStoreId, RequestContent content, RequestContext context = null) { + Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); Argument.AssertNotNull(content, nameof(content)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.UploadFile"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.CreateVectorStoreFileBatch"); scope.Start(); try { - using HttpMessage message = CreateUploadFileRequest(content, contentType, context); + using HttpMessage message = CreateCreateVectorStoreFileBatchRequest(vectorStoreId, content, context); return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); } catch (Exception e) @@ -3238,7 +3884,7 @@ internal virtual async Task UploadFileAsync(RequestContent content, st } /// - /// [Protocol Method] Uploads a file for use by other operations. + /// [Protocol Method] Create a vector store file batch. /// /// /// @@ -3247,21 +3893,23 @@ internal virtual async Task UploadFileAsync(RequestContent content, st /// /// /// + /// The ID of the vector store for which to create a File Batch. /// The content to send as the body of the request. - /// The 'content-type' header value, always 'multipart/format-data' for this operation. Allowed values: "multipart/form-data". /// The request context, which can override default behaviors of the client pipeline on a per-call basis. - /// is null. + /// or is null. + /// is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual Response UploadFile(RequestContent content, string contentType, RequestContext context = null) + internal virtual Response CreateVectorStoreFileBatch(string vectorStoreId, RequestContent content, RequestContext context = null) { + Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); Argument.AssertNotNull(content, nameof(content)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.UploadFile"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.CreateVectorStoreFileBatch"); scope.Start(); try { - using HttpMessage message = CreateUploadFileRequest(content, contentType, context); + using HttpMessage message = CreateCreateVectorStoreFileBatchRequest(vectorStoreId, content, context); return _pipeline.ProcessMessage(message, context); } catch (Exception e) @@ -3271,64 +3919,65 @@ internal virtual Response UploadFile(RequestContent content, string contentType, } } - /// Delete a previously uploaded file. - /// The ID of the file to delete. + /// Retrieve a vector store file batch. + /// The ID of the vector store that the file batch belongs to. + /// The ID of the file batch being retrieved. /// The cancellation token to use. - /// is null. - /// is an empty string, and was expected to be non-empty. - internal virtual async Task> InternalDeleteFileAsync(string fileId, CancellationToken cancellationToken = default) + /// or is null. + /// or is an empty string, and was expected to be non-empty. + public virtual async Task> GetVectorStoreFileBatchAsync(string vectorStoreId, string batchId, CancellationToken cancellationToken = default) { - Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); + Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); + Argument.AssertNotNullOrEmpty(batchId, nameof(batchId)); RequestContext context = FromCancellationToken(cancellationToken); - Response response = await InternalDeleteFileAsync(fileId, context).ConfigureAwait(false); - return Response.FromValue(InternalFileDeletionStatus.FromResponse(response), response); + Response response = await GetVectorStoreFileBatchAsync(vectorStoreId, batchId, context).ConfigureAwait(false); + return Response.FromValue(VectorStoreFileBatch.FromResponse(response), response); } - /// Delete a previously uploaded file. - /// The ID of the file to delete. + /// Retrieve a vector store file batch. + /// The ID of the vector store that the file batch belongs to. + /// The ID of the file batch being retrieved. /// The cancellation token to use. - /// is null. - /// is an empty string, and was expected to be non-empty. - internal virtual Response InternalDeleteFile(string fileId, CancellationToken cancellationToken = default) + /// or is null. + /// or is an empty string, and was expected to be non-empty. + public virtual Response GetVectorStoreFileBatch(string vectorStoreId, string batchId, CancellationToken cancellationToken = default) { - Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); + Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); + Argument.AssertNotNullOrEmpty(batchId, nameof(batchId)); RequestContext context = FromCancellationToken(cancellationToken); - Response response = InternalDeleteFile(fileId, context); - return Response.FromValue(InternalFileDeletionStatus.FromResponse(response), response); + Response response = GetVectorStoreFileBatch(vectorStoreId, batchId, context); + return Response.FromValue(VectorStoreFileBatch.FromResponse(response), response); } /// - /// [Protocol Method] Delete a previously uploaded file. + /// [Protocol Method] Retrieve a vector store file batch. /// /// /// /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. /// /// - /// - /// - /// Please try the simpler convenience overload with strongly typed models first. - /// - /// /// /// - /// The ID of the file to delete. + /// The ID of the vector store that the file batch belongs to. + /// The ID of the file batch being retrieved. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. - /// is null. - /// is an empty string, and was expected to be non-empty. + /// or is null. + /// or is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual async Task InternalDeleteFileAsync(string fileId, RequestContext context) + internal virtual async Task GetVectorStoreFileBatchAsync(string vectorStoreId, string batchId, RequestContext context) { - Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); + Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); + Argument.AssertNotNullOrEmpty(batchId, nameof(batchId)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.InternalDeleteFile"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.GetVectorStoreFileBatch"); scope.Start(); try { - using HttpMessage message = CreateInternalDeleteFileRequest(fileId, context); + using HttpMessage message = CreateGetVectorStoreFileBatchRequest(vectorStoreId, batchId, context); return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); } catch (Exception e) @@ -3339,35 +3988,32 @@ internal virtual async Task InternalDeleteFileAsync(string fileId, Req } /// - /// [Protocol Method] Delete a previously uploaded file. + /// [Protocol Method] Retrieve a vector store file batch. /// /// /// /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. /// /// - /// - /// - /// Please try the simpler convenience overload with strongly typed models first. - /// - /// /// /// - /// The ID of the file to delete. + /// The ID of the vector store that the file batch belongs to. + /// The ID of the file batch being retrieved. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. - /// is null. - /// is an empty string, and was expected to be non-empty. + /// or is null. + /// or is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual Response InternalDeleteFile(string fileId, RequestContext context) + internal virtual Response GetVectorStoreFileBatch(string vectorStoreId, string batchId, RequestContext context) { - Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); + Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); + Argument.AssertNotNullOrEmpty(batchId, nameof(batchId)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.InternalDeleteFile"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.GetVectorStoreFileBatch"); scope.Start(); try { - using HttpMessage message = CreateInternalDeleteFileRequest(fileId, context); + using HttpMessage message = CreateGetVectorStoreFileBatchRequest(vectorStoreId, batchId, context); return _pipeline.ProcessMessage(message, context); } catch (Exception e) @@ -3377,36 +4023,40 @@ internal virtual Response InternalDeleteFile(string fileId, RequestContext conte } } - /// Returns information about a specific file. Does not retrieve file content. - /// The ID of the file to retrieve. + /// Cancel a vector store file batch. This attempts to cancel the processing of files in this batch as soon as possible. + /// The ID of the vector store that the file batch belongs to. + /// The ID of the file batch to cancel. /// The cancellation token to use. - /// is null. - /// is an empty string, and was expected to be non-empty. - public virtual async Task> GetFileAsync(string fileId, CancellationToken cancellationToken = default) + /// or is null. + /// or is an empty string, and was expected to be non-empty. + public virtual async Task> CancelVectorStoreFileBatchAsync(string vectorStoreId, string batchId, CancellationToken cancellationToken = default) { - Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); + Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); + Argument.AssertNotNullOrEmpty(batchId, nameof(batchId)); RequestContext context = FromCancellationToken(cancellationToken); - Response response = await GetFileAsync(fileId, context).ConfigureAwait(false); - return Response.FromValue(OpenAIFile.FromResponse(response), response); + Response response = await CancelVectorStoreFileBatchAsync(vectorStoreId, batchId, context).ConfigureAwait(false); + return Response.FromValue(VectorStoreFileBatch.FromResponse(response), response); } - /// Returns information about a specific file. Does not retrieve file content. - /// The ID of the file to retrieve. + /// Cancel a vector store file batch. This attempts to cancel the processing of files in this batch as soon as possible. + /// The ID of the vector store that the file batch belongs to. + /// The ID of the file batch to cancel. /// The cancellation token to use. - /// is null. - /// is an empty string, and was expected to be non-empty. - public virtual Response GetFile(string fileId, CancellationToken cancellationToken = default) + /// or is null. + /// or is an empty string, and was expected to be non-empty. + public virtual Response CancelVectorStoreFileBatch(string vectorStoreId, string batchId, CancellationToken cancellationToken = default) { - Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); + Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); + Argument.AssertNotNullOrEmpty(batchId, nameof(batchId)); RequestContext context = FromCancellationToken(cancellationToken); - Response response = GetFile(fileId, context); - return Response.FromValue(OpenAIFile.FromResponse(response), response); + Response response = CancelVectorStoreFileBatch(vectorStoreId, batchId, context); + return Response.FromValue(VectorStoreFileBatch.FromResponse(response), response); } /// - /// [Protocol Method] Returns information about a specific file. Does not retrieve file content. + /// [Protocol Method] Cancel a vector store file batch. This attempts to cancel the processing of files in this batch as soon as possible. /// /// /// @@ -3415,21 +4065,23 @@ public virtual Response GetFile(string fileId, CancellationToken can /// /// /// - /// The ID of the file to retrieve. + /// The ID of the vector store that the file batch belongs to. + /// The ID of the file batch to cancel. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. - /// is null. - /// is an empty string, and was expected to be non-empty. + /// or is null. + /// or is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual async Task GetFileAsync(string fileId, RequestContext context) + internal virtual async Task CancelVectorStoreFileBatchAsync(string vectorStoreId, string batchId, RequestContext context) { - Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); + Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); + Argument.AssertNotNullOrEmpty(batchId, nameof(batchId)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.GetFile"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.CancelVectorStoreFileBatch"); scope.Start(); try { - using HttpMessage message = CreateGetFileRequest(fileId, context); + using HttpMessage message = CreateCancelVectorStoreFileBatchRequest(vectorStoreId, batchId, context); return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); } catch (Exception e) @@ -3440,7 +4092,7 @@ internal virtual async Task GetFileAsync(string fileId, RequestContext } /// - /// [Protocol Method] Returns information about a specific file. Does not retrieve file content. + /// [Protocol Method] Cancel a vector store file batch. This attempts to cancel the processing of files in this batch as soon as possible. /// /// /// @@ -3449,21 +4101,23 @@ internal virtual async Task GetFileAsync(string fileId, RequestContext /// /// /// - /// The ID of the file to retrieve. + /// The ID of the vector store that the file batch belongs to. + /// The ID of the file batch to cancel. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. - /// is null. - /// is an empty string, and was expected to be non-empty. + /// or is null. + /// or is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual Response GetFile(string fileId, RequestContext context) + internal virtual Response CancelVectorStoreFileBatch(string vectorStoreId, string batchId, RequestContext context) { - Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); + Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); + Argument.AssertNotNullOrEmpty(batchId, nameof(batchId)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.GetFile"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.CancelVectorStoreFileBatch"); scope.Start(); try { - using HttpMessage message = CreateGetFileRequest(fileId, context); + using HttpMessage message = CreateCancelVectorStoreFileBatchRequest(vectorStoreId, batchId, context); return _pipeline.ProcessMessage(message, context); } catch (Exception e) @@ -3473,36 +4127,50 @@ internal virtual Response GetFile(string fileId, RequestContext context) } } - /// Returns information about a specific file. Does not retrieve file content. - /// The ID of the file to retrieve. + /// Returns a list of vector store files in a batch. + /// The ID of the vector store that the file batch belongs to. + /// The ID of the file batch that the files belong to. + /// Filter by file status. + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. + /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. + /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, starting with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. /// The cancellation token to use. - /// is null. - /// is an empty string, and was expected to be non-empty. - public virtual async Task> GetFileContentAsync(string fileId, CancellationToken cancellationToken = default) + /// or is null. + /// or is an empty string, and was expected to be non-empty. + public virtual async Task> GetVectorStoreFileBatchFilesAsync(string vectorStoreId, string batchId, VectorStoreFileStatusFilter? filter = null, int? limit = null, ListSortOrder? order = null, string after = null, string before = null, CancellationToken cancellationToken = default) { - Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); + Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); + Argument.AssertNotNullOrEmpty(batchId, nameof(batchId)); RequestContext context = FromCancellationToken(cancellationToken); - Response response = await GetFileContentAsync(fileId, context).ConfigureAwait(false); - return Response.FromValue(response.Content, response); + Response response = await GetVectorStoreFileBatchFilesAsync(vectorStoreId, batchId, filter?.ToString(), limit, order?.ToString(), after, before, context).ConfigureAwait(false); + return Response.FromValue(OpenAIPageableListOfVectorStoreFile.FromResponse(response), response); } - /// Returns information about a specific file. Does not retrieve file content. - /// The ID of the file to retrieve. + /// Returns a list of vector store files in a batch. + /// The ID of the vector store that the file batch belongs to. + /// The ID of the file batch that the files belong to. + /// Filter by file status. + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. + /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. + /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, starting with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. /// The cancellation token to use. - /// is null. - /// is an empty string, and was expected to be non-empty. - public virtual Response GetFileContent(string fileId, CancellationToken cancellationToken = default) + /// or is null. + /// or is an empty string, and was expected to be non-empty. + public virtual Response GetVectorStoreFileBatchFiles(string vectorStoreId, string batchId, VectorStoreFileStatusFilter? filter = null, int? limit = null, ListSortOrder? order = null, string after = null, string before = null, CancellationToken cancellationToken = default) { - Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); + Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); + Argument.AssertNotNullOrEmpty(batchId, nameof(batchId)); RequestContext context = FromCancellationToken(cancellationToken); - Response response = GetFileContent(fileId, context); - return Response.FromValue(response.Content, response); + Response response = GetVectorStoreFileBatchFiles(vectorStoreId, batchId, filter?.ToString(), limit, order?.ToString(), after, before, context); + return Response.FromValue(OpenAIPageableListOfVectorStoreFile.FromResponse(response), response); } /// - /// [Protocol Method] Returns information about a specific file. Does not retrieve file content. + /// [Protocol Method] Returns a list of vector store files in a batch. /// /// /// @@ -3511,21 +4179,28 @@ public virtual Response GetFileContent(string fileId, CancellationTo /// /// /// - /// The ID of the file to retrieve. + /// The ID of the vector store that the file batch belongs to. + /// The ID of the file batch that the files belong to. + /// Filter by file status. Allowed values: "in_progress" | "completed" | "failed" | "cancelled". + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. Allowed values: "asc" | "desc". + /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. + /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, starting with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. - /// is null. - /// is an empty string, and was expected to be non-empty. + /// or is null. + /// or is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual async Task GetFileContentAsync(string fileId, RequestContext context) + internal virtual async Task GetVectorStoreFileBatchFilesAsync(string vectorStoreId, string batchId, string filter, int? limit, string order, string after, string before, RequestContext context) { - Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); + Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); + Argument.AssertNotNullOrEmpty(batchId, nameof(batchId)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.GetFileContent"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.GetVectorStoreFileBatchFiles"); scope.Start(); try { - using HttpMessage message = CreateGetFileContentRequest(fileId, context); + using HttpMessage message = CreateGetVectorStoreFileBatchFilesRequest(vectorStoreId, batchId, filter, limit, order, after, before, context); return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); } catch (Exception e) @@ -3536,7 +4211,7 @@ internal virtual async Task GetFileContentAsync(string fileId, Request } /// - /// [Protocol Method] Returns information about a specific file. Does not retrieve file content. + /// [Protocol Method] Returns a list of vector store files in a batch. /// /// /// @@ -3545,21 +4220,28 @@ internal virtual async Task GetFileContentAsync(string fileId, Request /// /// /// - /// The ID of the file to retrieve. + /// The ID of the vector store that the file batch belongs to. + /// The ID of the file batch that the files belong to. + /// Filter by file status. Allowed values: "in_progress" | "completed" | "failed" | "cancelled". + /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. Allowed values: "asc" | "desc". + /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. + /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, starting with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. /// The request context, which can override default behaviors of the client pipeline on a per-call basis. - /// is null. - /// is an empty string, and was expected to be non-empty. + /// or is null. + /// or is an empty string, and was expected to be non-empty. /// Service returned a non-success status code. /// The response returned from the service. - internal virtual Response GetFileContent(string fileId, RequestContext context) + internal virtual Response GetVectorStoreFileBatchFiles(string vectorStoreId, string batchId, string filter, int? limit, string order, string after, string before, RequestContext context) { - Argument.AssertNotNullOrEmpty(fileId, nameof(fileId)); + Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId)); + Argument.AssertNotNullOrEmpty(batchId, nameof(batchId)); - using var scope = ClientDiagnostics.CreateScope("AssistantsClient.GetFileContent"); + using var scope = ClientDiagnostics.CreateScope("AssistantsClient.GetVectorStoreFileBatchFiles"); scope.Start(); try { - using HttpMessage message = CreateGetFileContentRequest(fileId, context); + using HttpMessage message = CreateGetVectorStoreFileBatchFilesRequest(vectorStoreId, batchId, filter, limit, order, after, before, context); return _pipeline.ProcessMessage(message, context); } catch (Exception e) @@ -3569,6 +4251,380 @@ internal virtual Response GetFileContent(string fileId, RequestContext context) } } + internal HttpMessage CreateInternalGetMessagesRequest(string threadId, string runId, int? limit, string order, string after, string before, RequestContext context) + { + var message = _pipeline.CreateMessage(context, ResponseClassifier200); + var request = message.Request; + request.Method = RequestMethod.Get; + var uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/threads/", false); + uri.AppendPath(threadId, true); + uri.AppendPath("/messages", false); + if (runId != null) + { + uri.AppendQuery("runId", runId, true); + } + if (limit != null) + { + uri.AppendQuery("limit", limit.Value, true); + } + if (order != null) + { + uri.AppendQuery("order", order, true); + } + if (after != null) + { + uri.AppendQuery("after", after, true); + } + if (before != null) + { + uri.AppendQuery("before", before, true); + } + request.Uri = uri; + request.Headers.Add("Accept", "application/json"); + return message; + } + + internal HttpMessage CreateCreateRunRequest(string threadId, RequestContent content, IEnumerable runInclude, RequestContext context) + { + var message = _pipeline.CreateMessage(context, ResponseClassifier200); + var request = message.Request; + request.Method = RequestMethod.Post; + var uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/threads/", false); + uri.AppendPath(threadId, true); + uri.AppendPath("/runs", false); + if (runInclude != null && !(runInclude is ChangeTrackingList changeTrackingList && changeTrackingList.IsUndefined)) + { + uri.AppendQueryDelimited("include[]", runInclude, ",", true); + } + request.Uri = uri; + request.Headers.Add("Accept", "application/json"); + request.Headers.Add("Content-Type", "application/json"); + request.Content = content; + return message; + } + + internal HttpMessage CreateGetRunStepRequest(string threadId, string runId, string stepId, IEnumerable runInclude, RequestContext context) + { + var message = _pipeline.CreateMessage(context, ResponseClassifier200); + var request = message.Request; + request.Method = RequestMethod.Get; + var uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/threads/", false); + uri.AppendPath(threadId, true); + uri.AppendPath("/runs/", false); + uri.AppendPath(runId, true); + uri.AppendPath("/steps/", false); + uri.AppendPath(stepId, true); + if (runInclude != null && !(runInclude is ChangeTrackingList changeTrackingList && changeTrackingList.IsUndefined)) + { + uri.AppendQueryDelimited("include[]", runInclude, ",", true); + } + request.Uri = uri; + request.Headers.Add("Accept", "application/json"); + return message; + } + + internal HttpMessage CreateInternalGetRunStepsRequest(string threadId, string runId, IEnumerable runInclude, int? limit, string order, string after, string before, RequestContext context) + { + var message = _pipeline.CreateMessage(context, ResponseClassifier200); + var request = message.Request; + request.Method = RequestMethod.Get; + var uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/threads/", false); + uri.AppendPath(threadId, true); + uri.AppendPath("/runs/", false); + uri.AppendPath(runId, true); + uri.AppendPath("/steps", false); + if (runInclude != null && !(runInclude is ChangeTrackingList changeTrackingList && changeTrackingList.IsUndefined)) + { + uri.AppendQueryDelimited("include[]", runInclude, ",", true); + } + if (limit != null) + { + uri.AppendQuery("limit", limit.Value, true); + } + if (order != null) + { + uri.AppendQuery("order", order, true); + } + if (after != null) + { + uri.AppendQuery("after", after, true); + } + if (before != null) + { + uri.AppendQuery("before", before, true); + } + request.Uri = uri; + request.Headers.Add("Accept", "application/json"); + return message; + } + + internal HttpMessage CreateGetVectorStoresRequest(int? limit, string order, string after, string before, RequestContext context) + { + var message = _pipeline.CreateMessage(context, ResponseClassifier200); + var request = message.Request; + request.Method = RequestMethod.Get; + var uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/vector_stores", false); + if (limit != null) + { + uri.AppendQuery("limit", limit.Value, true); + } + if (order != null) + { + uri.AppendQuery("order", order, true); + } + if (after != null) + { + uri.AppendQuery("after", after, true); + } + if (before != null) + { + uri.AppendQuery("before", before, true); + } + request.Uri = uri; + request.Headers.Add("Accept", "application/json"); + return message; + } + + internal HttpMessage CreateCreateVectorStoreRequest(RequestContent content, RequestContext context) + { + var message = _pipeline.CreateMessage(context, ResponseClassifier200); + var request = message.Request; + request.Method = RequestMethod.Post; + var uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/vector_stores", false); + request.Uri = uri; + request.Headers.Add("Accept", "application/json"); + request.Headers.Add("Content-Type", "application/json"); + request.Content = content; + return message; + } + + internal HttpMessage CreateGetVectorStoreRequest(string vectorStoreId, RequestContext context) + { + var message = _pipeline.CreateMessage(context, ResponseClassifier200); + var request = message.Request; + request.Method = RequestMethod.Get; + var uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/vector_stores/", false); + uri.AppendPath(vectorStoreId, true); + request.Uri = uri; + request.Headers.Add("Accept", "application/json"); + return message; + } + + internal HttpMessage CreateModifyVectorStoreRequest(string vectorStoreId, RequestContent content, RequestContext context) + { + var message = _pipeline.CreateMessage(context, ResponseClassifier200); + var request = message.Request; + request.Method = RequestMethod.Post; + var uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/vector_stores/", false); + uri.AppendPath(vectorStoreId, true); + request.Uri = uri; + request.Headers.Add("Accept", "application/json"); + request.Headers.Add("Content-Type", "application/json"); + request.Content = content; + return message; + } + + internal HttpMessage CreateDeleteVectorStoreRequest(string vectorStoreId, RequestContext context) + { + var message = _pipeline.CreateMessage(context, ResponseClassifier200); + var request = message.Request; + request.Method = RequestMethod.Delete; + var uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/vector_stores/", false); + uri.AppendPath(vectorStoreId, true); + request.Uri = uri; + request.Headers.Add("Accept", "application/json"); + return message; + } + + internal HttpMessage CreateGetVectorStoreFilesRequest(string vectorStoreId, string filter, int? limit, string order, string after, string before, RequestContext context) + { + var message = _pipeline.CreateMessage(context, ResponseClassifier200); + var request = message.Request; + request.Method = RequestMethod.Get; + var uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/vector_stores/", false); + uri.AppendPath(vectorStoreId, true); + uri.AppendPath("/files", false); + if (filter != null) + { + uri.AppendQuery("filter", filter, true); + } + if (limit != null) + { + uri.AppendQuery("limit", limit.Value, true); + } + if (order != null) + { + uri.AppendQuery("order", order, true); + } + if (after != null) + { + uri.AppendQuery("after", after, true); + } + if (before != null) + { + uri.AppendQuery("before", before, true); + } + request.Uri = uri; + request.Headers.Add("Accept", "application/json"); + return message; + } + + internal HttpMessage CreateCreateVectorStoreFileRequest(string vectorStoreId, RequestContent content, RequestContext context) + { + var message = _pipeline.CreateMessage(context, ResponseClassifier200); + var request = message.Request; + request.Method = RequestMethod.Post; + var uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/vector_stores/", false); + uri.AppendPath(vectorStoreId, true); + uri.AppendPath("/files", false); + request.Uri = uri; + request.Headers.Add("Accept", "application/json"); + request.Headers.Add("Content-Type", "application/json"); + request.Content = content; + return message; + } + + internal HttpMessage CreateGetVectorStoreFileRequest(string vectorStoreId, string fileId, RequestContext context) + { + var message = _pipeline.CreateMessage(context, ResponseClassifier200); + var request = message.Request; + request.Method = RequestMethod.Get; + var uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/vector_stores/", false); + uri.AppendPath(vectorStoreId, true); + uri.AppendPath("/files/", false); + uri.AppendPath(fileId, true); + request.Uri = uri; + request.Headers.Add("Accept", "application/json"); + return message; + } + + internal HttpMessage CreateDeleteVectorStoreFileRequest(string vectorStoreId, string fileId, RequestContext context) + { + var message = _pipeline.CreateMessage(context, ResponseClassifier200); + var request = message.Request; + request.Method = RequestMethod.Delete; + var uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/vector_stores/", false); + uri.AppendPath(vectorStoreId, true); + uri.AppendPath("/files/", false); + uri.AppendPath(fileId, true); + request.Uri = uri; + request.Headers.Add("Accept", "application/json"); + return message; + } + + internal HttpMessage CreateCreateVectorStoreFileBatchRequest(string vectorStoreId, RequestContent content, RequestContext context) + { + var message = _pipeline.CreateMessage(context, ResponseClassifier200); + var request = message.Request; + request.Method = RequestMethod.Post; + var uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/vector_stores/", false); + uri.AppendPath(vectorStoreId, true); + uri.AppendPath("/file_batches", false); + request.Uri = uri; + request.Headers.Add("Accept", "application/json"); + request.Headers.Add("Content-Type", "application/json"); + request.Content = content; + return message; + } + + internal HttpMessage CreateGetVectorStoreFileBatchRequest(string vectorStoreId, string batchId, RequestContext context) + { + var message = _pipeline.CreateMessage(context, ResponseClassifier200); + var request = message.Request; + request.Method = RequestMethod.Get; + var uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/vector_stores/", false); + uri.AppendPath(vectorStoreId, true); + uri.AppendPath("/file_batches/", false); + uri.AppendPath(batchId, true); + request.Uri = uri; + request.Headers.Add("Accept", "application/json"); + return message; + } + + internal HttpMessage CreateCancelVectorStoreFileBatchRequest(string vectorStoreId, string batchId, RequestContext context) + { + var message = _pipeline.CreateMessage(context, ResponseClassifier200); + var request = message.Request; + request.Method = RequestMethod.Post; + var uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/vector_stores/", false); + uri.AppendPath(vectorStoreId, true); + uri.AppendPath("/file_batches/", false); + uri.AppendPath(batchId, true); + uri.AppendPath("/cancel", false); + request.Uri = uri; + request.Headers.Add("Accept", "application/json"); + return message; + } + + internal HttpMessage CreateGetVectorStoreFileBatchFilesRequest(string vectorStoreId, string batchId, string filter, int? limit, string order, string after, string before, RequestContext context) + { + var message = _pipeline.CreateMessage(context, ResponseClassifier200); + var request = message.Request; + request.Method = RequestMethod.Get; + var uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/vector_stores/", false); + uri.AppendPath(vectorStoreId, true); + uri.AppendPath("/file_batches/", false); + uri.AppendPath(batchId, true); + uri.AppendPath("/files", false); + if (filter != null) + { + uri.AppendQuery("filter", filter, true); + } + if (limit != null) + { + uri.AppendQuery("limit", limit.Value, true); + } + if (order != null) + { + uri.AppendQuery("order", order, true); + } + if (after != null) + { + uri.AppendQuery("after", after, true); + } + if (before != null) + { + uri.AppendQuery("before", before, true); + } + request.Uri = uri; + request.Headers.Add("Accept", "application/json"); + return message; + } + private static RequestContext DefaultRequestContext = new RequestContext(); internal static RequestContext FromCancellationToken(CancellationToken cancellationToken = default) { diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsClientOptions.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsClientOptions.cs index a847db2052bd..1f5ea9b91e20 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsClientOptions.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsClientOptions.cs @@ -13,13 +13,23 @@ namespace Azure.AI.OpenAI.Assistants /// Client options for AssistantsClient. public partial class AssistantsClientOptions : ClientOptions { - private const ServiceVersion LatestVersion = ServiceVersion.V2024_02_15_Preview; + private const ServiceVersion LatestVersion = ServiceVersion.V2025_01_01_Preview; /// The version of the service to use. public enum ServiceVersion { /// Service version "2024-02-15-preview". V2024_02_15_Preview = 1, + /// Service version "2024-05-01-preview". + V2024_05_01_Preview = 2, + /// Service version "2024-07-01-preview". + V2024_07_01_Preview = 3, + /// Service version "2024-09-01-preview". + V2024_09_01_Preview = 4, + /// Service version "2024-10-01-preview". + V2024_10_01_Preview = 5, + /// Service version "2025-01-01-preview". + V2025_01_01_Preview = 6, } internal string Version { get; } @@ -30,6 +40,11 @@ public AssistantsClientOptions(ServiceVersion version = LatestVersion) Version = version switch { ServiceVersion.V2024_02_15_Preview => "2024-02-15-preview", + ServiceVersion.V2024_05_01_Preview => "2024-05-01-preview", + ServiceVersion.V2024_07_01_Preview => "2024-07-01-preview", + ServiceVersion.V2024_09_01_Preview => "2024-09-01-preview", + ServiceVersion.V2024_10_01_Preview => "2024-10-01-preview", + ServiceVersion.V2025_01_01_Preview => "2025-01-01-preview", _ => throw new NotSupportedException() }; } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsModelFactory.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsModelFactory.cs index 5b8ad9bf95c0..852d5e06e3b3 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsModelFactory.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsModelFactory.cs @@ -5,6 +5,7 @@ #nullable disable +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -22,15 +23,28 @@ public static partial class AssistantsModelFactory /// /// The collection of tools to enable for the new assistant. /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. - /// The available derived classes include , and . + /// The available derived classes include , and . /// - /// A list of previously uploaded file IDs to attach to the assistant. + /// + /// A set of resources that are used by the assistant's tools. The resources are specific to the type of tool. For example, the `code_interpreter` + /// tool requires a list of file IDs, while the `file_search` tool requires a list of vector store IDs. + /// + /// + /// What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, + /// while lower values like 0.2 will make it more focused and deterministic. + /// + /// + /// An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. + /// So 0.1 means only the tokens comprising the top 10% probability mass are considered. + /// + /// We generally recommend altering this or temperature but not both. + /// + /// The response format of the tool calls used by this assistant. /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. /// A new instance for mocking. - public static AssistantCreationOptions AssistantCreationOptions(string model = null, string name = null, string description = null, string instructions = null, IEnumerable tools = null, IEnumerable fileIds = null, IDictionary metadata = null) + public static AssistantCreationOptions AssistantCreationOptions(string model = null, string name = null, string description = null, string instructions = null, IEnumerable tools = null, CreateToolResourcesOptions toolResources = null, float? temperature = null, float? topP = null, BinaryData responseFormat = null, IDictionary metadata = null) { tools ??= new List(); - fileIds ??= new List(); metadata ??= new Dictionary(); return new AssistantCreationOptions( @@ -39,37 +53,94 @@ public static AssistantCreationOptions AssistantCreationOptions(string model = n description, instructions, tools?.ToList(), - fileIds?.ToList(), + toolResources, + temperature, + topP, + responseFormat, metadata, serializedAdditionalRawData: null); } - /// Initializes a new instance of . - /// The role associated with the assistant thread message. Currently, only 'user' is supported when providing initial messages to a new thread. - /// The textual content of the initial message. Currently, robust input including images and annotated text may only be provided via a separate call to the create message API. - /// - /// A list of file IDs that the assistant should use. Useful for tools like retrieval and code_interpreter that can - /// access files. + /// Initializes a new instance of . + /// A list of file IDs to add to the vector store. There can be a maximum of 10000 files in a vector store. + /// + /// The chunking strategy used to chunk the file(s). If not set, will use the `auto` strategy. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include and . /// /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. - /// A new instance for mocking. - public static ThreadInitializationMessage ThreadInitializationMessage(MessageRole role = default, string content = null, IEnumerable fileIds = null, IDictionary metadata = null) + /// A new instance for mocking. + public static CreateFileSearchToolResourceVectorStoreOptions CreateFileSearchToolResourceVectorStoreOptions(IEnumerable fileIds = null, VectorStoreChunkingStrategyRequest chunkingStrategy = null, IDictionary metadata = null) { fileIds ??= new List(); metadata ??= new Dictionary(); - return new ThreadInitializationMessage(role, content, fileIds?.ToList(), metadata, serializedAdditionalRawData: null); + return new CreateFileSearchToolResourceVectorStoreOptions(fileIds?.ToList(), chunkingStrategy, metadata, serializedAdditionalRawData: null); } - /// Initializes a new instance of . - /// The object type. - /// The textual content associated with this text annotation item. - /// The first text index associated with this text annotation. - /// The last text index associated with this text annotation. - /// A new instance for mocking. - public static MessageTextAnnotation MessageTextAnnotation(string type = null, string text = null, int startIndex = default, int endIndex = default) + /// Initializes a new instance of . + /// The options for the static chunking strategy. + /// A new instance for mocking. + public static VectorStoreStaticChunkingStrategyRequest VectorStoreStaticChunkingStrategyRequest(VectorStoreStaticChunkingStrategyOptions @static = null) + { + return new VectorStoreStaticChunkingStrategyRequest(VectorStoreChunkingStrategyRequestType.Static, serializedAdditionalRawData: null, @static); + } + + /// Initializes a new instance of . + /// Resources to be used by the `code_interpreter tool` consisting of file IDs. + /// Resources to be used by the `file_search` tool consisting of vector store IDs. + /// A new instance for mocking. + public static ToolResources ToolResources(CodeInterpreterToolResource codeInterpreter = null, FileSearchToolResource fileSearch = null) + { + return new ToolResources(codeInterpreter, fileSearch, serializedAdditionalRawData: null); + } + + /// Initializes a new instance of . + /// + /// A list of file IDs made available to the `code_interpreter` tool. There can be a maximum of 20 files + /// associated with the tool. + /// + /// A new instance for mocking. + public static CodeInterpreterToolResource CodeInterpreterToolResource(IEnumerable fileIds = null) + { + fileIds ??= new List(); + + return new CodeInterpreterToolResource(fileIds?.ToList(), serializedAdditionalRawData: null); + } + + /// Initializes a new instance of . + /// + /// The ID of the vector store attached to this assistant. There can be a maximum of 1 vector + /// store attached to the assistant. + /// + /// A new instance for mocking. + public static FileSearchToolResource FileSearchToolResource(IEnumerable vectorStoreIds = null) + { + vectorStoreIds ??= new List(); + + return new FileSearchToolResource(vectorStoreIds?.ToList(), serializedAdditionalRawData: null); + } + + /// Initializes a new instance of . + /// + /// The role of the entity that is creating the message. Allowed values include: + /// - `user`: Indicates the message is sent by an actual user and should be used in most cases to represent user-generated messages. + /// - `assistant`: Indicates the message is generated by the assistant. Use this value to insert messages from the assistant into + /// the conversation. + /// + /// + /// The textual content of the initial message. Currently, robust input including images and annotated text may only be provided via + /// a separate call to the create message API. + /// + /// A list of files attached to the message, and the tools they should be added to. + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + /// A new instance for mocking. + public static ThreadMessageOptions ThreadMessageOptions(MessageRole role = default, string content = null, IEnumerable attachments = null, IDictionary metadata = null) { - return new UnknownMessageTextAnnotation(type, text, startIndex, endIndex, serializedAdditionalRawData: null); + attachments ??= new List(); + metadata ??= new Dictionary(); + + return new ThreadMessageOptions(role, content, attachments?.ToList(), metadata, serializedAdditionalRawData: null); } /// Initializes a new instance of . @@ -80,15 +151,46 @@ public static MessageTextAnnotation MessageTextAnnotation(string type = null, st /// Additional instructions to append at the end of the instructions for the run. This is useful for modifying the behavior /// on a per-run basis without overriding other instructions. /// + /// Adds additional messages to the thread before creating the run. /// /// The overridden list of enabled tools that the assistant should use to run the thread. /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. - /// The available derived classes include , and . + /// The available derived classes include , and . + /// + /// Whether to enable parallel function calling during tool use. + /// + /// If `true`, returns a stream of events that happen during the Run as server-sent events, + /// terminating when the Run enters a terminal state with a `data: [DONE]` message. /// + /// + /// What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output + /// more random, while lower values like 0.2 will make it more focused and deterministic. + /// + /// + /// An alternative to sampling with temperature, called nucleus sampling, where the model + /// considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens + /// comprising the top 10% probability mass are considered. + /// + /// We generally recommend altering this or temperature but not both. + /// + /// + /// The maximum number of prompt tokens that may be used over the course of the run. The run will make a best effort to use only + /// the number of prompt tokens specified, across multiple turns of the run. If the run exceeds the number of prompt tokens specified, + /// the run will end with status `incomplete`. See `incomplete_details` for more info. + /// + /// + /// The maximum number of completion tokens that may be used over the course of the run. The run will make a best effort + /// to use only the number of completion tokens specified, across multiple turns of the run. If the run exceeds the number of + /// completion tokens specified, the run will end with status `incomplete`. See `incomplete_details` for more info. + /// + /// The strategy to use for dropping messages as the context windows moves forward. + /// Controls whether or not and which tool is called by the model. + /// Specifies the format that the model must output. /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. /// A new instance for mocking. - public static CreateRunOptions CreateRunOptions(string assistantId = null, string overrideModelName = null, string overrideInstructions = null, string additionalInstructions = null, IEnumerable overrideTools = null, IDictionary metadata = null) + public static CreateRunOptions CreateRunOptions(string assistantId = null, string overrideModelName = null, string overrideInstructions = null, string additionalInstructions = null, IEnumerable additionalMessages = null, IEnumerable overrideTools = null, bool? parallelToolCalls = null, bool? stream = null, float? temperature = null, float? topP = null, int? maxPromptTokens = null, int? maxCompletionTokens = null, TruncationObject truncationStrategy = null, BinaryData toolChoice = null, BinaryData responseFormat = null, IDictionary metadata = null) { + additionalMessages ??= new List(); overrideTools ??= new List(); metadata ??= new Dictionary(); @@ -97,7 +199,17 @@ public static CreateRunOptions CreateRunOptions(string assistantId = null, strin overrideModelName, overrideInstructions, additionalInstructions, + additionalMessages?.ToList(), overrideTools?.ToList(), + parallelToolCalls, + stream, + temperature, + topP, + maxPromptTokens, + maxCompletionTokens, + truncationStrategy, + toolChoice, + responseFormat, metadata, serializedAdditionalRawData: null); } @@ -120,19 +232,59 @@ public static RunError RunError(string code = null, string message = null) return new RunError(code, message, serializedAdditionalRawData: null); } + /// Initializes a new instance of . + /// Number of completion tokens used over the course of the run. + /// Number of prompt tokens used over the course of the run. + /// Total number of tokens used (prompt + completion). + /// A new instance for mocking. + public static RunCompletionUsage RunCompletionUsage(long completionTokens = default, long promptTokens = default, long totalTokens = default) + { + return new RunCompletionUsage(completionTokens, promptTokens, totalTokens, serializedAdditionalRawData: null); + } + /// Initializes a new instance of . /// The ID of the assistant for which the thread should be created. - /// The details used to create the new thread. + /// The details used to create the new thread. If no thread is provided, an empty one will be created. /// The overridden model that the assistant should use to run the thread. /// The overridden system instructions the assistant should use to run the thread. /// /// The overridden list of enabled tools the assistant should use to run the thread. /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. - /// The available derived classes include , and . + /// The available derived classes include , and . + /// + /// Whether to enable parallel function calling during tool use. + /// Override the tools the assistant can use for this run. This is useful for modifying the behavior on a per-run basis. + /// + /// If `true`, returns a stream of events that happen during the Run as server-sent events, + /// terminating when the Run enters a terminal state with a `data: [DONE]` message. + /// + /// + /// What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output + /// more random, while lower values like 0.2 will make it more focused and deterministic. + /// + /// + /// An alternative to sampling with temperature, called nucleus sampling, where the model + /// considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens + /// comprising the top 10% probability mass are considered. + /// + /// We generally recommend altering this or temperature but not both. + /// + /// + /// The maximum number of prompt tokens that may be used over the course of the run. The run will make a best effort to use only + /// the number of prompt tokens specified, across multiple turns of the run. If the run exceeds the number of prompt tokens specified, + /// the run will end with status `incomplete`. See `incomplete_details` for more info. + /// + /// + /// The maximum number of completion tokens that may be used over the course of the run. The run will make a best effort to use only + /// the number of completion tokens specified, across multiple turns of the run. If the run exceeds the number of completion tokens + /// specified, the run will end with status `incomplete`. See `incomplete_details` for more info. /// + /// The strategy to use for dropping messages as the context windows moves forward. + /// Controls whether or not and which tool is called by the model. + /// Specifies the format that the model must output. /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. /// A new instance for mocking. - public static CreateAndRunThreadOptions CreateAndRunThreadOptions(string assistantId = null, AssistantThreadCreationOptions thread = null, string overrideModelName = null, string overrideInstructions = null, IEnumerable overrideTools = null, IDictionary metadata = null) + public static CreateAndRunThreadOptions CreateAndRunThreadOptions(string assistantId = null, AssistantThreadCreationOptions thread = null, string overrideModelName = null, string overrideInstructions = null, IEnumerable overrideTools = null, bool? parallelToolCalls = null, UpdateToolResourcesOptions toolResources = null, bool? stream = null, float? temperature = null, float? topP = null, int? maxPromptTokens = null, int? maxCompletionTokens = null, TruncationObject truncationStrategy = null, BinaryData toolChoice = null, BinaryData responseFormat = null, IDictionary metadata = null) { overrideTools ??= new List(); metadata ??= new Dictionary(); @@ -143,6 +295,16 @@ public static CreateAndRunThreadOptions CreateAndRunThreadOptions(string assista overrideModelName, overrideInstructions, overrideTools?.ToList(), + parallelToolCalls, + toolResources, + stream, + temperature, + topP, + maxPromptTokens, + maxCompletionTokens, + truncationStrategy, + toolChoice, + responseFormat, metadata, serializedAdditionalRawData: null); } @@ -167,7 +329,7 @@ public static RunStepMessageCreationReference RunStepMessageCreationReference(st /// /// A list of tool call details for this run step. /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. - /// The available derived classes include , and . + /// The available derived classes include , and . /// /// A new instance for mocking. public static RunStepToolCallDetails RunStepToolCallDetails(IEnumerable toolCalls = null) @@ -210,15 +372,37 @@ public static RunStepCodeInterpreterImageReference RunStepCodeInterpreterImageRe return new RunStepCodeInterpreterImageReference(fileId, serializedAdditionalRawData: null); } - /// Initializes a new instance of . + /// Initializes a new instance of . /// The ID of the tool call. This ID must be referenced when you submit tool outputs. - /// The key/value pairs produced by the retrieval tool. - /// A new instance for mocking. - public static RunStepRetrievalToolCall RunStepRetrievalToolCall(string id = null, IReadOnlyDictionary retrieval = null) + /// The results of the file search. + /// A new instance for mocking. + public static RunStepFileSearchToolCall RunStepFileSearchToolCall(string id = null, IEnumerable fileSearch = null) { - retrieval ??= new Dictionary(); + fileSearch ??= new List(); - return new RunStepRetrievalToolCall("retrieval", id, serializedAdditionalRawData: null, retrieval); + return new RunStepFileSearchToolCall("file_search", id, serializedAdditionalRawData: null, fileSearch?.ToList()); + } + + /// Initializes a new instance of . + /// The ID of the file that result was found in. + /// The name of the file that result was found in. + /// The score of the result. All values must be a floating point number between 0 and 1. + /// The content of the result that was found. The content is only included if requested via the include query parameter. + /// A new instance for mocking. + public static FileSearchToolCallResult FileSearchToolCallResult(string fileId = null, string fileName = null, double score = default, IEnumerable content = null) + { + content ??= new List(); + + return new FileSearchToolCallResult(fileId, fileName, score, content?.ToList(), serializedAdditionalRawData: null); + } + + /// Initializes a new instance of . + /// The type of the content. + /// The text content of the file. + /// A new instance for mocking. + public static FileSearchToolCallResultContentItem FileSearchToolCallResultContentItem(FileSearchToolCallResultContentItemType? type = null, string text = null) + { + return new FileSearchToolCallResultContentItem(type, text, serializedAdditionalRawData: null); } /// Initializes a new instance of . @@ -230,6 +414,16 @@ public static RunStepError RunStepError(RunStepErrorCode code = default, string return new RunStepError(code, message, serializedAdditionalRawData: null); } + /// Initializes a new instance of . + /// Number of completion tokens used over the course of the run step. + /// Number of prompt tokens used over the course of the run step. + /// Total number of tokens used (prompt + completion). + /// A new instance for mocking. + public static RunStepCompletionUsage RunStepCompletionUsage(long completionTokens = default, long promptTokens = default, long totalTokens = default) + { + return new RunStepCompletionUsage(completionTokens, promptTokens, totalTokens, serializedAdditionalRawData: null); + } + /// Initializes a new instance of . /// The file data (not filename) to upload. /// The intended purpose of the file. @@ -239,5 +433,478 @@ public static UploadFileRequest UploadFileRequest(Stream data = null, OpenAIFile { return new UploadFileRequest(data, purpose, filename, serializedAdditionalRawData: null); } + + /// Initializes a new instance of . + /// The object type, which is always list. + /// The requested list of items. + /// The first ID represented in this list. + /// The last ID represented in this list. + /// A value indicating whether there are additional values available not captured in this list. + /// A new instance for mocking. + public static OpenAIPageableListOfVectorStore OpenAIPageableListOfVectorStore(OpenAIPageableListOfVectorStoreObject @object = default, IEnumerable data = null, string firstId = null, string lastId = null, bool hasMore = default) + { + data ??= new List(); + + return new OpenAIPageableListOfVectorStore( + @object, + data?.ToList(), + firstId, + lastId, + hasMore, + serializedAdditionalRawData: null); + } + + /// Initializes a new instance of . + /// The identifier, which can be referenced in API endpoints. + /// The object type, which is always `vector_store`. + /// The Unix timestamp (in seconds) for when the vector store was created. + /// The name of the vector store. + /// The total number of bytes used by the files in the vector store. + /// Files count grouped by status processed or being processed by this vector store. + /// The status of the vector store, which can be either `expired`, `in_progress`, or `completed`. A status of `completed` indicates that the vector store is ready for use. + /// Details on when this vector store expires. + /// The Unix timestamp (in seconds) for when the vector store will expire. + /// The Unix timestamp (in seconds) for when the vector store was last active. + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + /// A new instance for mocking. + public static VectorStore VectorStore(string id = null, VectorStoreObject @object = default, DateTimeOffset createdAt = default, string name = null, int usageBytes = default, VectorStoreFileCount fileCounts = null, VectorStoreStatus status = default, VectorStoreExpirationPolicy expiresAfter = null, DateTimeOffset? expiresAt = null, DateTimeOffset? lastActiveAt = null, IReadOnlyDictionary metadata = null) + { + metadata ??= new Dictionary(); + + return new VectorStore( + id, + @object, + createdAt, + name, + usageBytes, + fileCounts, + status, + expiresAfter, + expiresAt, + lastActiveAt, + metadata, + serializedAdditionalRawData: null); + } + + /// Initializes a new instance of . + /// The number of files that are currently being processed. + /// The number of files that have been successfully processed. + /// The number of files that have failed to process. + /// The number of files that were cancelled. + /// The total number of files. + /// A new instance for mocking. + public static VectorStoreFileCount VectorStoreFileCount(int inProgress = default, int completed = default, int failed = default, int cancelled = default, int total = default) + { + return new VectorStoreFileCount( + inProgress, + completed, + failed, + cancelled, + total, + serializedAdditionalRawData: null); + } + + /// Initializes a new instance of . + /// The ID of the resource specified for deletion. + /// A value indicating whether deletion was successful. + /// The object type, which is always 'vector_store.deleted'. + /// A new instance for mocking. + public static VectorStoreDeletionStatus VectorStoreDeletionStatus(string id = null, bool deleted = default, VectorStoreDeletionStatusObject @object = default) + { + return new VectorStoreDeletionStatus(id, deleted, @object, serializedAdditionalRawData: null); + } + + /// Initializes a new instance of . + /// The object type, which is always list. + /// The requested list of items. + /// The first ID represented in this list. + /// The last ID represented in this list. + /// A value indicating whether there are additional values available not captured in this list. + /// A new instance for mocking. + public static OpenAIPageableListOfVectorStoreFile OpenAIPageableListOfVectorStoreFile(OpenAIPageableListOfVectorStoreFileObject @object = default, IEnumerable data = null, string firstId = null, string lastId = null, bool hasMore = default) + { + data ??= new List(); + + return new OpenAIPageableListOfVectorStoreFile( + @object, + data?.ToList(), + firstId, + lastId, + hasMore, + serializedAdditionalRawData: null); + } + + /// Initializes a new instance of . + /// The identifier, which can be referenced in API endpoints. + /// The object type, which is always `vector_store.file`. + /// + /// The total vector store usage in bytes. Note that this may be different from the original file + /// size. + /// + /// The Unix timestamp (in seconds) for when the vector store file was created. + /// The ID of the vector store that the file is attached to. + /// The status of the vector store file, which can be either `in_progress`, `completed`, `cancelled`, or `failed`. The status `completed` indicates that the vector store file is ready for use. + /// The last error associated with this vector store file. Will be `null` if there are no errors. + /// + /// The strategy used to chunk the file. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include and . + /// + /// A new instance for mocking. + public static VectorStoreFile VectorStoreFile(string id = null, VectorStoreFileObject @object = default, int usageBytes = default, DateTimeOffset createdAt = default, string vectorStoreId = null, VectorStoreFileStatus status = default, VectorStoreFileError lastError = null, VectorStoreChunkingStrategyResponse chunkingStrategy = null) + { + return new VectorStoreFile( + id, + @object, + usageBytes, + createdAt, + vectorStoreId, + status, + lastError, + chunkingStrategy, + serializedAdditionalRawData: null); + } + + /// Initializes a new instance of . + /// One of `server_error` or `rate_limit_exceeded`. + /// A human-readable description of the error. + /// A new instance for mocking. + public static VectorStoreFileError VectorStoreFileError(VectorStoreFileErrorCode code = default, string message = null) + { + return new VectorStoreFileError(code, message, serializedAdditionalRawData: null); + } + + /// Initializes a new instance of . + /// The options for the static chunking strategy. + /// A new instance for mocking. + public static VectorStoreStaticChunkingStrategyResponse VectorStoreStaticChunkingStrategyResponse(VectorStoreStaticChunkingStrategyOptions @static = null) + { + return new VectorStoreStaticChunkingStrategyResponse(VectorStoreChunkingStrategyResponseType.Static, serializedAdditionalRawData: null, @static); + } + + /// Initializes a new instance of . + /// The ID of the resource specified for deletion. + /// A value indicating whether deletion was successful. + /// The object type, which is always 'vector_store.deleted'. + /// A new instance for mocking. + public static VectorStoreFileDeletionStatus VectorStoreFileDeletionStatus(string id = null, bool deleted = default, VectorStoreFileDeletionStatusObject @object = default) + { + return new VectorStoreFileDeletionStatus(id, deleted, @object, serializedAdditionalRawData: null); + } + + /// Initializes a new instance of . + /// The identifier, which can be referenced in API endpoints. + /// The object type, which is always `vector_store.file_batch`. + /// The Unix timestamp (in seconds) for when the vector store files batch was created. + /// The ID of the vector store that the file is attached to. + /// The status of the vector store files batch, which can be either `in_progress`, `completed`, `cancelled` or `failed`. + /// Files count grouped by status processed or being processed by this vector store. + /// A new instance for mocking. + public static VectorStoreFileBatch VectorStoreFileBatch(string id = null, VectorStoreFileBatchObject @object = default, DateTimeOffset createdAt = default, string vectorStoreId = null, VectorStoreFileBatchStatus status = default, VectorStoreFileCount fileCounts = null) + { + return new VectorStoreFileBatch( + id, + @object, + createdAt, + vectorStoreId, + status, + fileCounts, + serializedAdditionalRawData: null); + } + + /// Initializes a new instance of . + /// The identifier of the message, which can be referenced in API endpoints. + /// The object type, which is always `thread.message.delta`. + /// The delta containing the fields that have changed on the Message. + /// A new instance for mocking. + public static MessageDeltaChunk MessageDeltaChunk(string id = null, MessageDeltaChunkObject @object = default, MessageDelta delta = null) + { + return new MessageDeltaChunk(id, @object, delta, serializedAdditionalRawData: null); + } + + /// Initializes a new instance of . + /// The entity that produced the message. + /// + /// The content of the message as an array of text and/or images. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include and . + /// + /// A new instance for mocking. + public static MessageDelta MessageDelta(MessageRole role = default, IEnumerable content = null) + { + content ??= new List(); + + return new MessageDelta(role, content?.ToList(), serializedAdditionalRawData: null); + } + + /// Initializes a new instance of . + /// The index of the content part of the message. + /// The type of content for this content part. + /// A new instance for mocking. + public static MessageDeltaContent MessageDeltaContent(int index = default, string type = null) + { + return new UnknownMessageDeltaContent(index, type, serializedAdditionalRawData: null); + } + + /// Initializes a new instance of . + /// The index of the content part of the message. + /// The image_file data. + /// A new instance for mocking. + public static MessageDeltaImageFileContent MessageDeltaImageFileContent(int index = default, MessageDeltaImageFileContentObject imageFile = null) + { + return new MessageDeltaImageFileContent(index, "image_file", serializedAdditionalRawData: null, imageFile); + } + + /// Initializes a new instance of . + /// The file ID of the image in the message content. + /// A new instance for mocking. + public static MessageDeltaImageFileContentObject MessageDeltaImageFileContentObject(string fileId = null) + { + return new MessageDeltaImageFileContentObject(fileId, serializedAdditionalRawData: null); + } + + /// Initializes a new instance of . + /// The index of the content part of the message. + /// The text content details. + /// A new instance for mocking. + public static MessageDeltaTextContentObject MessageDeltaTextContentObject(int index = default, MessageDeltaTextContent text = null) + { + return new MessageDeltaTextContentObject(index, "text", serializedAdditionalRawData: null, text); + } + + /// Initializes a new instance of . + /// The data that makes up the text. + /// + /// Annotations for the text. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include and . + /// + /// A new instance for mocking. + public static MessageDeltaTextContent MessageDeltaTextContent(string value = null, IEnumerable annotations = null) + { + annotations ??= new List(); + + return new MessageDeltaTextContent(value, annotations?.ToList(), serializedAdditionalRawData: null); + } + + /// Initializes a new instance of . + /// The index of the annotation within a text content part. + /// The type of the text content annotation. + /// A new instance for mocking. + public static MessageDeltaTextAnnotation MessageDeltaTextAnnotation(int index = default, string type = null) + { + return new UnknownMessageDeltaTextAnnotation(index, type, serializedAdditionalRawData: null); + } + + /// Initializes a new instance of . + /// The index of the annotation within a text content part. + /// The file citation information. + /// The text in the message content that needs to be replaced. + /// The start index of this annotation in the content text. + /// The end index of this annotation in the content text. + /// A new instance for mocking. + public static MessageDeltaTextFileCitationAnnotationObject MessageDeltaTextFileCitationAnnotationObject(int index = default, MessageDeltaTextFileCitationAnnotation fileCitation = null, string text = null, int? startIndex = null, int? endIndex = null) + { + return new MessageDeltaTextFileCitationAnnotationObject( + index, + "file_citation", + serializedAdditionalRawData: null, + fileCitation, + text, + startIndex, + endIndex); + } + + /// Initializes a new instance of . + /// The ID of the specific file the citation is from. + /// The specific quote in the cited file. + /// A new instance for mocking. + public static MessageDeltaTextFileCitationAnnotation MessageDeltaTextFileCitationAnnotation(string fileId = null, string quote = null) + { + return new MessageDeltaTextFileCitationAnnotation(fileId, quote, serializedAdditionalRawData: null); + } + + /// Initializes a new instance of . + /// The index of the annotation within a text content part. + /// The file path information. + /// The start index of this annotation in the content text. + /// The end index of this annotation in the content text. + /// The text in the message content that needs to be replaced. + /// A new instance for mocking. + public static MessageDeltaTextFilePathAnnotationObject MessageDeltaTextFilePathAnnotationObject(int index = default, MessageDeltaTextFilePathAnnotation filePath = null, int? startIndex = null, int? endIndex = null, string text = null) + { + return new MessageDeltaTextFilePathAnnotationObject( + index, + "file_path", + serializedAdditionalRawData: null, + filePath, + startIndex, + endIndex, + text); + } + + /// Initializes a new instance of . + /// The file ID for the annotation. + /// A new instance for mocking. + public static MessageDeltaTextFilePathAnnotation MessageDeltaTextFilePathAnnotation(string fileId = null) + { + return new MessageDeltaTextFilePathAnnotation(fileId, serializedAdditionalRawData: null); + } + + /// Initializes a new instance of . + /// The identifier of the run step, which can be referenced in API endpoints. + /// The object type, which is always `thread.run.step.delta`. + /// The delta containing the fields that have changed on the run step. + /// A new instance for mocking. + public static RunStepDeltaChunk RunStepDeltaChunk(string id = null, RunStepDeltaChunkObject @object = default, RunStepDelta delta = null) + { + return new RunStepDeltaChunk(id, @object, delta, serializedAdditionalRawData: null); + } + + /// Initializes a new instance of . + /// + /// The details of the run step. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include and . + /// + /// A new instance for mocking. + public static RunStepDelta RunStepDelta(RunStepDeltaDetail stepDetails = null) + { + return new RunStepDelta(stepDetails, serializedAdditionalRawData: null); + } + + /// Initializes a new instance of . + /// The message creation data. + /// A new instance for mocking. + public static RunStepDeltaMessageCreation RunStepDeltaMessageCreation(RunStepDeltaMessageCreationObject messageCreation = null) + { + return new RunStepDeltaMessageCreation("message_creation", serializedAdditionalRawData: null, messageCreation); + } + + /// Initializes a new instance of . + /// The ID of the newly-created message. + /// A new instance for mocking. + public static RunStepDeltaMessageCreationObject RunStepDeltaMessageCreationObject(string messageId = null) + { + return new RunStepDeltaMessageCreationObject(messageId, serializedAdditionalRawData: null); + } + + /// Initializes a new instance of . + /// + /// The collection of tool calls for the tool call detail item. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include , and . + /// + /// A new instance for mocking. + public static RunStepDeltaToolCallObject RunStepDeltaToolCallObject(IEnumerable toolCalls = null) + { + toolCalls ??= new List(); + + return new RunStepDeltaToolCallObject("tool_calls", serializedAdditionalRawData: null, toolCalls?.ToList()); + } + + /// Initializes a new instance of . + /// The index of the tool call detail in the run step's tool_calls array. + /// The ID of the tool call, used when submitting outputs to the run. + /// The type of the tool call detail item in a streaming run step's details. + /// A new instance for mocking. + public static RunStepDeltaToolCall RunStepDeltaToolCall(int index = default, string id = null, string type = null) + { + return new UnknownRunStepDeltaToolCall(index, id, type, serializedAdditionalRawData: null); + } + + /// Initializes a new instance of . + /// The index of the tool call detail in the run step's tool_calls array. + /// The ID of the tool call, used when submitting outputs to the run. + /// The function data for the tool call. + /// A new instance for mocking. + public static RunStepDeltaFunctionToolCall RunStepDeltaFunctionToolCall(int index = default, string id = null, RunStepDeltaFunction function = null) + { + return new RunStepDeltaFunctionToolCall(index, id, "function", serializedAdditionalRawData: null, function); + } + + /// Initializes a new instance of . + /// The name of the function. + /// The arguments passed to the function as input. + /// The output of the function, null if outputs have not yet been submitted. + /// A new instance for mocking. + public static RunStepDeltaFunction RunStepDeltaFunction(string name = null, string arguments = null, string output = null) + { + return new RunStepDeltaFunction(name, arguments, output, serializedAdditionalRawData: null); + } + + /// Initializes a new instance of . + /// The index of the tool call detail in the run step's tool_calls array. + /// The ID of the tool call, used when submitting outputs to the run. + /// Reserved for future use. + /// A new instance for mocking. + public static RunStepDeltaFileSearchToolCall RunStepDeltaFileSearchToolCall(int index = default, string id = null, IReadOnlyDictionary fileSearch = null) + { + fileSearch ??= new Dictionary(); + + return new RunStepDeltaFileSearchToolCall(index, id, "file_search", serializedAdditionalRawData: null, fileSearch); + } + + /// Initializes a new instance of . + /// The index of the tool call detail in the run step's tool_calls array. + /// The ID of the tool call, used when submitting outputs to the run. + /// The Code Interpreter data for the tool call. + /// A new instance for mocking. + public static RunStepDeltaCodeInterpreterToolCall RunStepDeltaCodeInterpreterToolCall(int index = default, string id = null, RunStepDeltaCodeInterpreterDetailItemObject codeInterpreter = null) + { + return new RunStepDeltaCodeInterpreterToolCall(index, id, "code_interpreter", serializedAdditionalRawData: null, codeInterpreter); + } + + /// Initializes a new instance of . + /// The input into the Code Interpreter tool call. + /// + /// The outputs from the Code Interpreter tool call. Code Interpreter can output one or more + /// items, including text (`logs`) or images (`image`). Each of these are represented by a + /// different object type. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include and . + /// + /// A new instance for mocking. + public static RunStepDeltaCodeInterpreterDetailItemObject RunStepDeltaCodeInterpreterDetailItemObject(string input = null, IEnumerable outputs = null) + { + outputs ??= new List(); + + return new RunStepDeltaCodeInterpreterDetailItemObject(input, outputs?.ToList(), serializedAdditionalRawData: null); + } + + /// Initializes a new instance of . + /// The index of the output in the streaming run step tool call's Code Interpreter outputs array. + /// The type of the streaming run step tool call's Code Interpreter output. + /// A new instance for mocking. + public static RunStepDeltaCodeInterpreterOutput RunStepDeltaCodeInterpreterOutput(int index = default, string type = null) + { + return new UnknownRunStepDeltaCodeInterpreterOutput(index, type, serializedAdditionalRawData: null); + } + + /// Initializes a new instance of . + /// The index of the output in the streaming run step tool call's Code Interpreter outputs array. + /// The text output from the Code Interpreter tool call. + /// A new instance for mocking. + public static RunStepDeltaCodeInterpreterLogOutput RunStepDeltaCodeInterpreterLogOutput(int index = default, string logs = null) + { + return new RunStepDeltaCodeInterpreterLogOutput(index, "logs", serializedAdditionalRawData: null, logs); + } + + /// Initializes a new instance of . + /// The index of the output in the streaming run step tool call's Code Interpreter outputs array. + /// The image data for the Code Interpreter tool call output. + /// A new instance for mocking. + public static RunStepDeltaCodeInterpreterImageOutput RunStepDeltaCodeInterpreterImageOutput(int index = default, RunStepDeltaCodeInterpreterImageOutputObject image = null) + { + return new RunStepDeltaCodeInterpreterImageOutput(index, "image", serializedAdditionalRawData: null, image); + } + + /// Initializes a new instance of . + /// The file ID for the image. + /// A new instance for mocking. + public static RunStepDeltaCodeInterpreterImageOutputObject RunStepDeltaCodeInterpreterImageOutputObject(string fileId = null) + { + return new RunStepDeltaCodeInterpreterImageOutputObject(fileId, serializedAdditionalRawData: null); + } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsNamedToolChoice.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsNamedToolChoice.Serialization.cs new file mode 100644 index 000000000000..4c078f9fe11d --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsNamedToolChoice.Serialization.cs @@ -0,0 +1,157 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class AssistantsNamedToolChoice : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(AssistantsNamedToolChoice)} does not support writing '{format}' format."); + } + + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type.ToString()); + if (Optional.IsDefined(Function)) + { + writer.WritePropertyName("function"u8); + writer.WriteObjectValue(Function, options); + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + AssistantsNamedToolChoice 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(AssistantsNamedToolChoice)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeAssistantsNamedToolChoice(document.RootElement, options); + } + + internal static AssistantsNamedToolChoice DeserializeAssistantsNamedToolChoice(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + AssistantsNamedToolChoiceType type = default; + FunctionName function = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("type"u8)) + { + type = new AssistantsNamedToolChoiceType(property.Value.GetString()); + continue; + } + if (property.NameEquals("function"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + function = FunctionName.DeserializeFunctionName(property.Value, options); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new AssistantsNamedToolChoice(type, function, 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(AssistantsNamedToolChoice)} does not support writing '{options.Format}' format."); + } + } + + AssistantsNamedToolChoice 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeAssistantsNamedToolChoice(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(AssistantsNamedToolChoice)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static AssistantsNamedToolChoice FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeAssistantsNamedToolChoice(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsNamedToolChoice.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsNamedToolChoice.cs new file mode 100644 index 000000000000..b0da555fe4a1 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsNamedToolChoice.cs @@ -0,0 +1,76 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Specifies a tool the model should use. Use to force the model to call a specific tool. + public partial class AssistantsNamedToolChoice + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + /// the type of tool. If type is `function`, the function name must be set. + public AssistantsNamedToolChoice(AssistantsNamedToolChoiceType type) + { + Type = type; + } + + /// Initializes a new instance of . + /// the type of tool. If type is `function`, the function name must be set. + /// The name of the function to call. + /// Keeps track of any properties unknown to the library. + internal AssistantsNamedToolChoice(AssistantsNamedToolChoiceType type, FunctionName function, IDictionary serializedAdditionalRawData) + { + Type = type; + Function = function; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal AssistantsNamedToolChoice() + { + } + + /// the type of tool. If type is `function`, the function name must be set. + public AssistantsNamedToolChoiceType Type { get; set; } + /// The name of the function to call. + public FunctionName Function { get; set; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsNamedToolChoiceType.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsNamedToolChoiceType.cs new file mode 100644 index 000000000000..0d049b86843b --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantsNamedToolChoiceType.cs @@ -0,0 +1,54 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Available tool types for assistants named tools. + public readonly partial struct AssistantsNamedToolChoiceType : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public AssistantsNamedToolChoiceType(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string FunctionValue = "function"; + private const string CodeInterpreterValue = "code_interpreter"; + private const string FileSearchValue = "file_search"; + + /// Tool type `function`. + public static AssistantsNamedToolChoiceType Function { get; } = new AssistantsNamedToolChoiceType(FunctionValue); + /// Tool type `code_interpreter`. + public static AssistantsNamedToolChoiceType CodeInterpreter { get; } = new AssistantsNamedToolChoiceType(CodeInterpreterValue); + /// Tool type `file_search`. + public static AssistantsNamedToolChoiceType FileSearch { get; } = new AssistantsNamedToolChoiceType(FileSearchValue); + /// Determines if two values are the same. + public static bool operator ==(AssistantsNamedToolChoiceType left, AssistantsNamedToolChoiceType right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(AssistantsNamedToolChoiceType left, AssistantsNamedToolChoiceType right) => !left.Equals(right); + /// Converts a to a . + public static implicit operator AssistantsNamedToolChoiceType(string value) => new AssistantsNamedToolChoiceType(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is AssistantsNamedToolChoiceType other && Equals(other); + /// + public bool Equals(AssistantsNamedToolChoiceType 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/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolResource.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolResource.Serialization.cs new file mode 100644 index 000000000000..3274271efb84 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolResource.Serialization.cs @@ -0,0 +1,152 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class CodeInterpreterToolResource : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(CodeInterpreterToolResource)} does not support writing '{format}' format."); + } + + writer.WritePropertyName("file_ids"u8); + writer.WriteStartArray(); + foreach (var item in FileIds) + { + writer.WriteStringValue(item); + } + writer.WriteEndArray(); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + CodeInterpreterToolResource 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(CodeInterpreterToolResource)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeCodeInterpreterToolResource(document.RootElement, options); + } + + internal static CodeInterpreterToolResource DeserializeCodeInterpreterToolResource(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + IReadOnlyList fileIds = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("file_ids"u8)) + { + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(item.GetString()); + } + fileIds = array; + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new CodeInterpreterToolResource(fileIds, 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(CodeInterpreterToolResource)} does not support writing '{options.Format}' format."); + } + } + + CodeInterpreterToolResource 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeCodeInterpreterToolResource(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(CodeInterpreterToolResource)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static CodeInterpreterToolResource FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeCodeInterpreterToolResource(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolResource.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolResource.cs new file mode 100644 index 000000000000..a0a185a491bc --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CodeInterpreterToolResource.cs @@ -0,0 +1,85 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Azure.AI.OpenAI.Assistants +{ + /// A set of resources that are used by the `code_interpreter` tool. + public partial class CodeInterpreterToolResource + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + /// + /// A list of file IDs made available to the `code_interpreter` tool. There can be a maximum of 20 files + /// associated with the tool. + /// + /// is null. + internal CodeInterpreterToolResource(IEnumerable fileIds) + { + Argument.AssertNotNull(fileIds, nameof(fileIds)); + + FileIds = fileIds.ToList(); + } + + /// Initializes a new instance of . + /// + /// A list of file IDs made available to the `code_interpreter` tool. There can be a maximum of 20 files + /// associated with the tool. + /// + /// Keeps track of any properties unknown to the library. + internal CodeInterpreterToolResource(IReadOnlyList fileIds, IDictionary serializedAdditionalRawData) + { + FileIds = fileIds; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal CodeInterpreterToolResource() + { + } + + /// + /// A list of file IDs made available to the `code_interpreter` tool. There can be a maximum of 20 files + /// associated with the tool. + /// + public IReadOnlyList FileIds { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateAndRunThreadOptions.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateAndRunThreadOptions.Serialization.cs index 79d6c0e271fe..18ad0dc83511 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateAndRunThreadOptions.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateAndRunThreadOptions.Serialization.cs @@ -43,23 +43,164 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit } if (Optional.IsDefined(OverrideModelName)) { - writer.WritePropertyName("model"u8); - writer.WriteStringValue(OverrideModelName); + if (OverrideModelName != null) + { + writer.WritePropertyName("model"u8); + writer.WriteStringValue(OverrideModelName); + } + else + { + writer.WriteNull("model"); + } } if (Optional.IsDefined(OverrideInstructions)) { - writer.WritePropertyName("instructions"u8); - writer.WriteStringValue(OverrideInstructions); + if (OverrideInstructions != null) + { + writer.WritePropertyName("instructions"u8); + writer.WriteStringValue(OverrideInstructions); + } + else + { + writer.WriteNull("instructions"); + } } if (Optional.IsCollectionDefined(OverrideTools)) { - writer.WritePropertyName("tools"u8); - writer.WriteStartArray(); - foreach (var item in OverrideTools) + if (OverrideTools != null) + { + writer.WritePropertyName("tools"u8); + writer.WriteStartArray(); + foreach (var item in OverrideTools) + { + writer.WriteObjectValue(item, options); + } + writer.WriteEndArray(); + } + else + { + writer.WriteNull("tools"); + } + } + if (Optional.IsDefined(ParallelToolCalls)) + { + writer.WritePropertyName("parallel_tool_calls"u8); + writer.WriteBooleanValue(ParallelToolCalls.Value); + } + if (Optional.IsDefined(ToolResources)) + { + if (ToolResources != null) { - writer.WriteObjectValue(item, options); + writer.WritePropertyName("tool_resources"u8); + writer.WriteObjectValue(ToolResources, options); + } + else + { + writer.WriteNull("tool_resources"); + } + } + if (Optional.IsDefined(Stream)) + { + writer.WritePropertyName("stream"u8); + writer.WriteBooleanValue(Stream.Value); + } + if (Optional.IsDefined(Temperature)) + { + if (Temperature != null) + { + writer.WritePropertyName("temperature"u8); + writer.WriteNumberValue(Temperature.Value); + } + else + { + writer.WriteNull("temperature"); + } + } + if (Optional.IsDefined(TopP)) + { + if (TopP != null) + { + writer.WritePropertyName("top_p"u8); + writer.WriteNumberValue(TopP.Value); + } + else + { + writer.WriteNull("top_p"); + } + } + if (Optional.IsDefined(MaxPromptTokens)) + { + if (MaxPromptTokens != null) + { + writer.WritePropertyName("max_prompt_tokens"u8); + writer.WriteNumberValue(MaxPromptTokens.Value); + } + else + { + writer.WriteNull("max_prompt_tokens"); + } + } + if (Optional.IsDefined(MaxCompletionTokens)) + { + if (MaxCompletionTokens != null) + { + writer.WritePropertyName("max_completion_tokens"u8); + writer.WriteNumberValue(MaxCompletionTokens.Value); + } + else + { + writer.WriteNull("max_completion_tokens"); + } + } + if (Optional.IsDefined(TruncationStrategy)) + { + if (TruncationStrategy != null) + { + writer.WritePropertyName("truncation_strategy"u8); + writer.WriteObjectValue(TruncationStrategy, options); + } + else + { + writer.WriteNull("truncation_strategy"); + } + } + if (Optional.IsDefined(ToolChoice)) + { + if (ToolChoice != null) + { + writer.WritePropertyName("tool_choice"u8); +#if NET6_0_OR_GREATER + writer.WriteRawValue(ToolChoice); +#else + using (JsonDocument document = JsonDocument.Parse(ToolChoice, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + else + { + writer.WriteNull("tool_choice"); + } + } + if (Optional.IsDefined(ResponseFormat)) + { + if (ResponseFormat != null) + { + writer.WritePropertyName("response_format"u8); +#if NET6_0_OR_GREATER + writer.WriteRawValue(ResponseFormat); +#else + using (JsonDocument document = JsonDocument.Parse(ResponseFormat, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + else + { + writer.WriteNull("response_format"); } - writer.WriteEndArray(); } if (Optional.IsCollectionDefined(Metadata)) { @@ -121,6 +262,16 @@ internal static CreateAndRunThreadOptions DeserializeCreateAndRunThreadOptions(J string model = default; string instructions = default; IList tools = default; + bool? parallelToolCalls = default; + UpdateToolResourcesOptions toolResources = default; + bool? stream = default; + float? temperature = default; + float? topP = default; + int? maxPromptTokens = default; + int? maxCompletionTokens = default; + TruncationObject truncationStrategy = default; + BinaryData toolChoice = default; + BinaryData responseFormat = default; IDictionary metadata = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); @@ -142,11 +293,21 @@ internal static CreateAndRunThreadOptions DeserializeCreateAndRunThreadOptions(J } if (property.NameEquals("model"u8)) { + if (property.Value.ValueKind == JsonValueKind.Null) + { + model = null; + continue; + } model = property.Value.GetString(); continue; } if (property.NameEquals("instructions"u8)) { + if (property.Value.ValueKind == JsonValueKind.Null) + { + instructions = null; + continue; + } instructions = property.Value.GetString(); continue; } @@ -164,6 +325,104 @@ internal static CreateAndRunThreadOptions DeserializeCreateAndRunThreadOptions(J tools = array; continue; } + if (property.NameEquals("parallel_tool_calls"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + parallelToolCalls = property.Value.GetBoolean(); + continue; + } + if (property.NameEquals("tool_resources"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + toolResources = null; + continue; + } + toolResources = UpdateToolResourcesOptions.DeserializeUpdateToolResourcesOptions(property.Value, options); + continue; + } + if (property.NameEquals("stream"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + stream = property.Value.GetBoolean(); + continue; + } + if (property.NameEquals("temperature"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + temperature = null; + continue; + } + temperature = property.Value.GetSingle(); + continue; + } + if (property.NameEquals("top_p"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + topP = null; + continue; + } + topP = property.Value.GetSingle(); + continue; + } + if (property.NameEquals("max_prompt_tokens"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + maxPromptTokens = null; + continue; + } + maxPromptTokens = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("max_completion_tokens"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + maxCompletionTokens = null; + continue; + } + maxCompletionTokens = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("truncation_strategy"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + truncationStrategy = null; + continue; + } + truncationStrategy = TruncationObject.DeserializeTruncationObject(property.Value, options); + continue; + } + if (property.NameEquals("tool_choice"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + toolChoice = null; + continue; + } + toolChoice = BinaryData.FromString(property.Value.GetRawText()); + continue; + } + if (property.NameEquals("response_format"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + responseFormat = null; + continue; + } + responseFormat = BinaryData.FromString(property.Value.GetRawText()); + continue; + } if (property.NameEquals("metadata"u8)) { if (property.Value.ValueKind == JsonValueKind.Null) @@ -190,6 +449,16 @@ internal static CreateAndRunThreadOptions DeserializeCreateAndRunThreadOptions(J model, instructions, tools ?? new ChangeTrackingList(), + parallelToolCalls, + toolResources, + stream, + temperature, + topP, + maxPromptTokens, + maxCompletionTokens, + truncationStrategy, + toolChoice, + responseFormat, metadata ?? new ChangeTrackingDictionary(), serializedAdditionalRawData); } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateAndRunThreadOptions.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateAndRunThreadOptions.cs index cf9c983195f7..16f117a439d8 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateAndRunThreadOptions.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateAndRunThreadOptions.cs @@ -59,23 +59,63 @@ public CreateAndRunThreadOptions(string assistantId) /// Initializes a new instance of . /// The ID of the assistant for which the thread should be created. - /// The details used to create the new thread. + /// The details used to create the new thread. If no thread is provided, an empty one will be created. /// The overridden model that the assistant should use to run the thread. /// The overridden system instructions the assistant should use to run the thread. /// /// The overridden list of enabled tools the assistant should use to run the thread. /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. - /// The available derived classes include , and . + /// The available derived classes include , and . /// + /// Whether to enable parallel function calling during tool use. + /// Override the tools the assistant can use for this run. This is useful for modifying the behavior on a per-run basis. + /// + /// If `true`, returns a stream of events that happen during the Run as server-sent events, + /// terminating when the Run enters a terminal state with a `data: [DONE]` message. + /// + /// + /// What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output + /// more random, while lower values like 0.2 will make it more focused and deterministic. + /// + /// + /// An alternative to sampling with temperature, called nucleus sampling, where the model + /// considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens + /// comprising the top 10% probability mass are considered. + /// + /// We generally recommend altering this or temperature but not both. + /// + /// + /// The maximum number of prompt tokens that may be used over the course of the run. The run will make a best effort to use only + /// the number of prompt tokens specified, across multiple turns of the run. If the run exceeds the number of prompt tokens specified, + /// the run will end with status `incomplete`. See `incomplete_details` for more info. + /// + /// + /// The maximum number of completion tokens that may be used over the course of the run. The run will make a best effort to use only + /// the number of completion tokens specified, across multiple turns of the run. If the run exceeds the number of completion tokens + /// specified, the run will end with status `incomplete`. See `incomplete_details` for more info. + /// + /// The strategy to use for dropping messages as the context windows moves forward. + /// Controls whether or not and which tool is called by the model. + /// Specifies the format that the model must output. /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. /// Keeps track of any properties unknown to the library. - internal CreateAndRunThreadOptions(string assistantId, AssistantThreadCreationOptions thread, string overrideModelName, string overrideInstructions, IList overrideTools, IDictionary metadata, IDictionary serializedAdditionalRawData) + internal CreateAndRunThreadOptions(string assistantId, AssistantThreadCreationOptions thread, string overrideModelName, string overrideInstructions, IList overrideTools, bool? parallelToolCalls, UpdateToolResourcesOptions toolResources, bool? stream, float? temperature, float? topP, int? maxPromptTokens, int? maxCompletionTokens, TruncationObject truncationStrategy, BinaryData toolChoice, BinaryData responseFormat, IDictionary metadata, IDictionary serializedAdditionalRawData) { AssistantId = assistantId; Thread = thread; OverrideModelName = overrideModelName; OverrideInstructions = overrideInstructions; OverrideTools = overrideTools; + ParallelToolCalls = parallelToolCalls; + ToolResources = toolResources; + Stream = stream; + Temperature = temperature; + TopP = topP; + MaxPromptTokens = maxPromptTokens; + MaxCompletionTokens = maxCompletionTokens; + TruncationStrategy = truncationStrategy; + ToolChoice = toolChoice; + ResponseFormat = responseFormat; Metadata = metadata; _serializedAdditionalRawData = serializedAdditionalRawData; } @@ -87,7 +127,7 @@ internal CreateAndRunThreadOptions() /// The ID of the assistant for which the thread should be created. public string AssistantId { get; } - /// The details used to create the new thread. + /// The details used to create the new thread. If no thread is provided, an empty one will be created. public AssistantThreadCreationOptions Thread { get; set; } /// The overridden model that the assistant should use to run the thread. public string OverrideModelName { get; set; } @@ -96,9 +136,135 @@ internal CreateAndRunThreadOptions() /// /// The overridden list of enabled tools the assistant should use to run the thread. /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. - /// The available derived classes include , and . + /// The available derived classes include , and . + /// + public IList OverrideTools { get; set; } + /// Whether to enable parallel function calling during tool use. + public bool? ParallelToolCalls { get; set; } + /// Override the tools the assistant can use for this run. This is useful for modifying the behavior on a per-run basis. + public UpdateToolResourcesOptions ToolResources { get; set; } + /// + /// If `true`, returns a stream of events that happen during the Run as server-sent events, + /// terminating when the Run enters a terminal state with a `data: [DONE]` message. + /// + public bool? Stream { get; set; } + /// + /// What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output + /// more random, while lower values like 0.2 will make it more focused and deterministic. + /// + public float? Temperature { get; set; } + /// + /// An alternative to sampling with temperature, called nucleus sampling, where the model + /// considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens + /// comprising the top 10% probability mass are considered. + /// + /// We generally recommend altering this or temperature but not both. + /// + public float? TopP { get; set; } + /// + /// The maximum number of prompt tokens that may be used over the course of the run. The run will make a best effort to use only + /// the number of prompt tokens specified, across multiple turns of the run. If the run exceeds the number of prompt tokens specified, + /// the run will end with status `incomplete`. See `incomplete_details` for more info. + /// + public int? MaxPromptTokens { get; set; } + /// + /// The maximum number of completion tokens that may be used over the course of the run. The run will make a best effort to use only + /// the number of completion tokens specified, across multiple turns of the run. If the run exceeds the number of completion tokens + /// specified, the run will end with status `incomplete`. See `incomplete_details` for more info. + /// + public int? MaxCompletionTokens { get; set; } + /// The strategy to use for dropping messages as the context windows moves forward. + public TruncationObject TruncationStrategy { get; set; } + /// + /// Controls whether or not and which tool is called by the model. + /// + /// To assign an object to this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// + /// Supported types: + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + public BinaryData ToolChoice { get; set; } + /// + /// Specifies the format that the model must output. + /// + /// To assign an object to this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// + /// Supported types: + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// /// - public IList OverrideTools { get; } + public BinaryData ResponseFormat { get; set; } /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. public IDictionary Metadata { get; set; } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateCodeInterpreterToolResourceOptions.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateCodeInterpreterToolResourceOptions.Serialization.cs new file mode 100644 index 000000000000..06a1a7f3f6a6 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateCodeInterpreterToolResourceOptions.Serialization.cs @@ -0,0 +1,159 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class CreateCodeInterpreterToolResourceOptions : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(CreateCodeInterpreterToolResourceOptions)} does not support writing '{format}' format."); + } + + if (Optional.IsCollectionDefined(FileIds)) + { + writer.WritePropertyName("file_ids"u8); + writer.WriteStartArray(); + foreach (var item in FileIds) + { + writer.WriteStringValue(item); + } + writer.WriteEndArray(); + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + CreateCodeInterpreterToolResourceOptions 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(CreateCodeInterpreterToolResourceOptions)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeCreateCodeInterpreterToolResourceOptions(document.RootElement, options); + } + + internal static CreateCodeInterpreterToolResourceOptions DeserializeCreateCodeInterpreterToolResourceOptions(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + IList fileIds = 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 (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new CreateCodeInterpreterToolResourceOptions(fileIds ?? 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(CreateCodeInterpreterToolResourceOptions)} does not support writing '{options.Format}' format."); + } + } + + CreateCodeInterpreterToolResourceOptions 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeCreateCodeInterpreterToolResourceOptions(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(CreateCodeInterpreterToolResourceOptions)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static CreateCodeInterpreterToolResourceOptions FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeCreateCodeInterpreterToolResourceOptions(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateAssistantFileRequest.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateCodeInterpreterToolResourceOptions.cs similarity index 64% rename from sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateAssistantFileRequest.cs rename to sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateCodeInterpreterToolResourceOptions.cs index 5a1af0cc4664..97be44a94098 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateAssistantFileRequest.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateCodeInterpreterToolResourceOptions.cs @@ -10,8 +10,8 @@ namespace Azure.AI.OpenAI.Assistants { - /// The CreateAssistantFileRequest. - internal partial class CreateAssistantFileRequest + /// A set of resources that will be used by the `code_interpreter` tool. Request object. + public partial class CreateCodeInterpreterToolResourceOptions { /// /// Keeps track of any properties unknown to the library. @@ -45,31 +45,22 @@ internal partial class CreateAssistantFileRequest /// private IDictionary _serializedAdditionalRawData; - /// Initializes a new instance of . - /// The ID of the previously uploaded file to attach. - /// is null. - internal CreateAssistantFileRequest(string fileId) + /// Initializes a new instance of . + public CreateCodeInterpreterToolResourceOptions() { - Argument.AssertNotNull(fileId, nameof(fileId)); - - FileId = fileId; + FileIds = new ChangeTrackingList(); } - /// Initializes a new instance of . - /// The ID of the previously uploaded file to attach. + /// Initializes a new instance of . + /// A list of file IDs made available to the `code_interpreter` tool. /// Keeps track of any properties unknown to the library. - internal CreateAssistantFileRequest(string fileId, IDictionary serializedAdditionalRawData) + internal CreateCodeInterpreterToolResourceOptions(IList fileIds, IDictionary serializedAdditionalRawData) { - FileId = fileId; + FileIds = fileIds; _serializedAdditionalRawData = serializedAdditionalRawData; } - /// Initializes a new instance of for deserialization. - internal CreateAssistantFileRequest() - { - } - - /// The ID of the previously uploaded file to attach. - public string FileId { get; } + /// A list of file IDs made available to the `code_interpreter` tool. + public IList FileIds { get; } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadInitializationMessage.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateFileSearchToolResourceVectorStoreOptions.Serialization.cs similarity index 62% rename from sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadInitializationMessage.Serialization.cs rename to sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateFileSearchToolResourceVectorStoreOptions.Serialization.cs index 8bd17c2a1425..3805cd310f8f 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadInitializationMessage.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateFileSearchToolResourceVectorStoreOptions.Serialization.cs @@ -13,11 +13,11 @@ namespace Azure.AI.OpenAI.Assistants { - public partial class ThreadInitializationMessage : IUtf8JsonSerializable, IJsonModel + public partial class CreateFileSearchToolResourceVectorStoreOptions : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { writer.WriteStartObject(); JsonModelWriteCore(writer, options); @@ -28,26 +28,21 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelR /// The client options for reading and writing models. protected virtual void JsonModelWriteCore(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(ThreadInitializationMessage)} does not support writing '{format}' format."); + throw new FormatException($"The model {nameof(CreateFileSearchToolResourceVectorStoreOptions)} does not support writing '{format}' format."); } - writer.WritePropertyName("role"u8); - writer.WriteStringValue(Role.ToString()); - writer.WritePropertyName("content"u8); - writer.WriteStringValue(Content); - if (Optional.IsCollectionDefined(FileIds)) + writer.WritePropertyName("file_ids"u8); + writer.WriteStartArray(); + foreach (var item in FileIds) { - writer.WritePropertyName("file_ids"u8); - writer.WriteStartArray(); - foreach (var item in FileIds) - { - writer.WriteStringValue(item); - } - writer.WriteEndArray(); + writer.WriteStringValue(item); } + writer.WriteEndArray(); + writer.WritePropertyName("chunking_strategy"u8); + writer.WriteObjectValue(ChunkingStrategy, options); if (Optional.IsCollectionDefined(Metadata)) { if (Metadata != null) @@ -83,19 +78,19 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit } } - ThreadInitializationMessage IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + CreateFileSearchToolResourceVectorStoreOptions 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(ThreadInitializationMessage)} does not support reading '{format}' format."); + throw new FormatException($"The model {nameof(CreateFileSearchToolResourceVectorStoreOptions)} does not support reading '{format}' format."); } using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeThreadInitializationMessage(document.RootElement, options); + return DeserializeCreateFileSearchToolResourceVectorStoreOptions(document.RootElement, options); } - internal static ThreadInitializationMessage DeserializeThreadInitializationMessage(JsonElement element, ModelReaderWriterOptions options = null) + internal static CreateFileSearchToolResourceVectorStoreOptions DeserializeCreateFileSearchToolResourceVectorStoreOptions(JsonElement element, ModelReaderWriterOptions options = null) { options ??= ModelSerializationExtensions.WireOptions; @@ -103,30 +98,15 @@ internal static ThreadInitializationMessage DeserializeThreadInitializationMessa { return null; } - MessageRole role = default; - string content = default; IList fileIds = default; + VectorStoreChunkingStrategyRequest chunkingStrategy = default; IDictionary metadata = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { - if (property.NameEquals("role"u8)) - { - role = new MessageRole(property.Value.GetString()); - continue; - } - if (property.NameEquals("content"u8)) - { - content = property.Value.GetString(); - continue; - } if (property.NameEquals("file_ids"u8)) { - if (property.Value.ValueKind == JsonValueKind.Null) - { - continue; - } List array = new List(); foreach (var item in property.Value.EnumerateArray()) { @@ -135,6 +115,11 @@ internal static ThreadInitializationMessage DeserializeThreadInitializationMessa fileIds = array; continue; } + if (property.NameEquals("chunking_strategy"u8)) + { + chunkingStrategy = VectorStoreChunkingStrategyRequest.DeserializeVectorStoreChunkingStrategyRequest(property.Value, options); + continue; + } if (property.NameEquals("metadata"u8)) { if (property.Value.ValueKind == JsonValueKind.Null) @@ -155,46 +140,46 @@ internal static ThreadInitializationMessage DeserializeThreadInitializationMessa } } serializedAdditionalRawData = rawDataDictionary; - return new ThreadInitializationMessage(role, content, fileIds ?? new ChangeTrackingList(), metadata ?? new ChangeTrackingDictionary(), serializedAdditionalRawData); + return new CreateFileSearchToolResourceVectorStoreOptions(fileIds, chunkingStrategy, metadata ?? new ChangeTrackingDictionary(), 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(ThreadInitializationMessage)} does not support writing '{options.Format}' format."); + throw new FormatException($"The model {nameof(CreateFileSearchToolResourceVectorStoreOptions)} does not support writing '{options.Format}' format."); } } - ThreadInitializationMessage IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + CreateFileSearchToolResourceVectorStoreOptions 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, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeThreadInitializationMessage(document.RootElement, options); + return DeserializeCreateFileSearchToolResourceVectorStoreOptions(document.RootElement, options); } default: - throw new FormatException($"The model {nameof(ThreadInitializationMessage)} does not support reading '{options.Format}' format."); + throw new FormatException($"The model {nameof(CreateFileSearchToolResourceVectorStoreOptions)} does not support reading '{options.Format}' format."); } } - string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; /// Deserializes the model from a raw response. /// The response to deserialize the model from. - internal static ThreadInitializationMessage FromResponse(Response response) + internal static CreateFileSearchToolResourceVectorStoreOptions FromResponse(Response response) { using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeThreadInitializationMessage(document.RootElement); + return DeserializeCreateFileSearchToolResourceVectorStoreOptions(document.RootElement); } /// Convert into a . diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateFileSearchToolResourceVectorStoreOptions.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateFileSearchToolResourceVectorStoreOptions.cs new file mode 100644 index 000000000000..cac5e291a8a8 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateFileSearchToolResourceVectorStoreOptions.cs @@ -0,0 +1,100 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Azure.AI.OpenAI.Assistants +{ + /// File IDs associated to the vector store to be passed to the helper. + public partial class CreateFileSearchToolResourceVectorStoreOptions + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + /// A list of file IDs to add to the vector store. There can be a maximum of 10000 files in a vector store. + /// + /// The chunking strategy used to chunk the file(s). If not set, will use the `auto` strategy. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include and . + /// + /// or is null. + public CreateFileSearchToolResourceVectorStoreOptions(IEnumerable fileIds, VectorStoreChunkingStrategyRequest chunkingStrategy) + { + Argument.AssertNotNull(fileIds, nameof(fileIds)); + Argument.AssertNotNull(chunkingStrategy, nameof(chunkingStrategy)); + + FileIds = fileIds.ToList(); + ChunkingStrategy = chunkingStrategy; + Metadata = new ChangeTrackingDictionary(); + } + + /// Initializes a new instance of . + /// A list of file IDs to add to the vector store. There can be a maximum of 10000 files in a vector store. + /// + /// The chunking strategy used to chunk the file(s). If not set, will use the `auto` strategy. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include and . + /// + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + /// Keeps track of any properties unknown to the library. + internal CreateFileSearchToolResourceVectorStoreOptions(IList fileIds, VectorStoreChunkingStrategyRequest chunkingStrategy, IDictionary metadata, IDictionary serializedAdditionalRawData) + { + FileIds = fileIds; + ChunkingStrategy = chunkingStrategy; + Metadata = metadata; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal CreateFileSearchToolResourceVectorStoreOptions() + { + } + + /// A list of file IDs to add to the vector store. There can be a maximum of 10000 files in a vector store. + public IList FileIds { get; } + /// + /// The chunking strategy used to chunk the file(s). If not set, will use the `auto` strategy. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include and . + /// + public VectorStoreChunkingStrategyRequest ChunkingStrategy { get; } + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + public IDictionary Metadata { get; set; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateRunOptions.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateRunOptions.Serialization.cs index c5d2f1cafaac..4b237e4eb15f 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateRunOptions.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateRunOptions.Serialization.cs @@ -72,6 +72,23 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit writer.WriteNull("additional_instructions"); } } + if (Optional.IsCollectionDefined(AdditionalMessages)) + { + if (AdditionalMessages != null) + { + writer.WritePropertyName("additional_messages"u8); + writer.WriteStartArray(); + foreach (var item in AdditionalMessages) + { + writer.WriteObjectValue(item, options); + } + writer.WriteEndArray(); + } + else + { + writer.WriteNull("additional_messages"); + } + } if (Optional.IsCollectionDefined(OverrideTools)) { if (OverrideTools != null) @@ -89,6 +106,114 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit writer.WriteNull("tools"); } } + if (Optional.IsDefined(ParallelToolCalls)) + { + writer.WritePropertyName("parallel_tool_calls"u8); + writer.WriteBooleanValue(ParallelToolCalls.Value); + } + if (Optional.IsDefined(Stream)) + { + writer.WritePropertyName("stream"u8); + writer.WriteBooleanValue(Stream.Value); + } + if (Optional.IsDefined(Temperature)) + { + if (Temperature != null) + { + writer.WritePropertyName("temperature"u8); + writer.WriteNumberValue(Temperature.Value); + } + else + { + writer.WriteNull("temperature"); + } + } + if (Optional.IsDefined(TopP)) + { + if (TopP != null) + { + writer.WritePropertyName("top_p"u8); + writer.WriteNumberValue(TopP.Value); + } + else + { + writer.WriteNull("top_p"); + } + } + if (Optional.IsDefined(MaxPromptTokens)) + { + if (MaxPromptTokens != null) + { + writer.WritePropertyName("max_prompt_tokens"u8); + writer.WriteNumberValue(MaxPromptTokens.Value); + } + else + { + writer.WriteNull("max_prompt_tokens"); + } + } + if (Optional.IsDefined(MaxCompletionTokens)) + { + if (MaxCompletionTokens != null) + { + writer.WritePropertyName("max_completion_tokens"u8); + writer.WriteNumberValue(MaxCompletionTokens.Value); + } + else + { + writer.WriteNull("max_completion_tokens"); + } + } + if (Optional.IsDefined(TruncationStrategy)) + { + if (TruncationStrategy != null) + { + writer.WritePropertyName("truncation_strategy"u8); + writer.WriteObjectValue(TruncationStrategy, options); + } + else + { + writer.WriteNull("truncation_strategy"); + } + } + if (Optional.IsDefined(ToolChoice)) + { + if (ToolChoice != null) + { + writer.WritePropertyName("tool_choice"u8); +#if NET6_0_OR_GREATER + writer.WriteRawValue(ToolChoice); +#else + using (JsonDocument document = JsonDocument.Parse(ToolChoice, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + else + { + writer.WriteNull("tool_choice"); + } + } + if (Optional.IsDefined(ResponseFormat)) + { + if (ResponseFormat != null) + { + writer.WritePropertyName("response_format"u8); +#if NET6_0_OR_GREATER + writer.WriteRawValue(ResponseFormat); +#else + using (JsonDocument document = JsonDocument.Parse(ResponseFormat, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + else + { + writer.WriteNull("response_format"); + } + } if (Optional.IsCollectionDefined(Metadata)) { if (Metadata != null) @@ -148,7 +273,17 @@ internal static CreateRunOptions DeserializeCreateRunOptions(JsonElement element string model = default; string instructions = default; string additionalInstructions = default; + IList additionalMessages = default; IList tools = default; + bool? parallelToolCalls = default; + bool? stream = default; + float? temperature = default; + float? topP = default; + int? maxPromptTokens = default; + int? maxCompletionTokens = default; + TruncationObject truncationStrategy = default; + BinaryData toolChoice = default; + BinaryData responseFormat = default; IDictionary metadata = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); @@ -189,6 +324,20 @@ internal static CreateRunOptions DeserializeCreateRunOptions(JsonElement element additionalInstructions = property.Value.GetString(); continue; } + if (property.NameEquals("additional_messages"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(ThreadMessage.DeserializeThreadMessage(item, options)); + } + additionalMessages = array; + continue; + } if (property.NameEquals("tools"u8)) { if (property.Value.ValueKind == JsonValueKind.Null) @@ -203,6 +352,94 @@ internal static CreateRunOptions DeserializeCreateRunOptions(JsonElement element tools = array; continue; } + if (property.NameEquals("parallel_tool_calls"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + parallelToolCalls = property.Value.GetBoolean(); + continue; + } + if (property.NameEquals("stream"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + stream = property.Value.GetBoolean(); + continue; + } + if (property.NameEquals("temperature"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + temperature = null; + continue; + } + temperature = property.Value.GetSingle(); + continue; + } + if (property.NameEquals("top_p"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + topP = null; + continue; + } + topP = property.Value.GetSingle(); + continue; + } + if (property.NameEquals("max_prompt_tokens"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + maxPromptTokens = null; + continue; + } + maxPromptTokens = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("max_completion_tokens"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + maxCompletionTokens = null; + continue; + } + maxCompletionTokens = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("truncation_strategy"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + truncationStrategy = null; + continue; + } + truncationStrategy = TruncationObject.DeserializeTruncationObject(property.Value, options); + continue; + } + if (property.NameEquals("tool_choice"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + toolChoice = null; + continue; + } + toolChoice = BinaryData.FromString(property.Value.GetRawText()); + continue; + } + if (property.NameEquals("response_format"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + responseFormat = null; + continue; + } + responseFormat = BinaryData.FromString(property.Value.GetRawText()); + continue; + } if (property.NameEquals("metadata"u8)) { if (property.Value.ValueKind == JsonValueKind.Null) @@ -228,7 +465,17 @@ internal static CreateRunOptions DeserializeCreateRunOptions(JsonElement element model, instructions, additionalInstructions, + additionalMessages ?? new ChangeTrackingList(), tools ?? new ChangeTrackingList(), + parallelToolCalls, + stream, + temperature, + topP, + maxPromptTokens, + maxCompletionTokens, + truncationStrategy, + toolChoice, + responseFormat, metadata ?? new ChangeTrackingDictionary(), serializedAdditionalRawData); } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateRunOptions.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateRunOptions.cs index 1c307b753523..b8a9e8507c50 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateRunOptions.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateRunOptions.cs @@ -53,6 +53,7 @@ public CreateRunOptions(string assistantId) Argument.AssertNotNull(assistantId, nameof(assistantId)); AssistantId = assistantId; + AdditionalMessages = new ChangeTrackingList(); OverrideTools = new ChangeTrackingList(); Metadata = new ChangeTrackingDictionary(); } @@ -65,20 +66,60 @@ public CreateRunOptions(string assistantId) /// Additional instructions to append at the end of the instructions for the run. This is useful for modifying the behavior /// on a per-run basis without overriding other instructions. /// + /// Adds additional messages to the thread before creating the run. /// /// The overridden list of enabled tools that the assistant should use to run the thread. /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. - /// The available derived classes include , and . + /// The available derived classes include , and . /// + /// Whether to enable parallel function calling during tool use. + /// + /// If `true`, returns a stream of events that happen during the Run as server-sent events, + /// terminating when the Run enters a terminal state with a `data: [DONE]` message. + /// + /// + /// What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output + /// more random, while lower values like 0.2 will make it more focused and deterministic. + /// + /// + /// An alternative to sampling with temperature, called nucleus sampling, where the model + /// considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens + /// comprising the top 10% probability mass are considered. + /// + /// We generally recommend altering this or temperature but not both. + /// + /// + /// The maximum number of prompt tokens that may be used over the course of the run. The run will make a best effort to use only + /// the number of prompt tokens specified, across multiple turns of the run. If the run exceeds the number of prompt tokens specified, + /// the run will end with status `incomplete`. See `incomplete_details` for more info. + /// + /// + /// The maximum number of completion tokens that may be used over the course of the run. The run will make a best effort + /// to use only the number of completion tokens specified, across multiple turns of the run. If the run exceeds the number of + /// completion tokens specified, the run will end with status `incomplete`. See `incomplete_details` for more info. + /// + /// The strategy to use for dropping messages as the context windows moves forward. + /// Controls whether or not and which tool is called by the model. + /// Specifies the format that the model must output. /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. /// Keeps track of any properties unknown to the library. - internal CreateRunOptions(string assistantId, string overrideModelName, string overrideInstructions, string additionalInstructions, IList overrideTools, IDictionary metadata, IDictionary serializedAdditionalRawData) + internal CreateRunOptions(string assistantId, string overrideModelName, string overrideInstructions, string additionalInstructions, IList additionalMessages, IList overrideTools, bool? parallelToolCalls, bool? stream, float? temperature, float? topP, int? maxPromptTokens, int? maxCompletionTokens, TruncationObject truncationStrategy, BinaryData toolChoice, BinaryData responseFormat, IDictionary metadata, IDictionary serializedAdditionalRawData) { AssistantId = assistantId; OverrideModelName = overrideModelName; OverrideInstructions = overrideInstructions; AdditionalInstructions = additionalInstructions; + AdditionalMessages = additionalMessages; OverrideTools = overrideTools; + ParallelToolCalls = parallelToolCalls; + Stream = stream; + Temperature = temperature; + TopP = topP; + MaxPromptTokens = maxPromptTokens; + MaxCompletionTokens = maxCompletionTokens; + TruncationStrategy = truncationStrategy; + ToolChoice = toolChoice; + ResponseFormat = responseFormat; Metadata = metadata; _serializedAdditionalRawData = serializedAdditionalRawData; } @@ -99,12 +140,138 @@ internal CreateRunOptions() /// on a per-run basis without overriding other instructions. /// public string AdditionalInstructions { get; set; } + /// Adds additional messages to the thread before creating the run. + public IList AdditionalMessages { get; set; } /// /// The overridden list of enabled tools that the assistant should use to run the thread. /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. - /// The available derived classes include , and . + /// The available derived classes include , and . /// public IList OverrideTools { get; set; } + /// Whether to enable parallel function calling during tool use. + public bool? ParallelToolCalls { get; set; } + /// + /// If `true`, returns a stream of events that happen during the Run as server-sent events, + /// terminating when the Run enters a terminal state with a `data: [DONE]` message. + /// + public bool? Stream { get; set; } + /// + /// What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output + /// more random, while lower values like 0.2 will make it more focused and deterministic. + /// + public float? Temperature { get; set; } + /// + /// An alternative to sampling with temperature, called nucleus sampling, where the model + /// considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens + /// comprising the top 10% probability mass are considered. + /// + /// We generally recommend altering this or temperature but not both. + /// + public float? TopP { get; set; } + /// + /// The maximum number of prompt tokens that may be used over the course of the run. The run will make a best effort to use only + /// the number of prompt tokens specified, across multiple turns of the run. If the run exceeds the number of prompt tokens specified, + /// the run will end with status `incomplete`. See `incomplete_details` for more info. + /// + public int? MaxPromptTokens { get; set; } + /// + /// The maximum number of completion tokens that may be used over the course of the run. The run will make a best effort + /// to use only the number of completion tokens specified, across multiple turns of the run. If the run exceeds the number of + /// completion tokens specified, the run will end with status `incomplete`. See `incomplete_details` for more info. + /// + public int? MaxCompletionTokens { get; set; } + /// The strategy to use for dropping messages as the context windows moves forward. + public TruncationObject TruncationStrategy { get; set; } + /// + /// Controls whether or not and which tool is called by the model. + /// + /// To assign an object to this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// + /// Supported types: + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + public BinaryData ToolChoice { get; set; } + /// + /// Specifies the format that the model must output. + /// + /// To assign an object to this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// + /// Supported types: + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + public BinaryData ResponseFormat { get; set; } /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. public IDictionary Metadata { get; set; } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateToolResourcesOptions.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateToolResourcesOptions.Serialization.cs new file mode 100644 index 000000000000..cad4b4ba65c7 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateToolResourcesOptions.Serialization.cs @@ -0,0 +1,171 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class CreateToolResourcesOptions : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(CreateToolResourcesOptions)} does not support writing '{format}' format."); + } + + if (Optional.IsDefined(CodeInterpreter)) + { + writer.WritePropertyName("code_interpreter"u8); + writer.WriteObjectValue(CodeInterpreter, options); + } + if (Optional.IsDefined(FileSearch)) + { + writer.WritePropertyName("file_search"u8); +#if NET6_0_OR_GREATER + writer.WriteRawValue(FileSearch); +#else + using (JsonDocument document = JsonDocument.Parse(FileSearch, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + CreateToolResourcesOptions 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(CreateToolResourcesOptions)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeCreateToolResourcesOptions(document.RootElement, options); + } + + internal static CreateToolResourcesOptions DeserializeCreateToolResourcesOptions(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + CreateCodeInterpreterToolResourceOptions codeInterpreter = default; + BinaryData fileSearch = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("code_interpreter"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + codeInterpreter = CreateCodeInterpreterToolResourceOptions.DeserializeCreateCodeInterpreterToolResourceOptions(property.Value, options); + continue; + } + if (property.NameEquals("file_search"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + fileSearch = BinaryData.FromString(property.Value.GetRawText()); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new CreateToolResourcesOptions(codeInterpreter, fileSearch, 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(CreateToolResourcesOptions)} does not support writing '{options.Format}' format."); + } + } + + CreateToolResourcesOptions 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeCreateToolResourcesOptions(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(CreateToolResourcesOptions)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static CreateToolResourcesOptions FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeCreateToolResourcesOptions(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateToolResourcesOptions.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateToolResourcesOptions.cs new file mode 100644 index 000000000000..796bdccc21f0 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateToolResourcesOptions.cs @@ -0,0 +1,119 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// + /// Request object. A set of resources that are used by the assistant's tools. The resources are specific to the + /// type of tool. For example, the `code_interpreter` tool requires a list of file IDs, while the `file_search` + /// tool requires a list of vector store IDs. + /// + public partial class CreateToolResourcesOptions + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + public CreateToolResourcesOptions() + { + } + + /// Initializes a new instance of . + /// + /// A list of file IDs made available to the `code_interpreter` tool. There can be a maximum of 20 files + /// associated with the tool. + /// + /// A list of vector stores or their IDs made available to the `file_search` tool. + /// Keeps track of any properties unknown to the library. + internal CreateToolResourcesOptions(CreateCodeInterpreterToolResourceOptions codeInterpreter, BinaryData fileSearch, IDictionary serializedAdditionalRawData) + { + CodeInterpreter = codeInterpreter; + FileSearch = fileSearch; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// + /// A list of file IDs made available to the `code_interpreter` tool. There can be a maximum of 20 files + /// associated with the tool. + /// + public CreateCodeInterpreterToolResourceOptions CodeInterpreter { get; set; } + /// + /// A list of vector stores or their IDs made available to the `file_search` tool. + /// + /// To assign an object to this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// + /// Supported types: + /// + /// + /// where T is of type + /// + /// + /// where T is of type + /// + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + public BinaryData FileSearch { get; set; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateVectorStoreFileBatchRequest.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateVectorStoreFileBatchRequest.Serialization.cs new file mode 100644 index 000000000000..f29ad1fbd34f --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateVectorStoreFileBatchRequest.Serialization.cs @@ -0,0 +1,167 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + internal partial class CreateVectorStoreFileBatchRequest : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(CreateVectorStoreFileBatchRequest)} does not support writing '{format}' format."); + } + + writer.WritePropertyName("file_ids"u8); + writer.WriteStartArray(); + foreach (var item in FileIds) + { + writer.WriteStringValue(item); + } + writer.WriteEndArray(); + if (Optional.IsDefined(ChunkingStrategy)) + { + writer.WritePropertyName("chunking_strategy"u8); + writer.WriteObjectValue(ChunkingStrategy, options); + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + CreateVectorStoreFileBatchRequest 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(CreateVectorStoreFileBatchRequest)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeCreateVectorStoreFileBatchRequest(document.RootElement, options); + } + + internal static CreateVectorStoreFileBatchRequest DeserializeCreateVectorStoreFileBatchRequest(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + IReadOnlyList fileIds = default; + VectorStoreChunkingStrategyRequest chunkingStrategy = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("file_ids"u8)) + { + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(item.GetString()); + } + fileIds = array; + continue; + } + if (property.NameEquals("chunking_strategy"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + chunkingStrategy = VectorStoreChunkingStrategyRequest.DeserializeVectorStoreChunkingStrategyRequest(property.Value, options); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new CreateVectorStoreFileBatchRequest(fileIds, chunkingStrategy, 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(CreateVectorStoreFileBatchRequest)} does not support writing '{options.Format}' format."); + } + } + + CreateVectorStoreFileBatchRequest 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeCreateVectorStoreFileBatchRequest(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(CreateVectorStoreFileBatchRequest)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static CreateVectorStoreFileBatchRequest FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeCreateVectorStoreFileBatchRequest(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateVectorStoreFileBatchRequest.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateVectorStoreFileBatchRequest.cs new file mode 100644 index 000000000000..ae91f3b2fed8 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateVectorStoreFileBatchRequest.cs @@ -0,0 +1,88 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The CreateVectorStoreFileBatchRequest. + internal partial class CreateVectorStoreFileBatchRequest + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + /// A list of File IDs that the vector store should use. Useful for tools like `file_search` that can access files. + /// is null. + internal CreateVectorStoreFileBatchRequest(IEnumerable fileIds) + { + Argument.AssertNotNull(fileIds, nameof(fileIds)); + + FileIds = fileIds.ToList(); + } + + /// Initializes a new instance of . + /// A list of File IDs that the vector store should use. Useful for tools like `file_search` that can access files. + /// + /// The chunking strategy used to chunk the file(s). If not set, will use the auto strategy. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include and . + /// + /// Keeps track of any properties unknown to the library. + internal CreateVectorStoreFileBatchRequest(IReadOnlyList fileIds, VectorStoreChunkingStrategyRequest chunkingStrategy, IDictionary serializedAdditionalRawData) + { + FileIds = fileIds; + ChunkingStrategy = chunkingStrategy; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal CreateVectorStoreFileBatchRequest() + { + } + + /// A list of File IDs that the vector store should use. Useful for tools like `file_search` that can access files. + public IReadOnlyList FileIds { get; } + /// + /// The chunking strategy used to chunk the file(s). If not set, will use the auto strategy. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include and . + /// + public VectorStoreChunkingStrategyRequest ChunkingStrategy { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateVectorStoreFileRequest.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateVectorStoreFileRequest.Serialization.cs new file mode 100644 index 000000000000..830d3de04dc3 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateVectorStoreFileRequest.Serialization.cs @@ -0,0 +1,157 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + internal partial class CreateVectorStoreFileRequest : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(CreateVectorStoreFileRequest)} does not support writing '{format}' format."); + } + + writer.WritePropertyName("file_id"u8); + writer.WriteStringValue(FileId); + if (Optional.IsDefined(ChunkingStrategy)) + { + writer.WritePropertyName("chunking_strategy"u8); + writer.WriteObjectValue(ChunkingStrategy, options); + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + CreateVectorStoreFileRequest 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(CreateVectorStoreFileRequest)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeCreateVectorStoreFileRequest(document.RootElement, options); + } + + internal static CreateVectorStoreFileRequest DeserializeCreateVectorStoreFileRequest(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string fileId = default; + VectorStoreChunkingStrategyRequest chunkingStrategy = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("file_id"u8)) + { + fileId = property.Value.GetString(); + continue; + } + if (property.NameEquals("chunking_strategy"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + chunkingStrategy = VectorStoreChunkingStrategyRequest.DeserializeVectorStoreChunkingStrategyRequest(property.Value, options); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new CreateVectorStoreFileRequest(fileId, chunkingStrategy, 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(CreateVectorStoreFileRequest)} does not support writing '{options.Format}' format."); + } + } + + CreateVectorStoreFileRequest 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeCreateVectorStoreFileRequest(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(CreateVectorStoreFileRequest)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static CreateVectorStoreFileRequest FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeCreateVectorStoreFileRequest(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateVectorStoreFileRequest.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateVectorStoreFileRequest.cs new file mode 100644 index 000000000000..fdda0a8891d1 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateVectorStoreFileRequest.cs @@ -0,0 +1,87 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The CreateVectorStoreFileRequest. + internal partial class CreateVectorStoreFileRequest + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + /// A File ID that the vector store should use. Useful for tools like `file_search` that can access files. + /// is null. + internal CreateVectorStoreFileRequest(string fileId) + { + Argument.AssertNotNull(fileId, nameof(fileId)); + + FileId = fileId; + } + + /// Initializes a new instance of . + /// A File ID that the vector store should use. Useful for tools like `file_search` that can access files. + /// + /// The chunking strategy used to chunk the file(s). If not set, will use the auto strategy. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include and . + /// + /// Keeps track of any properties unknown to the library. + internal CreateVectorStoreFileRequest(string fileId, VectorStoreChunkingStrategyRequest chunkingStrategy, IDictionary serializedAdditionalRawData) + { + FileId = fileId; + ChunkingStrategy = chunkingStrategy; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal CreateVectorStoreFileRequest() + { + } + + /// A File ID that the vector store should use. Useful for tools like `file_search` that can access files. + public string FileId { get; } + /// + /// The chunking strategy used to chunk the file(s). If not set, will use the auto strategy. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include and . + /// + public VectorStoreChunkingStrategyRequest ChunkingStrategy { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/DoneEvent.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/DoneEvent.cs new file mode 100644 index 000000000000..d59d8966c668 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/DoneEvent.cs @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Terminal event indicating the successful end of a stream. + public readonly partial struct DoneEvent : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public DoneEvent(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string DoneValue = "done"; + + /// Event sent when the stream is done. + public static DoneEvent Done { get; } = new DoneEvent(DoneValue); + /// Determines if two values are the same. + public static bool operator ==(DoneEvent left, DoneEvent right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(DoneEvent left, DoneEvent right) => !left.Equals(right); + /// Converts a to a . + public static implicit operator DoneEvent(string value) => new DoneEvent(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is DoneEvent other && Equals(other); + /// + public bool Equals(DoneEvent 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/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ErrorEvent.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ErrorEvent.cs new file mode 100644 index 000000000000..3a26ca078a2f --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ErrorEvent.cs @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Terminal event indicating a server side error while streaming. + public readonly partial struct ErrorEvent : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public ErrorEvent(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string ErrorValue = "error"; + + /// Event sent when an error occurs, such as an internal server error or a timeout. + public static ErrorEvent Error { get; } = new ErrorEvent(ErrorValue); + /// Determines if two values are the same. + public static bool operator ==(ErrorEvent left, ErrorEvent right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(ErrorEvent left, ErrorEvent right) => !left.Equals(right); + /// Converts a to a . + public static implicit operator ErrorEvent(string value) => new ErrorEvent(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is ErrorEvent other && Equals(other); + /// + public bool Equals(ErrorEvent 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/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FileSearchToolCallResult.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FileSearchToolCallResult.Serialization.cs new file mode 100644 index 000000000000..c2034d6ebcad --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FileSearchToolCallResult.Serialization.cs @@ -0,0 +1,183 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class FileSearchToolCallResult : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(FileSearchToolCallResult)} does not support writing '{format}' format."); + } + + writer.WritePropertyName("file_id"u8); + writer.WriteStringValue(FileId); + writer.WritePropertyName("file_name"u8); + writer.WriteStringValue(FileName); + writer.WritePropertyName("score"u8); + writer.WriteNumberValue(Score); + if (Optional.IsCollectionDefined(Content)) + { + writer.WritePropertyName("content"u8); + writer.WriteStartArray(); + foreach (var item in Content) + { + writer.WriteObjectValue(item, options); + } + writer.WriteEndArray(); + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + FileSearchToolCallResult 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(FileSearchToolCallResult)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeFileSearchToolCallResult(document.RootElement, options); + } + + internal static FileSearchToolCallResult DeserializeFileSearchToolCallResult(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string fileId = default; + string fileName = default; + double score = default; + IReadOnlyList content = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("file_id"u8)) + { + fileId = property.Value.GetString(); + continue; + } + if (property.NameEquals("file_name"u8)) + { + fileName = property.Value.GetString(); + continue; + } + if (property.NameEquals("score"u8)) + { + score = property.Value.GetDouble(); + continue; + } + if (property.NameEquals("content"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(FileSearchToolCallResultContentItem.DeserializeFileSearchToolCallResultContentItem(item, options)); + } + content = array; + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new FileSearchToolCallResult(fileId, fileName, score, content ?? 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(FileSearchToolCallResult)} does not support writing '{options.Format}' format."); + } + } + + FileSearchToolCallResult 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeFileSearchToolCallResult(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(FileSearchToolCallResult)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static FileSearchToolCallResult FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeFileSearchToolCallResult(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FileSearchToolCallResult.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FileSearchToolCallResult.cs new file mode 100644 index 000000000000..7d6159b1839f --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FileSearchToolCallResult.cs @@ -0,0 +1,93 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// File search tool call result. + public partial class FileSearchToolCallResult + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + /// The ID of the file that result was found in. + /// The name of the file that result was found in. + /// The score of the result. All values must be a floating point number between 0 and 1. + /// or is null. + internal FileSearchToolCallResult(string fileId, string fileName, double score) + { + Argument.AssertNotNull(fileId, nameof(fileId)); + Argument.AssertNotNull(fileName, nameof(fileName)); + + FileId = fileId; + FileName = fileName; + Score = score; + Content = new ChangeTrackingList(); + } + + /// Initializes a new instance of . + /// The ID of the file that result was found in. + /// The name of the file that result was found in. + /// The score of the result. All values must be a floating point number between 0 and 1. + /// The content of the result that was found. The content is only included if requested via the include query parameter. + /// Keeps track of any properties unknown to the library. + internal FileSearchToolCallResult(string fileId, string fileName, double score, IReadOnlyList content, IDictionary serializedAdditionalRawData) + { + FileId = fileId; + FileName = fileName; + Score = score; + Content = content; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal FileSearchToolCallResult() + { + } + + /// The ID of the file that result was found in. + public string FileId { get; } + /// The name of the file that result was found in. + public string FileName { get; } + /// The score of the result. All values must be a floating point number between 0 and 1. + public double Score { get; } + /// The content of the result that was found. The content is only included if requested via the include query parameter. + public IReadOnlyList Content { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FileSearchToolCallResultContentItem.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FileSearchToolCallResultContentItem.Serialization.cs new file mode 100644 index 000000000000..0e05d7c1e915 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FileSearchToolCallResultContentItem.Serialization.cs @@ -0,0 +1,160 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class FileSearchToolCallResultContentItem : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(FileSearchToolCallResultContentItem)} does not support writing '{format}' format."); + } + + if (Optional.IsDefined(Type)) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type.Value.ToString()); + } + if (Optional.IsDefined(Text)) + { + writer.WritePropertyName("text"u8); + writer.WriteStringValue(Text); + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + FileSearchToolCallResultContentItem 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(FileSearchToolCallResultContentItem)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeFileSearchToolCallResultContentItem(document.RootElement, options); + } + + internal static FileSearchToolCallResultContentItem DeserializeFileSearchToolCallResultContentItem(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + FileSearchToolCallResultContentItemType? type = default; + string text = 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 FileSearchToolCallResultContentItemType(property.Value.GetString()); + continue; + } + if (property.NameEquals("text"u8)) + { + text = property.Value.GetString(); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new FileSearchToolCallResultContentItem(type, text, 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(FileSearchToolCallResultContentItem)} does not support writing '{options.Format}' format."); + } + } + + FileSearchToolCallResultContentItem 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeFileSearchToolCallResultContentItem(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(FileSearchToolCallResultContentItem)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static FileSearchToolCallResultContentItem FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeFileSearchToolCallResultContentItem(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FileSearchToolCallResultContentItem.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FileSearchToolCallResultContentItem.cs new file mode 100644 index 000000000000..ea20181aa787 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FileSearchToolCallResultContentItem.cs @@ -0,0 +1,69 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Content item in a file search result. + public partial class FileSearchToolCallResultContentItem + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + internal FileSearchToolCallResultContentItem() + { + } + + /// Initializes a new instance of . + /// The type of the content. + /// The text content of the file. + /// Keeps track of any properties unknown to the library. + internal FileSearchToolCallResultContentItem(FileSearchToolCallResultContentItemType? type, string text, IDictionary serializedAdditionalRawData) + { + Type = type; + Text = text; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// The type of the content. + public FileSearchToolCallResultContentItemType? Type { get; } + /// The text content of the file. + public string Text { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FileSearchToolCallResultContentItemType.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FileSearchToolCallResultContentItemType.cs new file mode 100644 index 000000000000..e9a465abb4fc --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FileSearchToolCallResultContentItemType.cs @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The FileSearchToolCallResultContentItem_type. + public readonly partial struct FileSearchToolCallResultContentItemType : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public FileSearchToolCallResultContentItemType(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string TextValue = "text"; + + /// text. + public static FileSearchToolCallResultContentItemType Text { get; } = new FileSearchToolCallResultContentItemType(TextValue); + /// Determines if two values are the same. + public static bool operator ==(FileSearchToolCallResultContentItemType left, FileSearchToolCallResultContentItemType right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(FileSearchToolCallResultContentItemType left, FileSearchToolCallResultContentItemType right) => !left.Equals(right); + /// Converts a to a . + public static implicit operator FileSearchToolCallResultContentItemType(string value) => new FileSearchToolCallResultContentItemType(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is FileSearchToolCallResultContentItemType other && Equals(other); + /// + public bool Equals(FileSearchToolCallResultContentItemType 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/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepRetrievalToolCall.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FileSearchToolDefinition.Serialization.cs similarity index 60% rename from sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepRetrievalToolCall.Serialization.cs rename to sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FileSearchToolDefinition.Serialization.cs index b3efbd20a0e9..89ef61c42fb2 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepRetrievalToolCall.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FileSearchToolDefinition.Serialization.cs @@ -13,11 +13,11 @@ namespace Azure.AI.OpenAI.Assistants { - public partial class RunStepRetrievalToolCall : IUtf8JsonSerializable, IJsonModel + public partial class FileSearchToolDefinition : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { writer.WriteStartObject(); JsonModelWriteCore(writer, options); @@ -28,36 +28,33 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelRead /// The client options for reading and writing models. protected override void JsonModelWriteCore(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(RunStepRetrievalToolCall)} does not support writing '{format}' format."); + throw new FormatException($"The model {nameof(FileSearchToolDefinition)} does not support writing '{format}' format."); } base.JsonModelWriteCore(writer, options); - writer.WritePropertyName("retrieval"u8); - writer.WriteStartObject(); - foreach (var item in Retrieval) + if (Optional.IsDefined(FileSearch)) { - writer.WritePropertyName(item.Key); - writer.WriteStringValue(item.Value); + writer.WritePropertyName("file_search"u8); + writer.WriteObjectValue(FileSearch, options); } - writer.WriteEndObject(); } - RunStepRetrievalToolCall IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + FileSearchToolDefinition 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(RunStepRetrievalToolCall)} does not support reading '{format}' format."); + throw new FormatException($"The model {nameof(FileSearchToolDefinition)} does not support reading '{format}' format."); } using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeRunStepRetrievalToolCall(document.RootElement, options); + return DeserializeFileSearchToolDefinition(document.RootElement, options); } - internal static RunStepRetrievalToolCall DeserializeRunStepRetrievalToolCall(JsonElement element, ModelReaderWriterOptions options = null) + internal static FileSearchToolDefinition DeserializeFileSearchToolDefinition(JsonElement element, ModelReaderWriterOptions options = null) { options ??= ModelSerializationExtensions.WireOptions; @@ -65,21 +62,19 @@ internal static RunStepRetrievalToolCall DeserializeRunStepRetrievalToolCall(Jso { return null; } - IReadOnlyDictionary retrieval = default; + FileSearchToolDefinitionDetails fileSearch = default; string type = default; - string id = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { - if (property.NameEquals("retrieval"u8)) + if (property.NameEquals("file_search"u8)) { - Dictionary dictionary = new Dictionary(); - foreach (var property0 in property.Value.EnumerateObject()) + if (property.Value.ValueKind == JsonValueKind.Null) { - dictionary.Add(property0.Name, property0.Value.GetString()); + continue; } - retrieval = dictionary; + fileSearch = FileSearchToolDefinitionDetails.DeserializeFileSearchToolDefinitionDetails(property.Value, options); continue; } if (property.NameEquals("type"u8)) @@ -87,57 +82,52 @@ internal static RunStepRetrievalToolCall DeserializeRunStepRetrievalToolCall(Jso type = property.Value.GetString(); continue; } - if (property.NameEquals("id"u8)) - { - id = property.Value.GetString(); - continue; - } if (options.Format != "W") { rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); } } serializedAdditionalRawData = rawDataDictionary; - return new RunStepRetrievalToolCall(type, id, serializedAdditionalRawData, retrieval); + return new FileSearchToolDefinition(type, serializedAdditionalRawData, fileSearch); } - 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(RunStepRetrievalToolCall)} does not support writing '{options.Format}' format."); + throw new FormatException($"The model {nameof(FileSearchToolDefinition)} does not support writing '{options.Format}' format."); } } - RunStepRetrievalToolCall IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + FileSearchToolDefinition 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, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeRunStepRetrievalToolCall(document.RootElement, options); + return DeserializeFileSearchToolDefinition(document.RootElement, options); } default: - throw new FormatException($"The model {nameof(RunStepRetrievalToolCall)} does not support reading '{options.Format}' format."); + throw new FormatException($"The model {nameof(FileSearchToolDefinition)} does not support reading '{options.Format}' format."); } } - string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; /// Deserializes the model from a raw response. /// The response to deserialize the model from. - internal static new RunStepRetrievalToolCall FromResponse(Response response) + internal static new FileSearchToolDefinition FromResponse(Response response) { using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeRunStepRetrievalToolCall(document.RootElement); + return DeserializeFileSearchToolDefinition(document.RootElement); } /// Convert into a . diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FileSearchToolDefinition.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FileSearchToolDefinition.cs new file mode 100644 index 000000000000..e68594b90832 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FileSearchToolDefinition.cs @@ -0,0 +1,34 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The input definition information for a file search tool as used to configure an assistant. + public partial class FileSearchToolDefinition : ToolDefinition + { + /// Initializes a new instance of . + public FileSearchToolDefinition() + { + Type = "file_search"; + } + + /// Initializes a new instance of . + /// The object type. + /// Keeps track of any properties unknown to the library. + /// Options overrides for the file search tool. + internal FileSearchToolDefinition(string type, IDictionary serializedAdditionalRawData, FileSearchToolDefinitionDetails fileSearch) : base(type, serializedAdditionalRawData) + { + FileSearch = fileSearch; + } + + /// Options overrides for the file search tool. + public FileSearchToolDefinitionDetails FileSearch { get; set; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FileSearchToolDefinitionDetails.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FileSearchToolDefinitionDetails.Serialization.cs new file mode 100644 index 000000000000..eee4d45e9194 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FileSearchToolDefinitionDetails.Serialization.cs @@ -0,0 +1,149 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class FileSearchToolDefinitionDetails : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(FileSearchToolDefinitionDetails)} does not support writing '{format}' format."); + } + + if (Optional.IsDefined(MaxNumResults)) + { + writer.WritePropertyName("max_num_results"u8); + writer.WriteNumberValue(MaxNumResults.Value); + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + FileSearchToolDefinitionDetails 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(FileSearchToolDefinitionDetails)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeFileSearchToolDefinitionDetails(document.RootElement, options); + } + + internal static FileSearchToolDefinitionDetails DeserializeFileSearchToolDefinitionDetails(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + int? maxNumResults = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("max_num_results"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + maxNumResults = property.Value.GetInt32(); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new FileSearchToolDefinitionDetails(maxNumResults, 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(FileSearchToolDefinitionDetails)} does not support writing '{options.Format}' format."); + } + } + + FileSearchToolDefinitionDetails 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeFileSearchToolDefinitionDetails(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(FileSearchToolDefinitionDetails)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static FileSearchToolDefinitionDetails FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeFileSearchToolDefinitionDetails(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FileSearchToolDefinitionDetails.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FileSearchToolDefinitionDetails.cs new file mode 100644 index 000000000000..019548640805 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FileSearchToolDefinitionDetails.cs @@ -0,0 +1,73 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Options overrides for the file search tool. + public partial class FileSearchToolDefinitionDetails + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + public FileSearchToolDefinitionDetails() + { + } + + /// Initializes a new instance of . + /// + /// The maximum number of results the file search tool should output. The default is 20 for gpt-4* models and 5 for gpt-3.5-turbo. This number should be between 1 and 50 inclusive. + /// + /// Note that the file search tool may output fewer than `max_num_results` results. See the file search tool documentation for more information. + /// + /// Keeps track of any properties unknown to the library. + internal FileSearchToolDefinitionDetails(int? maxNumResults, IDictionary serializedAdditionalRawData) + { + MaxNumResults = maxNumResults; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// + /// The maximum number of results the file search tool should output. The default is 20 for gpt-4* models and 5 for gpt-3.5-turbo. This number should be between 1 and 50 inclusive. + /// + /// Note that the file search tool may output fewer than `max_num_results` results. See the file search tool documentation for more information. + /// + public int? MaxNumResults { get; set; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FileSearchToolResource.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FileSearchToolResource.Serialization.cs new file mode 100644 index 000000000000..8957903edbe7 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FileSearchToolResource.Serialization.cs @@ -0,0 +1,159 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class FileSearchToolResource : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(FileSearchToolResource)} does not support writing '{format}' format."); + } + + if (Optional.IsCollectionDefined(VectorStoreIds)) + { + writer.WritePropertyName("vector_store_ids"u8); + writer.WriteStartArray(); + foreach (var item in VectorStoreIds) + { + writer.WriteStringValue(item); + } + writer.WriteEndArray(); + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + FileSearchToolResource 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(FileSearchToolResource)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeFileSearchToolResource(document.RootElement, options); + } + + internal static FileSearchToolResource DeserializeFileSearchToolResource(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + IReadOnlyList 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 (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new FileSearchToolResource(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(FileSearchToolResource)} does not support writing '{options.Format}' format."); + } + } + + FileSearchToolResource 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeFileSearchToolResource(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(FileSearchToolResource)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static FileSearchToolResource FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeFileSearchToolResource(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FileSearchToolResource.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FileSearchToolResource.cs new file mode 100644 index 000000000000..94422e677d08 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FileSearchToolResource.cs @@ -0,0 +1,72 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// A set of resources that are used by the `file_search` tool. + public partial class FileSearchToolResource + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + internal FileSearchToolResource() + { + VectorStoreIds = new ChangeTrackingList(); + } + + /// Initializes a new instance of . + /// + /// The ID of the vector store attached to this assistant. There can be a maximum of 1 vector + /// store attached to the assistant. + /// + /// Keeps track of any properties unknown to the library. + internal FileSearchToolResource(IReadOnlyList vectorStoreIds, IDictionary serializedAdditionalRawData) + { + VectorStoreIds = vectorStoreIds; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// + /// The ID of the vector store attached to this assistant. There can be a maximum of 1 vector + /// store attached to the assistant. + /// + public IReadOnlyList VectorStoreIds { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FileState.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FileState.cs new file mode 100644 index 000000000000..47ce58179d3d --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FileState.cs @@ -0,0 +1,75 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The state of the file. + public readonly partial struct FileState : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public FileState(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string UploadedValue = "uploaded"; + private const string PendingValue = "pending"; + private const string RunningValue = "running"; + private const string ProcessedValue = "processed"; + private const string ErrorValue = "error"; + private const string DeletingValue = "deleting"; + private const string DeletedValue = "deleted"; + + /// + /// The file has been uploaded but it's not yet processed. This state is not returned by Azure OpenAI and exposed only for + /// compatibility. It can be categorized as an inactive state. + /// + public static FileState Uploaded { get; } = new FileState(UploadedValue); + /// The operation was created and is not queued to be processed in the future. It can be categorized as an inactive state. + public static FileState Pending { get; } = new FileState(PendingValue); + /// The operation has started to be processed. It can be categorized as an active state. + public static FileState Running { get; } = new FileState(RunningValue); + /// The operation has successfully processed and is ready for consumption. It can be categorized as a terminal state. + public static FileState Processed { get; } = new FileState(ProcessedValue); + /// The operation has completed processing with a failure and cannot be further consumed. It can be categorized as a terminal state. + public static FileState Error { get; } = new FileState(ErrorValue); + /// + /// The entity is in the process to be deleted. This state is not returned by Azure OpenAI and exposed only for compatibility. + /// It can be categorized as an active state. + /// + public static FileState Deleting { get; } = new FileState(DeletingValue); + /// + /// The entity has been deleted but may still be referenced by other entities predating the deletion. It can be categorized as a + /// terminal state. + /// + public static FileState Deleted { get; } = new FileState(DeletedValue); + /// Determines if two values are the same. + public static bool operator ==(FileState left, FileState right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(FileState left, FileState right) => !left.Equals(right); + /// Converts a to a . + public static implicit operator FileState(string value) => new FileState(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is FileState other && Equals(other); + /// + public bool Equals(FileState 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/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateAssistantFileRequest.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FunctionName.Serialization.cs similarity index 61% rename from sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateAssistantFileRequest.Serialization.cs rename to sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FunctionName.Serialization.cs index 5399705adc93..fb4ff9ca04a5 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateAssistantFileRequest.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FunctionName.Serialization.cs @@ -13,11 +13,11 @@ namespace Azure.AI.OpenAI.Assistants { - internal partial class CreateAssistantFileRequest : IUtf8JsonSerializable, IJsonModel + public partial class FunctionName : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { writer.WriteStartObject(); JsonModelWriteCore(writer, options); @@ -28,14 +28,14 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelRe /// The client options for reading and writing models. protected virtual void JsonModelWriteCore(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(CreateAssistantFileRequest)} does not support writing '{format}' format."); + throw new FormatException($"The model {nameof(FunctionName)} does not support writing '{format}' format."); } - writer.WritePropertyName("file_id"u8); - writer.WriteStringValue(FileId); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(Name); if (options.Format != "W" && _serializedAdditionalRawData != null) { foreach (var item in _serializedAdditionalRawData) @@ -53,19 +53,19 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit } } - CreateAssistantFileRequest IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + FunctionName 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(CreateAssistantFileRequest)} does not support reading '{format}' format."); + throw new FormatException($"The model {nameof(FunctionName)} does not support reading '{format}' format."); } using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeCreateAssistantFileRequest(document.RootElement, options); + return DeserializeFunctionName(document.RootElement, options); } - internal static CreateAssistantFileRequest DeserializeCreateAssistantFileRequest(JsonElement element, ModelReaderWriterOptions options = null) + internal static FunctionName DeserializeFunctionName(JsonElement element, ModelReaderWriterOptions options = null) { options ??= ModelSerializationExtensions.WireOptions; @@ -73,14 +73,14 @@ internal static CreateAssistantFileRequest DeserializeCreateAssistantFileRequest { return null; } - string fileId = default; + string name = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { - if (property.NameEquals("file_id"u8)) + if (property.NameEquals("name"u8)) { - fileId = property.Value.GetString(); + name = property.Value.GetString(); continue; } if (options.Format != "W") @@ -89,46 +89,46 @@ internal static CreateAssistantFileRequest DeserializeCreateAssistantFileRequest } } serializedAdditionalRawData = rawDataDictionary; - return new CreateAssistantFileRequest(fileId, serializedAdditionalRawData); + return new FunctionName(name, 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(CreateAssistantFileRequest)} does not support writing '{options.Format}' format."); + throw new FormatException($"The model {nameof(FunctionName)} does not support writing '{options.Format}' format."); } } - CreateAssistantFileRequest IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + FunctionName 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, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeCreateAssistantFileRequest(document.RootElement, options); + return DeserializeFunctionName(document.RootElement, options); } default: - throw new FormatException($"The model {nameof(CreateAssistantFileRequest)} does not support reading '{options.Format}' format."); + throw new FormatException($"The model {nameof(FunctionName)} does not support reading '{options.Format}' format."); } } - string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; /// Deserializes the model from a raw response. /// The response to deserialize the model from. - internal static CreateAssistantFileRequest FromResponse(Response response) + internal static FunctionName FromResponse(Response response) { using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeCreateAssistantFileRequest(document.RootElement); + return DeserializeFunctionName(document.RootElement); } /// Convert into a . diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FunctionName.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FunctionName.cs new file mode 100644 index 000000000000..70fcf993d4ae --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/FunctionName.cs @@ -0,0 +1,75 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The function name that will be used, if using the `function` tool. + public partial class FunctionName + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + /// The name of the function to call. + /// is null. + public FunctionName(string name) + { + Argument.AssertNotNull(name, nameof(name)); + + Name = name; + } + + /// Initializes a new instance of . + /// The name of the function to call. + /// Keeps track of any properties unknown to the library. + internal FunctionName(string name, IDictionary serializedAdditionalRawData) + { + Name = name; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal FunctionName() + { + } + + /// The name of the function to call. + public string Name { get; set; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/IncompleteRunDetails.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/IncompleteRunDetails.cs new file mode 100644 index 000000000000..373733568f34 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/IncompleteRunDetails.cs @@ -0,0 +1,51 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The reason why the run is incomplete. This will point to which specific token limit was reached over the course of the run. + public readonly partial struct IncompleteRunDetails : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public IncompleteRunDetails(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string MaxCompletionTokensValue = "max_completion_tokens"; + private const string MaxPromptTokensValue = "max_prompt_tokens"; + + /// Maximum completion tokens exceeded. + public static IncompleteRunDetails MaxCompletionTokens { get; } = new IncompleteRunDetails(MaxCompletionTokensValue); + /// Maximum prompt tokens exceeded. + public static IncompleteRunDetails MaxPromptTokens { get; } = new IncompleteRunDetails(MaxPromptTokensValue); + /// Determines if two values are the same. + public static bool operator ==(IncompleteRunDetails left, IncompleteRunDetails right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(IncompleteRunDetails left, IncompleteRunDetails right) => !left.Equals(right); + /// Converts a to a . + public static implicit operator IncompleteRunDetails(string value) => new IncompleteRunDetails(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is IncompleteRunDetails other && Equals(other); + /// + public bool Equals(IncompleteRunDetails 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/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantFileDeletionStatusObject.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantFileDeletionStatusObject.cs deleted file mode 100644 index 5c52700f6c0f..000000000000 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantFileDeletionStatusObject.cs +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.ComponentModel; - -namespace Azure.AI.OpenAI.Assistants -{ - /// The InternalAssistantFileDeletionStatus_object. - internal readonly partial struct InternalAssistantFileDeletionStatusObject : IEquatable - { - private readonly string _value; - - /// Initializes a new instance of . - /// is null. - public InternalAssistantFileDeletionStatusObject(string value) - { - _value = value ?? throw new ArgumentNullException(nameof(value)); - } - - private const string AssistantFileDeletedValue = "assistant.file.deleted"; - - /// assistant.file.deleted. - public static InternalAssistantFileDeletionStatusObject AssistantFileDeleted { get; } = new InternalAssistantFileDeletionStatusObject(AssistantFileDeletedValue); - /// Determines if two values are the same. - public static bool operator ==(InternalAssistantFileDeletionStatusObject left, InternalAssistantFileDeletionStatusObject right) => left.Equals(right); - /// Determines if two values are not the same. - public static bool operator !=(InternalAssistantFileDeletionStatusObject left, InternalAssistantFileDeletionStatusObject right) => !left.Equals(right); - /// Converts a to a . - public static implicit operator InternalAssistantFileDeletionStatusObject(string value) => new InternalAssistantFileDeletionStatusObject(value); - - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals(object obj) => obj is InternalAssistantFileDeletionStatusObject other && Equals(other); - /// - public bool Equals(InternalAssistantFileDeletionStatusObject 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/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageImageFileDetails.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageImageFileDetails.cs index eb315c465ad1..89cfab2a18a4 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageImageFileDetails.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageImageFileDetails.cs @@ -48,7 +48,7 @@ internal partial class InternalMessageImageFileDetails /// Initializes a new instance of . /// The ID for the file associated with this image. /// is null. - internal InternalMessageImageFileDetails(string internalDetails) + public InternalMessageImageFileDetails(string internalDetails) { Argument.AssertNotNull(internalDetails, nameof(internalDetails)); @@ -70,6 +70,6 @@ internal InternalMessageImageFileDetails() } /// The ID for the file associated with this image. - public string InternalDetails { get; } + public string InternalDetails { get; set; } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextDetails.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextDetails.Serialization.cs index 9b7a63c4c392..51a2be6fdef4 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextDetails.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextDetails.Serialization.cs @@ -81,7 +81,7 @@ internal static InternalMessageTextDetails DeserializeInternalMessageTextDetails return null; } string value = default; - IReadOnlyList annotations = default; + IList annotations = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextDetails.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextDetails.cs index 7f6a60a62245..4489c4dd184e 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextDetails.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextDetails.cs @@ -54,7 +54,7 @@ internal partial class InternalMessageTextDetails /// The available derived classes include and . /// /// or is null. - internal InternalMessageTextDetails(string text, IEnumerable annotations) + public InternalMessageTextDetails(string text, IEnumerable annotations) { Argument.AssertNotNull(text, nameof(text)); Argument.AssertNotNull(annotations, nameof(annotations)); @@ -71,7 +71,7 @@ internal InternalMessageTextDetails(string text, IEnumerable and . /// /// Keeps track of any properties unknown to the library. - internal InternalMessageTextDetails(string text, IReadOnlyList annotations, IDictionary serializedAdditionalRawData) + internal InternalMessageTextDetails(string text, IList annotations, IDictionary serializedAdditionalRawData) { Text = text; Annotations = annotations; @@ -84,12 +84,12 @@ internal InternalMessageTextDetails() } /// The text data. - public string Text { get; } + public string Text { get; set; } /// /// A list of annotations associated with this text. /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. /// The available derived classes include and . /// - public IReadOnlyList Annotations { get; } + public IList Annotations { get; } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextFileCitationDetails.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextFileCitationDetails.cs index 3bbdf07622ce..158100231c04 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextFileCitationDetails.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextFileCitationDetails.cs @@ -49,7 +49,7 @@ internal partial class InternalMessageTextFileCitationDetails /// The ID of the file associated with this citation. /// The specific quote cited in the associated file. /// or is null. - internal InternalMessageTextFileCitationDetails(string fileId, string quote) + public InternalMessageTextFileCitationDetails(string fileId, string quote) { Argument.AssertNotNull(fileId, nameof(fileId)); Argument.AssertNotNull(quote, nameof(quote)); @@ -75,8 +75,8 @@ internal InternalMessageTextFileCitationDetails() } /// The ID of the file associated with this citation. - public string FileId { get; } + public string FileId { get; set; } /// The specific quote cited in the associated file. - public string Quote { get; } + public string Quote { get; set; } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextFilePathDetails.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextFilePathDetails.cs index 4b86d66be5a2..f56d8a2f2cce 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextFilePathDetails.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalMessageTextFilePathDetails.cs @@ -48,7 +48,7 @@ internal partial class InternalMessageTextFilePathDetails /// Initializes a new instance of . /// The ID of the specific file that the citation is from. /// is null. - internal InternalMessageTextFilePathDetails(string fileId) + public InternalMessageTextFilePathDetails(string fileId) { Argument.AssertNotNull(fileId, nameof(fileId)); @@ -70,6 +70,6 @@ internal InternalMessageTextFilePathDetails() } /// The ID of the specific file that the citation is from. - public string FileId { get; } + public string FileId { get; set; } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageAttachment.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageAttachment.Serialization.cs new file mode 100644 index 000000000000..757e1dcee158 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageAttachment.Serialization.cs @@ -0,0 +1,179 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class MessageAttachment : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(MessageAttachment)} does not support writing '{format}' format."); + } + + writer.WritePropertyName("file_id"u8); + writer.WriteStringValue(FileId); + writer.WritePropertyName("tools"u8); + writer.WriteStartArray(); + foreach (var item in Tools) + { + if (item == null) + { + writer.WriteNullValue(); + continue; + } +#if NET6_0_OR_GREATER + writer.WriteRawValue(item); +#else + using (JsonDocument document = JsonDocument.Parse(item, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + writer.WriteEndArray(); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + MessageAttachment 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(MessageAttachment)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeMessageAttachment(document.RootElement, options); + } + + internal static MessageAttachment DeserializeMessageAttachment(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string fileId = default; + IList tools = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("file_id"u8)) + { + fileId = property.Value.GetString(); + continue; + } + if (property.NameEquals("tools"u8)) + { + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + if (item.ValueKind == JsonValueKind.Null) + { + array.Add(null); + } + else + { + array.Add(BinaryData.FromString(item.GetRawText())); + } + } + tools = array; + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new MessageAttachment(fileId, tools, 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(MessageAttachment)} does not support writing '{options.Format}' format."); + } + } + + MessageAttachment 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeMessageAttachment(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(MessageAttachment)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static MessageAttachment FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeMessageAttachment(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageAttachment.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageAttachment.cs new file mode 100644 index 000000000000..f905e2a52576 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageAttachment.cs @@ -0,0 +1,120 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Azure.AI.OpenAI.Assistants +{ + /// This describes to which tools a file has been attached. + public partial class MessageAttachment + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + /// The ID of the file to attach to the message. + /// The tools to add to this file. + /// or is null. + public MessageAttachment(string fileId, IEnumerable tools) + { + Argument.AssertNotNull(fileId, nameof(fileId)); + Argument.AssertNotNull(tools, nameof(tools)); + + FileId = fileId; + Tools = tools.ToList(); + } + + /// Initializes a new instance of . + /// The ID of the file to attach to the message. + /// The tools to add to this file. + /// Keeps track of any properties unknown to the library. + internal MessageAttachment(string fileId, IList tools, IDictionary serializedAdditionalRawData) + { + FileId = fileId; + Tools = tools; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal MessageAttachment() + { + } + + /// The ID of the file to attach to the message. + public string FileId { get; set; } + /// + /// The tools to add to this file. + /// + /// To assign an object to the element of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// + /// Supported types: + /// + /// + /// + /// + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + public IList Tools { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDelta.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDelta.Serialization.cs new file mode 100644 index 000000000000..9b27c0a4b619 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDelta.Serialization.cs @@ -0,0 +1,160 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class MessageDelta : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(MessageDelta)} does not support writing '{format}' format."); + } + + writer.WritePropertyName("role"u8); + writer.WriteStringValue(Role.ToString()); + writer.WritePropertyName("content"u8); + writer.WriteStartArray(); + foreach (var item in Content) + { + writer.WriteObjectValue(item, options); + } + writer.WriteEndArray(); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + MessageDelta 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(MessageDelta)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeMessageDelta(document.RootElement, options); + } + + internal static MessageDelta DeserializeMessageDelta(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + MessageRole role = default; + IReadOnlyList content = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("role"u8)) + { + role = new MessageRole(property.Value.GetString()); + continue; + } + if (property.NameEquals("content"u8)) + { + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(MessageDeltaContent.DeserializeMessageDeltaContent(item, options)); + } + content = array; + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new MessageDelta(role, content, 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(MessageDelta)} does not support writing '{options.Format}' format."); + } + } + + MessageDelta 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeMessageDelta(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(MessageDelta)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static MessageDelta FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeMessageDelta(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDelta.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDelta.cs new file mode 100644 index 000000000000..ec114efcb09d --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDelta.cs @@ -0,0 +1,94 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Represents the typed 'delta' payload within a streaming message delta chunk. + public partial class MessageDelta + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + /// The entity that produced the message. + /// + /// The content of the message as an array of text and/or images. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include and . + /// + /// is null. + internal MessageDelta(MessageRole role, IEnumerable content) + { + Argument.AssertNotNull(content, nameof(content)); + + Role = role; + Content = content.ToList(); + } + + /// Initializes a new instance of . + /// The entity that produced the message. + /// + /// The content of the message as an array of text and/or images. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include and . + /// + /// Keeps track of any properties unknown to the library. + internal MessageDelta(MessageRole role, IReadOnlyList content, IDictionary serializedAdditionalRawData) + { + Role = role; + Content = content; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal MessageDelta() + { + } + + /// The entity that produced the message. + public MessageRole Role { get; } + /// + /// The content of the message as an array of text and/or images. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include and . + /// + public IReadOnlyList Content { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageFile.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaChunk.Serialization.cs similarity index 64% rename from sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageFile.Serialization.cs rename to sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaChunk.Serialization.cs index bae85ab90a4f..fd7cf3e6bb08 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageFile.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaChunk.Serialization.cs @@ -13,11 +13,11 @@ namespace Azure.AI.OpenAI.Assistants { - public partial class MessageFile : IUtf8JsonSerializable, IJsonModel + public partial class MessageDeltaChunk : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { writer.WriteStartObject(); JsonModelWriteCore(writer, options); @@ -28,20 +28,18 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptio /// The client options for reading and writing models. protected virtual void JsonModelWriteCore(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(MessageFile)} does not support writing '{format}' format."); + throw new FormatException($"The model {nameof(MessageDeltaChunk)} does not support writing '{format}' format."); } writer.WritePropertyName("id"u8); writer.WriteStringValue(Id); writer.WritePropertyName("object"u8); - writer.WriteStringValue(Object); - writer.WritePropertyName("created_at"u8); - writer.WriteNumberValue(CreatedAt, "U"); - writer.WritePropertyName("message_id"u8); - writer.WriteStringValue(MessageId); + writer.WriteStringValue(Object.ToString()); + writer.WritePropertyName("delta"u8); + writer.WriteObjectValue(Delta, options); if (options.Format != "W" && _serializedAdditionalRawData != null) { foreach (var item in _serializedAdditionalRawData) @@ -59,19 +57,19 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit } } - MessageFile IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + MessageDeltaChunk 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(MessageFile)} does not support reading '{format}' format."); + throw new FormatException($"The model {nameof(MessageDeltaChunk)} does not support reading '{format}' format."); } using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeMessageFile(document.RootElement, options); + return DeserializeMessageDeltaChunk(document.RootElement, options); } - internal static MessageFile DeserializeMessageFile(JsonElement element, ModelReaderWriterOptions options = null) + internal static MessageDeltaChunk DeserializeMessageDeltaChunk(JsonElement element, ModelReaderWriterOptions options = null) { options ??= ModelSerializationExtensions.WireOptions; @@ -80,9 +78,8 @@ internal static MessageFile DeserializeMessageFile(JsonElement element, ModelRea return null; } string id = default; - string @object = default; - DateTimeOffset createdAt = default; - string messageId = default; + MessageDeltaChunkObject @object = default; + MessageDelta delta = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) @@ -94,17 +91,12 @@ internal static MessageFile DeserializeMessageFile(JsonElement element, ModelRea } if (property.NameEquals("object"u8)) { - @object = property.Value.GetString(); + @object = new MessageDeltaChunkObject(property.Value.GetString()); continue; } - if (property.NameEquals("created_at"u8)) + if (property.NameEquals("delta"u8)) { - createdAt = DateTimeOffset.FromUnixTimeSeconds(property.Value.GetInt64()); - continue; - } - if (property.NameEquals("message_id"u8)) - { - messageId = property.Value.GetString(); + delta = MessageDelta.DeserializeMessageDelta(property.Value, options); continue; } if (options.Format != "W") @@ -113,46 +105,46 @@ internal static MessageFile DeserializeMessageFile(JsonElement element, ModelRea } } serializedAdditionalRawData = rawDataDictionary; - return new MessageFile(id, @object, createdAt, messageId, serializedAdditionalRawData); + return new MessageDeltaChunk(id, @object, delta, 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(MessageFile)} does not support writing '{options.Format}' format."); + throw new FormatException($"The model {nameof(MessageDeltaChunk)} does not support writing '{options.Format}' format."); } } - MessageFile IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + MessageDeltaChunk 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, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeMessageFile(document.RootElement, options); + return DeserializeMessageDeltaChunk(document.RootElement, options); } default: - throw new FormatException($"The model {nameof(MessageFile)} does not support reading '{options.Format}' format."); + throw new FormatException($"The model {nameof(MessageDeltaChunk)} does not support reading '{options.Format}' format."); } } - string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; /// Deserializes the model from a raw response. /// The response to deserialize the model from. - internal static MessageFile FromResponse(Response response) + internal static MessageDeltaChunk FromResponse(Response response) { using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeMessageFile(document.RootElement); + return DeserializeMessageDeltaChunk(document.RootElement); } /// Convert into a . diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageFile.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaChunk.cs similarity index 56% rename from sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageFile.cs rename to sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaChunk.cs index a33691868926..3a8984a1a101 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageFile.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaChunk.cs @@ -10,8 +10,8 @@ namespace Azure.AI.OpenAI.Assistants { - /// Information about a file attached to an assistant thread message. - public partial class MessageFile + /// Represents a message delta i.e. any changed fields on a message during streaming. + public partial class MessageDeltaChunk { /// /// Keeps track of any properties unknown to the library. @@ -45,47 +45,43 @@ public partial class MessageFile /// private IDictionary _serializedAdditionalRawData; - /// Initializes a new instance of . - /// The identifier, which can be referenced in API endpoints. - /// The Unix timestamp, in seconds, representing when this object was created. - /// The ID of the message that this file is attached to. - /// or is null. - internal MessageFile(string id, DateTimeOffset createdAt, string messageId) + /// Initializes a new instance of . + /// The identifier of the message, which can be referenced in API endpoints. + /// The delta containing the fields that have changed on the Message. + /// or is null. + internal MessageDeltaChunk(string id, MessageDelta delta) { Argument.AssertNotNull(id, nameof(id)); - Argument.AssertNotNull(messageId, nameof(messageId)); + Argument.AssertNotNull(delta, nameof(delta)); Id = id; - CreatedAt = createdAt; - MessageId = messageId; + Delta = delta; } - /// Initializes a new instance of . - /// The identifier, which can be referenced in API endpoints. - /// The object type, which is always 'thread.message.file'. - /// The Unix timestamp, in seconds, representing when this object was created. - /// The ID of the message that this file is attached to. + /// Initializes a new instance of . + /// The identifier of the message, which can be referenced in API endpoints. + /// The object type, which is always `thread.message.delta`. + /// The delta containing the fields that have changed on the Message. /// Keeps track of any properties unknown to the library. - internal MessageFile(string id, string @object, DateTimeOffset createdAt, string messageId, IDictionary serializedAdditionalRawData) + internal MessageDeltaChunk(string id, MessageDeltaChunkObject @object, MessageDelta delta, IDictionary serializedAdditionalRawData) { Id = id; Object = @object; - CreatedAt = createdAt; - MessageId = messageId; + Delta = delta; _serializedAdditionalRawData = serializedAdditionalRawData; } - /// Initializes a new instance of for deserialization. - internal MessageFile() + /// Initializes a new instance of for deserialization. + internal MessageDeltaChunk() { } - /// The identifier, which can be referenced in API endpoints. + /// The identifier of the message, which can be referenced in API endpoints. public string Id { get; } + /// The object type, which is always `thread.message.delta`. + public MessageDeltaChunkObject Object { get; } = MessageDeltaChunkObject.ThreadMessageDelta; - /// The Unix timestamp, in seconds, representing when this object was created. - public DateTimeOffset CreatedAt { get; } - /// The ID of the message that this file is attached to. - public string MessageId { get; } + /// The delta containing the fields that have changed on the Message. + public MessageDelta Delta { get; } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaChunkObject.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaChunkObject.cs new file mode 100644 index 000000000000..b8b58471b5b6 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaChunkObject.cs @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The MessageDeltaChunk_object. + public readonly partial struct MessageDeltaChunkObject : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public MessageDeltaChunkObject(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string ThreadMessageDeltaValue = "thread.message.delta"; + + /// thread.message.delta. + public static MessageDeltaChunkObject ThreadMessageDelta { get; } = new MessageDeltaChunkObject(ThreadMessageDeltaValue); + /// Determines if two values are the same. + public static bool operator ==(MessageDeltaChunkObject left, MessageDeltaChunkObject right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(MessageDeltaChunkObject left, MessageDeltaChunkObject right) => !left.Equals(right); + /// Converts a to a . + public static implicit operator MessageDeltaChunkObject(string value) => new MessageDeltaChunkObject(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is MessageDeltaChunkObject other && Equals(other); + /// + public bool Equals(MessageDeltaChunkObject 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/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaContent.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaContent.Serialization.cs new file mode 100644 index 000000000000..4fb64165c9f6 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaContent.Serialization.cs @@ -0,0 +1,136 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + [PersistableModelProxy(typeof(UnknownMessageDeltaContent))] + public partial class MessageDeltaContent : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(MessageDeltaContent)} does not support writing '{format}' format."); + } + + writer.WritePropertyName("index"u8); + writer.WriteNumberValue(Index); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + MessageDeltaContent 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(MessageDeltaContent)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeMessageDeltaContent(document.RootElement, options); + } + + internal static MessageDeltaContent DeserializeMessageDeltaContent(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 "image_file": return MessageDeltaImageFileContent.DeserializeMessageDeltaImageFileContent(element, options); + case "text": return MessageDeltaTextContentObject.DeserializeMessageDeltaTextContentObject(element, options); + } + } + return UnknownMessageDeltaContent.DeserializeUnknownMessageDeltaContent(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(MessageDeltaContent)} does not support writing '{options.Format}' format."); + } + } + + MessageDeltaContent 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeMessageDeltaContent(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(MessageDeltaContent)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static MessageDeltaContent FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeMessageDeltaContent(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaContent.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaContent.cs new file mode 100644 index 000000000000..454d8e437f56 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaContent.cs @@ -0,0 +1,80 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// + /// The abstract base representation of a partial streamed message content payload. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include and . + /// + public abstract partial class MessageDeltaContent + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private protected IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + /// The index of the content part of the message. + protected MessageDeltaContent(int index) + { + Index = index; + } + + /// Initializes a new instance of . + /// The index of the content part of the message. + /// The type of content for this content part. + /// Keeps track of any properties unknown to the library. + internal MessageDeltaContent(int index, string type, IDictionary serializedAdditionalRawData) + { + Index = index; + Type = type; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal MessageDeltaContent() + { + } + + /// The index of the content part of the message. + public int Index { get; } + /// The type of content for this content part. + internal string Type { get; set; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaImageFileContent.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaImageFileContent.Serialization.cs new file mode 100644 index 000000000000..6bb7eb0f9d16 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaImageFileContent.Serialization.cs @@ -0,0 +1,147 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class MessageDeltaImageFileContent : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(MessageDeltaImageFileContent)} does not support writing '{format}' format."); + } + + base.JsonModelWriteCore(writer, options); + if (Optional.IsDefined(ImageFile)) + { + writer.WritePropertyName("image_file"u8); + writer.WriteObjectValue(ImageFile, options); + } + } + + MessageDeltaImageFileContent 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(MessageDeltaImageFileContent)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeMessageDeltaImageFileContent(document.RootElement, options); + } + + internal static MessageDeltaImageFileContent DeserializeMessageDeltaImageFileContent(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + MessageDeltaImageFileContentObject imageFile = default; + int index = default; + string type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("image_file"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + imageFile = MessageDeltaImageFileContentObject.DeserializeMessageDeltaImageFileContentObject(property.Value, options); + continue; + } + if (property.NameEquals("index"u8)) + { + index = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new MessageDeltaImageFileContent(index, type, serializedAdditionalRawData, imageFile); + } + + 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(MessageDeltaImageFileContent)} does not support writing '{options.Format}' format."); + } + } + + MessageDeltaImageFileContent 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeMessageDeltaImageFileContent(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(MessageDeltaImageFileContent)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new MessageDeltaImageFileContent FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeMessageDeltaImageFileContent(document.RootElement); + } + + /// Convert into a . + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaImageFileContent.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaImageFileContent.cs new file mode 100644 index 000000000000..212421c7c2e7 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaImageFileContent.cs @@ -0,0 +1,41 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Represents a streamed image file content part within a streaming message delta chunk. + public partial class MessageDeltaImageFileContent : MessageDeltaContent + { + /// Initializes a new instance of . + /// The index of the content part of the message. + internal MessageDeltaImageFileContent(int index) : base(index) + { + Type = "image_file"; + } + + /// Initializes a new instance of . + /// The index of the content part of the message. + /// The type of content for this content part. + /// Keeps track of any properties unknown to the library. + /// The image_file data. + internal MessageDeltaImageFileContent(int index, string type, IDictionary serializedAdditionalRawData, MessageDeltaImageFileContentObject imageFile) : base(index, type, serializedAdditionalRawData) + { + ImageFile = imageFile; + } + + /// Initializes a new instance of for deserialization. + internal MessageDeltaImageFileContent() + { + } + + /// The image_file data. + public MessageDeltaImageFileContentObject ImageFile { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaImageFileContentObject.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaImageFileContentObject.Serialization.cs new file mode 100644 index 000000000000..f8452d6289ab --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaImageFileContentObject.Serialization.cs @@ -0,0 +1,145 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class MessageDeltaImageFileContentObject : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(MessageDeltaImageFileContentObject)} does not support writing '{format}' format."); + } + + if (Optional.IsDefined(FileId)) + { + writer.WritePropertyName("file_id"u8); + writer.WriteStringValue(FileId); + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + MessageDeltaImageFileContentObject 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(MessageDeltaImageFileContentObject)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeMessageDeltaImageFileContentObject(document.RootElement, options); + } + + internal static MessageDeltaImageFileContentObject DeserializeMessageDeltaImageFileContentObject(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string fileId = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("file_id"u8)) + { + fileId = property.Value.GetString(); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new MessageDeltaImageFileContentObject(fileId, 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(MessageDeltaImageFileContentObject)} does not support writing '{options.Format}' format."); + } + } + + MessageDeltaImageFileContentObject 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeMessageDeltaImageFileContentObject(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(MessageDeltaImageFileContentObject)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static MessageDeltaImageFileContentObject FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeMessageDeltaImageFileContentObject(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaImageFileContentObject.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaImageFileContentObject.cs new file mode 100644 index 000000000000..592b0e9cef60 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaImageFileContentObject.cs @@ -0,0 +1,65 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Represents the 'image_file' payload within streaming image file content. + public partial class MessageDeltaImageFileContentObject + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + internal MessageDeltaImageFileContentObject() + { + } + + /// Initializes a new instance of . + /// The file ID of the image in the message content. + /// Keeps track of any properties unknown to the library. + internal MessageDeltaImageFileContentObject(string fileId, IDictionary serializedAdditionalRawData) + { + FileId = fileId; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// The file ID of the image in the message content. + public string FileId { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaTextAnnotation.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaTextAnnotation.Serialization.cs new file mode 100644 index 000000000000..e17d766b64e0 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaTextAnnotation.Serialization.cs @@ -0,0 +1,136 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + [PersistableModelProxy(typeof(UnknownMessageDeltaTextAnnotation))] + public partial class MessageDeltaTextAnnotation : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(MessageDeltaTextAnnotation)} does not support writing '{format}' format."); + } + + writer.WritePropertyName("index"u8); + writer.WriteNumberValue(Index); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + MessageDeltaTextAnnotation 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(MessageDeltaTextAnnotation)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeMessageDeltaTextAnnotation(document.RootElement, options); + } + + internal static MessageDeltaTextAnnotation DeserializeMessageDeltaTextAnnotation(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 "file_citation": return MessageDeltaTextFileCitationAnnotationObject.DeserializeMessageDeltaTextFileCitationAnnotationObject(element, options); + case "file_path": return MessageDeltaTextFilePathAnnotationObject.DeserializeMessageDeltaTextFilePathAnnotationObject(element, options); + } + } + return UnknownMessageDeltaTextAnnotation.DeserializeUnknownMessageDeltaTextAnnotation(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(MessageDeltaTextAnnotation)} does not support writing '{options.Format}' format."); + } + } + + MessageDeltaTextAnnotation 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeMessageDeltaTextAnnotation(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(MessageDeltaTextAnnotation)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static MessageDeltaTextAnnotation FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeMessageDeltaTextAnnotation(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaTextAnnotation.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaTextAnnotation.cs new file mode 100644 index 000000000000..2171bf6148cb --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaTextAnnotation.cs @@ -0,0 +1,80 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// + /// The abstract base representation of a streamed text content part's text annotation. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include and . + /// + public abstract partial class MessageDeltaTextAnnotation + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private protected IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + /// The index of the annotation within a text content part. + protected MessageDeltaTextAnnotation(int index) + { + Index = index; + } + + /// Initializes a new instance of . + /// The index of the annotation within a text content part. + /// The type of the text content annotation. + /// Keeps track of any properties unknown to the library. + internal MessageDeltaTextAnnotation(int index, string type, IDictionary serializedAdditionalRawData) + { + Index = index; + Type = type; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal MessageDeltaTextAnnotation() + { + } + + /// The index of the annotation within a text content part. + public int Index { get; } + /// The type of the text content annotation. + internal string Type { get; set; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaTextContent.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaTextContent.Serialization.cs new file mode 100644 index 000000000000..8f7f833260b9 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaTextContent.Serialization.cs @@ -0,0 +1,170 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class MessageDeltaTextContent : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(MessageDeltaTextContent)} does not support writing '{format}' format."); + } + + if (Optional.IsDefined(Value)) + { + writer.WritePropertyName("value"u8); + writer.WriteStringValue(Value); + } + if (Optional.IsCollectionDefined(Annotations)) + { + writer.WritePropertyName("annotations"u8); + writer.WriteStartArray(); + foreach (var item in Annotations) + { + writer.WriteObjectValue(item, options); + } + writer.WriteEndArray(); + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + MessageDeltaTextContent 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(MessageDeltaTextContent)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeMessageDeltaTextContent(document.RootElement, options); + } + + internal static MessageDeltaTextContent DeserializeMessageDeltaTextContent(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string value = default; + IReadOnlyList annotations = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("value"u8)) + { + value = property.Value.GetString(); + continue; + } + if (property.NameEquals("annotations"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(MessageDeltaTextAnnotation.DeserializeMessageDeltaTextAnnotation(item, options)); + } + annotations = array; + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new MessageDeltaTextContent(value, annotations ?? 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(MessageDeltaTextContent)} does not support writing '{options.Format}' format."); + } + } + + MessageDeltaTextContent 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeMessageDeltaTextContent(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(MessageDeltaTextContent)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static MessageDeltaTextContent FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeMessageDeltaTextContent(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaTextContent.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaTextContent.cs new file mode 100644 index 000000000000..15c4cac2d7ca --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaTextContent.cs @@ -0,0 +1,78 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Represents the data of a streamed text content part within a streaming message delta chunk. + public partial class MessageDeltaTextContent + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + internal MessageDeltaTextContent() + { + Annotations = new ChangeTrackingList(); + } + + /// Initializes a new instance of . + /// The data that makes up the text. + /// + /// Annotations for the text. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include and . + /// + /// Keeps track of any properties unknown to the library. + internal MessageDeltaTextContent(string value, IReadOnlyList annotations, IDictionary serializedAdditionalRawData) + { + Value = value; + Annotations = annotations; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// The data that makes up the text. + public string Value { get; } + /// + /// Annotations for the text. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include and . + /// + public IReadOnlyList Annotations { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaTextContentObject.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaTextContentObject.Serialization.cs new file mode 100644 index 000000000000..870b54bc371d --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaTextContentObject.Serialization.cs @@ -0,0 +1,147 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class MessageDeltaTextContentObject : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(MessageDeltaTextContentObject)} does not support writing '{format}' format."); + } + + base.JsonModelWriteCore(writer, options); + if (Optional.IsDefined(Text)) + { + writer.WritePropertyName("text"u8); + writer.WriteObjectValue(Text, options); + } + } + + MessageDeltaTextContentObject 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(MessageDeltaTextContentObject)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeMessageDeltaTextContentObject(document.RootElement, options); + } + + internal static MessageDeltaTextContentObject DeserializeMessageDeltaTextContentObject(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + MessageDeltaTextContent text = default; + int index = default; + string type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("text"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + text = MessageDeltaTextContent.DeserializeMessageDeltaTextContent(property.Value, options); + continue; + } + if (property.NameEquals("index"u8)) + { + index = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new MessageDeltaTextContentObject(index, type, serializedAdditionalRawData, text); + } + + 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(MessageDeltaTextContentObject)} does not support writing '{options.Format}' format."); + } + } + + MessageDeltaTextContentObject 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeMessageDeltaTextContentObject(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(MessageDeltaTextContentObject)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new MessageDeltaTextContentObject FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeMessageDeltaTextContentObject(document.RootElement); + } + + /// Convert into a . + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaTextContentObject.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaTextContentObject.cs new file mode 100644 index 000000000000..54247431988a --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaTextContentObject.cs @@ -0,0 +1,41 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Represents a streamed text content part within a streaming message delta chunk. + public partial class MessageDeltaTextContentObject : MessageDeltaContent + { + /// Initializes a new instance of . + /// The index of the content part of the message. + internal MessageDeltaTextContentObject(int index) : base(index) + { + Type = "text"; + } + + /// Initializes a new instance of . + /// The index of the content part of the message. + /// The type of content for this content part. + /// Keeps track of any properties unknown to the library. + /// The text content details. + internal MessageDeltaTextContentObject(int index, string type, IDictionary serializedAdditionalRawData, MessageDeltaTextContent text) : base(index, type, serializedAdditionalRawData) + { + Text = text; + } + + /// Initializes a new instance of for deserialization. + internal MessageDeltaTextContentObject() + { + } + + /// The text content details. + public MessageDeltaTextContent Text { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaTextFileCitationAnnotation.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaTextFileCitationAnnotation.Serialization.cs new file mode 100644 index 000000000000..ee069d01c29e --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaTextFileCitationAnnotation.Serialization.cs @@ -0,0 +1,156 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class MessageDeltaTextFileCitationAnnotation : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(MessageDeltaTextFileCitationAnnotation)} does not support writing '{format}' format."); + } + + if (Optional.IsDefined(FileId)) + { + writer.WritePropertyName("file_id"u8); + writer.WriteStringValue(FileId); + } + if (Optional.IsDefined(Quote)) + { + writer.WritePropertyName("quote"u8); + writer.WriteStringValue(Quote); + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + MessageDeltaTextFileCitationAnnotation 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(MessageDeltaTextFileCitationAnnotation)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeMessageDeltaTextFileCitationAnnotation(document.RootElement, options); + } + + internal static MessageDeltaTextFileCitationAnnotation DeserializeMessageDeltaTextFileCitationAnnotation(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string fileId = default; + string quote = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("file_id"u8)) + { + fileId = property.Value.GetString(); + continue; + } + if (property.NameEquals("quote"u8)) + { + quote = property.Value.GetString(); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new MessageDeltaTextFileCitationAnnotation(fileId, quote, 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(MessageDeltaTextFileCitationAnnotation)} does not support writing '{options.Format}' format."); + } + } + + MessageDeltaTextFileCitationAnnotation 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeMessageDeltaTextFileCitationAnnotation(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(MessageDeltaTextFileCitationAnnotation)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static MessageDeltaTextFileCitationAnnotation FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeMessageDeltaTextFileCitationAnnotation(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaTextFileCitationAnnotation.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaTextFileCitationAnnotation.cs new file mode 100644 index 000000000000..6f2fd703c231 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaTextFileCitationAnnotation.cs @@ -0,0 +1,69 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Represents the data of a streamed file citation as applied to a streaming text content part. + public partial class MessageDeltaTextFileCitationAnnotation + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + internal MessageDeltaTextFileCitationAnnotation() + { + } + + /// Initializes a new instance of . + /// The ID of the specific file the citation is from. + /// The specific quote in the cited file. + /// Keeps track of any properties unknown to the library. + internal MessageDeltaTextFileCitationAnnotation(string fileId, string quote, IDictionary serializedAdditionalRawData) + { + FileId = fileId; + Quote = quote; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// The ID of the specific file the citation is from. + public string FileId { get; } + /// The specific quote in the cited file. + public string Quote { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaTextFileCitationAnnotationObject.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaTextFileCitationAnnotationObject.Serialization.cs new file mode 100644 index 000000000000..1d631f9bded1 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaTextFileCitationAnnotationObject.Serialization.cs @@ -0,0 +1,195 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class MessageDeltaTextFileCitationAnnotationObject : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(MessageDeltaTextFileCitationAnnotationObject)} does not support writing '{format}' format."); + } + + base.JsonModelWriteCore(writer, options); + if (Optional.IsDefined(FileCitation)) + { + writer.WritePropertyName("file_citation"u8); + writer.WriteObjectValue(FileCitation, options); + } + if (Optional.IsDefined(Text)) + { + writer.WritePropertyName("text"u8); + writer.WriteStringValue(Text); + } + if (Optional.IsDefined(StartIndex)) + { + writer.WritePropertyName("start_index"u8); + writer.WriteNumberValue(StartIndex.Value); + } + if (Optional.IsDefined(EndIndex)) + { + writer.WritePropertyName("end_index"u8); + writer.WriteNumberValue(EndIndex.Value); + } + } + + MessageDeltaTextFileCitationAnnotationObject 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(MessageDeltaTextFileCitationAnnotationObject)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeMessageDeltaTextFileCitationAnnotationObject(document.RootElement, options); + } + + internal static MessageDeltaTextFileCitationAnnotationObject DeserializeMessageDeltaTextFileCitationAnnotationObject(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + MessageDeltaTextFileCitationAnnotation fileCitation = default; + string text = default; + int? startIndex = default; + int? endIndex = default; + int index = default; + string type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("file_citation"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + fileCitation = MessageDeltaTextFileCitationAnnotation.DeserializeMessageDeltaTextFileCitationAnnotation(property.Value, options); + continue; + } + if (property.NameEquals("text"u8)) + { + text = property.Value.GetString(); + continue; + } + if (property.NameEquals("start_index"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + startIndex = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("end_index"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + endIndex = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("index"u8)) + { + index = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new MessageDeltaTextFileCitationAnnotationObject( + index, + type, + serializedAdditionalRawData, + fileCitation, + text, + startIndex, + endIndex); + } + + 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(MessageDeltaTextFileCitationAnnotationObject)} does not support writing '{options.Format}' format."); + } + } + + MessageDeltaTextFileCitationAnnotationObject 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeMessageDeltaTextFileCitationAnnotationObject(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(MessageDeltaTextFileCitationAnnotationObject)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new MessageDeltaTextFileCitationAnnotationObject FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeMessageDeltaTextFileCitationAnnotationObject(document.RootElement); + } + + /// Convert into a . + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaTextFileCitationAnnotationObject.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaTextFileCitationAnnotationObject.cs new file mode 100644 index 000000000000..1a67dafe8dfa --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaTextFileCitationAnnotationObject.cs @@ -0,0 +1,53 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Represents a streamed file citation applied to a streaming text content part. + public partial class MessageDeltaTextFileCitationAnnotationObject : MessageDeltaTextAnnotation + { + /// Initializes a new instance of . + /// The index of the annotation within a text content part. + internal MessageDeltaTextFileCitationAnnotationObject(int index) : base(index) + { + Type = "file_citation"; + } + + /// Initializes a new instance of . + /// The index of the annotation within a text content part. + /// The type of the text content annotation. + /// Keeps track of any properties unknown to the library. + /// The file citation information. + /// The text in the message content that needs to be replaced. + /// The start index of this annotation in the content text. + /// The end index of this annotation in the content text. + internal MessageDeltaTextFileCitationAnnotationObject(int index, string type, IDictionary serializedAdditionalRawData, MessageDeltaTextFileCitationAnnotation fileCitation, string text, int? startIndex, int? endIndex) : base(index, type, serializedAdditionalRawData) + { + FileCitation = fileCitation; + Text = text; + StartIndex = startIndex; + EndIndex = endIndex; + } + + /// Initializes a new instance of for deserialization. + internal MessageDeltaTextFileCitationAnnotationObject() + { + } + + /// The file citation information. + public MessageDeltaTextFileCitationAnnotation FileCitation { get; } + /// The text in the message content that needs to be replaced. + public string Text { get; } + /// The start index of this annotation in the content text. + public int? StartIndex { get; } + /// The end index of this annotation in the content text. + public int? EndIndex { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaTextFilePathAnnotation.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaTextFilePathAnnotation.Serialization.cs new file mode 100644 index 000000000000..57e4b12964f9 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaTextFilePathAnnotation.Serialization.cs @@ -0,0 +1,145 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class MessageDeltaTextFilePathAnnotation : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(MessageDeltaTextFilePathAnnotation)} does not support writing '{format}' format."); + } + + if (Optional.IsDefined(FileId)) + { + writer.WritePropertyName("file_id"u8); + writer.WriteStringValue(FileId); + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + MessageDeltaTextFilePathAnnotation 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(MessageDeltaTextFilePathAnnotation)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeMessageDeltaTextFilePathAnnotation(document.RootElement, options); + } + + internal static MessageDeltaTextFilePathAnnotation DeserializeMessageDeltaTextFilePathAnnotation(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string fileId = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("file_id"u8)) + { + fileId = property.Value.GetString(); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new MessageDeltaTextFilePathAnnotation(fileId, 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(MessageDeltaTextFilePathAnnotation)} does not support writing '{options.Format}' format."); + } + } + + MessageDeltaTextFilePathAnnotation 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeMessageDeltaTextFilePathAnnotation(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(MessageDeltaTextFilePathAnnotation)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static MessageDeltaTextFilePathAnnotation FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeMessageDeltaTextFilePathAnnotation(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaTextFilePathAnnotation.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaTextFilePathAnnotation.cs new file mode 100644 index 000000000000..dbdd8626dc56 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaTextFilePathAnnotation.cs @@ -0,0 +1,65 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Represents the data of a streamed file path annotation as applied to a streaming text content part. + public partial class MessageDeltaTextFilePathAnnotation + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + internal MessageDeltaTextFilePathAnnotation() + { + } + + /// Initializes a new instance of . + /// The file ID for the annotation. + /// Keeps track of any properties unknown to the library. + internal MessageDeltaTextFilePathAnnotation(string fileId, IDictionary serializedAdditionalRawData) + { + FileId = fileId; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// The file ID for the annotation. + public string FileId { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaTextFilePathAnnotationObject.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaTextFilePathAnnotationObject.Serialization.cs new file mode 100644 index 000000000000..8c54af2bbcc6 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaTextFilePathAnnotationObject.Serialization.cs @@ -0,0 +1,195 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class MessageDeltaTextFilePathAnnotationObject : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(MessageDeltaTextFilePathAnnotationObject)} does not support writing '{format}' format."); + } + + base.JsonModelWriteCore(writer, options); + if (Optional.IsDefined(FilePath)) + { + writer.WritePropertyName("file_path"u8); + writer.WriteObjectValue(FilePath, options); + } + if (Optional.IsDefined(StartIndex)) + { + writer.WritePropertyName("start_index"u8); + writer.WriteNumberValue(StartIndex.Value); + } + if (Optional.IsDefined(EndIndex)) + { + writer.WritePropertyName("end_index"u8); + writer.WriteNumberValue(EndIndex.Value); + } + if (Optional.IsDefined(Text)) + { + writer.WritePropertyName("text"u8); + writer.WriteStringValue(Text); + } + } + + MessageDeltaTextFilePathAnnotationObject 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(MessageDeltaTextFilePathAnnotationObject)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeMessageDeltaTextFilePathAnnotationObject(document.RootElement, options); + } + + internal static MessageDeltaTextFilePathAnnotationObject DeserializeMessageDeltaTextFilePathAnnotationObject(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + MessageDeltaTextFilePathAnnotation filePath = default; + int? startIndex = default; + int? endIndex = default; + string text = default; + int index = default; + string type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("file_path"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + filePath = MessageDeltaTextFilePathAnnotation.DeserializeMessageDeltaTextFilePathAnnotation(property.Value, options); + continue; + } + if (property.NameEquals("start_index"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + startIndex = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("end_index"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + endIndex = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("text"u8)) + { + text = property.Value.GetString(); + continue; + } + if (property.NameEquals("index"u8)) + { + index = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new MessageDeltaTextFilePathAnnotationObject( + index, + type, + serializedAdditionalRawData, + filePath, + startIndex, + endIndex, + text); + } + + 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(MessageDeltaTextFilePathAnnotationObject)} does not support writing '{options.Format}' format."); + } + } + + MessageDeltaTextFilePathAnnotationObject 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeMessageDeltaTextFilePathAnnotationObject(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(MessageDeltaTextFilePathAnnotationObject)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new MessageDeltaTextFilePathAnnotationObject FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeMessageDeltaTextFilePathAnnotationObject(document.RootElement); + } + + /// Convert into a . + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaTextFilePathAnnotationObject.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaTextFilePathAnnotationObject.cs new file mode 100644 index 000000000000..85df4f20c57d --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageDeltaTextFilePathAnnotationObject.cs @@ -0,0 +1,53 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Represents a streamed file path annotation applied to a streaming text content part. + public partial class MessageDeltaTextFilePathAnnotationObject : MessageDeltaTextAnnotation + { + /// Initializes a new instance of . + /// The index of the annotation within a text content part. + internal MessageDeltaTextFilePathAnnotationObject(int index) : base(index) + { + Type = "file_path"; + } + + /// Initializes a new instance of . + /// The index of the annotation within a text content part. + /// The type of the text content annotation. + /// Keeps track of any properties unknown to the library. + /// The file path information. + /// The start index of this annotation in the content text. + /// The end index of this annotation in the content text. + /// The text in the message content that needs to be replaced. + internal MessageDeltaTextFilePathAnnotationObject(int index, string type, IDictionary serializedAdditionalRawData, MessageDeltaTextFilePathAnnotation filePath, int? startIndex, int? endIndex, string text) : base(index, type, serializedAdditionalRawData) + { + FilePath = filePath; + StartIndex = startIndex; + EndIndex = endIndex; + Text = text; + } + + /// Initializes a new instance of for deserialization. + internal MessageDeltaTextFilePathAnnotationObject() + { + } + + /// The file path information. + public MessageDeltaTextFilePathAnnotation FilePath { get; } + /// The start index of this annotation in the content text. + public int? StartIndex { get; } + /// The end index of this annotation in the content text. + public int? EndIndex { get; } + /// The text in the message content that needs to be replaced. + public string Text { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageImageFileContent.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageImageFileContent.cs index 8997ff05b177..7e252658ea5e 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageImageFileContent.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageImageFileContent.cs @@ -16,7 +16,7 @@ public partial class MessageImageFileContent : MessageContent /// Initializes a new instance of . /// The image file for this thread message content item. /// is null. - internal MessageImageFileContent(InternalMessageImageFileDetails internalDetails) + public MessageImageFileContent(InternalMessageImageFileDetails internalDetails) { Argument.AssertNotNull(internalDetails, nameof(internalDetails)); diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageIncompleteDetails.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageIncompleteDetails.Serialization.cs new file mode 100644 index 000000000000..6faa89be320e --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageIncompleteDetails.Serialization.cs @@ -0,0 +1,142 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class MessageIncompleteDetails : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(MessageIncompleteDetails)} does not support writing '{format}' format."); + } + + writer.WritePropertyName("reason"u8); + writer.WriteStringValue(Reason.ToString()); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + MessageIncompleteDetails 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(MessageIncompleteDetails)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeMessageIncompleteDetails(document.RootElement, options); + } + + internal static MessageIncompleteDetails DeserializeMessageIncompleteDetails(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + MessageIncompleteDetailsReason reason = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("reason"u8)) + { + reason = new MessageIncompleteDetailsReason(property.Value.GetString()); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new MessageIncompleteDetails(reason, 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(MessageIncompleteDetails)} does not support writing '{options.Format}' format."); + } + } + + MessageIncompleteDetails 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeMessageIncompleteDetails(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(MessageIncompleteDetails)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static MessageIncompleteDetails FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeMessageIncompleteDetails(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageIncompleteDetails.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageIncompleteDetails.cs new file mode 100644 index 000000000000..335c1009db7f --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageIncompleteDetails.cs @@ -0,0 +1,72 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Information providing additional detail about a message entering an incomplete status. + public partial class MessageIncompleteDetails + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + /// The provided reason describing why the message was marked as incomplete. + public MessageIncompleteDetails(MessageIncompleteDetailsReason reason) + { + Reason = reason; + } + + /// Initializes a new instance of . + /// The provided reason describing why the message was marked as incomplete. + /// Keeps track of any properties unknown to the library. + internal MessageIncompleteDetails(MessageIncompleteDetailsReason reason, IDictionary serializedAdditionalRawData) + { + Reason = reason; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal MessageIncompleteDetails() + { + } + + /// The provided reason describing why the message was marked as incomplete. + public MessageIncompleteDetailsReason Reason { get; set; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageIncompleteDetailsReason.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageIncompleteDetailsReason.cs new file mode 100644 index 000000000000..ec0c57835d91 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageIncompleteDetailsReason.cs @@ -0,0 +1,60 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.OpenAI.Assistants +{ + /// A set of reasons describing why a message is marked as incomplete. + public readonly partial struct MessageIncompleteDetailsReason : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public MessageIncompleteDetailsReason(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string ContentFilterValue = "content_filter"; + private const string MaxTokensValue = "max_tokens"; + private const string RunCancelledValue = "run_cancelled"; + private const string RunFailedValue = "run_failed"; + private const string RunExpiredValue = "run_expired"; + + /// The run generating the message was terminated due to content filter flagging. + public static MessageIncompleteDetailsReason ContentFilter { get; } = new MessageIncompleteDetailsReason(ContentFilterValue); + /// The run generating the message exhausted available tokens before completion. + public static MessageIncompleteDetailsReason MaxTokens { get; } = new MessageIncompleteDetailsReason(MaxTokensValue); + /// The run generating the message was cancelled before completion. + public static MessageIncompleteDetailsReason RunCancelled { get; } = new MessageIncompleteDetailsReason(RunCancelledValue); + /// The run generating the message failed. + public static MessageIncompleteDetailsReason RunFailed { get; } = new MessageIncompleteDetailsReason(RunFailedValue); + /// The run generating the message expired. + public static MessageIncompleteDetailsReason RunExpired { get; } = new MessageIncompleteDetailsReason(RunExpiredValue); + /// Determines if two values are the same. + public static bool operator ==(MessageIncompleteDetailsReason left, MessageIncompleteDetailsReason right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(MessageIncompleteDetailsReason left, MessageIncompleteDetailsReason right) => !left.Equals(right); + /// Converts a to a . + public static implicit operator MessageIncompleteDetailsReason(string value) => new MessageIncompleteDetailsReason(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is MessageIncompleteDetailsReason other && Equals(other); + /// + public bool Equals(MessageIncompleteDetailsReason 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/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageStatus.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageStatus.cs new file mode 100644 index 000000000000..d63a6bcf8b56 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageStatus.cs @@ -0,0 +1,54 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The possible execution status values for a thread message. + public readonly partial struct MessageStatus : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public MessageStatus(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string InProgressValue = "in_progress"; + private const string IncompleteValue = "incomplete"; + private const string CompletedValue = "completed"; + + /// A run is currently creating this message. + public static MessageStatus InProgress { get; } = new MessageStatus(InProgressValue); + /// This message is incomplete. See incomplete_details for more information. + public static MessageStatus Incomplete { get; } = new MessageStatus(IncompleteValue); + /// This message was successfully completed by a run. + public static MessageStatus Completed { get; } = new MessageStatus(CompletedValue); + /// Determines if two values are the same. + public static bool operator ==(MessageStatus left, MessageStatus right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(MessageStatus left, MessageStatus right) => !left.Equals(right); + /// Converts a to a . + public static implicit operator MessageStatus(string value) => new MessageStatus(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is MessageStatus other && Equals(other); + /// + public bool Equals(MessageStatus 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/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageStreamEvent.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageStreamEvent.cs new file mode 100644 index 000000000000..13c90b7d0b77 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageStreamEvent.cs @@ -0,0 +1,60 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Message operation related streaming events. + public readonly partial struct MessageStreamEvent : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public MessageStreamEvent(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string ThreadMessageCreatedValue = "thread.message.created"; + private const string ThreadMessageInProgressValue = "thread.message.in_progress"; + private const string ThreadMessageDeltaValue = "thread.message.delta"; + private const string ThreadMessageCompletedValue = "thread.message.completed"; + private const string ThreadMessageIncompleteValue = "thread.message.incomplete"; + + /// Event sent when a new message is created. The data of this event is of type ThreadMessage. + public static MessageStreamEvent ThreadMessageCreated { get; } = new MessageStreamEvent(ThreadMessageCreatedValue); + /// Event sent when a message moves to `in_progress` status. The data of this event is of type ThreadMessage. + public static MessageStreamEvent ThreadMessageInProgress { get; } = new MessageStreamEvent(ThreadMessageInProgressValue); + /// Event sent when a message is being streamed. The data of this event is of type MessageDeltaChunk. + public static MessageStreamEvent ThreadMessageDelta { get; } = new MessageStreamEvent(ThreadMessageDeltaValue); + /// Event sent when a message is completed. The data of this event is of type ThreadMessage. + public static MessageStreamEvent ThreadMessageCompleted { get; } = new MessageStreamEvent(ThreadMessageCompletedValue); + /// Event sent before a message is completed. The data of this event is of type ThreadMessage. + public static MessageStreamEvent ThreadMessageIncomplete { get; } = new MessageStreamEvent(ThreadMessageIncompleteValue); + /// Determines if two values are the same. + public static bool operator ==(MessageStreamEvent left, MessageStreamEvent right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(MessageStreamEvent left, MessageStreamEvent right) => !left.Equals(right); + /// Converts a to a . + public static implicit operator MessageStreamEvent(string value) => new MessageStreamEvent(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is MessageStreamEvent other && Equals(other); + /// + public bool Equals(MessageStreamEvent 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/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextAnnotation.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextAnnotation.Serialization.cs index fdc1994429ae..0a4c9644f85e 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextAnnotation.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextAnnotation.Serialization.cs @@ -38,10 +38,6 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit writer.WriteStringValue(Type); writer.WritePropertyName("text"u8); writer.WriteStringValue(Text); - writer.WritePropertyName("start_index"u8); - writer.WriteNumberValue(StartIndex); - writer.WritePropertyName("end_index"u8); - writer.WriteNumberValue(EndIndex); if (options.Format != "W" && _serializedAdditionalRawData != null) { foreach (var item in _serializedAdditionalRawData) diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextAnnotation.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextAnnotation.cs index 082f8fea6a5b..aa8769d7ed21 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextAnnotation.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextAnnotation.cs @@ -51,30 +51,22 @@ public abstract partial class MessageTextAnnotation /// Initializes a new instance of . /// The textual content associated with this text annotation item. - /// The first text index associated with this text annotation. - /// The last text index associated with this text annotation. /// is null. - protected MessageTextAnnotation(string text, int startIndex, int endIndex) + protected MessageTextAnnotation(string text) { Argument.AssertNotNull(text, nameof(text)); Text = text; - StartIndex = startIndex; - EndIndex = endIndex; } /// Initializes a new instance of . /// The object type. /// The textual content associated with this text annotation item. - /// The first text index associated with this text annotation. - /// The last text index associated with this text annotation. /// Keeps track of any properties unknown to the library. - internal MessageTextAnnotation(string type, string text, int startIndex, int endIndex, IDictionary serializedAdditionalRawData) + internal MessageTextAnnotation(string type, string text, IDictionary serializedAdditionalRawData) { Type = type; Text = text; - StartIndex = startIndex; - EndIndex = endIndex; _serializedAdditionalRawData = serializedAdditionalRawData; } @@ -86,10 +78,6 @@ internal MessageTextAnnotation() /// The object type. internal string Type { get; set; } /// The textual content associated with this text annotation item. - public string Text { get; } - /// The first text index associated with this text annotation. - public int StartIndex { get; } - /// The last text index associated with this text annotation. - public int EndIndex { get; } + public string Text { get; set; } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextContent.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextContent.cs index 61d7241bb927..ef579043014c 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextContent.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextContent.cs @@ -16,7 +16,7 @@ public partial class MessageTextContent : MessageContent /// Initializes a new instance of . /// The text and associated annotations for this thread message content item. /// is null. - internal MessageTextContent(InternalMessageTextDetails internalDetails) + public MessageTextContent(InternalMessageTextDetails internalDetails) { Argument.AssertNotNull(internalDetails, nameof(internalDetails)); diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextFileCitationAnnotation.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextFileCitationAnnotation.Serialization.cs index 678600787d28..3a0adb7f527f 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextFileCitationAnnotation.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextFileCitationAnnotation.Serialization.cs @@ -37,6 +37,16 @@ protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWri base.JsonModelWriteCore(writer, options); writer.WritePropertyName("file_citation"u8); writer.WriteObjectValue(InternalDetails, options); + if (Optional.IsDefined(StartIndex)) + { + writer.WritePropertyName("start_index"u8); + writer.WriteNumberValue(StartIndex.Value); + } + if (Optional.IsDefined(EndIndex)) + { + writer.WritePropertyName("end_index"u8); + writer.WriteNumberValue(EndIndex.Value); + } } MessageTextFileCitationAnnotation IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) @@ -60,10 +70,10 @@ internal static MessageTextFileCitationAnnotation DeserializeMessageTextFileCita return null; } InternalMessageTextFileCitationDetails fileCitation = default; + int? startIndex = default; + int? endIndex = default; string type = default; string text = default; - int startIndex = default; - int endIndex = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) @@ -73,24 +83,32 @@ internal static MessageTextFileCitationAnnotation DeserializeMessageTextFileCita fileCitation = InternalMessageTextFileCitationDetails.DeserializeInternalMessageTextFileCitationDetails(property.Value, options); continue; } - if (property.NameEquals("type"u8)) + if (property.NameEquals("start_index"u8)) { - type = property.Value.GetString(); + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + startIndex = property.Value.GetInt32(); continue; } - if (property.NameEquals("text"u8)) + if (property.NameEquals("end_index"u8)) { - text = property.Value.GetString(); + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + endIndex = property.Value.GetInt32(); continue; } - if (property.NameEquals("start_index"u8)) + if (property.NameEquals("type"u8)) { - startIndex = property.Value.GetInt32(); + type = property.Value.GetString(); continue; } - if (property.NameEquals("end_index"u8)) + if (property.NameEquals("text"u8)) { - endIndex = property.Value.GetInt32(); + text = property.Value.GetString(); continue; } if (options.Format != "W") @@ -102,10 +120,10 @@ internal static MessageTextFileCitationAnnotation DeserializeMessageTextFileCita return new MessageTextFileCitationAnnotation( type, text, - startIndex, - endIndex, serializedAdditionalRawData, - fileCitation); + fileCitation, + startIndex, + endIndex); } BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextFileCitationAnnotation.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextFileCitationAnnotation.cs index a036ec9b468b..6db943f9c9a3 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextFileCitationAnnotation.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextFileCitationAnnotation.cs @@ -10,19 +10,17 @@ namespace Azure.AI.OpenAI.Assistants { - /// A citation within the message that points to a specific quote from a specific File associated with the assistant or the message. Generated when the assistant uses the 'retrieval' tool to search files. + /// A citation within the message that points to a specific quote from a specific File associated with the assistant or the message. Generated when the assistant uses the 'file_search' tool to search files. public partial class MessageTextFileCitationAnnotation : MessageTextAnnotation { /// Initializes a new instance of . /// The textual content associated with this text annotation item. - /// The first text index associated with this text annotation. - /// The last text index associated with this text annotation. /// /// A citation within the message that points to a specific quote from a specific file. - /// Generated when the assistant uses the "retrieval" tool to search files. + /// Generated when the assistant uses the "file_search" tool to search files. /// /// or is null. - internal MessageTextFileCitationAnnotation(string text, int startIndex, int endIndex, InternalMessageTextFileCitationDetails internalDetails) : base(text, startIndex, endIndex) + public MessageTextFileCitationAnnotation(string text, InternalMessageTextFileCitationDetails internalDetails) : base(text) { Argument.AssertNotNull(text, nameof(text)); Argument.AssertNotNull(internalDetails, nameof(internalDetails)); @@ -34,21 +32,27 @@ internal MessageTextFileCitationAnnotation(string text, int startIndex, int endI /// Initializes a new instance of . /// The object type. /// The textual content associated with this text annotation item. - /// The first text index associated with this text annotation. - /// The last text index associated with this text annotation. /// Keeps track of any properties unknown to the library. /// /// A citation within the message that points to a specific quote from a specific file. - /// Generated when the assistant uses the "retrieval" tool to search files. + /// Generated when the assistant uses the "file_search" tool to search files. /// - internal MessageTextFileCitationAnnotation(string type, string text, int startIndex, int endIndex, IDictionary serializedAdditionalRawData, InternalMessageTextFileCitationDetails internalDetails) : base(type, text, startIndex, endIndex, serializedAdditionalRawData) + /// The first text index associated with this text annotation. + /// The last text index associated with this text annotation. + internal MessageTextFileCitationAnnotation(string type, string text, IDictionary serializedAdditionalRawData, InternalMessageTextFileCitationDetails internalDetails, int? startIndex, int? endIndex) : base(type, text, serializedAdditionalRawData) { InternalDetails = internalDetails; + StartIndex = startIndex; + EndIndex = endIndex; } /// Initializes a new instance of for deserialization. internal MessageTextFileCitationAnnotation() { } + /// The first text index associated with this text annotation. + public int? StartIndex { get; set; } + /// The last text index associated with this text annotation. + public int? EndIndex { get; set; } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextFilePathAnnotation.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextFilePathAnnotation.Serialization.cs index 2ce71641798e..ed63ad704b75 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextFilePathAnnotation.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextFilePathAnnotation.Serialization.cs @@ -37,6 +37,16 @@ protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWri base.JsonModelWriteCore(writer, options); writer.WritePropertyName("file_path"u8); writer.WriteObjectValue(InternalDetails, options); + if (Optional.IsDefined(StartIndex)) + { + writer.WritePropertyName("start_index"u8); + writer.WriteNumberValue(StartIndex.Value); + } + if (Optional.IsDefined(EndIndex)) + { + writer.WritePropertyName("end_index"u8); + writer.WriteNumberValue(EndIndex.Value); + } } MessageTextFilePathAnnotation IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) @@ -60,10 +70,10 @@ internal static MessageTextFilePathAnnotation DeserializeMessageTextFilePathAnno return null; } InternalMessageTextFilePathDetails filePath = default; + int? startIndex = default; + int? endIndex = default; string type = default; string text = default; - int startIndex = default; - int endIndex = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) @@ -73,24 +83,32 @@ internal static MessageTextFilePathAnnotation DeserializeMessageTextFilePathAnno filePath = InternalMessageTextFilePathDetails.DeserializeInternalMessageTextFilePathDetails(property.Value, options); continue; } - if (property.NameEquals("type"u8)) + if (property.NameEquals("start_index"u8)) { - type = property.Value.GetString(); + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + startIndex = property.Value.GetInt32(); continue; } - if (property.NameEquals("text"u8)) + if (property.NameEquals("end_index"u8)) { - text = property.Value.GetString(); + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + endIndex = property.Value.GetInt32(); continue; } - if (property.NameEquals("start_index"u8)) + if (property.NameEquals("type"u8)) { - startIndex = property.Value.GetInt32(); + type = property.Value.GetString(); continue; } - if (property.NameEquals("end_index"u8)) + if (property.NameEquals("text"u8)) { - endIndex = property.Value.GetInt32(); + text = property.Value.GetString(); continue; } if (options.Format != "W") @@ -102,10 +120,10 @@ internal static MessageTextFilePathAnnotation DeserializeMessageTextFilePathAnno return new MessageTextFilePathAnnotation( type, text, - startIndex, - endIndex, serializedAdditionalRawData, - filePath); + filePath, + startIndex, + endIndex); } BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextFilePathAnnotation.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextFilePathAnnotation.cs index 787c70831f54..276bb7ded43d 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextFilePathAnnotation.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/MessageTextFilePathAnnotation.cs @@ -15,11 +15,9 @@ public partial class MessageTextFilePathAnnotation : MessageTextAnnotation { /// Initializes a new instance of . /// The textual content associated with this text annotation item. - /// The first text index associated with this text annotation. - /// The last text index associated with this text annotation. /// A URL for the file that's generated when the assistant used the code_interpreter tool to generate a file. /// or is null. - internal MessageTextFilePathAnnotation(string text, int startIndex, int endIndex, InternalMessageTextFilePathDetails internalDetails) : base(text, startIndex, endIndex) + public MessageTextFilePathAnnotation(string text, InternalMessageTextFilePathDetails internalDetails) : base(text) { Argument.AssertNotNull(text, nameof(text)); Argument.AssertNotNull(internalDetails, nameof(internalDetails)); @@ -31,18 +29,24 @@ internal MessageTextFilePathAnnotation(string text, int startIndex, int endIndex /// Initializes a new instance of . /// The object type. /// The textual content associated with this text annotation item. - /// The first text index associated with this text annotation. - /// The last text index associated with this text annotation. /// Keeps track of any properties unknown to the library. /// A URL for the file that's generated when the assistant used the code_interpreter tool to generate a file. - internal MessageTextFilePathAnnotation(string type, string text, int startIndex, int endIndex, IDictionary serializedAdditionalRawData, InternalMessageTextFilePathDetails internalDetails) : base(type, text, startIndex, endIndex, serializedAdditionalRawData) + /// The first text index associated with this text annotation. + /// The last text index associated with this text annotation. + internal MessageTextFilePathAnnotation(string type, string text, IDictionary serializedAdditionalRawData, InternalMessageTextFilePathDetails internalDetails, int? startIndex, int? endIndex) : base(type, text, serializedAdditionalRawData) { InternalDetails = internalDetails; + StartIndex = startIndex; + EndIndex = endIndex; } /// Initializes a new instance of for deserialization. internal MessageTextFilePathAnnotation() { } + /// The first text index associated with this text annotation. + public int? StartIndex { get; set; } + /// The last text index associated with this text annotation. + public int? EndIndex { get; set; } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIFile.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIFile.Serialization.cs index 7bb6222023a9..4a2eb30a8a00 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIFile.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIFile.Serialization.cs @@ -46,6 +46,16 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit writer.WriteNumberValue(CreatedAt, "U"); writer.WritePropertyName("purpose"u8); writer.WriteStringValue(Purpose.ToString()); + if (Optional.IsDefined(Status)) + { + writer.WritePropertyName("status"u8); + writer.WriteStringValue(Status.Value.ToString()); + } + if (Optional.IsDefined(StatusDetails)) + { + writer.WritePropertyName("status_details"u8); + writer.WriteStringValue(StatusDetails); + } if (options.Format != "W" && _serializedAdditionalRawData != null) { foreach (var item in _serializedAdditionalRawData) @@ -89,6 +99,8 @@ internal static OpenAIFile DeserializeOpenAIFile(JsonElement element, ModelReade string filename = default; DateTimeOffset createdAt = default; OpenAIFilePurpose purpose = default; + FileState? status = default; + string statusDetails = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) @@ -123,6 +135,20 @@ internal static OpenAIFile DeserializeOpenAIFile(JsonElement element, ModelReade purpose = new OpenAIFilePurpose(property.Value.GetString()); continue; } + if (property.NameEquals("status"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + status = new FileState(property.Value.GetString()); + continue; + } + if (property.NameEquals("status_details"u8)) + { + statusDetails = property.Value.GetString(); + continue; + } if (options.Format != "W") { rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); @@ -136,6 +162,8 @@ internal static OpenAIFile DeserializeOpenAIFile(JsonElement element, ModelReade filename, createdAt, purpose, + status, + statusDetails, serializedAdditionalRawData); } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIFile.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIFile.cs index 318f90d4c5a5..29264237fe5a 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIFile.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIFile.cs @@ -71,8 +71,10 @@ internal OpenAIFile(string id, int size, string filename, DateTimeOffset created /// The name of the file. /// The Unix timestamp, in seconds, representing when this object was created. /// The intended purpose of a file. + /// The state of the file. This field is available in Azure OpenAI only. + /// The error message with details in case processing of this file failed. This field is available in Azure OpenAI only. /// Keeps track of any properties unknown to the library. - internal OpenAIFile(string @object, string id, int size, string filename, DateTimeOffset createdAt, OpenAIFilePurpose purpose, IDictionary serializedAdditionalRawData) + internal OpenAIFile(string @object, string id, int size, string filename, DateTimeOffset createdAt, OpenAIFilePurpose purpose, FileState? status, string statusDetails, IDictionary serializedAdditionalRawData) { Object = @object; Id = id; @@ -80,6 +82,8 @@ internal OpenAIFile(string @object, string id, int size, string filename, DateTi Filename = filename; CreatedAt = createdAt; Purpose = purpose; + Status = status; + StatusDetails = statusDetails; _serializedAdditionalRawData = serializedAdditionalRawData; } @@ -98,5 +102,9 @@ internal OpenAIFile() public DateTimeOffset CreatedAt { get; } /// The intended purpose of a file. public OpenAIFilePurpose Purpose { get; } + /// The state of the file. This field is available in Azure OpenAI only. + public FileState? Status { get; } + /// The error message with details in case processing of this file failed. This field is available in Azure OpenAI only. + public string StatusDetails { get; } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIFilePurpose.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIFilePurpose.cs index 50d531cac562..e58119d1b591 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIFilePurpose.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIFilePurpose.cs @@ -26,6 +26,9 @@ public OpenAIFilePurpose(string value) private const string FineTuneResultsValue = "fine-tune-results"; private const string AssistantsValue = "assistants"; private const string AssistantsOutputValue = "assistants_output"; + private const string BatchValue = "batch"; + private const string BatchOutputValue = "batch_output"; + private const string VisionValue = "vision"; /// Indicates a file is used for fine tuning input. public static OpenAIFilePurpose FineTune { get; } = new OpenAIFilePurpose(FineTuneValue); @@ -35,6 +38,12 @@ public OpenAIFilePurpose(string value) public static OpenAIFilePurpose Assistants { get; } = new OpenAIFilePurpose(AssistantsValue); /// Indicates a file is used as output by assistants. public static OpenAIFilePurpose AssistantsOutput { get; } = new OpenAIFilePurpose(AssistantsOutputValue); + /// Indicates a file is used as input to . + public static OpenAIFilePurpose Batch { get; } = new OpenAIFilePurpose(BatchValue); + /// Indicates a file is used as output by a vector store batch operation. + public static OpenAIFilePurpose BatchOutput { get; } = new OpenAIFilePurpose(BatchOutputValue); + /// Indicates a file is used as input to a vision operation. + public static OpenAIFilePurpose Vision { get; } = new OpenAIFilePurpose(VisionValue); /// Determines if two values are the same. public static bool operator ==(OpenAIFilePurpose left, OpenAIFilePurpose right) => left.Equals(right); /// Determines if two values are not the same. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIPageableListOfAssistantFileObject.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIPageableListOfAssistantFileObject.cs deleted file mode 100644 index 1a72c0020e88..000000000000 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIPageableListOfAssistantFileObject.cs +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.ComponentModel; - -namespace Azure.AI.OpenAI.Assistants -{ - /// The OpenAIPageableListOfAssistantFile_object. - internal readonly partial struct OpenAIPageableListOfAssistantFileObject : IEquatable - { - private readonly string _value; - - /// Initializes a new instance of . - /// is null. - public OpenAIPageableListOfAssistantFileObject(string value) - { - _value = value ?? throw new ArgumentNullException(nameof(value)); - } - - private const string ListValue = "list"; - - /// list. - public static OpenAIPageableListOfAssistantFileObject List { get; } = new OpenAIPageableListOfAssistantFileObject(ListValue); - /// Determines if two values are the same. - public static bool operator ==(OpenAIPageableListOfAssistantFileObject left, OpenAIPageableListOfAssistantFileObject right) => left.Equals(right); - /// Determines if two values are not the same. - public static bool operator !=(OpenAIPageableListOfAssistantFileObject left, OpenAIPageableListOfAssistantFileObject right) => !left.Equals(right); - /// Converts a to a . - public static implicit operator OpenAIPageableListOfAssistantFileObject(string value) => new OpenAIPageableListOfAssistantFileObject(value); - - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals(object obj) => obj is OpenAIPageableListOfAssistantFileObject other && Equals(other); - /// - public bool Equals(OpenAIPageableListOfAssistantFileObject 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/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfMessageFile.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIPageableListOfVectorStore.Serialization.cs similarity index 66% rename from sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfMessageFile.Serialization.cs rename to sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIPageableListOfVectorStore.Serialization.cs index 0f7226e4395b..f7cc560e9ff4 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfMessageFile.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIPageableListOfVectorStore.Serialization.cs @@ -13,11 +13,11 @@ namespace Azure.AI.OpenAI.Assistants { - internal partial class InternalOpenAIPageableListOfMessageFile : IUtf8JsonSerializable, IJsonModel + public partial class OpenAIPageableListOfVectorStore : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { writer.WriteStartObject(); JsonModelWriteCore(writer, options); @@ -28,10 +28,10 @@ void IJsonModel.Write(Utf8JsonWriter wr /// The client options for reading and writing models. protected virtual void JsonModelWriteCore(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(InternalOpenAIPageableListOfMessageFile)} does not support writing '{format}' format."); + throw new FormatException($"The model {nameof(OpenAIPageableListOfVectorStore)} does not support writing '{format}' format."); } writer.WritePropertyName("object"u8); @@ -66,19 +66,19 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit } } - InternalOpenAIPageableListOfMessageFile IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + OpenAIPageableListOfVectorStore 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(InternalOpenAIPageableListOfMessageFile)} does not support reading '{format}' format."); + throw new FormatException($"The model {nameof(OpenAIPageableListOfVectorStore)} does not support reading '{format}' format."); } using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeInternalOpenAIPageableListOfMessageFile(document.RootElement, options); + return DeserializeOpenAIPageableListOfVectorStore(document.RootElement, options); } - internal static InternalOpenAIPageableListOfMessageFile DeserializeInternalOpenAIPageableListOfMessageFile(JsonElement element, ModelReaderWriterOptions options = null) + internal static OpenAIPageableListOfVectorStore DeserializeOpenAIPageableListOfVectorStore(JsonElement element, ModelReaderWriterOptions options = null) { options ??= ModelSerializationExtensions.WireOptions; @@ -86,8 +86,8 @@ internal static InternalOpenAIPageableListOfMessageFile DeserializeInternalOpenA { return null; } - OpenAIPageableListOfMessageFileObject @object = default; - IReadOnlyList data = default; + OpenAIPageableListOfVectorStoreObject @object = default; + IReadOnlyList data = default; string firstId = default; string lastId = default; bool hasMore = default; @@ -97,15 +97,15 @@ internal static InternalOpenAIPageableListOfMessageFile DeserializeInternalOpenA { if (property.NameEquals("object"u8)) { - @object = new OpenAIPageableListOfMessageFileObject(property.Value.GetString()); + @object = new OpenAIPageableListOfVectorStoreObject(property.Value.GetString()); continue; } if (property.NameEquals("data"u8)) { - List array = new List(); + List array = new List(); foreach (var item in property.Value.EnumerateArray()) { - array.Add(MessageFile.DeserializeMessageFile(item, options)); + array.Add(VectorStore.DeserializeVectorStore(item, options)); } data = array; continue; @@ -131,7 +131,7 @@ internal static InternalOpenAIPageableListOfMessageFile DeserializeInternalOpenA } } serializedAdditionalRawData = rawDataDictionary; - return new InternalOpenAIPageableListOfMessageFile( + return new OpenAIPageableListOfVectorStore( @object, data, firstId, @@ -140,43 +140,43 @@ internal static InternalOpenAIPageableListOfMessageFile DeserializeInternalOpenA 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(InternalOpenAIPageableListOfMessageFile)} does not support writing '{options.Format}' format."); + throw new FormatException($"The model {nameof(OpenAIPageableListOfVectorStore)} does not support writing '{options.Format}' format."); } } - InternalOpenAIPageableListOfMessageFile IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + OpenAIPageableListOfVectorStore 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, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeInternalOpenAIPageableListOfMessageFile(document.RootElement, options); + return DeserializeOpenAIPageableListOfVectorStore(document.RootElement, options); } default: - throw new FormatException($"The model {nameof(InternalOpenAIPageableListOfMessageFile)} does not support reading '{options.Format}' format."); + throw new FormatException($"The model {nameof(OpenAIPageableListOfVectorStore)} does not support reading '{options.Format}' format."); } } - string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; /// Deserializes the model from a raw response. /// The response to deserialize the model from. - internal static InternalOpenAIPageableListOfMessageFile FromResponse(Response response) + internal static OpenAIPageableListOfVectorStore FromResponse(Response response) { using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeInternalOpenAIPageableListOfMessageFile(document.RootElement); + return DeserializeOpenAIPageableListOfVectorStore(document.RootElement); } /// Convert into a . diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfAssistantFile.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIPageableListOfVectorStore.cs similarity index 78% rename from sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfAssistantFile.cs rename to sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIPageableListOfVectorStore.cs index 7b5f1581bf67..1cfa1fd0b07d 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfAssistantFile.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIPageableListOfVectorStore.cs @@ -12,7 +12,7 @@ namespace Azure.AI.OpenAI.Assistants { /// The response data for a requested list of items. - internal partial class InternalOpenAIPageableListOfAssistantFile + public partial class OpenAIPageableListOfVectorStore { /// /// Keeps track of any properties unknown to the library. @@ -46,13 +46,13 @@ internal partial class InternalOpenAIPageableListOfAssistantFile /// private IDictionary _serializedAdditionalRawData; - /// Initializes a new instance of . + /// Initializes a new instance of . /// The requested list of items. /// The first ID represented in this list. /// The last ID represented in this list. /// A value indicating whether there are additional values available not captured in this list. /// , or is null. - internal InternalOpenAIPageableListOfAssistantFile(IEnumerable data, string firstId, string lastId, bool hasMore) + internal OpenAIPageableListOfVectorStore(IEnumerable data, string firstId, string lastId, bool hasMore) { Argument.AssertNotNull(data, nameof(data)); Argument.AssertNotNull(firstId, nameof(firstId)); @@ -64,14 +64,14 @@ internal InternalOpenAIPageableListOfAssistantFile(IEnumerable da HasMore = hasMore; } - /// Initializes a new instance of . + /// Initializes a new instance of . /// The object type, which is always list. /// The requested list of items. /// The first ID represented in this list. /// The last ID represented in this list. /// A value indicating whether there are additional values available not captured in this list. /// Keeps track of any properties unknown to the library. - internal InternalOpenAIPageableListOfAssistantFile(OpenAIPageableListOfAssistantFileObject @object, IReadOnlyList data, string firstId, string lastId, bool hasMore, IDictionary serializedAdditionalRawData) + internal OpenAIPageableListOfVectorStore(OpenAIPageableListOfVectorStoreObject @object, IReadOnlyList data, string firstId, string lastId, bool hasMore, IDictionary serializedAdditionalRawData) { Object = @object; Data = data; @@ -81,16 +81,16 @@ internal InternalOpenAIPageableListOfAssistantFile(OpenAIPageableListOfAssistant _serializedAdditionalRawData = serializedAdditionalRawData; } - /// Initializes a new instance of for deserialization. - internal InternalOpenAIPageableListOfAssistantFile() + /// Initializes a new instance of for deserialization. + internal OpenAIPageableListOfVectorStore() { } /// The object type, which is always list. - public OpenAIPageableListOfAssistantFileObject Object { get; } = OpenAIPageableListOfAssistantFileObject.List; + public OpenAIPageableListOfVectorStoreObject Object { get; } = OpenAIPageableListOfVectorStoreObject.List; /// The requested list of items. - public IReadOnlyList Data { get; } + public IReadOnlyList Data { get; } /// The first ID represented in this list. public string FirstId { get; } /// The last ID represented in this list. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfAssistantFile.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIPageableListOfVectorStoreFile.Serialization.cs similarity index 65% rename from sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfAssistantFile.Serialization.cs rename to sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIPageableListOfVectorStoreFile.Serialization.cs index 1408fa34d5f6..d3ad52c01a1f 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfAssistantFile.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIPageableListOfVectorStoreFile.Serialization.cs @@ -13,11 +13,11 @@ namespace Azure.AI.OpenAI.Assistants { - internal partial class InternalOpenAIPageableListOfAssistantFile : IUtf8JsonSerializable, IJsonModel + public partial class OpenAIPageableListOfVectorStoreFile : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { writer.WriteStartObject(); JsonModelWriteCore(writer, options); @@ -28,10 +28,10 @@ void IJsonModel.Write(Utf8JsonWriter /// The client options for reading and writing models. protected virtual void JsonModelWriteCore(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(InternalOpenAIPageableListOfAssistantFile)} does not support writing '{format}' format."); + throw new FormatException($"The model {nameof(OpenAIPageableListOfVectorStoreFile)} does not support writing '{format}' format."); } writer.WritePropertyName("object"u8); @@ -66,19 +66,19 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit } } - InternalOpenAIPageableListOfAssistantFile IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + OpenAIPageableListOfVectorStoreFile 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(InternalOpenAIPageableListOfAssistantFile)} does not support reading '{format}' format."); + throw new FormatException($"The model {nameof(OpenAIPageableListOfVectorStoreFile)} does not support reading '{format}' format."); } using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeInternalOpenAIPageableListOfAssistantFile(document.RootElement, options); + return DeserializeOpenAIPageableListOfVectorStoreFile(document.RootElement, options); } - internal static InternalOpenAIPageableListOfAssistantFile DeserializeInternalOpenAIPageableListOfAssistantFile(JsonElement element, ModelReaderWriterOptions options = null) + internal static OpenAIPageableListOfVectorStoreFile DeserializeOpenAIPageableListOfVectorStoreFile(JsonElement element, ModelReaderWriterOptions options = null) { options ??= ModelSerializationExtensions.WireOptions; @@ -86,8 +86,8 @@ internal static InternalOpenAIPageableListOfAssistantFile DeserializeInternalOpe { return null; } - OpenAIPageableListOfAssistantFileObject @object = default; - IReadOnlyList data = default; + OpenAIPageableListOfVectorStoreFileObject @object = default; + IReadOnlyList data = default; string firstId = default; string lastId = default; bool hasMore = default; @@ -97,15 +97,15 @@ internal static InternalOpenAIPageableListOfAssistantFile DeserializeInternalOpe { if (property.NameEquals("object"u8)) { - @object = new OpenAIPageableListOfAssistantFileObject(property.Value.GetString()); + @object = new OpenAIPageableListOfVectorStoreFileObject(property.Value.GetString()); continue; } if (property.NameEquals("data"u8)) { - List array = new List(); + List array = new List(); foreach (var item in property.Value.EnumerateArray()) { - array.Add(AssistantFile.DeserializeAssistantFile(item, options)); + array.Add(VectorStoreFile.DeserializeVectorStoreFile(item, options)); } data = array; continue; @@ -131,7 +131,7 @@ internal static InternalOpenAIPageableListOfAssistantFile DeserializeInternalOpe } } serializedAdditionalRawData = rawDataDictionary; - return new InternalOpenAIPageableListOfAssistantFile( + return new OpenAIPageableListOfVectorStoreFile( @object, data, firstId, @@ -140,43 +140,43 @@ internal static InternalOpenAIPageableListOfAssistantFile DeserializeInternalOpe 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(InternalOpenAIPageableListOfAssistantFile)} does not support writing '{options.Format}' format."); + throw new FormatException($"The model {nameof(OpenAIPageableListOfVectorStoreFile)} does not support writing '{options.Format}' format."); } } - InternalOpenAIPageableListOfAssistantFile IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + OpenAIPageableListOfVectorStoreFile 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, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeInternalOpenAIPageableListOfAssistantFile(document.RootElement, options); + return DeserializeOpenAIPageableListOfVectorStoreFile(document.RootElement, options); } default: - throw new FormatException($"The model {nameof(InternalOpenAIPageableListOfAssistantFile)} does not support reading '{options.Format}' format."); + throw new FormatException($"The model {nameof(OpenAIPageableListOfVectorStoreFile)} does not support reading '{options.Format}' format."); } } - string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; /// Deserializes the model from a raw response. /// The response to deserialize the model from. - internal static InternalOpenAIPageableListOfAssistantFile FromResponse(Response response) + internal static OpenAIPageableListOfVectorStoreFile FromResponse(Response response) { using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeInternalOpenAIPageableListOfAssistantFile(document.RootElement); + return DeserializeOpenAIPageableListOfVectorStoreFile(document.RootElement); } /// Convert into a . diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfMessageFile.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIPageableListOfVectorStoreFile.cs similarity index 78% rename from sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfMessageFile.cs rename to sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIPageableListOfVectorStoreFile.cs index 591f029940a1..8f4e487d59ad 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalOpenAIPageableListOfMessageFile.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIPageableListOfVectorStoreFile.cs @@ -12,7 +12,7 @@ namespace Azure.AI.OpenAI.Assistants { /// The response data for a requested list of items. - internal partial class InternalOpenAIPageableListOfMessageFile + public partial class OpenAIPageableListOfVectorStoreFile { /// /// Keeps track of any properties unknown to the library. @@ -46,13 +46,13 @@ internal partial class InternalOpenAIPageableListOfMessageFile /// private IDictionary _serializedAdditionalRawData; - /// Initializes a new instance of . + /// Initializes a new instance of . /// The requested list of items. /// The first ID represented in this list. /// The last ID represented in this list. /// A value indicating whether there are additional values available not captured in this list. /// , or is null. - internal InternalOpenAIPageableListOfMessageFile(IEnumerable data, string firstId, string lastId, bool hasMore) + internal OpenAIPageableListOfVectorStoreFile(IEnumerable data, string firstId, string lastId, bool hasMore) { Argument.AssertNotNull(data, nameof(data)); Argument.AssertNotNull(firstId, nameof(firstId)); @@ -64,14 +64,14 @@ internal InternalOpenAIPageableListOfMessageFile(IEnumerable data, HasMore = hasMore; } - /// Initializes a new instance of . + /// Initializes a new instance of . /// The object type, which is always list. /// The requested list of items. /// The first ID represented in this list. /// The last ID represented in this list. /// A value indicating whether there are additional values available not captured in this list. /// Keeps track of any properties unknown to the library. - internal InternalOpenAIPageableListOfMessageFile(OpenAIPageableListOfMessageFileObject @object, IReadOnlyList data, string firstId, string lastId, bool hasMore, IDictionary serializedAdditionalRawData) + internal OpenAIPageableListOfVectorStoreFile(OpenAIPageableListOfVectorStoreFileObject @object, IReadOnlyList data, string firstId, string lastId, bool hasMore, IDictionary serializedAdditionalRawData) { Object = @object; Data = data; @@ -81,16 +81,16 @@ internal InternalOpenAIPageableListOfMessageFile(OpenAIPageableListOfMessageFile _serializedAdditionalRawData = serializedAdditionalRawData; } - /// Initializes a new instance of for deserialization. - internal InternalOpenAIPageableListOfMessageFile() + /// Initializes a new instance of for deserialization. + internal OpenAIPageableListOfVectorStoreFile() { } /// The object type, which is always list. - public OpenAIPageableListOfMessageFileObject Object { get; } = OpenAIPageableListOfMessageFileObject.List; + public OpenAIPageableListOfVectorStoreFileObject Object { get; } = OpenAIPageableListOfVectorStoreFileObject.List; /// The requested list of items. - public IReadOnlyList Data { get; } + public IReadOnlyList Data { get; } /// The first ID represented in this list. public string FirstId { get; } /// The last ID represented in this list. diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIPageableListOfVectorStoreFileObject.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIPageableListOfVectorStoreFileObject.cs new file mode 100644 index 000000000000..1c678fe63a61 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIPageableListOfVectorStoreFileObject.cs @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The OpenAIPageableListOfVectorStoreFile_object. + public readonly partial struct OpenAIPageableListOfVectorStoreFileObject : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public OpenAIPageableListOfVectorStoreFileObject(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string ListValue = "list"; + + /// list. + public static OpenAIPageableListOfVectorStoreFileObject List { get; } = new OpenAIPageableListOfVectorStoreFileObject(ListValue); + /// Determines if two values are the same. + public static bool operator ==(OpenAIPageableListOfVectorStoreFileObject left, OpenAIPageableListOfVectorStoreFileObject right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(OpenAIPageableListOfVectorStoreFileObject left, OpenAIPageableListOfVectorStoreFileObject right) => !left.Equals(right); + /// Converts a to a . + public static implicit operator OpenAIPageableListOfVectorStoreFileObject(string value) => new OpenAIPageableListOfVectorStoreFileObject(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is OpenAIPageableListOfVectorStoreFileObject other && Equals(other); + /// + public bool Equals(OpenAIPageableListOfVectorStoreFileObject 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/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIPageableListOfMessageFileObject.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIPageableListOfVectorStoreObject.cs similarity index 55% rename from sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIPageableListOfMessageFileObject.cs rename to sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIPageableListOfVectorStoreObject.cs index 9993d3b6fdec..38b2253eef2e 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIPageableListOfMessageFileObject.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/OpenAIPageableListOfVectorStoreObject.cs @@ -10,14 +10,14 @@ namespace Azure.AI.OpenAI.Assistants { - /// The OpenAIPageableListOfMessageFile_object. - internal readonly partial struct OpenAIPageableListOfMessageFileObject : IEquatable + /// The OpenAIPageableListOfVectorStore_object. + public readonly partial struct OpenAIPageableListOfVectorStoreObject : IEquatable { private readonly string _value; - /// Initializes a new instance of . + /// Initializes a new instance of . /// is null. - public OpenAIPageableListOfMessageFileObject(string value) + public OpenAIPageableListOfVectorStoreObject(string value) { _value = value ?? throw new ArgumentNullException(nameof(value)); } @@ -25,19 +25,19 @@ public OpenAIPageableListOfMessageFileObject(string value) private const string ListValue = "list"; /// list. - public static OpenAIPageableListOfMessageFileObject List { get; } = new OpenAIPageableListOfMessageFileObject(ListValue); - /// Determines if two values are the same. - public static bool operator ==(OpenAIPageableListOfMessageFileObject left, OpenAIPageableListOfMessageFileObject right) => left.Equals(right); - /// Determines if two values are not the same. - public static bool operator !=(OpenAIPageableListOfMessageFileObject left, OpenAIPageableListOfMessageFileObject right) => !left.Equals(right); - /// Converts a to a . - public static implicit operator OpenAIPageableListOfMessageFileObject(string value) => new OpenAIPageableListOfMessageFileObject(value); + public static OpenAIPageableListOfVectorStoreObject List { get; } = new OpenAIPageableListOfVectorStoreObject(ListValue); + /// Determines if two values are the same. + public static bool operator ==(OpenAIPageableListOfVectorStoreObject left, OpenAIPageableListOfVectorStoreObject right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(OpenAIPageableListOfVectorStoreObject left, OpenAIPageableListOfVectorStoreObject right) => !left.Equals(right); + /// Converts a to a . + public static implicit operator OpenAIPageableListOfVectorStoreObject(string value) => new OpenAIPageableListOfVectorStoreObject(value); /// [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals(object obj) => obj is OpenAIPageableListOfMessageFileObject other && Equals(other); + public override bool Equals(object obj) => obj is OpenAIPageableListOfVectorStoreObject other && Equals(other); /// - public bool Equals(OpenAIPageableListOfMessageFileObject other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + public bool Equals(OpenAIPageableListOfVectorStoreObject other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); /// [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RetrievalToolDefinition.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RetrievalToolDefinition.cs deleted file mode 100644 index f2f39855b348..000000000000 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RetrievalToolDefinition.cs +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Collections.Generic; - -namespace Azure.AI.OpenAI.Assistants -{ - /// The input definition information for a retrieval tool as used to configure an assistant. - public partial class RetrievalToolDefinition : ToolDefinition - { - /// Initializes a new instance of . - public RetrievalToolDefinition() - { - Type = "retrieval"; - } - - /// Initializes a new instance of . - /// The object type. - /// Keeps track of any properties unknown to the library. - internal RetrievalToolDefinition(string type, IDictionary serializedAdditionalRawData) : base(type, serializedAdditionalRawData) - { - } - } -} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunCompletionUsage.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunCompletionUsage.Serialization.cs new file mode 100644 index 000000000000..282fd568dd43 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunCompletionUsage.Serialization.cs @@ -0,0 +1,158 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class RunCompletionUsage : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(RunCompletionUsage)} does not support writing '{format}' format."); + } + + writer.WritePropertyName("completion_tokens"u8); + writer.WriteNumberValue(CompletionTokens); + writer.WritePropertyName("prompt_tokens"u8); + writer.WriteNumberValue(PromptTokens); + writer.WritePropertyName("total_tokens"u8); + writer.WriteNumberValue(TotalTokens); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + RunCompletionUsage 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(RunCompletionUsage)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeRunCompletionUsage(document.RootElement, options); + } + + internal static RunCompletionUsage DeserializeRunCompletionUsage(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + long completionTokens = default; + long promptTokens = default; + long totalTokens = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("completion_tokens"u8)) + { + completionTokens = property.Value.GetInt64(); + continue; + } + if (property.NameEquals("prompt_tokens"u8)) + { + promptTokens = property.Value.GetInt64(); + continue; + } + if (property.NameEquals("total_tokens"u8)) + { + totalTokens = property.Value.GetInt64(); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new RunCompletionUsage(completionTokens, promptTokens, totalTokens, 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(RunCompletionUsage)} does not support writing '{options.Format}' format."); + } + } + + RunCompletionUsage 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeRunCompletionUsage(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(RunCompletionUsage)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static RunCompletionUsage FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeRunCompletionUsage(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunCompletionUsage.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunCompletionUsage.cs new file mode 100644 index 000000000000..2dfd3c2ee2c8 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunCompletionUsage.cs @@ -0,0 +1,84 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Usage statistics related to the run. This value will be `null` if the run is not in a terminal state (i.e. `in_progress`, `queued`, etc.). + public partial class RunCompletionUsage + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + /// Number of completion tokens used over the course of the run. + /// Number of prompt tokens used over the course of the run. + /// Total number of tokens used (prompt + completion). + internal RunCompletionUsage(long completionTokens, long promptTokens, long totalTokens) + { + CompletionTokens = completionTokens; + PromptTokens = promptTokens; + TotalTokens = totalTokens; + } + + /// Initializes a new instance of . + /// Number of completion tokens used over the course of the run. + /// Number of prompt tokens used over the course of the run. + /// Total number of tokens used (prompt + completion). + /// Keeps track of any properties unknown to the library. + internal RunCompletionUsage(long completionTokens, long promptTokens, long totalTokens, IDictionary serializedAdditionalRawData) + { + CompletionTokens = completionTokens; + PromptTokens = promptTokens; + TotalTokens = totalTokens; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal RunCompletionUsage() + { + } + + /// Number of completion tokens used over the course of the run. + public long CompletionTokens { get; } + /// Number of prompt tokens used over the course of the run. + public long PromptTokens { get; } + /// Total number of tokens used (prompt + completion). + public long TotalTokens { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunIncludes.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunIncludes.cs new file mode 100644 index 000000000000..5e0e0daee070 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunIncludes.cs @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Values to for the includes parameter in the create run operation. + public readonly partial struct RunIncludes : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public RunIncludes(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string FileSearchContentValue = "step_details.tool_calls[*].file_search.results[*].content"; + + /// Fetch the file search result content. + public static RunIncludes FileSearchContent { get; } = new RunIncludes(FileSearchContentValue); + /// Determines if two values are the same. + public static bool operator ==(RunIncludes left, RunIncludes right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(RunIncludes left, RunIncludes right) => !left.Equals(right); + /// Converts a to a . + public static implicit operator RunIncludes(string value) => new RunIncludes(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is RunIncludes other && Equals(other); + /// + public bool Equals(RunIncludes 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/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStep.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStep.Serialization.cs index 3efdb79c0c6a..25e17327254c 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStep.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStep.Serialization.cs @@ -97,6 +97,18 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit { writer.WriteNull("failed_at"); } + if (Optional.IsDefined(Usage)) + { + if (Usage != null) + { + writer.WritePropertyName("usage"u8); + writer.WriteObjectValue(Usage, options); + } + else + { + writer.WriteNull("usage"); + } + } if (Metadata != null && Optional.IsCollectionDefined(Metadata)) { writer.WritePropertyName("metadata"u8); @@ -163,6 +175,7 @@ internal static RunStep DeserializeRunStep(JsonElement element, ModelReaderWrite DateTimeOffset? completedAt = default; DateTimeOffset? cancelledAt = default; DateTimeOffset? failedAt = default; + RunStepCompletionUsage usage = default; IReadOnlyDictionary metadata = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); @@ -243,6 +256,16 @@ internal static RunStep DeserializeRunStep(JsonElement element, ModelReaderWrite DeserializeNullableDateTimeOffset(property, ref failedAt); continue; } + if (property.NameEquals("usage"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + usage = null; + continue; + } + usage = RunStepCompletionUsage.DeserializeRunStepCompletionUsage(property.Value, options); + continue; + } if (property.NameEquals("metadata"u8)) { if (property.Value.ValueKind == JsonValueKind.Null) @@ -279,6 +302,7 @@ internal static RunStep DeserializeRunStep(JsonElement element, ModelReaderWrite completedAt, cancelledAt, failedAt, + usage, metadata, serializedAdditionalRawData); } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStep.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStep.cs index 9d8d21d55457..3b622f261eb6 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStep.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStep.cs @@ -108,9 +108,10 @@ internal RunStep(string id, RunStepType type, string assistantId, string threadI /// The Unix timestamp, in seconds, representing when this completed. /// The Unix timestamp, in seconds, representing when this was cancelled. /// The Unix timestamp, in seconds, representing when this failed. + /// Usage statistics related to the run step. This value will be `null` while the run step's status is `in_progress`. /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. /// Keeps track of any properties unknown to the library. - internal RunStep(string id, string @object, RunStepType type, string assistantId, string threadId, string runId, RunStepStatus status, RunStepDetails stepDetails, RunStepError lastError, DateTimeOffset createdAt, DateTimeOffset? expiredAt, DateTimeOffset? completedAt, DateTimeOffset? cancelledAt, DateTimeOffset? failedAt, IReadOnlyDictionary metadata, IDictionary serializedAdditionalRawData) + internal RunStep(string id, string @object, RunStepType type, string assistantId, string threadId, string runId, RunStepStatus status, RunStepDetails stepDetails, RunStepError lastError, DateTimeOffset createdAt, DateTimeOffset? expiredAt, DateTimeOffset? completedAt, DateTimeOffset? cancelledAt, DateTimeOffset? failedAt, RunStepCompletionUsage usage, IReadOnlyDictionary metadata, IDictionary serializedAdditionalRawData) { Id = id; Object = @object; @@ -126,6 +127,7 @@ internal RunStep(string id, string @object, RunStepType type, string assistantId CompletedAt = completedAt; CancelledAt = cancelledAt; FailedAt = failedAt; + Usage = usage; Metadata = metadata; _serializedAdditionalRawData = serializedAdditionalRawData; } @@ -166,6 +168,8 @@ internal RunStep() public DateTimeOffset? CancelledAt { get; } /// The Unix timestamp, in seconds, representing when this failed. public DateTimeOffset? FailedAt { get; } + /// Usage statistics related to the run step. This value will be `null` while the run step's status is `in_progress`. + public RunStepCompletionUsage Usage { get; } /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. public IReadOnlyDictionary Metadata { get; } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepCompletionUsage.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepCompletionUsage.Serialization.cs new file mode 100644 index 000000000000..1d6631a4b731 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepCompletionUsage.Serialization.cs @@ -0,0 +1,158 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class RunStepCompletionUsage : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(RunStepCompletionUsage)} does not support writing '{format}' format."); + } + + writer.WritePropertyName("completion_tokens"u8); + writer.WriteNumberValue(CompletionTokens); + writer.WritePropertyName("prompt_tokens"u8); + writer.WriteNumberValue(PromptTokens); + writer.WritePropertyName("total_tokens"u8); + writer.WriteNumberValue(TotalTokens); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + RunStepCompletionUsage 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(RunStepCompletionUsage)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeRunStepCompletionUsage(document.RootElement, options); + } + + internal static RunStepCompletionUsage DeserializeRunStepCompletionUsage(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + long completionTokens = default; + long promptTokens = default; + long totalTokens = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("completion_tokens"u8)) + { + completionTokens = property.Value.GetInt64(); + continue; + } + if (property.NameEquals("prompt_tokens"u8)) + { + promptTokens = property.Value.GetInt64(); + continue; + } + if (property.NameEquals("total_tokens"u8)) + { + totalTokens = property.Value.GetInt64(); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new RunStepCompletionUsage(completionTokens, promptTokens, totalTokens, 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(RunStepCompletionUsage)} does not support writing '{options.Format}' format."); + } + } + + RunStepCompletionUsage 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeRunStepCompletionUsage(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(RunStepCompletionUsage)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static RunStepCompletionUsage FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeRunStepCompletionUsage(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepCompletionUsage.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepCompletionUsage.cs new file mode 100644 index 000000000000..738d57f0df80 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepCompletionUsage.cs @@ -0,0 +1,84 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Usage statistics related to the run step. + public partial class RunStepCompletionUsage + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + /// Number of completion tokens used over the course of the run step. + /// Number of prompt tokens used over the course of the run step. + /// Total number of tokens used (prompt + completion). + internal RunStepCompletionUsage(long completionTokens, long promptTokens, long totalTokens) + { + CompletionTokens = completionTokens; + PromptTokens = promptTokens; + TotalTokens = totalTokens; + } + + /// Initializes a new instance of . + /// Number of completion tokens used over the course of the run step. + /// Number of prompt tokens used over the course of the run step. + /// Total number of tokens used (prompt + completion). + /// Keeps track of any properties unknown to the library. + internal RunStepCompletionUsage(long completionTokens, long promptTokens, long totalTokens, IDictionary serializedAdditionalRawData) + { + CompletionTokens = completionTokens; + PromptTokens = promptTokens; + TotalTokens = totalTokens; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal RunStepCompletionUsage() + { + } + + /// Number of completion tokens used over the course of the run step. + public long CompletionTokens { get; } + /// Number of prompt tokens used over the course of the run step. + public long PromptTokens { get; } + /// Total number of tokens used (prompt + completion). + public long TotalTokens { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDelta.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDelta.Serialization.cs new file mode 100644 index 000000000000..fbc756acda1b --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDelta.Serialization.cs @@ -0,0 +1,149 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class RunStepDelta : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(RunStepDelta)} does not support writing '{format}' format."); + } + + if (Optional.IsDefined(StepDetails)) + { + writer.WritePropertyName("step_details"u8); + writer.WriteObjectValue(StepDetails, options); + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + RunStepDelta 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(RunStepDelta)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeRunStepDelta(document.RootElement, options); + } + + internal static RunStepDelta DeserializeRunStepDelta(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + RunStepDeltaDetail stepDetails = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("step_details"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + stepDetails = RunStepDeltaDetail.DeserializeRunStepDeltaDetail(property.Value, options); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new RunStepDelta(stepDetails, 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(RunStepDelta)} does not support writing '{options.Format}' format."); + } + } + + RunStepDelta 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeRunStepDelta(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(RunStepDelta)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static RunStepDelta FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeRunStepDelta(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDelta.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDelta.cs new file mode 100644 index 000000000000..9b28f292c68b --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDelta.cs @@ -0,0 +1,73 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Represents the delta payload in a streaming run step delta chunk. + public partial class RunStepDelta + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + internal RunStepDelta() + { + } + + /// Initializes a new instance of . + /// + /// The details of the run step. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include and . + /// + /// Keeps track of any properties unknown to the library. + internal RunStepDelta(RunStepDeltaDetail stepDetails, IDictionary serializedAdditionalRawData) + { + StepDetails = stepDetails; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// + /// The details of the run step. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include and . + /// + public RunStepDeltaDetail StepDetails { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaChunk.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaChunk.Serialization.cs new file mode 100644 index 000000000000..94cbacc1a0a3 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaChunk.Serialization.cs @@ -0,0 +1,158 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class RunStepDeltaChunk : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(RunStepDeltaChunk)} does not support writing '{format}' format."); + } + + writer.WritePropertyName("id"u8); + writer.WriteStringValue(Id); + writer.WritePropertyName("object"u8); + writer.WriteStringValue(Object.ToString()); + writer.WritePropertyName("delta"u8); + writer.WriteObjectValue(Delta, options); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + RunStepDeltaChunk 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(RunStepDeltaChunk)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeRunStepDeltaChunk(document.RootElement, options); + } + + internal static RunStepDeltaChunk DeserializeRunStepDeltaChunk(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string id = default; + RunStepDeltaChunkObject @object = default; + RunStepDelta delta = 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("object"u8)) + { + @object = new RunStepDeltaChunkObject(property.Value.GetString()); + continue; + } + if (property.NameEquals("delta"u8)) + { + delta = RunStepDelta.DeserializeRunStepDelta(property.Value, options); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new RunStepDeltaChunk(id, @object, delta, 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(RunStepDeltaChunk)} does not support writing '{options.Format}' format."); + } + } + + RunStepDeltaChunk 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeRunStepDeltaChunk(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(RunStepDeltaChunk)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static RunStepDeltaChunk FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeRunStepDeltaChunk(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantFile.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaChunk.cs similarity index 51% rename from sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantFile.cs rename to sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaChunk.cs index 119a216efc63..b577dd0a9f7d 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantFile.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaChunk.cs @@ -10,8 +10,8 @@ namespace Azure.AI.OpenAI.Assistants { - /// Information about a file attached to an assistant, as used by tools that can read files. - public partial class AssistantFile + /// Represents a run step delta i.e. any changed fields on a run step during streaming. + public partial class RunStepDeltaChunk { /// /// Keeps track of any properties unknown to the library. @@ -45,47 +45,43 @@ public partial class AssistantFile /// private IDictionary _serializedAdditionalRawData; - /// Initializes a new instance of . - /// The identifier, which can be referenced in API endpoints. - /// The Unix timestamp, in seconds, representing when this object was created. - /// The assistant ID that the file is attached to. - /// or is null. - internal AssistantFile(string id, DateTimeOffset createdAt, string assistantId) + /// Initializes a new instance of . + /// The identifier of the run step, which can be referenced in API endpoints. + /// The delta containing the fields that have changed on the run step. + /// or is null. + internal RunStepDeltaChunk(string id, RunStepDelta delta) { Argument.AssertNotNull(id, nameof(id)); - Argument.AssertNotNull(assistantId, nameof(assistantId)); + Argument.AssertNotNull(delta, nameof(delta)); Id = id; - CreatedAt = createdAt; - AssistantId = assistantId; + Delta = delta; } - /// Initializes a new instance of . - /// The identifier, which can be referenced in API endpoints. - /// The object type, which is always 'assistant.file'. - /// The Unix timestamp, in seconds, representing when this object was created. - /// The assistant ID that the file is attached to. + /// Initializes a new instance of . + /// The identifier of the run step, which can be referenced in API endpoints. + /// The object type, which is always `thread.run.step.delta`. + /// The delta containing the fields that have changed on the run step. /// Keeps track of any properties unknown to the library. - internal AssistantFile(string id, string @object, DateTimeOffset createdAt, string assistantId, IDictionary serializedAdditionalRawData) + internal RunStepDeltaChunk(string id, RunStepDeltaChunkObject @object, RunStepDelta delta, IDictionary serializedAdditionalRawData) { Id = id; Object = @object; - CreatedAt = createdAt; - AssistantId = assistantId; + Delta = delta; _serializedAdditionalRawData = serializedAdditionalRawData; } - /// Initializes a new instance of for deserialization. - internal AssistantFile() + /// Initializes a new instance of for deserialization. + internal RunStepDeltaChunk() { } - /// The identifier, which can be referenced in API endpoints. + /// The identifier of the run step, which can be referenced in API endpoints. public string Id { get; } + /// The object type, which is always `thread.run.step.delta`. + public RunStepDeltaChunkObject Object { get; } = RunStepDeltaChunkObject.ThreadRunStepDelta; - /// The Unix timestamp, in seconds, representing when this object was created. - public DateTimeOffset CreatedAt { get; } - /// The assistant ID that the file is attached to. - public string AssistantId { get; } + /// The delta containing the fields that have changed on the run step. + public RunStepDelta Delta { get; } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaChunkObject.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaChunkObject.cs new file mode 100644 index 000000000000..4cadb42a2b35 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaChunkObject.cs @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The RunStepDeltaChunk_object. + public readonly partial struct RunStepDeltaChunkObject : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public RunStepDeltaChunkObject(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string ThreadRunStepDeltaValue = "thread.run.step.delta"; + + /// thread.run.step.delta. + public static RunStepDeltaChunkObject ThreadRunStepDelta { get; } = new RunStepDeltaChunkObject(ThreadRunStepDeltaValue); + /// Determines if two values are the same. + public static bool operator ==(RunStepDeltaChunkObject left, RunStepDeltaChunkObject right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(RunStepDeltaChunkObject left, RunStepDeltaChunkObject right) => !left.Equals(right); + /// Converts a to a . + public static implicit operator RunStepDeltaChunkObject(string value) => new RunStepDeltaChunkObject(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is RunStepDeltaChunkObject other && Equals(other); + /// + public bool Equals(RunStepDeltaChunkObject 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/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaCodeInterpreterDetailItemObject.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaCodeInterpreterDetailItemObject.Serialization.cs new file mode 100644 index 000000000000..6c053796b8bb --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaCodeInterpreterDetailItemObject.Serialization.cs @@ -0,0 +1,170 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class RunStepDeltaCodeInterpreterDetailItemObject : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(RunStepDeltaCodeInterpreterDetailItemObject)} does not support writing '{format}' format."); + } + + if (Optional.IsDefined(Input)) + { + writer.WritePropertyName("input"u8); + writer.WriteStringValue(Input); + } + if (Optional.IsCollectionDefined(Outputs)) + { + writer.WritePropertyName("outputs"u8); + writer.WriteStartArray(); + foreach (var item in Outputs) + { + writer.WriteObjectValue(item, options); + } + writer.WriteEndArray(); + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + RunStepDeltaCodeInterpreterDetailItemObject 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(RunStepDeltaCodeInterpreterDetailItemObject)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeRunStepDeltaCodeInterpreterDetailItemObject(document.RootElement, options); + } + + internal static RunStepDeltaCodeInterpreterDetailItemObject DeserializeRunStepDeltaCodeInterpreterDetailItemObject(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string input = default; + IReadOnlyList outputs = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("input"u8)) + { + input = property.Value.GetString(); + continue; + } + if (property.NameEquals("outputs"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(RunStepDeltaCodeInterpreterOutput.DeserializeRunStepDeltaCodeInterpreterOutput(item, options)); + } + outputs = array; + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new RunStepDeltaCodeInterpreterDetailItemObject(input, outputs ?? 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(RunStepDeltaCodeInterpreterDetailItemObject)} does not support writing '{options.Format}' format."); + } + } + + RunStepDeltaCodeInterpreterDetailItemObject 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeRunStepDeltaCodeInterpreterDetailItemObject(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(RunStepDeltaCodeInterpreterDetailItemObject)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static RunStepDeltaCodeInterpreterDetailItemObject FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeRunStepDeltaCodeInterpreterDetailItemObject(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaCodeInterpreterDetailItemObject.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaCodeInterpreterDetailItemObject.cs new file mode 100644 index 000000000000..d3a655d903d0 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaCodeInterpreterDetailItemObject.cs @@ -0,0 +1,82 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Represents the Code Interpreter tool call data in a streaming run step's tool calls. + public partial class RunStepDeltaCodeInterpreterDetailItemObject + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + internal RunStepDeltaCodeInterpreterDetailItemObject() + { + Outputs = new ChangeTrackingList(); + } + + /// Initializes a new instance of . + /// The input into the Code Interpreter tool call. + /// + /// The outputs from the Code Interpreter tool call. Code Interpreter can output one or more + /// items, including text (`logs`) or images (`image`). Each of these are represented by a + /// different object type. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include and . + /// + /// Keeps track of any properties unknown to the library. + internal RunStepDeltaCodeInterpreterDetailItemObject(string input, IReadOnlyList outputs, IDictionary serializedAdditionalRawData) + { + Input = input; + Outputs = outputs; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// The input into the Code Interpreter tool call. + public string Input { get; } + /// + /// The outputs from the Code Interpreter tool call. Code Interpreter can output one or more + /// items, including text (`logs`) or images (`image`). Each of these are represented by a + /// different object type. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include and . + /// + public IReadOnlyList Outputs { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaCodeInterpreterImageOutput.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaCodeInterpreterImageOutput.Serialization.cs new file mode 100644 index 000000000000..593618121d8d --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaCodeInterpreterImageOutput.Serialization.cs @@ -0,0 +1,147 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class RunStepDeltaCodeInterpreterImageOutput : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(RunStepDeltaCodeInterpreterImageOutput)} does not support writing '{format}' format."); + } + + base.JsonModelWriteCore(writer, options); + if (Optional.IsDefined(Image)) + { + writer.WritePropertyName("image"u8); + writer.WriteObjectValue(Image, options); + } + } + + RunStepDeltaCodeInterpreterImageOutput 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(RunStepDeltaCodeInterpreterImageOutput)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeRunStepDeltaCodeInterpreterImageOutput(document.RootElement, options); + } + + internal static RunStepDeltaCodeInterpreterImageOutput DeserializeRunStepDeltaCodeInterpreterImageOutput(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + RunStepDeltaCodeInterpreterImageOutputObject image = default; + int index = default; + string type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("image"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + image = RunStepDeltaCodeInterpreterImageOutputObject.DeserializeRunStepDeltaCodeInterpreterImageOutputObject(property.Value, options); + continue; + } + if (property.NameEquals("index"u8)) + { + index = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new RunStepDeltaCodeInterpreterImageOutput(index, type, serializedAdditionalRawData, image); + } + + 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(RunStepDeltaCodeInterpreterImageOutput)} does not support writing '{options.Format}' format."); + } + } + + RunStepDeltaCodeInterpreterImageOutput 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeRunStepDeltaCodeInterpreterImageOutput(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(RunStepDeltaCodeInterpreterImageOutput)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new RunStepDeltaCodeInterpreterImageOutput FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeRunStepDeltaCodeInterpreterImageOutput(document.RootElement); + } + + /// Convert into a . + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaCodeInterpreterImageOutput.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaCodeInterpreterImageOutput.cs new file mode 100644 index 000000000000..0d80fac4887c --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaCodeInterpreterImageOutput.cs @@ -0,0 +1,41 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Represents an image output as produced the Code interpreter tool and as represented in a streaming run step's delta tool calls collection. + public partial class RunStepDeltaCodeInterpreterImageOutput : RunStepDeltaCodeInterpreterOutput + { + /// Initializes a new instance of . + /// The index of the output in the streaming run step tool call's Code Interpreter outputs array. + internal RunStepDeltaCodeInterpreterImageOutput(int index) : base(index) + { + Type = "image"; + } + + /// Initializes a new instance of . + /// The index of the output in the streaming run step tool call's Code Interpreter outputs array. + /// The type of the streaming run step tool call's Code Interpreter output. + /// Keeps track of any properties unknown to the library. + /// The image data for the Code Interpreter tool call output. + internal RunStepDeltaCodeInterpreterImageOutput(int index, string type, IDictionary serializedAdditionalRawData, RunStepDeltaCodeInterpreterImageOutputObject image) : base(index, type, serializedAdditionalRawData) + { + Image = image; + } + + /// Initializes a new instance of for deserialization. + internal RunStepDeltaCodeInterpreterImageOutput() + { + } + + /// The image data for the Code Interpreter tool call output. + public RunStepDeltaCodeInterpreterImageOutputObject Image { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaCodeInterpreterImageOutputObject.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaCodeInterpreterImageOutputObject.Serialization.cs new file mode 100644 index 000000000000..9d7feaabb742 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaCodeInterpreterImageOutputObject.Serialization.cs @@ -0,0 +1,145 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class RunStepDeltaCodeInterpreterImageOutputObject : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(RunStepDeltaCodeInterpreterImageOutputObject)} does not support writing '{format}' format."); + } + + if (Optional.IsDefined(FileId)) + { + writer.WritePropertyName("file_id"u8); + writer.WriteStringValue(FileId); + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + RunStepDeltaCodeInterpreterImageOutputObject 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(RunStepDeltaCodeInterpreterImageOutputObject)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeRunStepDeltaCodeInterpreterImageOutputObject(document.RootElement, options); + } + + internal static RunStepDeltaCodeInterpreterImageOutputObject DeserializeRunStepDeltaCodeInterpreterImageOutputObject(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string fileId = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("file_id"u8)) + { + fileId = property.Value.GetString(); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new RunStepDeltaCodeInterpreterImageOutputObject(fileId, 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(RunStepDeltaCodeInterpreterImageOutputObject)} does not support writing '{options.Format}' format."); + } + } + + RunStepDeltaCodeInterpreterImageOutputObject 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeRunStepDeltaCodeInterpreterImageOutputObject(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(RunStepDeltaCodeInterpreterImageOutputObject)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static RunStepDeltaCodeInterpreterImageOutputObject FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeRunStepDeltaCodeInterpreterImageOutputObject(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaCodeInterpreterImageOutputObject.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaCodeInterpreterImageOutputObject.cs new file mode 100644 index 000000000000..35c4bf8d080b --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaCodeInterpreterImageOutputObject.cs @@ -0,0 +1,65 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Represents the data for a streaming run step's Code Interpreter tool call image output. + public partial class RunStepDeltaCodeInterpreterImageOutputObject + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + internal RunStepDeltaCodeInterpreterImageOutputObject() + { + } + + /// Initializes a new instance of . + /// The file ID for the image. + /// Keeps track of any properties unknown to the library. + internal RunStepDeltaCodeInterpreterImageOutputObject(string fileId, IDictionary serializedAdditionalRawData) + { + FileId = fileId; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// The file ID for the image. + public string FileId { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaCodeInterpreterLogOutput.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaCodeInterpreterLogOutput.Serialization.cs new file mode 100644 index 000000000000..b92c96d6348f --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaCodeInterpreterLogOutput.Serialization.cs @@ -0,0 +1,143 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class RunStepDeltaCodeInterpreterLogOutput : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(RunStepDeltaCodeInterpreterLogOutput)} does not support writing '{format}' format."); + } + + base.JsonModelWriteCore(writer, options); + if (Optional.IsDefined(Logs)) + { + writer.WritePropertyName("logs"u8); + writer.WriteStringValue(Logs); + } + } + + RunStepDeltaCodeInterpreterLogOutput 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(RunStepDeltaCodeInterpreterLogOutput)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeRunStepDeltaCodeInterpreterLogOutput(document.RootElement, options); + } + + internal static RunStepDeltaCodeInterpreterLogOutput DeserializeRunStepDeltaCodeInterpreterLogOutput(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string logs = default; + int index = default; + string type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("logs"u8)) + { + logs = property.Value.GetString(); + continue; + } + if (property.NameEquals("index"u8)) + { + index = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new RunStepDeltaCodeInterpreterLogOutput(index, type, serializedAdditionalRawData, logs); + } + + 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(RunStepDeltaCodeInterpreterLogOutput)} does not support writing '{options.Format}' format."); + } + } + + RunStepDeltaCodeInterpreterLogOutput 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeRunStepDeltaCodeInterpreterLogOutput(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(RunStepDeltaCodeInterpreterLogOutput)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new RunStepDeltaCodeInterpreterLogOutput FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeRunStepDeltaCodeInterpreterLogOutput(document.RootElement); + } + + /// Convert into a . + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaCodeInterpreterLogOutput.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaCodeInterpreterLogOutput.cs new file mode 100644 index 000000000000..96eaa7b38dc3 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaCodeInterpreterLogOutput.cs @@ -0,0 +1,41 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Represents a log output as produced by the Code Interpreter tool and as represented in a streaming run step's delta tool calls collection. + public partial class RunStepDeltaCodeInterpreterLogOutput : RunStepDeltaCodeInterpreterOutput + { + /// Initializes a new instance of . + /// The index of the output in the streaming run step tool call's Code Interpreter outputs array. + internal RunStepDeltaCodeInterpreterLogOutput(int index) : base(index) + { + Type = "logs"; + } + + /// Initializes a new instance of . + /// The index of the output in the streaming run step tool call's Code Interpreter outputs array. + /// The type of the streaming run step tool call's Code Interpreter output. + /// Keeps track of any properties unknown to the library. + /// The text output from the Code Interpreter tool call. + internal RunStepDeltaCodeInterpreterLogOutput(int index, string type, IDictionary serializedAdditionalRawData, string logs) : base(index, type, serializedAdditionalRawData) + { + Logs = logs; + } + + /// Initializes a new instance of for deserialization. + internal RunStepDeltaCodeInterpreterLogOutput() + { + } + + /// The text output from the Code Interpreter tool call. + public string Logs { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaCodeInterpreterOutput.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaCodeInterpreterOutput.Serialization.cs new file mode 100644 index 000000000000..f67acd16276c --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaCodeInterpreterOutput.Serialization.cs @@ -0,0 +1,136 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + [PersistableModelProxy(typeof(UnknownRunStepDeltaCodeInterpreterOutput))] + public partial class RunStepDeltaCodeInterpreterOutput : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(RunStepDeltaCodeInterpreterOutput)} does not support writing '{format}' format."); + } + + writer.WritePropertyName("index"u8); + writer.WriteNumberValue(Index); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + RunStepDeltaCodeInterpreterOutput 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(RunStepDeltaCodeInterpreterOutput)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeRunStepDeltaCodeInterpreterOutput(document.RootElement, options); + } + + internal static RunStepDeltaCodeInterpreterOutput DeserializeRunStepDeltaCodeInterpreterOutput(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 "image": return RunStepDeltaCodeInterpreterImageOutput.DeserializeRunStepDeltaCodeInterpreterImageOutput(element, options); + case "logs": return RunStepDeltaCodeInterpreterLogOutput.DeserializeRunStepDeltaCodeInterpreterLogOutput(element, options); + } + } + return UnknownRunStepDeltaCodeInterpreterOutput.DeserializeUnknownRunStepDeltaCodeInterpreterOutput(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(RunStepDeltaCodeInterpreterOutput)} does not support writing '{options.Format}' format."); + } + } + + RunStepDeltaCodeInterpreterOutput 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeRunStepDeltaCodeInterpreterOutput(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(RunStepDeltaCodeInterpreterOutput)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static RunStepDeltaCodeInterpreterOutput FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeRunStepDeltaCodeInterpreterOutput(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaCodeInterpreterOutput.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaCodeInterpreterOutput.cs new file mode 100644 index 000000000000..396e993239ce --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaCodeInterpreterOutput.cs @@ -0,0 +1,80 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// + /// The abstract base representation of a streaming run step tool call's Code Interpreter tool output. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include and . + /// + public abstract partial class RunStepDeltaCodeInterpreterOutput + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private protected IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + /// The index of the output in the streaming run step tool call's Code Interpreter outputs array. + protected RunStepDeltaCodeInterpreterOutput(int index) + { + Index = index; + } + + /// Initializes a new instance of . + /// The index of the output in the streaming run step tool call's Code Interpreter outputs array. + /// The type of the streaming run step tool call's Code Interpreter output. + /// Keeps track of any properties unknown to the library. + internal RunStepDeltaCodeInterpreterOutput(int index, string type, IDictionary serializedAdditionalRawData) + { + Index = index; + Type = type; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal RunStepDeltaCodeInterpreterOutput() + { + } + + /// The index of the output in the streaming run step tool call's Code Interpreter outputs array. + public int Index { get; } + /// The type of the streaming run step tool call's Code Interpreter output. + internal string Type { get; set; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaCodeInterpreterToolCall.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaCodeInterpreterToolCall.Serialization.cs new file mode 100644 index 000000000000..489f5d289a93 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaCodeInterpreterToolCall.Serialization.cs @@ -0,0 +1,153 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class RunStepDeltaCodeInterpreterToolCall : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(RunStepDeltaCodeInterpreterToolCall)} does not support writing '{format}' format."); + } + + base.JsonModelWriteCore(writer, options); + if (Optional.IsDefined(CodeInterpreter)) + { + writer.WritePropertyName("code_interpreter"u8); + writer.WriteObjectValue(CodeInterpreter, options); + } + } + + RunStepDeltaCodeInterpreterToolCall 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(RunStepDeltaCodeInterpreterToolCall)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeRunStepDeltaCodeInterpreterToolCall(document.RootElement, options); + } + + internal static RunStepDeltaCodeInterpreterToolCall DeserializeRunStepDeltaCodeInterpreterToolCall(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + RunStepDeltaCodeInterpreterDetailItemObject codeInterpreter = default; + int index = default; + string id = default; + string type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("code_interpreter"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + codeInterpreter = RunStepDeltaCodeInterpreterDetailItemObject.DeserializeRunStepDeltaCodeInterpreterDetailItemObject(property.Value, options); + continue; + } + if (property.NameEquals("index"u8)) + { + index = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("id"u8)) + { + id = property.Value.GetString(); + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new RunStepDeltaCodeInterpreterToolCall(index, id, type, serializedAdditionalRawData, codeInterpreter); + } + + 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(RunStepDeltaCodeInterpreterToolCall)} does not support writing '{options.Format}' format."); + } + } + + RunStepDeltaCodeInterpreterToolCall 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeRunStepDeltaCodeInterpreterToolCall(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(RunStepDeltaCodeInterpreterToolCall)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new RunStepDeltaCodeInterpreterToolCall FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeRunStepDeltaCodeInterpreterToolCall(document.RootElement); + } + + /// Convert into a . + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaCodeInterpreterToolCall.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaCodeInterpreterToolCall.cs new file mode 100644 index 000000000000..059c30cbca81 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaCodeInterpreterToolCall.cs @@ -0,0 +1,46 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Represents a Code Interpreter tool call within a streaming run step's tool call details. + public partial class RunStepDeltaCodeInterpreterToolCall : RunStepDeltaToolCall + { + /// Initializes a new instance of . + /// The index of the tool call detail in the run step's tool_calls array. + /// The ID of the tool call, used when submitting outputs to the run. + /// is null. + internal RunStepDeltaCodeInterpreterToolCall(int index, string id) : base(index, id) + { + Argument.AssertNotNull(id, nameof(id)); + + Type = "code_interpreter"; + } + + /// Initializes a new instance of . + /// The index of the tool call detail in the run step's tool_calls array. + /// The ID of the tool call, used when submitting outputs to the run. + /// The type of the tool call detail item in a streaming run step's details. + /// Keeps track of any properties unknown to the library. + /// The Code Interpreter data for the tool call. + internal RunStepDeltaCodeInterpreterToolCall(int index, string id, string type, IDictionary serializedAdditionalRawData, RunStepDeltaCodeInterpreterDetailItemObject codeInterpreter) : base(index, id, type, serializedAdditionalRawData) + { + CodeInterpreter = codeInterpreter; + } + + /// Initializes a new instance of for deserialization. + internal RunStepDeltaCodeInterpreterToolCall() + { + } + + /// The Code Interpreter data for the tool call. + public RunStepDeltaCodeInterpreterDetailItemObject CodeInterpreter { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaDetail.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaDetail.Serialization.cs new file mode 100644 index 000000000000..8fad23851a70 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaDetail.Serialization.cs @@ -0,0 +1,134 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + [PersistableModelProxy(typeof(UnknownRunStepDeltaDetail))] + public partial class RunStepDeltaDetail : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(RunStepDeltaDetail)} does not support writing '{format}' format."); + } + + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + RunStepDeltaDetail 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(RunStepDeltaDetail)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeRunStepDeltaDetail(document.RootElement, options); + } + + internal static RunStepDeltaDetail DeserializeRunStepDeltaDetail(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 "message_creation": return RunStepDeltaMessageCreation.DeserializeRunStepDeltaMessageCreation(element, options); + case "tool_calls": return RunStepDeltaToolCallObject.DeserializeRunStepDeltaToolCallObject(element, options); + } + } + return UnknownRunStepDeltaDetail.DeserializeUnknownRunStepDeltaDetail(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(RunStepDeltaDetail)} does not support writing '{options.Format}' format."); + } + } + + RunStepDeltaDetail 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeRunStepDeltaDetail(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(RunStepDeltaDetail)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static RunStepDeltaDetail FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeRunStepDeltaDetail(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaDetail.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaDetail.cs new file mode 100644 index 000000000000..508fac38660c --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaDetail.cs @@ -0,0 +1,69 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// + /// Represents a single run step detail item in a streaming run step's delta payload. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include and . + /// + public abstract partial class RunStepDeltaDetail + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private protected IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + protected RunStepDeltaDetail() + { + } + + /// Initializes a new instance of . + /// The object type for the run step detail object. + /// Keeps track of any properties unknown to the library. + internal RunStepDeltaDetail(string type, IDictionary serializedAdditionalRawData) + { + Type = type; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// The object type for the run step detail object. + internal string Type { get; set; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaFileSearchToolCall.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaFileSearchToolCall.Serialization.cs new file mode 100644 index 000000000000..2ef059879d2f --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaFileSearchToolCall.Serialization.cs @@ -0,0 +1,164 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class RunStepDeltaFileSearchToolCall : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(RunStepDeltaFileSearchToolCall)} does not support writing '{format}' format."); + } + + base.JsonModelWriteCore(writer, options); + if (Optional.IsCollectionDefined(FileSearch)) + { + writer.WritePropertyName("file_search"u8); + writer.WriteStartObject(); + foreach (var item in FileSearch) + { + writer.WritePropertyName(item.Key); + writer.WriteStringValue(item.Value); + } + writer.WriteEndObject(); + } + } + + RunStepDeltaFileSearchToolCall 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(RunStepDeltaFileSearchToolCall)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeRunStepDeltaFileSearchToolCall(document.RootElement, options); + } + + internal static RunStepDeltaFileSearchToolCall DeserializeRunStepDeltaFileSearchToolCall(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + IReadOnlyDictionary fileSearch = default; + int index = default; + string id = default; + string type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("file_search"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()); + } + fileSearch = dictionary; + continue; + } + if (property.NameEquals("index"u8)) + { + index = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("id"u8)) + { + id = property.Value.GetString(); + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new RunStepDeltaFileSearchToolCall(index, id, type, serializedAdditionalRawData, fileSearch ?? new ChangeTrackingDictionary()); + } + + 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(RunStepDeltaFileSearchToolCall)} does not support writing '{options.Format}' format."); + } + } + + RunStepDeltaFileSearchToolCall 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeRunStepDeltaFileSearchToolCall(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(RunStepDeltaFileSearchToolCall)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new RunStepDeltaFileSearchToolCall FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeRunStepDeltaFileSearchToolCall(document.RootElement); + } + + /// Convert into a . + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaFileSearchToolCall.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaFileSearchToolCall.cs new file mode 100644 index 000000000000..7be515d9cc76 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaFileSearchToolCall.cs @@ -0,0 +1,47 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Represents a file search tool call within a streaming run step's tool call details. + public partial class RunStepDeltaFileSearchToolCall : RunStepDeltaToolCall + { + /// Initializes a new instance of . + /// The index of the tool call detail in the run step's tool_calls array. + /// The ID of the tool call, used when submitting outputs to the run. + /// is null. + internal RunStepDeltaFileSearchToolCall(int index, string id) : base(index, id) + { + Argument.AssertNotNull(id, nameof(id)); + + Type = "file_search"; + FileSearch = new ChangeTrackingDictionary(); + } + + /// Initializes a new instance of . + /// The index of the tool call detail in the run step's tool_calls array. + /// The ID of the tool call, used when submitting outputs to the run. + /// The type of the tool call detail item in a streaming run step's details. + /// Keeps track of any properties unknown to the library. + /// Reserved for future use. + internal RunStepDeltaFileSearchToolCall(int index, string id, string type, IDictionary serializedAdditionalRawData, IReadOnlyDictionary fileSearch) : base(index, id, type, serializedAdditionalRawData) + { + FileSearch = fileSearch; + } + + /// Initializes a new instance of for deserialization. + internal RunStepDeltaFileSearchToolCall() + { + } + + /// Reserved for future use. + public IReadOnlyDictionary FileSearch { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaFunction.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaFunction.Serialization.cs new file mode 100644 index 000000000000..dfd29726c505 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaFunction.Serialization.cs @@ -0,0 +1,179 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class RunStepDeltaFunction : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(RunStepDeltaFunction)} does not support writing '{format}' format."); + } + + if (Optional.IsDefined(Name)) + { + writer.WritePropertyName("name"u8); + writer.WriteStringValue(Name); + } + if (Optional.IsDefined(Arguments)) + { + writer.WritePropertyName("arguments"u8); + writer.WriteStringValue(Arguments); + } + if (Optional.IsDefined(Output)) + { + if (Output != null) + { + writer.WritePropertyName("output"u8); + writer.WriteStringValue(Output); + } + else + { + writer.WriteNull("output"); + } + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + RunStepDeltaFunction 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(RunStepDeltaFunction)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeRunStepDeltaFunction(document.RootElement, options); + } + + internal static RunStepDeltaFunction DeserializeRunStepDeltaFunction(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string name = default; + string arguments = default; + string output = 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("arguments"u8)) + { + arguments = property.Value.GetString(); + continue; + } + if (property.NameEquals("output"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + output = null; + continue; + } + output = property.Value.GetString(); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new RunStepDeltaFunction(name, arguments, output, 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(RunStepDeltaFunction)} does not support writing '{options.Format}' format."); + } + } + + RunStepDeltaFunction 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeRunStepDeltaFunction(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(RunStepDeltaFunction)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static RunStepDeltaFunction FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeRunStepDeltaFunction(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaFunction.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaFunction.cs new file mode 100644 index 000000000000..df34c88e6f43 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaFunction.cs @@ -0,0 +1,73 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Represents the function data in a streaming run step delta's function tool call. + public partial class RunStepDeltaFunction + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + internal RunStepDeltaFunction() + { + } + + /// Initializes a new instance of . + /// The name of the function. + /// The arguments passed to the function as input. + /// The output of the function, null if outputs have not yet been submitted. + /// Keeps track of any properties unknown to the library. + internal RunStepDeltaFunction(string name, string arguments, string output, IDictionary serializedAdditionalRawData) + { + Name = name; + Arguments = arguments; + Output = output; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// The name of the function. + public string Name { get; } + /// The arguments passed to the function as input. + public string Arguments { get; } + /// The output of the function, null if outputs have not yet been submitted. + public string Output { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaFunctionToolCall.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaFunctionToolCall.Serialization.cs new file mode 100644 index 000000000000..372692e32a75 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaFunctionToolCall.Serialization.cs @@ -0,0 +1,153 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class RunStepDeltaFunctionToolCall : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(RunStepDeltaFunctionToolCall)} does not support writing '{format}' format."); + } + + base.JsonModelWriteCore(writer, options); + if (Optional.IsDefined(Function)) + { + writer.WritePropertyName("function"u8); + writer.WriteObjectValue(Function, options); + } + } + + RunStepDeltaFunctionToolCall 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(RunStepDeltaFunctionToolCall)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeRunStepDeltaFunctionToolCall(document.RootElement, options); + } + + internal static RunStepDeltaFunctionToolCall DeserializeRunStepDeltaFunctionToolCall(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + RunStepDeltaFunction function = default; + int index = default; + string id = default; + string type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("function"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + function = RunStepDeltaFunction.DeserializeRunStepDeltaFunction(property.Value, options); + continue; + } + if (property.NameEquals("index"u8)) + { + index = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("id"u8)) + { + id = property.Value.GetString(); + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new RunStepDeltaFunctionToolCall(index, id, type, serializedAdditionalRawData, function); + } + + 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(RunStepDeltaFunctionToolCall)} does not support writing '{options.Format}' format."); + } + } + + RunStepDeltaFunctionToolCall 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeRunStepDeltaFunctionToolCall(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(RunStepDeltaFunctionToolCall)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new RunStepDeltaFunctionToolCall FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeRunStepDeltaFunctionToolCall(document.RootElement); + } + + /// Convert into a . + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaFunctionToolCall.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaFunctionToolCall.cs new file mode 100644 index 000000000000..ce9d9486ef82 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaFunctionToolCall.cs @@ -0,0 +1,46 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Represents a function tool call within a streaming run step's tool call details. + public partial class RunStepDeltaFunctionToolCall : RunStepDeltaToolCall + { + /// Initializes a new instance of . + /// The index of the tool call detail in the run step's tool_calls array. + /// The ID of the tool call, used when submitting outputs to the run. + /// is null. + internal RunStepDeltaFunctionToolCall(int index, string id) : base(index, id) + { + Argument.AssertNotNull(id, nameof(id)); + + Type = "function"; + } + + /// Initializes a new instance of . + /// The index of the tool call detail in the run step's tool_calls array. + /// The ID of the tool call, used when submitting outputs to the run. + /// The type of the tool call detail item in a streaming run step's details. + /// Keeps track of any properties unknown to the library. + /// The function data for the tool call. + internal RunStepDeltaFunctionToolCall(int index, string id, string type, IDictionary serializedAdditionalRawData, RunStepDeltaFunction function) : base(index, id, type, serializedAdditionalRawData) + { + Function = function; + } + + /// Initializes a new instance of for deserialization. + internal RunStepDeltaFunctionToolCall() + { + } + + /// The function data for the tool call. + public RunStepDeltaFunction Function { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaMessageCreation.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaMessageCreation.Serialization.cs new file mode 100644 index 000000000000..aa98784dc30f --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaMessageCreation.Serialization.cs @@ -0,0 +1,141 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class RunStepDeltaMessageCreation : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(RunStepDeltaMessageCreation)} does not support writing '{format}' format."); + } + + base.JsonModelWriteCore(writer, options); + if (Optional.IsDefined(MessageCreation)) + { + writer.WritePropertyName("message_creation"u8); + writer.WriteObjectValue(MessageCreation, options); + } + } + + RunStepDeltaMessageCreation 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(RunStepDeltaMessageCreation)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeRunStepDeltaMessageCreation(document.RootElement, options); + } + + internal static RunStepDeltaMessageCreation DeserializeRunStepDeltaMessageCreation(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + RunStepDeltaMessageCreationObject messageCreation = default; + string type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("message_creation"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + messageCreation = RunStepDeltaMessageCreationObject.DeserializeRunStepDeltaMessageCreationObject(property.Value, options); + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new RunStepDeltaMessageCreation(type, serializedAdditionalRawData, messageCreation); + } + + 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(RunStepDeltaMessageCreation)} does not support writing '{options.Format}' format."); + } + } + + RunStepDeltaMessageCreation 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeRunStepDeltaMessageCreation(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(RunStepDeltaMessageCreation)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new RunStepDeltaMessageCreation FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeRunStepDeltaMessageCreation(document.RootElement); + } + + /// Convert into a . + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaMessageCreation.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaMessageCreation.cs new file mode 100644 index 000000000000..38f8a808eeac --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaMessageCreation.cs @@ -0,0 +1,34 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Represents a message creation within a streaming run step delta. + public partial class RunStepDeltaMessageCreation : RunStepDeltaDetail + { + /// Initializes a new instance of . + internal RunStepDeltaMessageCreation() + { + Type = "message_creation"; + } + + /// Initializes a new instance of . + /// The object type for the run step detail object. + /// Keeps track of any properties unknown to the library. + /// The message creation data. + internal RunStepDeltaMessageCreation(string type, IDictionary serializedAdditionalRawData, RunStepDeltaMessageCreationObject messageCreation) : base(type, serializedAdditionalRawData) + { + MessageCreation = messageCreation; + } + + /// The message creation data. + public RunStepDeltaMessageCreationObject MessageCreation { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaMessageCreationObject.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaMessageCreationObject.Serialization.cs new file mode 100644 index 000000000000..f25ce59a3ae4 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaMessageCreationObject.Serialization.cs @@ -0,0 +1,145 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class RunStepDeltaMessageCreationObject : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(RunStepDeltaMessageCreationObject)} does not support writing '{format}' format."); + } + + if (Optional.IsDefined(MessageId)) + { + writer.WritePropertyName("message_id"u8); + writer.WriteStringValue(MessageId); + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + RunStepDeltaMessageCreationObject 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(RunStepDeltaMessageCreationObject)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeRunStepDeltaMessageCreationObject(document.RootElement, options); + } + + internal static RunStepDeltaMessageCreationObject DeserializeRunStepDeltaMessageCreationObject(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string messageId = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("message_id"u8)) + { + messageId = property.Value.GetString(); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new RunStepDeltaMessageCreationObject(messageId, 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(RunStepDeltaMessageCreationObject)} does not support writing '{options.Format}' format."); + } + } + + RunStepDeltaMessageCreationObject 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeRunStepDeltaMessageCreationObject(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(RunStepDeltaMessageCreationObject)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static RunStepDeltaMessageCreationObject FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeRunStepDeltaMessageCreationObject(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaMessageCreationObject.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaMessageCreationObject.cs new file mode 100644 index 000000000000..15aaccdbc60c --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaMessageCreationObject.cs @@ -0,0 +1,65 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Represents the data within a streaming run step message creation response object. + public partial class RunStepDeltaMessageCreationObject + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + internal RunStepDeltaMessageCreationObject() + { + } + + /// Initializes a new instance of . + /// The ID of the newly-created message. + /// Keeps track of any properties unknown to the library. + internal RunStepDeltaMessageCreationObject(string messageId, IDictionary serializedAdditionalRawData) + { + MessageId = messageId; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// The ID of the newly-created message. + public string MessageId { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaToolCall.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaToolCall.Serialization.cs new file mode 100644 index 000000000000..308ee81ccf2f --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaToolCall.Serialization.cs @@ -0,0 +1,139 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + [PersistableModelProxy(typeof(UnknownRunStepDeltaToolCall))] + public partial class RunStepDeltaToolCall : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(RunStepDeltaToolCall)} does not support writing '{format}' format."); + } + + writer.WritePropertyName("index"u8); + writer.WriteNumberValue(Index); + writer.WritePropertyName("id"u8); + writer.WriteStringValue(Id); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + RunStepDeltaToolCall 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(RunStepDeltaToolCall)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeRunStepDeltaToolCall(document.RootElement, options); + } + + internal static RunStepDeltaToolCall DeserializeRunStepDeltaToolCall(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 "code_interpreter": return RunStepDeltaCodeInterpreterToolCall.DeserializeRunStepDeltaCodeInterpreterToolCall(element, options); + case "file_search": return RunStepDeltaFileSearchToolCall.DeserializeRunStepDeltaFileSearchToolCall(element, options); + case "function": return RunStepDeltaFunctionToolCall.DeserializeRunStepDeltaFunctionToolCall(element, options); + } + } + return UnknownRunStepDeltaToolCall.DeserializeUnknownRunStepDeltaToolCall(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(RunStepDeltaToolCall)} does not support writing '{options.Format}' format."); + } + } + + RunStepDeltaToolCall 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeRunStepDeltaToolCall(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(RunStepDeltaToolCall)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static RunStepDeltaToolCall FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeRunStepDeltaToolCall(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaToolCall.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaToolCall.cs new file mode 100644 index 000000000000..c056ec5693c5 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaToolCall.cs @@ -0,0 +1,89 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// + /// The abstract base representation of a single tool call within a streaming run step's delta tool call details. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include , and . + /// + public abstract partial class RunStepDeltaToolCall + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private protected IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + /// The index of the tool call detail in the run step's tool_calls array. + /// The ID of the tool call, used when submitting outputs to the run. + /// is null. + protected RunStepDeltaToolCall(int index, string id) + { + Argument.AssertNotNull(id, nameof(id)); + + Index = index; + Id = id; + } + + /// Initializes a new instance of . + /// The index of the tool call detail in the run step's tool_calls array. + /// The ID of the tool call, used when submitting outputs to the run. + /// The type of the tool call detail item in a streaming run step's details. + /// Keeps track of any properties unknown to the library. + internal RunStepDeltaToolCall(int index, string id, string type, IDictionary serializedAdditionalRawData) + { + Index = index; + Id = id; + Type = type; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal RunStepDeltaToolCall() + { + } + + /// The index of the tool call detail in the run step's tool_calls array. + public int Index { get; } + /// The ID of the tool call, used when submitting outputs to the run. + public string Id { get; } + /// The type of the tool call detail item in a streaming run step's details. + internal string Type { get; set; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaToolCallObject.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaToolCallObject.Serialization.cs new file mode 100644 index 000000000000..8803d2e2754e --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaToolCallObject.Serialization.cs @@ -0,0 +1,151 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class RunStepDeltaToolCallObject : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(RunStepDeltaToolCallObject)} does not support writing '{format}' format."); + } + + base.JsonModelWriteCore(writer, options); + if (Optional.IsCollectionDefined(ToolCalls)) + { + writer.WritePropertyName("tool_calls"u8); + writer.WriteStartArray(); + foreach (var item in ToolCalls) + { + writer.WriteObjectValue(item, options); + } + writer.WriteEndArray(); + } + } + + RunStepDeltaToolCallObject 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(RunStepDeltaToolCallObject)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeRunStepDeltaToolCallObject(document.RootElement, options); + } + + internal static RunStepDeltaToolCallObject DeserializeRunStepDeltaToolCallObject(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + IReadOnlyList toolCalls = default; + string type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("tool_calls"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(RunStepDeltaToolCall.DeserializeRunStepDeltaToolCall(item, options)); + } + toolCalls = array; + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new RunStepDeltaToolCallObject(type, serializedAdditionalRawData, toolCalls ?? new ChangeTrackingList()); + } + + 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(RunStepDeltaToolCallObject)} does not support writing '{options.Format}' format."); + } + } + + RunStepDeltaToolCallObject 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeRunStepDeltaToolCallObject(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(RunStepDeltaToolCallObject)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new RunStepDeltaToolCallObject FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeRunStepDeltaToolCallObject(document.RootElement); + } + + /// Convert into a . + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaToolCallObject.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaToolCallObject.cs new file mode 100644 index 000000000000..77d87fe333e1 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepDeltaToolCallObject.cs @@ -0,0 +1,43 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Represents an invocation of tool calls as part of a streaming run step. + public partial class RunStepDeltaToolCallObject : RunStepDeltaDetail + { + /// Initializes a new instance of . + internal RunStepDeltaToolCallObject() + { + Type = "tool_calls"; + ToolCalls = new ChangeTrackingList(); + } + + /// Initializes a new instance of . + /// The object type for the run step detail object. + /// Keeps track of any properties unknown to the library. + /// + /// The collection of tool calls for the tool call detail item. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include , and . + /// + internal RunStepDeltaToolCallObject(string type, IDictionary serializedAdditionalRawData, IReadOnlyList toolCalls) : base(type, serializedAdditionalRawData) + { + ToolCalls = toolCalls; + } + + /// + /// The collection of tool calls for the tool call detail item. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include , and . + /// + public IReadOnlyList ToolCalls { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepFileSearchToolCall.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepFileSearchToolCall.Serialization.cs new file mode 100644 index 000000000000..083a4df3e845 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepFileSearchToolCall.Serialization.cs @@ -0,0 +1,150 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class RunStepFileSearchToolCall : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(RunStepFileSearchToolCall)} does not support writing '{format}' format."); + } + + base.JsonModelWriteCore(writer, options); + writer.WritePropertyName("file_search"u8); + writer.WriteStartArray(); + foreach (var item in FileSearch) + { + writer.WriteObjectValue(item, options); + } + writer.WriteEndArray(); + } + + RunStepFileSearchToolCall 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(RunStepFileSearchToolCall)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeRunStepFileSearchToolCall(document.RootElement, options); + } + + internal static RunStepFileSearchToolCall DeserializeRunStepFileSearchToolCall(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + IReadOnlyList fileSearch = default; + string type = default; + string id = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("file_search"u8)) + { + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(FileSearchToolCallResult.DeserializeFileSearchToolCallResult(item, options)); + } + fileSearch = array; + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + if (property.NameEquals("id"u8)) + { + id = property.Value.GetString(); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new RunStepFileSearchToolCall(type, id, serializedAdditionalRawData, fileSearch); + } + + 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(RunStepFileSearchToolCall)} does not support writing '{options.Format}' format."); + } + } + + RunStepFileSearchToolCall 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeRunStepFileSearchToolCall(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(RunStepFileSearchToolCall)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new RunStepFileSearchToolCall FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeRunStepFileSearchToolCall(document.RootElement); + } + + /// Convert into a . + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepFileSearchToolCall.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepFileSearchToolCall.cs new file mode 100644 index 000000000000..23e713b3d2b0 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepFileSearchToolCall.cs @@ -0,0 +1,51 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Azure.AI.OpenAI.Assistants +{ + /// + /// A record of a call to a file search tool, issued by the model in evaluation of a defined tool, that represents + /// executed file search. + /// + public partial class RunStepFileSearchToolCall : RunStepToolCall + { + /// Initializes a new instance of . + /// The ID of the tool call. This ID must be referenced when you submit tool outputs. + /// The results of the file search. + /// or is null. + internal RunStepFileSearchToolCall(string id, IEnumerable fileSearch) : base(id) + { + Argument.AssertNotNull(id, nameof(id)); + Argument.AssertNotNull(fileSearch, nameof(fileSearch)); + + Type = "file_search"; + FileSearch = fileSearch.ToList(); + } + + /// Initializes a new instance of . + /// The object type. + /// The ID of the tool call. This ID must be referenced when you submit tool outputs. + /// Keeps track of any properties unknown to the library. + /// The results of the file search. + internal RunStepFileSearchToolCall(string type, string id, IDictionary serializedAdditionalRawData, IReadOnlyList fileSearch) : base(type, id, serializedAdditionalRawData) + { + FileSearch = fileSearch; + } + + /// Initializes a new instance of for deserialization. + internal RunStepFileSearchToolCall() + { + } + + /// The results of the file search. + public IReadOnlyList FileSearch { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepRetrievalToolCall.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepRetrievalToolCall.cs deleted file mode 100644 index 5f119347d5f3..000000000000 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepRetrievalToolCall.cs +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Collections.Generic; - -namespace Azure.AI.OpenAI.Assistants -{ - /// - /// A record of a call to a retrieval tool, issued by the model in evaluation of a defined tool, that represents - /// executed retrieval actions. - /// - public partial class RunStepRetrievalToolCall : RunStepToolCall - { - /// Initializes a new instance of . - /// The ID of the tool call. This ID must be referenced when you submit tool outputs. - /// The key/value pairs produced by the retrieval tool. - /// or is null. - internal RunStepRetrievalToolCall(string id, IReadOnlyDictionary retrieval) : base(id) - { - Argument.AssertNotNull(id, nameof(id)); - Argument.AssertNotNull(retrieval, nameof(retrieval)); - - Type = "retrieval"; - Retrieval = retrieval; - } - - /// Initializes a new instance of . - /// The object type. - /// The ID of the tool call. This ID must be referenced when you submit tool outputs. - /// Keeps track of any properties unknown to the library. - /// The key/value pairs produced by the retrieval tool. - internal RunStepRetrievalToolCall(string type, string id, IDictionary serializedAdditionalRawData, IReadOnlyDictionary retrieval) : base(type, id, serializedAdditionalRawData) - { - Retrieval = retrieval; - } - - /// Initializes a new instance of for deserialization. - internal RunStepRetrievalToolCall() - { - } - - /// The key/value pairs produced by the retrieval tool. - public IReadOnlyDictionary Retrieval { get; } - } -} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepStreamEvent.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepStreamEvent.cs new file mode 100644 index 000000000000..3949704709ad --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepStreamEvent.cs @@ -0,0 +1,66 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Run step operation related streaming events. + public readonly partial struct RunStepStreamEvent : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public RunStepStreamEvent(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string ThreadRunStepCreatedValue = "thread.run.step.created"; + private const string ThreadRunStepInProgressValue = "thread.run.step.in_progress"; + private const string ThreadRunStepDeltaValue = "thread.run.step.delta"; + private const string ThreadRunStepCompletedValue = "thread.run.step.completed"; + private const string ThreadRunStepFailedValue = "thread.run.step.failed"; + private const string ThreadRunStepCancelledValue = "thread.run.step.cancelled"; + private const string ThreadRunStepExpiredValue = "thread.run.step.expired"; + + /// Event sent when a new thread run step is created. The data of this event is of type RunStep. + public static RunStepStreamEvent ThreadRunStepCreated { get; } = new RunStepStreamEvent(ThreadRunStepCreatedValue); + /// Event sent when a run step moves to `in_progress` status. The data of this event is of type RunStep. + public static RunStepStreamEvent ThreadRunStepInProgress { get; } = new RunStepStreamEvent(ThreadRunStepInProgressValue); + /// Event sent when a run stepis being streamed. The data of this event is of type RunStepDeltaChunk. + public static RunStepStreamEvent ThreadRunStepDelta { get; } = new RunStepStreamEvent(ThreadRunStepDeltaValue); + /// Event sent when a run step is completed. The data of this event is of type RunStep. + public static RunStepStreamEvent ThreadRunStepCompleted { get; } = new RunStepStreamEvent(ThreadRunStepCompletedValue); + /// Event sent when a run step fails. The data of this event is of type RunStep. + public static RunStepStreamEvent ThreadRunStepFailed { get; } = new RunStepStreamEvent(ThreadRunStepFailedValue); + /// Event sent when a run step is cancelled. The data of this event is of type RunStep. + public static RunStepStreamEvent ThreadRunStepCancelled { get; } = new RunStepStreamEvent(ThreadRunStepCancelledValue); + /// Event sent when a run step is expired. The data of this event is of type RunStep. + public static RunStepStreamEvent ThreadRunStepExpired { get; } = new RunStepStreamEvent(ThreadRunStepExpiredValue); + /// Determines if two values are the same. + public static bool operator ==(RunStepStreamEvent left, RunStepStreamEvent right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(RunStepStreamEvent left, RunStepStreamEvent right) => !left.Equals(right); + /// Converts a to a . + public static implicit operator RunStepStreamEvent(string value) => new RunStepStreamEvent(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is RunStepStreamEvent other && Equals(other); + /// + public bool Equals(RunStepStreamEvent 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/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepToolCall.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepToolCall.Serialization.cs index 3f2722881b5f..59eb0aae5583 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepToolCall.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepToolCall.Serialization.cs @@ -80,8 +80,8 @@ internal static RunStepToolCall DeserializeRunStepToolCall(JsonElement element, switch (discriminator.GetString()) { case "code_interpreter": return RunStepCodeInterpreterToolCall.DeserializeRunStepCodeInterpreterToolCall(element, options); + case "file_search": return RunStepFileSearchToolCall.DeserializeRunStepFileSearchToolCall(element, options); case "function": return RunStepFunctionToolCall.DeserializeRunStepFunctionToolCall(element, options); - case "retrieval": return RunStepRetrievalToolCall.DeserializeRunStepRetrievalToolCall(element, options); } } return UnknownRunStepToolCall.DeserializeUnknownRunStepToolCall(element, options); diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepToolCall.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepToolCall.cs index a1f39c74d40e..b458fd4827e9 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepToolCall.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepToolCall.cs @@ -13,7 +13,7 @@ namespace Azure.AI.OpenAI.Assistants /// /// An abstract representation of a detailed tool call as recorded within a run step for an existing run. /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. - /// The available derived classes include , and . + /// The available derived classes include , and . /// public abstract partial class RunStepToolCall { diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepToolCallDetails.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepToolCallDetails.cs index dedd295f4d8a..1d55d40ac096 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepToolCallDetails.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStepToolCallDetails.cs @@ -18,7 +18,7 @@ public partial class RunStepToolCallDetails : RunStepDetails /// /// A list of tool call details for this run step. /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. - /// The available derived classes include , and . + /// The available derived classes include , and . /// /// is null. internal RunStepToolCallDetails(IEnumerable toolCalls) @@ -35,7 +35,7 @@ internal RunStepToolCallDetails(IEnumerable toolCalls) /// /// A list of tool call details for this run step. /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. - /// The available derived classes include , and . + /// The available derived classes include , and . /// internal RunStepToolCallDetails(RunStepType type, IDictionary serializedAdditionalRawData, IReadOnlyList toolCalls) : base(type, serializedAdditionalRawData) { @@ -50,7 +50,7 @@ internal RunStepToolCallDetails() /// /// A list of tool call details for this run step. /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. - /// The available derived classes include , and . + /// The available derived classes include , and . /// public IReadOnlyList ToolCalls { get; } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStreamEvent.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStreamEvent.cs new file mode 100644 index 000000000000..d9ce800c9594 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RunStreamEvent.cs @@ -0,0 +1,72 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Run operation related streaming events. + public readonly partial struct RunStreamEvent : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public RunStreamEvent(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string ThreadRunCreatedValue = "thread.run.created"; + private const string ThreadRunQueuedValue = "thread.run.queued"; + private const string ThreadRunInProgressValue = "thread.run.in_progress"; + private const string ThreadRunRequiresActionValue = "thread.run.requires_action"; + private const string ThreadRunCompletedValue = "thread.run.completed"; + private const string ThreadRunFailedValue = "thread.run.failed"; + private const string ThreadRunCancellingValue = "thread.run.cancelling"; + private const string ThreadRunCancelledValue = "thread.run.cancelled"; + private const string ThreadRunExpiredValue = "thread.run.expired"; + + /// Event sent when a new run is created. The data of this event is of type ThreadRun. + public static RunStreamEvent ThreadRunCreated { get; } = new RunStreamEvent(ThreadRunCreatedValue); + /// Event sent when a run moves to `queued` status. The data of this event is of type ThreadRun. + public static RunStreamEvent ThreadRunQueued { get; } = new RunStreamEvent(ThreadRunQueuedValue); + /// Event sent when a run moves to `in_progress` status. The data of this event is of type ThreadRun. + public static RunStreamEvent ThreadRunInProgress { get; } = new RunStreamEvent(ThreadRunInProgressValue); + /// Event sent when a run moves to `requires_action` status. The data of this event is of type ThreadRun. + public static RunStreamEvent ThreadRunRequiresAction { get; } = new RunStreamEvent(ThreadRunRequiresActionValue); + /// Event sent when a run is completed. The data of this event is of type ThreadRun. + public static RunStreamEvent ThreadRunCompleted { get; } = new RunStreamEvent(ThreadRunCompletedValue); + /// Event sent when a run fails. The data of this event is of type ThreadRun. + public static RunStreamEvent ThreadRunFailed { get; } = new RunStreamEvent(ThreadRunFailedValue); + /// Event sent when a run moves to `cancelling` status. The data of this event is of type ThreadRun. + public static RunStreamEvent ThreadRunCancelling { get; } = new RunStreamEvent(ThreadRunCancellingValue); + /// Event sent when a run is cancelled. The data of this event is of type ThreadRun. + public static RunStreamEvent ThreadRunCancelled { get; } = new RunStreamEvent(ThreadRunCancelledValue); + /// Event sent when a run is expired. The data of this event is of type ThreadRun. + public static RunStreamEvent ThreadRunExpired { get; } = new RunStreamEvent(ThreadRunExpiredValue); + /// Determines if two values are the same. + public static bool operator ==(RunStreamEvent left, RunStreamEvent right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(RunStreamEvent left, RunStreamEvent right) => !left.Equals(right); + /// Converts a to a . + public static implicit operator RunStreamEvent(string value) => new RunStreamEvent(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is RunStreamEvent other && Equals(other); + /// + public bool Equals(RunStreamEvent 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/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/SubmitToolOutputsToRunRequest.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/SubmitToolOutputsToRunRequest.Serialization.cs index 578385488318..3c283ee481a9 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/SubmitToolOutputsToRunRequest.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/SubmitToolOutputsToRunRequest.Serialization.cs @@ -41,6 +41,18 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit writer.WriteObjectValue(item, options); } writer.WriteEndArray(); + if (Optional.IsDefined(Stream)) + { + if (Stream != null) + { + writer.WritePropertyName("stream"u8); + writer.WriteBooleanValue(Stream.Value); + } + else + { + writer.WriteNull("stream"); + } + } if (options.Format != "W" && _serializedAdditionalRawData != null) { foreach (var item in _serializedAdditionalRawData) @@ -79,6 +91,7 @@ internal static SubmitToolOutputsToRunRequest DeserializeSubmitToolOutputsToRunR return null; } IReadOnlyList toolOutputs = default; + bool? stream = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) @@ -93,13 +106,23 @@ internal static SubmitToolOutputsToRunRequest DeserializeSubmitToolOutputsToRunR toolOutputs = array; continue; } + if (property.NameEquals("stream"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + stream = null; + continue; + } + stream = property.Value.GetBoolean(); + continue; + } if (options.Format != "W") { rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); } } serializedAdditionalRawData = rawDataDictionary; - return new SubmitToolOutputsToRunRequest(toolOutputs, serializedAdditionalRawData); + return new SubmitToolOutputsToRunRequest(toolOutputs, stream, serializedAdditionalRawData); } BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/SubmitToolOutputsToRunRequest.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/SubmitToolOutputsToRunRequest.cs index 7fc21ab959a6..2971598450d1 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/SubmitToolOutputsToRunRequest.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/SubmitToolOutputsToRunRequest.cs @@ -47,7 +47,7 @@ internal partial class SubmitToolOutputsToRunRequest private IDictionary _serializedAdditionalRawData; /// Initializes a new instance of . - /// The list of tool outputs requested by tool calls from the specified run. + /// A list of tools for which the outputs are being submitted. /// is null. internal SubmitToolOutputsToRunRequest(IEnumerable toolOutputs) { @@ -57,11 +57,13 @@ internal SubmitToolOutputsToRunRequest(IEnumerable toolOutputs) } /// Initializes a new instance of . - /// The list of tool outputs requested by tool calls from the specified run. + /// A list of tools for which the outputs are being submitted. + /// If `true`, returns a stream of events that happen during the Run as server-sent events, terminating when the Run enters a terminal state with a `data: [DONE]` message. /// Keeps track of any properties unknown to the library. - internal SubmitToolOutputsToRunRequest(IReadOnlyList toolOutputs, IDictionary serializedAdditionalRawData) + internal SubmitToolOutputsToRunRequest(IReadOnlyList toolOutputs, bool? stream, IDictionary serializedAdditionalRawData) { ToolOutputs = toolOutputs; + Stream = stream; _serializedAdditionalRawData = serializedAdditionalRawData; } @@ -70,7 +72,9 @@ internal SubmitToolOutputsToRunRequest() { } - /// The list of tool outputs requested by tool calls from the specified run. + /// A list of tools for which the outputs are being submitted. public IReadOnlyList ToolOutputs { get; } + /// If `true`, returns a stream of events that happen during the Run as server-sent events, terminating when the Run enters a terminal state with a `data: [DONE]` message. + public bool? Stream { get; } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadMessage.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadMessage.Serialization.cs index c76a75916857..f83443bb45a0 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadMessage.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadMessage.Serialization.cs @@ -42,6 +42,35 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit writer.WriteNumberValue(CreatedAt, "U"); writer.WritePropertyName("thread_id"u8); writer.WriteStringValue(ThreadId); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(Status.ToString()); + if (IncompleteDetails != null) + { + writer.WritePropertyName("incomplete_details"u8); + writer.WriteObjectValue(IncompleteDetails, options); + } + else + { + writer.WriteNull("incomplete_details"); + } + if (CompletedAt != null) + { + writer.WritePropertyName("completed_at"u8); + writer.WriteNumberValue(CompletedAt.Value, "U"); + } + else + { + writer.WriteNull("completed_at"); + } + if (IncompleteAt != null) + { + writer.WritePropertyName("incomplete_at"u8); + writer.WriteNumberValue(IncompleteAt.Value, "U"); + } + else + { + writer.WriteNull("incomplete_at"); + } writer.WritePropertyName("role"u8); writer.WriteStringValue(Role.ToString()); writer.WritePropertyName("content"u8); @@ -51,23 +80,38 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit writer.WriteObjectValue(item, options); } writer.WriteEndArray(); - if (Optional.IsDefined(AssistantId)) + if (AssistantId != null) { writer.WritePropertyName("assistant_id"u8); writer.WriteStringValue(AssistantId); } - if (Optional.IsDefined(RunId)) + else + { + writer.WriteNull("assistant_id"); + } + if (RunId != null) { writer.WritePropertyName("run_id"u8); writer.WriteStringValue(RunId); } - writer.WritePropertyName("file_ids"u8); - writer.WriteStartArray(); - foreach (var item in FileIds) + else { - writer.WriteStringValue(item); + writer.WriteNull("run_id"); + } + if (Attachments != null && Optional.IsCollectionDefined(Attachments)) + { + writer.WritePropertyName("attachments"u8); + writer.WriteStartArray(); + foreach (var item in Attachments) + { + writer.WriteObjectValue(item, options); + } + writer.WriteEndArray(); + } + else + { + writer.WriteNull("attachments"); } - writer.WriteEndArray(); if (Metadata != null && Optional.IsCollectionDefined(Metadata)) { writer.WritePropertyName("metadata"u8); @@ -124,12 +168,16 @@ internal static ThreadMessage DeserializeThreadMessage(JsonElement element, Mode string @object = default; DateTimeOffset createdAt = default; string threadId = default; + MessageStatus status = default; + MessageIncompleteDetails incompleteDetails = default; + DateTimeOffset? completedAt = default; + DateTimeOffset? incompleteAt = default; MessageRole role = default; - IReadOnlyList content = default; + IList content = default; string assistantId = default; string runId = default; - IReadOnlyList fileIds = default; - IReadOnlyDictionary metadata = default; + IList attachments = default; + IDictionary metadata = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) @@ -154,6 +202,41 @@ internal static ThreadMessage DeserializeThreadMessage(JsonElement element, Mode threadId = property.Value.GetString(); continue; } + if (property.NameEquals("status"u8)) + { + status = new MessageStatus(property.Value.GetString()); + continue; + } + if (property.NameEquals("incomplete_details"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + incompleteDetails = null; + continue; + } + incompleteDetails = MessageIncompleteDetails.DeserializeMessageIncompleteDetails(property.Value, options); + continue; + } + if (property.NameEquals("completed_at"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + completedAt = null; + continue; + } + completedAt = DateTimeOffset.FromUnixTimeSeconds(property.Value.GetInt64()); + continue; + } + if (property.NameEquals("incomplete_at"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + incompleteAt = null; + continue; + } + incompleteAt = DateTimeOffset.FromUnixTimeSeconds(property.Value.GetInt64()); + continue; + } if (property.NameEquals("role"u8)) { role = new MessageRole(property.Value.GetString()); @@ -171,22 +254,37 @@ internal static ThreadMessage DeserializeThreadMessage(JsonElement element, Mode } if (property.NameEquals("assistant_id"u8)) { + if (property.Value.ValueKind == JsonValueKind.Null) + { + assistantId = null; + continue; + } assistantId = property.Value.GetString(); continue; } if (property.NameEquals("run_id"u8)) { + if (property.Value.ValueKind == JsonValueKind.Null) + { + runId = null; + continue; + } runId = property.Value.GetString(); continue; } - if (property.NameEquals("file_ids"u8)) + if (property.NameEquals("attachments"u8)) { - List array = new List(); + if (property.Value.ValueKind == JsonValueKind.Null) + { + attachments = new ChangeTrackingList(); + continue; + } + List array = new List(); foreach (var item in property.Value.EnumerateArray()) { - array.Add(item.GetString()); + array.Add(MessageAttachment.DeserializeMessageAttachment(item, options)); } - fileIds = array; + attachments = array; continue; } if (property.NameEquals("metadata"u8)) @@ -215,11 +313,15 @@ internal static ThreadMessage DeserializeThreadMessage(JsonElement element, Mode @object, createdAt, threadId, + status, + incompleteDetails, + completedAt, + incompleteAt, role, content, assistantId, runId, - fileIds, + attachments, metadata, serializedAdditionalRawData); } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadMessage.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadMessage.cs index 8bc5a7e7779b..c730b23b4dcf 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadMessage.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadMessage.cs @@ -50,31 +50,39 @@ public partial class ThreadMessage /// The identifier, which can be referenced in API endpoints. /// The Unix timestamp, in seconds, representing when this object was created. /// The ID of the thread that this message belongs to. + /// The status of the message. + /// On an incomplete message, details about why the message is incomplete. + /// The Unix timestamp (in seconds) for when the message was completed. + /// The Unix timestamp (in seconds) for when the message was marked as incomplete. /// The role associated with the assistant thread message. /// /// The list of content items associated with the assistant thread message. /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. /// The available derived classes include and . /// - /// - /// A list of file IDs that the assistant should use. Useful for tools like retrieval and code_interpreter that can - /// access files. - /// + /// If applicable, the ID of the assistant that authored this message. + /// If applicable, the ID of the run associated with the authoring of this message. + /// A list of files attached to the message, and the tools they were added to. /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. - /// , , or is null. - internal ThreadMessage(string id, DateTimeOffset createdAt, string threadId, MessageRole role, IEnumerable contentItems, IEnumerable fileIds, IReadOnlyDictionary metadata) + /// , or is null. + public ThreadMessage(string id, DateTimeOffset createdAt, string threadId, MessageStatus status, MessageIncompleteDetails incompleteDetails, DateTimeOffset? completedAt, DateTimeOffset? incompleteAt, MessageRole role, IEnumerable contentItems, string assistantId, string runId, IEnumerable attachments, IDictionary metadata) { Argument.AssertNotNull(id, nameof(id)); Argument.AssertNotNull(threadId, nameof(threadId)); Argument.AssertNotNull(contentItems, nameof(contentItems)); - Argument.AssertNotNull(fileIds, nameof(fileIds)); Id = id; CreatedAt = createdAt; ThreadId = threadId; + Status = status; + IncompleteDetails = incompleteDetails; + CompletedAt = completedAt; + IncompleteAt = incompleteAt; Role = role; ContentItems = contentItems.ToList(); - FileIds = fileIds.ToList(); + AssistantId = assistantId; + RunId = runId; + Attachments = attachments?.ToList(); Metadata = metadata; } @@ -83,6 +91,10 @@ internal ThreadMessage(string id, DateTimeOffset createdAt, string threadId, Mes /// The object type, which is always 'thread.message'. /// The Unix timestamp, in seconds, representing when this object was created. /// The ID of the thread that this message belongs to. + /// The status of the message. + /// On an incomplete message, details about why the message is incomplete. + /// The Unix timestamp (in seconds) for when the message was completed. + /// The Unix timestamp (in seconds) for when the message was marked as incomplete. /// The role associated with the assistant thread message. /// /// The list of content items associated with the assistant thread message. @@ -91,23 +103,24 @@ internal ThreadMessage(string id, DateTimeOffset createdAt, string threadId, Mes /// /// If applicable, the ID of the assistant that authored this message. /// If applicable, the ID of the run associated with the authoring of this message. - /// - /// A list of file IDs that the assistant should use. Useful for tools like retrieval and code_interpreter that can - /// access files. - /// + /// A list of files attached to the message, and the tools they were added to. /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. /// Keeps track of any properties unknown to the library. - internal ThreadMessage(string id, string @object, DateTimeOffset createdAt, string threadId, MessageRole role, IReadOnlyList contentItems, string assistantId, string runId, IReadOnlyList fileIds, IReadOnlyDictionary metadata, IDictionary serializedAdditionalRawData) + internal ThreadMessage(string id, string @object, DateTimeOffset createdAt, string threadId, MessageStatus status, MessageIncompleteDetails incompleteDetails, DateTimeOffset? completedAt, DateTimeOffset? incompleteAt, MessageRole role, IList contentItems, string assistantId, string runId, IList attachments, IDictionary metadata, IDictionary serializedAdditionalRawData) { Id = id; Object = @object; CreatedAt = createdAt; ThreadId = threadId; + Status = status; + IncompleteDetails = incompleteDetails; + CompletedAt = completedAt; + IncompleteAt = incompleteAt; Role = role; ContentItems = contentItems; AssistantId = assistantId; RunId = runId; - FileIds = fileIds; + Attachments = attachments; Metadata = metadata; _serializedAdditionalRawData = serializedAdditionalRawData; } @@ -118,30 +131,35 @@ internal ThreadMessage() } /// The identifier, which can be referenced in API endpoints. - public string Id { get; } + public string Id { get; set; } /// The Unix timestamp, in seconds, representing when this object was created. - public DateTimeOffset CreatedAt { get; } + public DateTimeOffset CreatedAt { get; set; } /// The ID of the thread that this message belongs to. - public string ThreadId { get; } + public string ThreadId { get; set; } + /// The status of the message. + public MessageStatus Status { get; set; } + /// On an incomplete message, details about why the message is incomplete. + public MessageIncompleteDetails IncompleteDetails { get; set; } + /// The Unix timestamp (in seconds) for when the message was completed. + public DateTimeOffset? CompletedAt { get; set; } + /// The Unix timestamp (in seconds) for when the message was marked as incomplete. + public DateTimeOffset? IncompleteAt { get; set; } /// The role associated with the assistant thread message. - public MessageRole Role { get; } + public MessageRole Role { get; set; } /// /// The list of content items associated with the assistant thread message. /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. /// The available derived classes include and . /// - public IReadOnlyList ContentItems { get; } + public IList ContentItems { get; } /// If applicable, the ID of the assistant that authored this message. - public string AssistantId { get; } + public string AssistantId { get; set; } /// If applicable, the ID of the run associated with the authoring of this message. - public string RunId { get; } - /// - /// A list of file IDs that the assistant should use. Useful for tools like retrieval and code_interpreter that can - /// access files. - /// - public IReadOnlyList FileIds { get; } + public string RunId { get; set; } + /// A list of files attached to the message, and the tools they were added to. + public IList Attachments { get; set; } /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. - public IReadOnlyDictionary Metadata { get; } + public IDictionary Metadata { get; set; } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateMessageRequest.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadMessageOptions.Serialization.cs similarity index 70% rename from sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateMessageRequest.Serialization.cs rename to sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadMessageOptions.Serialization.cs index b8cd2cbf423c..80dd17220a50 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateMessageRequest.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadMessageOptions.Serialization.cs @@ -13,11 +13,11 @@ namespace Azure.AI.OpenAI.Assistants { - internal partial class CreateMessageRequest : IUtf8JsonSerializable, IJsonModel + public partial class ThreadMessageOptions : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { writer.WriteStartObject(); JsonModelWriteCore(writer, options); @@ -28,25 +28,32 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWr /// The client options for reading and writing models. protected virtual void JsonModelWriteCore(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(CreateMessageRequest)} does not support writing '{format}' format."); + throw new FormatException($"The model {nameof(ThreadMessageOptions)} does not support writing '{format}' format."); } writer.WritePropertyName("role"u8); writer.WriteStringValue(Role.ToString()); writer.WritePropertyName("content"u8); writer.WriteStringValue(Content); - if (Optional.IsCollectionDefined(FileIds)) + if (Optional.IsCollectionDefined(Attachments)) { - writer.WritePropertyName("file_ids"u8); - writer.WriteStartArray(); - foreach (var item in FileIds) + if (Attachments != null) { - writer.WriteStringValue(item); + writer.WritePropertyName("attachments"u8); + writer.WriteStartArray(); + foreach (var item in Attachments) + { + writer.WriteObjectValue(item, options); + } + writer.WriteEndArray(); + } + else + { + writer.WriteNull("attachments"); } - writer.WriteEndArray(); } if (Optional.IsCollectionDefined(Metadata)) { @@ -83,19 +90,19 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit } } - CreateMessageRequest IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + ThreadMessageOptions 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(CreateMessageRequest)} does not support reading '{format}' format."); + throw new FormatException($"The model {nameof(ThreadMessageOptions)} does not support reading '{format}' format."); } using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeCreateMessageRequest(document.RootElement, options); + return DeserializeThreadMessageOptions(document.RootElement, options); } - internal static CreateMessageRequest DeserializeCreateMessageRequest(JsonElement element, ModelReaderWriterOptions options = null) + internal static ThreadMessageOptions DeserializeThreadMessageOptions(JsonElement element, ModelReaderWriterOptions options = null) { options ??= ModelSerializationExtensions.WireOptions; @@ -105,8 +112,8 @@ internal static CreateMessageRequest DeserializeCreateMessageRequest(JsonElement } MessageRole role = default; string content = default; - IReadOnlyList fileIds = default; - IReadOnlyDictionary metadata = default; + IList attachments = default; + IDictionary metadata = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) @@ -121,18 +128,18 @@ internal static CreateMessageRequest DeserializeCreateMessageRequest(JsonElement content = property.Value.GetString(); continue; } - if (property.NameEquals("file_ids"u8)) + if (property.NameEquals("attachments"u8)) { if (property.Value.ValueKind == JsonValueKind.Null) { continue; } - List array = new List(); + List array = new List(); foreach (var item in property.Value.EnumerateArray()) { - array.Add(item.GetString()); + array.Add(MessageAttachment.DeserializeMessageAttachment(item, options)); } - fileIds = array; + attachments = array; continue; } if (property.NameEquals("metadata"u8)) @@ -155,46 +162,46 @@ internal static CreateMessageRequest DeserializeCreateMessageRequest(JsonElement } } serializedAdditionalRawData = rawDataDictionary; - return new CreateMessageRequest(role, content, fileIds ?? new ChangeTrackingList(), metadata ?? new ChangeTrackingDictionary(), serializedAdditionalRawData); + return new ThreadMessageOptions(role, content, attachments ?? new ChangeTrackingList(), metadata ?? new ChangeTrackingDictionary(), 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(CreateMessageRequest)} does not support writing '{options.Format}' format."); + throw new FormatException($"The model {nameof(ThreadMessageOptions)} does not support writing '{options.Format}' format."); } } - CreateMessageRequest IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + ThreadMessageOptions 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, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeCreateMessageRequest(document.RootElement, options); + return DeserializeThreadMessageOptions(document.RootElement, options); } default: - throw new FormatException($"The model {nameof(CreateMessageRequest)} does not support reading '{options.Format}' format."); + throw new FormatException($"The model {nameof(ThreadMessageOptions)} does not support reading '{options.Format}' format."); } } - string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; /// Deserializes the model from a raw response. /// The response to deserialize the model from. - internal static CreateMessageRequest FromResponse(Response response) + internal static ThreadMessageOptions FromResponse(Response response) { using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeCreateMessageRequest(document.RootElement); + return DeserializeThreadMessageOptions(document.RootElement); } /// Convert into a . diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadInitializationMessage.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadMessageOptions.cs similarity index 53% rename from sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadInitializationMessage.cs rename to sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadMessageOptions.cs index 5ce61588505d..6487c1ad7bf4 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadInitializationMessage.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadMessageOptions.cs @@ -11,7 +11,7 @@ namespace Azure.AI.OpenAI.Assistants { /// A single message within an assistant thread, as provided during that thread's creation for its initial state. - public partial class ThreadInitializationMessage + public partial class ThreadMessageOptions { /// /// Keeps track of any properties unknown to the library. @@ -45,52 +45,70 @@ public partial class ThreadInitializationMessage /// private IDictionary _serializedAdditionalRawData; - /// Initializes a new instance of . - /// The role associated with the assistant thread message. Currently, only 'user' is supported when providing initial messages to a new thread. - /// The textual content of the initial message. Currently, robust input including images and annotated text may only be provided via a separate call to the create message API. + /// Initializes a new instance of . + /// + /// The role of the entity that is creating the message. Allowed values include: + /// - `user`: Indicates the message is sent by an actual user and should be used in most cases to represent user-generated messages. + /// - `assistant`: Indicates the message is generated by the assistant. Use this value to insert messages from the assistant into + /// the conversation. + /// + /// + /// The textual content of the initial message. Currently, robust input including images and annotated text may only be provided via + /// a separate call to the create message API. + /// /// is null. - public ThreadInitializationMessage(MessageRole role, string content) + public ThreadMessageOptions(MessageRole role, string content) { Argument.AssertNotNull(content, nameof(content)); Role = role; Content = content; - FileIds = new ChangeTrackingList(); + Attachments = new ChangeTrackingList(); Metadata = new ChangeTrackingDictionary(); } - /// Initializes a new instance of . - /// The role associated with the assistant thread message. Currently, only 'user' is supported when providing initial messages to a new thread. - /// The textual content of the initial message. Currently, robust input including images and annotated text may only be provided via a separate call to the create message API. - /// - /// A list of file IDs that the assistant should use. Useful for tools like retrieval and code_interpreter that can - /// access files. + /// Initializes a new instance of . + /// + /// The role of the entity that is creating the message. Allowed values include: + /// - `user`: Indicates the message is sent by an actual user and should be used in most cases to represent user-generated messages. + /// - `assistant`: Indicates the message is generated by the assistant. Use this value to insert messages from the assistant into + /// the conversation. /// + /// + /// The textual content of the initial message. Currently, robust input including images and annotated text may only be provided via + /// a separate call to the create message API. + /// + /// A list of files attached to the message, and the tools they should be added to. /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. /// Keeps track of any properties unknown to the library. - internal ThreadInitializationMessage(MessageRole role, string content, IList fileIds, IDictionary metadata, IDictionary serializedAdditionalRawData) + internal ThreadMessageOptions(MessageRole role, string content, IList attachments, IDictionary metadata, IDictionary serializedAdditionalRawData) { Role = role; Content = content; - FileIds = fileIds; + Attachments = attachments; Metadata = metadata; _serializedAdditionalRawData = serializedAdditionalRawData; } - /// Initializes a new instance of for deserialization. - internal ThreadInitializationMessage() + /// Initializes a new instance of for deserialization. + internal ThreadMessageOptions() { } - /// The role associated with the assistant thread message. Currently, only 'user' is supported when providing initial messages to a new thread. + /// + /// The role of the entity that is creating the message. Allowed values include: + /// - `user`: Indicates the message is sent by an actual user and should be used in most cases to represent user-generated messages. + /// - `assistant`: Indicates the message is generated by the assistant. Use this value to insert messages from the assistant into + /// the conversation. + /// public MessageRole Role { get; } - /// The textual content of the initial message. Currently, robust input including images and annotated text may only be provided via a separate call to the create message API. - public string Content { get; } /// - /// A list of file IDs that the assistant should use. Useful for tools like retrieval and code_interpreter that can - /// access files. + /// The textual content of the initial message. Currently, robust input including images and annotated text may only be provided via + /// a separate call to the create message API. /// - public IList FileIds { get; } + public string Content { get; } + /// A list of files attached to the message, and the tools they should be added to. + public IList Attachments { get; set; } /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. public IDictionary Metadata { get; set; } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadRun.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadRun.Serialization.cs index e9eeb6a58e88..fb70c33b0349 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadRun.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadRun.Serialization.cs @@ -76,13 +76,6 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit writer.WriteObjectValue(item, options); } writer.WriteEndArray(); - writer.WritePropertyName("file_ids"u8); - writer.WriteStartArray(); - foreach (var item in FileIds) - { - writer.WriteStringValue(item); - } - writer.WriteEndArray(); writer.WritePropertyName("created_at"u8); writer.WriteNumberValue(CreatedAt, "U"); if (ExpiresAt != null) @@ -130,6 +123,109 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit { writer.WriteNull("failed_at"); } + if (IncompleteDetails != null) + { + writer.WritePropertyName("incomplete_details"u8); + writer.WriteStringValue(IncompleteDetails.Value.ToString()); + } + else + { + writer.WriteNull("incomplete_details"); + } + if (Usage != null) + { + writer.WritePropertyName("usage"u8); + writer.WriteObjectValue(Usage, options); + } + else + { + writer.WriteNull("usage"); + } + if (Optional.IsDefined(Temperature)) + { + if (Temperature != null) + { + writer.WritePropertyName("temperature"u8); + writer.WriteNumberValue(Temperature.Value); + } + else + { + writer.WriteNull("temperature"); + } + } + if (Optional.IsDefined(TopP)) + { + if (TopP != null) + { + writer.WritePropertyName("top_p"u8); + writer.WriteNumberValue(TopP.Value); + } + else + { + writer.WriteNull("top_p"); + } + } + if (MaxPromptTokens != null) + { + writer.WritePropertyName("max_prompt_tokens"u8); + writer.WriteNumberValue(MaxPromptTokens.Value); + } + else + { + writer.WriteNull("max_prompt_tokens"); + } + if (MaxCompletionTokens != null) + { + writer.WritePropertyName("max_completion_tokens"u8); + writer.WriteNumberValue(MaxCompletionTokens.Value); + } + else + { + writer.WriteNull("max_completion_tokens"); + } + if (TruncationStrategy != null) + { + writer.WritePropertyName("truncation_strategy"u8); + writer.WriteObjectValue(TruncationStrategy, options); + } + else + { + writer.WriteNull("truncation_strategy"); + } + if (ToolChoice != null) + { + writer.WritePropertyName("tool_choice"u8); +#if NET6_0_OR_GREATER + writer.WriteRawValue(ToolChoice); +#else + using (JsonDocument document = JsonDocument.Parse(ToolChoice, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + else + { + writer.WriteNull("tool_choice"); + } + writer.WritePropertyName("parallel_tool_calls"u8); + writer.WriteBooleanValue(ParallelToolCalls); + if (ResponseFormat != null) + { + writer.WritePropertyName("response_format"u8); +#if NET6_0_OR_GREATER + writer.WriteRawValue(ResponseFormat); +#else + using (JsonDocument document = JsonDocument.Parse(ResponseFormat, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + else + { + writer.WriteNull("response_format"); + } if (Metadata != null && Optional.IsCollectionDefined(Metadata)) { writer.WritePropertyName("metadata"u8); @@ -192,13 +288,22 @@ internal static ThreadRun DeserializeThreadRun(JsonElement element, ModelReaderW string model = default; string instructions = default; IReadOnlyList tools = default; - IReadOnlyList fileIds = default; DateTimeOffset createdAt = default; DateTimeOffset? expiresAt = default; DateTimeOffset? startedAt = default; DateTimeOffset? completedAt = default; DateTimeOffset? cancelledAt = default; DateTimeOffset? failedAt = default; + IncompleteRunDetails? incompleteDetails = default; + RunCompletionUsage usage = default; + float? temperature = default; + float? topP = default; + int? maxPromptTokens = default; + int? maxCompletionTokens = default; + TruncationObject truncationStrategy = default; + BinaryData toolChoice = default; + bool parallelToolCalls = default; + BinaryData responseFormat = default; IReadOnlyDictionary metadata = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); @@ -269,16 +374,6 @@ internal static ThreadRun DeserializeThreadRun(JsonElement element, ModelReaderW tools = array; continue; } - if (property.NameEquals("file_ids"u8)) - { - List array = new List(); - foreach (var item in property.Value.EnumerateArray()) - { - array.Add(item.GetString()); - } - fileIds = array; - continue; - } if (property.NameEquals("created_at"u8)) { createdAt = DateTimeOffset.FromUnixTimeSeconds(property.Value.GetInt64()); @@ -309,6 +404,101 @@ internal static ThreadRun DeserializeThreadRun(JsonElement element, ModelReaderW DeserializeNullableDateTimeOffset(property, ref failedAt); continue; } + if (property.NameEquals("incomplete_details"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + incompleteDetails = null; + continue; + } + incompleteDetails = new IncompleteRunDetails(property.Value.GetString()); + continue; + } + if (property.NameEquals("usage"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + usage = null; + continue; + } + usage = RunCompletionUsage.DeserializeRunCompletionUsage(property.Value, options); + continue; + } + if (property.NameEquals("temperature"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + temperature = null; + continue; + } + temperature = property.Value.GetSingle(); + continue; + } + if (property.NameEquals("top_p"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + topP = null; + continue; + } + topP = property.Value.GetSingle(); + continue; + } + if (property.NameEquals("max_prompt_tokens"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + maxPromptTokens = null; + continue; + } + maxPromptTokens = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("max_completion_tokens"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + maxCompletionTokens = null; + continue; + } + maxCompletionTokens = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("truncation_strategy"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + truncationStrategy = null; + continue; + } + truncationStrategy = TruncationObject.DeserializeTruncationObject(property.Value, options); + continue; + } + if (property.NameEquals("tool_choice"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + toolChoice = null; + continue; + } + toolChoice = BinaryData.FromString(property.Value.GetRawText()); + continue; + } + if (property.NameEquals("parallel_tool_calls"u8)) + { + parallelToolCalls = property.Value.GetBoolean(); + continue; + } + if (property.NameEquals("response_format"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + responseFormat = null; + continue; + } + responseFormat = BinaryData.FromString(property.Value.GetRawText()); + continue; + } if (property.NameEquals("metadata"u8)) { if (property.Value.ValueKind == JsonValueKind.Null) @@ -341,13 +531,22 @@ internal static ThreadRun DeserializeThreadRun(JsonElement element, ModelReaderW model, instructions, tools, - fileIds, createdAt, expiresAt, startedAt, completedAt, cancelledAt, failedAt, + incompleteDetails, + usage, + temperature, + topP, + maxPromptTokens, + maxCompletionTokens, + truncationStrategy, + toolChoice, + parallelToolCalls, + responseFormat, metadata, serializedAdditionalRawData); } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadRun.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadRun.cs index 31c97e45b559..16b96c0084e0 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadRun.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadRun.cs @@ -57,18 +57,25 @@ public partial class ThreadRun /// /// The overridden enabled tools used for this assistant thread run. /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. - /// The available derived classes include , and . + /// The available derived classes include , and . /// - /// A list of attached file IDs, ordered by creation date in ascending order. /// The Unix timestamp, in seconds, representing when this object was created. /// The Unix timestamp, in seconds, representing when this item expires. /// The Unix timestamp, in seconds, representing when this item was started. /// The Unix timestamp, in seconds, representing when this completed. /// The Unix timestamp, in seconds, representing when this was cancelled. /// The Unix timestamp, in seconds, representing when this failed. + /// Details on why the run is incomplete. Will be `null` if the run is not incomplete. + /// Usage statistics related to the run. This value will be `null` if the run is not in a terminal state (i.e. `in_progress`, `queued`, etc.). + /// The maximum number of prompt tokens specified to have been used over the course of the run. + /// The maximum number of completion tokens specified to have been used over the course of the run. + /// The strategy to use for dropping messages as the context windows moves forward. + /// Controls whether or not and which tool is called by the model. + /// Whether to enable parallel function calling during tool use. + /// The response format of the tool calls used in this run. /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. - /// , , , , , or is null. - internal ThreadRun(string id, string threadId, string assistantId, RunStatus status, RunError lastError, string model, string instructions, IEnumerable tools, IEnumerable fileIds, DateTimeOffset createdAt, DateTimeOffset? expiresAt, DateTimeOffset? startedAt, DateTimeOffset? completedAt, DateTimeOffset? cancelledAt, DateTimeOffset? failedAt, IReadOnlyDictionary metadata) + /// , , , , or is null. + internal ThreadRun(string id, string threadId, string assistantId, RunStatus status, RunError lastError, string model, string instructions, IEnumerable tools, DateTimeOffset createdAt, DateTimeOffset? expiresAt, DateTimeOffset? startedAt, DateTimeOffset? completedAt, DateTimeOffset? cancelledAt, DateTimeOffset? failedAt, IncompleteRunDetails? incompleteDetails, RunCompletionUsage usage, int? maxPromptTokens, int? maxCompletionTokens, TruncationObject truncationStrategy, BinaryData toolChoice, bool parallelToolCalls, BinaryData responseFormat, IReadOnlyDictionary metadata) { Argument.AssertNotNull(id, nameof(id)); Argument.AssertNotNull(threadId, nameof(threadId)); @@ -76,7 +83,6 @@ internal ThreadRun(string id, string threadId, string assistantId, RunStatus sta Argument.AssertNotNull(model, nameof(model)); Argument.AssertNotNull(instructions, nameof(instructions)); Argument.AssertNotNull(tools, nameof(tools)); - Argument.AssertNotNull(fileIds, nameof(fileIds)); Id = id; ThreadId = threadId; @@ -86,13 +92,20 @@ internal ThreadRun(string id, string threadId, string assistantId, RunStatus sta Model = model; Instructions = instructions; Tools = tools.ToList(); - FileIds = fileIds.ToList(); CreatedAt = createdAt; ExpiresAt = expiresAt; StartedAt = startedAt; CompletedAt = completedAt; CancelledAt = cancelledAt; FailedAt = failedAt; + IncompleteDetails = incompleteDetails; + Usage = usage; + MaxPromptTokens = maxPromptTokens; + MaxCompletionTokens = maxCompletionTokens; + TruncationStrategy = truncationStrategy; + ToolChoice = toolChoice; + ParallelToolCalls = parallelToolCalls; + ResponseFormat = responseFormat; Metadata = metadata; } @@ -113,18 +126,27 @@ internal ThreadRun(string id, string threadId, string assistantId, RunStatus sta /// /// The overridden enabled tools used for this assistant thread run. /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. - /// The available derived classes include , and . + /// The available derived classes include , and . /// - /// A list of attached file IDs, ordered by creation date in ascending order. /// The Unix timestamp, in seconds, representing when this object was created. /// The Unix timestamp, in seconds, representing when this item expires. /// The Unix timestamp, in seconds, representing when this item was started. /// The Unix timestamp, in seconds, representing when this completed. /// The Unix timestamp, in seconds, representing when this was cancelled. /// The Unix timestamp, in seconds, representing when this failed. + /// Details on why the run is incomplete. Will be `null` if the run is not incomplete. + /// Usage statistics related to the run. This value will be `null` if the run is not in a terminal state (i.e. `in_progress`, `queued`, etc.). + /// The sampling temperature used for this run. If not set, defaults to 1. + /// The nucleus sampling value used for this run. If not set, defaults to 1. + /// The maximum number of prompt tokens specified to have been used over the course of the run. + /// The maximum number of completion tokens specified to have been used over the course of the run. + /// The strategy to use for dropping messages as the context windows moves forward. + /// Controls whether or not and which tool is called by the model. + /// Whether to enable parallel function calling during tool use. + /// The response format of the tool calls used in this run. /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. /// Keeps track of any properties unknown to the library. - internal ThreadRun(string id, string @object, string threadId, string assistantId, RunStatus status, RequiredAction requiredAction, RunError lastError, string model, string instructions, IReadOnlyList tools, IReadOnlyList fileIds, DateTimeOffset createdAt, DateTimeOffset? expiresAt, DateTimeOffset? startedAt, DateTimeOffset? completedAt, DateTimeOffset? cancelledAt, DateTimeOffset? failedAt, IReadOnlyDictionary metadata, IDictionary serializedAdditionalRawData) + internal ThreadRun(string id, string @object, string threadId, string assistantId, RunStatus status, RequiredAction requiredAction, RunError lastError, string model, string instructions, IReadOnlyList tools, DateTimeOffset createdAt, DateTimeOffset? expiresAt, DateTimeOffset? startedAt, DateTimeOffset? completedAt, DateTimeOffset? cancelledAt, DateTimeOffset? failedAt, IncompleteRunDetails? incompleteDetails, RunCompletionUsage usage, float? temperature, float? topP, int? maxPromptTokens, int? maxCompletionTokens, TruncationObject truncationStrategy, BinaryData toolChoice, bool parallelToolCalls, BinaryData responseFormat, IReadOnlyDictionary metadata, IDictionary serializedAdditionalRawData) { Id = id; Object = @object; @@ -136,13 +158,22 @@ internal ThreadRun(string id, string @object, string threadId, string assistantI Model = model; Instructions = instructions; Tools = tools; - FileIds = fileIds; CreatedAt = createdAt; ExpiresAt = expiresAt; StartedAt = startedAt; CompletedAt = completedAt; CancelledAt = cancelledAt; FailedAt = failedAt; + IncompleteDetails = incompleteDetails; + Usage = usage; + Temperature = temperature; + TopP = topP; + MaxPromptTokens = maxPromptTokens; + MaxCompletionTokens = maxCompletionTokens; + TruncationStrategy = truncationStrategy; + ToolChoice = toolChoice; + ParallelToolCalls = parallelToolCalls; + ResponseFormat = responseFormat; Metadata = metadata; _serializedAdditionalRawData = serializedAdditionalRawData; } @@ -176,11 +207,9 @@ internal ThreadRun() /// /// The overridden enabled tools used for this assistant thread run. /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. - /// The available derived classes include , and . + /// The available derived classes include , and . /// public IReadOnlyList Tools { get; } - /// A list of attached file IDs, ordered by creation date in ascending order. - public IReadOnlyList FileIds { get; } /// The Unix timestamp, in seconds, representing when this object was created. public DateTimeOffset CreatedAt { get; } /// The Unix timestamp, in seconds, representing when this item expires. @@ -193,6 +222,112 @@ internal ThreadRun() public DateTimeOffset? CancelledAt { get; } /// The Unix timestamp, in seconds, representing when this failed. public DateTimeOffset? FailedAt { get; } + /// Details on why the run is incomplete. Will be `null` if the run is not incomplete. + public IncompleteRunDetails? IncompleteDetails { get; } + /// Usage statistics related to the run. This value will be `null` if the run is not in a terminal state (i.e. `in_progress`, `queued`, etc.). + public RunCompletionUsage Usage { get; } + /// The sampling temperature used for this run. If not set, defaults to 1. + public float? Temperature { get; } + /// The nucleus sampling value used for this run. If not set, defaults to 1. + public float? TopP { get; } + /// The maximum number of prompt tokens specified to have been used over the course of the run. + public int? MaxPromptTokens { get; } + /// The maximum number of completion tokens specified to have been used over the course of the run. + public int? MaxCompletionTokens { get; } + /// The strategy to use for dropping messages as the context windows moves forward. + public TruncationObject TruncationStrategy { get; } + /// + /// Controls whether or not and which tool is called by the model. + /// + /// To assign an object to this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// + /// Supported types: + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + public BinaryData ToolChoice { get; } + /// Whether to enable parallel function calling during tool use. + public bool ParallelToolCalls { get; } + /// + /// The response format of the tool calls used in this run. + /// + /// To assign an object to this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// + /// Supported types: + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + public BinaryData ResponseFormat { get; } /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. public IReadOnlyDictionary Metadata { get; } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadStreamEvent.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadStreamEvent.cs new file mode 100644 index 000000000000..172bd6c20d99 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ThreadStreamEvent.cs @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Thread operation related streaming events. + public readonly partial struct ThreadStreamEvent : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public ThreadStreamEvent(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string ThreadCreatedValue = "thread.created"; + + /// Event sent when a new thread is created. The data of this event is of type AssistantThread. + public static ThreadStreamEvent ThreadCreated { get; } = new ThreadStreamEvent(ThreadCreatedValue); + /// Determines if two values are the same. + public static bool operator ==(ThreadStreamEvent left, ThreadStreamEvent right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(ThreadStreamEvent left, ThreadStreamEvent right) => !left.Equals(right); + /// Converts a to a . + public static implicit operator ThreadStreamEvent(string value) => new ThreadStreamEvent(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is ThreadStreamEvent other && Equals(other); + /// + public bool Equals(ThreadStreamEvent 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/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolDefinition.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolDefinition.Serialization.cs index 94299b574576..17a5b3bc41b5 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolDefinition.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolDefinition.Serialization.cs @@ -78,8 +78,8 @@ internal static ToolDefinition DeserializeToolDefinition(JsonElement element, Mo switch (discriminator.GetString()) { case "code_interpreter": return CodeInterpreterToolDefinition.DeserializeCodeInterpreterToolDefinition(element, options); + case "file_search": return FileSearchToolDefinition.DeserializeFileSearchToolDefinition(element, options); case "function": return FunctionToolDefinition.DeserializeFunctionToolDefinition(element, options); - case "retrieval": return RetrievalToolDefinition.DeserializeRetrievalToolDefinition(element, options); } } return UnknownToolDefinition.DeserializeUnknownToolDefinition(element, options); diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolDefinition.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolDefinition.cs index b9d063fe1c0c..be4c9b0d6cbf 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolDefinition.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolDefinition.cs @@ -13,7 +13,7 @@ namespace Azure.AI.OpenAI.Assistants /// /// An abstract representation of an input tool definition that an assistant can use. /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. - /// The available derived classes include , and . + /// The available derived classes include , and . /// public abstract partial class ToolDefinition { diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantFile.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolResources.Serialization.cs similarity index 61% rename from sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantFile.Serialization.cs rename to sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolResources.Serialization.cs index 7f2c64263ba9..a2e53c705354 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/AssistantFile.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolResources.Serialization.cs @@ -13,11 +13,11 @@ namespace Azure.AI.OpenAI.Assistants { - public partial class AssistantFile : IUtf8JsonSerializable, IJsonModel + public partial class ToolResources : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { writer.WriteStartObject(); JsonModelWriteCore(writer, options); @@ -28,20 +28,22 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOpt /// The client options for reading and writing models. protected virtual void JsonModelWriteCore(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(AssistantFile)} does not support writing '{format}' format."); + throw new FormatException($"The model {nameof(ToolResources)} does not support writing '{format}' format."); } - writer.WritePropertyName("id"u8); - writer.WriteStringValue(Id); - writer.WritePropertyName("object"u8); - writer.WriteStringValue(Object); - writer.WritePropertyName("created_at"u8); - writer.WriteNumberValue(CreatedAt, "U"); - writer.WritePropertyName("assistant_id"u8); - writer.WriteStringValue(AssistantId); + if (Optional.IsDefined(CodeInterpreter)) + { + writer.WritePropertyName("code_interpreter"u8); + writer.WriteObjectValue(CodeInterpreter, options); + } + if (Optional.IsDefined(FileSearch)) + { + writer.WritePropertyName("file_search"u8); + writer.WriteObjectValue(FileSearch, options); + } if (options.Format != "W" && _serializedAdditionalRawData != null) { foreach (var item in _serializedAdditionalRawData) @@ -59,19 +61,19 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit } } - AssistantFile IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + ToolResources 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(AssistantFile)} does not support reading '{format}' format."); + throw new FormatException($"The model {nameof(ToolResources)} does not support reading '{format}' format."); } using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeAssistantFile(document.RootElement, options); + return DeserializeToolResources(document.RootElement, options); } - internal static AssistantFile DeserializeAssistantFile(JsonElement element, ModelReaderWriterOptions options = null) + internal static ToolResources DeserializeToolResources(JsonElement element, ModelReaderWriterOptions options = null) { options ??= ModelSerializationExtensions.WireOptions; @@ -79,32 +81,28 @@ internal static AssistantFile DeserializeAssistantFile(JsonElement element, Mode { return null; } - string id = default; - string @object = default; - DateTimeOffset createdAt = default; - string assistantId = default; + CodeInterpreterToolResource codeInterpreter = default; + FileSearchToolResource fileSearch = 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("object"u8)) + if (property.NameEquals("code_interpreter"u8)) { - @object = property.Value.GetString(); - continue; - } - if (property.NameEquals("created_at"u8)) - { - createdAt = DateTimeOffset.FromUnixTimeSeconds(property.Value.GetInt64()); + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + codeInterpreter = CodeInterpreterToolResource.DeserializeCodeInterpreterToolResource(property.Value, options); continue; } - if (property.NameEquals("assistant_id"u8)) + if (property.NameEquals("file_search"u8)) { - assistantId = property.Value.GetString(); + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + fileSearch = FileSearchToolResource.DeserializeFileSearchToolResource(property.Value, options); continue; } if (options.Format != "W") @@ -113,46 +111,46 @@ internal static AssistantFile DeserializeAssistantFile(JsonElement element, Mode } } serializedAdditionalRawData = rawDataDictionary; - return new AssistantFile(id, @object, createdAt, assistantId, serializedAdditionalRawData); + return new ToolResources(codeInterpreter, fileSearch, 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(AssistantFile)} does not support writing '{options.Format}' format."); + throw new FormatException($"The model {nameof(ToolResources)} does not support writing '{options.Format}' format."); } } - AssistantFile IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + ToolResources 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, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeAssistantFile(document.RootElement, options); + return DeserializeToolResources(document.RootElement, options); } default: - throw new FormatException($"The model {nameof(AssistantFile)} does not support reading '{options.Format}' format."); + throw new FormatException($"The model {nameof(ToolResources)} does not support reading '{options.Format}' format."); } } - string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; /// Deserializes the model from a raw response. /// The response to deserialize the model from. - internal static AssistantFile FromResponse(Response response) + internal static ToolResources FromResponse(Response response) { using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeAssistantFile(document.RootElement); + return DeserializeToolResources(document.RootElement); } /// Convert into a . diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolResources.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolResources.cs new file mode 100644 index 000000000000..408316763e48 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/ToolResources.cs @@ -0,0 +1,73 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// + /// A set of resources that are used by the assistant's tools. The resources are specific to the type of + /// tool. For example, the `code_interpreter` tool requires a list of file IDs, while the `file_search` + /// tool requires a list of vector store IDs. + /// + public partial class ToolResources + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + internal ToolResources() + { + } + + /// Initializes a new instance of . + /// Resources to be used by the `code_interpreter tool` consisting of file IDs. + /// Resources to be used by the `file_search` tool consisting of vector store IDs. + /// Keeps track of any properties unknown to the library. + internal ToolResources(CodeInterpreterToolResource codeInterpreter, FileSearchToolResource fileSearch, IDictionary serializedAdditionalRawData) + { + CodeInterpreter = codeInterpreter; + FileSearch = fileSearch; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Resources to be used by the `code_interpreter tool` consisting of file IDs. + public CodeInterpreterToolResource CodeInterpreter { get; } + /// Resources to be used by the `file_search` tool consisting of vector store IDs. + public FileSearchToolResource FileSearch { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/TruncationObject.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/TruncationObject.Serialization.cs new file mode 100644 index 000000000000..a4ef2894100f --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/TruncationObject.Serialization.cs @@ -0,0 +1,165 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class TruncationObject : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(TruncationObject)} does not support writing '{format}' format."); + } + + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type.ToString()); + if (Optional.IsDefined(LastMessages)) + { + if (LastMessages != null) + { + writer.WritePropertyName("last_messages"u8); + writer.WriteNumberValue(LastMessages.Value); + } + else + { + writer.WriteNull("last_messages"); + } + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + TruncationObject 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(TruncationObject)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeTruncationObject(document.RootElement, options); + } + + internal static TruncationObject DeserializeTruncationObject(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + TruncationStrategy type = default; + int? lastMessages = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("type"u8)) + { + type = new TruncationStrategy(property.Value.GetString()); + continue; + } + if (property.NameEquals("last_messages"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + lastMessages = null; + continue; + } + lastMessages = property.Value.GetInt32(); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new TruncationObject(type, lastMessages, 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(TruncationObject)} does not support writing '{options.Format}' format."); + } + } + + TruncationObject 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeTruncationObject(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(TruncationObject)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static TruncationObject FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeTruncationObject(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/TruncationObject.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/TruncationObject.cs new file mode 100644 index 000000000000..a662e1b7761f --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/TruncationObject.cs @@ -0,0 +1,91 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// + /// Controls for how a thread will be truncated prior to the run. Use this to control the initial + /// context window of the run. + /// + public partial class TruncationObject + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + /// + /// The truncation strategy to use for the thread. The default is `auto`. If set to `last_messages`, the thread will + /// be truncated to the `lastMessages` count most recent messages in the thread. When set to `auto`, messages in the middle of the thread + /// will be dropped to fit the context length of the model, `max_prompt_tokens`. + /// + public TruncationObject(TruncationStrategy type) + { + Type = type; + } + + /// Initializes a new instance of . + /// + /// The truncation strategy to use for the thread. The default is `auto`. If set to `last_messages`, the thread will + /// be truncated to the `lastMessages` count most recent messages in the thread. When set to `auto`, messages in the middle of the thread + /// will be dropped to fit the context length of the model, `max_prompt_tokens`. + /// + /// The number of most recent messages from the thread when constructing the context for the run. + /// Keeps track of any properties unknown to the library. + internal TruncationObject(TruncationStrategy type, int? lastMessages, IDictionary serializedAdditionalRawData) + { + Type = type; + LastMessages = lastMessages; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal TruncationObject() + { + } + + /// + /// The truncation strategy to use for the thread. The default is `auto`. If set to `last_messages`, the thread will + /// be truncated to the `lastMessages` count most recent messages in the thread. When set to `auto`, messages in the middle of the thread + /// will be dropped to fit the context length of the model, `max_prompt_tokens`. + /// + public TruncationStrategy Type { get; set; } + /// The number of most recent messages from the thread when constructing the context for the run. + public int? LastMessages { get; set; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/TruncationStrategy.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/TruncationStrategy.cs new file mode 100644 index 000000000000..7e51ad3d3242 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/TruncationStrategy.cs @@ -0,0 +1,51 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Possible truncation strategies for the thread. + public readonly partial struct TruncationStrategy : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public TruncationStrategy(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string AutoValue = "auto"; + private const string LastMessagesValue = "last_messages"; + + /// Default value. Messages in the middle of the thread will be dropped to fit the context length of the model. + public static TruncationStrategy Auto { get; } = new TruncationStrategy(AutoValue); + /// The thread will truncate to the `lastMessages` count of recent messages. + public static TruncationStrategy LastMessages { get; } = new TruncationStrategy(LastMessagesValue); + /// Determines if two values are the same. + public static bool operator ==(TruncationStrategy left, TruncationStrategy right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(TruncationStrategy left, TruncationStrategy right) => !left.Equals(right); + /// Converts a to a . + public static implicit operator TruncationStrategy(string value) => new TruncationStrategy(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is TruncationStrategy other && Equals(other); + /// + public bool Equals(TruncationStrategy 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/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownAssistantsApiResponseFormat.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownAssistantsApiResponseFormat.Serialization.cs new file mode 100644 index 000000000000..4fb52f3a2e5c --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownAssistantsApiResponseFormat.Serialization.cs @@ -0,0 +1,130 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + internal partial class UnknownAssistantsApiResponseFormat : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(AssistantsApiResponseFormat)} does not support writing '{format}' format."); + } + + base.JsonModelWriteCore(writer, options); + } + + AssistantsApiResponseFormat 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(AssistantsApiResponseFormat)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeAssistantsApiResponseFormat(document.RootElement, options); + } + + internal static UnknownAssistantsApiResponseFormat DeserializeUnknownAssistantsApiResponseFormat(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + ApiResponseFormat? type = "Unknown"; + 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 ApiResponseFormat(property.Value.GetString()); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new UnknownAssistantsApiResponseFormat(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(AssistantsApiResponseFormat)} does not support writing '{options.Format}' format."); + } + } + + AssistantsApiResponseFormat 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeAssistantsApiResponseFormat(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(AssistantsApiResponseFormat)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new UnknownAssistantsApiResponseFormat FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeUnknownAssistantsApiResponseFormat(document.RootElement); + } + + /// Convert into a . + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownAssistantsApiResponseFormat.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownAssistantsApiResponseFormat.cs new file mode 100644 index 000000000000..8e79946b17e3 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownAssistantsApiResponseFormat.cs @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Unknown version of AssistantsApiResponseFormat. + internal partial class UnknownAssistantsApiResponseFormat : AssistantsApiResponseFormat + { + /// Initializes a new instance of . + /// Must be one of `text`, `json_object` or `json_schema` . + /// Keeps track of any properties unknown to the library. + internal UnknownAssistantsApiResponseFormat(ApiResponseFormat? type, IDictionary serializedAdditionalRawData) : base(type, serializedAdditionalRawData) + { + } + + /// Initializes a new instance of for deserialization. + internal UnknownAssistantsApiResponseFormat() + { + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageDeltaContent.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageDeltaContent.Serialization.cs new file mode 100644 index 000000000000..58eb97f774a0 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageDeltaContent.Serialization.cs @@ -0,0 +1,132 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + internal partial class UnknownMessageDeltaContent : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(MessageDeltaContent)} does not support writing '{format}' format."); + } + + base.JsonModelWriteCore(writer, options); + } + + MessageDeltaContent 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(MessageDeltaContent)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeMessageDeltaContent(document.RootElement, options); + } + + internal static UnknownMessageDeltaContent DeserializeUnknownMessageDeltaContent(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + int index = default; + string type = "Unknown"; + 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("type"u8)) + { + type = property.Value.GetString(); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new UnknownMessageDeltaContent(index, 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(MessageDeltaContent)} does not support writing '{options.Format}' format."); + } + } + + MessageDeltaContent 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeMessageDeltaContent(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(MessageDeltaContent)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new UnknownMessageDeltaContent FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeUnknownMessageDeltaContent(document.RootElement); + } + + /// Convert into a . + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageDeltaContent.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageDeltaContent.cs new file mode 100644 index 000000000000..7b50c79a9122 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageDeltaContent.cs @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Unknown version of MessageDeltaContent. + internal partial class UnknownMessageDeltaContent : MessageDeltaContent + { + /// Initializes a new instance of . + /// The index of the content part of the message. + /// The type of content for this content part. + /// Keeps track of any properties unknown to the library. + internal UnknownMessageDeltaContent(int index, string type, IDictionary serializedAdditionalRawData) : base(index, type, serializedAdditionalRawData) + { + } + + /// Initializes a new instance of for deserialization. + internal UnknownMessageDeltaContent() + { + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageDeltaTextAnnotation.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageDeltaTextAnnotation.Serialization.cs new file mode 100644 index 000000000000..a3520c9dcea1 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageDeltaTextAnnotation.Serialization.cs @@ -0,0 +1,132 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + internal partial class UnknownMessageDeltaTextAnnotation : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(MessageDeltaTextAnnotation)} does not support writing '{format}' format."); + } + + base.JsonModelWriteCore(writer, options); + } + + MessageDeltaTextAnnotation 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(MessageDeltaTextAnnotation)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeMessageDeltaTextAnnotation(document.RootElement, options); + } + + internal static UnknownMessageDeltaTextAnnotation DeserializeUnknownMessageDeltaTextAnnotation(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + int index = default; + string type = "Unknown"; + 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("type"u8)) + { + type = property.Value.GetString(); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new UnknownMessageDeltaTextAnnotation(index, 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(MessageDeltaTextAnnotation)} does not support writing '{options.Format}' format."); + } + } + + MessageDeltaTextAnnotation 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeMessageDeltaTextAnnotation(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(MessageDeltaTextAnnotation)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new UnknownMessageDeltaTextAnnotation FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeUnknownMessageDeltaTextAnnotation(document.RootElement); + } + + /// Convert into a . + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageDeltaTextAnnotation.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageDeltaTextAnnotation.cs new file mode 100644 index 000000000000..3a65e8f866b4 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageDeltaTextAnnotation.cs @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Unknown version of MessageDeltaTextAnnotation. + internal partial class UnknownMessageDeltaTextAnnotation : MessageDeltaTextAnnotation + { + /// Initializes a new instance of . + /// The index of the annotation within a text content part. + /// The type of the text content annotation. + /// Keeps track of any properties unknown to the library. + internal UnknownMessageDeltaTextAnnotation(int index, string type, IDictionary serializedAdditionalRawData) : base(index, type, serializedAdditionalRawData) + { + } + + /// Initializes a new instance of for deserialization. + internal UnknownMessageDeltaTextAnnotation() + { + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageTextAnnotation.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageTextAnnotation.Serialization.cs index 1a27fc0aab34..8492c2f302f8 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageTextAnnotation.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageTextAnnotation.Serialization.cs @@ -59,8 +59,6 @@ internal static UnknownMessageTextAnnotation DeserializeUnknownMessageTextAnnota } string type = "Unknown"; string text = default; - int startIndex = default; - int endIndex = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) @@ -75,23 +73,13 @@ internal static UnknownMessageTextAnnotation DeserializeUnknownMessageTextAnnota text = property.Value.GetString(); continue; } - if (property.NameEquals("start_index"u8)) - { - startIndex = property.Value.GetInt32(); - continue; - } - if (property.NameEquals("end_index"u8)) - { - endIndex = property.Value.GetInt32(); - continue; - } if (options.Format != "W") { rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); } } serializedAdditionalRawData = rawDataDictionary; - return new UnknownMessageTextAnnotation(type, text, startIndex, endIndex, serializedAdditionalRawData); + return new UnknownMessageTextAnnotation(type, text, serializedAdditionalRawData); } BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageTextAnnotation.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageTextAnnotation.cs index 707b99138307..8df46b4ee1f3 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageTextAnnotation.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownMessageTextAnnotation.cs @@ -16,10 +16,8 @@ internal partial class UnknownMessageTextAnnotation : MessageTextAnnotation /// Initializes a new instance of . /// The object type. /// The textual content associated with this text annotation item. - /// The first text index associated with this text annotation. - /// The last text index associated with this text annotation. /// Keeps track of any properties unknown to the library. - internal UnknownMessageTextAnnotation(string type, string text, int startIndex, int endIndex, IDictionary serializedAdditionalRawData) : base(type, text, startIndex, endIndex, serializedAdditionalRawData) + internal UnknownMessageTextAnnotation(string type, string text, IDictionary serializedAdditionalRawData) : base(type, text, serializedAdditionalRawData) { } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRunStepDeltaCodeInterpreterOutput.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRunStepDeltaCodeInterpreterOutput.Serialization.cs new file mode 100644 index 000000000000..3ce8d7b7753c --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRunStepDeltaCodeInterpreterOutput.Serialization.cs @@ -0,0 +1,132 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + internal partial class UnknownRunStepDeltaCodeInterpreterOutput : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(RunStepDeltaCodeInterpreterOutput)} does not support writing '{format}' format."); + } + + base.JsonModelWriteCore(writer, options); + } + + RunStepDeltaCodeInterpreterOutput 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(RunStepDeltaCodeInterpreterOutput)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeRunStepDeltaCodeInterpreterOutput(document.RootElement, options); + } + + internal static UnknownRunStepDeltaCodeInterpreterOutput DeserializeUnknownRunStepDeltaCodeInterpreterOutput(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + int index = default; + string type = "Unknown"; + 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("type"u8)) + { + type = property.Value.GetString(); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new UnknownRunStepDeltaCodeInterpreterOutput(index, 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(RunStepDeltaCodeInterpreterOutput)} does not support writing '{options.Format}' format."); + } + } + + RunStepDeltaCodeInterpreterOutput 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeRunStepDeltaCodeInterpreterOutput(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(RunStepDeltaCodeInterpreterOutput)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new UnknownRunStepDeltaCodeInterpreterOutput FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeUnknownRunStepDeltaCodeInterpreterOutput(document.RootElement); + } + + /// Convert into a . + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRunStepDeltaCodeInterpreterOutput.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRunStepDeltaCodeInterpreterOutput.cs new file mode 100644 index 000000000000..cda7227367bc --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRunStepDeltaCodeInterpreterOutput.cs @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Unknown version of RunStepDeltaCodeInterpreterOutput. + internal partial class UnknownRunStepDeltaCodeInterpreterOutput : RunStepDeltaCodeInterpreterOutput + { + /// Initializes a new instance of . + /// The index of the output in the streaming run step tool call's Code Interpreter outputs array. + /// The type of the streaming run step tool call's Code Interpreter output. + /// Keeps track of any properties unknown to the library. + internal UnknownRunStepDeltaCodeInterpreterOutput(int index, string type, IDictionary serializedAdditionalRawData) : base(index, type, serializedAdditionalRawData) + { + } + + /// Initializes a new instance of for deserialization. + internal UnknownRunStepDeltaCodeInterpreterOutput() + { + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RetrievalToolDefinition.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRunStepDeltaDetail.Serialization.cs similarity index 59% rename from sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RetrievalToolDefinition.Serialization.cs rename to sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRunStepDeltaDetail.Serialization.cs index c706bdbf9bab..ef29b0d92f80 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/RetrievalToolDefinition.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRunStepDeltaDetail.Serialization.cs @@ -13,11 +13,11 @@ namespace Azure.AI.OpenAI.Assistants { - public partial class RetrievalToolDefinition : IUtf8JsonSerializable, IJsonModel + internal partial class UnknownRunStepDeltaDetail : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { writer.WriteStartObject(); JsonModelWriteCore(writer, options); @@ -28,28 +28,28 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReade /// The client options for reading and writing models. protected override void JsonModelWriteCore(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(RetrievalToolDefinition)} does not support writing '{format}' format."); + throw new FormatException($"The model {nameof(RunStepDeltaDetail)} does not support writing '{format}' format."); } base.JsonModelWriteCore(writer, options); } - RetrievalToolDefinition IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + RunStepDeltaDetail 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(RetrievalToolDefinition)} does not support reading '{format}' format."); + throw new FormatException($"The model {nameof(RunStepDeltaDetail)} does not support reading '{format}' format."); } using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeRetrievalToolDefinition(document.RootElement, options); + return DeserializeRunStepDeltaDetail(document.RootElement, options); } - internal static RetrievalToolDefinition DeserializeRetrievalToolDefinition(JsonElement element, ModelReaderWriterOptions options = null) + internal static UnknownRunStepDeltaDetail DeserializeUnknownRunStepDeltaDetail(JsonElement element, ModelReaderWriterOptions options = null) { options ??= ModelSerializationExtensions.WireOptions; @@ -57,7 +57,7 @@ internal static RetrievalToolDefinition DeserializeRetrievalToolDefinition(JsonE { return null; } - string type = default; + string type = "Unknown"; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) @@ -73,53 +73,53 @@ internal static RetrievalToolDefinition DeserializeRetrievalToolDefinition(JsonE } } serializedAdditionalRawData = rawDataDictionary; - return new RetrievalToolDefinition(type, serializedAdditionalRawData); + return new UnknownRunStepDeltaDetail(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(RetrievalToolDefinition)} does not support writing '{options.Format}' format."); + throw new FormatException($"The model {nameof(RunStepDeltaDetail)} does not support writing '{options.Format}' format."); } } - RetrievalToolDefinition IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + RunStepDeltaDetail 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, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeRetrievalToolDefinition(document.RootElement, options); + return DeserializeRunStepDeltaDetail(document.RootElement, options); } default: - throw new FormatException($"The model {nameof(RetrievalToolDefinition)} does not support reading '{options.Format}' format."); + throw new FormatException($"The model {nameof(RunStepDeltaDetail)} does not support reading '{options.Format}' format."); } } - string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; /// Deserializes the model from a raw response. /// The response to deserialize the model from. - internal static new RetrievalToolDefinition FromResponse(Response response) + internal static new UnknownRunStepDeltaDetail FromResponse(Response response) { using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeRetrievalToolDefinition(document.RootElement); + return DeserializeUnknownRunStepDeltaDetail(document.RootElement); } /// Convert into a . internal override RequestContent ToRequestContent() { var content = new Utf8JsonRequestContent(); - content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); return content; } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRunStepDeltaDetail.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRunStepDeltaDetail.cs new file mode 100644 index 000000000000..bf9efec7d936 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRunStepDeltaDetail.cs @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Unknown version of RunStepDeltaDetail. + internal partial class UnknownRunStepDeltaDetail : RunStepDeltaDetail + { + /// Initializes a new instance of . + /// The object type for the run step detail object. + /// Keeps track of any properties unknown to the library. + internal UnknownRunStepDeltaDetail(string type, IDictionary serializedAdditionalRawData) : base(type, serializedAdditionalRawData) + { + } + + /// Initializes a new instance of for deserialization. + internal UnknownRunStepDeltaDetail() + { + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRunStepDeltaToolCall.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRunStepDeltaToolCall.Serialization.cs new file mode 100644 index 000000000000..2841df37028f --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRunStepDeltaToolCall.Serialization.cs @@ -0,0 +1,138 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + internal partial class UnknownRunStepDeltaToolCall : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(RunStepDeltaToolCall)} does not support writing '{format}' format."); + } + + base.JsonModelWriteCore(writer, options); + } + + RunStepDeltaToolCall 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(RunStepDeltaToolCall)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeRunStepDeltaToolCall(document.RootElement, options); + } + + internal static UnknownRunStepDeltaToolCall DeserializeUnknownRunStepDeltaToolCall(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + int index = default; + string id = default; + string type = "Unknown"; + 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("id"u8)) + { + id = property.Value.GetString(); + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new UnknownRunStepDeltaToolCall(index, id, 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(RunStepDeltaToolCall)} does not support writing '{options.Format}' format."); + } + } + + RunStepDeltaToolCall 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeRunStepDeltaToolCall(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(RunStepDeltaToolCall)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new UnknownRunStepDeltaToolCall FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeUnknownRunStepDeltaToolCall(document.RootElement); + } + + /// Convert into a . + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRunStepDeltaToolCall.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRunStepDeltaToolCall.cs new file mode 100644 index 000000000000..01e29a7c3518 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownRunStepDeltaToolCall.cs @@ -0,0 +1,30 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Unknown version of RunStepDeltaToolCall. + internal partial class UnknownRunStepDeltaToolCall : RunStepDeltaToolCall + { + /// Initializes a new instance of . + /// The index of the tool call detail in the run step's tool_calls array. + /// The ID of the tool call, used when submitting outputs to the run. + /// The type of the tool call detail item in a streaming run step's details. + /// Keeps track of any properties unknown to the library. + internal UnknownRunStepDeltaToolCall(int index, string id, string type, IDictionary serializedAdditionalRawData) : base(index, id, type, serializedAdditionalRawData) + { + } + + /// Initializes a new instance of for deserialization. + internal UnknownRunStepDeltaToolCall() + { + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownVectorStoreChunkingStrategyRequest.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownVectorStoreChunkingStrategyRequest.Serialization.cs new file mode 100644 index 000000000000..fa6625d4e845 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownVectorStoreChunkingStrategyRequest.Serialization.cs @@ -0,0 +1,126 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + internal partial class UnknownVectorStoreChunkingStrategyRequest : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(VectorStoreChunkingStrategyRequest)} does not support writing '{format}' format."); + } + + base.JsonModelWriteCore(writer, options); + } + + VectorStoreChunkingStrategyRequest 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(VectorStoreChunkingStrategyRequest)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeVectorStoreChunkingStrategyRequest(document.RootElement, options); + } + + internal static UnknownVectorStoreChunkingStrategyRequest DeserializeUnknownVectorStoreChunkingStrategyRequest(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + VectorStoreChunkingStrategyRequestType type = "Unknown"; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("type"u8)) + { + type = new VectorStoreChunkingStrategyRequestType(property.Value.GetString()); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new UnknownVectorStoreChunkingStrategyRequest(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(VectorStoreChunkingStrategyRequest)} does not support writing '{options.Format}' format."); + } + } + + VectorStoreChunkingStrategyRequest 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeVectorStoreChunkingStrategyRequest(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(VectorStoreChunkingStrategyRequest)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new UnknownVectorStoreChunkingStrategyRequest FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeUnknownVectorStoreChunkingStrategyRequest(document.RootElement); + } + + /// Convert into a . + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownVectorStoreChunkingStrategyRequest.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownVectorStoreChunkingStrategyRequest.cs new file mode 100644 index 000000000000..287e2c3a3496 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownVectorStoreChunkingStrategyRequest.cs @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Unknown version of VectorStoreChunkingStrategyRequest. + internal partial class UnknownVectorStoreChunkingStrategyRequest : VectorStoreChunkingStrategyRequest + { + /// Initializes a new instance of . + /// The object type. + /// Keeps track of any properties unknown to the library. + internal UnknownVectorStoreChunkingStrategyRequest(VectorStoreChunkingStrategyRequestType type, IDictionary serializedAdditionalRawData) : base(type, serializedAdditionalRawData) + { + } + + /// Initializes a new instance of for deserialization. + internal UnknownVectorStoreChunkingStrategyRequest() + { + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownVectorStoreChunkingStrategyResponse.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownVectorStoreChunkingStrategyResponse.Serialization.cs new file mode 100644 index 000000000000..23b989280aa8 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownVectorStoreChunkingStrategyResponse.Serialization.cs @@ -0,0 +1,126 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + internal partial class UnknownVectorStoreChunkingStrategyResponse : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(VectorStoreChunkingStrategyResponse)} does not support writing '{format}' format."); + } + + base.JsonModelWriteCore(writer, options); + } + + VectorStoreChunkingStrategyResponse 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(VectorStoreChunkingStrategyResponse)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeVectorStoreChunkingStrategyResponse(document.RootElement, options); + } + + internal static UnknownVectorStoreChunkingStrategyResponse DeserializeUnknownVectorStoreChunkingStrategyResponse(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + VectorStoreChunkingStrategyResponseType type = "Unknown"; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("type"u8)) + { + type = new VectorStoreChunkingStrategyResponseType(property.Value.GetString()); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new UnknownVectorStoreChunkingStrategyResponse(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(VectorStoreChunkingStrategyResponse)} does not support writing '{options.Format}' format."); + } + } + + VectorStoreChunkingStrategyResponse 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeVectorStoreChunkingStrategyResponse(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(VectorStoreChunkingStrategyResponse)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new UnknownVectorStoreChunkingStrategyResponse FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeUnknownVectorStoreChunkingStrategyResponse(document.RootElement); + } + + /// Convert into a . + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownVectorStoreChunkingStrategyResponse.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownVectorStoreChunkingStrategyResponse.cs new file mode 100644 index 000000000000..d81dc4925d3c --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UnknownVectorStoreChunkingStrategyResponse.cs @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Unknown version of VectorStoreChunkingStrategyResponse. + internal partial class UnknownVectorStoreChunkingStrategyResponse : VectorStoreChunkingStrategyResponse + { + /// Initializes a new instance of . + /// The object type. + /// Keeps track of any properties unknown to the library. + internal UnknownVectorStoreChunkingStrategyResponse(VectorStoreChunkingStrategyResponseType type, IDictionary serializedAdditionalRawData) : base(type, serializedAdditionalRawData) + { + } + + /// Initializes a new instance of for deserialization. + internal UnknownVectorStoreChunkingStrategyResponse() + { + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateAssistantOptions.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateAssistantOptions.Serialization.cs index 921a89074dc7..2806542a5d84 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateAssistantOptions.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateAssistantOptions.Serialization.cs @@ -85,15 +85,53 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit } writer.WriteEndArray(); } - if (Optional.IsCollectionDefined(FileIds)) + if (Optional.IsDefined(ToolResources)) { - writer.WritePropertyName("file_ids"u8); - writer.WriteStartArray(); - foreach (var item in FileIds) + writer.WritePropertyName("tool_resources"u8); + writer.WriteObjectValue(ToolResources, options); + } + if (Optional.IsDefined(Temperature)) + { + if (Temperature != null) { - writer.WriteStringValue(item); + writer.WritePropertyName("temperature"u8); + writer.WriteNumberValue(Temperature.Value); + } + else + { + writer.WriteNull("temperature"); + } + } + if (Optional.IsDefined(TopP)) + { + if (TopP != null) + { + writer.WritePropertyName("top_p"u8); + writer.WriteNumberValue(TopP.Value); + } + else + { + writer.WriteNull("top_p"); + } + } + if (Optional.IsDefined(ResponseFormat)) + { + if (ResponseFormat != null) + { + writer.WritePropertyName("response_format"u8); +#if NET6_0_OR_GREATER + writer.WriteRawValue(ResponseFormat); +#else + using (JsonDocument document = JsonDocument.Parse(ResponseFormat, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + else + { + writer.WriteNull("response_format"); } - writer.WriteEndArray(); } if (Optional.IsCollectionDefined(Metadata)) { @@ -155,7 +193,10 @@ internal static UpdateAssistantOptions DeserializeUpdateAssistantOptions(JsonEle string description = default; string instructions = default; IList tools = default; - IList fileIds = default; + UpdateToolResourcesOptions toolResources = default; + float? temperature = default; + float? topP = default; + BinaryData responseFormat = default; IDictionary metadata = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); @@ -210,18 +251,43 @@ internal static UpdateAssistantOptions DeserializeUpdateAssistantOptions(JsonEle tools = array; continue; } - if (property.NameEquals("file_ids"u8)) + if (property.NameEquals("tool_resources"u8)) { if (property.Value.ValueKind == JsonValueKind.Null) { continue; } - List array = new List(); - foreach (var item in property.Value.EnumerateArray()) + toolResources = UpdateToolResourcesOptions.DeserializeUpdateToolResourcesOptions(property.Value, options); + continue; + } + if (property.NameEquals("temperature"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) { - array.Add(item.GetString()); + temperature = null; + continue; + } + temperature = property.Value.GetSingle(); + continue; + } + if (property.NameEquals("top_p"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + topP = null; + continue; + } + topP = property.Value.GetSingle(); + continue; + } + if (property.NameEquals("response_format"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + responseFormat = null; + continue; } - fileIds = array; + responseFormat = BinaryData.FromString(property.Value.GetRawText()); continue; } if (property.NameEquals("metadata"u8)) @@ -250,7 +316,10 @@ internal static UpdateAssistantOptions DeserializeUpdateAssistantOptions(JsonEle description, instructions, tools ?? new ChangeTrackingList(), - fileIds ?? new ChangeTrackingList(), + toolResources, + temperature, + topP, + responseFormat, metadata ?? new ChangeTrackingDictionary(), serializedAdditionalRawData); } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateAssistantOptions.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateAssistantOptions.cs index 85770c825c21..b3b50cb3bb79 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateAssistantOptions.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateAssistantOptions.cs @@ -49,7 +49,6 @@ public partial class UpdateAssistantOptions public UpdateAssistantOptions() { Tools = new ChangeTrackingList(); - FileIds = new ChangeTrackingList(); Metadata = new ChangeTrackingDictionary(); } @@ -61,19 +60,36 @@ public UpdateAssistantOptions() /// /// The modified collection of tools to enable for the assistant. /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. - /// The available derived classes include , and . + /// The available derived classes include , and . /// - /// The modified list of previously uploaded fileIDs to attach to the assistant. + /// + /// A set of resources that are used by the assistant's tools. The resources are specific to the type of tool. For example, + /// the `code_interpreter` tool requires a list of file IDs, while the `file_search` tool requires a list of vector store IDs. + /// + /// + /// What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, + /// while lower values like 0.2 will make it more focused and deterministic. + /// + /// + /// An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. + /// So 0.1 means only the tokens comprising the top 10% probability mass are considered. + /// + /// We generally recommend altering this or temperature but not both. + /// + /// The response format of the tool calls used by this assistant. /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. /// Keeps track of any properties unknown to the library. - internal UpdateAssistantOptions(string model, string name, string description, string instructions, IList tools, IList fileIds, IDictionary metadata, IDictionary serializedAdditionalRawData) + internal UpdateAssistantOptions(string model, string name, string description, string instructions, IList tools, UpdateToolResourcesOptions toolResources, float? temperature, float? topP, BinaryData responseFormat, IDictionary metadata, IDictionary serializedAdditionalRawData) { Model = model; Name = name; Description = description; Instructions = instructions; Tools = tools; - FileIds = fileIds; + ToolResources = toolResources; + Temperature = temperature; + TopP = topP; + ResponseFormat = responseFormat; Metadata = metadata; _serializedAdditionalRawData = serializedAdditionalRawData; } @@ -89,11 +105,71 @@ internal UpdateAssistantOptions(string model, string name, string description, s /// /// The modified collection of tools to enable for the assistant. /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. - /// The available derived classes include , and . + /// The available derived classes include , and . /// public IList Tools { get; } - /// The modified list of previously uploaded fileIDs to attach to the assistant. - public IList FileIds { get; } + /// + /// A set of resources that are used by the assistant's tools. The resources are specific to the type of tool. For example, + /// the `code_interpreter` tool requires a list of file IDs, while the `file_search` tool requires a list of vector store IDs. + /// + public UpdateToolResourcesOptions ToolResources { get; set; } + /// + /// What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, + /// while lower values like 0.2 will make it more focused and deterministic. + /// + public float? Temperature { get; set; } + /// + /// An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. + /// So 0.1 means only the tokens comprising the top 10% probability mass are considered. + /// + /// We generally recommend altering this or temperature but not both. + /// + public float? TopP { get; set; } + /// + /// The response format of the tool calls used by this assistant. + /// + /// To assign an object to this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// + /// Supported types: + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + public BinaryData ResponseFormat { get; set; } /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. public IDictionary Metadata { get; set; } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateThreadRequest.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateAssistantThreadOptions.Serialization.cs similarity index 62% rename from sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateThreadRequest.Serialization.cs rename to sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateAssistantThreadOptions.Serialization.cs index 1469ef70a4f8..9d5f8b5e50f7 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateThreadRequest.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateAssistantThreadOptions.Serialization.cs @@ -13,11 +13,11 @@ namespace Azure.AI.OpenAI.Assistants { - internal partial class UpdateThreadRequest : IUtf8JsonSerializable, IJsonModel + public partial class UpdateAssistantThreadOptions : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { writer.WriteStartObject(); JsonModelWriteCore(writer, options); @@ -28,12 +28,24 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWri /// The client options for reading and writing models. protected virtual void JsonModelWriteCore(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(UpdateThreadRequest)} does not support writing '{format}' format."); + throw new FormatException($"The model {nameof(UpdateAssistantThreadOptions)} does not support writing '{format}' format."); } + if (Optional.IsDefined(ToolResources)) + { + if (ToolResources != null) + { + writer.WritePropertyName("tool_resources"u8); + writer.WriteObjectValue(ToolResources, options); + } + else + { + writer.WriteNull("tool_resources"); + } + } if (Optional.IsCollectionDefined(Metadata)) { if (Metadata != null) @@ -69,19 +81,19 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit } } - UpdateThreadRequest IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + UpdateAssistantThreadOptions 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(UpdateThreadRequest)} does not support reading '{format}' format."); + throw new FormatException($"The model {nameof(UpdateAssistantThreadOptions)} does not support reading '{format}' format."); } using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeUpdateThreadRequest(document.RootElement, options); + return DeserializeUpdateAssistantThreadOptions(document.RootElement, options); } - internal static UpdateThreadRequest DeserializeUpdateThreadRequest(JsonElement element, ModelReaderWriterOptions options = null) + internal static UpdateAssistantThreadOptions DeserializeUpdateAssistantThreadOptions(JsonElement element, ModelReaderWriterOptions options = null) { options ??= ModelSerializationExtensions.WireOptions; @@ -89,11 +101,22 @@ internal static UpdateThreadRequest DeserializeUpdateThreadRequest(JsonElement e { return null; } - IReadOnlyDictionary metadata = default; + UpdateToolResourcesOptions toolResources = default; + IDictionary metadata = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { + if (property.NameEquals("tool_resources"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + toolResources = null; + continue; + } + toolResources = UpdateToolResourcesOptions.DeserializeUpdateToolResourcesOptions(property.Value, options); + continue; + } if (property.NameEquals("metadata"u8)) { if (property.Value.ValueKind == JsonValueKind.Null) @@ -114,46 +137,46 @@ internal static UpdateThreadRequest DeserializeUpdateThreadRequest(JsonElement e } } serializedAdditionalRawData = rawDataDictionary; - return new UpdateThreadRequest(metadata ?? new ChangeTrackingDictionary(), serializedAdditionalRawData); + return new UpdateAssistantThreadOptions(toolResources, metadata ?? new ChangeTrackingDictionary(), 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(UpdateThreadRequest)} does not support writing '{options.Format}' format."); + throw new FormatException($"The model {nameof(UpdateAssistantThreadOptions)} does not support writing '{options.Format}' format."); } } - UpdateThreadRequest IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + UpdateAssistantThreadOptions 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, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeUpdateThreadRequest(document.RootElement, options); + return DeserializeUpdateAssistantThreadOptions(document.RootElement, options); } default: - throw new FormatException($"The model {nameof(UpdateThreadRequest)} does not support reading '{options.Format}' format."); + throw new FormatException($"The model {nameof(UpdateAssistantThreadOptions)} does not support reading '{options.Format}' format."); } } - string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; /// Deserializes the model from a raw response. /// The response to deserialize the model from. - internal static UpdateThreadRequest FromResponse(Response response) + internal static UpdateAssistantThreadOptions FromResponse(Response response) { using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeUpdateThreadRequest(document.RootElement); + return DeserializeUpdateAssistantThreadOptions(document.RootElement); } /// Convert into a . diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateMessageRequest.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateAssistantThreadOptions.cs similarity index 53% rename from sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateMessageRequest.cs rename to sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateAssistantThreadOptions.cs index b58f5b245234..6b7141de049b 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/CreateMessageRequest.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateAssistantThreadOptions.cs @@ -10,8 +10,8 @@ namespace Azure.AI.OpenAI.Assistants { - /// The CreateMessageRequest. - internal partial class CreateMessageRequest + /// The details used to update an existing assistant thread. + public partial class UpdateAssistantThreadOptions { /// /// Keeps track of any properties unknown to the library. @@ -45,47 +45,34 @@ internal partial class CreateMessageRequest /// private IDictionary _serializedAdditionalRawData; - /// Initializes a new instance of . - /// The role to associate with the new message. - /// The textual content for the new message. - /// is null. - internal CreateMessageRequest(MessageRole role, string content) + /// Initializes a new instance of . + public UpdateAssistantThreadOptions() { - Argument.AssertNotNull(content, nameof(content)); - - Role = role; - Content = content; - FileIds = new ChangeTrackingList(); Metadata = new ChangeTrackingDictionary(); } - /// Initializes a new instance of . - /// The role to associate with the new message. - /// The textual content for the new message. - /// A list of up to 10 file IDs to associate with the message, as used by tools like 'code_interpreter' or 'retrieval' that can read files. + /// Initializes a new instance of . + /// + /// A set of resources that are made available to the assistant's tools in this thread. The resources are specific to the + /// type of tool. For example, the `code_interpreter` tool requires a list of file IDs, while the `file_search` tool requires + /// a list of vector store IDs + /// /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. /// Keeps track of any properties unknown to the library. - internal CreateMessageRequest(MessageRole role, string content, IReadOnlyList fileIds, IReadOnlyDictionary metadata, IDictionary serializedAdditionalRawData) + internal UpdateAssistantThreadOptions(UpdateToolResourcesOptions toolResources, IDictionary metadata, IDictionary serializedAdditionalRawData) { - Role = role; - Content = content; - FileIds = fileIds; + ToolResources = toolResources; Metadata = metadata; _serializedAdditionalRawData = serializedAdditionalRawData; } - /// Initializes a new instance of for deserialization. - internal CreateMessageRequest() - { - } - - /// The role to associate with the new message. - public MessageRole Role { get; } - /// The textual content for the new message. - public string Content { get; } - /// A list of up to 10 file IDs to associate with the message, as used by tools like 'code_interpreter' or 'retrieval' that can read files. - public IReadOnlyList FileIds { get; } + /// + /// A set of resources that are made available to the assistant's tools in this thread. The resources are specific to the + /// type of tool. For example, the `code_interpreter` tool requires a list of file IDs, while the `file_search` tool requires + /// a list of vector store IDs + /// + public UpdateToolResourcesOptions ToolResources { get; set; } /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. - public IReadOnlyDictionary Metadata { get; } + public IDictionary Metadata { get; set; } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateCodeInterpreterToolResourceOptions.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateCodeInterpreterToolResourceOptions.Serialization.cs new file mode 100644 index 000000000000..d88457c6b5a3 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateCodeInterpreterToolResourceOptions.Serialization.cs @@ -0,0 +1,159 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class UpdateCodeInterpreterToolResourceOptions : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(UpdateCodeInterpreterToolResourceOptions)} does not support writing '{format}' format."); + } + + if (Optional.IsCollectionDefined(FileIds)) + { + writer.WritePropertyName("file_ids"u8); + writer.WriteStartArray(); + foreach (var item in FileIds) + { + writer.WriteStringValue(item); + } + writer.WriteEndArray(); + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + UpdateCodeInterpreterToolResourceOptions 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(UpdateCodeInterpreterToolResourceOptions)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeUpdateCodeInterpreterToolResourceOptions(document.RootElement, options); + } + + internal static UpdateCodeInterpreterToolResourceOptions DeserializeUpdateCodeInterpreterToolResourceOptions(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + IList fileIds = 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 (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new UpdateCodeInterpreterToolResourceOptions(fileIds ?? 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(UpdateCodeInterpreterToolResourceOptions)} does not support writing '{options.Format}' format."); + } + } + + UpdateCodeInterpreterToolResourceOptions 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeUpdateCodeInterpreterToolResourceOptions(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(UpdateCodeInterpreterToolResourceOptions)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static UpdateCodeInterpreterToolResourceOptions FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeUpdateCodeInterpreterToolResourceOptions(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateCodeInterpreterToolResourceOptions.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateCodeInterpreterToolResourceOptions.cs new file mode 100644 index 000000000000..8c09267cd78d --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateCodeInterpreterToolResourceOptions.cs @@ -0,0 +1,66 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Request object to update `code_interpreted` tool resources. + public partial class UpdateCodeInterpreterToolResourceOptions + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + public UpdateCodeInterpreterToolResourceOptions() + { + FileIds = new ChangeTrackingList(); + } + + /// Initializes a new instance of . + /// A list of file IDs to override the current list of the assistant. + /// Keeps track of any properties unknown to the library. + internal UpdateCodeInterpreterToolResourceOptions(IList fileIds, IDictionary serializedAdditionalRawData) + { + FileIds = fileIds; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// A list of file IDs to override the current list of the assistant. + public IList FileIds { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateFileSearchToolResourceOptions.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateFileSearchToolResourceOptions.Serialization.cs new file mode 100644 index 000000000000..224226046340 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateFileSearchToolResourceOptions.Serialization.cs @@ -0,0 +1,159 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class UpdateFileSearchToolResourceOptions : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(UpdateFileSearchToolResourceOptions)} does not support writing '{format}' format."); + } + + if (Optional.IsCollectionDefined(VectorStoreIds)) + { + writer.WritePropertyName("vector_store_ids"u8); + writer.WriteStartArray(); + foreach (var item in VectorStoreIds) + { + writer.WriteStringValue(item); + } + writer.WriteEndArray(); + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + UpdateFileSearchToolResourceOptions 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(UpdateFileSearchToolResourceOptions)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeUpdateFileSearchToolResourceOptions(document.RootElement, options); + } + + internal static UpdateFileSearchToolResourceOptions DeserializeUpdateFileSearchToolResourceOptions(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 (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new UpdateFileSearchToolResourceOptions(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(UpdateFileSearchToolResourceOptions)} does not support writing '{options.Format}' format."); + } + } + + UpdateFileSearchToolResourceOptions 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeUpdateFileSearchToolResourceOptions(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(UpdateFileSearchToolResourceOptions)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static UpdateFileSearchToolResourceOptions FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeUpdateFileSearchToolResourceOptions(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateFileSearchToolResourceOptions.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateFileSearchToolResourceOptions.cs new file mode 100644 index 000000000000..8742c5cd1b07 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateFileSearchToolResourceOptions.cs @@ -0,0 +1,66 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Request object to update `file_search` tool resources. + public partial class UpdateFileSearchToolResourceOptions + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + public UpdateFileSearchToolResourceOptions() + { + VectorStoreIds = new ChangeTrackingList(); + } + + /// Initializes a new instance of . + /// A list of vector store IDs to override the current list of the assistant. + /// Keeps track of any properties unknown to the library. + internal UpdateFileSearchToolResourceOptions(IList vectorStoreIds, IDictionary serializedAdditionalRawData) + { + VectorStoreIds = vectorStoreIds; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// A list of vector store IDs to override the current list of the assistant. + public IList VectorStoreIds { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateToolResourcesOptions.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateToolResourcesOptions.Serialization.cs new file mode 100644 index 000000000000..beeca740951f --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateToolResourcesOptions.Serialization.cs @@ -0,0 +1,164 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class UpdateToolResourcesOptions : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(UpdateToolResourcesOptions)} does not support writing '{format}' format."); + } + + if (Optional.IsDefined(CodeInterpreter)) + { + writer.WritePropertyName("code_interpreter"u8); + writer.WriteObjectValue(CodeInterpreter, options); + } + if (Optional.IsDefined(FileSearch)) + { + writer.WritePropertyName("file_search"u8); + writer.WriteObjectValue(FileSearch, options); + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + UpdateToolResourcesOptions 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(UpdateToolResourcesOptions)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeUpdateToolResourcesOptions(document.RootElement, options); + } + + internal static UpdateToolResourcesOptions DeserializeUpdateToolResourcesOptions(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + UpdateCodeInterpreterToolResourceOptions codeInterpreter = default; + UpdateFileSearchToolResourceOptions fileSearch = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("code_interpreter"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + codeInterpreter = UpdateCodeInterpreterToolResourceOptions.DeserializeUpdateCodeInterpreterToolResourceOptions(property.Value, options); + continue; + } + if (property.NameEquals("file_search"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + fileSearch = UpdateFileSearchToolResourceOptions.DeserializeUpdateFileSearchToolResourceOptions(property.Value, options); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new UpdateToolResourcesOptions(codeInterpreter, fileSearch, 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(UpdateToolResourcesOptions)} does not support writing '{options.Format}' format."); + } + } + + UpdateToolResourcesOptions 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeUpdateToolResourcesOptions(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(UpdateToolResourcesOptions)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static UpdateToolResourcesOptions FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeUpdateToolResourcesOptions(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateToolResourcesOptions.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateToolResourcesOptions.cs new file mode 100644 index 000000000000..919e93c57f1f --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateToolResourcesOptions.cs @@ -0,0 +1,79 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// + /// Request object. A set of resources that are used by the assistant's tools. The resources are specific to the type of tool. + /// For example, the `code_interpreter` tool requires a list of file IDs, while the `file_search` tool requires a list of + /// vector store IDs. + /// + public partial class UpdateToolResourcesOptions + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + public UpdateToolResourcesOptions() + { + } + + /// Initializes a new instance of . + /// + /// Overrides the list of file IDs made available to the `code_interpreter` tool. There can be a maximum of 20 files + /// associated with the tool. + /// + /// Overrides the vector store attached to this assistant. There can be a maximum of 1 vector store attached to the assistant. + /// Keeps track of any properties unknown to the library. + internal UpdateToolResourcesOptions(UpdateCodeInterpreterToolResourceOptions codeInterpreter, UpdateFileSearchToolResourceOptions fileSearch, IDictionary serializedAdditionalRawData) + { + CodeInterpreter = codeInterpreter; + FileSearch = fileSearch; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// + /// Overrides the list of file IDs made available to the `code_interpreter` tool. There can be a maximum of 20 files + /// associated with the tool. + /// + public UpdateCodeInterpreterToolResourceOptions CodeInterpreter { get; set; } + /// Overrides the vector store attached to this assistant. There can be a maximum of 1 vector store attached to the assistant. + public UpdateFileSearchToolResourceOptions FileSearch { get; set; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStore.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStore.Serialization.cs new file mode 100644 index 000000000000..3ec00f4ffec9 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStore.Serialization.cs @@ -0,0 +1,291 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class VectorStore : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(VectorStore)} does not support writing '{format}' format."); + } + + writer.WritePropertyName("id"u8); + writer.WriteStringValue(Id); + writer.WritePropertyName("object"u8); + writer.WriteStringValue(Object.ToString()); + writer.WritePropertyName("created_at"u8); + writer.WriteNumberValue(CreatedAt, "U"); + writer.WritePropertyName("name"u8); + writer.WriteStringValue(Name); + writer.WritePropertyName("usage_bytes"u8); + writer.WriteNumberValue(UsageBytes); + writer.WritePropertyName("file_counts"u8); + writer.WriteObjectValue(FileCounts, options); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(Status.ToString()); + if (Optional.IsDefined(ExpiresAfter)) + { + writer.WritePropertyName("expires_after"u8); + writer.WriteObjectValue(ExpiresAfter, options); + } + if (Optional.IsDefined(ExpiresAt)) + { + if (ExpiresAt != null) + { + writer.WritePropertyName("expires_at"u8); + writer.WriteNumberValue(ExpiresAt.Value, "U"); + } + else + { + writer.WriteNull("expires_at"); + } + } + if (LastActiveAt != null) + { + writer.WritePropertyName("last_active_at"u8); + writer.WriteNumberValue(LastActiveAt.Value, "U"); + } + else + { + writer.WriteNull("last_active_at"); + } + if (Metadata != null && Optional.IsCollectionDefined(Metadata)) + { + writer.WritePropertyName("metadata"u8); + writer.WriteStartObject(); + foreach (var item in Metadata) + { + writer.WritePropertyName(item.Key); + writer.WriteStringValue(item.Value); + } + writer.WriteEndObject(); + } + else + { + writer.WriteNull("metadata"); + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + VectorStore 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(VectorStore)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeVectorStore(document.RootElement, options); + } + + internal static VectorStore DeserializeVectorStore(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string id = default; + VectorStoreObject @object = default; + DateTimeOffset createdAt = default; + string name = default; + int usageBytes = default; + VectorStoreFileCount fileCounts = default; + VectorStoreStatus status = default; + VectorStoreExpirationPolicy expiresAfter = default; + DateTimeOffset? expiresAt = default; + DateTimeOffset? lastActiveAt = default; + IReadOnlyDictionary metadata = 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("object"u8)) + { + @object = new VectorStoreObject(property.Value.GetString()); + continue; + } + if (property.NameEquals("created_at"u8)) + { + createdAt = DateTimeOffset.FromUnixTimeSeconds(property.Value.GetInt64()); + continue; + } + if (property.NameEquals("name"u8)) + { + name = property.Value.GetString(); + continue; + } + if (property.NameEquals("usage_bytes"u8)) + { + usageBytes = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("file_counts"u8)) + { + fileCounts = VectorStoreFileCount.DeserializeVectorStoreFileCount(property.Value, options); + continue; + } + if (property.NameEquals("status"u8)) + { + status = new VectorStoreStatus(property.Value.GetString()); + continue; + } + if (property.NameEquals("expires_after"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + expiresAfter = VectorStoreExpirationPolicy.DeserializeVectorStoreExpirationPolicy(property.Value, options); + continue; + } + if (property.NameEquals("expires_at"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + expiresAt = null; + continue; + } + expiresAt = DateTimeOffset.FromUnixTimeSeconds(property.Value.GetInt64()); + continue; + } + if (property.NameEquals("last_active_at"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + lastActiveAt = null; + continue; + } + lastActiveAt = DateTimeOffset.FromUnixTimeSeconds(property.Value.GetInt64()); + continue; + } + if (property.NameEquals("metadata"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + metadata = new ChangeTrackingDictionary(); + continue; + } + Dictionary dictionary = new Dictionary(); + foreach (var property0 in property.Value.EnumerateObject()) + { + dictionary.Add(property0.Name, property0.Value.GetString()); + } + metadata = dictionary; + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new VectorStore( + id, + @object, + createdAt, + name, + usageBytes, + fileCounts, + status, + expiresAfter, + expiresAt, + lastActiveAt, + metadata, + 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(VectorStore)} does not support writing '{options.Format}' format."); + } + } + + VectorStore 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeVectorStore(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(VectorStore)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static VectorStore FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeVectorStore(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStore.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStore.cs new file mode 100644 index 000000000000..bd3231e10fc6 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStore.cs @@ -0,0 +1,132 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// A vector store is a collection of processed files can be used by the `file_search` tool. + public partial class VectorStore + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + /// The identifier, which can be referenced in API endpoints. + /// The Unix timestamp (in seconds) for when the vector store was created. + /// The name of the vector store. + /// The total number of bytes used by the files in the vector store. + /// Files count grouped by status processed or being processed by this vector store. + /// The status of the vector store, which can be either `expired`, `in_progress`, or `completed`. A status of `completed` indicates that the vector store is ready for use. + /// The Unix timestamp (in seconds) for when the vector store was last active. + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + /// , or is null. + internal VectorStore(string id, DateTimeOffset createdAt, string name, int usageBytes, VectorStoreFileCount fileCounts, VectorStoreStatus status, DateTimeOffset? lastActiveAt, IReadOnlyDictionary metadata) + { + Argument.AssertNotNull(id, nameof(id)); + Argument.AssertNotNull(name, nameof(name)); + Argument.AssertNotNull(fileCounts, nameof(fileCounts)); + + Id = id; + CreatedAt = createdAt; + Name = name; + UsageBytes = usageBytes; + FileCounts = fileCounts; + Status = status; + LastActiveAt = lastActiveAt; + Metadata = metadata; + } + + /// Initializes a new instance of . + /// The identifier, which can be referenced in API endpoints. + /// The object type, which is always `vector_store`. + /// The Unix timestamp (in seconds) for when the vector store was created. + /// The name of the vector store. + /// The total number of bytes used by the files in the vector store. + /// Files count grouped by status processed or being processed by this vector store. + /// The status of the vector store, which can be either `expired`, `in_progress`, or `completed`. A status of `completed` indicates that the vector store is ready for use. + /// Details on when this vector store expires. + /// The Unix timestamp (in seconds) for when the vector store will expire. + /// The Unix timestamp (in seconds) for when the vector store was last active. + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + /// Keeps track of any properties unknown to the library. + internal VectorStore(string id, VectorStoreObject @object, DateTimeOffset createdAt, string name, int usageBytes, VectorStoreFileCount fileCounts, VectorStoreStatus status, VectorStoreExpirationPolicy expiresAfter, DateTimeOffset? expiresAt, DateTimeOffset? lastActiveAt, IReadOnlyDictionary metadata, IDictionary serializedAdditionalRawData) + { + Id = id; + Object = @object; + CreatedAt = createdAt; + Name = name; + UsageBytes = usageBytes; + FileCounts = fileCounts; + Status = status; + ExpiresAfter = expiresAfter; + ExpiresAt = expiresAt; + LastActiveAt = lastActiveAt; + Metadata = metadata; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal VectorStore() + { + } + + /// The identifier, which can be referenced in API endpoints. + public string Id { get; } + /// The object type, which is always `vector_store`. + public VectorStoreObject Object { get; } = VectorStoreObject.VectorStore; + + /// The Unix timestamp (in seconds) for when the vector store was created. + public DateTimeOffset CreatedAt { get; } + /// The name of the vector store. + public string Name { get; } + /// The total number of bytes used by the files in the vector store. + public int UsageBytes { get; } + /// Files count grouped by status processed or being processed by this vector store. + public VectorStoreFileCount FileCounts { get; } + /// The status of the vector store, which can be either `expired`, `in_progress`, or `completed`. A status of `completed` indicates that the vector store is ready for use. + public VectorStoreStatus Status { get; } + /// Details on when this vector store expires. + public VectorStoreExpirationPolicy ExpiresAfter { get; } + /// The Unix timestamp (in seconds) for when the vector store will expire. + public DateTimeOffset? ExpiresAt { get; } + /// The Unix timestamp (in seconds) for when the vector store was last active. + public DateTimeOffset? LastActiveAt { get; } + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + public IReadOnlyDictionary Metadata { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreAutoChunkingStrategyRequest.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreAutoChunkingStrategyRequest.Serialization.cs new file mode 100644 index 000000000000..b58f5bea42d0 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreAutoChunkingStrategyRequest.Serialization.cs @@ -0,0 +1,126 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class VectorStoreAutoChunkingStrategyRequest : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(VectorStoreAutoChunkingStrategyRequest)} does not support writing '{format}' format."); + } + + base.JsonModelWriteCore(writer, options); + } + + VectorStoreAutoChunkingStrategyRequest 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(VectorStoreAutoChunkingStrategyRequest)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeVectorStoreAutoChunkingStrategyRequest(document.RootElement, options); + } + + internal static VectorStoreAutoChunkingStrategyRequest DeserializeVectorStoreAutoChunkingStrategyRequest(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + VectorStoreChunkingStrategyRequestType type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("type"u8)) + { + type = new VectorStoreChunkingStrategyRequestType(property.Value.GetString()); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new VectorStoreAutoChunkingStrategyRequest(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(VectorStoreAutoChunkingStrategyRequest)} does not support writing '{options.Format}' format."); + } + } + + VectorStoreAutoChunkingStrategyRequest 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeVectorStoreAutoChunkingStrategyRequest(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(VectorStoreAutoChunkingStrategyRequest)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new VectorStoreAutoChunkingStrategyRequest FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeVectorStoreAutoChunkingStrategyRequest(document.RootElement); + } + + /// Convert into a . + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreAutoChunkingStrategyRequest.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreAutoChunkingStrategyRequest.cs new file mode 100644 index 000000000000..54ccde180223 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreAutoChunkingStrategyRequest.cs @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The default strategy. This strategy currently uses a max_chunk_size_tokens of 800 and chunk_overlap_tokens of 400. + public partial class VectorStoreAutoChunkingStrategyRequest : VectorStoreChunkingStrategyRequest + { + /// Initializes a new instance of . + public VectorStoreAutoChunkingStrategyRequest() + { + Type = VectorStoreChunkingStrategyRequestType.Auto; + } + + /// Initializes a new instance of . + /// The object type. + /// Keeps track of any properties unknown to the library. + internal VectorStoreAutoChunkingStrategyRequest(VectorStoreChunkingStrategyRequestType type, IDictionary serializedAdditionalRawData) : base(type, serializedAdditionalRawData) + { + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreAutoChunkingStrategyResponse.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreAutoChunkingStrategyResponse.Serialization.cs new file mode 100644 index 000000000000..f97bdd43c70b --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreAutoChunkingStrategyResponse.Serialization.cs @@ -0,0 +1,126 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class VectorStoreAutoChunkingStrategyResponse : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(VectorStoreAutoChunkingStrategyResponse)} does not support writing '{format}' format."); + } + + base.JsonModelWriteCore(writer, options); + } + + VectorStoreAutoChunkingStrategyResponse 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(VectorStoreAutoChunkingStrategyResponse)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeVectorStoreAutoChunkingStrategyResponse(document.RootElement, options); + } + + internal static VectorStoreAutoChunkingStrategyResponse DeserializeVectorStoreAutoChunkingStrategyResponse(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + VectorStoreChunkingStrategyResponseType type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("type"u8)) + { + type = new VectorStoreChunkingStrategyResponseType(property.Value.GetString()); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new VectorStoreAutoChunkingStrategyResponse(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(VectorStoreAutoChunkingStrategyResponse)} does not support writing '{options.Format}' format."); + } + } + + VectorStoreAutoChunkingStrategyResponse 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeVectorStoreAutoChunkingStrategyResponse(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(VectorStoreAutoChunkingStrategyResponse)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new VectorStoreAutoChunkingStrategyResponse FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeVectorStoreAutoChunkingStrategyResponse(document.RootElement); + } + + /// Convert into a . + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreAutoChunkingStrategyResponse.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreAutoChunkingStrategyResponse.cs new file mode 100644 index 000000000000..17218eca2365 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreAutoChunkingStrategyResponse.cs @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// This is returned when the chunking strategy is unknown. Typically, this is because the file was indexed before the chunking_strategy concept was introduced in the API. + public partial class VectorStoreAutoChunkingStrategyResponse : VectorStoreChunkingStrategyResponse + { + /// Initializes a new instance of . + internal VectorStoreAutoChunkingStrategyResponse() + { + Type = VectorStoreChunkingStrategyResponseType.Other; + } + + /// Initializes a new instance of . + /// The object type. + /// Keeps track of any properties unknown to the library. + internal VectorStoreAutoChunkingStrategyResponse(VectorStoreChunkingStrategyResponseType type, IDictionary serializedAdditionalRawData) : base(type, serializedAdditionalRawData) + { + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreChunkingStrategyRequest.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreChunkingStrategyRequest.Serialization.cs new file mode 100644 index 000000000000..d8709afaf21c --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreChunkingStrategyRequest.Serialization.cs @@ -0,0 +1,134 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + [PersistableModelProxy(typeof(UnknownVectorStoreChunkingStrategyRequest))] + public partial class VectorStoreChunkingStrategyRequest : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(VectorStoreChunkingStrategyRequest)} does not support writing '{format}' format."); + } + + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type.ToString()); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + VectorStoreChunkingStrategyRequest 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(VectorStoreChunkingStrategyRequest)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeVectorStoreChunkingStrategyRequest(document.RootElement, options); + } + + internal static VectorStoreChunkingStrategyRequest DeserializeVectorStoreChunkingStrategyRequest(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 "auto": return VectorStoreAutoChunkingStrategyRequest.DeserializeVectorStoreAutoChunkingStrategyRequest(element, options); + case "static": return VectorStoreStaticChunkingStrategyRequest.DeserializeVectorStoreStaticChunkingStrategyRequest(element, options); + } + } + return UnknownVectorStoreChunkingStrategyRequest.DeserializeUnknownVectorStoreChunkingStrategyRequest(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(VectorStoreChunkingStrategyRequest)} does not support writing '{options.Format}' format."); + } + } + + VectorStoreChunkingStrategyRequest 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeVectorStoreChunkingStrategyRequest(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(VectorStoreChunkingStrategyRequest)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static VectorStoreChunkingStrategyRequest FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeVectorStoreChunkingStrategyRequest(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreChunkingStrategyRequest.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreChunkingStrategyRequest.cs new file mode 100644 index 000000000000..5f64bb63f131 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreChunkingStrategyRequest.cs @@ -0,0 +1,69 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// + /// An abstract representation of a vector store chunking strategy configuration. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include and . + /// + public abstract partial class VectorStoreChunkingStrategyRequest + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private protected IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + protected VectorStoreChunkingStrategyRequest() + { + } + + /// Initializes a new instance of . + /// The object type. + /// Keeps track of any properties unknown to the library. + internal VectorStoreChunkingStrategyRequest(VectorStoreChunkingStrategyRequestType type, IDictionary serializedAdditionalRawData) + { + Type = type; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// The object type. + internal VectorStoreChunkingStrategyRequestType Type { get; set; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreChunkingStrategyRequestType.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreChunkingStrategyRequestType.cs new file mode 100644 index 000000000000..1b9a9691c970 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreChunkingStrategyRequestType.cs @@ -0,0 +1,51 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Type of chunking strategy. + internal readonly partial struct VectorStoreChunkingStrategyRequestType : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public VectorStoreChunkingStrategyRequestType(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string AutoValue = "auto"; + private const string StaticValue = "static"; + + /// auto. + public static VectorStoreChunkingStrategyRequestType Auto { get; } = new VectorStoreChunkingStrategyRequestType(AutoValue); + /// static. + public static VectorStoreChunkingStrategyRequestType Static { get; } = new VectorStoreChunkingStrategyRequestType(StaticValue); + /// Determines if two values are the same. + public static bool operator ==(VectorStoreChunkingStrategyRequestType left, VectorStoreChunkingStrategyRequestType right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(VectorStoreChunkingStrategyRequestType left, VectorStoreChunkingStrategyRequestType right) => !left.Equals(right); + /// Converts a to a . + public static implicit operator VectorStoreChunkingStrategyRequestType(string value) => new VectorStoreChunkingStrategyRequestType(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is VectorStoreChunkingStrategyRequestType other && Equals(other); + /// + public bool Equals(VectorStoreChunkingStrategyRequestType 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/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreChunkingStrategyResponse.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreChunkingStrategyResponse.Serialization.cs new file mode 100644 index 000000000000..c7888938c540 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreChunkingStrategyResponse.Serialization.cs @@ -0,0 +1,134 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + [PersistableModelProxy(typeof(UnknownVectorStoreChunkingStrategyResponse))] + public partial class VectorStoreChunkingStrategyResponse : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(VectorStoreChunkingStrategyResponse)} does not support writing '{format}' format."); + } + + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type.ToString()); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + VectorStoreChunkingStrategyResponse 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(VectorStoreChunkingStrategyResponse)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeVectorStoreChunkingStrategyResponse(document.RootElement, options); + } + + internal static VectorStoreChunkingStrategyResponse DeserializeVectorStoreChunkingStrategyResponse(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 "other": return VectorStoreAutoChunkingStrategyResponse.DeserializeVectorStoreAutoChunkingStrategyResponse(element, options); + case "static": return VectorStoreStaticChunkingStrategyResponse.DeserializeVectorStoreStaticChunkingStrategyResponse(element, options); + } + } + return UnknownVectorStoreChunkingStrategyResponse.DeserializeUnknownVectorStoreChunkingStrategyResponse(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(VectorStoreChunkingStrategyResponse)} does not support writing '{options.Format}' format."); + } + } + + VectorStoreChunkingStrategyResponse 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeVectorStoreChunkingStrategyResponse(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(VectorStoreChunkingStrategyResponse)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static VectorStoreChunkingStrategyResponse FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeVectorStoreChunkingStrategyResponse(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreChunkingStrategyResponse.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreChunkingStrategyResponse.cs new file mode 100644 index 000000000000..a4e4bac4d2a8 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreChunkingStrategyResponse.cs @@ -0,0 +1,69 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// + /// An abstract representation of a vector store chunking strategy configuration. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include and . + /// + public abstract partial class VectorStoreChunkingStrategyResponse + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private protected IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + protected VectorStoreChunkingStrategyResponse() + { + } + + /// Initializes a new instance of . + /// The object type. + /// Keeps track of any properties unknown to the library. + internal VectorStoreChunkingStrategyResponse(VectorStoreChunkingStrategyResponseType type, IDictionary serializedAdditionalRawData) + { + Type = type; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// The object type. + internal VectorStoreChunkingStrategyResponseType Type { get; set; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreChunkingStrategyResponseType.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreChunkingStrategyResponseType.cs new file mode 100644 index 000000000000..8b4d6338955c --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreChunkingStrategyResponseType.cs @@ -0,0 +1,51 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Type of chunking strategy. + internal readonly partial struct VectorStoreChunkingStrategyResponseType : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public VectorStoreChunkingStrategyResponseType(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string OtherValue = "other"; + private const string StaticValue = "static"; + + /// other. + public static VectorStoreChunkingStrategyResponseType Other { get; } = new VectorStoreChunkingStrategyResponseType(OtherValue); + /// static. + public static VectorStoreChunkingStrategyResponseType Static { get; } = new VectorStoreChunkingStrategyResponseType(StaticValue); + /// Determines if two values are the same. + public static bool operator ==(VectorStoreChunkingStrategyResponseType left, VectorStoreChunkingStrategyResponseType right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(VectorStoreChunkingStrategyResponseType left, VectorStoreChunkingStrategyResponseType right) => !left.Equals(right); + /// Converts a to a . + public static implicit operator VectorStoreChunkingStrategyResponseType(string value) => new VectorStoreChunkingStrategyResponseType(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is VectorStoreChunkingStrategyResponseType other && Equals(other); + /// + public bool Equals(VectorStoreChunkingStrategyResponseType 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/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantFileDeletionStatus.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreDeletionStatus.Serialization.cs similarity index 64% rename from sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantFileDeletionStatus.Serialization.cs rename to sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreDeletionStatus.Serialization.cs index 99bae8e62025..eb4873d43644 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantFileDeletionStatus.Serialization.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreDeletionStatus.Serialization.cs @@ -13,11 +13,11 @@ namespace Azure.AI.OpenAI.Assistants { - internal partial class InternalAssistantFileDeletionStatus : IUtf8JsonSerializable, IJsonModel + public partial class VectorStoreDeletionStatus : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { writer.WriteStartObject(); JsonModelWriteCore(writer, options); @@ -28,10 +28,10 @@ void IJsonModel.Write(Utf8JsonWriter writer /// The client options for reading and writing models. protected virtual void JsonModelWriteCore(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(InternalAssistantFileDeletionStatus)} does not support writing '{format}' format."); + throw new FormatException($"The model {nameof(VectorStoreDeletionStatus)} does not support writing '{format}' format."); } writer.WritePropertyName("id"u8); @@ -57,19 +57,19 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit } } - InternalAssistantFileDeletionStatus IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + VectorStoreDeletionStatus 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(InternalAssistantFileDeletionStatus)} does not support reading '{format}' format."); + throw new FormatException($"The model {nameof(VectorStoreDeletionStatus)} does not support reading '{format}' format."); } using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeInternalAssistantFileDeletionStatus(document.RootElement, options); + return DeserializeVectorStoreDeletionStatus(document.RootElement, options); } - internal static InternalAssistantFileDeletionStatus DeserializeInternalAssistantFileDeletionStatus(JsonElement element, ModelReaderWriterOptions options = null) + internal static VectorStoreDeletionStatus DeserializeVectorStoreDeletionStatus(JsonElement element, ModelReaderWriterOptions options = null) { options ??= ModelSerializationExtensions.WireOptions; @@ -79,7 +79,7 @@ internal static InternalAssistantFileDeletionStatus DeserializeInternalAssistant } string id = default; bool deleted = default; - InternalAssistantFileDeletionStatusObject @object = default; + VectorStoreDeletionStatusObject @object = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) @@ -96,7 +96,7 @@ internal static InternalAssistantFileDeletionStatus DeserializeInternalAssistant } if (property.NameEquals("object"u8)) { - @object = new InternalAssistantFileDeletionStatusObject(property.Value.GetString()); + @object = new VectorStoreDeletionStatusObject(property.Value.GetString()); continue; } if (options.Format != "W") @@ -105,46 +105,46 @@ internal static InternalAssistantFileDeletionStatus DeserializeInternalAssistant } } serializedAdditionalRawData = rawDataDictionary; - return new InternalAssistantFileDeletionStatus(id, deleted, @object, serializedAdditionalRawData); + return new VectorStoreDeletionStatus(id, deleted, @object, 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(InternalAssistantFileDeletionStatus)} does not support writing '{options.Format}' format."); + throw new FormatException($"The model {nameof(VectorStoreDeletionStatus)} does not support writing '{options.Format}' format."); } } - InternalAssistantFileDeletionStatus IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + VectorStoreDeletionStatus 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, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeInternalAssistantFileDeletionStatus(document.RootElement, options); + return DeserializeVectorStoreDeletionStatus(document.RootElement, options); } default: - throw new FormatException($"The model {nameof(InternalAssistantFileDeletionStatus)} does not support reading '{options.Format}' format."); + throw new FormatException($"The model {nameof(VectorStoreDeletionStatus)} does not support reading '{options.Format}' format."); } } - string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; /// Deserializes the model from a raw response. /// The response to deserialize the model from. - internal static InternalAssistantFileDeletionStatus FromResponse(Response response) + internal static VectorStoreDeletionStatus FromResponse(Response response) { using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); - return DeserializeInternalAssistantFileDeletionStatus(document.RootElement); + return DeserializeVectorStoreDeletionStatus(document.RootElement); } /// Convert into a . diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantFileDeletionStatus.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreDeletionStatus.cs similarity index 71% rename from sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantFileDeletionStatus.cs rename to sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreDeletionStatus.cs index 1a91eb299ceb..959f2da309e7 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/InternalAssistantFileDeletionStatus.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreDeletionStatus.cs @@ -10,8 +10,8 @@ namespace Azure.AI.OpenAI.Assistants { - /// The status of an assistant file deletion operation. - internal partial class InternalAssistantFileDeletionStatus + /// Response object for deleting a vector store. + public partial class VectorStoreDeletionStatus { /// /// Keeps track of any properties unknown to the library. @@ -45,11 +45,11 @@ internal partial class InternalAssistantFileDeletionStatus /// private IDictionary _serializedAdditionalRawData; - /// Initializes a new instance of . + /// Initializes a new instance of . /// The ID of the resource specified for deletion. /// A value indicating whether deletion was successful. /// is null. - internal InternalAssistantFileDeletionStatus(string id, bool deleted) + internal VectorStoreDeletionStatus(string id, bool deleted) { Argument.AssertNotNull(id, nameof(id)); @@ -57,12 +57,12 @@ internal InternalAssistantFileDeletionStatus(string id, bool deleted) Deleted = deleted; } - /// Initializes a new instance of . + /// Initializes a new instance of . /// The ID of the resource specified for deletion. /// A value indicating whether deletion was successful. - /// The object type, which is always 'assistant.file.deleted'. + /// The object type, which is always 'vector_store.deleted'. /// Keeps track of any properties unknown to the library. - internal InternalAssistantFileDeletionStatus(string id, bool deleted, InternalAssistantFileDeletionStatusObject @object, IDictionary serializedAdditionalRawData) + internal VectorStoreDeletionStatus(string id, bool deleted, VectorStoreDeletionStatusObject @object, IDictionary serializedAdditionalRawData) { Id = id; Deleted = deleted; @@ -70,8 +70,8 @@ internal InternalAssistantFileDeletionStatus(string id, bool deleted, InternalAs _serializedAdditionalRawData = serializedAdditionalRawData; } - /// Initializes a new instance of for deserialization. - internal InternalAssistantFileDeletionStatus() + /// Initializes a new instance of for deserialization. + internal VectorStoreDeletionStatus() { } @@ -79,7 +79,7 @@ internal InternalAssistantFileDeletionStatus() public string Id { get; } /// A value indicating whether deletion was successful. public bool Deleted { get; } - /// The object type, which is always 'assistant.file.deleted'. - public InternalAssistantFileDeletionStatusObject Object { get; } = InternalAssistantFileDeletionStatusObject.AssistantFileDeleted; + /// The object type, which is always 'vector_store.deleted'. + public VectorStoreDeletionStatusObject Object { get; } = VectorStoreDeletionStatusObject.VectorStoreDeleted; } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreDeletionStatusObject.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreDeletionStatusObject.cs new file mode 100644 index 000000000000..240b13fab2c5 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreDeletionStatusObject.cs @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The VectorStoreDeletionStatus_object. + public readonly partial struct VectorStoreDeletionStatusObject : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public VectorStoreDeletionStatusObject(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string VectorStoreDeletedValue = "vector_store.deleted"; + + /// vector_store.deleted. + public static VectorStoreDeletionStatusObject VectorStoreDeleted { get; } = new VectorStoreDeletionStatusObject(VectorStoreDeletedValue); + /// Determines if two values are the same. + public static bool operator ==(VectorStoreDeletionStatusObject left, VectorStoreDeletionStatusObject right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(VectorStoreDeletionStatusObject left, VectorStoreDeletionStatusObject right) => !left.Equals(right); + /// Converts a to a . + public static implicit operator VectorStoreDeletionStatusObject(string value) => new VectorStoreDeletionStatusObject(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is VectorStoreDeletionStatusObject other && Equals(other); + /// + public bool Equals(VectorStoreDeletionStatusObject 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/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreExpirationPolicy.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreExpirationPolicy.Serialization.cs new file mode 100644 index 000000000000..c0be5ad35db4 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreExpirationPolicy.Serialization.cs @@ -0,0 +1,150 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class VectorStoreExpirationPolicy : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(VectorStoreExpirationPolicy)} does not support writing '{format}' format."); + } + + writer.WritePropertyName("anchor"u8); + writer.WriteStringValue(Anchor.ToString()); + writer.WritePropertyName("days"u8); + writer.WriteNumberValue(Days); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + VectorStoreExpirationPolicy 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(VectorStoreExpirationPolicy)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeVectorStoreExpirationPolicy(document.RootElement, options); + } + + internal static VectorStoreExpirationPolicy DeserializeVectorStoreExpirationPolicy(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + VectorStoreExpirationPolicyAnchor anchor = default; + int days = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("anchor"u8)) + { + anchor = new VectorStoreExpirationPolicyAnchor(property.Value.GetString()); + continue; + } + if (property.NameEquals("days"u8)) + { + days = property.Value.GetInt32(); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new VectorStoreExpirationPolicy(anchor, days, 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(VectorStoreExpirationPolicy)} does not support writing '{options.Format}' format."); + } + } + + VectorStoreExpirationPolicy 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeVectorStoreExpirationPolicy(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(VectorStoreExpirationPolicy)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static VectorStoreExpirationPolicy FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeVectorStoreExpirationPolicy(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreExpirationPolicy.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreExpirationPolicy.cs new file mode 100644 index 000000000000..345d82299d9d --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreExpirationPolicy.cs @@ -0,0 +1,78 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The expiration policy for a vector store. + public partial class VectorStoreExpirationPolicy + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + /// Anchor timestamp after which the expiration policy applies. Supported anchors: `last_active_at`. + /// The anchor timestamp after which the expiration policy applies. + public VectorStoreExpirationPolicy(VectorStoreExpirationPolicyAnchor anchor, int days) + { + Anchor = anchor; + Days = days; + } + + /// Initializes a new instance of . + /// Anchor timestamp after which the expiration policy applies. Supported anchors: `last_active_at`. + /// The anchor timestamp after which the expiration policy applies. + /// Keeps track of any properties unknown to the library. + internal VectorStoreExpirationPolicy(VectorStoreExpirationPolicyAnchor anchor, int days, IDictionary serializedAdditionalRawData) + { + Anchor = anchor; + Days = days; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal VectorStoreExpirationPolicy() + { + } + + /// Anchor timestamp after which the expiration policy applies. Supported anchors: `last_active_at`. + public VectorStoreExpirationPolicyAnchor Anchor { get; set; } + /// The anchor timestamp after which the expiration policy applies. + public int Days { get; set; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreExpirationPolicyAnchor.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreExpirationPolicyAnchor.cs new file mode 100644 index 000000000000..864a769e6b50 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreExpirationPolicyAnchor.cs @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Describes the relationship between the days and the expiration of this vector store. + public readonly partial struct VectorStoreExpirationPolicyAnchor : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public VectorStoreExpirationPolicyAnchor(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string LastActiveAtValue = "last_active_at"; + + /// The expiration policy is based on the last time the vector store was active. + public static VectorStoreExpirationPolicyAnchor LastActiveAt { get; } = new VectorStoreExpirationPolicyAnchor(LastActiveAtValue); + /// Determines if two values are the same. + public static bool operator ==(VectorStoreExpirationPolicyAnchor left, VectorStoreExpirationPolicyAnchor right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(VectorStoreExpirationPolicyAnchor left, VectorStoreExpirationPolicyAnchor right) => !left.Equals(right); + /// Converts a to a . + public static implicit operator VectorStoreExpirationPolicyAnchor(string value) => new VectorStoreExpirationPolicyAnchor(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is VectorStoreExpirationPolicyAnchor other && Equals(other); + /// + public bool Equals(VectorStoreExpirationPolicyAnchor 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/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreFile.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreFile.Serialization.cs new file mode 100644 index 000000000000..a2ce877adbc7 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreFile.Serialization.cs @@ -0,0 +1,219 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class VectorStoreFile : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(VectorStoreFile)} does not support writing '{format}' format."); + } + + writer.WritePropertyName("id"u8); + writer.WriteStringValue(Id); + writer.WritePropertyName("object"u8); + writer.WriteStringValue(Object.ToString()); + writer.WritePropertyName("usage_bytes"u8); + writer.WriteNumberValue(UsageBytes); + writer.WritePropertyName("created_at"u8); + writer.WriteNumberValue(CreatedAt, "U"); + writer.WritePropertyName("vector_store_id"u8); + writer.WriteStringValue(VectorStoreId); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(Status.ToString()); + if (LastError != null) + { + writer.WritePropertyName("last_error"u8); + writer.WriteObjectValue(LastError, options); + } + else + { + writer.WriteNull("last_error"); + } + writer.WritePropertyName("chunking_strategy"u8); + writer.WriteObjectValue(ChunkingStrategy, options); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + VectorStoreFile 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(VectorStoreFile)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeVectorStoreFile(document.RootElement, options); + } + + internal static VectorStoreFile DeserializeVectorStoreFile(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string id = default; + VectorStoreFileObject @object = default; + int usageBytes = default; + DateTimeOffset createdAt = default; + string vectorStoreId = default; + VectorStoreFileStatus status = default; + VectorStoreFileError lastError = default; + VectorStoreChunkingStrategyResponse chunkingStrategy = 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("object"u8)) + { + @object = new VectorStoreFileObject(property.Value.GetString()); + continue; + } + if (property.NameEquals("usage_bytes"u8)) + { + usageBytes = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("created_at"u8)) + { + createdAt = DateTimeOffset.FromUnixTimeSeconds(property.Value.GetInt64()); + continue; + } + if (property.NameEquals("vector_store_id"u8)) + { + vectorStoreId = property.Value.GetString(); + continue; + } + if (property.NameEquals("status"u8)) + { + status = new VectorStoreFileStatus(property.Value.GetString()); + continue; + } + if (property.NameEquals("last_error"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + lastError = null; + continue; + } + lastError = VectorStoreFileError.DeserializeVectorStoreFileError(property.Value, options); + continue; + } + if (property.NameEquals("chunking_strategy"u8)) + { + chunkingStrategy = VectorStoreChunkingStrategyResponse.DeserializeVectorStoreChunkingStrategyResponse(property.Value, options); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new VectorStoreFile( + id, + @object, + usageBytes, + createdAt, + vectorStoreId, + status, + lastError, + chunkingStrategy, + 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(VectorStoreFile)} does not support writing '{options.Format}' format."); + } + } + + VectorStoreFile 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeVectorStoreFile(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(VectorStoreFile)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static VectorStoreFile FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeVectorStoreFile(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreFile.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreFile.cs new file mode 100644 index 000000000000..d7c12dbf07d8 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreFile.cs @@ -0,0 +1,139 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Description of a file attached to a vector store. + public partial class VectorStoreFile + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + /// The identifier, which can be referenced in API endpoints. + /// + /// The total vector store usage in bytes. Note that this may be different from the original file + /// size. + /// + /// The Unix timestamp (in seconds) for when the vector store file was created. + /// The ID of the vector store that the file is attached to. + /// The status of the vector store file, which can be either `in_progress`, `completed`, `cancelled`, or `failed`. The status `completed` indicates that the vector store file is ready for use. + /// The last error associated with this vector store file. Will be `null` if there are no errors. + /// + /// The strategy used to chunk the file. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include and . + /// + /// , or is null. + internal VectorStoreFile(string id, int usageBytes, DateTimeOffset createdAt, string vectorStoreId, VectorStoreFileStatus status, VectorStoreFileError lastError, VectorStoreChunkingStrategyResponse chunkingStrategy) + { + Argument.AssertNotNull(id, nameof(id)); + Argument.AssertNotNull(vectorStoreId, nameof(vectorStoreId)); + Argument.AssertNotNull(chunkingStrategy, nameof(chunkingStrategy)); + + Id = id; + UsageBytes = usageBytes; + CreatedAt = createdAt; + VectorStoreId = vectorStoreId; + Status = status; + LastError = lastError; + ChunkingStrategy = chunkingStrategy; + } + + /// Initializes a new instance of . + /// The identifier, which can be referenced in API endpoints. + /// The object type, which is always `vector_store.file`. + /// + /// The total vector store usage in bytes. Note that this may be different from the original file + /// size. + /// + /// The Unix timestamp (in seconds) for when the vector store file was created. + /// The ID of the vector store that the file is attached to. + /// The status of the vector store file, which can be either `in_progress`, `completed`, `cancelled`, or `failed`. The status `completed` indicates that the vector store file is ready for use. + /// The last error associated with this vector store file. Will be `null` if there are no errors. + /// + /// The strategy used to chunk the file. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include and . + /// + /// Keeps track of any properties unknown to the library. + internal VectorStoreFile(string id, VectorStoreFileObject @object, int usageBytes, DateTimeOffset createdAt, string vectorStoreId, VectorStoreFileStatus status, VectorStoreFileError lastError, VectorStoreChunkingStrategyResponse chunkingStrategy, IDictionary serializedAdditionalRawData) + { + Id = id; + Object = @object; + UsageBytes = usageBytes; + CreatedAt = createdAt; + VectorStoreId = vectorStoreId; + Status = status; + LastError = lastError; + ChunkingStrategy = chunkingStrategy; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal VectorStoreFile() + { + } + + /// The identifier, which can be referenced in API endpoints. + public string Id { get; } + /// The object type, which is always `vector_store.file`. + public VectorStoreFileObject Object { get; } = VectorStoreFileObject.VectorStoreFile; + + /// + /// The total vector store usage in bytes. Note that this may be different from the original file + /// size. + /// + public int UsageBytes { get; } + /// The Unix timestamp (in seconds) for when the vector store file was created. + public DateTimeOffset CreatedAt { get; } + /// The ID of the vector store that the file is attached to. + public string VectorStoreId { get; } + /// The status of the vector store file, which can be either `in_progress`, `completed`, `cancelled`, or `failed`. The status `completed` indicates that the vector store file is ready for use. + public VectorStoreFileStatus Status { get; } + /// The last error associated with this vector store file. Will be `null` if there are no errors. + public VectorStoreFileError LastError { get; } + /// + /// The strategy used to chunk the file. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include and . + /// + public VectorStoreChunkingStrategyResponse ChunkingStrategy { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreFileBatch.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreFileBatch.Serialization.cs new file mode 100644 index 000000000000..76745044dfb1 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreFileBatch.Serialization.cs @@ -0,0 +1,189 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class VectorStoreFileBatch : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(VectorStoreFileBatch)} does not support writing '{format}' format."); + } + + writer.WritePropertyName("id"u8); + writer.WriteStringValue(Id); + writer.WritePropertyName("object"u8); + writer.WriteStringValue(Object.ToString()); + writer.WritePropertyName("created_at"u8); + writer.WriteNumberValue(CreatedAt, "U"); + writer.WritePropertyName("vector_store_id"u8); + writer.WriteStringValue(VectorStoreId); + writer.WritePropertyName("status"u8); + writer.WriteStringValue(Status.ToString()); + writer.WritePropertyName("file_counts"u8); + writer.WriteObjectValue(FileCounts, options); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + VectorStoreFileBatch 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(VectorStoreFileBatch)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeVectorStoreFileBatch(document.RootElement, options); + } + + internal static VectorStoreFileBatch DeserializeVectorStoreFileBatch(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string id = default; + VectorStoreFileBatchObject @object = default; + DateTimeOffset createdAt = default; + string vectorStoreId = default; + VectorStoreFileBatchStatus status = default; + VectorStoreFileCount fileCounts = 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("object"u8)) + { + @object = new VectorStoreFileBatchObject(property.Value.GetString()); + continue; + } + if (property.NameEquals("created_at"u8)) + { + createdAt = DateTimeOffset.FromUnixTimeSeconds(property.Value.GetInt64()); + continue; + } + if (property.NameEquals("vector_store_id"u8)) + { + vectorStoreId = property.Value.GetString(); + continue; + } + if (property.NameEquals("status"u8)) + { + status = new VectorStoreFileBatchStatus(property.Value.GetString()); + continue; + } + if (property.NameEquals("file_counts"u8)) + { + fileCounts = VectorStoreFileCount.DeserializeVectorStoreFileCount(property.Value, options); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new VectorStoreFileBatch( + id, + @object, + createdAt, + vectorStoreId, + status, + fileCounts, + 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(VectorStoreFileBatch)} does not support writing '{options.Format}' format."); + } + } + + VectorStoreFileBatch 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeVectorStoreFileBatch(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(VectorStoreFileBatch)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static VectorStoreFileBatch FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeVectorStoreFileBatch(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreFileBatch.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreFileBatch.cs new file mode 100644 index 000000000000..898dd2ab2b55 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreFileBatch.cs @@ -0,0 +1,106 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// A batch of files attached to a vector store. + public partial class VectorStoreFileBatch + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + /// The identifier, which can be referenced in API endpoints. + /// The Unix timestamp (in seconds) for when the vector store files batch was created. + /// The ID of the vector store that the file is attached to. + /// The status of the vector store files batch, which can be either `in_progress`, `completed`, `cancelled` or `failed`. + /// Files count grouped by status processed or being processed by this vector store. + /// , or is null. + internal VectorStoreFileBatch(string id, DateTimeOffset createdAt, string vectorStoreId, VectorStoreFileBatchStatus status, VectorStoreFileCount fileCounts) + { + Argument.AssertNotNull(id, nameof(id)); + Argument.AssertNotNull(vectorStoreId, nameof(vectorStoreId)); + Argument.AssertNotNull(fileCounts, nameof(fileCounts)); + + Id = id; + CreatedAt = createdAt; + VectorStoreId = vectorStoreId; + Status = status; + FileCounts = fileCounts; + } + + /// Initializes a new instance of . + /// The identifier, which can be referenced in API endpoints. + /// The object type, which is always `vector_store.file_batch`. + /// The Unix timestamp (in seconds) for when the vector store files batch was created. + /// The ID of the vector store that the file is attached to. + /// The status of the vector store files batch, which can be either `in_progress`, `completed`, `cancelled` or `failed`. + /// Files count grouped by status processed or being processed by this vector store. + /// Keeps track of any properties unknown to the library. + internal VectorStoreFileBatch(string id, VectorStoreFileBatchObject @object, DateTimeOffset createdAt, string vectorStoreId, VectorStoreFileBatchStatus status, VectorStoreFileCount fileCounts, IDictionary serializedAdditionalRawData) + { + Id = id; + Object = @object; + CreatedAt = createdAt; + VectorStoreId = vectorStoreId; + Status = status; + FileCounts = fileCounts; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal VectorStoreFileBatch() + { + } + + /// The identifier, which can be referenced in API endpoints. + public string Id { get; } + /// The object type, which is always `vector_store.file_batch`. + public VectorStoreFileBatchObject Object { get; } = VectorStoreFileBatchObject.VectorStoreFilesBatch; + + /// The Unix timestamp (in seconds) for when the vector store files batch was created. + public DateTimeOffset CreatedAt { get; } + /// The ID of the vector store that the file is attached to. + public string VectorStoreId { get; } + /// The status of the vector store files batch, which can be either `in_progress`, `completed`, `cancelled` or `failed`. + public VectorStoreFileBatchStatus Status { get; } + /// Files count grouped by status processed or being processed by this vector store. + public VectorStoreFileCount FileCounts { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreFileBatchObject.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreFileBatchObject.cs new file mode 100644 index 000000000000..ff607d482dfa --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreFileBatchObject.cs @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The VectorStoreFileBatch_object. + public readonly partial struct VectorStoreFileBatchObject : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public VectorStoreFileBatchObject(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string VectorStoreFilesBatchValue = "vector_store.files_batch"; + + /// vector_store.files_batch. + public static VectorStoreFileBatchObject VectorStoreFilesBatch { get; } = new VectorStoreFileBatchObject(VectorStoreFilesBatchValue); + /// Determines if two values are the same. + public static bool operator ==(VectorStoreFileBatchObject left, VectorStoreFileBatchObject right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(VectorStoreFileBatchObject left, VectorStoreFileBatchObject right) => !left.Equals(right); + /// Converts a to a . + public static implicit operator VectorStoreFileBatchObject(string value) => new VectorStoreFileBatchObject(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is VectorStoreFileBatchObject other && Equals(other); + /// + public bool Equals(VectorStoreFileBatchObject 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/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreFileBatchStatus.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreFileBatchStatus.cs new file mode 100644 index 000000000000..79d886ab6ccd --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreFileBatchStatus.cs @@ -0,0 +1,57 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The status of the vector store file batch. + public readonly partial struct VectorStoreFileBatchStatus : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public VectorStoreFileBatchStatus(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string InProgressValue = "in_progress"; + private const string CompletedValue = "completed"; + private const string CancelledValue = "cancelled"; + private const string FailedValue = "failed"; + + /// The vector store is still processing this file batch. + public static VectorStoreFileBatchStatus InProgress { get; } = new VectorStoreFileBatchStatus(InProgressValue); + /// the vector store file batch is ready for use. + public static VectorStoreFileBatchStatus Completed { get; } = new VectorStoreFileBatchStatus(CompletedValue); + /// The vector store file batch was cancelled. + public static VectorStoreFileBatchStatus Cancelled { get; } = new VectorStoreFileBatchStatus(CancelledValue); + /// The vector store file batch failed to process. + public static VectorStoreFileBatchStatus Failed { get; } = new VectorStoreFileBatchStatus(FailedValue); + /// Determines if two values are the same. + public static bool operator ==(VectorStoreFileBatchStatus left, VectorStoreFileBatchStatus right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(VectorStoreFileBatchStatus left, VectorStoreFileBatchStatus right) => !left.Equals(right); + /// Converts a to a . + public static implicit operator VectorStoreFileBatchStatus(string value) => new VectorStoreFileBatchStatus(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is VectorStoreFileBatchStatus other && Equals(other); + /// + public bool Equals(VectorStoreFileBatchStatus 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/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreFileCount.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreFileCount.Serialization.cs new file mode 100644 index 000000000000..5aabbfa099b3 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreFileCount.Serialization.cs @@ -0,0 +1,180 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class VectorStoreFileCount : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(VectorStoreFileCount)} does not support writing '{format}' format."); + } + + writer.WritePropertyName("in_progress"u8); + writer.WriteNumberValue(InProgress); + writer.WritePropertyName("completed"u8); + writer.WriteNumberValue(Completed); + writer.WritePropertyName("failed"u8); + writer.WriteNumberValue(Failed); + writer.WritePropertyName("cancelled"u8); + writer.WriteNumberValue(Cancelled); + writer.WritePropertyName("total"u8); + writer.WriteNumberValue(Total); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + VectorStoreFileCount 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(VectorStoreFileCount)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeVectorStoreFileCount(document.RootElement, options); + } + + internal static VectorStoreFileCount DeserializeVectorStoreFileCount(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + int inProgress = default; + int completed = default; + int failed = default; + int cancelled = default; + int total = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("in_progress"u8)) + { + inProgress = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("completed"u8)) + { + completed = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("failed"u8)) + { + failed = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("cancelled"u8)) + { + cancelled = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("total"u8)) + { + total = property.Value.GetInt32(); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new VectorStoreFileCount( + inProgress, + completed, + failed, + cancelled, + total, + 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(VectorStoreFileCount)} does not support writing '{options.Format}' format."); + } + } + + VectorStoreFileCount 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeVectorStoreFileCount(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(VectorStoreFileCount)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static VectorStoreFileCount FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeVectorStoreFileCount(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreFileCount.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreFileCount.cs new file mode 100644 index 000000000000..a4fe9273bff4 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreFileCount.cs @@ -0,0 +1,96 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Counts of files processed or being processed by this vector store grouped by status. + public partial class VectorStoreFileCount + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + /// The number of files that are currently being processed. + /// The number of files that have been successfully processed. + /// The number of files that have failed to process. + /// The number of files that were cancelled. + /// The total number of files. + internal VectorStoreFileCount(int inProgress, int completed, int failed, int cancelled, int total) + { + InProgress = inProgress; + Completed = completed; + Failed = failed; + Cancelled = cancelled; + Total = total; + } + + /// Initializes a new instance of . + /// The number of files that are currently being processed. + /// The number of files that have been successfully processed. + /// The number of files that have failed to process. + /// The number of files that were cancelled. + /// The total number of files. + /// Keeps track of any properties unknown to the library. + internal VectorStoreFileCount(int inProgress, int completed, int failed, int cancelled, int total, IDictionary serializedAdditionalRawData) + { + InProgress = inProgress; + Completed = completed; + Failed = failed; + Cancelled = cancelled; + Total = total; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal VectorStoreFileCount() + { + } + + /// The number of files that are currently being processed. + public int InProgress { get; } + /// The number of files that have been successfully processed. + public int Completed { get; } + /// The number of files that have failed to process. + public int Failed { get; } + /// The number of files that were cancelled. + public int Cancelled { get; } + /// The total number of files. + public int Total { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreFileDeletionStatus.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreFileDeletionStatus.Serialization.cs new file mode 100644 index 000000000000..ec1a3c42e1dc --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreFileDeletionStatus.Serialization.cs @@ -0,0 +1,158 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class VectorStoreFileDeletionStatus : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(VectorStoreFileDeletionStatus)} does not support writing '{format}' format."); + } + + writer.WritePropertyName("id"u8); + writer.WriteStringValue(Id); + writer.WritePropertyName("deleted"u8); + writer.WriteBooleanValue(Deleted); + writer.WritePropertyName("object"u8); + writer.WriteStringValue(Object.ToString()); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + VectorStoreFileDeletionStatus 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(VectorStoreFileDeletionStatus)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeVectorStoreFileDeletionStatus(document.RootElement, options); + } + + internal static VectorStoreFileDeletionStatus DeserializeVectorStoreFileDeletionStatus(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string id = default; + bool deleted = default; + VectorStoreFileDeletionStatusObject @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("deleted"u8)) + { + deleted = property.Value.GetBoolean(); + continue; + } + if (property.NameEquals("object"u8)) + { + @object = new VectorStoreFileDeletionStatusObject(property.Value.GetString()); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new VectorStoreFileDeletionStatus(id, deleted, @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(VectorStoreFileDeletionStatus)} does not support writing '{options.Format}' format."); + } + } + + VectorStoreFileDeletionStatus 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeVectorStoreFileDeletionStatus(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(VectorStoreFileDeletionStatus)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static VectorStoreFileDeletionStatus FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeVectorStoreFileDeletionStatus(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreFileDeletionStatus.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreFileDeletionStatus.cs new file mode 100644 index 000000000000..009e5942a8ac --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreFileDeletionStatus.cs @@ -0,0 +1,85 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Response object for deleting a vector store file relationship. + public partial class VectorStoreFileDeletionStatus + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + /// The ID of the resource specified for deletion. + /// A value indicating whether deletion was successful. + /// is null. + internal VectorStoreFileDeletionStatus(string id, bool deleted) + { + Argument.AssertNotNull(id, nameof(id)); + + Id = id; + Deleted = deleted; + } + + /// Initializes a new instance of . + /// The ID of the resource specified for deletion. + /// A value indicating whether deletion was successful. + /// The object type, which is always 'vector_store.deleted'. + /// Keeps track of any properties unknown to the library. + internal VectorStoreFileDeletionStatus(string id, bool deleted, VectorStoreFileDeletionStatusObject @object, IDictionary serializedAdditionalRawData) + { + Id = id; + Deleted = deleted; + Object = @object; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal VectorStoreFileDeletionStatus() + { + } + + /// The ID of the resource specified for deletion. + public string Id { get; } + /// A value indicating whether deletion was successful. + public bool Deleted { get; } + /// The object type, which is always 'vector_store.deleted'. + public VectorStoreFileDeletionStatusObject Object { get; } = VectorStoreFileDeletionStatusObject.VectorStoreFileDeleted; + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreFileDeletionStatusObject.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreFileDeletionStatusObject.cs new file mode 100644 index 000000000000..ebd2a6f4d22f --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreFileDeletionStatusObject.cs @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The VectorStoreFileDeletionStatus_object. + public readonly partial struct VectorStoreFileDeletionStatusObject : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public VectorStoreFileDeletionStatusObject(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string VectorStoreFileDeletedValue = "vector_store.file.deleted"; + + /// vector_store.file.deleted. + public static VectorStoreFileDeletionStatusObject VectorStoreFileDeleted { get; } = new VectorStoreFileDeletionStatusObject(VectorStoreFileDeletedValue); + /// Determines if two values are the same. + public static bool operator ==(VectorStoreFileDeletionStatusObject left, VectorStoreFileDeletionStatusObject right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(VectorStoreFileDeletionStatusObject left, VectorStoreFileDeletionStatusObject right) => !left.Equals(right); + /// Converts a to a . + public static implicit operator VectorStoreFileDeletionStatusObject(string value) => new VectorStoreFileDeletionStatusObject(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is VectorStoreFileDeletionStatusObject other && Equals(other); + /// + public bool Equals(VectorStoreFileDeletionStatusObject 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/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreFileError.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreFileError.Serialization.cs new file mode 100644 index 000000000000..daf2ec2550de --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreFileError.Serialization.cs @@ -0,0 +1,150 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class VectorStoreFileError : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(VectorStoreFileError)} does not support writing '{format}' format."); + } + + writer.WritePropertyName("code"u8); + writer.WriteStringValue(Code.ToString()); + writer.WritePropertyName("message"u8); + writer.WriteStringValue(Message); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + VectorStoreFileError 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(VectorStoreFileError)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeVectorStoreFileError(document.RootElement, options); + } + + internal static VectorStoreFileError DeserializeVectorStoreFileError(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + VectorStoreFileErrorCode code = default; + string message = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("code"u8)) + { + code = new VectorStoreFileErrorCode(property.Value.GetString()); + continue; + } + if (property.NameEquals("message"u8)) + { + message = property.Value.GetString(); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new VectorStoreFileError(code, message, 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(VectorStoreFileError)} does not support writing '{options.Format}' format."); + } + } + + VectorStoreFileError 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeVectorStoreFileError(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(VectorStoreFileError)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static VectorStoreFileError FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeVectorStoreFileError(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreFileError.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreFileError.cs new file mode 100644 index 000000000000..5c96944e5f8e --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreFileError.cs @@ -0,0 +1,81 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Details on the error that may have ocurred while processing a file for this vector store. + public partial class VectorStoreFileError + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + /// One of `server_error` or `rate_limit_exceeded`. + /// A human-readable description of the error. + /// is null. + internal VectorStoreFileError(VectorStoreFileErrorCode code, string message) + { + Argument.AssertNotNull(message, nameof(message)); + + Code = code; + Message = message; + } + + /// Initializes a new instance of . + /// One of `server_error` or `rate_limit_exceeded`. + /// A human-readable description of the error. + /// Keeps track of any properties unknown to the library. + internal VectorStoreFileError(VectorStoreFileErrorCode code, string message, IDictionary serializedAdditionalRawData) + { + Code = code; + Message = message; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal VectorStoreFileError() + { + } + + /// One of `server_error` or `rate_limit_exceeded`. + public VectorStoreFileErrorCode Code { get; } + /// A human-readable description of the error. + public string Message { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreFileErrorCode.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreFileErrorCode.cs new file mode 100644 index 000000000000..62944f11529e --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreFileErrorCode.cs @@ -0,0 +1,54 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Error code variants for vector store file processing. + public readonly partial struct VectorStoreFileErrorCode : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public VectorStoreFileErrorCode(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string ServerErrorValue = "server_error"; + private const string UnsupportedFileValue = "unsupported_file"; + private const string InvalidFileValue = "invalid_file"; + + /// The server encountered an error. + public static VectorStoreFileErrorCode ServerError { get; } = new VectorStoreFileErrorCode(ServerErrorValue); + /// The file format is not supported. + public static VectorStoreFileErrorCode UnsupportedFile { get; } = new VectorStoreFileErrorCode(UnsupportedFileValue); + /// The file is invalid. + public static VectorStoreFileErrorCode InvalidFile { get; } = new VectorStoreFileErrorCode(InvalidFileValue); + /// Determines if two values are the same. + public static bool operator ==(VectorStoreFileErrorCode left, VectorStoreFileErrorCode right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(VectorStoreFileErrorCode left, VectorStoreFileErrorCode right) => !left.Equals(right); + /// Converts a to a . + public static implicit operator VectorStoreFileErrorCode(string value) => new VectorStoreFileErrorCode(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is VectorStoreFileErrorCode other && Equals(other); + /// + public bool Equals(VectorStoreFileErrorCode 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/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreFileObject.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreFileObject.cs new file mode 100644 index 000000000000..f4d205e40ce2 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreFileObject.cs @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The VectorStoreFile_object. + public readonly partial struct VectorStoreFileObject : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public VectorStoreFileObject(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string VectorStoreFileValue = "vector_store.file"; + + /// vector_store.file. + public static VectorStoreFileObject VectorStoreFile { get; } = new VectorStoreFileObject(VectorStoreFileValue); + /// Determines if two values are the same. + public static bool operator ==(VectorStoreFileObject left, VectorStoreFileObject right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(VectorStoreFileObject left, VectorStoreFileObject right) => !left.Equals(right); + /// Converts a to a . + public static implicit operator VectorStoreFileObject(string value) => new VectorStoreFileObject(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is VectorStoreFileObject other && Equals(other); + /// + public bool Equals(VectorStoreFileObject 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/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreFileStatus.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreFileStatus.cs new file mode 100644 index 000000000000..62c5dc3711e8 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreFileStatus.cs @@ -0,0 +1,57 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Vector store file status. + public readonly partial struct VectorStoreFileStatus : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public VectorStoreFileStatus(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string InProgressValue = "in_progress"; + private const string CompletedValue = "completed"; + private const string FailedValue = "failed"; + private const string CancelledValue = "cancelled"; + + /// The file is currently being processed. + public static VectorStoreFileStatus InProgress { get; } = new VectorStoreFileStatus(InProgressValue); + /// The file has been successfully processed. + public static VectorStoreFileStatus Completed { get; } = new VectorStoreFileStatus(CompletedValue); + /// The file has failed to process. + public static VectorStoreFileStatus Failed { get; } = new VectorStoreFileStatus(FailedValue); + /// The file was cancelled. + public static VectorStoreFileStatus Cancelled { get; } = new VectorStoreFileStatus(CancelledValue); + /// Determines if two values are the same. + public static bool operator ==(VectorStoreFileStatus left, VectorStoreFileStatus right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(VectorStoreFileStatus left, VectorStoreFileStatus right) => !left.Equals(right); + /// Converts a to a . + public static implicit operator VectorStoreFileStatus(string value) => new VectorStoreFileStatus(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is VectorStoreFileStatus other && Equals(other); + /// + public bool Equals(VectorStoreFileStatus 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/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreFileStatusFilter.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreFileStatusFilter.cs new file mode 100644 index 000000000000..cd796f8cae2a --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreFileStatusFilter.cs @@ -0,0 +1,57 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Query parameter filter for vector store file retrieval endpoint. + public readonly partial struct VectorStoreFileStatusFilter : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public VectorStoreFileStatusFilter(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string InProgressValue = "in_progress"; + private const string CompletedValue = "completed"; + private const string FailedValue = "failed"; + private const string CancelledValue = "cancelled"; + + /// Retrieve only files that are currently being processed. + public static VectorStoreFileStatusFilter InProgress { get; } = new VectorStoreFileStatusFilter(InProgressValue); + /// Retrieve only files that have been successfully processed. + public static VectorStoreFileStatusFilter Completed { get; } = new VectorStoreFileStatusFilter(CompletedValue); + /// Retrieve only files that have failed to process. + public static VectorStoreFileStatusFilter Failed { get; } = new VectorStoreFileStatusFilter(FailedValue); + /// Retrieve only files that were cancelled. + public static VectorStoreFileStatusFilter Cancelled { get; } = new VectorStoreFileStatusFilter(CancelledValue); + /// Determines if two values are the same. + public static bool operator ==(VectorStoreFileStatusFilter left, VectorStoreFileStatusFilter right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(VectorStoreFileStatusFilter left, VectorStoreFileStatusFilter right) => !left.Equals(right); + /// Converts a to a . + public static implicit operator VectorStoreFileStatusFilter(string value) => new VectorStoreFileStatusFilter(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is VectorStoreFileStatusFilter other && Equals(other); + /// + public bool Equals(VectorStoreFileStatusFilter 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/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreObject.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreObject.cs new file mode 100644 index 000000000000..abbc8b915139 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreObject.cs @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.OpenAI.Assistants +{ + /// The VectorStore_object. + public readonly partial struct VectorStoreObject : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public VectorStoreObject(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string VectorStoreValue = "vector_store"; + + /// vector_store. + public static VectorStoreObject VectorStore { get; } = new VectorStoreObject(VectorStoreValue); + /// Determines if two values are the same. + public static bool operator ==(VectorStoreObject left, VectorStoreObject right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(VectorStoreObject left, VectorStoreObject right) => !left.Equals(right); + /// Converts a to a . + public static implicit operator VectorStoreObject(string value) => new VectorStoreObject(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is VectorStoreObject other && Equals(other); + /// + public bool Equals(VectorStoreObject 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/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreOptions.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreOptions.Serialization.cs new file mode 100644 index 000000000000..31572f50309a --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreOptions.Serialization.cs @@ -0,0 +1,239 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class VectorStoreOptions : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(VectorStoreOptions)} does not support writing '{format}' format."); + } + + if (Optional.IsCollectionDefined(FileIds)) + { + writer.WritePropertyName("file_ids"u8); + writer.WriteStartArray(); + foreach (var item in FileIds) + { + writer.WriteStringValue(item); + } + writer.WriteEndArray(); + } + if (Optional.IsDefined(Name)) + { + writer.WritePropertyName("name"u8); + writer.WriteStringValue(Name); + } + if (Optional.IsDefined(ExpiresAfter)) + { + writer.WritePropertyName("expires_after"u8); + writer.WriteObjectValue(ExpiresAfter, options); + } + if (Optional.IsDefined(ChunkingStrategy)) + { + writer.WritePropertyName("chunking_strategy"u8); + writer.WriteObjectValue(ChunkingStrategy, options); + } + if (Optional.IsCollectionDefined(Metadata)) + { + if (Metadata != null) + { + writer.WritePropertyName("metadata"u8); + writer.WriteStartObject(); + foreach (var item in Metadata) + { + writer.WritePropertyName(item.Key); + writer.WriteStringValue(item.Value); + } + writer.WriteEndObject(); + } + else + { + writer.WriteNull("metadata"); + } + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + VectorStoreOptions 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(VectorStoreOptions)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeVectorStoreOptions(document.RootElement, options); + } + + internal static VectorStoreOptions DeserializeVectorStoreOptions(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + IList fileIds = default; + string name = default; + VectorStoreExpirationPolicy expiresAfter = default; + VectorStoreChunkingStrategyRequest chunkingStrategy = 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("name"u8)) + { + name = property.Value.GetString(); + continue; + } + if (property.NameEquals("expires_after"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + expiresAfter = VectorStoreExpirationPolicy.DeserializeVectorStoreExpirationPolicy(property.Value, options); + continue; + } + if (property.NameEquals("chunking_strategy"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + chunkingStrategy = VectorStoreChunkingStrategyRequest.DeserializeVectorStoreChunkingStrategyRequest(property.Value, options); + 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 (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new VectorStoreOptions( + fileIds ?? new ChangeTrackingList(), + name, + expiresAfter, + chunkingStrategy, + 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(VectorStoreOptions)} does not support writing '{options.Format}' format."); + } + } + + VectorStoreOptions 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeVectorStoreOptions(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(VectorStoreOptions)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static VectorStoreOptions FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeVectorStoreOptions(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreOptions.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreOptions.cs new file mode 100644 index 000000000000..2aa8bd2f3858 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreOptions.cs @@ -0,0 +1,91 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Request object for creating a vector store. + public partial class VectorStoreOptions + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + public VectorStoreOptions() + { + FileIds = new ChangeTrackingList(); + Metadata = new ChangeTrackingDictionary(); + } + + /// Initializes a new instance of . + /// A list of file IDs that the vector store should use. Useful for tools like `file_search` that can access files. + /// The name of the vector store. + /// Details on when this vector store expires. + /// + /// The chunking strategy used to chunk the file(s). If not set, will use the auto strategy. Only applicable if file_ids is non-empty. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include and . + /// + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + /// Keeps track of any properties unknown to the library. + internal VectorStoreOptions(IList fileIds, string name, VectorStoreExpirationPolicy expiresAfter, VectorStoreChunkingStrategyRequest chunkingStrategy, IDictionary metadata, IDictionary serializedAdditionalRawData) + { + FileIds = fileIds; + Name = name; + ExpiresAfter = expiresAfter; + ChunkingStrategy = chunkingStrategy; + Metadata = metadata; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// A list of file IDs that the vector store should use. Useful for tools like `file_search` that can access files. + public IList FileIds { get; } + /// The name of the vector store. + public string Name { get; set; } + /// Details on when this vector store expires. + public VectorStoreExpirationPolicy ExpiresAfter { get; set; } + /// + /// The chunking strategy used to chunk the file(s). If not set, will use the auto strategy. Only applicable if file_ids is non-empty. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include and . + /// + public VectorStoreChunkingStrategyRequest ChunkingStrategy { get; set; } + /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. + public IDictionary Metadata { get; set; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreStaticChunkingStrategyOptions.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreStaticChunkingStrategyOptions.Serialization.cs new file mode 100644 index 000000000000..21b248f546ff --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreStaticChunkingStrategyOptions.Serialization.cs @@ -0,0 +1,150 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class VectorStoreStaticChunkingStrategyOptions : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(VectorStoreStaticChunkingStrategyOptions)} does not support writing '{format}' format."); + } + + writer.WritePropertyName("max_chunk_size_tokens"u8); + writer.WriteNumberValue(MaxChunkSizeTokens); + writer.WritePropertyName("chunk_overlap_tokens"u8); + writer.WriteNumberValue(ChunkOverlapTokens); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + VectorStoreStaticChunkingStrategyOptions 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(VectorStoreStaticChunkingStrategyOptions)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeVectorStoreStaticChunkingStrategyOptions(document.RootElement, options); + } + + internal static VectorStoreStaticChunkingStrategyOptions DeserializeVectorStoreStaticChunkingStrategyOptions(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + int maxChunkSizeTokens = default; + int chunkOverlapTokens = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("max_chunk_size_tokens"u8)) + { + maxChunkSizeTokens = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("chunk_overlap_tokens"u8)) + { + chunkOverlapTokens = property.Value.GetInt32(); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new VectorStoreStaticChunkingStrategyOptions(maxChunkSizeTokens, chunkOverlapTokens, 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(VectorStoreStaticChunkingStrategyOptions)} does not support writing '{options.Format}' format."); + } + } + + VectorStoreStaticChunkingStrategyOptions 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeVectorStoreStaticChunkingStrategyOptions(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(VectorStoreStaticChunkingStrategyOptions)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static VectorStoreStaticChunkingStrategyOptions FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeVectorStoreStaticChunkingStrategyOptions(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreStaticChunkingStrategyOptions.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreStaticChunkingStrategyOptions.cs new file mode 100644 index 000000000000..38db6670abf3 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreStaticChunkingStrategyOptions.cs @@ -0,0 +1,87 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Options to configure a vector store static chunking strategy. + public partial class VectorStoreStaticChunkingStrategyOptions + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + /// The maximum number of tokens in each chunk. The default value is 800. The minimum value is 100 and the maximum value is 4096. + /// + /// The number of tokens that overlap between chunks. The default value is 400. + /// Note that the overlap must not exceed half of max_chunk_size_tokens. * + /// + public VectorStoreStaticChunkingStrategyOptions(int maxChunkSizeTokens, int chunkOverlapTokens) + { + MaxChunkSizeTokens = maxChunkSizeTokens; + ChunkOverlapTokens = chunkOverlapTokens; + } + + /// Initializes a new instance of . + /// The maximum number of tokens in each chunk. The default value is 800. The minimum value is 100 and the maximum value is 4096. + /// + /// The number of tokens that overlap between chunks. The default value is 400. + /// Note that the overlap must not exceed half of max_chunk_size_tokens. * + /// + /// Keeps track of any properties unknown to the library. + internal VectorStoreStaticChunkingStrategyOptions(int maxChunkSizeTokens, int chunkOverlapTokens, IDictionary serializedAdditionalRawData) + { + MaxChunkSizeTokens = maxChunkSizeTokens; + ChunkOverlapTokens = chunkOverlapTokens; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal VectorStoreStaticChunkingStrategyOptions() + { + } + + /// The maximum number of tokens in each chunk. The default value is 800. The minimum value is 100 and the maximum value is 4096. + public int MaxChunkSizeTokens { get; set; } + /// + /// The number of tokens that overlap between chunks. The default value is 400. + /// Note that the overlap must not exceed half of max_chunk_size_tokens. * + /// + public int ChunkOverlapTokens { get; set; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreStaticChunkingStrategyRequest.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreStaticChunkingStrategyRequest.Serialization.cs new file mode 100644 index 000000000000..25e218d5e3ed --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreStaticChunkingStrategyRequest.Serialization.cs @@ -0,0 +1,134 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class VectorStoreStaticChunkingStrategyRequest : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(VectorStoreStaticChunkingStrategyRequest)} does not support writing '{format}' format."); + } + + base.JsonModelWriteCore(writer, options); + writer.WritePropertyName("static"u8); + writer.WriteObjectValue(Static, options); + } + + VectorStoreStaticChunkingStrategyRequest 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(VectorStoreStaticChunkingStrategyRequest)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeVectorStoreStaticChunkingStrategyRequest(document.RootElement, options); + } + + internal static VectorStoreStaticChunkingStrategyRequest DeserializeVectorStoreStaticChunkingStrategyRequest(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + VectorStoreStaticChunkingStrategyOptions @static = default; + VectorStoreChunkingStrategyRequestType type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("static"u8)) + { + @static = VectorStoreStaticChunkingStrategyOptions.DeserializeVectorStoreStaticChunkingStrategyOptions(property.Value, options); + continue; + } + if (property.NameEquals("type"u8)) + { + type = new VectorStoreChunkingStrategyRequestType(property.Value.GetString()); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new VectorStoreStaticChunkingStrategyRequest(type, serializedAdditionalRawData, @static); + } + + 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(VectorStoreStaticChunkingStrategyRequest)} does not support writing '{options.Format}' format."); + } + } + + VectorStoreStaticChunkingStrategyRequest 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeVectorStoreStaticChunkingStrategyRequest(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(VectorStoreStaticChunkingStrategyRequest)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new VectorStoreStaticChunkingStrategyRequest FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeVectorStoreStaticChunkingStrategyRequest(document.RootElement); + } + + /// Convert into a . + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreStaticChunkingStrategyRequest.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreStaticChunkingStrategyRequest.cs new file mode 100644 index 000000000000..0a65da2962bd --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreStaticChunkingStrategyRequest.cs @@ -0,0 +1,44 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// A statically configured chunking strategy. + public partial class VectorStoreStaticChunkingStrategyRequest : VectorStoreChunkingStrategyRequest + { + /// Initializes a new instance of . + /// The options for the static chunking strategy. + /// is null. + public VectorStoreStaticChunkingStrategyRequest(VectorStoreStaticChunkingStrategyOptions @static) + { + Argument.AssertNotNull(@static, nameof(@static)); + + Type = VectorStoreChunkingStrategyRequestType.Static; + Static = @static; + } + + /// Initializes a new instance of . + /// The object type. + /// Keeps track of any properties unknown to the library. + /// The options for the static chunking strategy. + internal VectorStoreStaticChunkingStrategyRequest(VectorStoreChunkingStrategyRequestType type, IDictionary serializedAdditionalRawData, VectorStoreStaticChunkingStrategyOptions @static) : base(type, serializedAdditionalRawData) + { + Static = @static; + } + + /// Initializes a new instance of for deserialization. + internal VectorStoreStaticChunkingStrategyRequest() + { + } + + /// The options for the static chunking strategy. + public VectorStoreStaticChunkingStrategyOptions Static { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreStaticChunkingStrategyResponse.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreStaticChunkingStrategyResponse.Serialization.cs new file mode 100644 index 000000000000..a116c8ce6fe6 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreStaticChunkingStrategyResponse.Serialization.cs @@ -0,0 +1,134 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class VectorStoreStaticChunkingStrategyResponse : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(VectorStoreStaticChunkingStrategyResponse)} does not support writing '{format}' format."); + } + + base.JsonModelWriteCore(writer, options); + writer.WritePropertyName("static"u8); + writer.WriteObjectValue(Static, options); + } + + VectorStoreStaticChunkingStrategyResponse 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(VectorStoreStaticChunkingStrategyResponse)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeVectorStoreStaticChunkingStrategyResponse(document.RootElement, options); + } + + internal static VectorStoreStaticChunkingStrategyResponse DeserializeVectorStoreStaticChunkingStrategyResponse(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + VectorStoreStaticChunkingStrategyOptions @static = default; + VectorStoreChunkingStrategyResponseType type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("static"u8)) + { + @static = VectorStoreStaticChunkingStrategyOptions.DeserializeVectorStoreStaticChunkingStrategyOptions(property.Value, options); + continue; + } + if (property.NameEquals("type"u8)) + { + type = new VectorStoreChunkingStrategyResponseType(property.Value.GetString()); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new VectorStoreStaticChunkingStrategyResponse(type, serializedAdditionalRawData, @static); + } + + 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(VectorStoreStaticChunkingStrategyResponse)} does not support writing '{options.Format}' format."); + } + } + + VectorStoreStaticChunkingStrategyResponse 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeVectorStoreStaticChunkingStrategyResponse(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(VectorStoreStaticChunkingStrategyResponse)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static new VectorStoreStaticChunkingStrategyResponse FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeVectorStoreStaticChunkingStrategyResponse(document.RootElement); + } + + /// Convert into a . + internal override RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreStaticChunkingStrategyResponse.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreStaticChunkingStrategyResponse.cs new file mode 100644 index 000000000000..5d2a0200bdcd --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreStaticChunkingStrategyResponse.cs @@ -0,0 +1,44 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.AI.OpenAI.Assistants +{ + /// A statically configured chunking strategy. + public partial class VectorStoreStaticChunkingStrategyResponse : VectorStoreChunkingStrategyResponse + { + /// Initializes a new instance of . + /// The options for the static chunking strategy. + /// is null. + internal VectorStoreStaticChunkingStrategyResponse(VectorStoreStaticChunkingStrategyOptions @static) + { + Argument.AssertNotNull(@static, nameof(@static)); + + Type = VectorStoreChunkingStrategyResponseType.Static; + Static = @static; + } + + /// Initializes a new instance of . + /// The object type. + /// Keeps track of any properties unknown to the library. + /// The options for the static chunking strategy. + internal VectorStoreStaticChunkingStrategyResponse(VectorStoreChunkingStrategyResponseType type, IDictionary serializedAdditionalRawData, VectorStoreStaticChunkingStrategyOptions @static) : base(type, serializedAdditionalRawData) + { + Static = @static; + } + + /// Initializes a new instance of for deserialization. + internal VectorStoreStaticChunkingStrategyResponse() + { + } + + /// The options for the static chunking strategy. + public VectorStoreStaticChunkingStrategyOptions Static { get; } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreStatus.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreStatus.cs new file mode 100644 index 000000000000..d8b1d0e87b45 --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreStatus.cs @@ -0,0 +1,54 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.AI.OpenAI.Assistants +{ + /// Vector store possible status. + public readonly partial struct VectorStoreStatus : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public VectorStoreStatus(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string ExpiredValue = "expired"; + private const string InProgressValue = "in_progress"; + private const string CompletedValue = "completed"; + + /// expired status indicates that this vector store has expired and is no longer available for use. + public static VectorStoreStatus Expired { get; } = new VectorStoreStatus(ExpiredValue); + /// in_progress status indicates that this vector store is still processing files. + public static VectorStoreStatus InProgress { get; } = new VectorStoreStatus(InProgressValue); + /// completed status indicates that this vector store is ready for use. + public static VectorStoreStatus Completed { get; } = new VectorStoreStatus(CompletedValue); + /// Determines if two values are the same. + public static bool operator ==(VectorStoreStatus left, VectorStoreStatus right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(VectorStoreStatus left, VectorStoreStatus right) => !left.Equals(right); + /// Converts a to a . + public static implicit operator VectorStoreStatus(string value) => new VectorStoreStatus(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is VectorStoreStatus other && Equals(other); + /// + public bool Equals(VectorStoreStatus 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/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreUpdateOptions.Serialization.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreUpdateOptions.Serialization.cs new file mode 100644 index 000000000000..584d6fa01c6a --- /dev/null +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreUpdateOptions.Serialization.cs @@ -0,0 +1,213 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.AI.OpenAI.Assistants +{ + public partial class VectorStoreUpdateOptions : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(VectorStoreUpdateOptions)} does not support writing '{format}' format."); + } + + if (Optional.IsDefined(Name)) + { + if (Name != null) + { + writer.WritePropertyName("name"u8); + writer.WriteStringValue(Name); + } + else + { + writer.WriteNull("name"); + } + } + if (Optional.IsDefined(ExpiresAfter)) + { + if (ExpiresAfter != null) + { + writer.WritePropertyName("expires_after"u8); + writer.WriteObjectValue(ExpiresAfter, options); + } + else + { + writer.WriteNull("expires_after"); + } + } + if (Optional.IsCollectionDefined(Metadata)) + { + if (Metadata != null) + { + writer.WritePropertyName("metadata"u8); + writer.WriteStartObject(); + foreach (var item in Metadata) + { + writer.WritePropertyName(item.Key); + writer.WriteStringValue(item.Value); + } + writer.WriteEndObject(); + } + else + { + writer.WriteNull("metadata"); + } + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + VectorStoreUpdateOptions 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(VectorStoreUpdateOptions)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeVectorStoreUpdateOptions(document.RootElement, options); + } + + internal static VectorStoreUpdateOptions DeserializeVectorStoreUpdateOptions(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string name = default; + VectorStoreExpirationPolicy expiresAfter = default; + IDictionary metadata = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("name"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + name = null; + continue; + } + name = property.Value.GetString(); + continue; + } + if (property.NameEquals("expires_after"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + expiresAfter = null; + continue; + } + expiresAfter = VectorStoreExpirationPolicy.DeserializeVectorStoreExpirationPolicy(property.Value, options); + 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 (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new VectorStoreUpdateOptions(name, expiresAfter, 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(VectorStoreUpdateOptions)} does not support writing '{options.Format}' format."); + } + } + + VectorStoreUpdateOptions 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, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeVectorStoreUpdateOptions(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(VectorStoreUpdateOptions)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static VectorStoreUpdateOptions FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeVectorStoreUpdateOptions(document.RootElement); + } + + /// Convert into a . + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this, ModelSerializationExtensions.WireOptions); + return content; + } + } +} diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateThreadRequest.cs b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreUpdateOptions.cs similarity index 69% rename from sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateThreadRequest.cs rename to sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreUpdateOptions.cs index 46ab2f35dbcb..e3bcef35dc48 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/UpdateThreadRequest.cs +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/src/Generated/VectorStoreUpdateOptions.cs @@ -10,8 +10,8 @@ namespace Azure.AI.OpenAI.Assistants { - /// The UpdateThreadRequest. - internal partial class UpdateThreadRequest + /// Request object for updating a vector store. + public partial class VectorStoreUpdateOptions { /// /// Keeps track of any properties unknown to the library. @@ -45,22 +45,30 @@ internal partial class UpdateThreadRequest /// private IDictionary _serializedAdditionalRawData; - /// Initializes a new instance of . - internal UpdateThreadRequest() + /// Initializes a new instance of . + public VectorStoreUpdateOptions() { Metadata = new ChangeTrackingDictionary(); } - /// Initializes a new instance of . + /// Initializes a new instance of . + /// The name of the vector store. + /// Details on when this vector store expires. /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. /// Keeps track of any properties unknown to the library. - internal UpdateThreadRequest(IReadOnlyDictionary metadata, IDictionary serializedAdditionalRawData) + internal VectorStoreUpdateOptions(string name, VectorStoreExpirationPolicy expiresAfter, IDictionary metadata, IDictionary serializedAdditionalRawData) { + Name = name; + ExpiresAfter = expiresAfter; Metadata = metadata; _serializedAdditionalRawData = serializedAdditionalRawData; } + /// The name of the vector store. + public string Name { get; set; } + /// Details on when this vector store expires. + public VectorStoreExpirationPolicy ExpiresAfter { get; set; } /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length. - public IReadOnlyDictionary Metadata { get; } + public IDictionary Metadata { get; set; } } } diff --git a/sdk/openai/Azure.AI.OpenAI.Assistants/tsp-location.yaml b/sdk/openai/Azure.AI.OpenAI.Assistants/tsp-location.yaml index 0f4f485bb948..169871f0501a 100644 --- a/sdk/openai/Azure.AI.OpenAI.Assistants/tsp-location.yaml +++ b/sdk/openai/Azure.AI.OpenAI.Assistants/tsp-location.yaml @@ -1,3 +1,4 @@ directory: specification/ai/OpenAI.Assistants -commit: 893bdf5a70a28c7662b5d5f0ac10823b3dc1a896 +commit: 7d101437be365b88b2d26c4ea95e126123c88490 repo: Azure/azure-rest-api-specs +additionalDirectories: