Skip to content

Commit

Permalink
.Net: Rename ImportXXXPlugins methods to ImportXXXFunctions (#2937)
Browse files Browse the repository at this point in the history
### Motivation and Context

As part of the Skill -> Plugin rename the `ImportSkill` and
`ImportSemanticSkillFromDirectory` where renamed to use the term
`Plugin`. These methods actually import functions to the Kernel so this
PR renames them to match what they actually do.

We want to reserve `ImportPlugin` for use later when we add more plugin
support to the SK.

So now we do this:
`var functions = kernel.ImportFunctionsFromDirectory(...);`

In future we will do this
`var plugin = kernel.ImportPluginFromDirectory(...);`

The plugin instance will contain a list of functions in addition to
other data about the plugin.

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [ ] The code builds clean without any errors or warnings
- [ ] 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
- [ ] All unit tests pass, and I have added new tests where possible
- [ ] I didn't break anyone 😄
  • Loading branch information
markwallace-microsoft authored Sep 23, 2023
1 parent 086ef88 commit 3451a4e
Show file tree
Hide file tree
Showing 45 changed files with 217 additions and 208 deletions.
8 changes: 4 additions & 4 deletions dotnet/samples/ApplicationInsightsExample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ private static IKernel GetKernel(ILoggerFactory loggerFactory)
Env.Var("AzureOpenAI__ApiKey"))
.Build();

kernel.ImportSemanticPluginFromDirectory(folder, "SummarizePlugin", "WriterPlugin");
kernel.ImportSemanticFunctionsFromDirectory(folder, "SummarizePlugin", "WriterPlugin");

kernel.ImportPlugin(webSearchEnginePlugin, "WebSearch");
kernel.ImportPlugin(new LanguageCalculatorPlugin(kernel), "advancedCalculator");
kernel.ImportPlugin(new TimePlugin(), "time");
kernel.ImportFunctions(webSearchEnginePlugin, "WebSearch");
kernel.ImportFunctions(new LanguageCalculatorPlugin(kernel), "advancedCalculator");
kernel.ImportFunctions(new TimePlugin(), "time");

return kernel;
}
Expand Down
8 changes: 4 additions & 4 deletions dotnet/samples/KernelSyntaxExamples/Example02_Pipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ public static async Task RunAsync()
IKernel kernel = new KernelBuilder().WithLoggerFactory(s_loggerFactory).Build();

// Load native plugin
var text = kernel.ImportPlugin(new TextPlugin());
var textFunctions = kernel.ImportFunctions(new TextPlugin());

KernelResult result = await kernel.RunAsync(" i n f i n i t e s p a c e ",
text["TrimStart"],
text["TrimEnd"],
text["Uppercase"]);
textFunctions["TrimStart"],
textFunctions["TrimEnd"],
textFunctions["Uppercase"]);

Console.WriteLine(result.GetValue<string>());
}
Expand Down
6 changes: 3 additions & 3 deletions dotnet/samples/KernelSyntaxExamples/Example03_Variables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ public static async Task RunAsync()
Console.WriteLine("======== Variables ========");

IKernel kernel = new KernelBuilder().WithLoggerFactory(s_loggerFactory).Build();
var text = kernel.ImportPlugin(new StaticTextPlugin(), "text");
var textFunctions = kernel.ImportFunctions(new StaticTextPlugin(), "text");

var variables = new ContextVariables("Today is: ");
variables.Set("day", DateTimeOffset.Now.ToString("dddd", CultureInfo.CurrentCulture));

KernelResult result = await kernel.RunAsync(variables,
text["AppendDay"],
text["Uppercase"]);
textFunctions["AppendDay"],
textFunctions["Uppercase"]);

Console.WriteLine(result.GetValue<string>());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,31 +36,31 @@ public static async Task RunAsync()

var bingConnector = new BingConnector(bingApiKey);
var bing = new WebSearchEnginePlugin(bingConnector);
var search = kernel.ImportPlugin(bing, "bing");
var searchFunctions = kernel.ImportFunctions(bing, "bing");

// Load semantic plugins defined with prompt templates
string folder = RepoFiles.SamplePluginsPath();

var summarizePlugin = kernel.ImportSemanticPluginFromDirectory(folder, "SummarizePlugin");
var summarizeFunctions = kernel.ImportSemanticFunctionsFromDirectory(folder, "SummarizePlugin");

// Run
var ask = "What's the tallest building in South America";

var result1 = await kernel.RunAsync(
ask,
search["Search"]
searchFunctions["Search"]
);

var result2 = await kernel.RunAsync(
ask,
search["Search"],
summarizePlugin["Summarize"]
searchFunctions["Search"],
summarizeFunctions["Summarize"]
);

var result3 = await kernel.RunAsync(
ask,
search["Search"],
summarizePlugin["Notegen"]
searchFunctions["Search"],
summarizeFunctions["Notegen"]
);

