Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
9858a75
Created potential extensible FunctionInvokingChatClientV2
rogerbarreto Apr 19, 2025
3df56aa
Adding FunctionInvocationContextV2 and making AutoFunctionInvocation …
rogerbarreto Apr 19, 2025
48b50ee
Most Tests passing, missing identify reference issue
rogerbarreto Apr 19, 2025
e805c93
Using KernelArguments as Specialization of AIFunctionArguments and re…
rogerbarreto Apr 22, 2025
968190f
Fix typo
rogerbarreto Apr 22, 2025
193be17
Fix warnings
rogerbarreto Apr 22, 2025
a778718
Fix formatting
rogerbarreto Apr 22, 2025
6af06b8
Removing unused property
rogerbarreto Apr 23, 2025
2316427
Merge branch 'issues/11628-functioninvoking-extension' of https://git…
rogerbarreto Apr 23, 2025
bb97a21
Changes for 9.5
rogerbarreto Apr 29, 2025
7c014a5
SK update to use latest MEAI 9.5 Function invoking chat client
rogerbarreto Apr 29, 2025
340fbbe
Update to latest changes in 9.5.0-dev
rogerbarreto Apr 30, 2025
166bb29
Update latest MEAI version with Functin Invocking changes
rogerbarreto May 1, 2025
054fcf9
Remove unused files
rogerbarreto May 1, 2025
ebed086
Merge branch 'feature-msextensions-ai' into issues/11628-functioninvo…
rogerbarreto May 1, 2025
a7b531e
Revert nuget.config
rogerbarreto May 1, 2025
1bc29f8
Merge branch 'issues/11628-functioninvoking-extension' of https://git…
rogerbarreto May 1, 2025
b268871
Revert nuget.config
rogerbarreto May 1, 2025
c899c81
Remove unrelated test
rogerbarreto May 1, 2025
6b5eea3
Revert undesired changes
rogerbarreto May 1, 2025
f5847b9
Prevent unrelated warnings
rogerbarreto May 1, 2025
2503d58
Revert "Prevent unrelated warnings"
rogerbarreto May 1, 2025
2fbc65c
Merge branch 'feature-msextensions-ai' of https://github.com/microsof…
rogerbarreto May 1, 2025
d012c3d
Address latest changes to AutoFunctionInvocationContext
rogerbarreto May 2, 2025
c47cde7
Add missing UT
rogerbarreto May 2, 2025
c87d46d
Merge branch 'feature-msextensions-ai' into issues/11628-functioninvo…
rogerbarreto May 2, 2025
786df01
Fix warning
rogerbarreto May 2, 2025
cb40a56
Remove AIArguments + fix UT namespace
rogerbarreto May 2, 2025
062406f
Fix using order
rogerbarreto May 2, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -155,16 +155,16 @@ public static IServiceCollection AddOllamaChatCompletion(
{
var loggerFactory = serviceProvider.GetService<ILoggerFactory>();

var builder = ((IChatClient)new OllamaApiClient(endpoint, modelId))
.AsBuilder()
.UseFunctionInvocation(loggerFactory, config => config.MaximumIterationsPerRequest = MaxInflightAutoInvokes);
var ollamaClient = (IChatClient)new OllamaApiClient(endpoint, modelId);

if (loggerFactory is not null)
{
builder.UseLogging(loggerFactory);
ollamaClient.AsBuilder().UseLogging(loggerFactory).Build();
}

return builder.Build(serviceProvider).AsChatCompletionService(serviceProvider);
return ollamaClient
.AsKernelFunctionInvokingChatClient(loggerFactory)
.AsChatCompletionService();
});
}

Expand All @@ -190,16 +190,16 @@ public static IServiceCollection AddOllamaChatCompletion(

var loggerFactory = serviceProvider.GetService<ILoggerFactory>();

var builder = ((IChatClient)new OllamaApiClient(httpClient, modelId))
.AsBuilder()
.UseFunctionInvocation(loggerFactory, config => config.MaximumIterationsPerRequest = MaxInflightAutoInvokes);
var ollamaClient = (IChatClient)new OllamaApiClient(httpClient, modelId);

if (loggerFactory is not null)
{
builder.UseLogging(loggerFactory);
ollamaClient.AsBuilder().UseLogging(loggerFactory).Build();
}

return builder.Build(serviceProvider).AsChatCompletionService(serviceProvider);
return ollamaClient
.AsKernelFunctionInvokingChatClient(loggerFactory)
.AsChatCompletionService();
});
}

