mirror of
https://github.com/microsoft/semantic-kernel.git
synced 2026-10-12 02:19:06 +00:00
### Motivation, Context and Description This PR introduces several changes aimed to simplify the kernel and enhancing its extensibility for AI services management. The changes include the following: 1. Kernel simplification and extensibility: The code responsible for AI services management, such as registration and resolution, has been moved out of the Kernel and KernelConfig classes into a new class called AIServiceProvider. This restructuring promotes the principle of Single Responsibility, ensuring that each class has a clear and focused purpose. 2. Hosting apps customization: With the introduction of the AIServiceProvider, hosting applications now have the flexibility to provide their own implementation of the provider if needed. This promotes extensibility, allowing the hosting apps to tailor the AI service management according to their specific requirements. 3. AI services registration improvements: A new method called WithAiService has been added, which enables the registration of any new AI service that is not currently supported. 4. Improved kernel builder interface: The Add* methods for AI services registration have been moved from the KernelConfig class to the KernelBuilder. This change aligns the interface with other KernelBilder methods, such as WithLogger and WithMemory, creating a more cohesive and intuitive kernel builder interface. --------- Co-authored-by: Shawn Callegari <[email protected]> Co-authored-by: Lee Miller <[email protected]>
38 lines
1.1 KiB
C#
38 lines
1.1 KiB
C#
// Copyright (c) Microsoft. All rights reserved.
|
|
|
|
using System;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.SemanticKernel;
|
|
using RepoUtils;
|
|
|
|
/**
|
|
* This example shows how to use GPT3.5 Chat model for prompts and semantic functions.
|
|
*/
|
|
|
|
// ReSharper disable once InconsistentNaming
|
|
public static class Example27_SemanticFunctionsUsingChatGPT
|
|
{
|
|
public static async Task RunAsync()
|
|
{
|
|
Console.WriteLine("======== Using Chat GPT model for text completion ========");
|
|
|
|
IKernel kernel = new KernelBuilder()
|
|
.WithLogger(ConsoleLogger.Log)
|
|
// Note: we use Chat Completion and GPT 3.5 Turbo
|
|
.WithAzureChatCompletionService("gpt-35-turbo", "https://....openai.azure.com/", "...API KEY...")
|
|
.Build();
|
|
|
|
var func = kernel.CreateSemanticFunction(
|
|
"List the two planets closest to '{{$input}}', excluding moons, using bullet points.");
|
|
|
|
var result = await func.InvokeAsync("Jupiter");
|
|
Console.WriteLine(result);
|
|
|
|
/*
|
|
Output:
|
|
- Saturn
|
|
- Uranus
|
|
*/
|
|
}
|
|
}
|