37 lines
1.4 KiB
C#
37 lines
1.4 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.SemanticKernel;
|
|
using Yi.Framework.Core.Options;
|
|
|
|
namespace Yi.Framework.SemanticKernel;
|
|
|
|
public class YiFrameworkSemanticKernelModule : AbpModule
|
|
{
|
|
public override void ConfigureServices(ServiceConfigurationContext context)
|
|
{
|
|
var configuration = context.Services.GetConfiguration();
|
|
var services = context.Services;
|
|
|
|
// 配置绑定
|
|
var semanticKernelSection = configuration.GetSection("SemanticKernel");
|
|
services.Configure<SemanticKernelOptions>(configuration.GetSection("SemanticKernel"));
|
|
// 从配置中获取值
|
|
var options = semanticKernelSection.Get<SemanticKernelOptions>();
|
|
foreach (var optionsModelId in options.ModelIds)
|
|
{
|
|
services.AddKernel()
|
|
.AddAzureOpenAIChatCompletion(
|
|
deploymentName: optionsModelId,
|
|
endpoint: options.Endpoint,
|
|
apiKey: options.ApiKey,
|
|
serviceId: optionsModelId,
|
|
modelId: optionsModelId);
|
|
|
|
// .AddOpenAIChatCompletion(
|
|
// serviceId: optionsModelId,
|
|
// modelId: optionsModelId,
|
|
// endpoint: new Uri(options.Endpoint),
|
|
// apiKey: options.ApiKey);
|
|
}
|
|
}
|
|
} |