Expand Down Expand Up @@ -231,15 +231,16 @@ public static IServiceCollection AddOllamaChatCompletion(
}

var builder = ((IChatClient)ollamaClient)
.AsBuilder()
.UseFunctionInvocation(loggerFactory, config => config.MaximumIterationsPerRequest = MaxInflightAutoInvokes);
.AsKernelFunctionInvokingChatClient(loggerFactory)
.AsBuilder();

if (loggerFactory is not null)
{
builder.UseLogging(loggerFactory);
}

return builder.Build(serviceProvider).AsChatCompletionService(serviceProvider);
return builder.Build(serviceProvider)
.AsChatCompletionService(serviceProvider);
});
}

Expand Down Expand Up @@ -355,26 +356,4 @@ public static IServiceCollection AddOllamaTextEmbeddingGeneration(
}

#endregion

#region Private

/// <summary>
/// The maximum number of auto-invokes that can be in-flight at any given time as part of the current
/// asynchronous chain of execution.
/// </summary>
/// <remarks>
/// This is a fail-safe mechanism. If someone accidentally manages to set up execution settings in such a way that
/// auto-invocation is invoked recursively, and in particular where a prompt function is able to auto-invoke itself,
/// we could end up in an infinite loop. This const is a backstop against that happening. We should never come close
/// to this limit, but if we do, auto-invoke will be disabled for the current flow in order to prevent runaway execution.
/// With the current setup, the way this could possibly happen is if a prompt function is configured with built-in
/// execution settings that opt-in to auto-invocation of everything in the kernel, in which case the invocation of that
/// prompt function could advertize itself as a candidate for auto-invocation. We don't want to outright block that,
/// if that's something a developer has asked to do (e.g. it might be invoked with different arguments than its parent
/// was invoked with), but we do want to limit it. This limit is arbitrary and can be tweaked in the future and/or made
/// configurable should need arise.
/// </remarks>
private const int MaxInflightAutoInvokes = 128;

#endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ public void Dispose()
private static object? GetLastFunctionResultFromChatResponse(ChatResponse chatResponse)
{
Assert.NotEmpty(chatResponse.Messages);
var chatMessage = chatResponse.Messages[^1];
var chatMessage = chatResponse.Messages.Where(m => m.Role == ChatRole.Tool).Last();

Assert.NotEmpty(chatMessage.Contents);
Assert.Contains(chatMessage.Contents, c => c is Microsoft.Extensions.AI.FunctionResultContent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
using System.Threading.Tasks;
using Microsoft.SemanticKernel.Http;

#pragma warning disable CA1859 // Use concrete types when possible for improved performance

namespace Microsoft.SemanticKernel.Plugins.OpenApi;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
// Copyright (c) Microsoft. All rights reserved.

using System;
using System.Threading.Tasks;
using Xunit;
using Microsoft.SemanticKernel.Plugins.Core.CodeInterpreter;
using Microsoft.Extensions.Configuration;
using SemanticKernel.IntegrationTests.TestSettings;
using System.Collections.Generic;
using System.Net.Http;
using Azure.Identity;
using System.Threading.Tasks;
using Azure.Core;
using System.Collections.Generic;
using Microsoft.SemanticKernel;
using Azure.Identity;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.ChatCompletion;
using Microsoft.SemanticKernel.Connectors.AzureOpenAI;
using Microsoft.SemanticKernel.Plugins.Core.CodeInterpreter;
using SemanticKernel.IntegrationTests.TestSettings;
using Xunit;

namespace SemanticKernel.IntegrationTests.Plugins.Core;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ internal sealed class FunctionCallsProcessor
/// will be disabled. This is a safeguard against possible runaway execution if the model routinely re-requests
/// the same function over and over.
/// </remarks>
private const int MaximumAutoInvokeAttempts = 128;
internal const int MaximumAutoInvokeAttempts = 128;

/// <summary>Tracking <see cref="AsyncLocal{Int32}"/> for <see cref="MaxInflightAutoInvokes"/>.</summary>
/// <remarks>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ namespace Microsoft.SemanticKernel.ChatCompletion;
internal static class ChatOptionsExtensions
{
internal const string KernelKey = "AutoInvokingKernel";
internal const string IsStreamingKey = "AutoInvokingIsStreaming";
internal const string ChatMessageContentKey = "AutoInvokingChatCompletionContent";
internal const string PromptExecutionSettingsKey = "AutoInvokingPromptExecutionSettings";

Expand Down
Loading
Loading