forked from microsoft/semantic-kernel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding local ToListAsync method in Copilot Chat (microsoft#1346)
### Motivation and Context The `System.Linq.Async` package reference was removed from the core libraries so that everyone using SK wasn't forced to use it as well. This adds a helper `ToListAsync` method to enable async conversion of `IAsyncEnumerable<T>` to `List<T>` object. ### Description Was seeing the following error when using local project references, so this is an effort to future proof any SK nuget updates `'IAsyncEnumerable<MemoryQueryResult>' does not contain a definition for 'ToListAsync' and no accessible extension method 'ToListAsync' accepting a first argument of type 'IAsyncEnumerable<MemoryQueryResult>' could be found (are you missing a using directive or an assembly reference?) `
- Loading branch information
1 parent
134906a
commit f8567c6
Showing
3 changed files
with
29 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
samples/apps/copilot-chat-app/webapi/CopilotChat/Extensions/IAsyncEnumerableExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
|
||
namespace SemanticKernel.Service.CopilotChat.Extensions; | ||
|
||
/// <summary> | ||
/// Extension methods for enabling async LINQ operations on IAsyncEnumerable sequence. | ||
/// </summary> | ||
public static class IAsyncEnumerableExtensions | ||
{ | ||
/// <summary> | ||
/// Creates a List<T> from an IAsyncEnumerable<T> by enumerating it asynchronously. | ||
/// </summary> | ||
internal static async Task<List<T>> ToListAsync<T>(this IAsyncEnumerable<T> source) | ||
{ | ||
var result = new List<T>(); | ||
await foreach (var item in source.ConfigureAwait(false)) | ||
{ | ||
result.Add(item); | ||
} | ||
|
||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters