Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions eng/Packages.Data.props
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
<PackageReference Update="System.Text.Json" Version="8.0.6" />
<PackageReference Update="System.Text.Encodings.Web" Version="8.0.0" />
<PackageReference Update="System.ValueTuple" Version="4.5.0" />
<PackageReference Update="Microsoft.Bcl.AsyncInterfaces" Version="8.0.0" />
<PackageReference Update="Microsoft.Bcl.AsyncInterfaces" Version="9.0.9" />
<PackageReference Update="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Update="Microsoft.Extensions.Logging.Abstractions" Version="8.0.3"/>

Expand Down Expand Up @@ -204,15 +204,15 @@
</ItemGroup>

<ItemGroup Condition="$(MSBuildProjectName.StartsWith('Azure.AI.Agents'))">
<PackageReference Update="OpenAI" Version="[2.5.0,3.0)" />
<PackageReference Update="OpenAI" Version="[2.6.0,3.0)" />
</ItemGroup>

<ItemGroup Condition="$(MSBuildProjectName.StartsWith('Azure.AI.Projects'))">
<PackageReference Update="OpenAI" Version="[2.5.0,3.0)" />
<PackageReference Update="OpenAI" Version="[2.6.0,3.0)" />
</ItemGroup>

<ItemGroup Condition="$(MSBuildProjectName.StartsWith('Azure.AI.OpenAI'))">
<PackageReference Update="OpenAI" Version="2.5.0" />
<PackageReference Update="OpenAI" Version="2.6.0" />
</ItemGroup>

<ItemGroup Condition="$(MSBuildProjectName.StartsWith('Azure.Developer.Playwright'))">
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,12 @@ public static void AddAzureFinetuningParityPolicy(OpenAIClientOptions options)
"Content-Disposition: form-data; name=file; filename=([^;]*);.*") is Match fileContentDispositionMatch
&& fileContentDispositionMatch.Success)
{
newRequestWriter.WriteLine("Content-Type: application/octet-stream");
// We are explicitly set the line ending as
// WriteLine will add only \n symbol on Unix systems,
// Which will result in error 400 on te service side.
newRequestWriter.Write("Content-Type: application/octet-stream\r\n");
}
newRequestWriter.WriteLine(line);
newRequestWriter.Write($"{line}\r\n");
Copy link
Member

@trrwilson trrwilson Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it the case that Write is AOT-compatible and WriteLine isn't? That's so strange!!

I'd normally suggest that we should use Environment.NewLine instead of an explicit \r\n, but I have a sneaking suspicion that Environment.Newline resolution might be exactly why WriteLine doesn't work -- is that the case? newRequestWriter.Write(line).Write(Environment.NewLine) is "cleaner," but not if reproduces the same break!

Functionally, as long as this still works across platforms (which should be caught by SDK tests), I have no issue with the explicit \r\n there.

previousLine = line;
}

Expand Down
18 changes: 15 additions & 3 deletions sdk/ai/Azure.AI.Agents/src/Custom/OpenAIFileExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
// Licensed under the MIT License.

using System;
using System.ClientModel;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Text.Json;
using OpenAI.Files;

