feat: ai完成stock模块搭建

This commit is contained in:
橙子
2025-03-08 22:14:26 +08:00
parent 337088c908
commit 82865631fc
26 changed files with 1044 additions and 294 deletions

View File

@@ -1,14 +1,18 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.SemanticKernel;
using Volo.Abp.Caching;
using Volo.Abp.Domain;
using Yi.Framework.Stock.Domain.Shared;
using Yi.Framework.Mapster;
using Yi.Framework.Stock.Domain.Managers;
using Yi.Framework.Stock.Domain.Managers.SemanticKernel;
using Yi.Framework.Stock.Domain.Managers.SemanticKernel.Plugins;
using Yi.Framework.Stock.Domain.Shared;
namespace Yi.Framework.Stock.Domain
{
[DependsOn(
typeof(YiFrameworkStockDomainSharedModule),
typeof(YiFrameworkMapsterModule),
typeof(AbpDddDomainModule),
typeof(AbpCachingModule)
@@ -17,13 +21,30 @@ namespace Yi.Framework.Stock.Domain
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
Configure<SemanticKernelOptions>((options)=>{
options.Endpoint = "https://api.token-ai.cn/v1";
options.ApiKey = "sk-V6OqmrloXDAiTM2FWoisGgaop72Ngr0fXAnXL8";
options.ModelId = "gpt-4o-mini";
options.MaxTokens = 1000;
options.PluginsDirectoryPath = "plugins";
});
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>();
services.AddKernel()
.AddOpenAIChatCompletion(
modelId: options.ModelId,
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>();
}
}
}