diff --git a/OpenAI-DotNet/Assistants/Assistant.cs b/OpenAI-DotNet/Assistants/Assistant.cs index 252c0c3a..0ae9f4ae 100644 --- a/OpenAI-DotNet/Assistants/Assistant.cs +++ b/OpenAI-DotNet/Assistants/Assistant.cs @@ -1,70 +1,71 @@ using System.Collections.Generic; using System.Text.Json.Serialization; -namespace OpenAI.Assistants; - -public sealed class Assistant +namespace OpenAI.Assistants { - /// - /// The identifier, which can be referenced in API endpoints. - /// - [JsonPropertyName("id")] - public string Id { get; set; } + public sealed class Assistant + { + /// + /// The identifier, which can be referenced in API endpoints. + /// + [JsonPropertyName("id")] + public string Id { get; set; } - /// - /// The object type, which is always assistant. - /// - [JsonPropertyName("object")] - public string Object { get; set; } = "assistant"; + /// + /// The object type, which is always assistant. + /// + [JsonPropertyName("object")] + public string Object { get; set; } = "assistant"; - /// - /// The Unix timestamp (in seconds) for when the assistant was created. - /// - [JsonPropertyName("created_at")] - public int CreatedAt { get; set; } + /// + /// The Unix timestamp (in seconds) for when the assistant was created. + /// + [JsonPropertyName("created_at")] + public int CreatedAt { get; set; } - /// - /// The name of the assistant. The maximum length is 256 characters. - /// - [JsonPropertyName("name")] - public string Name { get; set; } + /// + /// The name of the assistant. The maximum length is 256 characters. + /// + [JsonPropertyName("name")] + public string Name { get; set; } - /// - /// The description of the assistant. The maximum length is 512 characters. - /// - [JsonPropertyName("description")] - public string Description { get; set; } + /// + /// The description of the assistant. The maximum length is 512 characters. + /// + [JsonPropertyName("description")] + public string Description { get; set; } - /// - /// ID of the model to use. You can use the List models API to see all of your available models, or see our Model overview for descriptions of them. - /// - [JsonPropertyName("model")] - public string Model { get; set; } + /// + /// ID of the model to use. You can use the List models API to see all of your available models, or see our Model overview for descriptions of them. + /// + [JsonPropertyName("model")] + public string Model { get; set; } - /// - /// The system instructions that the assistant uses. The maximum length is 32768 characters. - /// - [JsonPropertyName("instructions")] - public string Instructions { get; set; } + /// + /// The system instructions that the assistant uses. The maximum length is 32768 characters. + /// + [JsonPropertyName("instructions")] + public string Instructions { get; set; } - /// - /// A list of tool enabled on the assistant. There can be a maximum of 128 tools per assistant. - /// Tools can be of types code_interpreter, retrieval, or function. - /// - [JsonPropertyName("tools")] - public IReadOnlyList Tools { get; set; } + /// + /// A list of tool enabled on the assistant. There can be a maximum of 128 tools per assistant. + /// Tools can be of types code_interpreter, retrieval, or function. + /// + [JsonPropertyName("tools")] + public IReadOnlyList Tools { get; set; } - /// - /// A list of file IDs attached to this assistant. There can be a maximum of 20 files attached to the assistant. - /// Files are ordered by their creation date in ascending order. - /// - [JsonPropertyName("file_ids")] - public IReadOnlyList FileIds { get; set; } + /// + /// A list of file IDs attached to this assistant. There can be a maximum of 20 files attached to the assistant. + /// Files are ordered by their creation date in ascending order. + /// + [JsonPropertyName("file_ids")] + public IReadOnlyList FileIds { get; set; } - /// - /// Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information - /// about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long. - /// - [JsonPropertyName("metadata")] - public IReadOnlyDictionary Metadata { get; set; } + /// + /// Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information + /// about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long. + /// + [JsonPropertyName("metadata")] + public IReadOnlyDictionary Metadata { get; set; } + } } \ No newline at end of file diff --git a/OpenAI-DotNet/Assistants/AssistantFile.cs b/OpenAI-DotNet/Assistants/AssistantFile.cs index 0def7d75..63b2988b 100644 --- a/OpenAI-DotNet/Assistants/AssistantFile.cs +++ b/OpenAI-DotNet/Assistants/AssistantFile.cs @@ -1,34 +1,35 @@ using System.Text.Json.Serialization; -namespace OpenAI.Assistants; - -/// -/// File attached to an assistant. -/// -public sealed class AssistantFile +namespace OpenAI.Assistants { /// - /// The identifier, which can be referenced in API endpoints. + /// File attached to an assistant. /// - [JsonPropertyName("id")] - public string Id { get; set; } + public sealed class AssistantFile + { + /// + /// The identifier, which can be referenced in API endpoints. + /// + [JsonPropertyName("id")] + public string Id { get; set; } - /// - /// The object type, which is always assistant.file. - /// - [JsonPropertyName("object")] - public string Object { get; set; } = "assistant.file"; + /// + /// The object type, which is always assistant.file. + /// + [JsonPropertyName("object")] + public string Object { get; set; } = "assistant.file"; - /// - /// The Unix timestamp (in seconds) for when the assistant file was created. - /// - [JsonPropertyName("created_at")] - public int CreatedAt { get; set; } + /// + /// The Unix timestamp (in seconds) for when the assistant file was created. + /// + [JsonPropertyName("created_at")] + public int CreatedAt { get; set; } - /// - /// The assistant ID that the file is attached to. - /// - /// - [JsonPropertyName("assistant_id")] - public string AssistantId { get; set; } + /// + /// The assistant ID that the file is attached to. + /// + /// + [JsonPropertyName("assistant_id")] + public string AssistantId { get; set; } + } } \ No newline at end of file diff --git a/OpenAI-DotNet/Assistants/AssistantFilesList.cs b/OpenAI-DotNet/Assistants/AssistantFilesList.cs index 45f88092..ce702331 100644 --- a/OpenAI-DotNet/Assistants/AssistantFilesList.cs +++ b/OpenAI-DotNet/Assistants/AssistantFilesList.cs @@ -1,22 +1,23 @@ using System.Collections.Generic; using System.Text.Json.Serialization; -namespace OpenAI.Assistants; - -public class AssistantFilesList +namespace OpenAI.Assistants { - [JsonPropertyName("object")] - public string Object { get; set; } = "list"; + public class AssistantFilesList + { + [JsonPropertyName("object")] + public string Object { get; set; } = "list"; - [JsonPropertyName("data")] - public IReadOnlyList Data { get; set; } + [JsonPropertyName("data")] + public IReadOnlyList Data { get; set; } - [JsonPropertyName("first_id")] - public string FirstId { get; set; } + [JsonPropertyName("first_id")] + public string FirstId { get; set; } - [JsonPropertyName("last_id")] - public string LastId { get; set; } + [JsonPropertyName("last_id")] + public string LastId { get; set; } - [JsonPropertyName("has_more")] - public bool HasMore { get; set; } + [JsonPropertyName("has_more")] + public bool HasMore { get; set; } + } } \ No newline at end of file diff --git a/OpenAI-DotNet/Assistants/AssistantTool.cs b/OpenAI-DotNet/Assistants/AssistantTool.cs index c267403d..cdafa94f 100644 --- a/OpenAI-DotNet/Assistants/AssistantTool.cs +++ b/OpenAI-DotNet/Assistants/AssistantTool.cs @@ -1,13 +1,14 @@ using System.Text.Json.Serialization; using OpenAI.Chat; -namespace OpenAI.Assistants; - -public sealed class AssistantTool +namespace OpenAI.Assistants { - [JsonPropertyName("type")] - public string Type { get; set; } + public sealed class AssistantTool + { + [JsonPropertyName("type")] + public string Type { get; set; } - [JsonPropertyName("function")] - public Function Function { get; set; } + [JsonPropertyName("function")] + public Function Function { get; set; } + } } \ No newline at end of file diff --git a/OpenAI-DotNet/Assistants/AssistantsEndpoint.cs b/OpenAI-DotNet/Assistants/AssistantsEndpoint.cs index 5c5a9b98..d7c3c4eb 100644 --- a/OpenAI-DotNet/Assistants/AssistantsEndpoint.cs +++ b/OpenAI-DotNet/Assistants/AssistantsEndpoint.cs @@ -6,201 +6,202 @@ using System.Threading.Tasks; using OpenAI.Extensions; -namespace OpenAI.Assistants; - -public class AssistantsEndpoint : BaseEndPoint +namespace OpenAI.Assistants { - internal AssistantsEndpoint(OpenAIClient api) : base(api) { } - - protected override string Root => "assistants"; - - /// - /// Create an assistant with a model and instructions. - /// - /// - /// - /// - public async Task CreateAssistantAsync(CreateAssistantRequest request, CancellationToken cancellationToken = default) + public class AssistantsEndpoint : BaseEndPoint { - var jsonContent = JsonSerializer.Serialize(request, OpenAIClient.JsonSerializationOptions).ToJsonStringContent(EnableDebug); - var response = await Api.Client.PostAsync(GetUrl(), jsonContent, cancellationToken).ConfigureAwait(false); - var responseAsString = await response.ReadAsStringAsync(EnableDebug, cancellationToken).ConfigureAwait(false); - var created = JsonSerializer.Deserialize(responseAsString, OpenAIClient.JsonSerializationOptions); + internal AssistantsEndpoint(OpenAIClient api) : base(api) { } - return created; - } - - /// - /// Retrieves an assistant. - /// - /// The ID of the assistant to retrieve. - /// - /// - public async Task RetrieveAssistantAsync(string assistantId, CancellationToken cancellationToken = default) - { - var response = await Api.Client.GetAsync(GetUrl($"/{assistantId}"), cancellationToken).ConfigureAwait(false); - var responseAsString = await response.ReadAsStringAsync(EnableDebug, cancellationToken).ConfigureAwait(false); - var assistant = JsonSerializer.Deserialize(responseAsString, OpenAIClient.JsonSerializationOptions); - - return assistant; - } + protected override string Root => "assistants"; - /// - /// Modifies an assistant. - /// - /// The ID of the assistant to modify. - /// - /// - /// - public async Task ModifyAssistantAsync(string assistantId, ModifyAssistantRequest request, CancellationToken cancellationToken = default) - { - var jsonContent = JsonSerializer.Serialize(request, OpenAIClient.JsonSerializationOptions).ToJsonStringContent(EnableDebug); - var response = await Api.Client.PostAsync(GetUrl($"/{assistantId}"), jsonContent, cancellationToken).ConfigureAwait(false); - var responseAsString = await response.ReadAsStringAsync(EnableDebug, cancellationToken).ConfigureAwait(false); - var modified = JsonSerializer.Deserialize(responseAsString, OpenAIClient.JsonSerializationOptions); - - return modified; - } - - /// - /// Delete an assistant. - /// - /// The ID of the assistant to delete. - /// - /// - public async Task DeleteAssistantAsync(string assistantId, CancellationToken cancellationToken = default) - { - var response = await Api.Client.DeleteAsync(GetUrl($"/{assistantId}"), cancellationToken).ConfigureAwait(false); - var responseAsString = await response.ReadAsStringAsync(EnableDebug, cancellationToken).ConfigureAwait(false); - var status = JsonSerializer.Deserialize(responseAsString, OpenAIClient.JsonSerializationOptions); - - return status.Deleted; - } + /// + /// Create an assistant with a model and instructions. + /// + /// + /// + /// + public async Task CreateAssistantAsync(CreateAssistantRequest request, CancellationToken cancellationToken = default) + { + var jsonContent = JsonSerializer.Serialize(request, OpenAIClient.JsonSerializationOptions).ToJsonStringContent(EnableDebug); + var response = await Api.Client.PostAsync(GetUrl(), jsonContent, cancellationToken).ConfigureAwait(false); + var responseAsString = await response.ReadAsStringAsync(EnableDebug, cancellationToken).ConfigureAwait(false); + var created = JsonSerializer.Deserialize(responseAsString, OpenAIClient.JsonSerializationOptions); + + return created; + } + + /// + /// Retrieves an assistant. + /// + /// The ID of the assistant to retrieve. + /// + /// + public async Task RetrieveAssistantAsync(string assistantId, CancellationToken cancellationToken = default) + { + var response = await Api.Client.GetAsync(GetUrl($"/{assistantId}"), cancellationToken).ConfigureAwait(false); + var responseAsString = await response.ReadAsStringAsync(EnableDebug, cancellationToken).ConfigureAwait(false); + var assistant = JsonSerializer.Deserialize(responseAsString, OpenAIClient.JsonSerializationOptions); + + return assistant; + } - /// - /// Get list of assistants. - /// - /// 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. - /// - /// - /// - public async Task ListAssistantsAsync( - int? limit = null, string order = "desc", string after = null, string before = null, - CancellationToken cancellationToken = default) - { - var parameters = new Dictionary(); - if (limit.HasValue) parameters.Add("limit", limit.ToString()); - if (!String.IsNullOrEmpty(order)) parameters.Add("order", order); - if (!String.IsNullOrEmpty(after)) parameters.Add("after", after); - if (!String.IsNullOrEmpty(before)) parameters.Add("before", before); - - var response = await Api.Client.GetAsync(GetUrl(queryParameters: parameters), cancellationToken).ConfigureAwait(false); - var responseAsString = await response.ReadAsStringAsync(EnableDebug, cancellationToken).ConfigureAwait(false); - var list = JsonSerializer.Deserialize(responseAsString, OpenAIClient.JsonSerializationOptions); - - return list; - } - - /// - /// Create an assistant file by attaching a File to an assistant. - /// - /// The ID of the assistant for which to create a File. - /// - /// - /// - public async Task CreateAssistantFileAsync(string assistantId, CreateAssistantFileRequest request, CancellationToken cancellationToken = default) - { - var jsonContent = JsonSerializer.Serialize(request, OpenAIClient.JsonSerializationOptions).ToJsonStringContent(EnableDebug); - var response = await Api.Client.PostAsync(GetUrl($"/{assistantId}/files"), jsonContent, cancellationToken).ConfigureAwait(false); - var responseAsString = await response.ReadAsStringAsync(EnableDebug, cancellationToken).ConfigureAwait(false); - var created = JsonSerializer.Deserialize(responseAsString, OpenAIClient.JsonSerializationOptions); - - return created; - } - - /// - /// Retrieves an AssistantFile. - /// - /// The ID of the assistant who the file belongs to. - /// The ID of the file we're getting. - /// - /// - public async Task RetrieveAssistantFileAsync(string assistantId, string fileId, CancellationToken cancellationToken = default) - { - var response = await Api.Client.GetAsync(GetUrl($"/{assistantId}/files/{fileId}"), cancellationToken).ConfigureAwait(false); - var responseAsString = await response.ReadAsStringAsync(EnableDebug, cancellationToken).ConfigureAwait(false); - var created = JsonSerializer.Deserialize(responseAsString, OpenAIClient.JsonSerializationOptions); - - return created; - } - - /// - /// Delete an assistant file. - /// - /// The ID of the assistant that the file belongs to. - /// The ID of the file to delete. - /// - /// - public async Task DeleteAssistantFileAsync(string assistantId, string fileId, CancellationToken cancellationToken = default) - { - var response = await Api.Client.DeleteAsync(GetUrl($"/{assistantId}/files/{fileId}"), cancellationToken).ConfigureAwait(false); - var responseAsString = await response.ReadAsStringAsync(EnableDebug, cancellationToken).ConfigureAwait(false); - var status = JsonSerializer.Deserialize(responseAsString, OpenAIClient.JsonSerializationOptions); - - return status.Deleted; - } - - /// - /// Returns a list of assistant files. - /// - /// The ID of the assistant the file belongs to. - /// 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. - /// - /// - public async Task ListAssistantFilesAsync( - string assistantId, - int? limit = null, string order = "desc", string after = null, string before = null, - CancellationToken cancellationToken = default) - { - var parameters = new Dictionary(); - if (limit.HasValue) parameters.Add("limit", limit.ToString()); - if (!String.IsNullOrEmpty(order)) parameters.Add("order", order); - if (!String.IsNullOrEmpty(after)) parameters.Add("after", after); - if (!String.IsNullOrEmpty(before)) parameters.Add("before", before); - - var response = await Api.Client.GetAsync(GetUrl($"/{assistantId}/files", parameters), cancellationToken).ConfigureAwait(false); - var responseAsString = await response.ReadAsStringAsync(EnableDebug, cancellationToken).ConfigureAwait(false); - var list = JsonSerializer.Deserialize(responseAsString, OpenAIClient.JsonSerializationOptions); - - return list; - } - - private sealed class DeletionStatus - { - [JsonInclude] - [JsonPropertyName("id")] - public string Id { get; private set; } - - [JsonInclude] - [JsonPropertyName("object")] - public string Object { get; private set; } - - [JsonInclude] - [JsonPropertyName("deleted")] - public bool Deleted { get; private set; } + /// + /// Modifies an assistant. + /// + /// The ID of the assistant to modify. + /// + /// + /// + public async Task ModifyAssistantAsync(string assistantId, ModifyAssistantRequest request, CancellationToken cancellationToken = default) + { + var jsonContent = JsonSerializer.Serialize(request, OpenAIClient.JsonSerializationOptions).ToJsonStringContent(EnableDebug); + var response = await Api.Client.PostAsync(GetUrl($"/{assistantId}"), jsonContent, cancellationToken).ConfigureAwait(false); + var responseAsString = await response.ReadAsStringAsync(EnableDebug, cancellationToken).ConfigureAwait(false); + var modified = JsonSerializer.Deserialize(responseAsString, OpenAIClient.JsonSerializationOptions); + + return modified; + } + + /// + /// Delete an assistant. + /// + /// The ID of the assistant to delete. + /// + /// + public async Task DeleteAssistantAsync(string assistantId, CancellationToken cancellationToken = default) + { + var response = await Api.Client.DeleteAsync(GetUrl($"/{assistantId}"), cancellationToken).ConfigureAwait(false); + var responseAsString = await response.ReadAsStringAsync(EnableDebug, cancellationToken).ConfigureAwait(false); + var status = JsonSerializer.Deserialize(responseAsString, OpenAIClient.JsonSerializationOptions); + + return status.Deleted; + } + + /// + /// Get list of assistants. + /// + /// 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. + /// + /// + /// + public async Task ListAssistantsAsync( + int? limit = null, string order = "desc", string after = null, string before = null, + CancellationToken cancellationToken = default) + { + var parameters = new Dictionary(); + if (limit.HasValue) parameters.Add("limit", limit.ToString()); + if (!String.IsNullOrEmpty(order)) parameters.Add("order", order); + if (!String.IsNullOrEmpty(after)) parameters.Add("after", after); + if (!String.IsNullOrEmpty(before)) parameters.Add("before", before); + + var response = await Api.Client.GetAsync(GetUrl(queryParameters: parameters), cancellationToken).ConfigureAwait(false); + var responseAsString = await response.ReadAsStringAsync(EnableDebug, cancellationToken).ConfigureAwait(false); + var list = JsonSerializer.Deserialize(responseAsString, OpenAIClient.JsonSerializationOptions); + + return list; + } + + /// + /// Create an assistant file by attaching a File to an assistant. + /// + /// The ID of the assistant for which to create a File. + /// + /// + /// + public async Task CreateAssistantFileAsync(string assistantId, CreateAssistantFileRequest request, CancellationToken cancellationToken = default) + { + var jsonContent = JsonSerializer.Serialize(request, OpenAIClient.JsonSerializationOptions).ToJsonStringContent(EnableDebug); + var response = await Api.Client.PostAsync(GetUrl($"/{assistantId}/files"), jsonContent, cancellationToken).ConfigureAwait(false); + var responseAsString = await response.ReadAsStringAsync(EnableDebug, cancellationToken).ConfigureAwait(false); + var created = JsonSerializer.Deserialize(responseAsString, OpenAIClient.JsonSerializationOptions); + + return created; + } + + /// + /// Retrieves an AssistantFile. + /// + /// The ID of the assistant who the file belongs to. + /// The ID of the file we're getting. + /// + /// + public async Task RetrieveAssistantFileAsync(string assistantId, string fileId, CancellationToken cancellationToken = default) + { + var response = await Api.Client.GetAsync(GetUrl($"/{assistantId}/files/{fileId}"), cancellationToken).ConfigureAwait(false); + var responseAsString = await response.ReadAsStringAsync(EnableDebug, cancellationToken).ConfigureAwait(false); + var created = JsonSerializer.Deserialize(responseAsString, OpenAIClient.JsonSerializationOptions); + + return created; + } + + /// + /// Delete an assistant file. + /// + /// The ID of the assistant that the file belongs to. + /// The ID of the file to delete. + /// + /// + public async Task DeleteAssistantFileAsync(string assistantId, string fileId, CancellationToken cancellationToken = default) + { + var response = await Api.Client.DeleteAsync(GetUrl($"/{assistantId}/files/{fileId}"), cancellationToken).ConfigureAwait(false); + var responseAsString = await response.ReadAsStringAsync(EnableDebug, cancellationToken).ConfigureAwait(false); + var status = JsonSerializer.Deserialize(responseAsString, OpenAIClient.JsonSerializationOptions); + + return status.Deleted; + } + + /// + /// Returns a list of assistant files. + /// + /// The ID of the assistant the file belongs to. + /// 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. + /// + /// + public async Task ListAssistantFilesAsync( + string assistantId, + int? limit = null, string order = "desc", string after = null, string before = null, + CancellationToken cancellationToken = default) + { + var parameters = new Dictionary(); + if (limit.HasValue) parameters.Add("limit", limit.ToString()); + if (!String.IsNullOrEmpty(order)) parameters.Add("order", order); + if (!String.IsNullOrEmpty(after)) parameters.Add("after", after); + if (!String.IsNullOrEmpty(before)) parameters.Add("before", before); + + var response = await Api.Client.GetAsync(GetUrl($"/{assistantId}/files", parameters), cancellationToken).ConfigureAwait(false); + var responseAsString = await response.ReadAsStringAsync(EnableDebug, cancellationToken).ConfigureAwait(false); + var list = JsonSerializer.Deserialize(responseAsString, OpenAIClient.JsonSerializationOptions); + + return list; + } + + private sealed class DeletionStatus + { + [JsonInclude] + [JsonPropertyName("id")] + public string Id { get; private set; } + + [JsonInclude] + [JsonPropertyName("object")] + public string Object { get; private set; } + + [JsonInclude] + [JsonPropertyName("deleted")] + public bool Deleted { get; private set; } + } } } \ No newline at end of file diff --git a/OpenAI-DotNet/Assistants/AssistantsList.cs b/OpenAI-DotNet/Assistants/AssistantsList.cs index 70a74f1e..b4959d5b 100644 --- a/OpenAI-DotNet/Assistants/AssistantsList.cs +++ b/OpenAI-DotNet/Assistants/AssistantsList.cs @@ -1,22 +1,23 @@ using System.Collections.Generic; using System.Text.Json.Serialization; -namespace OpenAI.Assistants; - -public sealed class AssistantsList +namespace OpenAI.Assistants { - [JsonPropertyName("object")] - public string Object { get; set; } = "list"; + public sealed class AssistantsList + { + [JsonPropertyName("object")] + public string Object { get; set; } = "list"; - [JsonPropertyName("data")] - public IReadOnlyList Data { get; set; } + [JsonPropertyName("data")] + public IReadOnlyList Data { get; set; } - [JsonPropertyName("first_id")] - public string FirstId { get; set; } + [JsonPropertyName("first_id")] + public string FirstId { get; set; } - [JsonPropertyName("last_id")] - public string LastId { get; set; } + [JsonPropertyName("last_id")] + public string LastId { get; set; } - [JsonPropertyName("has_more")] - public bool HasMore { get; set; } + [JsonPropertyName("has_more")] + public bool HasMore { get; set; } + } } \ No newline at end of file diff --git a/OpenAI-DotNet/Assistants/CreateAssistantFileRequest.cs b/OpenAI-DotNet/Assistants/CreateAssistantFileRequest.cs index 7a55ee9f..5064e6f4 100644 --- a/OpenAI-DotNet/Assistants/CreateAssistantFileRequest.cs +++ b/OpenAI-DotNet/Assistants/CreateAssistantFileRequest.cs @@ -1,14 +1,15 @@ using System.Text.Json.Serialization; -namespace OpenAI.Assistants; - -public sealed class CreateAssistantFileRequest +namespace OpenAI.Assistants { - /// - /// A File ID (with purpose="assistants") that the assistant should use. - /// Useful for tools like retrieval and code_interpreter that can access files. - /// - /// - [JsonPropertyName("file_id")] - public string FileId { get; set; } + public sealed class CreateAssistantFileRequest + { + /// + /// A File ID (with purpose="assistants") that the assistant should use. + /// Useful for tools like retrieval and code_interpreter that can access files. + /// + /// + [JsonPropertyName("file_id")] + public string FileId { get; set; } + } } \ No newline at end of file diff --git a/OpenAI-DotNet/Assistants/CreateAssistantRequest.cs b/OpenAI-DotNet/Assistants/CreateAssistantRequest.cs index a26d6ea6..9033ea88 100644 --- a/OpenAI-DotNet/Assistants/CreateAssistantRequest.cs +++ b/OpenAI-DotNet/Assistants/CreateAssistantRequest.cs @@ -1,52 +1,53 @@ using System.Collections.Generic; using System.Text.Json.Serialization; -namespace OpenAI.Assistants; - -public sealed class CreateAssistantRequest +namespace OpenAI.Assistants { - /// - /// ID of the model to use. You can use the List models API to see all of your available models, or see our Model overview for descriptions of them. - /// - [JsonPropertyName("model")] - public string Model { get; set; } - - /// - /// The name of the assistant. The maximum length is 256 characters. - /// - [JsonPropertyName("name")] - public string Name { get; set; } - - /// - /// The description of the assistant. The maximum length is 512 characters. - /// - [JsonPropertyName("description")] - public string Description { get; set; } - - /// - /// The system instructions that the assistant uses. The maximum length is 32768 characters. - /// - [JsonPropertyName("instructions")] - public string Instructions { get; set; } - - /// - /// A list of tool enabled on the assistant. There can be a maximum of 128 tools per assistant. - /// Tools can be of types code_interpreter, retrieval, or function. - /// - [JsonPropertyName("tools")] - public List Tools { get; set; } - - /// - /// A list of file IDs attached to this assistant. There can be a maximum of 20 files attached to the assistant. - /// Files are ordered by their creation date in ascending order. - /// - [JsonPropertyName("file_ids")] - public List FileIds { get; set; } - - /// - /// Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information - /// about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long. - /// - [JsonPropertyName("metadata")] - public Dictionary Metadata { get; set; } + public sealed class CreateAssistantRequest + { + /// + /// ID of the model to use. You can use the List models API to see all of your available models, or see our Model overview for descriptions of them. + /// + [JsonPropertyName("model")] + public string Model { get; set; } + + /// + /// The name of the assistant. The maximum length is 256 characters. + /// + [JsonPropertyName("name")] + public string Name { get; set; } + + /// + /// The description of the assistant. The maximum length is 512 characters. + /// + [JsonPropertyName("description")] + public string Description { get; set; } + + /// + /// The system instructions that the assistant uses. The maximum length is 32768 characters. + /// + [JsonPropertyName("instructions")] + public string Instructions { get; set; } + + /// + /// A list of tool enabled on the assistant. There can be a maximum of 128 tools per assistant. + /// Tools can be of types code_interpreter, retrieval, or function. + /// + [JsonPropertyName("tools")] + public List Tools { get; set; } + + /// + /// A list of file IDs attached to this assistant. There can be a maximum of 20 files attached to the assistant. + /// Files are ordered by their creation date in ascending order. + /// + [JsonPropertyName("file_ids")] + public List FileIds { get; set; } + + /// + /// Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information + /// about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long. + /// + [JsonPropertyName("metadata")] + public Dictionary Metadata { get; set; } + } } \ No newline at end of file diff --git a/OpenAI-DotNet/Assistants/ModifyAssistantRequest.cs b/OpenAI-DotNet/Assistants/ModifyAssistantRequest.cs index 177ea3f7..5465e540 100644 --- a/OpenAI-DotNet/Assistants/ModifyAssistantRequest.cs +++ b/OpenAI-DotNet/Assistants/ModifyAssistantRequest.cs @@ -1,52 +1,53 @@ using System.Collections.Generic; using System.Text.Json.Serialization; -namespace OpenAI.Assistants; - -public sealed class ModifyAssistantRequest +namespace OpenAI.Assistants { - /// - /// ID of the model to use. You can use the List models API to see all of your available models, or see our Model overview for descriptions of them. - /// - [JsonPropertyName("model")] - public string Model { get; set; } - - /// - /// The name of the assistant. The maximum length is 256 characters. - /// - [JsonPropertyName("name")] - public string Name { get; set; } - - /// - /// The description of the assistant. The maximum length is 512 characters. - /// - [JsonPropertyName("description")] - public string Description { get; set; } - - /// - /// The system instructions that the assistant uses. The maximum length is 32768 characters. - /// - [JsonPropertyName("instructions")] - public string Instructions { get; set; } - - /// - /// A list of tool enabled on the assistant. There can be a maximum of 128 tools per assistant. - /// Tools can be of types code_interpreter, retrieval, or function. - /// - [JsonPropertyName("tools")] - public List Tools { get; set; } - - /// - /// A list of file IDs attached to this assistant. There can be a maximum of 20 files attached to the assistant. - /// Files are ordered by their creation date in ascending order. - /// - [JsonPropertyName("file_ids")] - public List FileIds { get; set; } - - /// - /// Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information - /// about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long. - /// - [JsonPropertyName("metadata")] - public Dictionary Metadata { get; set; } + public sealed class ModifyAssistantRequest + { + /// + /// ID of the model to use. You can use the List models API to see all of your available models, or see our Model overview for descriptions of them. + /// + [JsonPropertyName("model")] + public string Model { get; set; } + + /// + /// The name of the assistant. The maximum length is 256 characters. + /// + [JsonPropertyName("name")] + public string Name { get; set; } + + /// + /// The description of the assistant. The maximum length is 512 characters. + /// + [JsonPropertyName("description")] + public string Description { get; set; } + + /// + /// The system instructions that the assistant uses. The maximum length is 32768 characters. + /// + [JsonPropertyName("instructions")] + public string Instructions { get; set; } + + /// + /// A list of tool enabled on the assistant. There can be a maximum of 128 tools per assistant. + /// Tools can be of types code_interpreter, retrieval, or function. + /// + [JsonPropertyName("tools")] + public List Tools { get; set; } + + /// + /// A list of file IDs attached to this assistant. There can be a maximum of 20 files attached to the assistant. + /// Files are ordered by their creation date in ascending order. + /// + [JsonPropertyName("file_ids")] + public List FileIds { get; set; } + + /// + /// Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information + /// about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long. + /// + [JsonPropertyName("metadata")] + public Dictionary Metadata { get; set; } + } } \ No newline at end of file diff --git a/OpenAI-DotNet/Images/ImageResult.cs b/OpenAI-DotNet/Images/ImageResult.cs index 5add29d8..079aef15 100644 --- a/OpenAI-DotNet/Images/ImageResult.cs +++ b/OpenAI-DotNet/Images/ImageResult.cs @@ -16,7 +16,7 @@ public sealed class ImageResult [JsonPropertyName("revised_prompt")] public string RevisedPrompt { get; private set; } - public static implicit operator string(ImageResult result) => result.ToString(); + public static implicit operator string(ImageResult result) => result?.ToString(); public override string ToString() => !string.IsNullOrWhiteSpace(Url) diff --git a/OpenAI-DotNet/Threads/CreateThreadRequest.cs b/OpenAI-DotNet/Threads/CreateThreadRequest.cs index c90a1a26..44f5ca45 100644 --- a/OpenAI-DotNet/Threads/CreateThreadRequest.cs +++ b/OpenAI-DotNet/Threads/CreateThreadRequest.cs @@ -2,59 +2,60 @@ using System.Text.Json.Serialization; using OpenAI.Chat; -namespace OpenAI.Threads; - -public sealed class CreateThreadRequest +namespace OpenAI.Threads { - /// - /// A list of messages to start the thread with. - /// - [JsonPropertyName("messages")] - public List Messages { get; set; } = new(); - - /// - /// Set of 16 key-value pairs that can be attached to an object. - /// This can be useful for storing additional information about the object in a structured format. - /// Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long. - /// - [JsonPropertyName("metadata")] - public Dictionary Metadata { get; set; } - - public class Message + public sealed class CreateThreadRequest { - public Message() { } - - public Message(string content) - { - Role = Role.User; - Content = content; - } - - /// - /// The role of the entity that is creating the message. Currently only user is supported. - /// - [JsonPropertyName("role")] - public Role Role { get; set; } - - /// - /// The content of the message. - /// - [JsonPropertyName("content")] - public string Content { get; set; } - /// - /// A list of File IDs that the message should use. There can be a maximum of 10 files attached to a message. - /// Useful for tools like retrieval and code_interpreter that can access and use files. + /// A list of messages to start the thread with. /// - [JsonPropertyName("file_ids")] - public string[] FileIds { get; set; } + [JsonPropertyName("messages")] + public List Messages { get; set; } = new(); /// /// Set of 16 key-value pairs that can be attached to an object. /// This can be useful for storing additional information about the object in a structured format. - /// Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long. + /// Keys can be a maximum of 64 characters long and values can be a maximum of 512 characters long. /// [JsonPropertyName("metadata")] - public Dictionary Metadata { get; set; } + public Dictionary Metadata { get; set; } + + public class Message + { + public Message() { } + + public Message(string content) + { + Role = Role.User; + Content = content; + } + + /// + /// The role of the entity that is creating the message. Currently only user is supported. + /// + [JsonPropertyName("role")] + public Role Role { get; set; } + + /// + /// The content of the message. + /// + [JsonPropertyName("content")] + public string Content { get; set; } + + /// + /// A list of File IDs that the message should use. There can be a maximum of 10 files attached to a message. + /// Useful for tools like retrieval and code_interpreter that can access and use files. + /// + [JsonPropertyName("file_ids")] + public string[] FileIds { get; set; } + + /// + /// Set of 16 key-value pairs that can be attached to an object. + /// This can be useful for storing additional information about the object in a structured format. + /// Keys can be a maximum of 64 characters long and values can be a maximum of 512 characters long. + /// + [JsonPropertyName("metadata")] + public Dictionary Metadata { get; set; } + } } } \ No newline at end of file diff --git a/OpenAI-DotNet/Threads/Thread.cs b/OpenAI-DotNet/Threads/Thread.cs index 50ba1201..37ca6e60 100644 --- a/OpenAI-DotNet/Threads/Thread.cs +++ b/OpenAI-DotNet/Threads/Thread.cs @@ -1,34 +1,35 @@ using System.Collections.Generic; using System.Text.Json.Serialization; -namespace OpenAI.Threads; - -public sealed class Thread +namespace OpenAI.Threads { - /// - /// The identifier, which can be referenced in API endpoints. - /// - [JsonPropertyName("id")] - public string Id { get; set; } + public sealed class Thread + { + /// + /// The identifier, which can be referenced in API endpoints. + /// + [JsonPropertyName("id")] + public string Id { get; set; } - /// - /// The object type, which is always thread. - /// - [JsonPropertyName("object")] - public string Object { get; set; } = "thread"; + /// + /// The object type, which is always thread. + /// + [JsonPropertyName("object")] + public string Object { get; set; } = "thread"; - /// - /// The Unix timestamp (in seconds) for when the thread was created. - /// - /// - [JsonPropertyName("created_at")] - public int CreatedAt { get; set; } + /// + /// The Unix timestamp (in seconds) for when the thread was created. + /// + /// + [JsonPropertyName("created_at")] + public int CreatedAt { get; set; } - /// - /// Set of 16 key-value pairs that can be attached to an object. - /// This can be useful for storing additional information about the object in a structured format. - /// Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long. - /// - [JsonPropertyName("metadata")] - public IReadOnlyDictionary Metadata { get; set; } + /// + /// Set of 16 key-value pairs that can be attached to an object. + /// This can be useful for storing additional information about the object in a structured format. + /// Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long. + /// + [JsonPropertyName("metadata")] + public IReadOnlyDictionary Metadata { get; set; } + } } \ No newline at end of file diff --git a/OpenAI-DotNet/Threads/ThreadsEndpoint.cs b/OpenAI-DotNet/Threads/ThreadsEndpoint.cs index 1bc0ceab..a4d8c830 100644 --- a/OpenAI-DotNet/Threads/ThreadsEndpoint.cs +++ b/OpenAI-DotNet/Threads/ThreadsEndpoint.cs @@ -5,99 +5,100 @@ using System.Threading.Tasks; using OpenAI.Extensions; -namespace OpenAI.Threads; - -public class ThreadsEndpoint : BaseEndPoint +namespace OpenAI.Threads { - public ThreadsEndpoint(OpenAIClient api) : base(api) + public class ThreadsEndpoint : BaseEndPoint { - } + public ThreadsEndpoint(OpenAIClient api) : base(api) + { + } - protected override string Root => "/threads"; + protected override string Root => "/threads"; - /// - /// Create a thread. - /// - /// - /// - /// A thread object. - public async Task CreateThreadAsync(CreateThreadRequest request, - CancellationToken cancellationToken = default) - { - var jsonContent = JsonSerializer.Serialize(request, OpenAIClient.JsonSerializationOptions) - .ToJsonStringContent(EnableDebug); - var response = await Api.Client.PostAsync(GetUrl(), jsonContent, cancellationToken).ConfigureAwait(false); - var responseAsString = await response.ReadAsStringAsync(EnableDebug, cancellationToken).ConfigureAwait(false); - var created = JsonSerializer.Deserialize(responseAsString, OpenAIClient.JsonSerializationOptions); + /// + /// Create a thread. + /// + /// + /// + /// A thread object. + public async Task CreateThreadAsync(CreateThreadRequest request, + CancellationToken cancellationToken = default) + { + var jsonContent = JsonSerializer.Serialize(request, OpenAIClient.JsonSerializationOptions) + .ToJsonStringContent(EnableDebug); + var response = await Api.Client.PostAsync(GetUrl(), jsonContent, cancellationToken).ConfigureAwait(false); + var responseAsString = await response.ReadAsStringAsync(EnableDebug, cancellationToken).ConfigureAwait(false); + var created = JsonSerializer.Deserialize(responseAsString, OpenAIClient.JsonSerializationOptions); - return created; - } + return created; + } - /// - /// Retrieves a thread. - /// - /// The ID of the thread to retrieve. - /// - /// The thread object matching the specified ID. - public async Task RetrieveThreadAsync(string threadId, CancellationToken cancellationToken = default) - { - var response = await Api.Client.GetAsync(GetUrl($"/{threadId}"), cancellationToken).ConfigureAwait(false); - var responseAsString = await response.ReadAsStringAsync(EnableDebug, cancellationToken).ConfigureAwait(false); - var thread = JsonSerializer.Deserialize(responseAsString, OpenAIClient.JsonSerializationOptions); + /// + /// Retrieves a thread. + /// + /// The ID of the thread to retrieve. + /// + /// The thread object matching the specified ID. + public async Task RetrieveThreadAsync(string threadId, CancellationToken cancellationToken = default) + { + var response = await Api.Client.GetAsync(GetUrl($"/{threadId}"), cancellationToken).ConfigureAwait(false); + var responseAsString = await response.ReadAsStringAsync(EnableDebug, cancellationToken).ConfigureAwait(false); + var thread = JsonSerializer.Deserialize(responseAsString, OpenAIClient.JsonSerializationOptions); - return thread; - } + return thread; + } - /// - /// Modifies a thread. - /// - /// The ID of the thread to modify. Only the metadata can be modified. - /// Set of 16 key-value pairs that can be attached to an object. - /// This can be useful for storing additional information about the object in a structured format. - /// Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long. - /// - /// The modified thread object matching the specified ID. - public async Task ModifyThreadAsync(string threadId, Dictionary metadata, - CancellationToken cancellationToken = default) - { - var jsonContent = JsonSerializer.Serialize(new { metadata = metadata }, OpenAIClient.JsonSerializationOptions) - .ToJsonStringContent(EnableDebug); - var response = await Api.Client.PostAsync(GetUrl($"/{threadId}"), jsonContent, cancellationToken) - .ConfigureAwait(false); - var responseAsString = await response.ReadAsStringAsync(EnableDebug, cancellationToken).ConfigureAwait(false); - var thread = JsonSerializer.Deserialize(responseAsString, OpenAIClient.JsonSerializationOptions); + /// + /// Modifies a thread. + /// + /// The ID of the thread to modify. Only the metadata can be modified. + /// Set of 16 key-value pairs that can be attached to an object. + /// This can be useful for storing additional information about the object in a structured format. + /// Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long. + /// + /// The modified thread object matching the specified ID. + public async Task ModifyThreadAsync(string threadId, Dictionary metadata, + CancellationToken cancellationToken = default) + { + var jsonContent = JsonSerializer.Serialize(new { metadata = metadata }, OpenAIClient.JsonSerializationOptions) + .ToJsonStringContent(EnableDebug); + var response = await Api.Client.PostAsync(GetUrl($"/{threadId}"), jsonContent, cancellationToken) + .ConfigureAwait(false); + var responseAsString = await response.ReadAsStringAsync(EnableDebug, cancellationToken).ConfigureAwait(false); + var thread = JsonSerializer.Deserialize(responseAsString, OpenAIClient.JsonSerializationOptions); - return thread; - } + return thread; + } - /// - /// Delete a thread. - /// - /// The ID of the thread to delete. - /// - /// True, if was successfully deleted. - public async Task DeleteThreadAsync(string threadId, CancellationToken cancellationToken = default) - { - var response = await Api.Client.DeleteAsync(GetUrl($"/{threadId}"), cancellationToken).ConfigureAwait(false); - var responseAsString = await response.ReadAsStringAsync(EnableDebug, cancellationToken).ConfigureAwait(false); - var status = - JsonSerializer.Deserialize(responseAsString, OpenAIClient.JsonSerializationOptions); + /// + /// Delete a thread. + /// + /// The ID of the thread to delete. + /// + /// True, if was successfully deleted. + public async Task DeleteThreadAsync(string threadId, CancellationToken cancellationToken = default) + { + var response = await Api.Client.DeleteAsync(GetUrl($"/{threadId}"), cancellationToken).ConfigureAwait(false); + var responseAsString = await response.ReadAsStringAsync(EnableDebug, cancellationToken).ConfigureAwait(false); + var status = + JsonSerializer.Deserialize(responseAsString, OpenAIClient.JsonSerializationOptions); - return status.Deleted; - } + return status.Deleted; + } - private sealed class DeletionStatus - { - [JsonInclude] - [JsonPropertyName("id")] - public string Id { get; private set; } + private sealed class DeletionStatus + { + [JsonInclude] + [JsonPropertyName("id")] + public string Id { get; private set; } - [JsonInclude] - [JsonPropertyName("object")] - public string Object { get; private set; } + [JsonInclude] + [JsonPropertyName("object")] + public string Object { get; private set; } - [JsonInclude] - [JsonPropertyName("deleted")] - public bool Deleted { get; private set; } + [JsonInclude] + [JsonPropertyName("deleted")] + public bool Deleted { get; private set; } + } } } \ No newline at end of file