Skip to content

Commit

Permalink
.Net: Remove IOrderedEnumerable from method signatures (#3506)
Browse files Browse the repository at this point in the history
### Motivation and Context

It's incredibly unusual for public API in .NET to use LINQ's
IOrderedEnumerable, especially in an interface where doing so is forcing
an implementation to use OrderBy. These should just be IEnumerable.

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [x] The code builds clean without any errors or warnings
- [x] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [x] All unit tests pass, and I have added new tests where possible
- [ ] I didn't break anyone 😄
  • Loading branch information
stephentoub committed Nov 15, 2023
1 parent 55cb52e commit ca09459
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
Expand Up @@ -67,7 +67,7 @@ public static class ReadOnlyFunctionCollectionPlannerExtensions
ILogger? logger = null,
CancellationToken cancellationToken = default)
{
IOrderedEnumerable<FunctionView> availableFunctions = await functions.GetFunctionsAsync(config, semanticQuery, logger, cancellationToken).ConfigureAwait(false);
IEnumerable<FunctionView> availableFunctions = await functions.GetFunctionsAsync(config, semanticQuery, logger, cancellationToken).ConfigureAwait(false);

return string.Join("\n\n", availableFunctions.Select(x => x.ToManualString()));
}
Expand Down Expand Up @@ -101,7 +101,7 @@ JsonDocument schemaBuilderDelegate(Type type, string description)
return schema;
}

IOrderedEnumerable<FunctionView> availableFunctions = await functions.GetFunctionsAsync(config, semanticQuery, logger, cancellationToken).ConfigureAwait(false);
IEnumerable<FunctionView> availableFunctions = await functions.GetFunctionsAsync(config, semanticQuery, logger, cancellationToken).ConfigureAwait(false);
var manuals = availableFunctions.Select(x => x.ToJsonSchemaManual(schemaBuilderDelegate, includeOutputSchema));
return JsonSerializer.Serialize(manuals);
}
Expand All @@ -115,7 +115,7 @@ JsonDocument schemaBuilderDelegate(Type type, string description)
/// <param name="logger">The logger to use for logging.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
/// <returns>A list of functions that are available to the user based on the semantic query and the excluded plugins and functions.</returns>
public static async Task<IOrderedEnumerable<FunctionView>> GetFunctionsAsync(
public static async Task<IEnumerable<FunctionView>> GetFunctionsAsync(
this IReadOnlyFunctionCollection functions,
PlannerConfigBase config,
string? semanticQuery,
Expand All @@ -137,7 +137,7 @@ JsonDocument schemaBuilderDelegate(Type type, string description)
/// <param name="logger">The logger to use for logging.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
/// <returns>A list of functions that are available to the user based on the semantic query and the excluded plugins and functions.</returns>
public static async Task<IOrderedEnumerable<FunctionView>> GetAvailableFunctionsAsync(
public static async Task<IEnumerable<FunctionView>> GetAvailableFunctionsAsync(
this IReadOnlyFunctionCollection functions,
PlannerConfigBase config,
string? semanticQuery = null,
Expand Down
3 changes: 1 addition & 2 deletions dotnet/src/Planners/Planners.Core/PlannerConfigBase.cs
Expand Up @@ -2,7 +2,6 @@

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

Expand Down Expand Up @@ -45,7 +44,7 @@ public abstract class PlannerConfigBase
/// If set, this function takes precedence over <see cref="Memory"/>.
/// Setting <see cref="ExcludedPlugins"/>, <see cref="ExcludedFunctions"/> will be used to filter the results.
/// </summary>
public Func<PlannerConfigBase, string?, CancellationToken, Task<IOrderedEnumerable<FunctionView>>>? GetAvailableFunctionsAsync { get; set; }
public Func<PlannerConfigBase, string?, CancellationToken, Task<IEnumerable<FunctionView>>>? GetAvailableFunctionsAsync { get; set; }

/// <summary>
/// Callback to get a function by name (optional).
Expand Down

0 comments on commit ca09459

Please sign in to comment.