openai/openai-dotnet

Public

mirrored from https://github.com/openai/openai-dotnetAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
achandmsft-patch-1

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/Custom/Chat/ChatCompletionOptions.cs

218lines · modeblame

2ab1a942Jose Arriaga Maldonado1 years ago1using System;
d6615abeJose Arriaga Maldonado1 years ago2using System.ClientModel.Primitives;
9f9f2936Jose Arriaga Maldonado2 years ago3using System.Collections.Generic;
0f5e0249ShivangiReja1 years ago4using System.Diagnostics.CodeAnalysis;
d6615abeJose Arriaga Maldonado1 years ago5using System.Threading;
9f9f2936Jose Arriaga Maldonado2 years ago6
7namespace OpenAI.Chat;
8
9/// <summary>
10/// Request-level options for chat completion.
11/// </summary>
0ca4c062Jose Arriaga Maldonado1 years ago12[CodeGenType("CreateChatCompletionRequest")]
d6615abeJose Arriaga Maldonado1 years ago13[CodeGenSuppress("ChatCompletionOptions", typeof(IEnumerable<ChatMessage>), typeof(InternalCreateChatCompletionRequestModel?))]
2ab1a942Jose Arriaga Maldonado1 years ago14[CodeGenSerialization(nameof(Messages), SerializationValueHook = nameof(SerializeMessagesValue))]
9f9f2936Jose Arriaga Maldonado2 years ago15[CodeGenSerialization(nameof(StopSequences), SerializationValueHook = nameof(SerializeStopSequencesValue), DeserializationValueHook = nameof(DeserializeStopSequencesValue))]
16[CodeGenSerialization(nameof(LogitBiases), SerializationValueHook = nameof(SerializeLogitBiasesValue), DeserializationValueHook = nameof(DeserializeLogitBiasesValue))]
17public partial class ChatCompletionOptions
18{
19// CUSTOM:
20// - Made internal. This value comes from a parameter on the client method.
21// - Added setter.
22/// <summary>
23/// A list of messages comprising the conversation so far. [Example Python code](https://cookbook.openai.com/examples/how_to_format_inputs_to_chatgpt_models).
24/// 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.
25/// The available derived classes include <see cref="AssistantChatMessage"/>, <see cref="FunctionChatMessage"/>, <see cref="SystemChatMessage"/>, <see cref="ToolChatMessage"/> and <see cref="UserChatMessage"/>.
26/// </summary>
27[CodeGenMember("Messages")]
28internal IList<ChatMessage> Messages { get; set; }
29
30// CUSTOM:
31// - Made internal. This value comes from a parameter on the client method.
32// - Added setter.
33/// <summary>
34/// 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.
35/// </summary>
36[CodeGenMember("Model")]
d6615abeJose Arriaga Maldonado1 years ago37internal InternalCreateChatCompletionRequestModel? Model { get; set; }
9f9f2936Jose Arriaga Maldonado2 years ago38
39// CUSTOM: Made internal. We only ever request a single choice.
40/// <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>
41[CodeGenMember("N")]
42internal int? N { get; set; }
43
44// CUSTOM: Made internal. We set this manually based on the client method that is called.
45/// <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>
46[CodeGenMember("Stream")]
47internal bool? Stream { get; set; }
48
49/// <summary> Gets or sets the stream options. </summary>
50[CodeGenMember("StreamOptions")]
51internal InternalChatCompletionStreamOptions StreamOptions { get; set; }
52
53// CUSTOM: Made public now that there are no required properties.
54/// <summary> Initializes a new instance of <see cref="ChatCompletionOptions"/> for deserialization. </summary>
55public ChatCompletionOptions()
56{
d6615abeJose Arriaga Maldonado1 years ago57Messages = new ChangeTrackingList<ChatMessage>();
9f9f2936Jose Arriaga Maldonado2 years ago58LogitBiases = new ChangeTrackingDictionary<int, int>();
59StopSequences = new ChangeTrackingList<string>();
60Tools = new ChangeTrackingList<ChatTool>();
61Functions = new ChangeTrackingList<ChatFunction>();
d6615abeJose Arriaga Maldonado1 years ago62InternalModalities = new ChangeTrackingList<InternalCreateChatCompletionRequestModality>();
63Metadata = new ChangeTrackingDictionary<string, string>();
9f9f2936Jose Arriaga Maldonado2 years ago64}
65
66// CUSTOM: Renamed.
67/// <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>
68[CodeGenMember("Logprobs")]
58f93c8dShivangiReja2 years ago69public bool? IncludeLogProbabilities { get; set; }
9f9f2936Jose Arriaga Maldonado2 years ago70
71// CUSTOM: Renamed.
72/// <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>
73[CodeGenMember("TopLogprobs")]
58f93c8dShivangiReja2 years ago74public int? TopLogProbabilityCount { get; set; }
9f9f2936Jose Arriaga Maldonado2 years ago75
76// CUSTOM:
77// - Renamed.
78// - Changed type to treat a single string as a collection of strings with one item.
79/// <summary> Up to 4 sequences where the API will stop generating further tokens. </summary>
80[CodeGenMember("Stop")]
81public IList<string> StopSequences { get; }
82
83// CUSTOM:
84// - Renamed.
85// - Changed type to treat tokens as integers instead of strings.
86/// <summary>
87/// 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.
88/// </summary>
89[CodeGenMember("LogitBias")]
90public IDictionary<int, int> LogitBiases { get; }
91
92// CUSTOM: Changed type to avoid BinaryData.
93/// <summary>
94/// 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.
95/// <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.
96/// <remarks>
97/// <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.
98/// </remarks>
99/// </summary>
100[CodeGenMember("ToolChoice")]
58f93c8dShivangiReja2 years ago101public ChatToolChoice ToolChoice { get; set; }
9f9f2936Jose Arriaga Maldonado2 years ago102
103// CUSTOM:
104// - Renamed.
105// - Changed type to avoid BinaryData.
2ab1a942Jose Arriaga Maldonado1 years ago106[Obsolete($"This property is obsolete. Please use {nameof(ToolChoice)} instead.")]
9f9f2936Jose Arriaga Maldonado2 years ago107[CodeGenMember("FunctionCall")]
58f93c8dShivangiReja2 years ago108public ChatFunctionChoice FunctionChoice { get; set; }
1af6569eTravis Wilson2 years ago109
13a9c686Jose Arriaga Maldonado1 years ago110// CUSTOM: Renamed.
1af6569eTravis Wilson2 years ago111/// <summary>
0ca4c062Jose Arriaga Maldonado1 years ago112/// Whether to enable parallel function calling during tool use.
1af6569eTravis Wilson2 years ago113/// </summary>
114/// <remarks>
115/// Assumed <c>true</c> if not otherwise specified.
116/// </remarks>
117[CodeGenMember("ParallelToolCalls")]
19ceae44ShivangiReja1 years ago118public bool? AllowParallelToolCalls { get; set; }
13a9c686Jose Arriaga Maldonado1 years ago119
3467b535Travis Wilson1 years ago120[CodeGenMember("ServiceTier")]
121internal InternalCreateChatCompletionRequestServiceTier? _serviceTier;
122
13a9c686Jose Arriaga Maldonado1 years ago123// CUSTOM: Renamed.
124/// <summary>
125/// A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse.
126/// <see href="https://platform.openai.com/docs/guides/safety-best-practices/end-user-ids">Learn more</see>.
127/// </summary>
128[CodeGenMember("User")]
129public string EndUserId { get; set; }
0f5e0249ShivangiReja1 years ago130
2ab1a942Jose Arriaga Maldonado1 years ago131// CUSTOM: Added the Experimental attribute.
0f5e0249ShivangiReja1 years ago132/// <summary>
133/// 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.
134/// </summary>
135[Experimental("OPENAI001")]
136public long? Seed { get; set; }
2ab1a942Jose Arriaga Maldonado1 years ago137
138// CUSTOM: Hide deprecated max_tokens and reroute to newer max_completion_tokens.
139[CodeGenMember("MaxTokens")]
140internal int? _deprecatedMaxTokens { get; set; }
141
142// CUSTOM: Add legacy `max_tokens` routing.
143/// <summary>
144/// 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.
145/// </summary>
146[CodeGenMember("MaxCompletionTokens")]
147public int? MaxOutputTokenCount { get; set; }
148
149// CUSTOM: Added the Obsolete attribute.
150[Obsolete($"This property is obsolete. Please use {nameof(Tools)} instead.")]
151public IList<ChatFunction> Functions { get; }
b0f9e5c3Jose Arriaga Maldonado1 years ago152
153// CUSTOM: Removed public setter.
bf3f0eddJose Arriaga Maldonado1 years ago154/// <summary>
155/// Developer-defined tags and values used for filtering completions in the
156/// <see href="https://platform.openai.com/chat-completions">OpenAI Platform dashboard</see>.
157/// </summary>
b0f9e5c3Jose Arriaga Maldonado1 years ago158[CodeGenMember("Metadata")]
d6615abeJose Arriaga Maldonado1 years ago159public IDictionary<string, string> Metadata { get; }
b0f9e5c3Jose Arriaga Maldonado1 years ago160
161// CUSTOM: Renamed.
bf3f0eddJose Arriaga Maldonado1 years ago162/// <summary>
163/// Indicates whether to store the output of this chat completion request for use in
164/// <see href="https://platform.openai.com/docs/guides/distillation">model distillation</see>
165/// or <see href="https://platform.openai.com/docs/guides/evals">evals</see>.
166/// </summary>
b0f9e5c3Jose Arriaga Maldonado1 years ago167[CodeGenMember("Store")]
168public bool? StoredOutputEnabled { get; set; }
0e0c460cJose Arriaga Maldonado1 years ago169
170// CUSTOM: Renamed.
171/// <summary>
172/// (o1 and newer reasoning models only) Constrains effort on reasoning for reasoning models.
173/// Currently supported values are <see cref="ChatReasoningEffortLevel.Low"/>, <see cref="ChatReasoningEffortLevel.Medium"/>, and <see cref="ChatReasoningEffortLevel.High"/>.
174/// Reducing reasoning effort can result in faster responses and fewer tokens used on reasoning in a response.
175/// </summary>
176[CodeGenMember("ReasoningEffort")]
177public ChatReasoningEffortLevel? ReasoningEffortLevel { get; set; }
178
179// CUSTOM: Made internal for automatic enablement via audio options.
180[CodeGenMember("Modalities")]
d6615abeJose Arriaga Maldonado1 years ago181private IList<InternalCreateChatCompletionRequestModality> InternalModalities
182{
183get => _internalModalities;
184set
185{
186_internalModalities = value;
187_responseModalities = ChatResponseModalitiesExtensions.FromInternalModalities(value);
188}
189}
190private IList<InternalCreateChatCompletionRequestModality> _internalModalities;
0e0c460cJose Arriaga Maldonado1 years ago191
192/// <summary>
193/// Specifies the content types that the model should generate in its responses.
194/// </summary>
195/// <remarks>
196/// Most models can generate text and the default <c>["text"]</c> value, from <c><see cref="ChatResponseModalities.Text"/></c>, requests this.
197/// Some models like <c>gpt-4o-audio-preview</c> can also generate audio, and this can be requested by combining <c>["text","audio"]</c> via
198/// the flags <c><see cref="ChatResponseModalities.Text"/> | <see cref="ChatResponseModalities.Audio"/></c>.
199/// </remarks>
200public ChatResponseModalities ResponseModalities
201{
d6615abeJose Arriaga Maldonado1 years ago202get => _responseModalities;
0e0c460cJose Arriaga Maldonado1 years ago203set
204{
d6615abeJose Arriaga Maldonado1 years ago205_responseModalities = value;
206_internalModalities = value.ToInternalModalities();
0e0c460cJose Arriaga Maldonado1 years ago207}
208}
d6615abeJose Arriaga Maldonado1 years ago209private ChatResponseModalities _responseModalities;
210
211// CUSTOM: Renamed.
212[CodeGenMember("Audio")]
213public ChatAudioOptions AudioOptions { get; set; }
0e0c460cJose Arriaga Maldonado1 years ago214
215// CUSTOM: rename.
216[CodeGenMember("Prediction")]
217public ChatOutputPrediction OutputPrediction { get; set; }
0f5e0249ShivangiReja1 years ago218}