Skip to content

Commit dad98cd

Browse files
authored
.Net: Remove ReadOnlySkillCollection accessor from ISkillCollection (microsoft#2178)
This ISkillCollection inherits IReadOnlySkillCollection, and therefore this is an implicit cast. There's certainly no need to implement it as a required property for future implementers of ISkillCollection. ### Description Remove property `ISkillCollection.ReadOnlySkillCollection`. Clean up comments, samples and tests. ### Contribution Checklist - [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 😄 -> This could be a (very low impact) breaking change, if anyone happens to be calling this.
1 parent 156ec85 commit dad98cd

File tree

7 files changed

+9
-63
lines changed

7 files changed

+9
-63
lines changed

dotnet/src/Extensions/Extensions.UnitTests/Planning/SequentialPlanner/SKContextExtensionsTests.cs

+2-4
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public async Task CanCallGetAvailableFunctionsWithNoFunctionsAsync()
4343
.Returns(asyncEnumerable);
4444

4545
// Arrange GetAvailableFunctionsAsync parameters
46-
var context = new SKContext(variables, skills.ReadOnlySkillCollection, logger);
46+
var context = new SKContext(variables, skills, logger);
4747
var config = new SequentialPlannerConfig() { Memory = memory.Object };
4848
var semanticQuery = "test";
4949

@@ -95,7 +95,6 @@ public async Task CanCallGetAvailableFunctionsWithFunctionsAsync()
9595
skills.Setup(x => x.TryGetFunction(It.IsAny<string>(), It.IsAny<string>(), out It.Ref<ISKFunction?>.IsAny)).Returns(true);
9696
skills.Setup(x => x.GetFunction(It.IsAny<string>(), It.IsAny<string>())).Returns(functionMock.Object);
9797
skills.Setup(x => x.GetFunctionsView(It.IsAny<bool>(), It.IsAny<bool>())).Returns(functionsView);
98-
skills.SetupGet(x => x.ReadOnlySkillCollection).Returns(skills.Object);
9998

10099
// Arrange GetAvailableFunctionsAsync parameters
101100
var context = new SKContext(variables, skills.Object, logger);
@@ -161,7 +160,6 @@ public async Task CanCallGetAvailableFunctionsWithFunctionsWithRelevancyAsync()
161160
skills.Setup(x => x.TryGetFunction(It.IsAny<string>(), It.IsAny<string>(), out It.Ref<ISKFunction?>.IsAny)).Returns(true);
162161
skills.Setup(x => x.GetFunction(It.IsAny<string>(), It.IsAny<string>())).Returns(functionMock.Object);
163162
skills.Setup(x => x.GetFunctionsView(It.IsAny<bool>(), It.IsAny<bool>())).Returns(functionsView);
164-
skills.SetupGet(x => x.ReadOnlySkillCollection).Returns(skills.Object);
165163

166164
// Arrange GetAvailableFunctionsAsync parameters
167165
var context = new SKContext(variables, skills.Object, logger);
@@ -217,7 +215,7 @@ public async Task CanCallGetAvailableFunctionsAsyncWithDefaultRelevancyAsync()
217215
.Returns(asyncEnumerable);
218216

219217
// Arrange GetAvailableFunctionsAsync parameters
220-
var context = new SKContext(variables, skills.ReadOnlySkillCollection, logger);
218+
var context = new SKContext(variables, skills, logger);
221219
var config = new SequentialPlannerConfig { RelevancyThreshold = 0.78, Memory = memory.Object };
222220
var semanticQuery = "test";
223221

dotnet/src/SemanticKernel.Abstractions/SkillDefinition/IReadOnlySkillCollection.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Microsoft.SemanticKernel.SkillDefinition;
77
/// <summary>
88
/// Read-only skill collection interface.
99
/// </summary>
10-
[SuppressMessage("Naming", "CA1711:Identifiers should not have incorrect suffix", Justification = "It is a collection")]
10+
[SuppressMessage("Naming", "CA1711:Identifiers should not have incorrect suffix")]
1111
public interface IReadOnlySkillCollection
1212
{
1313
/// <summary>

dotnet/src/SemanticKernel.Abstractions/SkillDefinition/ISkillCollection.cs

+1-6
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,9 @@ namespace Microsoft.SemanticKernel.SkillDefinition;
77
/// <summary>
88
/// Skill collection interface.
99
/// </summary>
10-
[SuppressMessage("Naming", "CA1711:Identifiers should not have incorrect suffix", Justification = "It is a collection")]
10+
[SuppressMessage("Naming", "CA1711:Identifiers should not have incorrect suffix")]
1111
public interface ISkillCollection : IReadOnlySkillCollection
1212
{
13-
/// <summary>
14-
/// Readonly only access into the collection
15-
/// </summary>
16-
IReadOnlySkillCollection ReadOnlySkillCollection { get; }
17-
1813
/// <summary>
1914
/// Add a function to the collection
2015
/// </summary>

dotnet/src/SemanticKernel/Kernel.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public sealed class Kernel : IKernel, IDisposable
4242
public ISemanticTextMemory Memory => this._memory;
4343

4444
/// <inheritdoc/>
45-
public IReadOnlySkillCollection Skills => this._skillCollection.ReadOnlySkillCollection;
45+
public IReadOnlySkillCollection Skills => this._skillCollection;
4646

4747
/// <inheritdoc/>
4848
public IPromptTemplateEngine PromptTemplateEngine { get; }
@@ -172,7 +172,7 @@ public async Task<SKContext> RunAsync(ContextVariables variables, CancellationTo
172172
{
173173
var context = new SKContext(
174174
variables,
175-
this._skillCollection.ReadOnlySkillCollection,
175+
this._skillCollection,
176176
this.Log);
177177

178178
int pipelineStepCount = -1;
@@ -222,7 +222,7 @@ public ISKFunction Func(string skillName, string functionName)
222222
public SKContext CreateNewContext()
223223
{
224224
return new SKContext(
225-
skills: this._skillCollection.ReadOnlySkillCollection,
225+
skills: this._skillCollection,
226226
logger: this.Log);
227227
}
228228

dotnet/src/SemanticKernel/SkillDefinition/IReadOnlySkillCollectionTypeProxy.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
namespace Microsoft.SemanticKernel.SkillDefinition;
88

99
/// <summary>
10-
/// Debugger type proxy for <see cref="SkillCollection"/> and <see cref="ReadOnlySkillCollection"/>.
10+
/// Debugger type proxy for <see cref="SkillCollection"/>.
1111
/// </summary>
1212
// ReSharper disable once InconsistentNaming
1313
internal sealed class IReadOnlySkillCollectionTypeProxy

dotnet/src/SemanticKernel/SkillDefinition/ReadOnlySkillCollection.cs

-42
This file was deleted.

dotnet/src/SemanticKernel/SkillDefinition/SkillCollection.cs

+1-6
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,17 @@ namespace Microsoft.SemanticKernel.SkillDefinition;
1616
/// The class holds a list of all the functions, native and semantic, known to the kernel instance.
1717
/// The list is used by the planner and when executing pipelines of function compositions.
1818
/// </summary>
19-
[SuppressMessage("Naming", "CA1711:Identifiers should not have incorrect suffix", Justification = "It is a collection")]
19+
[SuppressMessage("Naming", "CA1711:Identifiers should not have incorrect suffix")]
2020
[DebuggerTypeProxy(typeof(IReadOnlySkillCollectionTypeProxy))]
2121
[DebuggerDisplay("{DebuggerDisplay,nq}")]
2222
public class SkillCollection : ISkillCollection
2323
{
2424
internal const string GlobalSkill = "_GLOBAL_FUNCTIONS_";
2525

26-
/// <inheritdoc/>
27-
public IReadOnlySkillCollection ReadOnlySkillCollection { get; }
28-
2926
public SkillCollection(ILogger? log = null)
3027
{
3128
this._log = log ?? NullLogger.Instance;
3229

33-
this.ReadOnlySkillCollection = new ReadOnlySkillCollection(this);
34-
3530
// Important: names are case insensitive
3631
this._skillCollection = new(StringComparer.OrdinalIgnoreCase);
3732
}

0 commit comments

Comments
 (0)