Skip to content

Commit 0dca1e8

Browse files
committed
Merge branch 'main' into dbohdanov/metadata-resolver-api
2 parents e9839a6 + a0e6496 commit 0dca1e8

File tree

110 files changed

+4522
-282
lines changed

Some content is hidden

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

110 files changed

+4522
-282
lines changed

.nuget/nuget.exe

8.56 MB
Binary file not shown.

eng/Versions.props

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,5 +168,8 @@
168168
Starting with 3.0.0, xunit.runner.visualstudio only supports net472, but we target net462
169169
-->
170170
<XUnitRunnerVisualStudioVersion>2.8.2</XUnitRunnerVisualStudioVersion>
171+
<!-- MEVD is still part of the Semantic Kernel repo -->
172+
<MicrosoftExtensionsVectorDataAbstractionsVersion>9.7.0</MicrosoftExtensionsVectorDataAbstractionsVersion>
173+
<MicrosoftSemanticKernelConnectorsVersion>1.66.0-preview</MicrosoftSemanticKernelConnectorsVersion>
171174
</PropertyGroup>
172175
</Project>

eng/packages/General.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="$(MicrosoftCodeAnalysisVersion)" />
1414
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="$(MicrosoftCodeAnalysisVersion)" />
1515
<PackageVersion Include="Microsoft.CodeAnalysis" Version="$(MicrosoftCodeAnalysisVersion)" />
16+
<PackageVersion Include="Microsoft.Extensions.VectorData.Abstractions" Version="$(MicrosoftExtensionsVectorDataAbstractionsVersion)" />
1617
<PackageVersion Include="Microsoft.IO.RecyclableMemoryStream" Version="3.0.0" />
1718
<PackageVersion Include="Microsoft.ML.Tokenizers" Version="$(MicrosoftMLTokenizersVersion)" />
1819
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />

eng/packages/TestOnly.props

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
<PackageVersion Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="9.0.0" />
1313
<PackageVersion Include="Microsoft.Extensions.Configuration.UserSecrets" Version="9.0.0" />
1414
<PackageVersion Include="Microsoft.ML.Tokenizers.Data.O200kBase" Version="$(MicrosoftMLTokenizersVersion)" />
15+
<PackageVersion Include="Microsoft.SemanticKernel.Connectors.InMemory" Version="$(MicrosoftSemanticKernelConnectorsVersion)" />
16+
<PackageVersion Include="Microsoft.SemanticKernel.Connectors.SqliteVec" Version="$(MicrosoftSemanticKernelConnectorsVersion)" />
1517
<PackageVersion Include="Microsoft.TemplateEngine.Authoring.TemplateVerifier" Version="9.0.201" />
1618
<PackageVersion Include="Microsoft.TemplateEngine.TestHelper" Version="9.0.200-rtm.25066.4" />
1719
<PackageVersion Include="Moq.AutoMock" Version="3.1.0" />

eng/sdl-tsa-vars.config

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-SourceToolsList @("policheck","credscan")
2+
-ArtifactToolsList @("binskim")
3+
-TsaInstanceURL https://devdiv.visualstudio.com/
4+
-TsaProjectName DEVDIV
5+
-TsaNotificationEmail [email protected]
6+
-TsaCodebaseAdmin REDMOND\aspnetcore-build
7+
-TsaBugAreaPath "DevDiv\ASP.NET Core\Policy Violations"
8+
-TsaIterationPath DevDiv
9+
-TsaRepositoryName dotnetextensions
10+
-TsaCodebaseName dotnetextensions
11+
-TsaOnboard $True
12+
-TsaPublish $True
13+
-PoliCheckAdditionalRunConfigParams @("UserExclusionPath < $(Build.SourcesDirectory)/.config/PoliCheckExclusions.xml")
14+
-CrScanAdditionalRunConfigParams @("SuppressionsPath < $(Build.SourcesDirectory)/.config/CredScanSuppressions.json")

src/Libraries/Microsoft.Extensions.AI.Abstractions/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,15 @@
22

33
## NOT YET RELEASED
44

5+
- Updated `AIFunctionFactory` to respect `[DisplayName(...)]` on functions as a way to override the function name.
6+
- Updated `AIFunctionFactory` to respect `[DefaultValue(...)]` on function parameters as a way to specify default values.
7+
8+
## 9.10.1
9+
510
- Updated `HostedMcpServerTool` to allow for non-`Uri` server addresses, in order to enable built-in names.
611
- Updated `HostedMcpServerTool` to replace the header collection with an `AuthorizationToken` property.
12+
- Fixed `ToChatResponse{Async}` to not discard `TextReasoningContent.ProtectedData` when coalescing messages.
13+
- Fixed `AIFunctionFactory.Create` to special-case return types of `AIContent` and `IEnumerable<AIContent>` to not automatically JSON serialize them.
714

