Skip to content

Commit b726c7d

Browse files
committed
Merge branch 'main' of https://github.com/openai/openai-dotnet into Shreja_AudioSpecUpdate
2 parents 44bd018 + fabfc88 commit b726c7d

File tree

41 files changed

+1927
-1183
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1927
-1183
lines changed

.config/dotnet-tools.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"rollForward": false
1111
},
1212
"azure.sdk.tools.testproxy": {
13-
"version": "1.0.0-dev.20250922.2",
13+
"version": "1.0.0-dev.20251209.1",
1414
"commands": [
1515
"test-proxy"
1616
],

Directory.Packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<PackageVersion Include="Moq" Version="[4.18.2]" />
3232

3333
<!-- Development Feed Packages -->
34-
<PackageVersion Include="Microsoft.ClientModel.TestFramework" Version="1.0.0-alpha.20250919.1" />
34+
<PackageVersion Include="Microsoft.ClientModel.TestFramework" Version="1.0.0-alpha.20260121.1" />
3535
</ItemGroup>
3636

3737
<!-- Generator-Only Dependencies -->

api/OpenAI.net8.0.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5621,6 +5621,8 @@ public class McpToolCallApprovalPolicy : IJsonModel<McpToolCallApprovalPolicy>,
56215621
public ref JsonPatch Patch { get; }
56225622
protected virtual McpToolCallApprovalPolicy JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
56235623
protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
5624+
public static implicit operator McpToolCallApprovalPolicy(CustomMcpToolCallApprovalPolicy customPolicy);
5625+
public static implicit operator McpToolCallApprovalPolicy(GlobalMcpToolCallApprovalPolicy globalPolicy);
56245626
protected virtual McpToolCallApprovalPolicy PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options);
56255627
protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options);
56265628
}
@@ -5801,6 +5803,7 @@ public class ResponseContentPart : IJsonModel<ResponseContentPart>, IPersistable
58015803
public string InputFilename { get; }
58025804
public ResponseImageDetailLevel? InputImageDetailLevel { get; }
58035805
public string InputImageFileId { get; }
5806+
public string InputImageUrl { get; }
58045807
public ResponseContentPartKind Kind { get; }
58055808
public IReadOnlyList<ResponseMessageAnnotation> OutputTextAnnotations { get; }
58065809
[Serialization.JsonIgnore]

api/OpenAI.netstandard2.0.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4922,6 +4922,8 @@ public class McpToolCallApprovalPolicy : IJsonModel<McpToolCallApprovalPolicy>,
49224922
public ref JsonPatch Patch { get; }
49234923
protected virtual McpToolCallApprovalPolicy JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
49244924
protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
4925+
public static implicit operator McpToolCallApprovalPolicy(CustomMcpToolCallApprovalPolicy customPolicy);
4926+
public static implicit operator McpToolCallApprovalPolicy(GlobalMcpToolCallApprovalPolicy globalPolicy);
49254927
protected virtual McpToolCallApprovalPolicy PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options);
49264928
protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options);
49274929
}
@@ -5083,6 +5085,7 @@ public class ResponseContentPart : IJsonModel<ResponseContentPart>, IPersistable
50835085
public string InputFilename { get; }
50845086
public ResponseImageDetailLevel? InputImageDetailLevel { get; }
50855087
public string InputImageFileId { get; }
5088+
public string InputImageUrl { get; }
50865089
public ResponseContentPartKind Kind { get; }
50875090
public IReadOnlyList<ResponseMessageAnnotation> OutputTextAnnotations { get; }
50885091
[Serialization.JsonIgnore]

examples/Responses/Example05_RemoteMcp.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public void Example05_RemoteMcp()
2525
new McpTool(serverLabel: "dmcp", serverUri: new Uri("https://dmcp-server.deno.dev/sse"))
2626
{
2727
ServerDescription = "A Dungeons and Dragons MCP server to assist with dice rolling.",
28-
ToolCallApprovalPolicy = new McpToolCallApprovalPolicy(GlobalMcpToolCallApprovalPolicy.NeverRequireApproval)
28+
ToolCallApprovalPolicy = GlobalMcpToolCallApprovalPolicy.NeverRequireApproval // An implicit conversion is used here for convenience.
2929
}
3030
}
3131
};

examples/Responses/Example05_RemoteMcpAsync.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public async Task Example05_RemoteMcpAsync()
2626
new McpTool(serverLabel: "dmcp", serverUri: new Uri("https://dmcp-server.deno.dev/sse"))
2727
{
2828
ServerDescription = "A Dungeons and Dragons MCP server to assist with dice rolling.",
29-
ToolCallApprovalPolicy = new McpToolCallApprovalPolicy(GlobalMcpToolCallApprovalPolicy.NeverRequireApproval)
29+
ToolCallApprovalPolicy = GlobalMcpToolCallApprovalPolicy.NeverRequireApproval // An implicit conversion is used here for convenience.
3030
}
3131
}
3232
};

