diff --git a/docs/decisions/0006-prompt-extract-template-engine.md b/docs/decisions/0006-prompt-extract-template-engine.md new file mode 100644 index 0000000000..a72f5adc14 --- /dev/null +++ b/docs/decisions/0006-prompt-extract-template-engine.md @@ -0,0 +1,32 @@ +--- +# These are optional elements. Feel free to remove any of them. +status: accepted +date: 2023-08-25 +deciders: shawncal +consulted: +informed: +--- +# Extract the Prompt Template Engine from Semantic Kernel core + +## Context and Problem Statement + +The Semantic Kernel includes a default prompt template engine which is used to render Semantic Kernel prompts i.e., `skprompt.txt` files. The prompt template is rendered before being send to the AI to allow the prompt to be generated dynamically e.g., include input parameters or the result of a native or semantic function execution. +To reduce the complexity and API surface of the Semantic Kernel the prompt template engine is going to be extracted and added to it's own package. + +The long term goal is to enable the following scenarios: + +1. Implement a custom template engine e.g., using Handlebars templates. This is supported now but we want to simplify the API to be implemented. +2. Support using zero or many template engines. + +## Decision Drivers + +* Reduce API surface and complexity of the Semantic Kernel core. +* Simplify the `IPromptTemplateEngine` interface to make it easier to implement a custom template engine. +* Make the change without breaking existing clients. + +## Decision Outcome + +* Create a new package called `Microsoft.SemanticKernel.TemplateEngine`. +* Maintain the existing namespace for all prompt template engine code. +* Simplify the `IPromptTemplateEngine` interface to just require implementation of `RenderAsync`. +* Dynamically load the existing `PromptTemplateEngine` if the `Microsoft.SemanticKernel.TemplateEngine` assembly is available. diff --git a/dotnet/SK-dotnet.sln b/dotnet/SK-dotnet.sln index d668e5b2d4..67a3ba7a12 100644 --- a/dotnet/SK-dotnet.sln +++ b/dotnet/SK-dotnet.sln @@ -152,6 +152,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApplicationInsightsExample" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Connectors.Memory.Kusto", "src\Connectors\Connectors.Memory.Kusto\Connectors.Memory.Kusto.csproj", "{E07608CC-D710-4655-BB9E-D22CF3CDD193}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TemplateEngine.PromptTemplateEngine", "src\Extensions\TemplateEngine.PromptTemplateEngine\TemplateEngine.PromptTemplateEngine.csproj", "{10E4B697-D4E8-468D-872D-49670FD150FB}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -369,6 +371,12 @@ Global {E07608CC-D710-4655-BB9E-D22CF3CDD193}.Publish|Any CPU.Build.0 = Debug|Any CPU {E07608CC-D710-4655-BB9E-D22CF3CDD193}.Release|Any CPU.ActiveCfg = Release|Any CPU {E07608CC-D710-4655-BB9E-D22CF3CDD193}.Release|Any CPU.Build.0 = Release|Any CPU + {10E4B697-D4E8-468D-872D-49670FD150FB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {10E4B697-D4E8-468D-872D-49670FD150FB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {10E4B697-D4E8-468D-872D-49670FD150FB}.Publish|Any CPU.ActiveCfg = Publish|Any CPU + {10E4B697-D4E8-468D-872D-49670FD150FB}.Publish|Any CPU.Build.0 = Publish|Any CPU + {10E4B697-D4E8-468D-872D-49670FD150FB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {10E4B697-D4E8-468D-872D-49670FD150FB}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -422,6 +430,7 @@ Global {4762BCAF-E1C5-4714-B88D-E50FA333C50E} = {078F96B4-09E1-4E0E-B214-F71A4F4BF633} {C754950A-E16C-4F96-9CC7-9328E361B5AF} = {FA3720F1-C99A-49B2-9577-A940257098BF} {E07608CC-D710-4655-BB9E-D22CF3CDD193} = {0247C2C9-86C3-45BA-8873-28B0948EDC0C} + {10E4B697-D4E8-468D-872D-49670FD150FB} = {078F96B4-09E1-4E0E-B214-F71A4F4BF633} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {FBDC56A3-86AD-4323-AA0F-201E59123B83} diff --git a/dotnet/samples/KernelSyntaxExamples/Example06_TemplateLanguage.cs b/dotnet/samples/KernelSyntaxExamples/Example06_TemplateLanguage.cs index 0cdb28645b..fa0c246f4b 100644 --- a/dotnet/samples/KernelSyntaxExamples/Example06_TemplateLanguage.cs +++ b/dotnet/samples/KernelSyntaxExamples/Example06_TemplateLanguage.cs @@ -4,7 +4,7 @@ using System; using System.Threading.Tasks; using Microsoft.SemanticKernel; using Microsoft.SemanticKernel.Skills.Core; -using Microsoft.SemanticKernel.TemplateEngine; +using Microsoft.SemanticKernel.TemplateEngine.Prompt; using RepoUtils; // ReSharper disable once InconsistentNaming diff --git a/dotnet/samples/KernelSyntaxExamples/Example07_BingAndGoogleSkills.cs b/dotnet/samples/KernelSyntaxExamples/Example07_BingAndGoogleSkills.cs index 745298d632..52ab28c2cd 100644 --- a/dotnet/samples/KernelSyntaxExamples/Example07_BingAndGoogleSkills.cs +++ b/dotnet/samples/KernelSyntaxExamples/Example07_BingAndGoogleSkills.cs @@ -6,7 +6,7 @@ using Microsoft.SemanticKernel; using Microsoft.SemanticKernel.Skills.Web; using Microsoft.SemanticKernel.Skills.Web.Bing; using Microsoft.SemanticKernel.Skills.Web.Google; -using Microsoft.SemanticKernel.TemplateEngine; +using Microsoft.SemanticKernel.TemplateEngine.Prompt; using RepoUtils; /// diff --git a/dotnet/samples/KernelSyntaxExamples/Example30_ChatWithPrompts.cs b/dotnet/samples/KernelSyntaxExamples/Example30_ChatWithPrompts.cs index f94e0bc491..2df80819f3 100644 --- a/dotnet/samples/KernelSyntaxExamples/Example30_ChatWithPrompts.cs +++ b/dotnet/samples/KernelSyntaxExamples/Example30_ChatWithPrompts.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; using Microsoft.SemanticKernel; using Microsoft.SemanticKernel.AI.ChatCompletion; using Microsoft.SemanticKernel.Skills.Core; -using Microsoft.SemanticKernel.TemplateEngine; +using Microsoft.SemanticKernel.TemplateEngine.Prompt; using RepoUtils; using Resources; diff --git a/dotnet/samples/KernelSyntaxExamples/Example40_DIContainer.cs b/dotnet/samples/KernelSyntaxExamples/Example40_DIContainer.cs index 7873b01ccc..858d921df5 100644 --- a/dotnet/samples/KernelSyntaxExamples/Example40_DIContainer.cs +++ b/dotnet/samples/KernelSyntaxExamples/Example40_DIContainer.cs @@ -10,6 +10,7 @@ using Microsoft.SemanticKernel.Memory; using Microsoft.SemanticKernel.Services; using Microsoft.SemanticKernel.SkillDefinition; using Microsoft.SemanticKernel.TemplateEngine; +using Microsoft.SemanticKernel.TemplateEngine.Prompt; using RepoUtils; /** diff --git a/dotnet/samples/KernelSyntaxExamples/Example42_KernelBuilder.cs b/dotnet/samples/KernelSyntaxExamples/Example42_KernelBuilder.cs index 2fd8578579..32f9e64012 100644 --- a/dotnet/samples/KernelSyntaxExamples/Example42_KernelBuilder.cs +++ b/dotnet/samples/KernelSyntaxExamples/Example42_KernelBuilder.cs @@ -21,7 +21,7 @@ using Microsoft.SemanticKernel.Memory; using Microsoft.SemanticKernel.Reliability; using Microsoft.SemanticKernel.Services; using Microsoft.SemanticKernel.SkillDefinition; -using Microsoft.SemanticKernel.TemplateEngine; +using Microsoft.SemanticKernel.TemplateEngine.Prompt; using Polly; using Polly.Retry; diff --git a/dotnet/samples/KernelSyntaxExamples/KernelSyntaxExamples.csproj b/dotnet/samples/KernelSyntaxExamples/KernelSyntaxExamples.csproj index b440c11e94..9dded4df04 100644 --- a/dotnet/samples/KernelSyntaxExamples/KernelSyntaxExamples.csproj +++ b/dotnet/samples/KernelSyntaxExamples/KernelSyntaxExamples.csproj @@ -41,6 +41,7 @@ + diff --git a/dotnet/src/Extensions/Extensions.UnitTests/Extensions.UnitTests.csproj b/dotnet/src/Extensions/Extensions.UnitTests/Extensions.UnitTests.csproj index 27580b44a7..174e37f623 100644 --- a/dotnet/src/Extensions/Extensions.UnitTests/Extensions.UnitTests.csproj +++ b/dotnet/src/Extensions/Extensions.UnitTests/Extensions.UnitTests.csproj @@ -31,6 +31,7 @@ + diff --git a/dotnet/src/SemanticKernel.UnitTests/TemplateEngine/Blocks/CodeBlockTests.cs b/dotnet/src/Extensions/Extensions.UnitTests/TemplateEngine/Prompt/Blocks/CodeBlockTests.cs similarity index 98% rename from dotnet/src/SemanticKernel.UnitTests/TemplateEngine/Blocks/CodeBlockTests.cs rename to dotnet/src/Extensions/Extensions.UnitTests/TemplateEngine/Prompt/Blocks/CodeBlockTests.cs index c03300c4f6..c15c0335ab 100644 --- a/dotnet/src/SemanticKernel.UnitTests/TemplateEngine/Blocks/CodeBlockTests.cs +++ b/dotnet/src/Extensions/Extensions.UnitTests/TemplateEngine/Prompt/Blocks/CodeBlockTests.cs @@ -10,11 +10,11 @@ using Microsoft.SemanticKernel.AI.TextCompletion; using Microsoft.SemanticKernel.Diagnostics; using Microsoft.SemanticKernel.Orchestration; using Microsoft.SemanticKernel.SkillDefinition; -using Microsoft.SemanticKernel.TemplateEngine.Blocks; +using Microsoft.SemanticKernel.TemplateEngine.Prompt.Blocks; using Moq; using Xunit; -namespace SemanticKernel.UnitTests.TemplateEngine.Blocks; +namespace SemanticKernel.Extensions.UnitTests.TemplateEngine.Prompt.Blocks; public class CodeBlockTests { diff --git a/dotnet/src/SemanticKernel.UnitTests/TemplateEngine/Blocks/FunctionIdBlockTests.cs b/dotnet/src/Extensions/Extensions.UnitTests/TemplateEngine/Prompt/Blocks/FunctionIdBlockTests.cs similarity index 95% rename from dotnet/src/SemanticKernel.UnitTests/TemplateEngine/Blocks/FunctionIdBlockTests.cs rename to dotnet/src/Extensions/Extensions.UnitTests/TemplateEngine/Prompt/Blocks/FunctionIdBlockTests.cs index e7e4db0e95..75bd2c58c6 100644 --- a/dotnet/src/SemanticKernel.UnitTests/TemplateEngine/Blocks/FunctionIdBlockTests.cs +++ b/dotnet/src/Extensions/Extensions.UnitTests/TemplateEngine/Prompt/Blocks/FunctionIdBlockTests.cs @@ -2,10 +2,10 @@ using Microsoft.Extensions.Logging.Abstractions; using Microsoft.SemanticKernel.Diagnostics; -using Microsoft.SemanticKernel.TemplateEngine.Blocks; +using Microsoft.SemanticKernel.TemplateEngine.Prompt.Blocks; using Xunit; -namespace SemanticKernel.UnitTests.TemplateEngine.Blocks; +namespace SemanticKernel.Extensions.UnitTests.TemplateEngine.Prompt.Blocks; public class FunctionIdBlockTests { diff --git a/dotnet/src/SemanticKernel.UnitTests/TemplateEngine/Blocks/TextBlockTests.cs b/dotnet/src/Extensions/Extensions.UnitTests/TemplateEngine/Prompt/Blocks/TextBlockTests.cs similarity index 91% rename from dotnet/src/SemanticKernel.UnitTests/TemplateEngine/Blocks/TextBlockTests.cs rename to dotnet/src/Extensions/Extensions.UnitTests/TemplateEngine/Prompt/Blocks/TextBlockTests.cs index 2660eac50b..d0be92529a 100644 --- a/dotnet/src/SemanticKernel.UnitTests/TemplateEngine/Blocks/TextBlockTests.cs +++ b/dotnet/src/Extensions/Extensions.UnitTests/TemplateEngine/Prompt/Blocks/TextBlockTests.cs @@ -1,9 +1,9 @@ // Copyright (c) Microsoft. All rights reserved. -using Microsoft.SemanticKernel.TemplateEngine.Blocks; +using Microsoft.SemanticKernel.TemplateEngine.Prompt.Blocks; using Xunit; -namespace SemanticKernel.UnitTests.TemplateEngine.Blocks; +namespace SemanticKernel.Extensions.UnitTests.TemplateEngine.Prompt.Blocks; public class TextBlockTests { diff --git a/dotnet/src/SemanticKernel.UnitTests/TemplateEngine/Blocks/ValBlockTests.cs b/dotnet/src/Extensions/Extensions.UnitTests/TemplateEngine/Prompt/Blocks/ValBlockTests.cs similarity index 92% rename from dotnet/src/SemanticKernel.UnitTests/TemplateEngine/Blocks/ValBlockTests.cs rename to dotnet/src/Extensions/Extensions.UnitTests/TemplateEngine/Prompt/Blocks/ValBlockTests.cs index 1add88f952..23a365cbea 100644 --- a/dotnet/src/SemanticKernel.UnitTests/TemplateEngine/Blocks/ValBlockTests.cs +++ b/dotnet/src/Extensions/Extensions.UnitTests/TemplateEngine/Prompt/Blocks/ValBlockTests.cs @@ -1,9 +1,9 @@ // Copyright (c) Microsoft. All rights reserved. -using Microsoft.SemanticKernel.TemplateEngine.Blocks; +using Microsoft.SemanticKernel.TemplateEngine.Prompt.Blocks; using Xunit; -namespace SemanticKernel.UnitTests.TemplateEngine.Blocks; +namespace SemanticKernel.Extensions.UnitTests.TemplateEngine.Prompt.Blocks; public class ValBlockTests { diff --git a/dotnet/src/SemanticKernel.UnitTests/TemplateEngine/Blocks/VarBlockTests.cs b/dotnet/src/Extensions/Extensions.UnitTests/TemplateEngine/Prompt/Blocks/VarBlockTests.cs similarity index 96% rename from dotnet/src/SemanticKernel.UnitTests/TemplateEngine/Blocks/VarBlockTests.cs rename to dotnet/src/Extensions/Extensions.UnitTests/TemplateEngine/Prompt/Blocks/VarBlockTests.cs index a3dc5cc9fa..327c696fc0 100644 --- a/dotnet/src/SemanticKernel.UnitTests/TemplateEngine/Blocks/VarBlockTests.cs +++ b/dotnet/src/Extensions/Extensions.UnitTests/TemplateEngine/Prompt/Blocks/VarBlockTests.cs @@ -2,10 +2,10 @@ using Microsoft.SemanticKernel.Diagnostics; using Microsoft.SemanticKernel.Orchestration; -using Microsoft.SemanticKernel.TemplateEngine.Blocks; +using Microsoft.SemanticKernel.TemplateEngine.Prompt.Blocks; using Xunit; -namespace SemanticKernel.UnitTests.TemplateEngine.Blocks; +namespace SemanticKernel.Extensions.UnitTests.TemplateEngine.Prompt.Blocks; public class VarBlockTests { diff --git a/dotnet/src/SemanticKernel.UnitTests/TemplateEngine/CodeTokenizerTests.cs b/dotnet/src/Extensions/Extensions.UnitTests/TemplateEngine/Prompt/CodeTokenizerTests.cs similarity index 95% rename from dotnet/src/SemanticKernel.UnitTests/TemplateEngine/CodeTokenizerTests.cs rename to dotnet/src/Extensions/Extensions.UnitTests/TemplateEngine/Prompt/CodeTokenizerTests.cs index 6485a2fa01..0d9bae3edc 100644 --- a/dotnet/src/SemanticKernel.UnitTests/TemplateEngine/CodeTokenizerTests.cs +++ b/dotnet/src/Extensions/Extensions.UnitTests/TemplateEngine/Prompt/CodeTokenizerTests.cs @@ -1,11 +1,11 @@ // Copyright (c) Microsoft. All rights reserved. using Microsoft.SemanticKernel.Diagnostics; -using Microsoft.SemanticKernel.TemplateEngine; -using Microsoft.SemanticKernel.TemplateEngine.Blocks; +using Microsoft.SemanticKernel.TemplateEngine.Prompt; +using Microsoft.SemanticKernel.TemplateEngine.Prompt.Blocks; using Xunit; -namespace SemanticKernel.UnitTests.TemplateEngine; +namespace SemanticKernel.Extensions.UnitTests.TemplateEngine.Prompt; public class CodeTokenizerTests { diff --git a/dotnet/src/SemanticKernel.UnitTests/TemplateEngine/PromptTemplateEngineTests.cs b/dotnet/src/Extensions/Extensions.UnitTests/TemplateEngine/Prompt/PromptTemplateEngineTests.cs similarity index 97% rename from dotnet/src/SemanticKernel.UnitTests/TemplateEngine/PromptTemplateEngineTests.cs rename to dotnet/src/Extensions/Extensions.UnitTests/TemplateEngine/Prompt/PromptTemplateEngineTests.cs index c49defb8cc..251714b249 100644 --- a/dotnet/src/SemanticKernel.UnitTests/TemplateEngine/PromptTemplateEngineTests.cs +++ b/dotnet/src/Extensions/Extensions.UnitTests/TemplateEngine/Prompt/PromptTemplateEngineTests.cs @@ -6,14 +6,14 @@ using System.Reflection; using System.Threading.Tasks; using Microsoft.SemanticKernel.Orchestration; using Microsoft.SemanticKernel.SkillDefinition; -using Microsoft.SemanticKernel.TemplateEngine; -using Microsoft.SemanticKernel.TemplateEngine.Blocks; +using Microsoft.SemanticKernel.TemplateEngine.Prompt; +using Microsoft.SemanticKernel.TemplateEngine.Prompt.Blocks; using Moq; -using SemanticKernel.UnitTests.XunitHelpers; +using SemanticKernel.Extensions.UnitTests.XunitHelpers; using Xunit; using Xunit.Abstractions; -namespace SemanticKernel.UnitTests.TemplateEngine; +namespace SemanticKernel.Extensions.UnitTests.TemplateEngine.Prompt; public sealed class PromptTemplateEngineTests { diff --git a/dotnet/src/SemanticKernel.UnitTests/TemplateEngine/TemplateTokenizerTests.cs b/dotnet/src/Extensions/Extensions.UnitTests/TemplateEngine/Prompt/TemplateTokenizerTests.cs similarity index 97% rename from dotnet/src/SemanticKernel.UnitTests/TemplateEngine/TemplateTokenizerTests.cs rename to dotnet/src/Extensions/Extensions.UnitTests/TemplateEngine/Prompt/TemplateTokenizerTests.cs index 77fd89b0be..903a2fba23 100644 --- a/dotnet/src/SemanticKernel.UnitTests/TemplateEngine/TemplateTokenizerTests.cs +++ b/dotnet/src/Extensions/Extensions.UnitTests/TemplateEngine/Prompt/TemplateTokenizerTests.cs @@ -1,10 +1,10 @@ // Copyright (c) Microsoft. All rights reserved. -using Microsoft.SemanticKernel.TemplateEngine; -using Microsoft.SemanticKernel.TemplateEngine.Blocks; +using Microsoft.SemanticKernel.TemplateEngine.Prompt; +using Microsoft.SemanticKernel.TemplateEngine.Prompt.Blocks; using Xunit; -namespace SemanticKernel.UnitTests.TemplateEngine; +namespace SemanticKernel.Extensions.UnitTests.TemplateEngine.Prompt; public class TemplateTokenizerTests { diff --git a/dotnet/src/SemanticKernel.Abstractions/TemplateEngine/Blocks/Block.cs b/dotnet/src/Extensions/TemplateEngine.PromptTemplateEngine/Blocks/Block.cs similarity index 95% rename from dotnet/src/SemanticKernel.Abstractions/TemplateEngine/Blocks/Block.cs rename to dotnet/src/Extensions/TemplateEngine.PromptTemplateEngine/Blocks/Block.cs index 6a762a6949..2b288f3831 100644 --- a/dotnet/src/SemanticKernel.Abstractions/TemplateEngine/Blocks/Block.cs +++ b/dotnet/src/Extensions/TemplateEngine.PromptTemplateEngine/Blocks/Block.cs @@ -3,7 +3,7 @@ using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; -namespace Microsoft.SemanticKernel.TemplateEngine.Blocks; +namespace Microsoft.SemanticKernel.TemplateEngine.Prompt.Blocks; /// /// Base class for blocks parsed from a prompt template diff --git a/dotnet/src/SemanticKernel.Abstractions/TemplateEngine/Blocks/BlockTypes.cs b/dotnet/src/Extensions/TemplateEngine.PromptTemplateEngine/Blocks/BlockTypes.cs similarity index 73% rename from dotnet/src/SemanticKernel.Abstractions/TemplateEngine/Blocks/BlockTypes.cs rename to dotnet/src/Extensions/TemplateEngine.PromptTemplateEngine/Blocks/BlockTypes.cs index 9ede01cfd0..0036cafc0f 100644 --- a/dotnet/src/SemanticKernel.Abstractions/TemplateEngine/Blocks/BlockTypes.cs +++ b/dotnet/src/Extensions/TemplateEngine.PromptTemplateEngine/Blocks/BlockTypes.cs @@ -1,6 +1,6 @@ // Copyright (c) Microsoft. All rights reserved. -namespace Microsoft.SemanticKernel.TemplateEngine.Blocks; +namespace Microsoft.SemanticKernel.TemplateEngine.Prompt.Blocks; internal enum BlockTypes { diff --git a/dotnet/src/SemanticKernel/TemplateEngine/Blocks/CodeBlock.cs b/dotnet/src/Extensions/TemplateEngine.PromptTemplateEngine/Blocks/CodeBlock.cs similarity index 88% rename from dotnet/src/SemanticKernel/TemplateEngine/Blocks/CodeBlock.cs rename to dotnet/src/Extensions/TemplateEngine.PromptTemplateEngine/Blocks/CodeBlock.cs index a765f14792..6252bc352f 100644 --- a/dotnet/src/SemanticKernel/TemplateEngine/Blocks/CodeBlock.cs +++ b/dotnet/src/Extensions/TemplateEngine.PromptTemplateEngine/Blocks/CodeBlock.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; using System.Threading; using System.Threading.Tasks; using Microsoft.Extensions.Logging; @@ -10,9 +9,11 @@ using Microsoft.SemanticKernel.Diagnostics; using Microsoft.SemanticKernel.Orchestration; using Microsoft.SemanticKernel.SkillDefinition; -namespace Microsoft.SemanticKernel.TemplateEngine.Blocks; +namespace Microsoft.SemanticKernel.TemplateEngine.Prompt.Blocks; #pragma warning disable CA2254 // error strings are used also internally, not just for logging +#pragma warning disable CA1031 // IsCriticalException is an internal utility and should not be used by extensions + // ReSharper disable TemplateIsNotCompileTimeConstantProblem internal sealed class CodeBlock : Block, ICodeRendering { @@ -139,22 +140,24 @@ internal sealed class CodeBlock : Block, ICodeRendering contextClone.Variables.Update(input); } + Exception? localException = null; try { - contextClone = await function.InvokeAsync(contextClone).ConfigureAwait(false); + contextClone = await function!.InvokeAsync(contextClone).ConfigureAwait(false); } - catch (Exception ex) when (!ex.IsCriticalException()) + catch (Exception ex) { this.Logger.LogError(ex, "Something went wrong when invoking function with custom input: {0}.{1}. Error: {2}", - function.SkillName, function.Name, ex.Message); - contextClone.LastException = ex; + function!.SkillName, function.Name, ex.Message); + localException = ex; } - if (contextClone.ErrorOccurred) + if (contextClone.ErrorOccurred || localException is not null) { - var errorMsg = $"Function `{fBlock.Content}` execution failed. {contextClone.LastException?.GetType().FullName}: {contextClone.LastException?.Message}"; + var lastException = localException ?? contextClone.LastException; + var errorMsg = $"Function `{fBlock.Content}` execution failed. {lastException?.GetType().FullName}: {lastException?.Message}"; this.Logger.LogError(errorMsg); - throw new SKException(errorMsg, contextClone.LastException); + throw new SKException(errorMsg, lastException); } return contextClone.Result; @@ -163,7 +166,7 @@ internal sealed class CodeBlock : Block, ICodeRendering private bool GetFunctionFromSkillCollection( IReadOnlySkillCollection skills, FunctionIdBlock fBlock, - [NotNullWhen(true)] out ISKFunction? function) + out ISKFunction? function) { if (string.IsNullOrEmpty(fBlock.SkillName)) { diff --git a/dotnet/src/SemanticKernel/TemplateEngine/Blocks/FunctionIdBlock.cs b/dotnet/src/Extensions/TemplateEngine.PromptTemplateEngine/Blocks/FunctionIdBlock.cs similarity index 97% rename from dotnet/src/SemanticKernel/TemplateEngine/Blocks/FunctionIdBlock.cs rename to dotnet/src/Extensions/TemplateEngine.PromptTemplateEngine/Blocks/FunctionIdBlock.cs index 23b96e3365..04751aa42e 100644 --- a/dotnet/src/SemanticKernel/TemplateEngine/Blocks/FunctionIdBlock.cs +++ b/dotnet/src/Extensions/TemplateEngine.PromptTemplateEngine/Blocks/FunctionIdBlock.cs @@ -6,7 +6,7 @@ using Microsoft.Extensions.Logging; using Microsoft.SemanticKernel.Diagnostics; using Microsoft.SemanticKernel.Orchestration; -namespace Microsoft.SemanticKernel.TemplateEngine.Blocks; +namespace Microsoft.SemanticKernel.TemplateEngine.Prompt.Blocks; internal sealed class FunctionIdBlock : Block, ITextRendering { diff --git a/dotnet/src/SemanticKernel/TemplateEngine/Blocks/ICodeRendering.cs b/dotnet/src/Extensions/TemplateEngine.PromptTemplateEngine/Blocks/ICodeRendering.cs similarity index 92% rename from dotnet/src/SemanticKernel/TemplateEngine/Blocks/ICodeRendering.cs rename to dotnet/src/Extensions/TemplateEngine.PromptTemplateEngine/Blocks/ICodeRendering.cs index 93ec182b80..9f79122bba 100644 --- a/dotnet/src/SemanticKernel/TemplateEngine/Blocks/ICodeRendering.cs +++ b/dotnet/src/Extensions/TemplateEngine.PromptTemplateEngine/Blocks/ICodeRendering.cs @@ -4,7 +4,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.SemanticKernel.Orchestration; -namespace Microsoft.SemanticKernel.TemplateEngine.Blocks; +namespace Microsoft.SemanticKernel.TemplateEngine.Prompt.Blocks; /// /// Interface of dynamic blocks that need async IO to be rendered. diff --git a/dotnet/src/SemanticKernel/TemplateEngine/Blocks/ITextRendering.cs b/dotnet/src/Extensions/TemplateEngine.PromptTemplateEngine/Blocks/ITextRendering.cs similarity index 88% rename from dotnet/src/SemanticKernel/TemplateEngine/Blocks/ITextRendering.cs rename to dotnet/src/Extensions/TemplateEngine.PromptTemplateEngine/Blocks/ITextRendering.cs index 8f67259caa..a19a7242f2 100644 --- a/dotnet/src/SemanticKernel/TemplateEngine/Blocks/ITextRendering.cs +++ b/dotnet/src/Extensions/TemplateEngine.PromptTemplateEngine/Blocks/ITextRendering.cs @@ -2,7 +2,7 @@ using Microsoft.SemanticKernel.Orchestration; -namespace Microsoft.SemanticKernel.TemplateEngine.Blocks; +namespace Microsoft.SemanticKernel.TemplateEngine.Prompt.Blocks; /// /// Interface of static blocks that don't need async IO to be rendered. diff --git a/dotnet/src/SemanticKernel/TemplateEngine/Blocks/Symbols.cs b/dotnet/src/Extensions/TemplateEngine.PromptTemplateEngine/Blocks/Symbols.cs similarity index 88% rename from dotnet/src/SemanticKernel/TemplateEngine/Blocks/Symbols.cs rename to dotnet/src/Extensions/TemplateEngine.PromptTemplateEngine/Blocks/Symbols.cs index 7fafa50230..1a89bbb93e 100644 --- a/dotnet/src/SemanticKernel/TemplateEngine/Blocks/Symbols.cs +++ b/dotnet/src/Extensions/TemplateEngine.PromptTemplateEngine/Blocks/Symbols.cs @@ -1,6 +1,6 @@ // Copyright (c) Microsoft. All rights reserved. -namespace Microsoft.SemanticKernel.TemplateEngine.Blocks; +namespace Microsoft.SemanticKernel.TemplateEngine.Prompt.Blocks; internal static class Symbols { diff --git a/dotnet/src/SemanticKernel/TemplateEngine/Blocks/TextBlock.cs b/dotnet/src/Extensions/TemplateEngine.PromptTemplateEngine/Blocks/TextBlock.cs similarity index 92% rename from dotnet/src/SemanticKernel/TemplateEngine/Blocks/TextBlock.cs rename to dotnet/src/Extensions/TemplateEngine.PromptTemplateEngine/Blocks/TextBlock.cs index 478bcba795..131da252b2 100644 --- a/dotnet/src/SemanticKernel/TemplateEngine/Blocks/TextBlock.cs +++ b/dotnet/src/Extensions/TemplateEngine.PromptTemplateEngine/Blocks/TextBlock.cs @@ -3,7 +3,7 @@ using Microsoft.Extensions.Logging; using Microsoft.SemanticKernel.Orchestration; -namespace Microsoft.SemanticKernel.TemplateEngine.Blocks; +namespace Microsoft.SemanticKernel.TemplateEngine.Prompt.Blocks; internal sealed class TextBlock : Block, ITextRendering { diff --git a/dotnet/src/SemanticKernel/TemplateEngine/Blocks/ValBlock.cs b/dotnet/src/Extensions/TemplateEngine.PromptTemplateEngine/Blocks/ValBlock.cs similarity index 93% rename from dotnet/src/SemanticKernel/TemplateEngine/Blocks/ValBlock.cs rename to dotnet/src/Extensions/TemplateEngine.PromptTemplateEngine/Blocks/ValBlock.cs index 8f4572f2c4..3d1f363a15 100644 --- a/dotnet/src/SemanticKernel/TemplateEngine/Blocks/ValBlock.cs +++ b/dotnet/src/Extensions/TemplateEngine.PromptTemplateEngine/Blocks/ValBlock.cs @@ -2,9 +2,8 @@ using Microsoft.Extensions.Logging; using Microsoft.SemanticKernel.Orchestration; -using Microsoft.SemanticKernel.Text; -namespace Microsoft.SemanticKernel.TemplateEngine.Blocks; +namespace Microsoft.SemanticKernel.TemplateEngine.Prompt.Blocks; internal sealed class ValBlock : Block, ITextRendering { @@ -69,8 +68,8 @@ internal sealed class ValBlock : Block, ITextRendering public static bool HasValPrefix(string? text) { - return !text.IsNullOrEmpty() - && text.Length > 0 + return !string.IsNullOrEmpty(text) + && text!.Length > 0 && (text[0] is Symbols.DblQuote or Symbols.SglQuote); } } diff --git a/dotnet/src/SemanticKernel/TemplateEngine/Blocks/VarBlock.cs b/dotnet/src/Extensions/TemplateEngine.PromptTemplateEngine/Blocks/VarBlock.cs similarity index 97% rename from dotnet/src/SemanticKernel/TemplateEngine/Blocks/VarBlock.cs rename to dotnet/src/Extensions/TemplateEngine.PromptTemplateEngine/Blocks/VarBlock.cs index 95b39bf80b..a6371c5d45 100644 --- a/dotnet/src/SemanticKernel/TemplateEngine/Blocks/VarBlock.cs +++ b/dotnet/src/Extensions/TemplateEngine.PromptTemplateEngine/Blocks/VarBlock.cs @@ -5,7 +5,7 @@ using Microsoft.Extensions.Logging; using Microsoft.SemanticKernel.Diagnostics; using Microsoft.SemanticKernel.Orchestration; -namespace Microsoft.SemanticKernel.TemplateEngine.Blocks; +namespace Microsoft.SemanticKernel.TemplateEngine.Prompt.Blocks; internal sealed class VarBlock : Block, ITextRendering { diff --git a/dotnet/src/SemanticKernel/TemplateEngine/CodeTokenizer.cs b/dotnet/src/Extensions/TemplateEngine.PromptTemplateEngine/CodeTokenizer.cs similarity index 97% rename from dotnet/src/SemanticKernel/TemplateEngine/CodeTokenizer.cs rename to dotnet/src/Extensions/TemplateEngine.PromptTemplateEngine/CodeTokenizer.cs index bf95a3025f..e58a831aa2 100644 --- a/dotnet/src/SemanticKernel/TemplateEngine/CodeTokenizer.cs +++ b/dotnet/src/Extensions/TemplateEngine.PromptTemplateEngine/CodeTokenizer.cs @@ -5,10 +5,9 @@ using System.Text; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Microsoft.SemanticKernel.Diagnostics; -using Microsoft.SemanticKernel.TemplateEngine.Blocks; -using Microsoft.SemanticKernel.Text; +using Microsoft.SemanticKernel.TemplateEngine.Prompt.Blocks; -namespace Microsoft.SemanticKernel.TemplateEngine; +namespace Microsoft.SemanticKernel.TemplateEngine.Prompt; /// /// Simple tokenizer used for default SK template code language. @@ -62,7 +61,7 @@ internal sealed class CodeTokenizer text = text?.Trim(); // Render NULL to "" - if (text.IsNullOrEmpty()) { return new List(); } + if (string.IsNullOrEmpty(text)) { return new List(); } // Track what type of token we're reading TokenTypes currentTokenType = TokenTypes.None; @@ -73,7 +72,7 @@ internal sealed class CodeTokenizer char textValueDelimiter = '\0'; var blocks = new List(); - char nextChar = text[0]; + char nextChar = text![0]; // Tokens must be separated by spaces, track their presence bool spaceSeparatorFound = false; diff --git a/dotnet/src/SemanticKernel/TemplateEngine/PromptTemplateEngine.cs b/dotnet/src/Extensions/TemplateEngine.PromptTemplateEngine/PromptTemplateEngine.cs similarity index 87% rename from dotnet/src/SemanticKernel/TemplateEngine/PromptTemplateEngine.cs rename to dotnet/src/Extensions/TemplateEngine.PromptTemplateEngine/PromptTemplateEngine.cs index d0770939d7..057a4fb1b9 100644 --- a/dotnet/src/SemanticKernel/TemplateEngine/PromptTemplateEngine.cs +++ b/dotnet/src/Extensions/TemplateEngine.PromptTemplateEngine/PromptTemplateEngine.cs @@ -9,9 +9,9 @@ using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Microsoft.SemanticKernel.Diagnostics; using Microsoft.SemanticKernel.Orchestration; -using Microsoft.SemanticKernel.TemplateEngine.Blocks; +using Microsoft.SemanticKernel.TemplateEngine.Prompt.Blocks; -namespace Microsoft.SemanticKernel.TemplateEngine; +namespace Microsoft.SemanticKernel.TemplateEngine.Prompt; /// /// Given a prompt, that might contain references to variables and functions: @@ -37,7 +37,20 @@ public class PromptTemplateEngine : IPromptTemplateEngine } /// - public IList ExtractBlocks(string? templateText, bool validate = true) + public async Task RenderAsync(string templateText, SKContext context, CancellationToken cancellationToken = default) + { + this._logger.LogTrace("Rendering string template: {0}", templateText); + var blocks = this.ExtractBlocks(templateText); + return await this.RenderAsync(blocks, context, cancellationToken).ConfigureAwait(false); + } + + /// + /// Given a prompt template string, extract all the blocks (text, variables, function calls) + /// + /// Prompt template (see skprompt.txt files) + /// Whether to validate the blocks syntax, or just return the blocks found, which could contain invalid code + /// A list of all the blocks, ie the template tokenized in text, variables and function calls + internal IList ExtractBlocks(string? templateText, bool validate = true) { this._logger.LogTrace("Extracting blocks from template: {0}", templateText); var blocks = this._tokenizer.Tokenize(templateText); @@ -56,14 +69,6 @@ public class PromptTemplateEngine : IPromptTemplateEngine return blocks; } - /// - public async Task RenderAsync(string templateText, SKContext context, CancellationToken cancellationToken = default) - { - this._logger.LogTrace("Rendering string template: {0}", templateText); - var blocks = this.ExtractBlocks(templateText); - return await this.RenderAsync(blocks, context, cancellationToken).ConfigureAwait(false); - } - /// /// Given a list of blocks render each block and compose the final result /// diff --git a/dotnet/src/Extensions/TemplateEngine.PromptTemplateEngine/TemplateEngine.PromptTemplateEngine.csproj b/dotnet/src/Extensions/TemplateEngine.PromptTemplateEngine/TemplateEngine.PromptTemplateEngine.csproj new file mode 100644 index 0000000000..6215627363 --- /dev/null +++ b/dotnet/src/Extensions/TemplateEngine.PromptTemplateEngine/TemplateEngine.PromptTemplateEngine.csproj @@ -0,0 +1,25 @@ + + + + + Microsoft.SemanticKernel.TemplateEngine.PromptTemplateEngine + Microsoft.SemanticKernel.TemplateEngine.Prompt + netstandard2.0 + + + + + + + Semantic Kernel - Prompt Template Engine + Semantic Kernel Prompt Template Engine + + + + + + + + + + \ No newline at end of file diff --git a/dotnet/src/SemanticKernel/TemplateEngine/TemplateTokenizer.cs b/dotnet/src/Extensions/TemplateEngine.PromptTemplateEngine/TemplateTokenizer.cs similarity index 97% rename from dotnet/src/SemanticKernel/TemplateEngine/TemplateTokenizer.cs rename to dotnet/src/Extensions/TemplateEngine.PromptTemplateEngine/TemplateTokenizer.cs index 892f2a6834..8039081d19 100644 --- a/dotnet/src/SemanticKernel/TemplateEngine/TemplateTokenizer.cs +++ b/dotnet/src/Extensions/TemplateEngine.PromptTemplateEngine/TemplateTokenizer.cs @@ -4,10 +4,9 @@ using System.Collections.Generic; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Microsoft.SemanticKernel.Diagnostics; -using Microsoft.SemanticKernel.TemplateEngine.Blocks; -using Microsoft.SemanticKernel.Text; +using Microsoft.SemanticKernel.TemplateEngine.Prompt.Blocks; -namespace Microsoft.SemanticKernel.TemplateEngine; +namespace Microsoft.SemanticKernel.TemplateEngine.Prompt; /// /// Simple tokenizer used for default SK template language. @@ -58,13 +57,13 @@ internal sealed class TemplateTokenizer const int MinCodeBlockLength = EmptyCodeBlockLength + 1; // Render NULL to "" - if (text.IsNullOrEmpty()) + if (string.IsNullOrEmpty(text)) { return new List { new TextBlock(string.Empty, this._loggerFactory) }; } // If the template is "empty" return the content as a text block - if (text.Length < MinCodeBlockLength) + if (text!.Length < MinCodeBlockLength) { return new List { new TextBlock(text, this._loggerFactory) }; } diff --git a/dotnet/src/IntegrationTests/IntegrationTests.csproj b/dotnet/src/IntegrationTests/IntegrationTests.csproj index 916a506a2c..0a4fd525da 100644 --- a/dotnet/src/IntegrationTests/IntegrationTests.csproj +++ b/dotnet/src/IntegrationTests/IntegrationTests.csproj @@ -43,6 +43,7 @@ + diff --git a/dotnet/src/IntegrationTests/SkillDefinition/InlineFunctionsDefinitionExtensionsTests.cs b/dotnet/src/IntegrationTests/SkillDefinition/InlineFunctionsDefinitionExtensionsTests.cs index 56d223ad08..013dd4d337 100644 --- a/dotnet/src/IntegrationTests/SkillDefinition/InlineFunctionsDefinitionExtensionsTests.cs +++ b/dotnet/src/IntegrationTests/SkillDefinition/InlineFunctionsDefinitionExtensionsTests.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; using Microsoft.SemanticKernel; using Microsoft.SemanticKernel.AI.TextCompletion; using Microsoft.SemanticKernel.Orchestration; -using Microsoft.SemanticKernel.TemplateEngine; +using Microsoft.SemanticKernel.TemplateEngine.Prompt; using SemanticKernel.IntegrationTests.Fakes; using Xunit; using Xunit.Abstractions; diff --git a/dotnet/src/IntegrationTests/TemplateLanguage/PromptTemplateEngineTests.cs b/dotnet/src/IntegrationTests/TemplateLanguage/PromptTemplateEngineTests.cs index ef2ff5b2b0..ca59132f8f 100644 --- a/dotnet/src/IntegrationTests/TemplateLanguage/PromptTemplateEngineTests.cs +++ b/dotnet/src/IntegrationTests/TemplateLanguage/PromptTemplateEngineTests.cs @@ -8,7 +8,7 @@ using System.Threading.Tasks; using Microsoft.SemanticKernel; using Microsoft.SemanticKernel.Diagnostics; using Microsoft.SemanticKernel.SkillDefinition; -using Microsoft.SemanticKernel.TemplateEngine; +using Microsoft.SemanticKernel.TemplateEngine.Prompt; using Xunit; using Xunit.Abstractions; diff --git a/dotnet/src/SemanticKernel.Abstractions/TemplateEngine/IPromptTemplateEngine.cs b/dotnet/src/SemanticKernel.Abstractions/TemplateEngine/IPromptTemplateEngine.cs index 0774fdaadd..2ae1f7b2c5 100644 --- a/dotnet/src/SemanticKernel.Abstractions/TemplateEngine/IPromptTemplateEngine.cs +++ b/dotnet/src/SemanticKernel.Abstractions/TemplateEngine/IPromptTemplateEngine.cs @@ -1,10 +1,8 @@ // Copyright (c) Microsoft. All rights reserved. -using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using Microsoft.SemanticKernel.Orchestration; -using Microsoft.SemanticKernel.TemplateEngine.Blocks; namespace Microsoft.SemanticKernel.TemplateEngine; @@ -13,16 +11,6 @@ namespace Microsoft.SemanticKernel.TemplateEngine; /// public interface IPromptTemplateEngine { - /// - /// Given a prompt template string, extract all the blocks (text, variables, function calls) - /// - /// Prompt template (see skprompt.txt files) - /// Whether to validate the blocks syntax, or just return the blocks found, which could contain invalid code - /// A list of all the blocks, ie the template tokenized in text, variables and function calls - IList ExtractBlocks( - string? templateText, - bool validate = true); - /// /// Given a prompt template, replace the variables with their values and execute the functions replacing their /// reference with the function result. diff --git a/dotnet/src/SemanticKernel.MetaPackage/SemanticKernel.MetaPackage.csproj b/dotnet/src/SemanticKernel.MetaPackage/SemanticKernel.MetaPackage.csproj index 73e4cb561a..9ee4e768c1 100644 --- a/dotnet/src/SemanticKernel.MetaPackage/SemanticKernel.MetaPackage.csproj +++ b/dotnet/src/SemanticKernel.MetaPackage/SemanticKernel.MetaPackage.csproj @@ -16,6 +16,7 @@ Empowers app owners to integrate cutting-edge LLM technology quickly and easily + diff --git a/dotnet/src/SemanticKernel/KernelBuilder.cs b/dotnet/src/SemanticKernel/KernelBuilder.cs index 3db8b7602a..b97e1565de 100644 --- a/dotnet/src/SemanticKernel/KernelBuilder.cs +++ b/dotnet/src/SemanticKernel/KernelBuilder.cs @@ -1,10 +1,15 @@ // Copyright (c) Microsoft. All rights reserved. using System; +using System.Linq; +using System.Reflection; +using System.Threading; +using System.Threading.Tasks; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Microsoft.SemanticKernel.Diagnostics; using Microsoft.SemanticKernel.Memory; +using Microsoft.SemanticKernel.Orchestration; using Microsoft.SemanticKernel.Reliability; using Microsoft.SemanticKernel.Services; using Microsoft.SemanticKernel.SkillDefinition; @@ -25,6 +30,9 @@ public sealed class KernelBuilder private IPromptTemplateEngine? _promptTemplateEngine; private readonly AIServiceCollection _aiServices = new(); + private static bool _promptTemplateEngineInitialized = false; + private static Type? _promptTemplateEngineType = null; + /// /// Create a new kernel instance /// @@ -49,7 +57,7 @@ public sealed class KernelBuilder var instance = new Kernel( new SkillCollection(this._loggerFactory), this._aiServices.Build(), - this._promptTemplateEngine ?? new PromptTemplateEngine(this._loggerFactory), + this._promptTemplateEngine ?? this.CreateDefaultPromptTemplateEngine(this._loggerFactory), this._memoryFactory.Invoke(), this._config, this._loggerFactory @@ -221,4 +229,68 @@ public sealed class KernelBuilder this._aiServices.SetService(serviceId, () => factory(this._loggerFactory, this._config), setAsDefault); return this; } + + /// + /// Create a default prompt template engine. + /// + /// This is a temporary solution to avoid breaking existing clients. + /// There will be a separate task to add support for registering instances of IPromptTemplateEngine and obsoleting the current approach. + /// + /// + /// Logger factory to be used by the template engine + /// Instance of . + private IPromptTemplateEngine CreateDefaultPromptTemplateEngine(ILoggerFactory? loggerFactory = null) + { + if (!_promptTemplateEngineInitialized) + { + _promptTemplateEngineType = this.GetPromptTemplateEngineType(); + _promptTemplateEngineInitialized = true; + } + + if (_promptTemplateEngineType is not null) + { + var constructor = _promptTemplateEngineType.GetConstructor(new Type[] { typeof(ILoggerFactory) }); + if (constructor is not null) + { +#pragma warning disable CS8601 // Null logger factory is OK + return (IPromptTemplateEngine)constructor.Invoke(new object[] { loggerFactory }); +#pragma warning restore CS8601 + } + } + + return new NullPromptTemplateEngine(); + } + + /// + /// Get the prompt template engine type if available + /// + /// The type for the prompt template engine if available + private Type? GetPromptTemplateEngineType() + { + try + { + var assembly = Assembly.Load("Microsoft.SemanticKernel.TemplateEngine.PromptTemplateEngine"); + + return assembly.ExportedTypes.Single(type => + type.Name.Equals("PromptTemplateEngine", StringComparison.Ordinal) && + type.GetInterface(nameof(IPromptTemplateEngine)) is not null); + } + catch (Exception ex) when (!ex.IsCriticalException()) + { + return null; + } + } +} + +/// +/// No-operation IPromptTemplateEngine which performs no rendering of the template. +/// +/// This is a temporary solution to avoid breaking existing clients. +/// +internal class NullPromptTemplateEngine : IPromptTemplateEngine +{ + public Task RenderAsync(string templateText, SKContext context, CancellationToken cancellationToken = default) + { + return Task.FromResult(templateText); + } } diff --git a/dotnet/src/SemanticKernel/SemanticFunctions/PromptTemplate.cs b/dotnet/src/SemanticKernel/SemanticFunctions/PromptTemplate.cs index 023b7a2f9b..e02179fe27 100644 --- a/dotnet/src/SemanticKernel/SemanticFunctions/PromptTemplate.cs +++ b/dotnet/src/SemanticKernel/SemanticFunctions/PromptTemplate.cs @@ -8,7 +8,6 @@ using System.Threading.Tasks; using Microsoft.SemanticKernel.Orchestration; using Microsoft.SemanticKernel.SkillDefinition; using Microsoft.SemanticKernel.TemplateEngine; -using Microsoft.SemanticKernel.TemplateEngine.Blocks; namespace Microsoft.SemanticKernel.SemanticFunctions; @@ -64,16 +63,6 @@ public sealed class PromptTemplate : IPromptTemplate result[p.Name] = new ParameterView(p.Name, p.Description, p.DefaultValue); } - // Parameters from the template - foreach (var block in this._templateEngine.ExtractBlocks(this._template)) - { - string? blockName = (block as VarBlock)?.Name; - if (!string.IsNullOrEmpty(blockName) && !result.ContainsKey(blockName!)) - { - result.Add(blockName!, new ParameterView(blockName!)); - } - } - return result.Values.ToList(); }