Skip to content

Commit b6dcba9

Browse files
committed
A few more tweaks
1 parent b115f96 commit b6dcba9

File tree

15 files changed

+14
-45
lines changed

15 files changed

+14
-45
lines changed

src/Libraries/.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5648,7 +5648,7 @@ dotnet_diagnostic.SA1202.severity = suggestion
56485648
# Title : Constants should appear before fields
56495649
# Category : StyleCop.CSharp.OrderingRules
56505650
# Help Link: https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1203.md
5651-
dotnet_diagnostic.SA1203.severity = warning
5651+
dotnet_diagnostic.SA1203.severity = suggestion
56525652

56535653
# Title : Static elements should appear before instance elements
56545654
# Category : StyleCop.CSharp.OrderingRules

src/Libraries/Microsoft.Extensions.AI.Abstractions/AdditionalPropertiesDictionary{TValue}.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
using System.Linq;
1111
using Microsoft.Shared.Diagnostics;
1212

13-
#pragma warning disable S2365 // Properties should not make collection or array copies
1413
#pragma warning disable S4039 // Interface methods should be callable by derived types
1514
#pragma warning disable CA1033 // Interface methods should be callable by derived types
1615

@@ -253,7 +252,9 @@ private sealed class DebugView(AdditionalPropertiesDictionary<TValue> properties
253252
private readonly AdditionalPropertiesDictionary<TValue> _properties = Throw.IfNull(properties);
254253

255254
[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
255+
#pragma warning disable S2365 // Properties should not make collection or array copies
256256
public AdditionalProperty[] Items => (from p in _properties select new AdditionalProperty(p.Key, p.Value)).ToArray();
257+
#pragma warning restore S2365
257258

258259
[DebuggerDisplay("{Value}", Name = "[{Key}]")]
259260
public readonly struct AdditionalProperty(string key, TValue value)

src/Libraries/Microsoft.Extensions.AI.Abstractions/Embeddings/EmbeddingGeneratorExtensions.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
using System.Threading.Tasks;
99
using Microsoft.Shared.Diagnostics;
1010

11-
#pragma warning disable S4136 // Method overloads should be grouped together
12-
1311
namespace Microsoft.Extensions.AI;
1412

1513
/// <summary>Provides a collection of static methods for extending <see cref="IEmbeddingGenerator{TInput,TEmbedding}"/> instances.</summary>

src/Libraries/Microsoft.Extensions.AI.Abstractions/Functions/AIFunctionArguments.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,10 @@ public AIFunctionArguments(IEqualityComparer<string>? comparer)
7777
/// </remarks>
7878
public AIFunctionArguments(IDictionary<string, object?>? arguments, IEqualityComparer<string>? comparer)
7979
{
80-
#pragma warning disable S1698 // Consider using 'Equals' if value comparison is intended.
8180
_arguments =
82-
arguments is null
83-
? new Dictionary<string, object?>(comparer)
84-
: (arguments is Dictionary<string, object?> dc) && (comparer is null || dc.Comparer == comparer)
85-
? dc
86-
: new Dictionary<string, object?>(arguments, comparer);
87-
#pragma warning restore S1698 // Consider using 'Equals' if value comparison is intended.
81+
arguments is null ? new(comparer) :
82+
arguments is Dictionary<string, object?> dc && (comparer is null || ReferenceEquals(dc.Comparer, comparer)) ? dc :
83+
new(arguments, comparer);
8884
}
8985

9086
/// <summary>Gets or sets services optionally associated with these arguments.</summary>

src/Libraries/Microsoft.Extensions.AI.Abstractions/Functions/AIFunctionFactory.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
using Microsoft.Shared.Diagnostics;
2424

2525
#pragma warning disable S3011 // Reflection should not be used to increase accessibility of classes, methods, or fields
26-
#pragma warning disable SA1203 // Constants should appear before fields
2726

2827
namespace Microsoft.Extensions.AI;
2928

@@ -1046,8 +1045,8 @@ static void ThrowNullServices(string parameterName) =>
10461045
static object ThrowIfNullResult(object? result) => result ?? throw new InvalidOperationException("Function returned null unexpectedly.");
10471046
}
10481047

1049-
private static readonly MethodInfo _taskGetResult = typeof(Task<>).GetProperty(nameof(Task<int>.Result), BindingFlags.Instance | BindingFlags.Public)!.GetMethod!;
1050-
private static readonly MethodInfo _valueTaskAsTask = typeof(ValueTask<>).GetMethod(nameof(ValueTask<int>.AsTask), BindingFlags.Instance | BindingFlags.Public)!;
1048+
private static readonly MethodInfo _taskGetResult = typeof(Task<>).GetProperty(nameof(Task<>.Result), BindingFlags.Instance | BindingFlags.Public)!.GetMethod!;
1049+
private static readonly MethodInfo _valueTaskAsTask = typeof(ValueTask<>).GetMethod(nameof(ValueTask<>.AsTask), BindingFlags.Instance | BindingFlags.Public)!;
10511050

10521051
private static MethodInfo GetMethodFromGenericMethodDefinition(Type specializedType, MethodInfo genericMethodDefinition)
10531052
{

src/Libraries/Microsoft.Extensions.AI.AzureAIInference/AzureAIInferenceChatClient.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
using Azure.AI.Inference;
1616
using Microsoft.Shared.Diagnostics;
1717

18-
#pragma warning disable S1135 // Track uses of "TODO" tags
1918
#pragma warning disable S3011 // Reflection should not be used to increase accessibility of classes, methods, or fields
2019
#pragma warning disable SA1204 // Static elements should appear before instance elements
2120

@@ -183,13 +182,6 @@ public async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(
183182
// Transfer over tool call updates.
184183
if (chatCompletionUpdate.ToolCallUpdate is { } toolCallUpdate)
185184
{
186-
// TODO https://github.com/Azure/azure-sdk-for-net/issues/46830: Azure.AI.Inference
187-
// has removed the Index property from ToolCallUpdate. It's now impossible via the
188-
// exposed APIs to correctly handle multiple parallel tool calls, as the CallId is
189-
// often null for anything other than the first update for a given call, and Index
190-
// isn't available to correlate which updates are for which call. This is a temporary
191-
// workaround to at least make a single tool call work and also make work multiple
192-
// tool calls when their updates aren't interleaved.
193185
if (toolCallUpdate.Id is not null)
194186
{
195187
lastCallId = toolCallUpdate.Id;
@@ -485,8 +477,6 @@ private static IEnumerable<ChatRequestMessage> ToAzureAIInferenceChatMessages(IE
485477
}
486478
else if (input.Role == ChatRole.Assistant)
487479
{
488-
// TODO: ChatRequestAssistantMessage only enables text content currently.
489-
// Update it with other content types when it supports that.
490480
ChatRequestAssistantMessage message = new(string.Concat(input.Contents.Where(c => c is TextContent)));
491481

492482
foreach (var content in input.Contents)

src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIAssistantsChatClient.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
#pragma warning disable S125 // Sections of code should not be commented out
1818
#pragma warning disable S1751 // Loops with at most one iteration should be refactored
1919
#pragma warning disable S3011 // Reflection should not be used to increase accessibility of classes, methods, or fields
20-
#pragma warning disable S4456 // Parameter validation in yielding methods should be wrapped
21-
#pragma warning disable S4457 // Parameter validation in "async"/"await" methods should be wrapped
2220

2321
namespace Microsoft.Extensions.AI;
2422

src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIEmbeddingGenerator.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
using OpenAI.Embeddings;
1414

1515
#pragma warning disable S3011 // Reflection should not be used to increase accessibility of classes, methods, or fields
16-
#pragma warning disable EA0011 // Consider removing unnecessary conditional access operator (?)
1716

1817
namespace Microsoft.Extensions.AI;
1918

src/Libraries/Microsoft.Extensions.AI/Embeddings/ConfigureOptionsEmbeddingGeneratorBuilderExtensions.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
using System;
55
using Microsoft.Shared.Diagnostics;
66

7-
#pragma warning disable SA1629 // Documentation text should end with a period
8-
97
namespace Microsoft.Extensions.AI;
108

119
/// <summary>Provides extensions for configuring <see cref="ConfigureOptionsEmbeddingGenerator{TInput, TEmbedding}"/> instances.</summary>

src/Libraries/Microsoft.Extensions.AI/Embeddings/EmbeddingGeneratorBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ public IEmbeddingGenerator<TInput, TEmbedding> Build(IServiceProvider? services
5858
if (embeddingGenerator is null)
5959
{
6060
Throw.InvalidOperationException(
61-
$"The {nameof(IEmbeddingGenerator<TInput, TEmbedding>)} entry at index {i} returned null. " +
62-
$"Ensure that the callbacks passed to {nameof(Use)} return non-null {nameof(IEmbeddingGenerator<TInput, TEmbedding>)} instances.");
61+
$"The {nameof(IEmbeddingGenerator<,>)} entry at index {i} returned null. " +
62+
$"Ensure that the callbacks passed to {nameof(Use)} return non-null {nameof(IEmbeddingGenerator<,>)} instances.");
6363
}
6464
}
6565
}

0 commit comments

Comments
 (0)