mirror of
https://github.com/microsoft/semantic-kernel.git
synced 2026-10-12 02:19:06 +00:00
### Motivation and Context In order to keep documentation examples up to date, moving them to a repo where they will actually be built and run. ### Description Move documentation examples from doc repo to this one. ### Contribution Checklist - [ ] 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 😄
34 lines
1.4 KiB
C#
34 lines
1.4 KiB
C#
// Copyright (c) Microsoft. All rights reserved.
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.SemanticKernel;
|
|
using Models;
|
|
|
|
internal static class KernelBuilderExtensions
|
|
{
|
|
/// <summary>
|
|
/// Adds a chat completion service to the list. It can be either an OpenAI or Azure OpenAI backend service.
|
|
/// </summary>
|
|
/// <param name="kernelBuilder"></param>
|
|
/// <param name="kernelSettings"></param>
|
|
/// <exception cref="ArgumentException"></exception>
|
|
internal static IServiceCollection WithChatCompletionService(this IServiceCollection kernelBuilder, KernelSettings kernelSettings)
|
|
{
|
|
switch (kernelSettings.ServiceType.ToUpperInvariant())
|
|
{
|
|
case ServiceTypes.AzureOpenAI:
|
|
kernelBuilder.AddAzureOpenAIChatCompletion(deploymentName: kernelSettings.DeploymentOrModelId, modelId: kernelSettings.DeploymentOrModelId, endpoint: kernelSettings.Endpoint, apiKey: kernelSettings.ApiKey, serviceId: kernelSettings.ServiceId);
|
|
break;
|
|
|
|
case ServiceTypes.OpenAI:
|
|
kernelBuilder.AddOpenAIChatCompletion(modelId: kernelSettings.DeploymentOrModelId, apiKey: kernelSettings.ApiKey, orgId: kernelSettings.OrgId, serviceId: kernelSettings.ServiceId);
|
|
break;
|
|
|
|
default:
|
|
throw new ArgumentException($"Invalid service type value: {kernelSettings.ServiceType}");
|
|
}
|
|
|
|
return kernelBuilder;
|
|
}
|
|
}
|