nuget.config

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
</packageSources>
99
<packageSourceMapping>
1010
<packageSource key="azure-sdk-dev-feed">
11-
<package pattern="System.ClientModel" />
1211
<package pattern="Microsoft.ClientModel.TestFramework" />
1312
<package pattern="Azure.Sdk.Tools.*" />
1413
</packageSource>

src/Custom/Chat/ChatClient.cs

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,12 @@ internal async Task<ClientResult<ChatCompletion>> CompleteChatAsync(IEnumerable<
152152
}
153153

154154
options ??= new();
155-
CreateChatCompletionOptions(messages, ref options);
156-
using OpenTelemetryScope scope = _telemetry.StartChatScope(options);
155+
var clonedOptions = CreateChatCompletionOptions(messages, options);
156+
using OpenTelemetryScope scope = _telemetry.StartChatScope(clonedOptions);
157157

158158
try
159159
{
160-
using BinaryContent content = options.ToBinaryContent();
160+
using BinaryContent content = clonedOptions.ToBinaryContent();
161161

162162
ClientResult result = await CompleteChatAsync(content, requestOptions).ConfigureAwait(false);
163163
ChatCompletion chatCompletion = (ChatCompletion)result;
@@ -182,12 +182,12 @@ public virtual ClientResult<ChatCompletion> CompleteChat(IEnumerable<ChatMessage
182182
Argument.AssertNotNullOrEmpty(messages, nameof(messages));
183183

184184
options ??= new();
185-
CreateChatCompletionOptions(messages, ref options);
186-
using OpenTelemetryScope scope = _telemetry.StartChatScope(options);
185+
var clonedOptions = CreateChatCompletionOptions(messages, options);
186+
using OpenTelemetryScope scope = _telemetry.StartChatScope(clonedOptions);
187187

188188
try
189189
{
190-
using BinaryContent content = options.ToBinaryContent();
190+
using BinaryContent content = clonedOptions.ToBinaryContent();
191191
ClientResult result = CompleteChat(content, cancellationToken.ToRequestOptions());
192192
ChatCompletion chatCompletion = (ChatCompletion)result;
193193

@@ -243,9 +243,9 @@ internal AsyncCollectionResult<StreamingChatCompletionUpdate> CompleteChatStream
243243
}
244244

245245
options ??= new();
246-
CreateChatCompletionOptions(messages, ref options, stream: true);
246+
var clonedOptions = CreateChatCompletionOptions(messages, options, stream: true);
247247

248-
using BinaryContent content = options.ToBinaryContent();
248+
using BinaryContent content = clonedOptions.ToBinaryContent();
249249
return new AsyncSseUpdateCollection<StreamingChatCompletionUpdate>(
250250
async () => await CompleteChatAsync(content, requestOptions).ConfigureAwait(false),
251251
StreamingChatCompletionUpdate.DeserializeStreamingChatCompletionUpdate,
@@ -270,9 +270,9 @@ public virtual CollectionResult<StreamingChatCompletionUpdate> CompleteChatStrea
270270
Argument.AssertNotNull(messages, nameof(messages));
271271

272272
options ??= new();
273-
CreateChatCompletionOptions(messages, ref options, stream: true);
273+
var clonedOptions = CreateChatCompletionOptions(messages, options, stream: true);
274274

275-
using BinaryContent content = options.ToBinaryContent();
275+
using BinaryContent content = clonedOptions.ToBinaryContent();
276276
return new SseUpdateCollection<StreamingChatCompletionUpdate>(
277277
() => CompleteChat(content, cancellationToken.ToRequestOptions(streaming: true)),
278278
StreamingChatCompletionUpdate.DeserializeStreamingChatCompletionUpdate,
@@ -381,19 +381,24 @@ public virtual ClientResult<ChatCompletionDeletionResult> DeleteChatCompletion(s
381381
return ClientResult.FromValue((ChatCompletionDeletionResult)result, result.GetRawResponse());
382382
}
383383

384-
private void CreateChatCompletionOptions(IEnumerable<ChatMessage> messages, ref ChatCompletionOptions options, bool stream = false)
384+
private ChatCompletionOptions CreateChatCompletionOptions(IEnumerable<ChatMessage> messages, ChatCompletionOptions options, bool stream = false)
385385
{
386-
options.Messages = messages.ToList();
387-
options.Model = _model;
386+
var clonedOptions = options.Clone();
387+
foreach (var message in messages)
388+
{
389+
clonedOptions.Messages.Add(message);
390+
}
391+
clonedOptions.Model ??= _model;
388392
if (stream)
389393
{
390-
options.Stream = true;
391-
options.StreamOptions = s_includeUsageStreamOptions;
394+
clonedOptions.Stream = true;
395+
clonedOptions.StreamOptions = s_includeUsageStreamOptions;
392396
}
393397
else
394398
{
395-
options.Stream = null;
396-
options.StreamOptions = null;
399+
clonedOptions.Stream = null;
400+
clonedOptions.StreamOptions = null;
397401
}
402+
return clonedOptions;
398403
}
399404
}

src/Custom/Chat/ChatCompletionOptions.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
using System.ClientModel;
44
using System.Collections.Generic;
55
using System.Diagnostics.CodeAnalysis;
6+
using System.Linq;
7+
using System.Threading;
68

79
namespace OpenAI.Chat;
810

@@ -213,4 +215,44 @@ public ChatResponseModalities ResponseModalities
213215
public ChatOutputPrediction OutputPrediction { get; set; }
214216

215217
internal BinaryContent ToBinaryContent() => BinaryContent.Create(this, ModelSerializationExtensions.WireOptions);
218+
219+
internal ChatCompletionOptions Clone()
220+
{
221+
// Copy the values of the properties to a new instance of ChatCompletionOptions. For collection properties, create a new list and add the items from the original list.
222+
var clone = new ChatCompletionOptions();
223+
clone.Model = Model;
224+
clone.N = N;
225+
clone.Stream = Stream;
226+
clone.StreamOptions = StreamOptions;
227+
clone.IncludeLogProbabilities = IncludeLogProbabilities;
228+
clone.TopLogProbabilityCount = TopLogProbabilityCount;
229+
foreach (var s in StopSequences) clone.StopSequences.Add(s);
230+
foreach (var l in LogitBiases) clone.LogitBiases[l.Key] = l.Value;
231+
clone.ToolChoice = ToolChoice;
232+
clone.FunctionChoice = FunctionChoice;
233+
clone.AllowParallelToolCalls = AllowParallelToolCalls;
234+
clone.EndUserId = EndUserId;
235+
clone._deprecatedMaxTokens = _deprecatedMaxTokens;
236+
clone.MaxOutputTokenCount = MaxOutputTokenCount;
237+
foreach (var f in Functions) clone.Functions.Add(f);
238+
foreach (var m in Metadata) clone.Metadata[m.Key] = m.Value;
239+
clone.StoredOutputEnabled = StoredOutputEnabled;
240+
clone.ReasoningEffortLevel = ReasoningEffortLevel;
241+
clone.InternalModalities = _internalModalities?.ToList();
242+
clone.ResponseModalities = _responseModalities;
243+
clone.ResponseFormat = ResponseFormat;
244+
clone.AudioOptions = AudioOptions;
245+
clone.OutputPrediction = OutputPrediction;
246+
clone.Messages = Messages?.Select(m => m).ToList();
247+
foreach (var t in Tools) clone.Tools.Add(t);
248+
clone.Temperature = Temperature;
249+
clone.TopP = TopP;
250+
clone.SafetyIdentifier = SafetyIdentifier;
251+
clone.ServiceTier = ServiceTier;
252+
clone.FrequencyPenalty = FrequencyPenalty;
253+
clone.PresencePenalty = PresencePenalty;
254+
clone.WebSearchOptions = WebSearchOptions;
255+
clone.Seed = Seed;
256+
return clone;
257+
}
216258
}

src/Custom/Responses/CreateResponseOptions.cs

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,46 @@ public CreateResponseOptions(IEnumerable<ResponseItem> inputItems, string model
122122
[CodeGenMember("User")]
123123
public string EndUserId { get; set; }
124124

125-
internal CreateResponseOptions GetClone()
125+
internal CreateResponseOptions Clone()
126126
{
127-
CreateResponseOptions copiedOptions = (CreateResponseOptions)this.MemberwiseClone();
128-
copiedOptions.Patch = _patch;
129-
return copiedOptions;
127+
var clone = new CreateResponseOptions();
128+
foreach (var kvp in Metadata ?? Enumerable.Empty<KeyValuePair<string, string>>())
129+
{
130+
clone.Metadata[kvp.Key] = kvp.Value;
131+
}
132+
clone.Temperature = Temperature;
133+
clone.TopLogProbabilityCount = TopLogProbabilityCount;
134+
clone.TopP = TopP;
135+
clone.EndUserId = EndUserId;
136+
clone.SafetyIdentifier = SafetyIdentifier;
137+
clone.ServiceTier = ServiceTier;
138+
clone.PreviousResponseId = PreviousResponseId;
139+
clone.Model = Model;
140+
clone.ReasoningOptions = ReasoningOptions;
141+
clone.BackgroundModeEnabled = BackgroundModeEnabled;
142+
clone.MaxOutputTokenCount = MaxOutputTokenCount;
143+
clone.MaxToolCallCount = MaxToolCallCount;
144+
clone.Instructions = Instructions;
145+
clone.TextOptions = TextOptions;
146+
foreach (var tool in Tools)
147+
{
148+
clone.Tools.Add(tool);
149+
}
150+
clone.ToolChoice = ToolChoice;
151+
clone.TruncationMode = TruncationMode;
152+
foreach (var item in InputItems)
153+
{
154+
clone.InputItems.Add(item);
155+
}
156+
foreach (var item in IncludedProperties)
157+
{
158+
clone.IncludedProperties.Add(item);
159+
}
160+
clone.ParallelToolCallsEnabled = ParallelToolCallsEnabled;
161+
clone.StoredOutputEnabled = StoredOutputEnabled;
162+
clone.StreamingEnabled = StreamingEnabled;
163+
clone.ConversationOptions = ConversationOptions;
164+
165+
return clone;
130166
}
131167
}

0 commit comments

Comments
 (0)