#pragma warning disable CS0618
Expand All @@ -13,10 +17,18 @@ public static partial class OpenAIFileExtensions
{
public static string GetAzureFileStatus(this OpenAIFile file)
{
if (AdditionalPropertyHelpers.GetAdditionalProperty<OpenAIFile, string>(file, "_sdk_status") is string extraStatusValue
&& extraStatusValue.Length > 2)
using BinaryContent contentBytes = BinaryContent.Create(file, ModelSerializationExtensions.WireOptions);
using var stream = new MemoryStream();
contentBytes.WriteTo(stream);
string json = Encoding.UTF8.GetString(stream.ToArray());
JsonDocument doc = JsonDocument.Parse(json);
if (doc.RootElement.TryGetProperty("_sdk_status", out JsonElement extraStatusElement))
{
return extraStatusValue.Substring(1, extraStatusValue.Length - 2);
string extraStatusValue = extraStatusElement.GetString();
if (!string.IsNullOrEmpty(extraStatusValue))
{
return extraStatusValue;
}
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@

using System;
using System.ClientModel.Primitives;
using System.Collections.Generic;
using System.Reflection;
using OpenAI.Responses;

#pragma warning disable OPENAI001
#pragma warning disable SCME0001

namespace Azure.AI.Agents;

Expand All @@ -22,9 +21,9 @@ public static partial class ResponseCreationOptionsExtensions
/// <param name="agentReference"></param>
public static void SetAgentReference(this ResponseCreationOptions responseCreationOptions, AgentReference agentReference)
{
AdditionalPropertyHelpers.SetAdditionalProperty(responseCreationOptions, "agent", agentReference);
// Agent specification is mutually exclusive with model specification; see internal issue 4770700
AdditionalPropertyHelpers.SetAdditionalProperty(responseCreationOptions, "model", BinaryData.FromBytes("\"__EMPTY__\""u8.ToArray()));
BinaryData agentReferenceBin = ModelReaderWriter.Write(agentReference, ModelSerializationExtensions.WireOptions, AzureAIAgentsContext.Default);
responseCreationOptions.Patch.Set("$.agent"u8, agentReferenceBin);
responseCreationOptions.Patch.Remove("$.model"u8);
}

/// <summary>
Expand Down Expand Up @@ -60,9 +59,7 @@ public static void SetAgentReference(this ResponseCreationOptions responseCreati
/// <param name="conversationId"></param>
public static void SetConversationReference(this ResponseCreationOptions responseCreationOptions, string conversationId)
{
responseCreationOptions.SetAdditionalProperty(
"conversation",
BinaryData.FromString($"\"{conversationId}\""));
responseCreationOptions.Patch.Set("$.conversation"u8, $"{conversationId}");
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Azure.Identity" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" VersionOverride="9.0.0" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" VersionOverride="9.0.9" />
<PackageReference Include="NUnit" VersionOverride="4.4.0" />
<PackageReference Include="NUnit3TestAdapter" VersionOverride="5.1.0"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
Expand Down
32 changes: 16 additions & 16 deletions sdk/openai/Azure.AI.OpenAI/src/Custom/Chat/AzureChatClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#pragma warning disable AOAI001
#pragma warning disable AZC0112
#pragma warning disable SCME0001

namespace Azure.AI.OpenAI.Chat;

Expand Down Expand Up @@ -86,16 +87,14 @@ public override CollectionResult<StreamingChatCompletionUpdate> CompleteChatStre
*/
private static void PostfixClearStreamOptions(IEnumerable<ChatMessage> messages, ref ChatCompletionOptions options)
{
if (AdditionalPropertyHelpers
.GetAdditionalPropertyAsListOfChatDataSource(options?.SerializedAdditionalRawData, "data_sources")?.Count > 0
if (options?.GetDataSources()?.Count > 0
|| messages?.Any(
message => message?.Content?.Any(
contentPart => contentPart?.Kind == ChatMessageContentPartKind.Image) == true)
== true)
{
options ??= new();
options.SerializedAdditionalRawData ??= new Dictionary<string, BinaryData>();
AdditionalPropertyHelpers.SetEmptySentinelValue(options.SerializedAdditionalRawData, "stream_options");
options.Patch.Remove("$.stream_options"u8);
}
}

Expand All @@ -114,14 +113,13 @@ private static void PostfixSwapMaxTokens(ref ChatCompletionOptions options)
{
options ??= new();
bool valueIsSet = options.MaxOutputTokenCount is not null;
bool oldPropertyBlocked = AdditionalPropertyHelpers.GetIsEmptySentinelValue(options.SerializedAdditionalRawData, "max_tokens");
bool oldPropertyBlocked = AdditionalPropertyHelpers.GetIsEmptySentinelValue(options.Patch, "$.max_tokens"u8);

if (valueIsSet)
{
if (!oldPropertyBlocked)
{
options.SerializedAdditionalRawData ??= new ChangeTrackingDictionary<string, BinaryData>();
AdditionalPropertyHelpers.SetEmptySentinelValue(options.SerializedAdditionalRawData, "max_completion_tokens");
options.Patch.Remove("$.max_completion_tokens"u8);

using MemoryStream stream = new();
using Utf8JsonWriter writer = new(stream);
Expand All @@ -137,28 +135,30 @@ private static void PostfixSwapMaxTokens(ref ChatCompletionOptions options)

writer.Flush();

options.SerializedAdditionalRawData["max_tokens"] = BinaryData.FromBytes(stream.ToArray());
options.Patch.Set("$.max_tokens"u8, BinaryData.FromBytes(stream.ToArray()));
}
else
{
if (options.Patch.Contains("$.max_tokens"u8))
{
options.Patch.Remove("$.max_tokens"u8);
}
// Allow standard serialization to the new property to occur; remove overrides
if (options.SerializedAdditionalRawData.ContainsKey("max_completion_tokens"))
if (options.Patch.Contains("$.max_completion_tokens"u8))
{
options.SerializedAdditionalRawData.Remove("max_completion_tokens");
options.Patch.Remove("$.max_completion_tokens"u8);
}
}
}
else
{
if (!AdditionalPropertyHelpers.GetIsEmptySentinelValue(options.SerializedAdditionalRawData, "max_tokens")
&& options.SerializedAdditionalRawData?.ContainsKey("max_tokens") == true)
if (options.Patch.Contains("$.max_tokens"u8))
{
options.SerializedAdditionalRawData.Remove("max_tokens");
options.Patch.Remove("$.max_tokens"u8);
}
if (!AdditionalPropertyHelpers.GetIsEmptySentinelValue(options.SerializedAdditionalRawData, "max_completion_tokens")
&& options.SerializedAdditionalRawData?.ContainsKey("max_completion_tokens") == true)
if (options.Patch.Contains("$.max_completion_tokens"u8))
{
options.SerializedAdditionalRawData.Remove("max_completion_tokens");
options.Patch.Remove("$.max_completion_tokens"u8);
}
}
}
Expand Down
Loading
Loading