openai/openai-dotnet
Publicmirrored from https://github.com/openai/openai-dotnetAvailable
src/Custom/Chat/ChatCompletionOptions.cs
104lines · modecode
| 1 | using System.Collections.Generic; |
| 2 | |
| 3 | namespace OpenAI.Chat; |
| 4 | |
| 5 | /// <summary> |
| 6 | /// Request-level options for chat completion. |
| 7 | /// </summary> |
| 8 | [CodeGenModel("CreateChatCompletionRequest")] |
| 9 | [CodeGenSuppress("ChatCompletionOptions", typeof(IEnumerable<ChatMessage>), typeof(InternalCreateChatCompletionRequestModel))] |
| 10 | [CodeGenSerialization(nameof(StopSequences), SerializationValueHook = nameof(SerializeStopSequencesValue), DeserializationValueHook = nameof(DeserializeStopSequencesValue))] |
| 11 | [CodeGenSerialization(nameof(LogitBiases), SerializationValueHook = nameof(SerializeLogitBiasesValue), DeserializationValueHook = nameof(DeserializeLogitBiasesValue))] |
| 12 | public partial class ChatCompletionOptions |
| 13 | { |
| 14 | // CUSTOM: |
| 15 | // - Made internal. This value comes from a parameter on the client method. |
| 16 | // - Added setter. |
| 17 | /// <summary> |
| 18 | /// A list of messages comprising the conversation so far. [Example Python code](https://cookbook.openai.com/examples/how_to_format_inputs_to_chatgpt_models). |
| 19 | /// 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. |
| 20 | /// The available derived classes include <see cref="AssistantChatMessage"/>, <see cref="FunctionChatMessage"/>, <see cref="SystemChatMessage"/>, <see cref="ToolChatMessage"/> and <see cref="UserChatMessage"/>. |
| 21 | /// </summary> |
| 22 | [CodeGenMember("Messages")] |
| 23 | internal IList<ChatMessage> Messages { get; set; } |
| 24 | |
| 25 | // CUSTOM: |
| 26 | // - Made internal. This value comes from a parameter on the client method. |
| 27 | // - Added setter. |
| 28 | /// <summary> |
| 29 | /// 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. |
| 30 | /// </summary> |
| 31 | [CodeGenMember("Model")] |
| 32 | internal InternalCreateChatCompletionRequestModel Model { get; set; } |
| 33 | |
| 34 | // CUSTOM: Made internal. We only ever request a single choice. |
| 35 | /// <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> |
| 36 | [CodeGenMember("N")] |
| 37 | internal int? N { get; set; } |
| 38 | |
| 39 | // CUSTOM: Made internal. We set this manually based on the client method that is called. |
| 40 | /// <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> |
| 41 | [CodeGenMember("Stream")] |
| 42 | internal bool? Stream { get; set; } |
| 43 | |
| 44 | /// <summary> Gets or sets the stream options. </summary> |
| 45 | [CodeGenMember("StreamOptions")] |
| 46 | internal InternalChatCompletionStreamOptions StreamOptions { get; set; } |
| 47 | = new() { IncludeUsage = true }; |
| 48 | |
| 49 | // CUSTOM: Made public now that there are no required properties. |
| 50 | /// <summary> Initializes a new instance of <see cref="ChatCompletionOptions"/> for deserialization. </summary> |
| 51 | public ChatCompletionOptions() |
| 52 | { |
| 53 | LogitBiases = new ChangeTrackingDictionary<int, int>(); |
| 54 | StopSequences = new ChangeTrackingList<string>(); |
| 55 | Tools = new ChangeTrackingList<ChatTool>(); |
| 56 | Functions = new ChangeTrackingList<ChatFunction>(); |
| 57 | } |
| 58 | |
| 59 | // CUSTOM: Renamed. |
| 60 | /// <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> |
| 61 | [CodeGenMember("Logprobs")] |
| 62 | public bool? IncludeLogProbabilities { get; init; } |
| 63 | |
| 64 | // CUSTOM: Renamed. |
| 65 | /// <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> |
| 66 | [CodeGenMember("TopLogprobs")] |
| 67 | public int? TopLogProbabilityCount { get; init; } |
| 68 | |
| 69 | // CUSTOM: |
| 70 | // - Renamed. |
| 71 | // - Changed type to treat a single string as a collection of strings with one item. |
| 72 | /// <summary> Up to 4 sequences where the API will stop generating further tokens. </summary> |
| 73 | [CodeGenMember("Stop")] |
| 74 | public IList<string> StopSequences { get; } |
| 75 | |
| 76 | // CUSTOM: |
| 77 | // - Renamed. |
| 78 | // - Changed type to treat tokens as integers instead of strings. |
| 79 | /// <summary> |
| 80 | /// 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. |
| 81 | /// </summary> |
| 82 | [CodeGenMember("LogitBias")] |
| 83 | public IDictionary<int, int> LogitBiases { get; } |
| 84 | |
| 85 | // CUSTOM: Changed type to avoid BinaryData. |
| 86 | /// <summary> |
| 87 | /// 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. |
| 88 | /// <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. |
| 89 | /// <remarks> |
| 90 | /// <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. |
| 91 | /// </remarks> |
| 92 | /// </summary> |
| 93 | [CodeGenMember("ToolChoice")] |
| 94 | public ChatToolChoice ToolChoice { get; init; } |
| 95 | |
| 96 | // CUSTOM: |
| 97 | // - Renamed. |
| 98 | // - Changed type to avoid BinaryData. |
| 99 | /// <summary> |
| 100 | /// Deprecated in favor of <see cref="ToolChoice"/>. |
| 101 | /// </summary> |
| 102 | [CodeGenMember("FunctionCall")] |
| 103 | public ChatFunctionChoice FunctionChoice { get; init; } |
| 104 | } |