Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static async Task RunAsync()
* function inline if you like.
*/

Kernel kernel = new KernelBuilder()
Kernel kernel = Kernel.CreateBuilder()
.AddOpenAIChatCompletion(
modelId: openAIModelId,
apiKey: openAIApiKey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static async Task RunAsync()
return;
}

Kernel kernel = new KernelBuilder()
Kernel kernel = Kernel.CreateBuilder()
.AddOpenAIChatCompletion(
modelId: openAIModelId,
apiKey: openAIApiKey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static async Task RunAsync()
return;
}

Kernel kernel = new KernelBuilder()
Kernel kernel = Kernel.CreateBuilder()
.AddOpenAIChatCompletion(
modelId: openAIModelId,
apiKey: openAIApiKey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static class Example08_RetryHandler
public static async Task RunAsync()
{
// Create a Kernel with the HttpClient
KernelBuilder builder = new();
IKernelBuilder builder = Kernel.CreateBuilder();
builder.Services.AddLogging(c => c.AddConsole().SetMinimumLevel(LogLevel.Information));
builder.Services.ConfigureHttpClientDefaults(c =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static async Task RunAsync()
{
Console.WriteLine("======== Method Function types ========");

var kernel = new KernelBuilder()
var kernel = Kernel.CreateBuilder()
.AddOpenAIChatCompletion(TestConfiguration.OpenAI.ChatModelId, TestConfiguration.OpenAI.ApiKey)
.Build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static Task RunAsync()
{
Console.WriteLine("======== Describe all plugins and functions ========");

var kernel = new KernelBuilder()
var kernel = Kernel.CreateBuilder()
.AddOpenAIChatCompletion(
modelId: TestConfiguration.OpenAI.ChatModelId,
apiKey: TestConfiguration.OpenAI.ApiKey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ private static async Task GetConversationTopicsAsync()

private static Kernel InitializeKernel()
{
Kernel kernel = new KernelBuilder()
Kernel kernel = Kernel.CreateBuilder()
.AddAzureOpenAIChatCompletion(
TestConfiguration.AzureOpenAI.ChatDeploymentName,
TestConfiguration.AzureOpenAI.ChatModelId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ private static IMemoryStore CreateSampleKustoMemoryStore()

private static async Task RunWithStoreAsync(IMemoryStore memoryStore, CancellationToken cancellationToken)
{
var kernel = new KernelBuilder()
var kernel = Kernel.CreateBuilder()
.AddOpenAIChatCompletion(TestConfiguration.OpenAI.ChatModelId, TestConfiguration.OpenAI.ApiKey)
.AddOpenAITextEmbeddingGeneration(TestConfiguration.OpenAI.EmbeddingModelId, TestConfiguration.OpenAI.ApiKey)
.Build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private static async Task CustomTextGenerationWithSKFunctionAsync()
{
Console.WriteLine("======== Custom LLM - Text Completion - SKFunction ========");

KernelBuilder builder = new();
IKernelBuilder builder = Kernel.CreateBuilder();
builder.Services.AddSingleton(ConsoleLogger.LoggerFactory);
// Add your text generation service as a singleton instance
builder.Services.AddKeyedSingleton<ITextGenerationService>("myService1", new MyTextGenerationService());
Expand Down
4 changes: 2 additions & 2 deletions dotnet/samples/KernelSyntaxExamples/Example18_DallE.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ private static async Task OpenAIDallEAsync()
{
Console.WriteLine("======== OpenAI Dall-E 2 Text To Image ========");

Kernel kernel = new KernelBuilder()
Kernel kernel = Kernel.CreateBuilder()
// Add your text to image service
.AddOpenAITextToImage(TestConfiguration.OpenAI.ApiKey)
// Add your chat completion service
Expand Down Expand Up @@ -90,7 +90,7 @@ public static async Task AzureOpenAIDallEAsync()
{
Console.WriteLine("========Azure OpenAI Dall-E 2 Text To Image ========");

Kernel kernel = new KernelBuilder()
Kernel kernel = Kernel.CreateBuilder()
// Add your text to image service
.AddAzureOpenAITextToImage(TestConfiguration.AzureOpenAI.Endpoint, TestConfiguration.AzureOpenAI.ImageModelId, TestConfiguration.AzureOpenAI.ApiKey)
// Add your chat completion service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ private static async Task RunInferenceApiExampleAsync()
{
Console.WriteLine("\n======== HuggingFace Inference API example ========\n");

Kernel kernel = new KernelBuilder()
Kernel kernel = Kernel.CreateBuilder()
.AddHuggingFaceTextGeneration(
model: TestConfiguration.HuggingFace.ModelId,
apiKey: TestConfiguration.HuggingFace.ApiKey)
Expand Down Expand Up @@ -57,7 +57,7 @@ private static async Task RunLlamaExampleAsync()
// HuggingFace local HTTP server endpoint
const string Endpoint = "http://localhost:5000/completions";

Kernel kernel = new KernelBuilder()
Kernel kernel = Kernel.CreateBuilder()
.AddHuggingFaceTextGeneration(
model: Model,
endpoint: Endpoint,
Expand Down
2 changes: 1 addition & 1 deletion dotnet/samples/KernelSyntaxExamples/Example26_AADAuth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static async Task RunAsync()
ExcludeAzurePowerShellCredential = true
};

Kernel kernel = new KernelBuilder()
Kernel kernel = Kernel.CreateBuilder()
// Add Azure OpenAI chat completion service using DefaultAzureCredential AAD auth
.AddAzureOpenAIChatCompletion(
TestConfiguration.AzureOpenAI.ChatDeploymentName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static async Task RunAsync()
{
Console.WriteLine("======== Using Chat GPT model for text generation ========");

Kernel kernel = new KernelBuilder()
Kernel kernel = Kernel.CreateBuilder()
.AddAzureOpenAIChatCompletion(TestConfiguration.AzureOpenAI.ChatDeploymentName, TestConfiguration.AzureOpenAI.ChatModelId, TestConfiguration.AzureOpenAI.Endpoint, TestConfiguration.AzureOpenAI.ApiKey)
.Build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static async Task RunAsync()
var selectedText = EmbeddedResource.Read("30-user-context.txt");
var userPromptTemplate = EmbeddedResource.Read("30-user-prompt.txt");

Kernel kernel = new KernelBuilder()
Kernel kernel = Kernel.CreateBuilder()
.AddOpenAIChatCompletion(TestConfiguration.OpenAI.ChatModelId, TestConfiguration.OpenAI.ApiKey, serviceId: "chat")
.Build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static Task RunAsync()
/// </summary>
private static void UseDefaultHttpClient()
{
var kernel = new KernelBuilder()
var kernel = Kernel.CreateBuilder()
.AddOpenAIChatCompletion(
modelId: TestConfiguration.OpenAI.ChatModelId,
apiKey: TestConfiguration.OpenAI.ApiKey) // If you need to use the default HttpClient from the SK SDK, simply omit the argument for the httpMessageInvoker parameter.
Expand All @@ -46,7 +46,7 @@ private static void UseCustomHttpClient()
using var httpClient = new HttpClient();

// If you need to use a custom HttpClient, simply pass it as an argument for the httpClient parameter.
var kernel = new KernelBuilder()
var kernel = Kernel.CreateBuilder()
.AddOpenAIChatCompletion(
modelId: TestConfiguration.OpenAI.ModelId,
apiKey: TestConfiguration.OpenAI.ApiKey,
Expand All @@ -67,7 +67,7 @@ private static void UseBasicRegistrationWithHttpClientFactory()
{
var factory = sp.GetRequiredService<IHttpClientFactory>();

return new KernelBuilder()
return Kernel.CreateBuilder()
.AddOpenAIChatCompletion(
modelId: TestConfiguration.OpenAI.ChatModelId,
apiKey: TestConfiguration.OpenAI.ApiKey,
Expand Down Expand Up @@ -96,7 +96,7 @@ private static void UseNamedRegistrationWitHttpClientFactory()
{
var factory = sp.GetRequiredService<IHttpClientFactory>();

return new KernelBuilder()
return Kernel.CreateBuilder()
.AddOpenAIChatCompletion(
modelId: TestConfiguration.OpenAI.ChatModelId,
apiKey: TestConfiguration.OpenAI.ApiKey,
Expand Down
10 changes: 5 additions & 5 deletions dotnet/samples/KernelSyntaxExamples/Example42_KernelBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// ==========================================================================================================
// The easier way to instantiate the Semantic Kernel is to use KernelBuilder.
// You can access the builder using new KernelBuilder().
// You can access the builder using Kernel.CreateBuilder().

#pragma warning disable CA1852

Expand All @@ -26,26 +26,26 @@ public static Task RunAsync()

// KernelBuilder provides a simple way to configure a Kernel. This constructs a kernel
// with logging and an Azure OpenAI chat completion service configured.
Kernel kernel1 = new KernelBuilder()
Kernel kernel1 = Kernel.CreateBuilder()
.AddAzureOpenAIChatCompletion(azureOpenAIChatDeploymentName, azureOpenAIChatModelId, azureOpenAIEndpoint, azureOpenAIKey)
.Build();

// For greater flexibility and to incorporate arbitrary services, KernelBuilder.Services
// provides direct access to an underlying IServiceCollection.
KernelBuilder builder = new();
IKernelBuilder builder = Kernel.CreateBuilder();
builder.Services.AddLogging(c => c.AddConsole().SetMinimumLevel(LogLevel.Information))
.AddHttpClient()
.AddAzureOpenAIChatCompletion(azureOpenAIChatDeploymentName, azureOpenAIChatModelId, azureOpenAIEndpoint, azureOpenAIKey);
Kernel kernel2 = builder.Build();

// Plugins may also be configured via the corresponding Plugins property.
builder = new KernelBuilder();
builder = Kernel.CreateBuilder();
builder.Plugins.AddFromType<HttpPlugin>();
Kernel kernel3 = builder.Build();

// Every call to KernelBuilder.Build creates a new Kernel instance, with a new service provider
// and a new plugin collection.
builder = new KernelBuilder();
builder = Kernel.CreateBuilder();
Debug.Assert(!ReferenceEquals(builder.Build(), builder.Build()));

// KernelBuilder provides a convenient API for creating Kernel instances. However, it is just a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static async Task RunAsync()
{
Console.WriteLine("======== Inline Function Definition + Result ========");

Kernel kernel = new KernelBuilder()
Kernel kernel = Kernel.CreateBuilder()
.AddOpenAIChatCompletion(
modelId: TestConfiguration.OpenAI.ChatModelId,
apiKey: TestConfiguration.OpenAI.ApiKey)
Expand Down Expand Up @@ -47,7 +47,7 @@ public static async Task RunAsync()
Console.WriteLine();

// Getting the error details
kernel = new KernelBuilder()
kernel = Kernel.CreateBuilder()
.AddOpenAIChatCompletion(TestConfiguration.OpenAI.ChatModelId, "Invalid Key")
.Build();
var errorFunction = kernel.CreateFunctionFromPrompt(FunctionDefinition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static async Task RunAsync()
public static async Task GroundednessCheckingAsync()
{
Console.WriteLine("\n======== Groundedness Checks ========");
var kernel = new KernelBuilder()
var kernel = Kernel.CreateBuilder()
.AddAzureOpenAIChatCompletion(
TestConfiguration.AzureOpenAI.ChatDeploymentName,
TestConfiguration.AzureOpenAI.ChatModelId,
Expand Down Expand Up @@ -126,7 +126,7 @@ which are not grounded in the original.

Console.WriteLine("\n======== Planning - Groundedness Checks ========");

var kernel = new KernelBuilder()
var kernel = Kernel.CreateBuilder()
.AddAzureOpenAIChatCompletion(
TestConfiguration.AzureOpenAI.ChatDeploymentName,
TestConfiguration.AzureOpenAI.ChatModelId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static async Task RunAsync()
};
var openAIClient = new OpenAIClient(apimUri, new BearerTokenCredential(accessToken), clientOptions);

KernelBuilder builder = new();
IKernelBuilder builder = Kernel.CreateBuilder();
builder.Services.AddLogging(c => c.SetMinimumLevel(LogLevel.Warning).AddConsole());
builder.AddAzureOpenAIChatCompletion(TestConfiguration.AzureOpenAI.ChatDeploymentName, TestConfiguration.AzureOpenAI.ChatModelId, openAIClient);
Kernel kernel = builder.Build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private static async Task ExampleWithKernelAsync()

var completionWithDataConfig = GetCompletionWithDataConfig();

Kernel kernel = new KernelBuilder()
Kernel kernel = Kernel.CreateBuilder()
.AddAzureOpenAIChatCompletion(config: completionWithDataConfig)
.Build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static async Task RunAsync()
return;
}

KernelBuilder builder = new();
IKernelBuilder builder = Kernel.CreateBuilder();
builder.Services.AddLogging(c => c.AddConsole());
builder.AddAzureOpenAIChatCompletion(
deploymentName: deploymentName,
Expand Down
10 changes: 5 additions & 5 deletions dotnet/samples/KernelSyntaxExamples/Example57_KernelHooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private static async Task GetUsageAsync()
{
Console.WriteLine("\n======== Get Usage Data ========\n");

Kernel kernel = new KernelBuilder()
Kernel kernel = Kernel.CreateBuilder()
.AddOpenAIChatCompletion(
modelId: s_openAIModelId!,
apiKey: s_openAIApiKey!)
Expand Down Expand Up @@ -87,7 +87,7 @@ private static async Task GetRenderedPromptAsync()
{
Console.WriteLine("\n======== Get Rendered Prompt ========\n");

Kernel kernel = new KernelBuilder()
Kernel kernel = Kernel.CreateBuilder()
.AddOpenAIChatCompletion(
modelId: s_openAIModelId!,
apiKey: s_openAIApiKey!)
Expand Down Expand Up @@ -126,7 +126,7 @@ private static async Task ChangingResultAsync()
{
Console.WriteLine("\n======== Changing/Filtering Function Result ========\n");

Kernel kernel = new KernelBuilder()
Kernel kernel = Kernel.CreateBuilder()
.AddOpenAIChatCompletion(
modelId: s_openAIModelId!,
apiKey: s_openAIApiKey!)
Expand Down Expand Up @@ -160,7 +160,7 @@ private static async Task BeforeInvokeCancellationAsync()
{
Console.WriteLine("\n======== Cancelling Pipeline Execution - Invoking event ========\n");

Kernel kernel = new KernelBuilder()
Kernel kernel = Kernel.CreateBuilder()
.AddOpenAIChatCompletion(
modelId: s_openAIModelId!,
apiKey: s_openAIApiKey!)
Expand Down Expand Up @@ -195,7 +195,7 @@ private static async Task AfterInvokeCancellationAsync()
{
Console.WriteLine("\n======== Cancelling Pipeline Execution - Invoked event ========\n");

Kernel kernel = new KernelBuilder()
Kernel kernel = Kernel.CreateBuilder()
.AddOpenAIChatCompletion(
modelId: s_openAIModelId!,
apiKey: s_openAIApiKey!)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static async Task RunAsync()
return;
}

Kernel kernel = new KernelBuilder()
Kernel kernel = Kernel.CreateBuilder()
.AddAzureOpenAIChatCompletion(
deploymentName: chatDeploymentName,
modelId: chatModelId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static class Example59_OpenAIFunctionCalling
public static async Task RunAsync()
{
// Create kernel with chat completions service and plugins
KernelBuilder builder = new();
IKernelBuilder builder = Kernel.CreateBuilder();
builder.Plugins.AddFromType<TimePlugin>();
builder.Plugins.AddFromType<WidgetPlugin>();
builder.AddOpenAIChatCompletion(TestConfiguration.OpenAI.ChatModelId, TestConfiguration.OpenAI.ApiKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static async Task RunAsync()
return;
}

Kernel kernel = new KernelBuilder()
Kernel kernel = Kernel.CreateBuilder()
.AddAzureOpenAIChatCompletion(
deploymentName: azureDeploymentName,
endpoint: azureEndpoint,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static async Task RunAsync()
}

// Build a kernel with multiple chat completion services
var builder = new KernelBuilder()
var builder = Kernel.CreateBuilder()
.AddAzureOpenAIChatCompletion(
deploymentName: azureDeploymentName,
endpoint: azureEndpoint,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static async Task RunAsync()
<message role=""system"">Respond with JSON.</message>
";

var kernel = new KernelBuilder()
var kernel = Kernel.CreateBuilder()
.AddOpenAIChatCompletion(
modelId: TestConfiguration.OpenAI.ChatModelId,
apiKey: TestConfiguration.OpenAI.ApiKey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ private static FlowOrchestratorConfig GetOrchestratorConfig()

private static KernelBuilder GetKernelBuilder(ILoggerFactory loggerFactory)
{
var builder = new KernelBuilder();
var builder = Kernel.CreateBuilder();

return builder
.WithAzureOpenAIChatCompletion(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static async Task RunAsync()
return;
}

Kernel kernel = new KernelBuilder()
Kernel kernel = Kernel.CreateBuilder()
.AddAzureOpenAIChatCompletion(
deploymentName: chatDeploymentName,
modelId: chatModelId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private static async Task RunSampleAsync(string goal, bool shouldPrintPrompt = f
return;
}

var kernel = new KernelBuilder()
var kernel = Kernel.CreateBuilder()
.AddAzureOpenAIChatCompletion(
deploymentName: chatDeploymentName,
modelId: chatModelId,
Expand Down
Loading