From 98fdf4523b5f09fcb77cb528ca094d702d7ab1c6 Mon Sep 17 00:00:00 2001 From: markwallace-microsoft Date: Fri, 13 Oct 2023 15:02:10 +0100 Subject: [PATCH 1/3] Move IPromptTemplate to namespace Microsoft.SemanticKernel.TemplateEngine --- dotnet/src/Functions/Functions.Semantic/SemanticFunction.cs | 1 + .../SemanticFunctions/SemanticFunctionConfig.cs | 2 ++ .../{SemanticFunctions => TemplateEngine}/IPromptTemplate.cs | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) rename dotnet/src/SemanticKernel.Abstractions/{SemanticFunctions => TemplateEngine}/IPromptTemplate.cs (94%) diff --git a/dotnet/src/Functions/Functions.Semantic/SemanticFunction.cs b/dotnet/src/Functions/Functions.Semantic/SemanticFunction.cs index 922bb71101e7..393366c5bea5 100644 --- a/dotnet/src/Functions/Functions.Semantic/SemanticFunction.cs +++ b/dotnet/src/Functions/Functions.Semantic/SemanticFunction.cs @@ -15,6 +15,7 @@ using Microsoft.SemanticKernel.Diagnostics; using Microsoft.SemanticKernel.Orchestration; using Microsoft.SemanticKernel.SemanticFunctions; +using Microsoft.SemanticKernel.TemplateEngine; #pragma warning disable IDE0130 // ReSharper disable once CheckNamespace - Using the main namespace diff --git a/dotnet/src/Functions/Functions.Semantic/SemanticFunctions/SemanticFunctionConfig.cs b/dotnet/src/Functions/Functions.Semantic/SemanticFunctions/SemanticFunctionConfig.cs index 20af5f86e7c5..661f8e8b97c3 100644 --- a/dotnet/src/Functions/Functions.Semantic/SemanticFunctions/SemanticFunctionConfig.cs +++ b/dotnet/src/Functions/Functions.Semantic/SemanticFunctions/SemanticFunctionConfig.cs @@ -1,5 +1,7 @@ // Copyright (c) Microsoft. All rights reserved. +using Microsoft.SemanticKernel.TemplateEngine; + namespace Microsoft.SemanticKernel.SemanticFunctions; /// diff --git a/dotnet/src/SemanticKernel.Abstractions/SemanticFunctions/IPromptTemplate.cs b/dotnet/src/SemanticKernel.Abstractions/TemplateEngine/IPromptTemplate.cs similarity index 94% rename from dotnet/src/SemanticKernel.Abstractions/SemanticFunctions/IPromptTemplate.cs rename to dotnet/src/SemanticKernel.Abstractions/TemplateEngine/IPromptTemplate.cs index b81d423fea8a..e0cc43e31814 100644 --- a/dotnet/src/SemanticKernel.Abstractions/SemanticFunctions/IPromptTemplate.cs +++ b/dotnet/src/SemanticKernel.Abstractions/TemplateEngine/IPromptTemplate.cs @@ -5,7 +5,7 @@ using System.Threading.Tasks; using Microsoft.SemanticKernel.Orchestration; -namespace Microsoft.SemanticKernel.SemanticFunctions; +namespace Microsoft.SemanticKernel.TemplateEngine; /// /// Interface for prompt template. From 56bffc9324e38d487a33297f12a575eaa532d09f Mon Sep 17 00:00:00 2001 From: markwallace-microsoft Date: Fri, 13 Oct 2023 15:47:49 +0100 Subject: [PATCH 2/3] Eliminate Microsoft.SemanticKernel.SemanticFunctions namespace --- .../Example58_ConfigureRequestSettings.cs | 2 +- .../Extensions/KernelSemanticFunctionExtensions.cs | 2 +- dotnet/src/Functions/Functions.Semantic/SemanticFunction.cs | 1 - .../{SemanticFunctions => TemplateEngine}/PromptTemplate.cs | 3 +-- .../PromptTemplateConfig.cs | 2 +- .../SemanticFunctionConfig.cs | 4 +--- .../SemanticFunctions/PromptTemplateConfigTests.cs | 2 +- .../SemanticFunctions/SemanticFunctionTests.cs | 2 +- .../Connectors/OpenAI/OpenAICompletionTests.cs | 2 +- .../Sequential/SequentialPlanParserTests.cs | 2 +- .../Extensions/PromptTemplateConfigExtensions.cs | 2 +- dotnet/src/Planners/Planners.Core/Stepwise/StepwisePlanner.cs | 2 +- .../Planners/Planners.Core/Stepwise/StepwisePlannerConfig.cs | 2 +- 13 files changed, 12 insertions(+), 16 deletions(-) rename dotnet/src/Functions/Functions.Semantic/{SemanticFunctions => TemplateEngine}/PromptTemplate.cs (96%) rename dotnet/src/Functions/Functions.Semantic/{SemanticFunctions => TemplateEngine}/PromptTemplateConfig.cs (98%) rename dotnet/src/Functions/Functions.Semantic/{SemanticFunctions => TemplateEngine}/SemanticFunctionConfig.cs (89%) diff --git a/dotnet/samples/KernelSyntaxExamples/Example58_ConfigureRequestSettings.cs b/dotnet/samples/KernelSyntaxExamples/Example58_ConfigureRequestSettings.cs index 991a1e399df0..3090b6f922a9 100644 --- a/dotnet/samples/KernelSyntaxExamples/Example58_ConfigureRequestSettings.cs +++ b/dotnet/samples/KernelSyntaxExamples/Example58_ConfigureRequestSettings.cs @@ -5,7 +5,7 @@ using System.Threading.Tasks; using Microsoft.SemanticKernel; using Microsoft.SemanticKernel.Connectors.AI.OpenAI; -using Microsoft.SemanticKernel.SemanticFunctions; +using Microsoft.SemanticKernel.TemplateEngine; using RepoUtils; // ReSharper disable once InconsistentNaming diff --git a/dotnet/src/Functions/Functions.Semantic/Extensions/KernelSemanticFunctionExtensions.cs b/dotnet/src/Functions/Functions.Semantic/Extensions/KernelSemanticFunctionExtensions.cs index 0d57925c73d1..51207b908b88 100644 --- a/dotnet/src/Functions/Functions.Semantic/Extensions/KernelSemanticFunctionExtensions.cs +++ b/dotnet/src/Functions/Functions.Semantic/Extensions/KernelSemanticFunctionExtensions.cs @@ -10,7 +10,7 @@ using Microsoft.SemanticKernel.AI.TextCompletion; using Microsoft.SemanticKernel.Diagnostics; using Microsoft.SemanticKernel.Orchestration; -using Microsoft.SemanticKernel.SemanticFunctions; +using Microsoft.SemanticKernel.TemplateEngine; using Microsoft.SemanticKernel.Text; #pragma warning disable IDE0130 diff --git a/dotnet/src/Functions/Functions.Semantic/SemanticFunction.cs b/dotnet/src/Functions/Functions.Semantic/SemanticFunction.cs index 393366c5bea5..38cf780a5c63 100644 --- a/dotnet/src/Functions/Functions.Semantic/SemanticFunction.cs +++ b/dotnet/src/Functions/Functions.Semantic/SemanticFunction.cs @@ -14,7 +14,6 @@ using Microsoft.SemanticKernel.AI.TextCompletion; using Microsoft.SemanticKernel.Diagnostics; using Microsoft.SemanticKernel.Orchestration; -using Microsoft.SemanticKernel.SemanticFunctions; using Microsoft.SemanticKernel.TemplateEngine; #pragma warning disable IDE0130 diff --git a/dotnet/src/Functions/Functions.Semantic/SemanticFunctions/PromptTemplate.cs b/dotnet/src/Functions/Functions.Semantic/TemplateEngine/PromptTemplate.cs similarity index 96% rename from dotnet/src/Functions/Functions.Semantic/SemanticFunctions/PromptTemplate.cs rename to dotnet/src/Functions/Functions.Semantic/TemplateEngine/PromptTemplate.cs index 722f6793431b..74b9912c9786 100644 --- a/dotnet/src/Functions/Functions.Semantic/SemanticFunctions/PromptTemplate.cs +++ b/dotnet/src/Functions/Functions.Semantic/TemplateEngine/PromptTemplate.cs @@ -6,9 +6,8 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.SemanticKernel.Orchestration; -using Microsoft.SemanticKernel.TemplateEngine; -namespace Microsoft.SemanticKernel.SemanticFunctions; +namespace Microsoft.SemanticKernel.TemplateEngine; /// /// Prompt template. diff --git a/dotnet/src/Functions/Functions.Semantic/SemanticFunctions/PromptTemplateConfig.cs b/dotnet/src/Functions/Functions.Semantic/TemplateEngine/PromptTemplateConfig.cs similarity index 98% rename from dotnet/src/Functions/Functions.Semantic/SemanticFunctions/PromptTemplateConfig.cs rename to dotnet/src/Functions/Functions.Semantic/TemplateEngine/PromptTemplateConfig.cs index d96593a7aa03..9e5817d27c0d 100644 --- a/dotnet/src/Functions/Functions.Semantic/SemanticFunctions/PromptTemplateConfig.cs +++ b/dotnet/src/Functions/Functions.Semantic/TemplateEngine/PromptTemplateConfig.cs @@ -7,7 +7,7 @@ using Microsoft.SemanticKernel.AI; using Microsoft.SemanticKernel.Text; -namespace Microsoft.SemanticKernel.SemanticFunctions; +namespace Microsoft.SemanticKernel.TemplateEngine; /// /// Prompt template configuration. diff --git a/dotnet/src/Functions/Functions.Semantic/SemanticFunctions/SemanticFunctionConfig.cs b/dotnet/src/Functions/Functions.Semantic/TemplateEngine/SemanticFunctionConfig.cs similarity index 89% rename from dotnet/src/Functions/Functions.Semantic/SemanticFunctions/SemanticFunctionConfig.cs rename to dotnet/src/Functions/Functions.Semantic/TemplateEngine/SemanticFunctionConfig.cs index 661f8e8b97c3..f5593ea10b1e 100644 --- a/dotnet/src/Functions/Functions.Semantic/SemanticFunctions/SemanticFunctionConfig.cs +++ b/dotnet/src/Functions/Functions.Semantic/TemplateEngine/SemanticFunctionConfig.cs @@ -1,8 +1,6 @@ // Copyright (c) Microsoft. All rights reserved. -using Microsoft.SemanticKernel.TemplateEngine; - -namespace Microsoft.SemanticKernel.SemanticFunctions; +namespace Microsoft.SemanticKernel.TemplateEngine; /// /// Semantic function configuration. diff --git a/dotnet/src/Functions/Functions.UnitTests/SemanticFunctions/PromptTemplateConfigTests.cs b/dotnet/src/Functions/Functions.UnitTests/SemanticFunctions/PromptTemplateConfigTests.cs index b967d3e22465..d0f17df97d5b 100644 --- a/dotnet/src/Functions/Functions.UnitTests/SemanticFunctions/PromptTemplateConfigTests.cs +++ b/dotnet/src/Functions/Functions.UnitTests/SemanticFunctions/PromptTemplateConfigTests.cs @@ -2,7 +2,7 @@ using System.Text.Json; using Microsoft.SemanticKernel.Connectors.AI.OpenAI; -using Microsoft.SemanticKernel.SemanticFunctions; +using Microsoft.SemanticKernel.TemplateEngine; using Xunit; namespace SemanticKernel.Functions.UnitTests.SemanticFunctions; diff --git a/dotnet/src/Functions/Functions.UnitTests/SemanticFunctions/SemanticFunctionTests.cs b/dotnet/src/Functions/Functions.UnitTests/SemanticFunctions/SemanticFunctionTests.cs index 9d0c1229a8c7..72607a64e62e 100644 --- a/dotnet/src/Functions/Functions.UnitTests/SemanticFunctions/SemanticFunctionTests.cs +++ b/dotnet/src/Functions/Functions.UnitTests/SemanticFunctions/SemanticFunctionTests.cs @@ -13,7 +13,7 @@ using Microsoft.SemanticKernel.Connectors.AI.OpenAI; using Microsoft.SemanticKernel.Diagnostics; using Microsoft.SemanticKernel.Events; -using Microsoft.SemanticKernel.SemanticFunctions; +using Microsoft.SemanticKernel.TemplateEngine; using Moq; using Xunit; diff --git a/dotnet/src/IntegrationTests/Connectors/OpenAI/OpenAICompletionTests.cs b/dotnet/src/IntegrationTests/Connectors/OpenAI/OpenAICompletionTests.cs index b3aaed385d99..8e5a5f17f876 100644 --- a/dotnet/src/IntegrationTests/Connectors/OpenAI/OpenAICompletionTests.cs +++ b/dotnet/src/IntegrationTests/Connectors/OpenAI/OpenAICompletionTests.cs @@ -11,7 +11,7 @@ using Microsoft.SemanticKernel.Diagnostics; using Microsoft.SemanticKernel.Orchestration; using Microsoft.SemanticKernel.Reliability.Basic; -using Microsoft.SemanticKernel.SemanticFunctions; +using Microsoft.SemanticKernel.TemplateEngine; using SemanticKernel.IntegrationTests.TestSettings; using Xunit; using Xunit.Abstractions; diff --git a/dotnet/src/Planners/Planners.Core.UnitTests/Sequential/SequentialPlanParserTests.cs b/dotnet/src/Planners/Planners.Core.UnitTests/Sequential/SequentialPlanParserTests.cs index c620f6bc45b8..f93adc889c10 100644 --- a/dotnet/src/Planners/Planners.Core.UnitTests/Sequential/SequentialPlanParserTests.cs +++ b/dotnet/src/Planners/Planners.Core.UnitTests/Sequential/SequentialPlanParserTests.cs @@ -4,7 +4,7 @@ using Microsoft.Extensions.Logging; using Microsoft.SemanticKernel.Diagnostics; using Microsoft.SemanticKernel.Orchestration; -using Microsoft.SemanticKernel.SemanticFunctions; +using Microsoft.SemanticKernel.TemplateEngine; using Moq; using Xunit; using Xunit.Abstractions; diff --git a/dotnet/src/Planners/Planners.Core/Extensions/PromptTemplateConfigExtensions.cs b/dotnet/src/Planners/Planners.Core/Extensions/PromptTemplateConfigExtensions.cs index 2d89c77451b7..594e053d4426 100644 --- a/dotnet/src/Planners/Planners.Core/Extensions/PromptTemplateConfigExtensions.cs +++ b/dotnet/src/Planners/Planners.Core/Extensions/PromptTemplateConfigExtensions.cs @@ -2,7 +2,7 @@ // ReSharper disable once CheckNamespace - Using the namespace of IKernel using Microsoft.SemanticKernel.AI; -using Microsoft.SemanticKernel.SemanticFunctions; +using Microsoft.SemanticKernel.TemplateEngine; #pragma warning disable IDE0130 namespace Microsoft.SemanticKernel.Planners; diff --git a/dotnet/src/Planners/Planners.Core/Stepwise/StepwisePlanner.cs b/dotnet/src/Planners/Planners.Core/Stepwise/StepwisePlanner.cs index 6360fb167548..8adaf550b428 100644 --- a/dotnet/src/Planners/Planners.Core/Stepwise/StepwisePlanner.cs +++ b/dotnet/src/Planners/Planners.Core/Stepwise/StepwisePlanner.cs @@ -16,8 +16,8 @@ using Microsoft.SemanticKernel.Diagnostics; using Microsoft.SemanticKernel.Orchestration; using Microsoft.SemanticKernel.Planning; -using Microsoft.SemanticKernel.SemanticFunctions; using Microsoft.SemanticKernel.Services; +using Microsoft.SemanticKernel.TemplateEngine; using Microsoft.SemanticKernel.TemplateEngine.Basic; #pragma warning disable IDE0130 diff --git a/dotnet/src/Planners/Planners.Core/Stepwise/StepwisePlannerConfig.cs b/dotnet/src/Planners/Planners.Core/Stepwise/StepwisePlannerConfig.cs index 0b858d73cd55..545edf191cb9 100644 --- a/dotnet/src/Planners/Planners.Core/Stepwise/StepwisePlannerConfig.cs +++ b/dotnet/src/Planners/Planners.Core/Stepwise/StepwisePlannerConfig.cs @@ -1,6 +1,6 @@ // Copyright (c) Microsoft. All rights reserved. -using Microsoft.SemanticKernel.SemanticFunctions; +using Microsoft.SemanticKernel.TemplateEngine; #pragma warning disable IDE0130 // ReSharper disable once CheckNamespace - Using NS of Plan From b71941370f23cf25a64deccc0b26cc04b0daf606 Mon Sep 17 00:00:00 2001 From: markwallace-microsoft Date: Fri, 13 Oct 2023 17:07:10 +0100 Subject: [PATCH 3/3] Remove SemanticFunctionConfig --- .../Example58_ConfigureRequestSettings.cs | 2 +- .../KernelSemanticFunctionExtensions.cs | 55 ++++++++++--------- .../Functions.Semantic/SemanticFunction.cs | 15 +++-- .../TemplateEngine/SemanticFunctionConfig.cs | 32 ----------- .../OpenAI/OpenAICompletionTests.cs | 10 ++-- .../Sequential/SequentialPlanParserTests.cs | 3 +- 6 files changed, 44 insertions(+), 73 deletions(-) delete mode 100644 dotnet/src/Functions/Functions.Semantic/TemplateEngine/SemanticFunctionConfig.cs diff --git a/dotnet/samples/KernelSyntaxExamples/Example58_ConfigureRequestSettings.cs b/dotnet/samples/KernelSyntaxExamples/Example58_ConfigureRequestSettings.cs index 3090b6f922a9..5616c33fa83b 100644 --- a/dotnet/samples/KernelSyntaxExamples/Example58_ConfigureRequestSettings.cs +++ b/dotnet/samples/KernelSyntaxExamples/Example58_ConfigureRequestSettings.cs @@ -68,7 +68,7 @@ public static async Task RunAsync() } }"; var templateConfig = JsonSerializer.Deserialize(configPayload); - var func = kernel.CreateSemanticFunction(prompt, config: templateConfig!, "HelloAI"); + var func = kernel.CreateSemanticFunction(prompt, templateConfig!, "HelloAI"); result = await kernel.RunAsync(func); Console.WriteLine(result.GetValue()); diff --git a/dotnet/src/Functions/Functions.Semantic/Extensions/KernelSemanticFunctionExtensions.cs b/dotnet/src/Functions/Functions.Semantic/Extensions/KernelSemanticFunctionExtensions.cs index 51207b908b88..47fd2c4a53db 100644 --- a/dotnet/src/Functions/Functions.Semantic/Extensions/KernelSemanticFunctionExtensions.cs +++ b/dotnet/src/Functions/Functions.Semantic/Extensions/KernelSemanticFunctionExtensions.cs @@ -28,14 +28,16 @@ public static class KernelSemanticFunctionExtensions /// /// Semantic Kernel instance /// Name of the semantic function. The name can contain only alphanumeric chars + underscore. - /// Function configuration, e.g. I/O params, AI settings, localization details, etc. + /// Prompt template configuration. + /// Prompt template. /// A C# function wrapping AI logic, usually defined with natural language public static ISKFunction RegisterSemanticFunction( this IKernel kernel, string functionName, - SemanticFunctionConfig functionConfig) + PromptTemplateConfig promptTemplateConfig, + IPromptTemplate promptTemplate) { - return kernel.RegisterSemanticFunction(FunctionCollection.GlobalFunctionsPluginName, functionName, functionConfig); + return kernel.RegisterSemanticFunction(FunctionCollection.GlobalFunctionsPluginName, functionName, promptTemplateConfig, promptTemplate); } /// @@ -44,18 +46,20 @@ public static ISKFunction RegisterSemanticFunction( /// Semantic Kernel instance /// Name of the plugin containing the function. The name can contain only alphanumeric chars + underscore. /// Name of the semantic function. The name can contain only alphanumeric chars + underscore. - /// Function configuration, e.g. I/O params, AI settings, localization details, etc. + /// Prompt template configuration. + /// Prompt template. /// A C# function wrapping AI logic, usually defined with natural language public static ISKFunction RegisterSemanticFunction( this IKernel kernel, string pluginName, string functionName, - SemanticFunctionConfig functionConfig) + PromptTemplateConfig promptTemplateConfig, + IPromptTemplate promptTemplate) { // Future-proofing the name not to contain special chars Verify.ValidFunctionName(functionName); - ISKFunction function = kernel.CreateSemanticFunction(pluginName, functionName, functionConfig); + ISKFunction function = kernel.CreateSemanticFunction(pluginName, functionName, promptTemplateConfig, promptTemplate); return kernel.RegisterCustomFunction(function); } @@ -81,19 +85,19 @@ public static ISKFunction CreateSemanticFunction( { functionName ??= RandomFunctionName(); - var config = new PromptTemplateConfig + var promptTemplateConfig = new PromptTemplateConfig { Description = description ?? "Generic function, unknown purpose", }; if (requestSettings is not null) { - config.ModelSettings.Add(requestSettings); + promptTemplateConfig.ModelSettings.Add(requestSettings); } return kernel.CreateSemanticFunction( promptTemplate: promptTemplate, - config: config, + promptTemplateConfig: promptTemplateConfig, functionName: functionName, pluginName: pluginName); } @@ -103,7 +107,7 @@ public static ISKFunction CreateSemanticFunction( /// /// Semantic Kernel instance /// Plain language definition of the semantic function, using SK template language - /// Optional function settings + /// Prompt template configuration. /// A name for the given function. The name can be referenced in templates and used by the pipeline planner. /// An optional plugin name, e.g. to namespace functions with the same name. When empty, /// the function is added to the global namespace, overwriting functions with the same name @@ -111,7 +115,7 @@ public static ISKFunction CreateSemanticFunction( public static ISKFunction CreateSemanticFunction( this IKernel kernel, string promptTemplate, - PromptTemplateConfig config, + PromptTemplateConfig promptTemplateConfig, string? functionName = null, string? pluginName = null) { @@ -119,22 +123,19 @@ public static ISKFunction CreateSemanticFunction( Verify.ValidFunctionName(functionName); if (!string.IsNullOrEmpty(pluginName)) { Verify.ValidPluginName(pluginName); } - var template = new PromptTemplate(promptTemplate, config, kernel.PromptTemplateEngine); - - // Prepare lambda wrapping AI logic - var functionConfig = new SemanticFunctionConfig(config, template); + var template = new PromptTemplate(promptTemplate, promptTemplateConfig, kernel.PromptTemplateEngine); // TODO: manage overwrites, potentially error out return string.IsNullOrEmpty(pluginName) - ? kernel.RegisterSemanticFunction(functionName, functionConfig) - : kernel.RegisterSemanticFunction(pluginName!, functionName, functionConfig); + ? kernel.RegisterSemanticFunction(functionName, promptTemplateConfig, template) + : kernel.RegisterSemanticFunction(pluginName!, functionName, promptTemplateConfig, template); } /// /// Invoke a semantic function using the provided prompt template. /// /// Semantic Kernel instance - /// Plain language definition of the semantic function, using SK template language + /// Plain language definition of the semantic function, using SK template language /// A name for the given function. The name can be referenced in templates and used by the pipeline planner. /// Optional plugin name, for namespacing and avoid collisions /// Optional description, useful for the planner @@ -142,14 +143,14 @@ public static ISKFunction CreateSemanticFunction( /// Kernel execution result public static Task InvokeSemanticFunctionAsync( this IKernel kernel, - string promptTemplate, + string template, string? functionName = null, string? pluginName = null, string? description = null, AIRequestSettings? requestSettings = null) { var skFunction = kernel.CreateSemanticFunction( - promptTemplate, + template, functionName, pluginName, description, @@ -256,14 +257,12 @@ public static IDictionary ImportSemanticFunctionsFromDirect // Load prompt template var template = new PromptTemplate(File.ReadAllText(promptPath), config, kernel.PromptTemplateEngine); - var functionConfig = new SemanticFunctionConfig(config, template); - if (logger.IsEnabled(LogLevel.Trace)) { logger.LogTrace("Registering function {0}.{1} loaded from {2}", pluginDirectoryName, functionName, dir); } - functions[functionName] = kernel.RegisterSemanticFunction(pluginDirectoryName, functionName, functionConfig); + functions[functionName] = kernel.RegisterSemanticFunction(pluginDirectoryName, functionName, config, template); } } @@ -276,12 +275,14 @@ private static ISKFunction CreateSemanticFunction( this IKernel kernel, string pluginName, string functionName, - SemanticFunctionConfig functionConfig) + PromptTemplateConfig promptTemplateConfig, + IPromptTemplate promptTemplate) { ISKFunction func = SemanticFunction.FromSemanticConfig( pluginName, functionName, - functionConfig, + promptTemplateConfig, + promptTemplate, kernel.LoggerFactory ); @@ -289,10 +290,10 @@ private static ISKFunction CreateSemanticFunction( // is invoked manually without a context and without a way to find other functions. func.SetDefaultFunctionCollection(kernel.Functions); - func.SetAIConfiguration(functionConfig.PromptTemplateConfig.GetDefaultRequestSettings()); + func.SetAIConfiguration(promptTemplateConfig.GetDefaultRequestSettings()); // Note: the service is instantiated using the kernel configuration state when the function is invoked - func.SetAIService(() => kernel.GetService(functionConfig.PromptTemplateConfig.GetDefaultRequestSettings()?.ServiceId ?? null)); + func.SetAIService(() => kernel.GetService(promptTemplateConfig.GetDefaultRequestSettings()?.ServiceId ?? null)); return func; } diff --git a/dotnet/src/Functions/Functions.Semantic/SemanticFunction.cs b/dotnet/src/Functions/Functions.Semantic/SemanticFunction.cs index 38cf780a5c63..cf50d06de589 100644 --- a/dotnet/src/Functions/Functions.Semantic/SemanticFunction.cs +++ b/dotnet/src/Functions/Functions.Semantic/SemanticFunction.cs @@ -51,27 +51,30 @@ internal sealed class SemanticFunction : ISKFunction, IDisposable /// /// Name of the plugin to which the function being created belongs. /// Name of the function to create. - /// Semantic function configuration. + /// Prompt template configuration. + /// Prompt template. /// The to use for logging. If null, no logging will be performed. /// The to monitor for cancellation requests. The default is . /// SK function instance. public static ISKFunction FromSemanticConfig( string pluginName, string functionName, - SemanticFunctionConfig functionConfig, + PromptTemplateConfig promptTemplateConfig, + IPromptTemplate promptTemplate, ILoggerFactory? loggerFactory = null, CancellationToken cancellationToken = default) { - Verify.NotNull(functionConfig); + Verify.NotNull(promptTemplateConfig); + Verify.NotNull(promptTemplate); var func = new SemanticFunction( - template: functionConfig.PromptTemplate, - description: functionConfig.PromptTemplateConfig.Description, + template: promptTemplate, + description: promptTemplateConfig.Description, pluginName: pluginName, functionName: functionName, loggerFactory: loggerFactory ); - func.SetAIConfiguration(functionConfig.PromptTemplateConfig.GetDefaultRequestSettings()); + func.SetAIConfiguration(promptTemplateConfig.GetDefaultRequestSettings()); return func; } diff --git a/dotnet/src/Functions/Functions.Semantic/TemplateEngine/SemanticFunctionConfig.cs b/dotnet/src/Functions/Functions.Semantic/TemplateEngine/SemanticFunctionConfig.cs deleted file mode 100644 index f5593ea10b1e..000000000000 --- a/dotnet/src/Functions/Functions.Semantic/TemplateEngine/SemanticFunctionConfig.cs +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -namespace Microsoft.SemanticKernel.TemplateEngine; - -/// -/// Semantic function configuration. -/// -public sealed class SemanticFunctionConfig -{ - /// - /// Prompt template configuration. - /// - public PromptTemplateConfig PromptTemplateConfig { get; } - - /// - /// Prompt template. - /// - public IPromptTemplate PromptTemplate { get; } - - /// - /// Constructor for SemanticFunctionConfig. - /// - /// Prompt template configuration. - /// Prompt template. - public SemanticFunctionConfig( - PromptTemplateConfig config, - IPromptTemplate template) - { - this.PromptTemplateConfig = config; - this.PromptTemplate = template; - } -} diff --git a/dotnet/src/IntegrationTests/Connectors/OpenAI/OpenAICompletionTests.cs b/dotnet/src/IntegrationTests/Connectors/OpenAI/OpenAICompletionTests.cs index 8e5a5f17f876..e2649308d579 100644 --- a/dotnet/src/IntegrationTests/Connectors/OpenAI/OpenAICompletionTests.cs +++ b/dotnet/src/IntegrationTests/Connectors/OpenAI/OpenAICompletionTests.cs @@ -356,14 +356,12 @@ public async Task MultipleServiceLoadPromptConfigTestAsync() var defaultFunc = target.RegisterSemanticFunction( "WherePlugin", "FishMarket1", - new SemanticFunctionConfig( - defaultConfig, - new PromptTemplate(prompt, defaultConfig, target.PromptTemplateEngine))); + defaultConfig, + new PromptTemplate(prompt, defaultConfig, target.PromptTemplateEngine)); var azureFunc = target.RegisterSemanticFunction( "WherePlugin", "FishMarket2", - new SemanticFunctionConfig( - azureConfig, - new PromptTemplate(prompt, azureConfig, target.PromptTemplateEngine))); + azureConfig, + new PromptTemplate(prompt, azureConfig, target.PromptTemplateEngine)); // Act await Assert.ThrowsAsync(() => target.RunAsync(defaultFunc)); diff --git a/dotnet/src/Planners/Planners.Core.UnitTests/Sequential/SequentialPlanParserTests.cs b/dotnet/src/Planners/Planners.Core.UnitTests/Sequential/SequentialPlanParserTests.cs index f93adc889c10..141ac5f572ff 100644 --- a/dotnet/src/Planners/Planners.Core.UnitTests/Sequential/SequentialPlanParserTests.cs +++ b/dotnet/src/Planners/Planners.Core.UnitTests/Sequential/SequentialPlanParserTests.cs @@ -87,7 +87,8 @@ private void CreateKernelAndFunctionCreateMocks(List<(string name, string plugin kernelMock.Setup(x => x.RegisterSemanticFunction( It.IsAny(), It.IsAny(), - It.IsAny() + It.IsAny(), + It.IsAny() )).Returns(mockFunction.Object); } else