815
## 9.10.0
916

src/Libraries/Microsoft.Extensions.AI.Abstractions/ChatCompletion/ChatResponseExtensions.cs

Lines changed: 110 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
using System.Collections.Generic;
66
using System.Diagnostics;
77
using System.Diagnostics.CodeAnalysis;
8+
using System.IO;
89
using System.Linq;
10+
#if !NET
11+
using System.Runtime.InteropServices;
12+
#endif
913
using System.Text;
1014
using System.Threading;
1115
using System.Threading.Tasks;
@@ -181,7 +185,7 @@ static async Task<ChatResponse> ToChatResponseAsync(
181185
}
182186

183187
/// <summary>Coalesces sequential <see cref="AIContent"/> content elements.</summary>
184-
internal static void CoalesceTextContent(IList<AIContent> contents)
188+
internal static void CoalesceContent(IList<AIContent> contents)
185189
{
186190
Coalesce<TextContent>(
187191
contents,
@@ -215,6 +219,110 @@ internal static void CoalesceTextContent(IList<AIContent> contents)
215219
return content;
216220
});
217221

222+
Coalesce<DataContent>(
223+
contents,
224+
mergeSingle: false,
225+
canMerge: static (r1, r2) => r1.MediaType == r2.MediaType && r1.HasTopLevelMediaType("text") && r1.Name == r2.Name,
226+
static (contents, start, end) =>
227+
{
228+
Debug.Assert(end - start > 1, "Expected multiple contents to merge");
229+
230+
MemoryStream ms = new();
231+
for (int i = start; i < end; i++)
232+
{
233+
var current = (DataContent)contents[i];
234+
#if NET
235+
ms.Write(current.Data.Span);
236+
#else
237+
if (!MemoryMarshal.TryGetArray(current.Data, out var segment))
238+
{
239+
segment = new(current.Data.ToArray());
240+
}
241+
242+
ms.Write(segment.Array!, segment.Offset, segment.Count);
243+
#endif
244+
}
245+
246+
var first = (DataContent)contents[start];
247+
return new DataContent(new ReadOnlyMemory<byte>(ms.GetBuffer(), 0, (int)ms.Length), first.MediaType) { Name = first.Name };
248+
});
249+
250+
Coalesce<CodeInterpreterToolCallContent>(
251+
contents,
252+
mergeSingle: true,
253+
canMerge: static (r1, r2) => r1.CallId == r2.CallId,
254+
static (contents, start, end) =>
255+
{
256+
var firstContent = (CodeInterpreterToolCallContent)contents[start];
257+
258+
if (start == end - 1)
259+
{
260+
if (firstContent.Inputs is not null)
261+
{
262+
CoalesceContent(firstContent.Inputs);
263+
}
264+
265+
return firstContent;
266+
}
267+
268+
List<AIContent>? inputs = null;
269+
270+
for (int i = start; i < end; i++)
271+
{
272+
(inputs ??= []).AddRange(((CodeInterpreterToolCallContent)contents[i]).Inputs ?? []);
273+
}
274+
275+
if (inputs is not null)
276+
{
277+
CoalesceContent(inputs);
278+
}
279+
280+
return new()
281+
{
282+
CallId = firstContent.CallId,
283+
Inputs = inputs,
284+
AdditionalProperties = firstContent.AdditionalProperties?.Clone(),
285+
};
286+
});
287+
288+
Coalesce<CodeInterpreterToolResultContent>(
289+
contents,
290+
mergeSingle: true,
291+
canMerge: static (r1, r2) => r1.CallId is not null && r2.CallId is not null && r1.CallId == r2.CallId,
292+
static (contents, start, end) =>
293+
{
294+
var firstContent = (CodeInterpreterToolResultContent)contents[start];
295+
296+
if (start == end - 1)
297+
{
298+
if (firstContent.Outputs is not null)
299+
{
300+
CoalesceContent(firstContent.Outputs);
301+
}
302+
303+
return firstContent;
304+
}
305+
306+
List<AIContent>? output = null;
307+
308+
for (int i = start; i < end; i++)
309+
{
310+
(output ??= []).AddRange(((CodeInterpreterToolResultContent)contents[i]).Outputs ?? []);
311+
}
312+
313+
if (output is not null)
314+
{
315+
CoalesceContent(output);
316+
}
317+
318+
return new()
319+
{
320+
CallId = firstContent.CallId,
321+
Outputs = output,
322+
AdditionalProperties = firstContent.AdditionalProperties?.Clone(),
323+
};
324+
});
325+
218326
static string MergeText(IList<AIContent> contents, int start, int end)
219327
{
220328
Debug.Assert(end - start > 1, "Expected multiple contents to merge");
@@ -318,7 +426,7 @@ private static void FinalizeResponse(ChatResponse response)
318426
int count = response.Messages.Count;
319427
for (int i = 0; i < count; i++)
320428
{
321-
CoalesceTextContent((List<AIContent>)response.Messages[i].Contents);
429+
CoalesceContent((List<AIContent>)response.Messages[i].Contents);
322430
}
323431
}
324432