Console.WriteLine(ask + "\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static async Task RunAsync()

// Load native plugin into the kernel function collection, sharing its functions with prompt templates
// Functions loaded here are available as "time.*"
kernel.ImportPlugin(new TimePlugin(), "time");
kernel.ImportFunctions(new TimePlugin(), "time");

// Semantic Function invoking time.Date and time.Time native functions
const string FunctionDefinition = @"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static async Task RunAsync()
{
var bingConnector = new BingConnector(bingApiKey);
var bing = new WebSearchEnginePlugin(bingConnector);
var search = kernel.ImportPlugin(bing, "bing");
kernel.ImportFunctions(bing, "bing");
await Example1Async(kernel, "bing");
await Example2Async(kernel);
}
Expand All @@ -66,7 +66,7 @@ public static async Task RunAsync()
apiKey: googleApiKey,
searchEngineId: googleSearchEngineId);
var google = new WebSearchEnginePlugin(googleConnector);
var search = kernel.ImportPlugin(new WebSearchEnginePlugin(googleConnector), "google");
kernel.ImportFunctions(new WebSearchEnginePlugin(googleConnector), "google");
await Example1Async(kernel, "google");
}
}
Expand Down
4 changes: 2 additions & 2 deletions dotnet/samples/KernelSyntaxExamples/Example08_RetryHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ private static async Task ImportAndExecutePluginAsync(IKernel kernel)
// Load semantic plugin defined with prompt templates
string folder = RepoFiles.SamplePluginsPath();

kernel.ImportPlugin(new TimePlugin(), "time");
kernel.ImportFunctions(new TimePlugin(), "time");

