Skip to content

Commit 246ac76

Browse files
authored
.Net: Update Connector Dependencies + BugFix (#12610)
### Motivation and Context Update dependencies and small bugfix where ChatClient as CompletionServices were not updating the FunctionResultContent.FunctionName.
1 parent 6291383 commit 246ac76

File tree

4 files changed

+38
-26
lines changed

4 files changed

+38
-26
lines changed

dotnet/Directory.Packages.props

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
<PackageVersion Include="AWSSDK.SecurityToken" Version="4.0.1.2" />
2020
<PackageVersion Include="Azure.AI.Agents.Persistent" Version="1.0.0" />
2121
<PackageVersion Include="Azure.AI.ContentSafety" Version="1.0.0" />
22-
<PackageVersion Include="Azure.AI.Inference" Version="1.0.0-beta.5" />
2322
<PackageVersion Include="Azure.AI.OpenAI" Version="[2.2.0-beta.4]" />
2423
<PackageVersion Include="Azure.AI.Projects" Version="1.0.0-beta.9" />
2524
<PackageVersion Include="Azure.Identity" Version="1.13.2" />
@@ -79,7 +78,7 @@
7978
<PackageVersion Include="MSTest.TestFramework" Version="3.8.0" />
8079
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
8180
<PackageVersion Include="Npgsql" Version="8.0.6" />
82-
<PackageVersion Include="OllamaSharp" Version="5.1.12" />
81+
<PackageVersion Include="OllamaSharp" Version="5.2.3" />
8382
<PackageVersion Include="OpenAI" Version="[2.2.0-beta.4]" />
8483
<PackageVersion Include="OpenTelemetry.Exporter.Console" Version="1.9.0" />
8584
<PackageVersion Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.9.0" />
@@ -98,7 +97,7 @@
9897
<PackageVersion Include="System.Linq.Async" Version="6.0.1" />
9998
<PackageVersion Include="System.Memory.Data" Version="8.0.1" />
10099
<PackageVersion Include="System.Net.Http" Version="4.3.4" />
101-
<PackageVersion Include="System.Numerics.Tensors" Version="9.0.0" />
100+
<PackageVersion Include="System.Numerics.Tensors" Version="9.0.6" />
102101
<PackageVersion Include="System.Text.Json" Version="8.0.5" />
103102
<PackageVersion Include="System.ValueTuple" Version="4.6.1" />
104103
<PackageVersion Include="System.Threading.Tasks.Extensions" Version="4.6.3" />
@@ -110,9 +109,9 @@
110109
<PackageVersion Include="Microsoft.DeepDev.TokenizerLib" Version="1.3.3" />
111110
<PackageVersion Include="SharpToken" Version="2.0.3" />
112111
<!-- Microsoft.Extensions.* -->
113-
<PackageVersion Include="Microsoft.Extensions.AI" Version="9.5.0" />
112+
<PackageVersion Include="Microsoft.Extensions.AI" Version="9.6.0" />
114113
<PackageVersion Include="Microsoft.Extensions.AI.Abstractions" Version="9.5.0" />
115-
<PackageVersion Include="Microsoft.Extensions.AI.AzureAIInference" Version="9.5.0-preview.1.25265.7" />
114+
<PackageVersion Include="Microsoft.Extensions.AI.AzureAIInference" Version="9.6.0-preview.1.25310.2" />
116115
<PackageVersion Include="Microsoft.Extensions.AI.OpenAI" Version="9.5.0-preview.1.25265.7" />
117116
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
118117
<PackageVersion Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
@@ -145,7 +144,7 @@
145144
<PackageVersion Include="System.Threading.Tasks.Dataflow" Version="8.0.0" />
146145
<PackageVersion Include="xunit" Version="2.9.2" />
147146
<PackageVersion Include="xunit.abstractions" Version="2.0.3" />
148-
<PackageVersion Include="xunit.runner.visualstudio" Version="3.0.2" />
147+
<PackageVersion Include="xunit.runner.visualstudio" Version="3.1.1" />
149148
<PackageVersion Include="xretry" Version="1.9.0" />
150149
<PackageVersion Include="coverlet.collector" Version="6.0.4" />
151150
<PackageVersion Include="Docker.DotNet" Version="3.125.15" />
@@ -218,7 +217,7 @@
218217
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
219218
</PackageReference>
220219
<!-- OnnxRuntimeGenAI -->
221-
<PackageVersion Include="Microsoft.ML.OnnxRuntimeGenAI" Version="0.8.1" />
220+
<PackageVersion Include="Microsoft.ML.OnnxRuntimeGenAI" Version="0.8.2" />
222221
<PackageVersion Include="Microsoft.ML.OnnxRuntimeGenAI.Cuda" Version="0.8.1" />
223222
<PackageVersion Include="Microsoft.ML.OnnxRuntimeGenAI.DirectML" Version="0.8.1" />
224223
<!-- SpectreConsole-->

dotnet/src/IntegrationTests/Connectors/Ollama/OllamaChatClientIntegrationTests.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public OllamaChatClientIntegrationTests(ITestOutputHelper output)
3232
.Build();
3333
}
3434