src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/AIContent.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ namespace Microsoft.Extensions.AI;
3030
// [JsonDerivedType(typeof(McpServerToolResultContent), typeDiscriminator: "mcpServerToolResult")]
3131
// [JsonDerivedType(typeof(McpServerToolApprovalRequestContent), typeDiscriminator: "mcpServerToolApprovalRequest")]
3232
// [JsonDerivedType(typeof(McpServerToolApprovalResponseContent), typeDiscriminator: "mcpServerToolApprovalResponse")]
33+
// [JsonDerivedType(typeof(CodeInterpreterToolCallContent), typeDiscriminator: "codeInterpreterToolCall")]
34+
// [JsonDerivedType(typeof(CodeInterpreterToolResultContent), typeDiscriminator: "codeInterpreterToolResult")]
3335

3436
public class AIContent
3537
{
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Collections.Generic;
5+
using System.Diagnostics.CodeAnalysis;
6+
7+
namespace Microsoft.Extensions.AI;
8+
9+
/// <summary>
10+
/// Represents a code interpreter tool call invocation by a hosted service.
11+
/// </summary>
12+
/// <remarks>
13+
/// This content type represents when a hosted AI service invokes a code interpreter tool.
14+
/// It is informational only and represents the call itself, not the result.
15+
/// </remarks>
16+
[Experimental("MEAI001")]
17+
public sealed class CodeInterpreterToolCallContent : AIContent
18+
{
19+
/// <summary>
20+
/// Initializes a new instance of the <see cref="CodeInterpreterToolCallContent"/> class.
21+
/// </summary>
22+
public CodeInterpreterToolCallContent()
23+
{
24+
}
25+
26+
/// <summary>
27+
/// Gets or sets the tool call ID.
28+
/// </summary>
29+
public string? CallId { get; set; }
30+
31+
/// <summary>
32+
/// Gets or sets the inputs to the code interpreter tool.
33+
/// </summary>
34+
/// <remarks>
35+
/// Inputs can include various types of content such as <see cref="HostedFileContent"/> for files,
36+
/// <see cref="DataContent"/> for binary data, or other <see cref="AIContent"/> types as supported
37+
/// by the service. Typically <see cref="Inputs"/> includes a <see cref="DataContent"/> with a "text/x-python"
38+
/// media type representing the code for execution by the code interpreter tool.
39+
/// </remarks>
40+
public IList<AIContent>? Inputs { get; set; }
41+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Collections.Generic;
5+
using System.Diagnostics.CodeAnalysis;
6+
7+
namespace Microsoft.Extensions.AI;
8+
9+
/// <summary>
10+
/// Represents the result of a code interpreter tool invocation by a hosted service.
11+
/// </summary>
12+
[Experimental("MEAI001")]
13+
public sealed class CodeInterpreterToolResultContent : AIContent
14+
{
15+
/// <summary>
16+
/// Initializes a new instance of the <see cref="CodeInterpreterToolResultContent"/> class.
17+
/// </summary>
18+
public CodeInterpreterToolResultContent()
19+
{
20+
}
21+
22+
/// <summary>
23+
/// Gets or sets the tool call ID that this result corresponds to.
24+
/// </summary>
25+
public string? CallId { get; set; }
26+
27+
/// <summary>
28+
/// Gets or sets the output of code interpreter tool.
29+
/// </summary>
30+
/// <remarks>
31+
/// Outputs can include various types of content such as <see cref="HostedFileContent"/> for files,
32+
/// <see cref="DataContent"/> for binary data, <see cref="TextContent"/> for standard output text,
33+
/// or other <see cref="AIContent"/> types as supported by the service.
34+
/// </remarks>
35+
public IList<AIContent>? Outputs { get; set; }
36+
}

0 commit comments

Comments
 (0)