Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions eng/packages/General.props
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<PackageVersion Include="System.CommandLine.NamingConventionBinder" Version="2.0.0-beta4.22272.1" />
<PackageVersion Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageVersion Include="System.ComponentModel.Annotations" Version="5.0.0" />
<PackageVersion Include="System.Linq.AsyncEnumerable" Version="10.0.0" />
<PackageVersion Include="System.Memory" Version="4.5.5" />
<PackageVersion Include="System.Private.Uri" Version="4.3.2" />
<PackageVersion Include="System.Runtime.Caching" Version="$(SystemRuntimeCachingVersion)" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@
<PackageReference Include="System.Numerics.Tensors" />
</ItemGroup>

<ItemGroup Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net10.0'))">
<PackageReference Include="System.Linq.AsyncEnumerable" />
</ItemGroup>

</Project>
38 changes: 0 additions & 38 deletions src/Libraries/Microsoft.Extensions.DataIngestion/Utils/Batching.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@

using System;
using System.Collections.Generic;
#if NET10_0_OR_GREATER
using System.Linq;
#endif
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -69,40 +67,4 @@ internal static async IAsyncEnumerable<IngestionChunk<string>> ProcessAsync<TMet
}
}
}

#if !NET10_0_OR_GREATER
#pragma warning disable VSTHRD200 // Use "Async" suffix for async methods
private static IAsyncEnumerable<TSource[]> Chunk<TSource>(this IAsyncEnumerable<TSource> source, int count)
#pragma warning restore VSTHRD200 // Use "Async" suffix for async methods
{
_ = Throw.IfNull(source);
_ = Throw.IfLessThanOrEqual(count, 0);

return CoreAsync(source, count);

static async IAsyncEnumerable<TSource[]> CoreAsync(IAsyncEnumerable<TSource> source, int count,
[EnumeratorCancellation] CancellationToken cancellationToken = default)
{
var buffer = new TSource[count];
int index = 0;

await foreach (var item in source.WithCancellation(cancellationToken).ConfigureAwait(false))
{
buffer[index++] = item;

if (index == count)
{
index = 0;
yield return buffer;
}
}

if (index > 0)
{
Array.Resize(ref buffer, index);
yield return buffer;
}
}
}
#endif
}
4 changes: 2 additions & 2 deletions src/ProjectTemplates/GeneratedContent.targets
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<TemplatePackageVersion_OllamaSharp>5.4.8</TemplatePackageVersion_OllamaSharp>
<TemplatePackageVersion_OpenTelemetry>1.13.0</TemplatePackageVersion_OpenTelemetry>
<TemplatePackageVersion_PdfPig>0.1.11</TemplatePackageVersion_PdfPig>
<TemplatePackageVersion_SystemLinqAsync>6.0.3</TemplatePackageVersion_SystemLinqAsync>
<TemplatePackageVersion_SystemLinqAsyncEnumerable>10.0.0</TemplatePackageVersion_SystemLinqAsyncEnumerable>
</PropertyGroup>

<PropertyGroup>
Expand Down Expand Up @@ -83,7 +83,7 @@
TemplatePackageVersion_OllamaSharp=$(TemplatePackageVersion_OllamaSharp);
TemplatePackageVersion_OpenTelemetry=$(TemplatePackageVersion_OpenTelemetry);
TemplatePackageVersion_PdfPig=$(TemplatePackageVersion_PdfPig);
TemplatePackageVersion_SystemLinqAsync=$(TemplatePackageVersion_SystemLinqAsync);
TemplatePackageVersion_SystemLinqAsyncEnumerable=$(TemplatePackageVersion_SystemLinqAsyncEnumerable);

