Skip to content

Commit 476a07a

Browse files
committed
Fix unittests and the AOT compatibility.
1 parent f8653fa commit 476a07a

File tree

6 files changed

+29
-71
lines changed

6 files changed

+29
-71
lines changed

eng/Packages.Data.props

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,15 +204,15 @@
204204
</ItemGroup>
205205

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

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

214214
<ItemGroup Condition="$(MSBuildProjectName.StartsWith('Azure.AI.OpenAI'))">
215-
<PackageReference Update="OpenAI" Version="2.5.0" />
215+
<PackageReference Update="OpenAI" Version="2.6.0" />
216216
</ItemGroup>
217217

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

sdk/ai/Azure.AI.Agents/src/Custom/Internal/AdditionalPropertyHelpers.cs

Lines changed: 0 additions & 54 deletions
This file was deleted.

sdk/ai/Azure.AI.Agents/src/Custom/Internal/PipelinePolicyHelpers.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,12 @@ public static void AddAzureFinetuningParityPolicy(OpenAIClientOptions options)
199199
"Content-Disposition: form-data; name=file; filename=([^;]*);.*") is Match fileContentDispositionMatch
200200
&& fileContentDispositionMatch.Success)
201201
{
202-
newRequestWriter.WriteLine("Content-Type: application/octet-stream");
202+
// We are explicitly set the line ending as
203+
// WriteLine will add only \n symbol on Unix systems,
204+
// Which will result in error 400 on te service side.
205+
newRequestWriter.Write("Content-Type: application/octet-stream\r\n");
203206
}
204-
newRequestWriter.WriteLine(line);
207+
newRequestWriter.Write($"{line}\r\n");
205208
previousLine = line;
206209
}
207210

sdk/ai/Azure.AI.Agents/src/Custom/OpenAIFileExtensions.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
// Licensed under the MIT License.
33

44
using System;
5+
using System.ClientModel;
56
using System.Collections.Generic;
7+
using System.IO;
8+
using System.Text;
9+
using System.Text.Json;
610
using OpenAI.Files;
711

812
#pragma warning disable CS0618
@@ -13,10 +17,18 @@ public static partial class OpenAIFileExtensions
1317
{
1418
public static string GetAzureFileStatus(this OpenAIFile file)
1519
{
16-
if (AdditionalPropertyHelpers.GetAdditionalProperty<OpenAIFile, string>(file, "_sdk_status") is string extraStatusValue
17-
&& extraStatusValue.Length > 2)
20+
using BinaryContent contentBytes = BinaryContent.Create(file, ModelSerializationExtensions.WireOptions);
21+
using var stream = new MemoryStream();
22+
contentBytes.WriteTo(stream);
23+
string json = Encoding.UTF8.GetString(stream.ToArray());
24+
JsonDocument doc = JsonDocument.Parse(json);
25+
if (doc.RootElement.TryGetProperty("_sdk_status", out JsonElement extraStatusElement))
1826
{
19-
return extraStatusValue.Substring(1, extraStatusValue.Length - 2);
27+
string extraStatusValue = extraStatusElement.GetString();
28+
if (!string.IsNullOrEmpty(extraStatusValue))
29+
{
30+
return extraStatusValue;
31+
}
2032
}
2133
return null;
2234
}

sdk/ai/Azure.AI.Agents/src/Custom/ResponseCreationOptionsExtensions.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55

66
using System;
77
using System.ClientModel.Primitives;
8-
using System.Collections.Generic;
9-
using System.Reflection;
108
using OpenAI.Responses;
119

1210
#pragma warning disable OPENAI001
11+
#pragma warning disable SCME0001
1312

1413
namespace Azure.AI.Agents;
1514

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

3029
/// <summary>
@@ -60,9 +59,7 @@ public static void SetAgentReference(this ResponseCreationOptions responseCreati
6059
/// <param name="conversationId"></param>
6160
public static void SetConversationReference(this ResponseCreationOptions responseCreationOptions, string conversationId)
6261
{
63-
responseCreationOptions.SetAdditionalProperty(
64-
"conversation",
65-
BinaryData.FromString($"\"{conversationId}\""));
62+
responseCreationOptions.Patch.Set("$.conversation"u8, $"{conversationId}");
6663
}
6764

6865
/// <summary>

sdk/ai/Azure.AI.Agents/tests/Azure.AI.Agents.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
</ItemGroup>
2323
<ItemGroup>
2424
<PackageReference Include="Azure.Identity" />
25-
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" VersionOverride="9.0.0" />
25+
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" VersionOverride="9.0.9" />
2626
<PackageReference Include="NUnit" VersionOverride="4.4.0" />
2727
<PackageReference Include="NUnit3TestAdapter" VersionOverride="5.1.0"/>
2828
<PackageReference Include="Microsoft.NET.Test.Sdk" />

0 commit comments

Comments
 (0)