Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to RC1 of Semantic Kernel #32

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
12 changes: 7 additions & 5 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<!-- <PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Http.Resilience" Version="8.0.0" /> -->
<PackageVersion Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
<PackageVersion Include="Microsoft.ML.Tokenizers" Version="0.21.0-preview.23266.6"/>
<PackageVersion Include="Microsoft.SemanticKernel" Version="1.0.0-beta7" />
<PackageVersion Include="Microsoft.SemanticKernel.Planners.Core" Version="1.0.0-beta7" />
<PackageVersion Include="Microsoft.SemanticKernel.Plugins.Web" Version="1.0.0-beta7" />
<PackageVersion Include="Microsoft.SemanticKernel.Reliability.Basic" Version="1.0.0-beta7" />
<PackageVersion Include="Microsoft.SemanticKernel" Version="1.0.0-rc1" />
<PackageVersion Include="Microsoft.SemanticKernel.Planners.Handlebars" Version="1.0.0-rc1" />
<PackageVersion Include="Microsoft.SemanticKernel.Planners.OpenAI" Version="1.0.0-rc1" />
<PackageVersion Include="Microsoft.SemanticKernel.Plugins.Web" Version="1.0.0-rc1" />
<PackageVersion Include="Spectre.Console" Version="0.47.0" />
<PackageVersion Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageVersion Include="TextCopy" Version="6.2.1" />
Expand Down
11 changes: 6 additions & 5 deletions apps/SKonsole/Commands/CommitCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private static async Task RunCommitMessage(CancellationToken token, ILogger logg
}
}

var pullRequestPlugin = kernel.ImportFunctions(new PRPlugin.PullRequestPlugin(kernel));
var pullRequestPlugin = kernel.ImportPluginFromObject(new PRPlugin.PullRequestPlugin(kernel));

