@@ -155,7 +155,7 @@ public static KernelPlugin CreateWithGetSearchResults(this ITextSearch textSearc
155
155
[ RequiresDynamicCode ( "Uses reflection to handle various aspects of the function creation and invocation, making it incompatible with AOT scenarios." ) ]
156
156
public static KernelFunction CreateSearch ( this ITextSearch textSearch , KernelFunctionFromMethodOptions ? options = null , TextSearchOptions ? searchOptions = null )
157
157
{
158
- async Task < IEnumerable < string > > SearchAsync ( Kernel kernel , KernelFunction function , KernelArguments arguments , CancellationToken cancellationToken )
158
+ async Task < IEnumerable < string > > SearchAsync ( Kernel kernel , KernelFunction function , KernelArguments arguments , CancellationToken cancellationToken , int count = 2 , int skip = 0 )
159
159
{
160
160
arguments . TryGetValue ( "query" , out var query ) ;
161
161
if ( string . IsNullOrEmpty ( query ? . ToString ( ) ) )
@@ -167,8 +167,8 @@ async Task<IEnumerable<string>> SearchAsync(Kernel kernel, KernelFunction functi
167
167
168
168
searchOptions ??= new ( )
169
169
{
170
- Top = GetArgumentValue ( arguments , parameters , " count" , 2 ) ,
171
- Skip = GetArgumentValue ( arguments , parameters , " skip" , 0 ) ,
170
+ Top = count ,
171
+ Skip = skip ,
172
172
Filter = CreateBasicFilter ( options , arguments )
173
173
} ;
174
174
@@ -194,7 +194,7 @@ async Task<IEnumerable<string>> SearchAsync(Kernel kernel, KernelFunction functi
194
194
[ Experimental ( "SKEXP0120" ) ]
195
195
public static KernelFunction CreateSearch ( this ITextSearch textSearch , JsonSerializerOptions jsonSerializerOptions , KernelFunctionFromMethodOptions ? options = null , TextSearchOptions ? searchOptions = null )
196
196
{
197
- async Task < IEnumerable < string > > SearchAsync ( Kernel kernel , KernelFunction function , KernelArguments arguments , CancellationToken cancellationToken )
197
+ async Task < IEnumerable < string > > SearchAsync ( Kernel kernel , KernelFunction function , KernelArguments arguments , CancellationToken cancellationToken , int count = 2 , int skip = 0 )
198
198
{
199
199
arguments . TryGetValue ( "query" , out var query ) ;
200
200
if ( string . IsNullOrEmpty ( query ? . ToString ( ) ) )
@@ -206,8 +206,8 @@ async Task<IEnumerable<string>> SearchAsync(Kernel kernel, KernelFunction functi
206
206
207
207
searchOptions ??= new ( )
208
208
{
209
- Top = GetArgumentValue ( arguments , parameters , " count" , 2 ) ,
210
- Skip = GetArgumentValue ( arguments , parameters , " skip" , 0 ) ,
209
+ Top = count ,
210
+ Skip = skip ,
211
211
Filter = CreateBasicFilter ( options , arguments )
212
212
} ;
213
213
@@ -234,7 +234,7 @@ async Task<IEnumerable<string>> SearchAsync(Kernel kernel, KernelFunction functi
234
234
[ RequiresDynamicCode ( "Uses reflection to handle various aspects of the function creation and invocation, making it incompatible with AOT scenarios." ) ]
235
235
public static KernelFunction CreateGetTextSearchResults ( this ITextSearch textSearch , KernelFunctionFromMethodOptions ? options = null , TextSearchOptions ? searchOptions = null )
236
236
{
237
- async Task < IEnumerable < TextSearchResult > > GetTextSearchResultAsync ( Kernel kernel , KernelFunction function , KernelArguments arguments , CancellationToken cancellationToken )
237
+ async Task < IEnumerable < TextSearchResult > > GetTextSearchResultAsync ( Kernel kernel , KernelFunction function , KernelArguments arguments , CancellationToken cancellationToken , int count = 2 , int skip = 0 )
238
238
{
239
239
arguments . TryGetValue ( "query" , out var query ) ;
240
240
if ( string . IsNullOrEmpty ( query ? . ToString ( ) ) )
@@ -246,8 +246,8 @@ async Task<IEnumerable<TextSearchResult>> GetTextSearchResultAsync(Kernel kernel
246
246
247
247
searchOptions ??= new ( )
248
248
{
249
- Top = GetArgumentValue ( arguments , parameters , " count" , 2 ) ,
250
- Skip = GetArgumentValue ( arguments , parameters , " skip" , 0 ) ,
249
+ Top = count ,
250
+ Skip = skip ,
251
251
Filter = CreateBasicFilter ( options , arguments )
252
252
} ;
253
253
@@ -272,7 +272,7 @@ async Task<IEnumerable<TextSearchResult>> GetTextSearchResultAsync(Kernel kernel
272
272
[ Experimental ( "SKEXP0120" ) ]
273
273
public static KernelFunction CreateGetTextSearchResults ( this ITextSearch textSearch , JsonSerializerOptions jsonSerializerOptions , KernelFunctionFromMethodOptions ? options = null , TextSearchOptions ? searchOptions = null )
274
274
{
275
- async Task < IEnumerable < TextSearchResult > > GetTextSearchResultAsync ( Kernel kernel , KernelFunction function , KernelArguments arguments , CancellationToken cancellationToken )
275
+ async Task < IEnumerable < TextSearchResult > > GetTextSearchResultAsync ( Kernel kernel , KernelFunction function , KernelArguments arguments , CancellationToken cancellationToken , int count = 2 , int skip = 0 )
276
276
{
277
277
arguments . TryGetValue ( "query" , out var query ) ;
278
278
if ( string . IsNullOrEmpty ( query ? . ToString ( ) ) )
@@ -284,8 +284,8 @@ async Task<IEnumerable<TextSearchResult>> GetTextSearchResultAsync(Kernel kernel
284
284
285
285
searchOptions ??= new ( )
286
286
{
287
- Top = GetArgumentValue ( arguments , parameters , " count" , 2 ) ,
288
- Skip = GetArgumentValue ( arguments , parameters , " skip" , 0 ) ,
287
+ Top = count ,
288
+ Skip = skip ,
289
289
Filter = CreateBasicFilter ( options , arguments )
290
290
} ;
291
291
@@ -311,7 +311,7 @@ async Task<IEnumerable<TextSearchResult>> GetTextSearchResultAsync(Kernel kernel
311
311
[ RequiresDynamicCode ( "Uses reflection to handle various aspects of the function creation and invocation, making it incompatible with AOT scenarios." ) ]
312
312
public static KernelFunction CreateGetSearchResults ( this ITextSearch textSearch , KernelFunctionFromMethodOptions ? options = null , TextSearchOptions ? searchOptions = null )
313
313
{
314
- async Task < IEnumerable < object > > GetSearchResultAsync ( Kernel kernel , KernelFunction function , KernelArguments arguments , CancellationToken cancellationToken )
314
+ async Task < IEnumerable < object > > GetSearchResultAsync ( Kernel kernel , KernelFunction function , KernelArguments arguments , CancellationToken cancellationToken , int count = 2 , int skip = 0 )
315
315
{
316
316
arguments . TryGetValue ( "query" , out var query ) ;
317
317
if ( string . IsNullOrEmpty ( query ? . ToString ( ) ) )
@@ -323,8 +323,8 @@ async Task<IEnumerable<object>> GetSearchResultAsync(Kernel kernel, KernelFuncti
323
323
324
324
searchOptions ??= new ( )
325
325
{
326
- Top = GetArgumentValue ( arguments , parameters , " count" , 2 ) ,
327
- Skip = GetArgumentValue ( arguments , parameters , " skip" , 0 ) ,
326
+ Top = count ,
327
+ Skip = skip ,
328
328
Filter = CreateBasicFilter ( options , arguments )
329
329
} ;
330
330
@@ -349,7 +349,7 @@ async Task<IEnumerable<object>> GetSearchResultAsync(Kernel kernel, KernelFuncti
349
349
[ Experimental ( "SKEXP0120" ) ]
350
350
public static KernelFunction CreateGetSearchResults ( this ITextSearch textSearch , JsonSerializerOptions jsonSerializerOptions , KernelFunctionFromMethodOptions ? options = null , TextSearchOptions ? searchOptions = null )
351
351
{
352
- async Task < IEnumerable < object > > GetSearchResultAsync ( Kernel kernel , KernelFunction function , KernelArguments arguments , CancellationToken cancellationToken )
352
+ async Task < IEnumerable < object > > GetSearchResultAsync ( Kernel kernel , KernelFunction function , KernelArguments arguments , CancellationToken cancellationToken , int count = 2 , int skip = 0 )
353
353
{
354
354
arguments . TryGetValue ( "query" , out var query ) ;
355
355
if ( string . IsNullOrEmpty ( query ? . ToString ( ) ) )
@@ -361,8 +361,8 @@ async Task<IEnumerable<object>> GetSearchResultAsync(Kernel kernel, KernelFuncti
361
361
362
362
searchOptions ??= new ( )
363
363
{
364
- Top = GetArgumentValue ( arguments , parameters , " count" , 2 ) ,
365
- Skip = GetArgumentValue ( arguments , parameters , " skip" , 0 ) ,
364
+ Top = count ,
365
+ Skip = skip ,
366
366
Filter = CreateBasicFilter ( options , arguments )
367
367
} ;
368
368
@@ -380,30 +380,6 @@ async Task<IEnumerable<object>> GetSearchResultAsync(Kernel kernel, KernelFuncti
380
380
#endregion
381
381
382
382
#region private
383
- /// <summary>
384
- /// Get the argument value from <see cref="KernelArguments"/> or users default value from
385
- /// <see cref="KernelReturnParameterMetadata"/> or default to the provided value.
386
- /// </summary>
387
- /// <param name="arguments">KernelArguments instance.</param>
388
- /// <param name="parameters">List of KernelReturnParameterMetadata.</param>
389
- /// <param name="name">Name of the argument.</param>
390
- /// <param name="defaultValue">Default value of the argument.</param>
391
- private static int GetArgumentValue ( KernelArguments arguments , IReadOnlyList < KernelParameterMetadata > parameters , string name , int defaultValue )
392
- {
393
- if ( arguments . TryGetValue ( name , out var value ) && value is int argument )
394
- {
395
- return argument ;
396
- }
397
-
398
- value = parameters . FirstOrDefault ( parameter => parameter . Name == name ) ? . DefaultValue ;
399
- if ( value is int metadataDefault )
400
- {
401
- return metadataDefault ;
402
- }
403
-
404
- return defaultValue ;
405
- }
406
-
407
383
/// <summary>
408
384
/// Create the default <see cref="KernelFunctionFromMethodOptions"/> for <see cref="ITextSearch.SearchAsync(string, TextSearchOptions?, CancellationToken)"/>.
409
385
/// </summary>
0 commit comments