Files
Yi.Admin/Yi.Abp.Net8/module/ai-stock/Yi.Framework.Stock.Domain/YiFrameworkStockDomainModule.cs

51 lines
2.0 KiB
C#
Raw Normal View History

2025-03-08 22:14:26 +08:00
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.SemanticKernel;
2025-03-01 00:06:56 +08:00
using Volo.Abp.Caching;
using Volo.Abp.Domain;
using Yi.Framework.Mapster;
2025-03-07 00:35:32 +08:00
using Yi.Framework.Stock.Domain.Managers;
2025-03-08 22:14:26 +08:00
using Yi.Framework.Stock.Domain.Managers.SemanticKernel;
using Yi.Framework.Stock.Domain.Managers.SemanticKernel.Plugins;
using Yi.Framework.Stock.Domain.Shared;
2025-03-01 00:06:56 +08:00
namespace Yi.Framework.Stock.Domain
{
[DependsOn(
typeof(YiFrameworkStockDomainSharedModule),
typeof(YiFrameworkMapsterModule),
typeof(AbpDddDomainModule),
typeof(AbpCachingModule)
)]
public class YiFrameworkStockDomainModule : AbpModule
{
2025-03-07 00:35:32 +08:00
public override void ConfigureServices(ServiceConfigurationContext context)
{
2025-03-08 22:14:26 +08:00
var configuration = context.Services.GetConfiguration();
var services = context.Services;
// 配置绑定
var semanticKernelSection = configuration.GetSection("SemanticKernel");
services.Configure<SemanticKernelOptions>(configuration.GetSection("SemanticKernel"));
services.AddHttpClient();
#pragma warning disable SKEXP0010
// 从配置中获取值
var options = semanticKernelSection.Get<SemanticKernelOptions>();
2025-03-21 18:24:59 +08:00
//股市优先使用第一个ai模型
2025-03-08 22:14:26 +08:00
services.AddKernel()
.AddOpenAIChatCompletion(
2025-03-21 18:24:59 +08:00
modelId: options.ModelIds.FirstOrDefault(),
2025-03-08 22:14:26 +08:00
endpoint: new Uri(options.Endpoint),
apiKey: options.ApiKey);
#pragma warning restore SKEXP0010
// 添加插件
services.AddSingleton<KernelPlugin>(sp => KernelPluginFactory.CreateFromType<NewsPlugins>(serviceProvider: sp));
services.AddSingleton<KernelPlugin>(sp => KernelPluginFactory.CreateFromType<StockPlugins>(serviceProvider: sp));
// 注册NewsManager
services.AddTransient<NewsManager>();
2025-03-07 00:35:32 +08:00
}
2025-03-01 00:06:56 +08:00
}
}