35-
[Theory(Skip = "This test is for manual verification.")]
35+
[Theory(Skip = "For manual verification only")]
3636
[InlineData("phi3")]
3737
[InlineData("llama3.2")]
3838
public async Task OllamaChatClientBasicUsageAsync(string modelId)
@@ -56,7 +56,7 @@ public async Task OllamaChatClientBasicUsageAsync(string modelId)
5656
this._output.WriteLine($"Response: {response.Text}");
5757
}
5858

59-
[Theory(Skip = "This test is for manual verification.")]
59+
[Theory(Skip = "For manual verification only")]
6060
[InlineData("phi3")]
6161
[InlineData("llama3.2")]
6262
public async Task OllamaChatClientStreamingUsageAsync(string modelId)
@@ -87,7 +87,7 @@ public async Task OllamaChatClientStreamingUsageAsync(string modelId)
8787
this._output.WriteLine($"Complete response: {responseText}");
8888
}
8989

90-
[Theory(Skip = "This test is for manual verification.")]
90+
[Theory(Skip = "For manual verification only")]
9191
[InlineData("phi3")]
9292
public async Task OllamaChatClientWithOptionsAsync(string modelId)
9393
{
@@ -116,7 +116,7 @@ public async Task OllamaChatClientWithOptionsAsync(string modelId)
116116
this._output.WriteLine($"Response: {response.Text}");
117117
}
118118

119-
[Fact(Skip = "This test is for manual verification.")]
119+
[Fact(Skip = "For manual verification only")]
120120
public async Task OllamaChatClientServiceCollectionIntegrationAsync()
121121
{
122122
// Arrange
@@ -146,7 +146,7 @@ public async Task OllamaChatClientServiceCollectionIntegrationAsync()
146146
this._output.WriteLine($"Response: {response.Text}");
147147
}
148148

149-
[Fact(Skip = "This test is for manual verification.")]
149+
[Fact(Skip = "For manual verification only")]
150150
public async Task OllamaChatClientKernelBuilderIntegrationAsync()
151151
{
152152
// Arrange
@@ -173,7 +173,7 @@ public async Task OllamaChatClientKernelBuilderIntegrationAsync()
173173
this._output.WriteLine($"Response: {response.Text}");
174174
}
175175

176-
[Fact]
176+
[Fact(Skip = "For manual verification only")]
177177
public void OllamaChatClientMetadataTest()
178178
{
179179
// Arrange
@@ -190,7 +190,7 @@ public void OllamaChatClientMetadataTest()
190190
Assert.Equal(modelId, metadata.DefaultModelId);
191191
}
192192

193-
[Fact(Skip = "This test is for manual verification.")]
193+
[Fact(Skip = "For manual verification only")]
194194
public async Task OllamaChatClientWithKernelFunctionInvocationAsync()
195195
{
196196
// Arrange

dotnet/src/IntegrationTests/Connectors/Ollama/OllamaChatCompletion_FunctionCallingTests.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Microsoft.SemanticKernel;
88
using Microsoft.SemanticKernel.ChatCompletion;
99
using SemanticKernel.IntegrationTests.TestSettings;
10+
using xRetry;
1011
using Xunit;
1112

1213
using ChatMessageContent = Microsoft.SemanticKernel.ChatMessageContent;
@@ -142,7 +143,7 @@ public async Task ConnectorAgnosticFunctionCallingModelClassesCanBeUsedForManual
142143
Assert.Contains("rain", messageContent.Content, StringComparison.InvariantCultureIgnoreCase);
143144
}
144145