<!-- Other properties -->
LocalChatTemplateVariant=$(_LocalChatTemplateVariant);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<PackageReference Include="Microsoft.ML.Tokenizers.Data.Cl100kBase" Version="${TemplatePackageVersion_MicrosoftMLTokenizers}" />
<PackageReference Include="Microsoft.ML.Tokenizers.Data.O200kBase" Version="${TemplatePackageVersion_MicrosoftMLTokenizers}" />
<!--#if (IsNET9) -->
<PackageReference Include="System.Linq.Async" Version="${TemplatePackageVersion_SystemLinqAsync}" />
<PackageReference Include="System.Linq.AsyncEnumerable" Version="${TemplatePackageVersion_SystemLinqAsyncEnumerable}" />
<!--#endif -->
<!--#if (IsAzureAISearch && IsAspire)
<PackageReference Include="Aspire.Azure.Search.Documents" Version="${TemplatePackageVersion_Aspire}" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public async Task StreamingCachesSuccessResultsAsync(bool conversationIdSet)
GetStreamingResponseAsyncCallback = delegate
{
innerCallCount++;
return ToAsyncEnumerableAsync(actualUpdate);
return actualUpdate.ToAsyncEnumerable();
}
};
using var outer = new DistributedCachingChatClient(testClient, _storage)
Expand Down Expand Up @@ -320,7 +320,7 @@ public async Task StreamingCoalescesConsecutiveTextChunksAsync(bool? coalesce)

using var testClient = new TestChatClient
{
GetStreamingResponseAsyncCallback = delegate { return ToAsyncEnumerableAsync(expectedResponse); }
GetStreamingResponseAsyncCallback = delegate { return expectedResponse.ToAsyncEnumerable(); }
};
using var outer = new DistributedCachingChatClient(testClient, _storage)
{
Expand Down Expand Up @@ -398,7 +398,7 @@ public async Task StreamingCoalescingPropagatesMetadataAsync()

using var testClient = new TestChatClient
{
GetStreamingResponseAsyncCallback = delegate { return ToAsyncEnumerableAsync(expectedResponse); }
GetStreamingResponseAsyncCallback = delegate { return expectedResponse.ToAsyncEnumerable(); }
};
using var outer = new DistributedCachingChatClient(testClient, _storage)
{
Expand Down Expand Up @@ -772,9 +772,6 @@ private static async Task<List<T>> ToListAsync<T>(IAsyncEnumerable<T> values)
return result;
}

private static IAsyncEnumerable<T> ToAsyncEnumerableAsync<T>(IEnumerable<T> values)
=> ToAsyncEnumerableAsync(Task.CompletedTask, values);

private static IAsyncEnumerable<T> ToAsyncEnumerableAsync<T>(Task preTask, IEnumerable<T> valueFactories)
=> ToAsyncEnumerableAsync(preTask, valueFactories.Select<T, Func<T>>(v => () => v));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
Expand Down Expand Up @@ -61,7 +62,7 @@ public async Task GetResponseAsync_CallsReducerBeforeInnerClient(bool streaming)
{
// Verify that the inner client receives the reduced messages
Assert.Same(reducedMessages, messages);
return ToAsyncEnumerable(expectedUpdates);
return expectedUpdates.ToAsyncEnumerable();
}
};

Expand Down Expand Up @@ -163,15 +164,6 @@ public async Task UseChatReducer_WithConfigureCallback()
Assert.IsType<ReducingChatClient>(configuredClient);
}

private static async IAsyncEnumerable<T> ToAsyncEnumerable<T>(IEnumerable<T> items)
{
foreach (var item in items)
{
await Task.Yield();
yield return item;
}
}

private sealed class TestReducer : IChatReducer
{
public IEnumerable<ChatMessage>? ReducedMessages { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
<PackageReference Include="OpenTelemetry.Exporter.InMemory" />
</ItemGroup>

<ItemGroup Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net10.0'))">
<PackageReference Include="System.Linq.AsyncEnumerable" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\Libraries\Microsoft.Extensions.Diagnostics.Testing\Microsoft.Extensions.Diagnostics.Testing.csproj" />
<ProjectReference Include="..\..\..\src\Libraries\Microsoft.Extensions.AI.Abstractions\Microsoft.Extensions.AI.Abstractions.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.ML.Tokenizers;
using Xunit;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.VectorData;
using Xunit;
Expand Down
Loading