{
var collection = new ServiceCollection();
//Registering Kernel
collection.AddTransient<IKernel>((serviceProvider) =>
{
return Kernel.Builder
.WithOpenAITextCompletionService("text-davinci-003", key, serviceId: "CodeGenerator")
.Build();
});
//Registering class that uses Kernel to execute a skill
collection.AddTransient<KernelClient>();
var serviceProvider = collection.BuildServiceProvider();
var kernelClient = serviceProvider.GetRequiredService<KernelClient>();
var result = await kernelClient.SummarizeAsync("china");
}
KernelClient:
public sealed class KernelClient
{
private readonly IKernel _kernel;
public KernelClient(IKernel kernel)
{
this._kernel = kernel;
}
public async Task<string> SummarizeAsync(string ask)
{
string folder = Path.Combine( Directory.GetCurrentDirectory(),"Skills");//SkillsPath
var sumSkill = this._kernel.ImportSemanticSkillFromDirectory(folder, "Country");
var result = await this._kernel.RunAsync(ask, sumSkill["Size"]);
return result.Result;
}
}
标签:Kernel,Semantic,KernelClient,kernel,collection,SK,var,public
From: https://www.cnblogs.com/fanfan-90/p/17542024.html