Created
April 3, 2025 19:12
-
-
Save atcarter714/7de44cd439ab7deddf7cd25fb8de4e57 to your computer and use it in GitHub Desktop.
A C# script file (CSX) implementing the OpenAI API (also works as regular C# code) ...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* -------------------------------------------------------------------------------- | |
| * Notes (AssistantsSchemas.cs) :: | |
| * -------------------------------------------------------------------------------- | |
| * This file contains a set of classes and interfaces that define the structure | |
| * of the JSON objects that are used to interact with the OpenAI API. These objects | |
| * are used to serialize and deserialize JSON data to and from C# objects. | |
| * We use System.Text.Json for this purpose, and the classes in this file are | |
| * designed to work with the default JSON serialization options provided by the | |
| * System.Text.Json library (higher performance than Newtonsoft.Json). | |
| * | |
| * This file is not 100% complete, and it is intended to be extended with additional | |
| * features and objects as needed (and as the OpenAI API evolves). | |
| * | |
| * Just recieved major cleanup/fixes in C# and CSX/notebook files. All compiler warnings | |
| * and errors have been resolved. The code is now ready for action. | |
| * -------------------------------------------------------------------------------- */ | |
| // ReSharper disable NotAccessedPositionalProperty.Global | |
| #if !CSX_SCRIPT | |
| namespace Arkaen.OpenAI.Schemas; | |
| #else | |
| #define CSX_SCRIPT | |
| #endif | |
| #region Using Directives | |
| using System ; | |
| using System.Linq ; | |
| using System.Text.Json ; | |
| using System.Threading.Tasks ; | |
| using System.Collections.Generic ; | |
| using System.Text.Json.Serialization ; | |
| #endregion | |
| /// <summary>Extension methods class (partial) for strings.</summary> | |
| public static class StringUtils { | |
| /// <summary>Converts the string to <c>snake_case</c> (Python/json) style.</summary> | |
| public static string ToSnakeCase( string str ) => | |
| string.Concat( str.Select( (x, i) => | |
| i > 0 && char.IsUpper(x) | |
| ? "_" + x | |
| : x.ToString() ) ).ToLower( ) ; | |
| public static string PythonToDotNetStyle( string str ) => | |
| string.Concat( | |
| str.Split('_') | |
| .Select( System.Threading.Thread.CurrentThread | |
| .CurrentCulture.TextInfo.ToTitleCase ) | |
| ) ; | |
| } ; | |
| /// <summary>Converts the names of properties from <c>snake_case</c> to <c>PascalCase</c>.</summary> | |
| public class PascalCaseNamingPolicy: JsonNamingPolicy { | |
| public override string ConvertName( string name ) => | |
| StringUtils.PythonToDotNetStyle( name ) ; | |
| } ; | |
| /// <summary>Helps define custom Json serialization strategies.</summary> | |
| public static class JsonOptions { | |
| public static JsonSerializerOptions DefaultJsonSerializerOptions => | |
| new JsonSerializerOptions { | |
| PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower, | |
| #if DEBUG | |
| WriteIndented = true, // Set to false in production for compact JSON | |
| #endif | |
| } ; | |
| public static JsonSerializerOptions EnumNameSerializerOptions => | |
| new JsonSerializerOptions { | |
| WriteIndented = true, | |
| Converters = { new JsonStringEnumConverter( JsonNamingPolicy.SnakeCaseLower ), }, | |
| } ; | |
| public static JsonSerializerOptions DeserializeAPIResponses => | |
| new JsonSerializerOptions { | |
| WriteIndented = true, | |
| Converters = { new JsonStringEnumConverter( new PascalCaseNamingPolicy() ), }, | |
| } ; | |
| } ; | |
| /// <summary>Base class for all JSON objects.</summary> | |
| public abstract class JsonObject { | |
| /// <summary>Converts the object to a JSON string.</summary> | |
| public virtual string ToJson( ) => | |
| JsonSerializer.Serialize( this, JsonOptions.DefaultJsonSerializerOptions ) ; | |
| /// <summary>Converts the object to a JSON string asynchronously.</summary> | |
| public async Task< string > ToJsonAsync( ) => await Task.Run( ( ) => ToJson( ) ) ; | |
| /// <summary>Converts a JSON string to an object of type <typeparamref name="T"/>.</summary> | |
| public static T? FromJson< T >( string json ) => | |
| JsonSerializer.Deserialize< T >( json, JsonOptions.DefaultJsonSerializerOptions ) ; | |
| } ; | |
| // ------------------------------------------------------------------------------- | |
| // OpenAI API Objects/DTOs :: | |
| // ------------------------------------------------------------------------------- | |
| /// <summary>Describes an OpenAI model offering that can be used with the API.</summary> | |
| public record Model ([property: JsonPropertyName("id")] string Id, | |
| [property: JsonPropertyName("object")] string Object, | |
| [property: JsonPropertyName("created")] int Created, | |
| [property: JsonPropertyName("owned_by")] string OwnedBy ) ; | |
| // -------------------------------- | |
| // API Response Objects :: | |
| // -------------------------------- | |
| /// <summary>API response (GET) containing a list of <see href="Model"/> objects.</summary> | |
| /// <param name="object">Always "list"</param> | |
| /// <param name="data">The list of <see href="Model"/> objects.</param> | |
| public record ModelsResponse( string @object, Model[ ] data ) ; | |
| // ------------------------------------------------------------------------------- | |
| // Assistants API :: | |
| // ------------------------------------------------------------------------------- | |
| /// <summary>Describes an "Assistant" object.</summary> | |
| /// <remarks>Partial class definition: can be extended in other files.</remarks> | |
| [Serializable] public class Assistant: JsonObject { | |
| /// <summary>The identifier, which can be referenced in API endpoints.</summary> | |
| [JsonPropertyName("id")] public string? Id { get; set; } | |
| /// <summary>The object type, which is always "assistant".</summary> | |
| [JsonPropertyName("object")] public string? Object { get; set; } | |
| /// <summary>The Unix timestamp (in seconds) for when the assistant was created.</summary> | |
| [JsonPropertyName("created_at")] public int CreatedAt { get; set; } | |
| /// <summary>The name of the assistant. The maximum length is 256 characters.</summary> | |
| [JsonPropertyName("name")] public string? Name { get; set; } | |
| /// <summary>The description of the assistant. The maximum length is 512 characters.</summary> | |
| [JsonPropertyName("description")] public string? Description { get; set; } | |
| /// <summary> | |
| /// 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. | |
| /// </summary> | |
| [JsonPropertyName("model")] public string? Model { get; set; } | |
| /// <summary>The system instructions that the assistant uses. The maximum length is 32768 characters.</summary> | |
| [JsonPropertyName("instructions")] public string? Instructions { get; set; } | |
| /// <summary>A list of tool enabled on the assistant. There can be a maximum of 128 tools per assistant.</summary> | |
| [JsonPropertyName("tools")] public Tool[ ]? Tools { get; set; } | |
| /// <summary> | |
| /// 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. | |
| /// </summary> | |
| [JsonPropertyName("file_ids")] public string[ ]? FileIds { get; set; } | |
| /// <summary> | |
| /// 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. | |
| /// </summary> | |
| [JsonPropertyName("metadata")] public Metadata? Metadata { get; set; } | |
| } ; | |
| // -------------------------------- | |
| // API Request Objects :: | |
| // -------------------------------- | |
| /// <summary> | |
| /// Query parameters for the <see href="AssistantsClient.ListAssistantsAsync"/> method. | |
| /// </summary> | |
| /// <param name="limit">The maximum number of <see href="Assistant"/> objects to return.</param> | |
| /// <param name="order">The sort order for the returned <see href="Assistant"/> objects.</param> | |
| /// <param name="after">A cursor for use in pagination.</param> | |
| /// <param name="before">A cursor for use in pagination.</param> | |
| public record AssistantsQueryParams( int limit = 20, string order = "desc", string after = "", string before = "" ) ; | |
| // -------------------------------- | |
| // API Response Objects :: | |
| // -------------------------------- | |
| /// <summary>API response containing a list of "Assistant" object data.</summary> | |
| public class AssistantsResponse: JsonObject { | |
| /// <summary>The object type, which is always "list".</summary> | |
| [JsonPropertyName("object")] public string? Object { get; set; } | |
| /// <summary>The list of <see href="Assistant"/> objects.</summary> | |
| /// <remarks>See <see href="AssistantsQueryParams"/> for query parameters.</remarks> | |
| [JsonPropertyName("data")] public Assistant[ ]? Data { get; set; } | |
| /// <summary>Cursor for use in pagination.</summary> | |
| [JsonPropertyName("first_id")] public string? FirstId { get; set; } | |
| /// <summary>Cursor for use in pagination.</summary> | |
| [JsonPropertyName("last_id")] public string? LastId { get; set; } | |
| /// <summary>Cursor for use in pagination.</summary> | |
| [JsonPropertyName("has_more")] public bool HasMore { get; set; } | |
| } ; | |
| /// <summary>API request object containing the data to create a new "Assistant" object.</summary> | |
| public class CreateAssistantRequest: JsonObject { | |
| /// <summary> | |
| /// 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. | |
| /// </summary> | |
| [JsonPropertyName("model")] public string? Model { get; set; } | |
| /// <summary>The name of the assistant. The maximum length is 256 characters.</summary> | |
| [JsonPropertyName("name")] public string? Name { get; set; } | |
| /// <summary>The description of the assistant. The maximum length is 512 characters.</summary> | |
| [JsonPropertyName("description")] public string? Description { get; set; } | |
| /// <summary>The system instructions that the assistant uses. The maximum length is 32768 characters.</summary> | |
| [JsonPropertyName("instructions")] public string? Instructions { get; set; } | |
| /// <summary> | |
| /// 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. | |
| /// </summary> | |
| [JsonPropertyName("tools")] public Tool[ ]? Tools { get; set; } | |
| /// <summary> | |
| /// 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. | |
| /// </summary> | |
| [JsonPropertyName("file_ids")] public string[ ]? FileIds { get; set; } | |
| /// <summary> | |
| /// 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 ... | |
| /// </summary> | |
| [JsonPropertyName("metadata")] public Dictionary< string, string >? Metadata { get; set; } | |
| } ; | |
| public class CreateAssistantResponse: Assistant { } | |
| public class CreateAssistantFileRequest: JsonObject { | |
| [JsonPropertyName("file_id")] public string? FileId { get; set; } | |
| } ; | |
| public class CreateAssistantFileResponse: AssistantFile { } | |
| [Serializable] public class ListAssistantsRequest: JsonObject { | |
| public int? Limit { get; set; } | |
| public string? Order { get; set; } | |
| public string? After { get; set; } | |
| public string? Before { get; set; } | |
| } ; | |
| [Serializable] public class ListAssistantsResponse: JsonObject { | |
| [JsonPropertyName("object")] public string? Object { get; set; } | |
| [JsonPropertyName("data")] public Assistant[ ]? Data { get; set; } | |
| [JsonPropertyName("first_id")] public string? FirstId { get; set; } | |
| [JsonPropertyName("last_id")] public string? LastId { get; set; } | |
| [JsonPropertyName("has_more")] public bool HasMore { get; set; } | |
| } ; | |
| [Serializable] public class ListAssistantFilesRequest: ListAssistantsRequest { } | |
| [Serializable] public class ListAssistantFilesResponse: JsonObject { | |
| [JsonPropertyName("object")] public string? Object { get; set; } | |
| [JsonPropertyName("data")] public AssistantFile[ ]? Data { get; set; } | |
| [JsonPropertyName("first_id")] public string? FirstId { get; set; } | |
| [JsonPropertyName("last_id")] public string? LastId { get; set; } | |
| [JsonPropertyName("has_more")] public bool HasMore { get; set; } | |
| } ; | |
| [Serializable] public class RetrieveAssistantResponse: Assistant { } | |
| [Serializable] public class RetrieveAssistantFileResponse: AssistantFile { } | |
| [Serializable] public class ModifyAssistantRequest: CreateAssistantRequest { } | |
| [Serializable] public class ModifyAssistantResponse: Assistant { } | |
| [Serializable] public class DeleteAssistantResponse: JsonObject { | |
| [JsonPropertyName("id")] public string? Id { get; set; } | |
| [JsonPropertyName("object")] public string? Object { get; set; } | |
| [JsonPropertyName("deleted")] public bool Deleted { get; set; } | |
| } ; | |
| [Serializable] public class DeleteAssistantFileResponse: DeleteAssistantResponse { } | |
| [Serializable] public class AssistantUpdateRequest: JsonObject { | |
| [JsonPropertyName("name")] public string? Name { get; set; } | |
| [JsonPropertyName("description")] public string? Description { get; set; } | |
| [JsonPropertyName("model")] public string? Model { get; set; } | |
| [JsonPropertyName("instructions")] public string? Instructions { get; set; } | |
| [JsonPropertyName("tools")] public Tool[ ]? Tools { get; set; } | |
| [JsonPropertyName("file_ids")] public string[ ]? FileIds { get; set; } | |
| [JsonPropertyName("metadata")] public Dictionary<string, string>? Metadata { get; set; } | |
| } ; | |
| // ------------------------------------------------------------------------------- | |
| [Serializable] public class Thread: JsonObject { | |
| [JsonPropertyName("id")] public string? Id { get; set; } | |
| [JsonPropertyName("object")] public string? Object { get; set; } | |
| [JsonPropertyName("created_at")] public int CreatedAt { get; set; } | |
| [JsonPropertyName("metadata")] public Dictionary< string, string >? Metadata { get; set; } | |
| } ; | |
| [Serializable] public class Message: JsonObject { | |
| [JsonPropertyName("id")] public string? Id { get; set; } | |
| [JsonPropertyName("object")] public string? Object { get; set; } | |
| [JsonPropertyName("created_at")] public int CreatedAt { get; set; } | |
| [JsonPropertyName("thread_id")] public string? ThreadId { get; set; } | |
| [JsonPropertyName("role")] public string? Role { get; set; } | |
| [JsonPropertyName("content")] public List<Content>? Content { get; set; } | |
| [JsonPropertyName("file_ids")] public List<string>? FileIds { get; set; } | |
| [JsonPropertyName("assistant_id")] public string? AssistantId { get; set; } | |
| [JsonPropertyName("run_id")] public string? RunId { get; set; } | |
| [JsonPropertyName("metadata")] public Dictionary<string, string>? Metadata { get; set; } | |
| } ; | |
| [Serializable] public class Content: JsonObject { | |
| [JsonPropertyName("type")] public string? Type { get; set; } | |
| [JsonPropertyName("text")] public TextContent? Text { get; set; } | |
| } ; | |
| /// <summary>Describes a token and its associated log probability.</summary> | |
| [Serializable] public class ContentInfo: JsonObject { | |
| /// <summary>The generated token.</summary> | |
| [JsonPropertyName( "token" )] public string? Token { get ; set ; } | |
| /// <summary>The log probability of the token.</summary> | |
| [JsonPropertyName( "logprob" )] public double LogProb { get ; set ; } | |
| /// <summary>The byte representation of the token.</summary> | |
| [JsonPropertyName( "bytes" )] public int[ ]? Bytes { get ; set ; } | |
| /// <summary>An array of the most likely subsequent tokens and their log probabilities.</summary> | |
| [JsonPropertyName( "top_logprobs" )] public TopLogProbs[ ]? TopLogProbs { get ; set ; } | |
| } ; | |
| [Serializable] public class TextContent: JsonObject { | |
| [JsonPropertyName("value")] public string? Value { get; set; } | |
| [JsonPropertyName("annotations")] public List< string >? Annotations { get; set; } | |
| } ; | |
| [Serializable] public class Run: JsonObject { | |
| [JsonPropertyName("id")] public string? Id { get; set; } | |
| [JsonPropertyName("object")] public string? Object { get; set; } | |
| [JsonPropertyName("created_at")] public int CreatedAt { get; set; } | |
| [JsonPropertyName("thread_id")] public string? ThreadId { get; set; } | |
| [JsonPropertyName("assistant_id")] public string? AssistantId { get; set; } | |
| [JsonPropertyName("status")] public string? Status { get; set; } | |
| [JsonPropertyName("required_action")] public RequiredAction? RequiredAction { get; set; } | |
| [JsonPropertyName("last_error")] public object? LastError { get; set; } // Adjust the type based on the structure of the error object | |
| [JsonPropertyName("expires_at")] public int? ExpiresAt { get; set; } | |
| [JsonPropertyName("started_at")] public int? StartedAt { get; set; } | |
| [JsonPropertyName("cancelled_at")] public int? CancelledAt { get; set; } | |
| [JsonPropertyName("failed_at")] public int? FailedAt { get; set; } | |
| [JsonPropertyName("completed_at")] public int? CompletedAt { get; set; } | |
| [JsonPropertyName("model")] public string? Model { get; set; } | |
| [JsonPropertyName("instructions")] public string? Instructions { get; set; } | |
| [JsonPropertyName("tools")] public List<Tool>? Tools { get; set; } | |
| [JsonPropertyName("file_ids")] public List<string>? FileIds { get; set; } | |
| [JsonPropertyName("metadata")] public Dictionary<string, string>? Metadata { get; set; } | |
| } ; | |
| [Serializable] public class RequiredAction: JsonObject { | |
| [JsonPropertyName("type")] public string? Type { get; set; } | |
| [JsonPropertyName("submit_tool_outputs")] public SubmitToolOutputs? SubmitToolOutputs { get; set; } | |
| } ; | |
| [Serializable] public class SubmitToolOutputs: JsonObject { | |
| [JsonPropertyName("tool_calls")] public List< ToolCall >? ToolCalls { get; set; } | |
| } ; | |
| [Serializable] public class ToolCall: JsonObject { | |
| [JsonPropertyName("id")] public string? Id { get; set; } | |
| [JsonPropertyName("type")] public string? Type { get; set; } | |
| [JsonPropertyName("function")] public FunctionCall? Function { get; set; } | |
| } ; | |
| [Serializable] public class FunctionCall: JsonObject { | |
| [JsonPropertyName("name")] public string? Name { get; set; } | |
| // Adjust the type if arguments are structured differently | |
| [JsonPropertyName("arguments")] public string? Arguments { get; set; } | |
| } ; | |
| /// <summary>Result of a call to a custom <see href="Function"/>.</summary> | |
| [Serializable] public class FunctionCallResult: JsonObject { | |
| /// <summary>The ID of the function call.</summary> | |
| [JsonPropertyName("id")] public string? Id { get; set; } | |
| /// <summary>The type of the tool. Currently, only function is supported.</summary> | |
| [JsonPropertyName("type")] public string? Type { get; set; } | |
| /// <summary>The function that the model called.</summary> | |
| [JsonPropertyName("function")] public Function? Function { get; set; } | |
| } ; | |
| [Serializable] public class RunStep: JsonObject { | |
| [JsonPropertyName("id")] public string? Id { get; set; } | |
| [JsonPropertyName("object")] public string? Object { get; set; } | |
| [JsonPropertyName("created_at")] public int CreatedAt { get; set; } | |
| [JsonPropertyName("run_id")] public string? RunId { get; set; } | |
| [JsonPropertyName("assistant_id")] public string? AssistantId { get; set; } | |
| [JsonPropertyName("thread_id")] public string? ThreadId { get; set; } | |
| [JsonPropertyName("type")] public string? Type { get; set; } | |
| [JsonPropertyName("status")] public string? Status { get; set; } | |
| [JsonPropertyName("step_details")] public StepDetails? StepDetails { get; set; } | |
| // Adjust the type based on the structure of the error object | |
| [JsonPropertyName("last_error")] public object? LastError { get; set; } | |
| [JsonPropertyName("expired_at")] public int? ExpiredAt { get; set; } | |
| [JsonPropertyName("cancelled_at")] public int? CancelledAt { get; set; } | |
| [JsonPropertyName("failed_at")] public int? FailedAt { get; set; } | |
| [JsonPropertyName("completed_at")] public int? CompletedAt { get; set; } | |
| [JsonPropertyName("metadata")] public Dictionary<string, string>? Metadata { get; set; } | |
| } ; | |
| [Serializable] public class StepDetails: JsonObject { | |
| [JsonPropertyName("type")] public string? Type { get; set; } | |
| [JsonPropertyName("message_creation")] public MessageCreationDetails? MessageCreation { get; set; } | |
| } ; | |
| [Serializable] public class MessageCreationDetails: JsonObject { | |
| [JsonPropertyName("message_id")] public string? MessageId { get; set; } | |
| } ; | |
| // ------------------------------------------------------------------------------- | |
| /// <summary>Represents the kinds of available <see href="Tool"/> selections that can be called</summary> | |
| [Serializable, JsonConverter(typeof(JsonStringEnumConverter)),] | |
| public enum ToolsTypes: uint { | |
| [JsonPropertyName("code_interpreter")] CodeInterpreter, | |
| [JsonPropertyName("retrieval")] Retrieval, | |
| [JsonPropertyName("function")] Function, | |
| [JsonPropertyName("custom")] Custom, | |
| } ; | |
| [Serializable] public class ToolChoice: JsonObject { | |
| [JsonPropertyName("type")] public string? Type { get; set; } | |
| [JsonPropertyName("function")] public FunctionChoice? Function { get; set; } | |
| } ; | |
| [Serializable] public class FunctionChoice: JsonObject { | |
| [JsonPropertyName("name")] public string? Name { get; set; } | |
| } ; | |
| /// <summary>Describes a "function" tool the assistant can call.</summary> | |
| [Serializable] public class Function: JsonObject { | |
| /// <summary>The name of the function.</summary> | |
| [JsonPropertyName("name")] public string? Name { get; set; } | |
| /// <summary>A description of what the function does, used by the | |
| /// model to choose when and how to call the function.</summary> | |
| [JsonPropertyName("description")] public string? Description { get; set; } | |
| /// <summary> | |
| /// The parameters the functions accepts, described as a JSON Schema object. | |
| /// See the <a href="https://platform.openai.com/docs/guides/text-generation/function-calling">guide</a> | |
| /// for examples, and the JSON Schema reference for documentation about the format. | |
| /// </summary> | |
| [JsonPropertyName("parameters")] public object? Parameters { get; set; } | |
| } ; | |
| /// <summary>Describes a "tool" for the assistant to use.</summary> | |
| [Serializable] public class Tool: JsonObject { | |
| [JsonPropertyName("type")] public ToolsTypes Type { get; set; } // snake_case: | |
| [JsonPropertyName("function")] public Function? Function { get; set; } | |
| } ; | |
| /// <summary>Contains a list of tools for an assistant (i.e., in an API response object).</summary> | |
| [Serializable] public class ToolsList: JsonObject { | |
| /// <summary>Gets or sets the array of <see href="Tool"/> items.</summary> | |
| [JsonPropertyName("tools")] public Tool[ ]? Tools { get; set; } | |
| } ; | |
| /// <summary>Metadata object for "Assistant" objects.</summary> | |
| /// <remarks>Partial class definition: can be extended in other files.</remarks> | |
| [Serializable] public class Metadata: JsonObject { } ; | |
| /// <summary>Represents the intended purpose of a file.</summary> | |
| /// <remarks> | |
| /// Supported values are <c>fine-tune</c>, <c>fine-tune-results</c>, | |
| /// <c>assistants</c>, and <c>assistants_output</c>. | |
| /// </remarks> | |
| [JsonConverter(typeof(JsonStringEnumConverter))] | |
| public enum Purpose { | |
| [JsonPropertyName("fine-tune")] FineTune, | |
| [JsonPropertyName("fine-tune-results")] FineTuneResults, | |
| [JsonPropertyName("assistants")] Assistants, | |
| [JsonPropertyName("assistants_output")] AssistantsOutput, | |
| } ; | |
| /// <summary>The File object represents a document that has been uploaded to OpenAI.</summary> | |
| [Serializable] public class File: JsonObject { | |
| /// <summary>The file identifier, which can be referenced in the API endpoints.</summary> | |
| [JsonPropertyName("id")] public int Id { get; set; } | |
| /// <summary>The name of the file.</summary> | |
| [JsonPropertyName("object")] public string Object { get; set; } = "file" ; | |
| /// <summary>The size of the file, in bytes.</summary> | |
| [JsonPropertyName("bytes")] public int Bytes { get; set; } | |
| /// <summary>The Unix timestamp (in seconds) for when the file was created.</summary> | |
| [JsonPropertyName("created_at")] public int CreatedAt { get; set; } | |
| /// <summary>The name of the file.</summary> | |
| [JsonPropertyName("filename")] public string? Filename { get; set; } | |
| /// <summary>The purpose of the file.</summary> | |
| [JsonPropertyName("purpose")] public Purpose Purpose { get; set; } | |
| } ; | |
| /// <summary>Describes a "chat completion" object.</summary> | |
| [Serializable] public class ChatCompletion: JsonObject { | |
| /// <summary>A unique identifier for the chat completion.</summary> | |
| [JsonPropertyName("id")] public string? Id { get; set; } | |
| /// <summary>The object type, which is always chat.completion.</summary> | |
| [JsonPropertyName("object")] public string? Object { get; set; } | |
| /// <summary>The Unix timestamp (in seconds) for when the chat completion was created.</summary> | |
| [JsonPropertyName("created")] public int Created { get; set; } | |
| /// <summary>The model name/id used for the chat completion.</summary> | |
| [JsonPropertyName("model")] public string? Model { get; set; } | |
| /// <summary> | |
| /// This fingerprint represents the backend configuration that the model runs with. | |
| /// Can be used in conjunction with the seed request parameter to understand when | |
| /// backend changes have been made that might impact determinism. | |
| /// </summary> | |
| [JsonPropertyName("system_fingerprint")] public string? SystemFingerprint { get; set; } | |
| /// <summary>A list of chat completion choices. Can be more than one if n is greater than 1.</summary> | |
| [JsonPropertyName("choices")] public Choice[ ]? Choices { get; set; } | |
| /// <summary>Usage statistics for the completion request.</summary> | |
| [JsonPropertyName("usage")] public Usage? Usage { get; set; } | |
| } ; | |
| /// <summary>Describes a "choice" object.</summary> | |
| [Serializable] public class Choice: JsonObject { | |
| /// <summary>The index of the choice in the list of choices.</summary> | |
| [JsonPropertyName("index")] public int Index { get; set; } | |
| /// <summary>A chat completion message generated by the model.</summary> | |
| [JsonPropertyName("message")] public Message? Message { get; set; } | |
| /// <summary> | |
| /// Whether to return log probabilities of the output tokens or not. | |
| /// If true, returns the log probabilities of each output token returned in the content of message. | |
| /// This option is currently not available on the gpt-4-vision-preview model. | |
| /// </summary> | |
| [JsonPropertyName("logprobs")] public object? Logprobs { get; set; } | |
| /// <summary> | |
| /// The reason the model stopped generating tokens. This will be stop if the model hit a natural stop point | |
| /// or a provided stop sequence, length if the maximum number of tokens specified in the request was reached, | |
| /// content_filter if content was omitted due to a flag from our content filters, tool_calls if the model | |
| /// called a tool, or function_call (deprecated) if the model called a function. | |
| /// </summary> | |
| [JsonPropertyName("finish_reason")] public string? FinishReason { get; set; } | |
| } ; | |
| /// <summary>Describes the role of the sender/creator of the message.</summary> | |
| [Serializable, JsonConverter(typeof(JsonStringEnumConverter))] public enum Role { | |
| /// <summary>Message from the system instructing the agent how to behave.</summary> | |
| [JsonPropertyName("system")] System, | |
| /// <summary>Message from the assistant.</summary> | |
| [JsonPropertyName("assistant")] Assistant, | |
| /// <summary>Message from the user.</summary> | |
| [JsonPropertyName("user")] User, | |
| /// <summary>Message or result returned from a <see href="Function"/> call.</summary> | |
| [JsonPropertyName("function")] Function, | |
| /// <summary>Message or result returned from a <see href="Tool"/> call.</summary> | |
| [JsonPropertyName("tool")] Tool, | |
| } ; | |
| /// <summary>Describes a "usage" object.</summary> | |
| [Serializable] public class Usage: JsonObject { | |
| [JsonPropertyName("prompt_tokens")] public int PromptTokens { get; set; } | |
| [JsonPropertyName("completion_tokens")] public int CompletionTokens { get; set; } | |
| [JsonPropertyName("total_tokens")] public int TotalTokens { get; set; } | |
| } ; | |
| /// <summary>Represents <see cref="File"/>s attached to an assistant.</summary> | |
| [Serializable] public class AssistantFile: JsonObject { | |
| [JsonPropertyName("id")] public string? Id { get; set; } | |
| [JsonPropertyName("object")] public string? Object { get; set; } | |
| [JsonPropertyName("created_at")] public int CreatedAt { get; set; } | |
| [JsonPropertyName("assistant_id")] public string? AssistantId { get; set; } | |
| } ; | |
| /// <summary>Describes a "message" object.</summary> | |
| [Serializable] public class MessageFile: JsonObject { | |
| [JsonPropertyName("id")] public string? Id { get; set; } | |
| [JsonPropertyName("object")] public string? Object { get; set; } | |
| [JsonPropertyName("created_at")] public int CreatedAt { get; set; } | |
| [JsonPropertyName("message_id")] public string? MessageId { get; set; } | |
| } ; | |
| // ------------------------------------------------------------------------------- | |
| // Completion Helper Objects :: | |
| // ------------------------------------------------------------------------------- | |
| /// <summary>Describes the format that the model must output.</summary> | |
| public class ResponseFormat: JsonObject { | |
| /// <summary>The type of response format, e.g., 'text' or 'json_object'.</summary> | |
| [JsonPropertyName("type")] public string? Type { get; set; } | |
| } ; | |
| /// <summary>Represents the log probabilities of tokens generated in a completion.</summary> | |
| public class LogProbs: JsonObject { | |
| /// <summary>An array of content objects representing tokens and their log probabilities.</summary> | |
| [JsonPropertyName("content")] public Content[ ]? Content { get; set; } | |
| } ; | |
| /// <summary>Describes the most likely subsequent tokens and their log probabilities.</summary> | |
| public class TopLogProbs: JsonObject { | |
| /// <summary>The subsequent token.</summary> | |
| [JsonPropertyName( "token" )] public string? Token { get ; set ; } | |
| /// <summary>The log probability of the subsequent token.</summary> | |
| [JsonPropertyName( "logprob" )] public double LogProb { get ; set ; } | |
| /// <summary>The byte representation of the subsequent token.</summary> | |
| [JsonPropertyName( "bytes" )] public int[ ]? Bytes { get ; set ; } | |
| } ; | |
| // ----------------------------------------------------------- | |
| // Message Types: | |
| // ----------------------------------------------------------- | |
| /// <summary>Describes a "message" object.</summary> | |
| public class MessageBase: JsonObject { | |
| /// <summary>The role of the author of this message.</summary> | |
| [JsonPropertyName("role")] public Role Role { get; set; } | |
| /// <summary>The content of the message.</summary> | |
| [JsonPropertyName("content")] public string? Content { get; set; } | |
| } ; | |
| /// <summary>A named <see href="Message"/> object with a <c>system</c> role.</summary> | |
| public class SystemMessage: Message { | |
| /// <summary>An optional name for the participant. Provides the model information to differentiate between participants of the same role.</summary> | |
| [JsonPropertyName("name")] public string? Name { get; } = "system" ; | |
| } ; | |
| /// <summary>A named <see href="Message"/> object with a <c>user</c> role.</summary> | |
| public class UserMessage: Message { | |
| /// <summary>An optional name for the participant. Provides the model information to differentiate between participants of the same role.</summary> | |
| [JsonPropertyName("name")] public string? Name { get; set; } | |
| } ; | |
| /// <summary>A named <see href="Message"/> object with an <c>assistant</c> role.</summary> | |
| public class AssistantMessage: Message { | |
| /// <summary>An optional name for the participant.</summary> | |
| [JsonPropertyName("name")] public string? Name { get; set; } | |
| } ; | |
| /// <summary>A <see href="Message"/> object with an <c>tool_call_id</c> and the special <c>tool</c> role.</summary> | |
| public class ToolMessage: Message { | |
| /// <summary>Tool call that this message is responding to.</summary> | |
| [JsonPropertyName("tool_call_id")] public string? ToolCallId { get; set; } | |
| } ; | |
| /// <summary>The "FunctionMessage" is marked as deprecated.</summary> | |
| [Obsolete] public class FunctionMessage: Message { | |
| /// <summary>The name of the function to call.</summary> | |
| [JsonPropertyName("name")] public string Name { get; set; } = "" ; | |
| } ; | |
| // ------------------------------------------------------------------------------- | |
| // Prompts API :: | |
| // ------------------------------------------------------------------------------- | |
| /// <summary>Describes a "prompt" object for generating completions.</summary> | |
| public class Prompt: JsonObject { | |
| /// <summary>The ID of the prompt.</summary> | |
| [JsonPropertyName( "id" )] public string? Id { get ; set ; } | |
| /// <summary>The object type, which is always "prompt".</summary> | |
| [JsonPropertyName( "object" )] public string? Object { get ; set ; } | |
| /// <summary>The Unix timestamp (in seconds) for when the prompt was created.</summary> | |
| [JsonPropertyName( "created_at" )] public int CreatedAt { get ; set ; } | |
| /// <summary>The input text of the prompt.</summary> | |
| [JsonPropertyName( "prompt_text" )] public string? PromptText { get ; set ; } | |
| /// <summary>The model used for generating completions for this prompt.</summary> | |
| [JsonPropertyName( "model" )] public string? Model { get ; set ; } | |
| } ; | |
| /// <summary>API response containing a list of "Prompt" object data.</summary> | |
| public class PromptsResponse: JsonObject { | |
| /// <summary>The object type, which is always "list".</summary> | |
| [JsonPropertyName( "object" )] public string? Object { get ; set ; } | |
| /// <summary>The list of <see href="Prompt"/> objects.</summary> | |
| [JsonPropertyName( "data" )] public Prompt[ ]? Data { get ; set ; } | |
| /// <summary>Cursor for use in pagination.</summary> | |
| [JsonPropertyName( "next_cursor" )] public string? NextCursor { get ; set ; } | |
| /// <summary>Cursor for use in pagination.</summary> | |
| [JsonPropertyName( "previous_cursor" )] public string? PreviousCursor { get ; set ; } | |
| } ; | |
| // ------------------------------------------------------------------------------- | |
| // Completion Requests :: | |
| // ------------------------------------------------------------------------------- | |
| /// <summary>Describes a request for generating a completion.</summary> | |
| public class CompletionRequest: JsonObject { | |
| /// <summary>The prompt to generate completions for.</summary> | |
| [JsonPropertyName("prompt")] public string? Prompt { get; set; } | |
| /// <summary>The maximum number of tokens to generate.</summary> | |
| [JsonPropertyName("max_tokens")] public int MaxTokens { get; set; } | |
| /// <summary>What sampling temperature to use.</summary> | |
| [JsonPropertyName("temperature")] public float Temperature { get; set; } | |
| /// <summary>Include the log probabilities on the logprobs most likely tokens.</summary> | |
| [JsonPropertyName("top_p")] public float TopP { get; set; } | |
| /// <summary>How many completions to generate for each prompt.</summary> | |
| [JsonPropertyName("n")] public int N { get; set; } | |
| /// <summary>Whether to stream back partial progress.</summary> | |
| [JsonPropertyName("stream")] public bool Stream { get; set; } | |
| /// <summary>Up to 4 sequences where the API will stop generating further tokens.</summary> | |
| [JsonPropertyName("stop")] public string[ ]? Stop { get; set; } | |
| } ; | |
| // ------------------------------------------------------------------------------- | |
| // Additional Helper Objects :: | |
| // ------------------------------------------------------------------------------- | |
| /// <summary>Describes a "log probability" object.</summary> | |
| public class LogProbability: JsonObject { | |
| /// <summary>The token for which the log probability is calculated.</summary> | |
| [JsonPropertyName( "token" )] public string? Token { get ; set ; } | |
| /// <summary>The log probability of the token.</summary> | |
| [JsonPropertyName( "logprob" )] public double LogProb { get ; set ; } | |
| } ; | |
| /// <summary>Describes a "token" object.</summary> | |
| public class Token: JsonObject { | |
| /// <summary>The text of the token.</summary> | |
| [JsonPropertyName("text")] public string? Text { get; set; } | |
| /// <summary>The index of the token in the completion.</summary> | |
| [JsonPropertyName("index")] public int Index { get; set; } | |
| } ; | |
| // ===================================================================================================================== | |
| // ===================================================================================================================== | |
| public class CreateChatCompletionRequest: JsonObject { | |
| [JsonPropertyName("messages")] public Message[ ]? Messages { get; set; } | |
| [JsonPropertyName("model")] public string? Model { get; set; } | |
| [JsonPropertyName("frequency_penalty")] public double? FrequencyPenalty { get; set; } | |
| [JsonPropertyName("logit_bias")] public Dictionary<string, double>? LogitBias { get; set; } | |
| [JsonPropertyName("logprobs")] public bool? Logprobs { get; set; } | |
| [JsonPropertyName("top_logprobs")] public int? TopLogprobs { get; set; } | |
| [JsonPropertyName("max_tokens")] public int? MaxTokens { get; set; } | |
| [JsonPropertyName("n")] public int? N { get; set; } | |
| [JsonPropertyName("presence_penalty")] public double? PresencePenalty { get; set; } | |
| [JsonPropertyName("response_format")] public ResponseFormat? ResponseFormat { get; set; } | |
| [JsonPropertyName("seed")] public int? Seed { get; set; } | |
| [JsonPropertyName("stop")] public string[ ]? Stop { get; set; } | |
| [JsonPropertyName("stream")] public bool? Stream { get; set; } | |
| [JsonPropertyName("temperature")] public double? Temperature { get; set; } | |
| [JsonPropertyName("top_p")] public double? TopP { get; set; } | |
| [JsonPropertyName("tools")] public Tool[ ]? Tools { get; set; } | |
| [JsonPropertyName("tool_choice")] public ToolChoice? ToolChoice { get; set; } | |
| [JsonPropertyName("user")] public string? User { get; set; } | |
| // Deprecated properties: | |
| [JsonPropertyName("function_call")] public string? FunctionCall { get; set; } | |
| [JsonPropertyName("functions")] public Function[]? Functions { get; set; } | |
| } ; | |
| public class ChatCompletionResponse: JsonObject { | |
| [JsonPropertyName("id")] public string? Id { get; set; } | |
| [JsonPropertyName("object")] public string? Object { get; set; } | |
| [JsonPropertyName("created")] public int Created { get; set; } | |
| [JsonPropertyName("model")] public string? Model { get; set; } | |
| [JsonPropertyName("system_fingerprint")] public string? SystemFingerprint { get; set; } | |
| [JsonPropertyName("choices")] public Choice[ ]? Choices { get; set; } | |
| [JsonPropertyName("usage")] public Usage? Usage { get; set; } | |
| } ; | |
| /// <summary> | |
| /// Represents a streamed chunk of a chat completion response | |
| /// returned by model, based on the provided input. | |
| /// </summary> | |
| public class ChatCompletionChunk: JsonObject { | |
| /// <summary>A unique identifier for the chat completion. Each chunk has the same ID.</summary> | |
| [JsonPropertyName("id")] public string? Id { get; set; } | |
| /// <summary>The object type, which is always chat.completion.</summary> | |
| [JsonPropertyName("object")] public string? Object { get; set; } | |
| /// <summary>The Unix timestamp (in seconds) for when the chat completion was created.</summary> | |
| [JsonPropertyName("created")] public int Created { get; set; } | |
| /// <summary>The model name/id used for the chat completion.</summary> | |
| [JsonPropertyName("model")] public string? Model { get; set; } | |
| /// <summary>This fingerprint represents the backend configuration that the model runs with.</summary> | |
| [JsonPropertyName("system_fingerprint")] public string? SystemFingerprint { get; set; } | |
| /// <summary>A list of chat completion choices. Can be more than one if n is greater than 1.</summary> | |
| [JsonPropertyName("choices")] public ChunkChoice[ ]? Choices { get; set; } | |
| } ; | |
| public class ChunkChoice: JsonObject { | |
| /// <summary>A unique identifier for the chat completion. Each chunk has the same ID.</summary> | |
| [JsonPropertyName("index")] public int Index { get; set; } | |
| /// <summary>The object type, which is always chat.completion.</summary> | |
| [JsonPropertyName("delta")] public Delta? Delta { get; set; } | |
| /// <summary>The Unix timestamp (in seconds) for when the chat completion was created.</summary> | |
| [JsonPropertyName("logprobs")] public object? Logprobs { get; set; } | |
| /// <summary>The model name/id used for the chat completion.</summary> | |
| [JsonPropertyName("finish_reason")] public string? FinishReason { get; set; } | |
| } ; | |
| public class Delta: JsonObject { | |
| [JsonPropertyName("content")] public string? Content { get; set; } | |
| [JsonPropertyName("function_call")] public FunctionCall? FunctionCall { get; set; } | |
| [JsonPropertyName("tool_calls")] public ToolCall[ ]? ToolCalls { get; set; } | |
| [JsonPropertyName("role")] public string? Role { get; set; } | |
| } ; | |
| // ===================================================================================================================== | |
| // ===================================================================================================================== | |
| // ------------------------------------------------------------------------------- | |
| // Fine-Tuning Objects :: | |
| // POST -> https://api.openai.com/v1/fine_tuning/ | |
| // ------------------------------------------------------------------------------- | |
| /// <summary>Describes a "fine-tune" object.</summary> | |
| public class FineTuneJob: JsonObject { | |
| /// <summary>The object type, which is always fine-tuning.job.</summary> | |
| [JsonPropertyName("object")] public string Object { get; set; } = "fine-tuning.job" ; | |
| /// <summary>The object identifier, which can be referenced in the API endpoints.</summary> | |
| [JsonPropertyName("id")] public string? Id { get; set; } | |
| /// <summary>The organization that owns the fine-tuning job.</summary> | |
| [JsonPropertyName("organization_id")] public string? OrganizationId { get; set; } | |
| /// <summary>The Unix timestamp (in seconds) for when the fine-tuning job was created.</summary> | |
| [JsonPropertyName("created_at")] public int CreatedAt { get; set; } | |
| /// <summary> | |
| /// The Unix timestamp (in seconds) for when the fine-tuning job was finished. | |
| /// The value will be null if the fine-tuning job is still running. | |
| /// </summary> | |
| [JsonPropertyName("finished_at")] public int FinishedAt { get; set; } | |
| [JsonPropertyName("completed")] public int Completed { get; set; } | |
| [JsonPropertyName("training_file")] public string? TrainingFile { get; set; } | |
| /// <summary>The base model that is being fine-tuned.</summary> | |
| [JsonPropertyName("model")] public string? Model { get; set; } | |
| /// <summary> | |
| /// The name of the fine-tuned model that is being created. | |
| /// The value will be null if the fine-tuning job is still running. | |
| /// </summary> | |
| [JsonPropertyName("fine_tuned_model")] public string? FineTunedModel { get; set; } | |
| [JsonPropertyName("error")] public ErrorObject? Error { get; set; } | |
| /// <summary> | |
| /// The current status of the fine-tuning job, which can be either | |
| /// <c>validating_files</c>, <c>queued</c>, <c>running</c>, | |
| /// <c>succeeded</c>, <c>failed</c>, or <c>cancelled</c>. | |
| /// </summary> | |
| [JsonPropertyName("status")] public string? Status { get; set; } | |
| /// <summary> | |
| /// The compiled results file ID(s) for the fine-tuning job. | |
| /// You can retrieve the results with the Files API. | |
| /// </summary> | |
| [JsonPropertyName("result_files")] public string[ ]? ResultFiles { get; set; } | |
| [JsonPropertyName("validation_file")] public string? ValidationFile { get; set; } | |
| [JsonPropertyName("hyperparameters")] public Hyperparameters? Hyperparameters { get; set; } | |
| /// <summary> | |
| /// The total number of billable tokens processed by this fine-tuning job. | |
| /// The value will be null if the fine-tuning job is still running. | |
| /// </summary> | |
| [JsonPropertyName("trained_tokens")] public int? TrainedTokens { get; set; } | |
| } ; | |
| public class FineTuningJobCreateRequest: JsonObject { | |
| [JsonPropertyName("model")] public string? Model { get; set; } | |
| [JsonPropertyName("training_file")] public string? TrainingFile { get; set; } | |
| [JsonPropertyName("hyperparameters")] public object? Hyperparameters { get; set; } | |
| [JsonPropertyName("suffix")] public string? Suffix { get; set; } | |
| [JsonPropertyName("validation_file")] public string? ValidationFile { get; set; } | |
| } ; | |
| public class FineTuningJob: JsonObject { | |
| [JsonPropertyName("id")] public string? Id { get; set; } | |
| [JsonPropertyName("object")] public string? Object { get; set; } | |
| [JsonPropertyName("created_at")] public int CreatedAt { get; set; } | |
| [JsonPropertyName("model")] public string? Model { get; set; } | |
| [JsonPropertyName("status")] public string? Status { get; set; } | |
| [JsonPropertyName("training_file")] public string? TrainingFile { get; set; } | |
| [JsonPropertyName("validation_file")] public string? ValidationFile { get; set; } | |
| [JsonPropertyName("hyperparameters")] public object? Hyperparameters { get; set; } | |
| [JsonPropertyName("fine_tuned_model")] public string? FineTunedModel { get; set; } | |
| [JsonPropertyName("organization_id")] public string? OrganizationId { get; set; } | |
| [JsonPropertyName("result_files")] public string[ ]? ResultFiles { get; set; } | |
| } ; | |
| public class FineTuningJobsListRequest: JsonObject { | |
| [JsonPropertyName("after")] public string? After { get; set; } | |
| [JsonPropertyName("limit")] public int Limit { get; set; } | |
| } ; | |
| public class FineTuningEventsListRequest: JsonObject { | |
| [JsonPropertyName("fine_tuning_job_id")] public string? FineTuningJobId { get; set; } | |
| [JsonPropertyName("after")] public string? After { get; set; } | |
| [JsonPropertyName("limit")] public int Limit { get; set; } | |
| } ; | |
| public class FineTuningJobEvent: JsonObject { | |
| [JsonPropertyName("id")] public string? Id { get; set; } | |
| [JsonPropertyName("object")] public string? Object { get; set; } | |
| [JsonPropertyName("created_at")] public int CreatedAt { get; set; } | |
| [JsonPropertyName("level")] public string? Level { get; set; } | |
| [JsonPropertyName("message")] public string? Message { get; set; } | |
| } ; | |
| public class FineTuningJobRetrieveRequest: JsonObject { | |
| [JsonPropertyName("fine_tuning_job_id")] public string? FineTuningJobId { get; set; } | |
| } ; | |
| public class FineTuningJobCancelRequest: JsonObject { | |
| [JsonPropertyName("fine_tuning_job_id")] public string? FineTuningJobId { get; set; } | |
| } ; | |
| public class ErrorObject: JsonObject { | |
| /// <summary> | |
| /// For fine-tuning jobs that have failed, this will contain more information on the cause of the failure. | |
| /// A machine-readable error code. | |
| /// </summary> | |
| [JsonPropertyName("code")] public string? Code { get; set; } | |
| /// <summary>A human-readable error message.</summary> | |
| [JsonPropertyName("message")] public string? Message { get; set; } | |
| /// <summary> | |
| /// The parameter that was invalid, usually training_file or validation_file. | |
| /// This field will be null if the failure was not parameter-specific. | |
| /// </summary> | |
| [JsonPropertyName("param")] public string? Param { get; set; } | |
| } ; | |
| /// <summary>The hyperparameters used for the fine-tuning job.</summary> | |
| public class Hyperparameters: JsonObject { | |
| /// <summary> | |
| /// The number of epochs to train the model for. | |
| /// An epoch refers to one full cycle through the training dataset. | |
| /// </summary> | |
| [JsonPropertyName("n_epochs")] public int? NEpochs { get; set; } | |
| /// <summary> | |
| /// Number of examples in each batch. A larger batch size means that | |
| /// model parameters are updated less frequently, but with lower variance. | |
| /// </summary> | |
| [JsonPropertyName("batch_size")] public int? BatchSize { get; set; } | |
| /// <summary>Scaling factor for the learning rate. A smaller learning rate may be useful to avoid overfitting.</summary> | |
| [JsonPropertyName("learning_rate_multiplier")] public double? LearningRateMultiplier { get; set; } | |
| [JsonPropertyName("prompt_loss_weight")] public double? PromptLossWeight { get; set; } | |
| // Add other hyperparameters as needed, such as: | |
| // - weight_decay | |
| // - max_grad_norm | |
| // - beta1 | |
| // - beta2 | |
| // - epsilon | |
| // - final_layer_lr_multiplier | |
| // - use_packing | |
| // - use_cache | |
| // - scale_lr | |
| // - best_of | |
| // - p | |
| // - max_tokens | |
| // - temperature | |
| // - top_p | |
| // - frequency_penalty | |
| // - presence_penalty | |
| // - stop | |
| // - logit_bias | |
| // - logprobs | |
| // - echo | |
| // - presence_penalty_max | |
| // - frequency_penalty_max | |
| // - presence_penalty_slope | |
| // - frequency_penalty_slope | |
| // - penalty_frequency_cutoff | |
| // - penalty_presence_cutoff | |
| } ; | |
| // ------------------------------------------------------------------------------- | |
| // Files API :: | |
| // ------------------------------------------------------------------------------- | |
| public class FileUploadRequest: JsonObject { | |
| [JsonPropertyName("file")] public byte[ ]? File { get; set; } | |
| [JsonPropertyName("purpose")] public string? Purpose { get; set; } | |
| } ; | |
| public class FilesListRequest: JsonObject { | |
| [JsonPropertyName("purpose")] public string? Purpose { get; set; } | |
| } ; | |
| public class FileRetrieveRequest: JsonObject { | |
| [JsonPropertyName("file_id")] public string? FileId { get; set; } | |
| } ; | |
| public class FileDeleteRequest: JsonObject { | |
| [JsonPropertyName("file_id")] public string? FileId { get; set; } | |
| } ; | |
| public class FileContentRetrieveRequest: JsonObject { | |
| [JsonPropertyName("file_id")] public string? FileId { get; set; } | |
| } ; | |
| public class FileContentRetrieveResponse: JsonObject { | |
| // Assuming the response is the raw content of the file | |
| [JsonPropertyName("content")] public string? Content { get; set; } | |
| } ; | |
| // =============================================================================== | |
| // ------------------------------------------------------------------------------- | |
| // Audio API :: | |
| // ------------------------------------------------------------------------------- | |
| /// <summary>Request to generate audio from the input text.</summary> | |
| /// <remarks>Returns: The audio file content.</remarks> | |
| public class CreateSpeechRequest: JsonObject { | |
| /// <summary>One of the available TTS models: tts-1 or tts-1-hd.</summary> | |
| [JsonPropertyName("model")] public AudioModels Model { get; set; } | |
| /// <summary>The text to generate audio for. The maximum length is 4096 characters.</summary> | |
| [JsonPropertyName("input")] public string? Input { get; set; } | |
| /// <summary> | |
| /// The voice to use when generating the audio. Supported voices are alloy, echo, fable, onyx, nova, and shimmer. | |
| /// Previews of the voices are available in the <a href="https://platform.openai.com/docs/guides/text-to-speech/voice-options">Text to speech guide</a>. | |
| /// </summary> | |
| [JsonPropertyName("voice")] public SpeechVoices Voice { get; set; } | |
| /// <summary>The format to audio in. Supported formats are mp3, opus, aac, and flac.</summary> | |
| [JsonPropertyName("response_format")] public AudioFormats? ResponseFormat { get; set; } | |
| /// <summary>The speed of the generated audio. Select a value from 0.25 to 4.0. 1.0 is the default.</summary> | |
| [JsonPropertyName("speed")] public double? Speed { get; set; } | |
| } ; | |
| /// <summary>Transcribes audio into the input language.</summary> | |
| public class CreateTranscriptionRequest: JsonObject { | |
| /// <summary> | |
| /// The audio file object (not file name) to transcribe, in one of these formats: | |
| /// flac, mp3, mp4, mpeg, mpga, m4a, ogg, wav, or webm. | |
| /// </summary> | |
| [JsonPropertyName("file")] public byte[ ]? File { get; set; } | |
| /// <summary>ID of the model to use. Only whisper-1 is currently available.</summary> | |
| [JsonPropertyName("model")] public TranscriberModels Model { get; set; } | |
| /// <summary>The language of the input audio. Supplying the input language in ISO-639-1 format will improve accuracy and latency.</summary> | |
| [JsonPropertyName("language")] public string? Language { get; set; } | |
| /// <summary> | |
| /// An optional text to guide the model's style or continue a previous audio segment. | |
| /// The <a href="https://platform.openai.com/docs/guides/speech-to-text/prompting">prompt</a> | |
| /// should match the audio language. | |
| /// </summary> | |
| [JsonPropertyName("prompt")] public string? Prompt { get; set; } | |
| /// <summary>The format of the transcript output, in one of these options: json, text, srt, verbose_json, or vtt.</summary> | |
| [JsonPropertyName("response_format")] public TranscriptionFormat? ResponseFormat { get; set; } | |
| /// <summary> | |
| /// The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, | |
| /// while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will | |
| /// use log probability to automatically increase the temperature until certain thresholds are hit. | |
| /// </summary> | |
| [JsonPropertyName("temperature")] public double? Temperature { get; set; } | |
| } ; | |
| /// <summary>Translates audio into English.</summary> | |
| public class CreateTranslationRequest: JsonObject { | |
| /// <summary> | |
| /// The audio file object (not file name) translate, in one of these formats: | |
| /// flac, mp3, mp4, mpeg, mpga, m4a, ogg, wav, or webm. | |
| /// </summary> | |
| [JsonPropertyName("file")] public byte[ ]? File { get; set; } | |
| /// <summary>ID of the model to use. Only whisper-1 is currently available.</summary> | |
| [JsonPropertyName("model")] public TranscriberModels Model { get; set; } | |
| /// <summary> | |
| /// An optional text to guide the model's style or continue a previous audio segment. | |
| /// The prompt should be in English. | |
| /// </summary> | |
| [JsonPropertyName("prompt")] public string? Prompt { get; set; } | |
| /// <summary>The format of the transcript output, in one of these options: json, text, srt, verbose_json, or vtt.</summary> | |
| [JsonPropertyName("response_format")] public TranscriptionFormat? ResponseFormat { get; set; } | |
| /// <summary> | |
| /// The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, | |
| /// while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will | |
| /// use log probability to automatically increase the temperature until certain thresholds are hit. | |
| /// </summary> | |
| [JsonPropertyName("temperature")] public double? Temperature { get; set; } | |
| } ; | |
| // ------------------------------------------------------------------------------- | |
| /// <summary>The format to audio in. Supported formats are mp3, opus, aac, and flac.</summary> | |
| /// <remarks>Defaults to mp3.</remarks> | |
| [Flags, JsonConverter(typeof(JsonStringEnumConverter)),] | |
| public enum AudioFormats { | |
| [JsonPropertyName("mp3")] Default = MP3, | |
| [JsonPropertyName("mp3")] MP3 = 0, | |
| [JsonPropertyName("opus")] Opus = 1, | |
| [JsonPropertyName("aac")] AAC = 2, | |
| [JsonPropertyName("aac")] FLAC = 4, | |
| } ; | |
| /// <summary> | |
| /// The voice to use when generating the audio. Supported voices are: | |
| /// alloy, echo, fable, onyx, nova, and shimmer. | |
| /// </summary> | |
| /// <remarks>Previews of the voices are available in the | |
| /// <a href="https://platform.openai.com/docs/guides/text-to-speech/voice-options">Text to speech guide</a>. | |
| /// </remarks> | |
| [Flags, JsonConverter(typeof(JsonStringEnumConverter)),] | |
| public enum SpeechVoices { | |
| [JsonPropertyName("alloy")] Default = Alloy, | |
| [JsonPropertyName("alloy")] Alloy = 0, | |
| [JsonPropertyName("echo")] Echo = 1, | |
| [JsonPropertyName("fable")] Fable = 2, | |
| [JsonPropertyName("onyx")] Onyx = 4, | |
| [JsonPropertyName("nova")] Nova = 8, | |
| [JsonPropertyName("shimmer")] Shimmer = 16, | |
| } ; | |
| /// <summary>Represents one of the available TTS models.</summary> | |
| /// <remarks><c>tts-1</c> or <c>tts-1-hd</c></remarks> | |
| [Flags, JsonConverter(typeof(JsonStringEnumConverter)),] | |
| public enum AudioModels { | |
| [JsonPropertyName("tts-1")] Default = TTS1, | |
| [JsonPropertyName("tts-1")] TTS1 = 0, | |
| [JsonPropertyName("tts-1-hd")] TTS1HD = 1, | |
| } ; | |
| /// <summary>Represents a speech-to-text or "transcriber" model.</summary> | |
| [Flags, JsonConverter(typeof(JsonStringEnumConverter)),] | |
| public enum TranscriberModels { | |
| [JsonPropertyName("whisper-1")] Default = Whisper1, | |
| [JsonPropertyName("whisper-1")] Whisper1 = 0, | |
| } ; | |
| /// <summary>Represents the format of a transcript output.</summary> | |
| /// <remarks> | |
| /// Valid values: | |
| /// <c>json</c>, <c>text</c>, <c>srt</c>, | |
| /// <c>verbose_json</c>, or <c>vtt</c>. | |
| /// </remarks> | |
| [Flags, JsonConverter(typeof(JsonStringEnumConverter)),] | |
| public enum TranscriptionFormat { | |
| [JsonPropertyName("json")] Default = JSON, | |
| [JsonPropertyName("json")] JSON = 0, | |
| [JsonPropertyName("text")] Text = 1, | |
| [JsonPropertyName("srt")] SRT = 2, | |
| [JsonPropertyName("verbose_json")] VerboseJSON = 4, | |
| [JsonPropertyName("vtt")] VTT = 8, | |
| } ; | |
| // ------------------------------------------------------------------------------- | |
| /// <summary>Creates an embedding vector representing the input text.</summary> | |
| public class CreateEmbeddingsRequest: JsonObject { | |
| /// <summary> | |
| /// Input text to embed, encoded as a string or array of tokens. | |
| /// To embed multiple inputs in a single request, pass an array of strings or array of token arrays. | |
| /// The input must not exceed the max input tokens for the model (8192 tokens for text-embedding-ada-002), | |
| /// cannot be an empty string, and any array must be 2048 dimensions or less. Example Python code for | |
| /// counting tokens. | |
| /// </summary> | |
| /// <remarks><para>Supported Types/Formats:</para> | |
| /// <list type="bullet"> | |
| /// <item><description><c>string</c>: The string that will be turned into an embedding.</description></item> | |
| /// <item><description><c>string[ ]</c>: The array of strings that will be turned into an embedding.</description></item> | |
| /// <item><description><c>int[ ]</c>: The array of integers that will be turned into an embedding.</description></item> | |
| /// <item><description><c>int[ ][ ]</c>: The array of arrays containing integers that will be turned into an embedding.</description></item> | |
| /// </list> | |
| /// </remarks> | |
| [JsonPropertyName("input")] public string? Input { get; set; } | |
| /// <summary> | |
| /// 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. | |
| /// </summary> | |
| [JsonPropertyName("model")] public string? Model { get; set; } | |
| /// <summary>The format to return the embeddings in. Can be either float or base64.</summary> | |
| [JsonPropertyName("encoding_format")] public string? EncodingFormat { get; set; } | |
| /// <summary>A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse.</summary> | |
| /// <remarks>Learn more about <a href="https://platform.openai.com/docs/guides/safety-best-practices/end-user-ids">end-user IDs</a>.</remarks> | |
| [JsonPropertyName("user")] public string? User { get; set; } | |
| } ; | |
| /// <summary>Represents an embedding vector returned by embedding endpoint.</summary> | |
| public class Embedding: JsonObject { | |
| /// <summary>The index of the embedding in the list of embeddings.</summary> | |
| [JsonPropertyName("index")] public int Index { get; set; } | |
| /// <summary> | |
| /// The embedding vector, which is a list of floats. | |
| /// The length of vector depends on the model as listed in the embedding guide. | |
| /// </summary> | |
| [JsonPropertyName("embedding")] public float[ ]? EmbeddingVector { get; set; } | |
| /// <summary>The object type, which is always "embedding".</summary> | |
| [JsonPropertyName("object")] public string ObjectType { get; set; } = "embedding"; | |
| } ; | |
| // =============================================================================== | |
| // ------------------------------------------------------------------------------- | |
| // Moderations API :: | |
| // ------------------------------------------------------------------------------- | |
| public class CreateModerationRequest: JsonObject { | |
| [JsonPropertyName("input")] public string? Input { get; set; } | |
| [JsonPropertyName("model")] public string? Model { get; set; } // Optional, defaults to text-moderation-latest | |
| } ; | |
| public class ModerationResult: JsonObject { | |
| [JsonPropertyName("flagged")] public bool Flagged { get; set; } | |
| [JsonPropertyName("categories")] public ModerationCategories? Categories { get; set; } | |
| [JsonPropertyName("category_scores")] public Dictionary<string, double>? CategoryScores { get; set; } | |
| } ; | |
| public class ModerationCategories: JsonObject { | |
| [JsonPropertyName("hate")] public bool Hate { get; set; } | |
| [JsonPropertyName("hate/threatening")] public bool HateThreatening { get; set; } | |
| [JsonPropertyName("harassment")] public bool Harassment { get; set; } | |
| [JsonPropertyName("harassment/threatening")] public bool HarassmentThreatening { get; set; } | |
| [JsonPropertyName("self-harm")] public bool SelfHarm { get; set; } | |
| [JsonPropertyName("self-harm/intent")] public bool SelfHarmIntent { get; set; } | |
| [JsonPropertyName("self-harm/instructions")] public bool SelfHarmInstructions { get; set; } | |
| [JsonPropertyName("sexual")] public bool Sexual { get; set; } | |
| [JsonPropertyName("sexual/minors")] public bool SexualMinors { get; set; } | |
| [JsonPropertyName("violence")] public bool Violence { get; set; } | |
| [JsonPropertyName("violence/graphic")] public bool ViolenceGraphic { get; set; } | |
| } ; | |
| public class ModerationResponse: JsonObject { | |
| [JsonPropertyName("id")] public string? Id { get; set; } | |
| [JsonPropertyName("model")] public string? Model { get; set; } | |
| [JsonPropertyName("results")] public ModerationResult[ ]? Results { get; set; } | |
| } ; | |
| // ------------------------------------------------------------------------------- | |
| /// <summary>Enum specifying the format that the model must output.</summary> | |
| /// <remarks> | |
| /// <para>Compatible with gpt-4-1106-preview and gpt-3.5-turbo-1106.</para> | |
| /// <para><b>Important</b>:</para> | |
| /// <para>When using JSON mode, you must also instruct the model to produce JSON yourself | |
| /// via a system or user message. Without this, the model may generate an unending stream | |
| /// of whitespace until the generation reaches the token limit, resulting in a long-running | |
| /// and seemingly "stuck" request. Also note that the message content may be partially cut | |
| /// off if finish_reason="length", which indicates the generation exceeded max_tokens or the | |
| /// conversation exceeded the max context length.</para><para/> | |
| /// <para><b>Notes</b>:</para> | |
| /// <para>string? (optional): Defaults to text</para> | |
| /// <para>Must be one of <c>text</c> or <c>json_object</c>.</para> | |
| /// </remarks> | |
| [JsonConverter(typeof(JsonStringEnumConverter))] | |
| public enum ResponseFormatType { | |
| /// <summary></summary> | |
| [JsonPropertyName("text")] Text, | |
| /// <summary>Enables JSON mode, which guarantees the message the model generates is valid JSON.</summary> | |
| [JsonPropertyName("json_object")] JsonObject, | |
| } ; | |
| // ================================================================================================================= | |
| //! End of OpenAI namespace ... | |
| // ================================================================================================================= |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment