1010using Microsoft . SemanticKernel . AI . TextCompletion ;
1111using Microsoft . SemanticKernel . Diagnostics ;
1212using Microsoft . SemanticKernel . Orchestration ;
13- using Microsoft . SemanticKernel . SemanticFunctions ;
13+ using Microsoft . SemanticKernel . TemplateEngine ;
1414using Microsoft . SemanticKernel . Text ;
1515
1616#pragma warning disable IDE0130
@@ -28,14 +28,16 @@ public static class KernelSemanticFunctionExtensions
2828 /// </summary>
2929 /// <param name="kernel">Semantic Kernel instance</param>
3030 /// <param name="functionName">Name of the semantic function. The name can contain only alphanumeric chars + underscore.</param>
31- /// <param name="functionConfig">Function configuration, e.g. I/O params, AI settings, localization details, etc.</param>
31+ /// <param name="promptTemplateConfig">Prompt template configuration.</param>
32+ /// <param name="promptTemplate">Prompt template.</param>
3233 /// <returns>A C# function wrapping AI logic, usually defined with natural language</returns>
3334 public static ISKFunction RegisterSemanticFunction (
3435 this IKernel kernel ,
3536 string functionName ,
36- SemanticFunctionConfig functionConfig )
37+ PromptTemplateConfig promptTemplateConfig ,
38+ IPromptTemplate promptTemplate )
3739 {
38- return kernel . RegisterSemanticFunction ( FunctionCollection . GlobalFunctionsPluginName , functionName , functionConfig ) ;
40+ return kernel . RegisterSemanticFunction ( FunctionCollection . GlobalFunctionsPluginName , functionName , promptTemplateConfig , promptTemplate ) ;
3941 }
4042
4143 /// <summary>
@@ -44,18 +46,20 @@ public static ISKFunction RegisterSemanticFunction(
4446 /// <param name="kernel">Semantic Kernel instance</param>
4547 /// <param name="pluginName">Name of the plugin containing the function. The name can contain only alphanumeric chars + underscore.</param>
4648 /// <param name="functionName">Name of the semantic function. The name can contain only alphanumeric chars + underscore.</param>
47- /// <param name="functionConfig">Function configuration, e.g. I/O params, AI settings, localization details, etc.</param>
49+ /// <param name="promptTemplateConfig">Prompt template configuration.</param>
50+ /// <param name="promptTemplate">Prompt template.</param>
4851 /// <returns>A C# function wrapping AI logic, usually defined with natural language</returns>
4952 public static ISKFunction RegisterSemanticFunction (
5053 this IKernel kernel ,
5154 string pluginName ,
5255 string functionName ,
53- SemanticFunctionConfig functionConfig )
56+ PromptTemplateConfig promptTemplateConfig ,
57+ IPromptTemplate promptTemplate )
5458 {
5559 // Future-proofing the name not to contain special chars
5660 Verify . ValidFunctionName ( functionName ) ;
5761
58- ISKFunction function = kernel . CreateSemanticFunction ( pluginName , functionName , functionConfig ) ;
62+ ISKFunction function = kernel . CreateSemanticFunction ( pluginName , functionName , promptTemplateConfig , promptTemplate ) ;
5963 return kernel . RegisterCustomFunction ( function ) ;
6064 }
6165
@@ -81,19 +85,19 @@ public static ISKFunction CreateSemanticFunction(
8185 {
8286 functionName ??= RandomFunctionName ( ) ;
8387
84- var config = new PromptTemplateConfig
88+ var promptTemplateConfig = new PromptTemplateConfig
8589 {
8690 Description = description ?? "Generic function, unknown purpose" ,
8791 } ;
8892
8993 if ( requestSettings is not null )
9094 {
91- config . ModelSettings . Add ( requestSettings ) ;
95+ promptTemplateConfig . ModelSettings . Add ( requestSettings ) ;
9296 }
9397
9498 return kernel . CreateSemanticFunction (
9599 promptTemplate : promptTemplate ,
96- config : config ,
100+ promptTemplateConfig : promptTemplateConfig ,
97101 functionName : functionName ,
98102 pluginName : pluginName ) ;
99103 }
@@ -103,53 +107,50 @@ public static ISKFunction CreateSemanticFunction(
103107 /// </summary>
104108 /// <param name="kernel">Semantic Kernel instance</param>
105109 /// <param name="promptTemplate">Plain language definition of the semantic function, using SK template language</param>
106- /// <param name="config">Optional function settings </param>
110+ /// <param name="promptTemplateConfig">Prompt template configuration. </param>
107111 /// <param name="functionName">A name for the given function. The name can be referenced in templates and used by the pipeline planner.</param>
108112 /// <param name="pluginName">An optional plugin name, e.g. to namespace functions with the same name. When empty,
109113 /// the function is added to the global namespace, overwriting functions with the same name</param>
110114 /// <returns>A function ready to use</returns>
111115 public static ISKFunction CreateSemanticFunction (
112116 this IKernel kernel ,
113117 string promptTemplate ,
114- PromptTemplateConfig config ,
118+ PromptTemplateConfig promptTemplateConfig ,
115119 string ? functionName = null ,
116120 string ? pluginName = null )
117121 {
118122 functionName ??= RandomFunctionName ( ) ;
119123 Verify . ValidFunctionName ( functionName ) ;
120124 if ( ! string . IsNullOrEmpty ( pluginName ) ) { Verify . ValidPluginName ( pluginName ) ; }
121125
122- var template = new PromptTemplate ( promptTemplate , config , kernel . PromptTemplateEngine ) ;
123-
124- // Prepare lambda wrapping AI logic
125- var functionConfig = new SemanticFunctionConfig ( config , template ) ;
126+ var template = new PromptTemplate ( promptTemplate , promptTemplateConfig , kernel . PromptTemplateEngine ) ;
126127
127128 // TODO: manage overwrites, potentially error out
128129 return string . IsNullOrEmpty ( pluginName )
129- ? kernel . RegisterSemanticFunction ( functionName , functionConfig )
130- : kernel . RegisterSemanticFunction ( pluginName ! , functionName , functionConfig ) ;
130+ ? kernel . RegisterSemanticFunction ( functionName , promptTemplateConfig , template )
131+ : kernel . RegisterSemanticFunction ( pluginName ! , functionName , promptTemplateConfig , template ) ;
131132 }
132133
133134 /// <summary>
134135 /// Invoke a semantic function using the provided prompt template.
135136 /// </summary>
136137 /// <param name="kernel">Semantic Kernel instance</param>
137- /// <param name="promptTemplate ">Plain language definition of the semantic function, using SK template language</param>
138+ /// <param name="template ">Plain language definition of the semantic function, using SK template language</param>
138139 /// <param name="functionName">A name for the given function. The name can be referenced in templates and used by the pipeline planner.</param>
139140 /// <param name="pluginName">Optional plugin name, for namespacing and avoid collisions</param>
140141 /// <param name="description">Optional description, useful for the planner</param>
141142 /// <param name="requestSettings">Optional LLM request settings</param>
142143 /// <returns>Kernel execution result</returns>
143144 public static Task < KernelResult > InvokeSemanticFunctionAsync (
144145 this IKernel kernel ,
145- string promptTemplate ,
146+ string template ,
146147 string ? functionName = null ,
147148 string ? pluginName = null ,
148149 string ? description = null ,
149150 AIRequestSettings ? requestSettings = null )
150151 {
151152 var skFunction = kernel . CreateSemanticFunction (
152- promptTemplate ,
153+ template ,
153154 functionName ,
154155 pluginName ,
155156 description ,
@@ -256,14 +257,12 @@ public static IDictionary<string, ISKFunction> ImportSemanticFunctionsFromDirect
256257 // Load prompt template
257258 var template = new PromptTemplate ( File . ReadAllText ( promptPath ) , config , kernel . PromptTemplateEngine ) ;
258259
259- var functionConfig = new SemanticFunctionConfig ( config , template ) ;
260-
261260 if ( logger . IsEnabled ( LogLevel . Trace ) )
262261 {
263262 logger . LogTrace ( "Registering function {0}.{1} loaded from {2}" , pluginDirectoryName , functionName , dir ) ;
264263 }
265264
266- functions [ functionName ] = kernel . RegisterSemanticFunction ( pluginDirectoryName , functionName , functionConfig ) ;
265+ functions [ functionName ] = kernel . RegisterSemanticFunction ( pluginDirectoryName , functionName , config , template ) ;
267266 }
268267 }
269268
@@ -276,23 +275,25 @@ private static ISKFunction CreateSemanticFunction(
276275 this IKernel kernel ,
277276 string pluginName ,
278277 string functionName ,
279- SemanticFunctionConfig functionConfig )
278+ PromptTemplateConfig promptTemplateConfig ,
279+ IPromptTemplate promptTemplate )
280280 {
281281 ISKFunction func = SemanticFunction . FromSemanticConfig (
282282 pluginName ,
283283 functionName ,
284- functionConfig ,
284+ promptTemplateConfig ,
285+ promptTemplate ,
285286 kernel . LoggerFactory
286287 ) ;
287288
288289 // Connect the function to the current kernel function collection, in case the function
289290 // is invoked manually without a context and without a way to find other functions.
290291 func . SetDefaultFunctionCollection ( kernel . Functions ) ;
291292
292- func . SetAIConfiguration ( functionConfig . PromptTemplateConfig . GetDefaultRequestSettings ( ) ) ;
293+ func . SetAIConfiguration ( promptTemplateConfig . GetDefaultRequestSettings ( ) ) ;
293294
294295 // Note: the service is instantiated using the kernel configuration state when the function is invoked
295- func . SetAIService ( ( ) => kernel . GetService < ITextCompletion > ( functionConfig . PromptTemplateConfig . GetDefaultRequestSettings ( ) ? . ServiceId ?? null ) ) ;
296+ func . SetAIService ( ( ) => kernel . GetService < ITextCompletion > ( promptTemplateConfig . GetDefaultRequestSettings ( ) ? . ServiceId ?? null ) ) ;
296297
297298 return func ;
298299 }
0 commit comments