145-
[Fact(Skip = "For manual verification only")]
146+
[RetryFact(Skip = "For manual verification only")]
146147
public async Task ConnectorAgnosticFunctionCallingModelClassesCanPassFunctionExceptionToConnectorAsync()
147148
{
148149
// Arrange
@@ -158,7 +159,6 @@ public async Task ConnectorAgnosticFunctionCallingModelClassesCanPassFunctionExc
158159

159160
// Act
160161
var messageContent = await completionService.GetChatMessageContentAsync(chatHistory, settings, kernel);
161-
162162
var functionCalls = FunctionCallContent.GetFunctionCalls(messageContent).ToArray();
163163

164164
while (functionCalls.Length != 0)
@@ -215,7 +215,7 @@ public async Task ConnectorAgnosticFunctionCallingModelClassesSupportSimulatedFu
215215
Assert.Contains("tornado", messageContent.Content, StringComparison.InvariantCultureIgnoreCase);
216216
}
217217

218-
[Fact(Skip = "For manual verification only")]
218+
[RetryFact(Skip = "For manual verification only")]
219219
public async Task ConnectorAgnosticFunctionCallingModelClassesCanBeUsedForAutoFunctionCallingAsync()
220220
{
221221
// Arrange
@@ -236,7 +236,7 @@ public async Task ConnectorAgnosticFunctionCallingModelClassesCanBeUsedForAutoFu
236236
Assert.Equal(AuthorRole.User, userMessage.Role);
237237

238238
// LLM requested the functions to call.
239-
var getParallelFunctionCallRequestMessage = chatHistory[1];
239+
var getParallelFunctionCallRequestMessage = chatHistory.First(m => m.Items.Any(i => i is FunctionCallContent));
240240
Assert.Equal(AuthorRole.Assistant, getParallelFunctionCallRequestMessage.Role);
241241

242242
// Parallel Function Calls in the same request
@@ -250,16 +250,16 @@ public async Task ConnectorAgnosticFunctionCallingModelClassesCanBeUsedForAutoFu
250250
getWeatherForCityFunctionCallRequest = functionCalls[0];
251251

252252
// Connector invoked the Get_Weather_For_City function and added result to chat history.
253-
getWeatherForCityFunctionCallResultMessage = chatHistory[2];
253+
getWeatherForCityFunctionCallResultMessage = chatHistory.First(m => m.Items.Any(i => i is FunctionResultContent));
254254

255-
Assert.Equal("HelperFunctions-Get_Weather_For_City", getWeatherForCityFunctionCallRequest.FunctionName);
255+
Assert.Equal("HelperFunctions_Get_Weather_For_City", getWeatherForCityFunctionCallRequest.FunctionName);
256256
Assert.NotNull(getWeatherForCityFunctionCallRequest.Id);
257257

258258
Assert.Equal(AuthorRole.Tool, getWeatherForCityFunctionCallResultMessage.Role);
259259
Assert.Single(getWeatherForCityFunctionCallResultMessage.Items.OfType<FunctionResultContent>()); // Current function calling model adds TextContent item representing the result of the function call.
260260

261261
var getWeatherForCityFunctionCallResult = getWeatherForCityFunctionCallResultMessage.Items.OfType<FunctionResultContent>().Single();
262-
Assert.Equal("HelperFunctions-Get_Weather_For_City", getWeatherForCityFunctionCallResult.FunctionName);
262+
Assert.Equal("HelperFunctions_Get_Weather_For_City", getWeatherForCityFunctionCallResult.FunctionName);
263263
Assert.Equal(getWeatherForCityFunctionCallRequest.Id, getWeatherForCityFunctionCallResult.CallId);
264264
Assert.NotNull(getWeatherForCityFunctionCallResult.Result);
265265
}
@@ -318,12 +318,12 @@ private Kernel CreateAndInitializeKernel(bool importHelperPlugin = false)
318318

