Skip to content

Commit

Permalink
Minor cleanup of collection nullability.
Browse files Browse the repository at this point in the history
Fixes #2064
Fixes #2065
  • Loading branch information
shawncal committed Jul 20, 2023
1 parent f324a4b commit 199f055
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,12 @@ public static async Task<IOrderedEnumerable<FunctionView>> GetAvailableFunctions
SequentialPlannerConfig config,
string? semanticQuery = null)
{
var excludedSkills = config.ExcludedSkills ?? new();
var excludedFunctions = config.ExcludedFunctions ?? new();
var includedFunctions = config.IncludedFunctions ?? new();

if (context.Skills == null)
{
throw new KernelException(
KernelException.ErrorCodes.SkillCollectionNotSet,
"Skill collection not found in the context");
}

var functionsView = context.Skills.GetFunctionsView();

var availableFunctions = functionsView.SemanticFunctions
.Concat(functionsView.NativeFunctions)
.SelectMany(x => x.Value)
.Where(s => !excludedSkills.Contains(s.SkillName) && !excludedFunctions.Contains(s.Name))
.Where(s => !config.ExcludedSkills.Contains(s.SkillName) && !config.ExcludedFunctions.Contains(s.Name))
.ToList();

List<FunctionView>? result = null;
Expand All @@ -96,7 +85,7 @@ public static async Task<IOrderedEnumerable<FunctionView>> GetAvailableFunctions
result.AddRange(await GetRelevantFunctionsAsync(context, availableFunctions, memories).ConfigureAwait(false));

// Add any missing functions that were included but not found in the search results.
var missingFunctions = includedFunctions
var missingFunctions = config.IncludedFunctions
.Except(result.Select(x => x.Name))
.Join(availableFunctions, f => f, af => af.Name, (_, af) => af);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public ISemanticTextMemory Memory
/// <summary>
/// Read only skills collection
/// </summary>
public IReadOnlySkillCollection? Skills { get; internal set; }
public IReadOnlySkillCollection Skills { get; }

/// <summary>
/// Access registered functions by skill + name. Not case sensitive.
Expand All @@ -118,13 +118,6 @@ public ISemanticTextMemory Memory
/// <returns>Delegate to execute the function</returns>
public ISKFunction Func(string skillName, string functionName)
{
if (this.Skills is null)
{
throw new KernelException(
KernelException.ErrorCodes.SkillCollectionNotSet,
"Skill collection not found in the context");
}

return this.Skills.GetFunction(skillName, functionName);
}

Expand Down
3 changes: 0 additions & 3 deletions dotnet/src/SemanticKernel/SkillDefinition/SKFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,6 @@ public FunctionView Describe()
/// <inheritdoc/>
public async Task<SKContext> InvokeAsync(SKContext context, CompleteRequestSettings? settings = null)
{
// If the function is invoked manually, the user might have left out the skill collection
context.Skills ??= this._skillCollection;

if (this.IsSemantic)
{
this.AddDefaultValues(context.Variables);
Expand Down

0 comments on commit 199f055

Please sign in to comment.