var qaPlugin = kernel.ImportSemanticPluginFromDirectory(
var qaPlugin = kernel.ImportSemanticFunctionsFromDirectory(
folder,
"QAPlugin");

Expand Down
66 changes: 33 additions & 33 deletions dotnet/samples/KernelSyntaxExamples/Example09_FunctionTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,71 +23,71 @@ public static async Task RunAsync()
var fakeContext = new SKContext(kernel);

// Load native plugin into the kernel function collection, sharing its functions with prompt templates
var test = kernel.ImportPlugin(new LocalExamplePlugin(), "test");
var testFunctions = kernel.ImportFunctions(new LocalExamplePlugin(), "test");

string folder = RepoFiles.SamplePluginsPath();
kernel.ImportSemanticPluginFromDirectory(folder, "SummarizePlugin");
kernel.ImportSemanticFunctionsFromDirectory(folder, "SummarizePlugin");

// The kernel takes care of wiring the input appropriately
await kernel.RunAsync(
test["type01"],
test["type02"],
test["type03"],
test["type04"],
test["type05"],
test["type06"],
test["type07"],
test["type08"],
test["type09"],
test["type10"],
test["type11"],
test["type12"],
test["type13"],
test["type14"],
test["type15"],
test["type16"],
test["type17"],
test["type18"]
testFunctions["type01"],
testFunctions["type02"],
testFunctions["type03"],
testFunctions["type04"],
testFunctions["type05"],
testFunctions["type06"],
testFunctions["type07"],
testFunctions["type08"],
testFunctions["type09"],
testFunctions["type10"],
testFunctions["type11"],
testFunctions["type12"],
testFunctions["type13"],
testFunctions["type14"],
testFunctions["type15"],
testFunctions["type16"],
testFunctions["type17"],
testFunctions["type18"]
);

// Using Kernel.RunAsync
await kernel.RunAsync(test["type01"]);
await kernel.RunAsync(testFunctions["type01"]);
await kernel.RunAsync(kernel.Functions.GetFunction("test", "type01"));

await kernel.RunAsync(test["type02"]);
await kernel.RunAsync(testFunctions["type02"]);
await kernel.RunAsync(kernel.Functions.GetFunction("test", "type02"));

await kernel.RunAsync(test["type03"]);
await kernel.RunAsync(testFunctions["type03"]);
await kernel.RunAsync(kernel.Functions.GetFunction("test", "type03"));

await kernel.RunAsync(test["type04"], fakeContext.Variables);
await kernel.RunAsync(testFunctions["type04"], fakeContext.Variables);
await kernel.RunAsync(fakeContext.Variables, kernel.Functions.GetFunction("test", "type04"));

await kernel.RunAsync(test["type05"], fakeContext.Variables);
await kernel.RunAsync(testFunctions["type05"], fakeContext.Variables);
await kernel.RunAsync(fakeContext.Variables, kernel.Functions.GetFunction("test", "type05"));

await kernel.RunAsync(test["type06"], fakeContext.Variables);
await kernel.RunAsync(testFunctions["type06"], fakeContext.Variables);
await kernel.RunAsync(fakeContext.Variables, kernel.Functions.GetFunction("test", "type06"));

await kernel.RunAsync(test["type07"], fakeContext.Variables);
await kernel.RunAsync(testFunctions["type07"], fakeContext.Variables);
await kernel.RunAsync(fakeContext.Variables, kernel.Functions.GetFunction("test", "type07"));

await kernel.RunAsync("", test["type08"]);
await kernel.RunAsync("", testFunctions["type08"]);
await kernel.RunAsync("", kernel.Functions.GetFunction("test", "type08"));

await kernel.RunAsync("", test["type09"]);
await kernel.RunAsync("", testFunctions["type09"]);
await kernel.RunAsync("", kernel.Functions.GetFunction("test", "type09"));

await kernel.RunAsync("", test["type10"]);
await kernel.RunAsync("", testFunctions["type10"]);
await kernel.RunAsync("", kernel.Functions.GetFunction("test", "type10"));

await kernel.RunAsync("", test["type11"]);
await kernel.RunAsync("", testFunctions["type11"]);
await kernel.RunAsync("", kernel.Functions.GetFunction("test", "type11"));

await kernel.RunAsync(fakeContext.Variables, test["type12"]);
await kernel.RunAsync(fakeContext.Variables, testFunctions["type12"]);
await kernel.RunAsync(fakeContext.Variables, kernel.Functions.GetFunction("test", "type12"));

await kernel.RunAsync(test["type18"]);
await kernel.RunAsync(testFunctions["type18"]);
await kernel.RunAsync(kernel.Functions.GetFunction("test", "type18"));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ public static Task RunAsync()
.Build();

// Import a native plugin
var plugin1 = new StaticTextPlugin();
kernel.ImportPlugin(plugin1, "StaticTextPlugin");
var staticText = new StaticTextPlugin();
kernel.ImportFunctions(staticText, "StaticTextPlugin");

// Import another native plugin
var plugin2 = new TextPlugin();
kernel.ImportPlugin(plugin2, "AnotherTextPlugin");
var text = new TextPlugin();
kernel.ImportFunctions(text, "AnotherTextPlugin");

// Import a semantic plugin
string folder = RepoFiles.SamplePluginsPath();
kernel.ImportSemanticPluginFromDirectory(folder, "SummarizePlugin");
kernel.ImportSemanticFunctionsFromDirectory(folder, "SummarizePlugin");

// Define a semantic function inline, without naming
var sFun1 = kernel.CreateSemanticFunction("tell a joke about {{$input}}", requestSettings: new OpenAIRequestSettings() { MaxTokens = 150 });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static async Task RunAsync()

// Load native plugins
var plugin = new SearchUrlPlugin();
var bing = kernel.ImportPlugin(plugin, "search");
var bing = kernel.ImportFunctions(plugin, "search");

// Run
var ask = "What's the tallest building in Europe?";
Expand Down
20 changes: 10 additions & 10 deletions dotnet/samples/KernelSyntaxExamples/Example12_SequentialPlanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ private static async Task PlanNotPossibleSampleAsync()

// Load additional plugins to enable planner but not enough for the given goal.
string folder = RepoFiles.SamplePluginsPath();
kernel.ImportSemanticPluginFromDirectory(folder, "SummarizePlugin");
kernel.ImportSemanticFunctionsFromDirectory(folder, "SummarizePlugin");

try
{
Expand Down Expand Up @@ -78,7 +78,7 @@ private static async Task PoetrySamplesAsync()
.Build();

string folder = RepoFiles.SamplePluginsPath();
kernel.ImportSemanticPluginFromDirectory(folder,
kernel.ImportSemanticFunctionsFromDirectory(folder,
"SummarizePlugin",
"WriterPlugin");

Expand Down Expand Up @@ -106,11 +106,11 @@ private static async Task EmailSamplesWithRecallAsync()
{
Console.WriteLine("======== Sequential Planner - Create and Execute Email Plan ========");
var kernel = InitializeKernelAndPlanner(out var planner, 512);
kernel.ImportPlugin(new EmailPlugin(), "email");
kernel.ImportFunctions(new EmailPlugin(), "email");

// Load additional plugins to enable planner to do non-trivial asks.
string folder = RepoFiles.SamplePluginsPath();
kernel.ImportSemanticPluginFromDirectory(folder,
kernel.ImportSemanticFunctionsFromDirectory(folder,
"SummarizePlugin",
"WriterPlugin");

Expand Down Expand Up @@ -198,8 +198,8 @@ private static async Task BookSamplesAsync()

// Load additional plugins to enable planner to do non-trivial asks.
string folder = RepoFiles.SamplePluginsPath();
kernel.ImportSemanticPluginFromDirectory(folder, "WriterPlugin");
kernel.ImportSemanticPluginFromDirectory(folder, "MiscPlugin");
kernel.ImportSemanticFunctionsFromDirectory(folder, "WriterPlugin");
kernel.ImportSemanticFunctionsFromDirectory(folder, "MiscPlugin");

var originalPlan = await planner.CreatePlanAsync("Create a book with 3 chapters about a group of kids in a club called 'The Thinking Caps.'");

Expand Down Expand Up @@ -230,7 +230,7 @@ private static async Task MemorySampleAsync()
var kernel = InitializeKernelWithMemory();

string folder = RepoFiles.SamplePluginsPath();
kernel.ImportSemanticPluginFromDirectory(folder,
kernel.ImportSemanticFunctionsFromDirectory(folder,
"SummarizePlugin",
"WriterPlugin",
"CalendarPlugin",
Expand All @@ -243,9 +243,9 @@ private static async Task MemorySampleAsync()
"MiscPlugin",
"QAPlugin");

kernel.ImportPlugin(new EmailPlugin(), "email");
kernel.ImportPlugin(new StaticTextPlugin(), "statictext");
kernel.ImportPlugin(new TextPlugin(), "coretext");
kernel.ImportFunctions(new EmailPlugin(), "email");
kernel.ImportFunctions(new StaticTextPlugin(), "statictext");
kernel.ImportFunctions(new TextPlugin(), "coretext");

var goal = "Create a book with 3 chapters about a group of kids in a club called 'The Thinking Caps.'";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ private static async Task ConversationSummaryPluginAsync()
IKernel kernel = InitializeKernel();

IDictionary<string, ISKFunction> conversationSummaryPlugin =
kernel.ImportPlugin(new ConversationSummaryPlugin(kernel));
kernel.ImportFunctions(new ConversationSummaryPlugin(kernel));

KernelResult summary = await kernel.RunAsync(
ChatTranscript,
Expand All @@ -148,12 +148,12 @@ private static async Task GetConversationActionItemsAsync()
Console.WriteLine("======== SamplePlugins - Conversation Summary Plugin - Action Items ========");
IKernel kernel = InitializeKernel();

IDictionary<string, ISKFunction> conversationSummaryPlugin =
kernel.ImportPlugin(new ConversationSummaryPlugin(kernel));
IDictionary<string, ISKFunction> conversationSummary =
kernel.ImportFunctions(new ConversationSummaryPlugin(kernel));

KernelResult summary = await kernel.RunAsync(
ChatTranscript,
conversationSummaryPlugin["GetConversationActionItems"]);
conversationSummary["GetConversationActionItems"]);

Console.WriteLine("Generated Action Items:");
Console.WriteLine(summary.GetValue<string>());
Expand All @@ -164,12 +164,12 @@ private static async Task GetConversationTopicsAsync()
Console.WriteLine("======== SamplePlugins - Conversation Summary Plugin - Topics ========");
IKernel kernel = InitializeKernel();

IDictionary<string, ISKFunction> conversationSummaryPlugin =
kernel.ImportPlugin(new ConversationSummaryPlugin(kernel));
IDictionary<string, ISKFunction> conversationSummary =
kernel.ImportFunctions(new ConversationSummaryPlugin(kernel));

KernelResult summary = await kernel.RunAsync(
ChatTranscript,
conversationSummaryPlugin["GetConversationTopics"]);
conversationSummary["GetConversationTopics"]);

Console.WriteLine("Generated Topics:");
Console.WriteLine(summary.GetValue<string>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ private static async Task RunWithStoreAsync(IMemoryStore memoryStore, Cancellati

// Import the TextMemoryPlugin into the Kernel for other functions
var memorySkill = new TextMemoryPlugin(textMemory);
var memoryFunctions = kernel.ImportPlugin(memorySkill);
var memoryFunctions = kernel.ImportFunctions(memorySkill);

// Save a memory with the Kernel
Console.WriteLine("Saving memory with key 'info5': \"My family is from New York\"");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ public static async Task RunAsync()
TestConfiguration.AzureOpenAI.ApiKey)
.Build();

string folder = RepoFiles.SamplePluginsPath();
kernel.ImportSemanticPluginFromDirectory(folder, "SummarizePlugin");
kernel.ImportSemanticPluginFromDirectory(folder, "WriterPlugin");
kernel.ImportSemanticPluginFromDirectory(folder, "FunPlugin");
string samplesDirectory = RepoFiles.SamplePluginsPath();
kernel.ImportSemanticFunctionsFromDirectory(samplesDirectory, "SummarizePlugin");
kernel.ImportSemanticFunctionsFromDirectory(samplesDirectory, "WriterPlugin");
kernel.ImportSemanticFunctionsFromDirectory(samplesDirectory, "FunPlugin");

// Create an optional config for the ActionPlanner. Use this to exclude plugins and functions if needed
var config = new ActionPlannerConfig();
Expand Down
Loading

0 comments on commit 3451a4e

Please sign in to comment.