319319
Assert.NotNull(config);
320320
Assert.NotNull(config.Endpoint);
321-
Assert.NotNull(config.ModelId);
321+
Assert.NotNull(config.ModelId ?? "llama3.2");
322322

323323
var kernelBuilder = base.CreateKernelBuilder();
324324

325325
kernelBuilder.AddOllamaChatCompletion(
326-
modelId: config.ModelId,
326+
modelId: config.ModelId ?? "llama3.2",
327327
endpoint: new Uri(config.Endpoint));
328328

329329
var kernel = kernelBuilder.Build();
@@ -332,7 +332,7 @@ private Kernel CreateAndInitializeKernel(bool importHelperPlugin = false)
332332
{
333333
kernel.ImportPluginFromFunctions("HelperFunctions",
334334
[
335-
kernel.CreateFunctionFromMethod(() => DateTime.UtcNow.ToString("R"), "GetCurrentUtcTime", "Retrieves the current time in UTC."),
335+
kernel.CreateFunctionFromMethod(() => DateTime.UtcNow.ToString("R"), "Get_Current_Utc_Time", "Retrieves the current time in UTC."),
336336
kernel.CreateFunctionFromMethod((string cityName) =>
337337
{
338338
return cityName switch

dotnet/src/SemanticKernel.Abstractions/AI/ChatClient/ChatMessageExtensions.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft. All rights reserved.
22

33
using System.Collections.Generic;
4+
using System.Linq;
45
using Microsoft.Extensions.AI;
56

67
namespace Microsoft.SemanticKernel.ChatCompletion;
@@ -30,8 +31,14 @@ internal static ChatMessageContent ToChatMessageContent(this ChatMessage message
3031
Microsoft.Extensions.AI.UriContent uc when uc.HasTopLevelMediaType("audio") => new Microsoft.SemanticKernel.AudioContent(uc.Uri),
3132
Microsoft.Extensions.AI.DataContent dc => new Microsoft.SemanticKernel.BinaryContent(dc.Uri),
3233
Microsoft.Extensions.AI.UriContent uc => new Microsoft.SemanticKernel.BinaryContent(uc.Uri),
33-
Microsoft.Extensions.AI.FunctionCallContent fcc => new Microsoft.SemanticKernel.FunctionCallContent(fcc.Name, null, fcc.CallId, fcc.Arguments is not null ? new(fcc.Arguments) : null),
34-
Microsoft.Extensions.AI.FunctionResultContent frc => new Microsoft.SemanticKernel.FunctionResultContent(callId: frc.CallId, result: frc.Result),
34+
Microsoft.Extensions.AI.FunctionCallContent fcc => new Microsoft.SemanticKernel.FunctionCallContent(
35+
functionName: fcc.Name,
36+
id: fcc.CallId,
37+
arguments: fcc.Arguments is not null ? new(fcc.Arguments) : null),
38+
Microsoft.Extensions.AI.FunctionResultContent frc => new Microsoft.SemanticKernel.FunctionResultContent(
39+
functionName: GetFunctionCallContent(frc.CallId)?.Name,
40+
callId: frc.CallId,
41+
result: frc.Result),
3542
_ => null
3643
};
3744

@@ -45,6 +52,12 @@ internal static ChatMessageContent ToChatMessageContent(this ChatMessage message
4552
}
4653

4754
return result;
55+
56+
Microsoft.Extensions.AI.FunctionCallContent? GetFunctionCallContent(string callId)
57+
=> response?.Messages
58+
.Select(m => m.Contents
59+
.FirstOrDefault(c => c is Microsoft.Extensions.AI.FunctionCallContent fcc && fcc.CallId == callId) as Microsoft.Extensions.AI.FunctionCallContent)
60+
.FirstOrDefault(fcc => fcc is not null);
4861
}
4962

5063
/// <summary>Converts a list of <see cref="ChatMessage"/> to a <see cref="ChatHistory"/>.</summary>

0 commit comments

Comments
 (0)