18
18
using Microsoft . SemanticKernel . Skills . OpenAPI . Rest ;
19
19
using Microsoft . SemanticKernel . Skills . OpenAPI . Skills ;
20
20
21
- namespace Microsoft . SemanticKernel . Skills . OpenAPI . Extensions ;
21
+ // ReSharper disable once CheckNamespace
22
+ namespace Microsoft . SemanticKernel ;
22
23
23
24
/// <summary>
24
25
/// Class for extensions methods for <see cref="IKernel"/> interface.
@@ -92,7 +93,11 @@ public static async Task<IDictionary<string, ISKFunction>> ImportOpenApiSkillFro
92
93
/// <param name="authCallback">Optional callback for adding auth data to the API requests.</param>
93
94
/// <param name="cancellationToken">The cancellation token.</param>
94
95
/// <returns>A list of all the semantic functions representing the skill.</returns>
95
- public static Task < IDictionary < string , ISKFunction > > ImportOpenApiSkillFromResourceAsync ( this IKernel kernel , string skillName , AuthenticateRequestAsyncCallback ? authCallback = null , CancellationToken cancellationToken = default )
96
+ public static Task < IDictionary < string , ISKFunction > > ImportOpenApiSkillFromResourceAsync (
97
+ this IKernel kernel ,
98
+ string skillName ,
99
+ AuthenticateRequestAsyncCallback ? authCallback = null ,
100
+ CancellationToken cancellationToken = default )
96
101
{
97
102
Verify . ValidSkillName ( skillName ) ;
98
103
@@ -157,14 +162,19 @@ public static async Task<IDictionary<string, ISKFunction>> ImportOpenApiSkillFro
157
162
/// <param name="authCallback">Optional callback for adding auth data to the API requests.</param>
158
163
/// <param name="cancellationToken">The cancellation token.</param>
159
164
/// <returns>A list of all the semantic functions representing the skill.</returns>
160
- public static async Task < IDictionary < string , ISKFunction > > ImportOpenApiSkillFromFileAsync ( this IKernel kernel , string skillName , string filePath , AuthenticateRequestAsyncCallback ? authCallback = null , CancellationToken cancellationToken = default )
165
+ public static async Task < IDictionary < string , ISKFunction > > ImportOpenApiSkillFromFileAsync (
166
+ this IKernel kernel ,
167
+ string skillName ,
168
+ string filePath ,
169
+ AuthenticateRequestAsyncCallback ? authCallback = null ,
170
+ CancellationToken cancellationToken = default )
161
171
{
162
172
if ( ! File . Exists ( filePath ) )
163
173
{
164
174
throw new FileNotFoundException ( $ "No OpenApi document for the specified path - { filePath } is found.") ;
165
175
}
166
176
167
- kernel . Log . LogTrace ( "Registering Rest functions from {0} OpenApi document. " , filePath ) ;
177
+ kernel . Log . LogTrace ( "Registering Rest functions from {0} OpenApi document" , filePath ) ;
168
178
169
179
// TODO: never used, why?
170
180
var skill = new Dictionary < string , ISKFunction > ( ) ;
@@ -183,7 +193,12 @@ public static async Task<IDictionary<string, ISKFunction>> ImportOpenApiSkillFro
183
193
/// <param name="authCallback">Optional callback for adding auth data to the API requests.</param>
184
194
/// <param name="cancellationToken">The cancellation token.</param>
185
195
/// <returns>A list of all the semantic functions representing the skill.</returns>
186
- public static async Task < IDictionary < string , ISKFunction > > RegisterOpenApiSkillAsync ( this IKernel kernel , Stream documentStream , string skillName , AuthenticateRequestAsyncCallback ? authCallback = null , CancellationToken cancellationToken = default )
196
+ public static async Task < IDictionary < string , ISKFunction > > RegisterOpenApiSkillAsync (
197
+ this IKernel kernel ,
198
+ Stream documentStream ,
199
+ string skillName ,
200
+ AuthenticateRequestAsyncCallback ? authCallback = null ,
201
+ CancellationToken cancellationToken = default )
187
202
{
188
203
Verify . NotNull ( kernel , nameof ( kernel ) ) ;
189
204
Verify . ValidSkillName ( skillName ) ;
@@ -199,15 +214,15 @@ public static async Task<IDictionary<string, ISKFunction>> RegisterOpenApiSkillA
199
214
{
200
215
try
201
216
{
202
- kernel . Log . LogTrace ( "Registering Rest function {0}.{1}. " , skillName , operation . Id ) ;
217
+ kernel . Log . LogTrace ( "Registering Rest function {0}.{1}" , skillName , operation . Id ) ;
203
218
var function = kernel . RegisterRestApiFunction ( skillName , operation , authCallback , cancellationToken ) ;
204
219
skill [ function . Name ] = function ;
205
220
}
206
221
catch ( Exception ex ) when ( ! ex . IsCriticalException ( ) )
207
222
{
208
223
//Logging the exception and keep registering other Rest functions
209
- kernel . Log . LogWarning ( ex , "Something went wrong while rendering the Rest function. Function: {0}.{1}. Error: {2}" , skillName , operation . Id ,
210
- ex . Message ) ;
224
+ kernel . Log . LogWarning ( ex , "Something went wrong while rendering the Rest function. Function: {0}.{1}. Error: {2}" ,
225
+ skillName , operation . Id , ex . Message ) ;
211
226
}
212
227
}
213
228
@@ -225,7 +240,12 @@ public static async Task<IDictionary<string, ISKFunction>> RegisterOpenApiSkillA
225
240
/// <param name="authCallback">Optional callback for adding auth data to the API requests.</param>
226
241
/// <param name="cancellationToken">The cancellation token.</param>
227
242
/// <returns>An instance of <see cref="SKFunction"/> class.</returns>
228
- private static ISKFunction RegisterRestApiFunction ( this IKernel kernel , string skillName , RestApiOperation operation , AuthenticateRequestAsyncCallback ? authCallback = null , CancellationToken cancellationToken = default )
243
+ private static ISKFunction RegisterRestApiFunction (
244
+ this IKernel kernel ,
245
+ string skillName ,
246
+ RestApiOperation operation ,
247
+ AuthenticateRequestAsyncCallback ? authCallback = null ,
248
+ CancellationToken cancellationToken = default )
229
249
{
230
250
var restOperationParameters = operation . GetParameters ( ) ;
231
251
@@ -260,7 +280,7 @@ async Task<SKContext> ExecuteAsync(SKContext context)
260
280
}
261
281
}
262
282
263
- var result = await runner . RunAsync ( operation , arguments , context . CancellationToken ) . ConfigureAwait ( false ) ;
283
+ var result = await runner . RunAsync ( operation , arguments , cancellationToken ) . ConfigureAwait ( false ) ;
264
284
if ( result != null )
265
285
{
266
286
context . Variables . Update ( result . ToString ( ) ) ;
@@ -276,18 +296,21 @@ async Task<SKContext> ExecuteAsync(SKContext context)
276
296
return context ;
277
297
}
278
298
279
- // TODO: to be fixed later
280
- #pragma warning disable CA2000 // Dispose objects before losing scope.
281
- var function = new SKFunction (
282
- delegateType : SKFunction . DelegateTypes . ContextSwitchInSKContextOutTaskSKContext ,
283
- delegateFunction : ExecuteAsync ,
284
- parameters : restOperationParameters . Select ( p => new ParameterView ( )
299
+ var parameters = restOperationParameters
300
+ . Select ( p => new ParameterView
285
301
{
286
302
Name = p . AlternativeName ?? p . Name ,
287
303
Description = p . Name ,
288
304
DefaultValue = p . DefaultValue ?? string . Empty
289
305
} )
290
- . ToList ( ) , //functionConfig.PromptTemplate.GetParameters(),
306
+ . ToList ( ) ;
307
+
308
+ // TODO: to be fixed later
309
+ #pragma warning disable CA2000 // Dispose objects before losing scope.
310
+ var function = new SKFunction (
311
+ delegateType : SKFunction . DelegateTypes . ContextSwitchInSKContextOutTaskSKContext ,
312
+ delegateFunction : ExecuteAsync ,
313
+ parameters : parameters ,
291
314
description : operation . Description ,
292
315
skillName : skillName ,
293
316
functionName : operation . Id ,
0 commit comments