openai/openai-dotnet
Publicmirrored from https://github.com/openai/openai-dotnetAvailable
src/Custom/Chat/ChatCompletionOptions.cs
162lines · modecode
| 1 | using System; |
| 2 | using System.Collections.Generic; |
| 3 | using System.Diagnostics.CodeAnalysis; |
| 4 | |
| 5 | namespace OpenAI.Chat; |
| 6 | |
| 7 | /// <summary> |
| 8 | /// Request-level options for chat completion. |
| 9 | /// </summary> |
| 10 | [CodeGenModel("CreateChatCompletionRequest")] |
| 11 | [CodeGenSuppress("ChatCompletionOptions", typeof(IEnumerable<ChatMessage>), typeof(InternalCreateChatCompletionRequestModel))] |
| 12 | [CodeGenSerialization(nameof(Messages), SerializationValueHook = nameof(SerializeMessagesValue))] |
| 13 | [CodeGenSerialization(nameof(StopSequences), SerializationValueHook = nameof(SerializeStopSequencesValue), DeserializationValueHook = nameof(DeserializeStopSequencesValue))] |
| 14 | [CodeGenSerialization(nameof(LogitBiases), SerializationValueHook = nameof(SerializeLogitBiasesValue), DeserializationValueHook = nameof(DeserializeLogitBiasesValue))] |
| 15 | public partial class ChatCompletionOptions |
| 16 | { |
| 17 | // CUSTOM: |
| 18 | // - Made internal. This value comes from a parameter on the client method. |
| 19 | // - Added setter. |
| 20 | /// <summary> |
| 21 | /// A list of messages comprising the conversation so far. [Example Python code](https://cookbook.openai.com/examples/how_to_format_inputs_to_chatgpt_models). |
| 22 | /// Please note <see cref="ChatMessage"/> is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. |
| 23 | /// The available derived classes include <see cref="AssistantChatMessage"/>, <see cref="FunctionChatMessage"/>, <see cref="SystemChatMessage"/>, <see cref="ToolChatMessage"/> and <see cref="UserChatMessage"/>. |
| 24 | /// </summary> |
| 25 | [CodeGenMember("Messages")] |
| 26 | internal IList<ChatMessage> Messages { get; set; } |
| 27 | |
| 28 | // CUSTOM: |
| 29 | // - Made internal. This value comes from a parameter on the client method. |
| 30 | // - Added setter. |
| 31 | /// <summary> |
| 32 | /// ID of the model to use. See the <see href="https://platform.openai.com/docs/models/model-endpoint-compatibility">model endpoint compatibility</see> table for details on which models work with the Chat API. |
| 33 | /// </summary> |
| 34 | [CodeGenMember("Model")] |
| 35 | internal InternalCreateChatCompletionRequestModel Model { get; set; } |
| 36 | |
| 37 | // CUSTOM: Made internal. We only ever request a single choice. |
| 38 | /// <summary> How many chat completion choices to generate for each input message. Note that you will be charged based on the number of generated tokens across all of the choices. Keep `n` as `1` to minimize costs. </summary> |
| 39 | [CodeGenMember("N")] |
| 40 | internal int? N { get; set; } |
| 41 | |
| 42 | // CUSTOM: Made internal. We set this manually based on the client method that is called. |
| 43 | /// <summary> If set, partial message deltas will be sent, like in ChatGPT. Tokens will be sent as data-only [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format) as they become available, with the stream terminated by a `data: [DONE]` message. [Example Python code](https://cookbook.openai.com/examples/how_to_stream_completions). </summary> |
| 44 | [CodeGenMember("Stream")] |
| 45 | internal bool? Stream { get; set; } |
| 46 | |
| 47 | /// <summary> Gets or sets the stream options. </summary> |
| 48 | [CodeGenMember("StreamOptions")] |
| 49 | internal InternalChatCompletionStreamOptions StreamOptions { get; set; } |
| 50 | = new() { IncludeUsage = true }; |
| 51 | |
| 52 | // CUSTOM: Made public now that there are no required properties. |
| 53 | /// <summary> Initializes a new instance of <see cref="ChatCompletionOptions"/> for deserialization. </summary> |
| 54 | public ChatCompletionOptions() |
| 55 | { |
| 56 | LogitBiases = new ChangeTrackingDictionary<int, int>(); |
| 57 | StopSequences = new ChangeTrackingList<string>(); |
| 58 | Tools = new ChangeTrackingList<ChatTool>(); |
| 59 | Functions = new ChangeTrackingList<ChatFunction>(); |
| 60 | } |
| 61 | |
| 62 | // CUSTOM: Renamed. |
| 63 | /// <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 message content. </summary> |
| 64 | [CodeGenMember("Logprobs")] |
| 65 | public bool? IncludeLogProbabilities { get; set; } |
| 66 | |
| 67 | // CUSTOM: Renamed. |
| 68 | /// <summary> An integer between 0 and 20 specifying the number of most likely tokens to return at each token position, each with an associated log probability. <see cref="IncludeLogProbabilities"/> must be set to <see langword="true"/> if this property is used. </summary> |
| 69 | [CodeGenMember("TopLogprobs")] |
| 70 | public int? TopLogProbabilityCount { get; set; } |
| 71 | |
| 72 | // CUSTOM: |
| 73 | // - Renamed. |
| 74 | // - Changed type to treat a single string as a collection of strings with one item. |
| 75 | /// <summary> Up to 4 sequences where the API will stop generating further tokens. </summary> |
| 76 | [CodeGenMember("Stop")] |
| 77 | public IList<string> StopSequences { get; } |
| 78 | |
| 79 | // CUSTOM: |
| 80 | // - Renamed. |
| 81 | // - Changed type to treat tokens as integers instead of strings. |
| 82 | /// <summary> |
| 83 | /// Modifies the likelihood of specified tokens appearing in the completion. It maps tokens (specified by their token ID in the tokenizer) to an associated bias value from -100 to 100. Mathematically, the bias is added to the logits generated by the model prior to sampling. The exact effect will vary per model, but values between -1 and 1 should decrease or increase likelihood of selection; values like -100 or 100 should result in a ban or exclusive selection of the relevant token. |
| 84 | /// </summary> |
| 85 | [CodeGenMember("LogitBias")] |
| 86 | public IDictionary<int, int> LogitBiases { get; } |
| 87 | |
| 88 | // CUSTOM: Changed type to avoid BinaryData. |
| 89 | /// <summary> |
| 90 | /// Specifies which tool is called by the model, if any. <see cref="ChatToolChoice.None"/> means the model will not call any tool and instead generates a message. <see cref="ChatToolChoice.Auto"/> means the model can pick between generating a message or calling one or more tools. |
| 91 | /// <see cref="ChatToolChoice.Required"/> means the model must call one or more tools. The model can also be forced to call a specific tool by constructing a new instance of <see cref="ChatToolChoice"/> while passing the desired <see cref="ChatTool"/> as a constructor parameter. |
| 92 | /// <remarks> |
| 93 | /// <see cref="ChatToolChoice.None"/> is the default behavior when no tools are present, while <see cref="ChatToolChoice.Auto"/> is the default if tools are present. |
| 94 | /// </remarks> |
| 95 | /// </summary> |
| 96 | [CodeGenMember("ToolChoice")] |
| 97 | public ChatToolChoice ToolChoice { get; set; } |
| 98 | |
| 99 | // CUSTOM: |
| 100 | // - Renamed. |
| 101 | // - Changed type to avoid BinaryData. |
| 102 | [Obsolete($"This property is obsolete. Please use {nameof(ToolChoice)} instead.")] |
| 103 | [CodeGenMember("FunctionCall")] |
| 104 | public ChatFunctionChoice FunctionChoice { get; set; } |
| 105 | |
| 106 | // CUSTOM: Renamed. |
| 107 | /// <summary> |
| 108 | /// Whether to enable parallel function calling during tool use. |
| 109 | /// </summary> |
| 110 | /// <remarks> |
| 111 | /// Assumed <c>true</c> if not otherwise specified. |
| 112 | /// </remarks> |
| 113 | [CodeGenMember("ParallelToolCalls")] |
| 114 | public bool? ParallelToolCallsEnabled { get; set; } |
| 115 | |
| 116 | /// <summary> |
| 117 | /// An object specifying the format that the model must output. |
| 118 | /// </summary> |
| 119 | /// <remarks> |
| 120 | /// <p> |
| 121 | /// Compatible with GPT-4o, GPT-4o mini, GPT-4 Turbo and all GPT-3.5 Turbo models newer than gpt-3.5-turbo-1106. |
| 122 | /// </p> |
| 123 | /// <p> |
| 124 | /// Learn more in the Structured Outputs guide. |
| 125 | /// </p> |
| 126 | /// </remarks> |
| 127 | //[CodeGenMember("ResponseFormat")] |
| 128 | //public ChatResponseFormat ResponseFormat { get; set; } |
| 129 | |
| 130 | [CodeGenMember("ServiceTier")] |
| 131 | internal InternalCreateChatCompletionRequestServiceTier? _serviceTier; |
| 132 | |
| 133 | // CUSTOM: Renamed. |
| 134 | /// <summary> |
| 135 | /// A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. |
| 136 | /// <see href="https://platform.openai.com/docs/guides/safety-best-practices/end-user-ids">Learn more</see>. |
| 137 | /// </summary> |
| 138 | [CodeGenMember("User")] |
| 139 | public string EndUserId { get; set; } |
| 140 | |
| 141 | // CUSTOM: Added the Experimental attribute. |
| 142 | /// <summary> |
| 143 | /// If specified, our system will make a best effort to sample deterministically, such that repeated requests with the same seed and parameters should return the same result. |
| 144 | /// </summary> |
| 145 | [Experimental("OPENAI001")] |
| 146 | public long? Seed { get; set; } |
| 147 | |
| 148 | // CUSTOM: Hide deprecated max_tokens and reroute to newer max_completion_tokens. |
| 149 | [CodeGenMember("MaxTokens")] |
| 150 | internal int? _deprecatedMaxTokens { get; set; } |
| 151 | |
| 152 | // CUSTOM: Add legacy `max_tokens` routing. |
| 153 | /// <summary> |
| 154 | /// An upper bound for the number of tokens that can be generated for a completion, including visible output tokens and, on applicable models, reasoning tokens. |
| 155 | /// </summary> |
| 156 | [CodeGenMember("MaxCompletionTokens")] |
| 157 | public int? MaxOutputTokenCount { get; set; } |
| 158 | |
| 159 | // CUSTOM: Added the Obsolete attribute. |
| 160 | [Obsolete($"This property is obsolete. Please use {nameof(Tools)} instead.")] |
| 161 | public IList<ChatFunction> Functions { get; } |
| 162 | } |
| 163 | |