88 lines
3.5 KiB
C#
88 lines
3.5 KiB
C#
using Alipay.EasySDK.Factory;
|
|
using Alipay.EasySDK.Kernel;
|
|
using Alipay.EasySDK.Kernel.Util;
|
|
using Alipay.EasySDK.Payment.FaceToFace.Models;
|
|
using Dm.util;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Volo.Abp.Domain;
|
|
using Yi.Framework.AiHub.Domain.AiGateWay;
|
|
using Yi.Framework.AiHub.Domain.AiGateWay.Impl.ThorAzureDatabricks.Chats;
|
|
using Yi.Framework.AiHub.Domain.AiGateWay.Impl.ThorAzureOpenAI.Chats;
|
|
using Yi.Framework.AiHub.Domain.AiGateWay.Impl.ThorAzureOpenAI.Images;
|
|
using Yi.Framework.AiHub.Domain.AiGateWay.Impl.ThorDeepSeek.Chats;
|
|
using Yi.Framework.AiHub.Domain.AiGateWay.Impl.ThorSiliconFlow.Embeddings;
|
|
using Yi.Framework.AiHub.Domain.Shared;
|
|
using Yi.Framework.AiHub.Domain.Shared.Dtos.OpenAi;
|
|
using Yi.Framework.Mapster;
|
|
|
|
namespace Yi.Framework.AiHub.Domain
|
|
{
|
|
[DependsOn(
|
|
typeof(YiFrameworkAiHubDomainSharedModule),
|
|
typeof(YiFrameworkMapsterModule),
|
|
typeof(AbpDddDomainModule)
|
|
)]
|
|
public class YiFrameworkAiHubDomainModule : AbpModule
|
|
{
|
|
public override void ConfigureServices(ServiceConfigurationContext context)
|
|
{
|
|
var configuration = context.Services.GetConfiguration();
|
|
var services = context.Services;
|
|
|
|
// Configure<AiGateWayOptions>(configuration.GetSection("AiGateWay"));
|
|
services.AddKeyedTransient<IChatCompletionService, AzureOpenAiChatCompletionCompletionsService>(
|
|
nameof(AzureOpenAiChatCompletionCompletionsService));
|
|
services.AddKeyedTransient<IChatCompletionService, AzureDatabricksChatCompletionsService>(
|
|
nameof(AzureDatabricksChatCompletionsService));
|
|
services.AddKeyedTransient<IChatCompletionService, DeepSeekChatCompletionsService>(
|
|
nameof(DeepSeekChatCompletionsService));
|
|
|
|
services.AddKeyedTransient<IImageService, AzureOpenAIServiceImageService>(
|
|
nameof(AzureOpenAIServiceImageService));
|
|
|
|
|
|
services.AddKeyedTransient<ITextEmbeddingService, SiliconFlowTextEmbeddingService>(
|
|
nameof(SiliconFlowTextEmbeddingService));
|
|
|
|
//ai模型特殊性兼容处理
|
|
Configure<SpecialCompatibleOptions>(options =>
|
|
{
|
|
options.Handles.Add(request =>
|
|
{
|
|
if (request.Model == "o1")
|
|
{
|
|
request.Temperature = null;
|
|
}
|
|
});
|
|
options.Handles.Add(request =>
|
|
{
|
|
if (request.Model.StartsWith("o3-mini") || request.Model.StartsWith("o4-mini"))
|
|
{
|
|
request.MaxCompletionTokens = request.MaxTokens;
|
|
request.MaxTokens = null;
|
|
request.Temperature = null;
|
|
}
|
|
});
|
|
options.Handles.Add(request =>
|
|
{
|
|
if (request.Stream == true)
|
|
{
|
|
request.StreamOptions = new ThorStreamOptions()
|
|
{
|
|
IncludeUsage = true
|
|
};
|
|
}
|
|
});
|
|
});
|
|
|
|
//配置支付宝支付
|
|
var config = configuration.GetSection("Alipay").Get<Config>();
|
|
Factory.SetOptions(config);
|
|
}
|
|
|
|
public override async Task OnApplicationInitializationAsync(ApplicationInitializationContext context)
|
|
{
|
|
}
|
|
}
|
|
} |