static void HorizontalRule(string title, string style = "white bold")
{
Expand All @@ -119,12 +119,13 @@ static void HorizontalRule(string title, string style = "white bold")
.StartAsync(async ctx =>
{
var task = ctx.AddTask("[green]Thinking...[/]", autoStart: true).IsIndeterminate();
var kernelResponse = await kernel.RunAsync(output, token, pullRequestPlugin["GenerateCommitMessage"]);
var kernelResponse = await kernel.InvokeAsync(pullRequestPlugin["GenerateCommitMessage"], output, token);
task.StopTask();

var result = kernelResponse.GetValue<string>() ?? string.Empty;
await ClipboardService.SetTextAsync(result);
return result;
var result = kernelResponse.GetValue<KernelArguments>();
var message = result?[KernelArguments.InputParameterName]?.ToString() ?? string.Empty;
await ClipboardService.SetTextAsync(message);
return message;
});

AnsiConsole.WriteLine(botMessage);
Expand Down
19 changes: 11 additions & 8 deletions apps/SKonsole/Commands/PRCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
using System.Diagnostics;
using Microsoft.Extensions.Logging;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Orchestration;

// using Microsoft.SemanticKernel;
// using Microsoft.SemanticKernel.Orchestration;
using SKonsole.Utils;

namespace SKonsole.Commands;
Expand Down Expand Up @@ -108,9 +110,9 @@ private static async Task RunPullRequestFeedback(CancellationToken token, ILogge

string output = await process.StandardOutput.ReadToEndAsync();

var pullRequestPlugin = kernel.ImportFunctions(new PRPlugin.PullRequestPlugin(kernel));
var pullRequestPlugin = kernel.ImportPluginFromObject(new PRPlugin.PullRequestPlugin(kernel));

var kernelResponse = await kernel.RunAsync(output, token, pullRequestPlugin["GeneratePullRequestFeedback"]);
var kernelResponse = await kernel.InvokeAsync(pullRequestPlugin["GeneratePullRequestFeedback"], output, token);

logger.LogInformation("Pull Request Feedback:\n{result}", kernelResponse.GetValue<string>());
}
Expand All @@ -121,13 +123,14 @@ private static async Task RunPullRequestDescription(CancellationToken token, ILo

var output = await FetchDiff(targetBranch, diffInputFile);

var pullRequestPlugin = kernel.ImportFunctions(new PRPlugin.PullRequestPlugin(kernel));
var pullRequestPlugin = kernel.ImportPluginFromObject(new PRPlugin.PullRequestPlugin(kernel));

var contextVariables = new ContextVariables(output);
contextVariables.Set("outputFormatInstructions", PRPlugin.Utils.FormatInstructionsProvider.GetOutputFormatInstructions(outputFormat));
var contextVariables = new KernelArguments();
contextVariables[KernelArguments.InputParameterName] = output;
contextVariables["outputFormatInstructions"] = PRPlugin.Utils.FormatInstructionsProvider.GetOutputFormatInstructions(outputFormat);

var kernelResponse = await kernel.RunAsync(contextVariables, token, pullRequestPlugin["GeneratePR"]);
logger.LogInformation("Pull Request Description:\n{result}", kernelResponse.GetValue<string>());
var kernelResponse = await kernel.InvokeAsync(pullRequestPlugin["GeneratePR"], contextVariables, token);
logger.LogInformation("Pull Request Description:\n{result}", kernelResponse.GetValue<KernelArguments>()?[KernelArguments.InputParameterName]);

if (!string.IsNullOrEmpty(outputFile))
{
Expand Down
19 changes: 6 additions & 13 deletions apps/SKonsole/Commands/PlannerCommand.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.CommandLine;
using Microsoft.Extensions.Logging;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Planners;
using Microsoft.SemanticKernel.Planning.Handlebars;
using Microsoft.SemanticKernel.Plugins.Web;
using Microsoft.SemanticKernel.Plugins.Web.Bing;
using SKonsole.Plugins;
Expand Down Expand Up @@ -43,23 +43,16 @@ private static async Task RunCreatePlan(CancellationToken token, ILogger logger,
{
var kernel = KernelProvider.Instance.Get();

// Eventually, Kernel will be smarter about what plugins it uses for an ask.
// kernel.ImportFunctions(new EmailPlugin(), "email");
// kernel.ImportFunctions(new GitPlugin(), "git");
// kernel.ImportFunctions(new SearchUrlPlugin(), "url");
// kernel.ImportFunctions(new HttpPlugin(), "http");
// kernel.ImportFunctions(new PRPlugin.PullRequestPlugin(kernel), "PullRequest");

kernel.ImportFunctions(new WriterPlugin(kernel), "writer");
kernel.ImportPluginFromObject(new WriterPlugin(kernel), "writer");
var bingConnector = new BingConnector(Configuration.ConfigVar("BING_API_KEY"));
var bing = new WebSearchEnginePlugin(bingConnector);
var search = kernel.ImportFunctions(bing, "bing");
var search = kernel.ImportPluginFromObject(bing, "bing");

// var planner = new ActionPlanner();
var planner = new SequentialPlanner(kernel);
var plan = await planner.CreatePlanAsync(message);
var planner = new HandlebarsPlanner();
var plan = await planner.CreatePlanAsync(kernel, message, token);

await kernel.RunAsync(plan);
plan.Invoke(kernel, new KernelArguments(), token);
}

private readonly ILogger _logger;
Expand Down
28 changes: 11 additions & 17 deletions apps/SKonsole/Commands/PromptChatCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
using Microsoft.Extensions.Logging;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.AI;
using Microsoft.SemanticKernel.Orchestration;
using Microsoft.SemanticKernel.TemplateEngine;
using Microsoft.SemanticKernel.TemplateEngine.Basic;
using SKonsole.Utils;
using Spectre.Console;

Expand Down Expand Up @@ -47,9 +44,9 @@ private static async Task RunPromptChat(CancellationToken token, ILogger logger)
AI:
";

var promptConfig = new PromptTemplateConfig();
promptConfig.ModelSettings.Add(
new AIRequestSettings()
var chatFunction = kernel.CreateFunctionFromPrompt(
SkPrompt,
new PromptExecutionSettings()
{
ExtensionData = new Dictionary<string, object>()
{
Expand All @@ -58,24 +55,21 @@ private static async Task RunPromptChat(CancellationToken token, ILogger logger)
{ "MaxTokens", 2000 },
{ "StopSequences", new List<string> { "Human:", "AI:" } }
}
}
);
var engine = new BasicPromptTemplateFactory(kernel.LoggerFactory);
var promptTemplate = engine.Create(SkPrompt, promptConfig);
var chatFunction = kernel.RegisterSemanticFunction("PromptBot", "Chat", promptConfig, promptTemplate);
},
"Chat");
await RunChat(kernel, logger, chatFunction);
}

private static async Task RunChat(IKernel kernel, ILogger? logger, ISKFunction chatFunction)
private static async Task RunChat(Kernel kernel, ILogger? logger, KernelFunction chatFunction)
{
AnsiConsole.MarkupLine("[grey]Press Enter twice to send a message.[/]");
AnsiConsole.MarkupLine("[grey]Enter 'exit' to exit.[/]");
var contextVariables = new ContextVariables();
var contextVariables = new KernelArguments();

var history = string.Empty;
contextVariables.Set("history", history);
contextVariables["history"] = history;

var result = await kernel.RunAsync(contextVariables, chatFunction);
var result = await kernel.InvokeAsync(chatFunction, contextVariables);
var botMessage = result.GetValue<string>();
var userMessage = string.Empty;

Expand All @@ -102,7 +96,7 @@ static void HorizontalRule(string title, string style = "white bold")
}

history += $"AI: {botMessage}\nHuman: {userMessage} \n";
contextVariables.Set("history", history);
contextVariables["history"] = history;

botMessage = await AnsiConsole.Progress()
.AutoClear(true)
Expand All @@ -115,7 +109,7 @@ static void HorizontalRule(string title, string style = "white bold")
{
var task = ctx.AddTask("[green]Thinking...[/]", autoStart: true).IsIndeterminate();

var result = await kernel.RunAsync(contextVariables, chatFunction);
var result = await kernel.InvokeAsync(chatFunction, contextVariables);

task.StopTask();
return result.GetValue<string>();
Expand Down
Loading
Loading