Browse Source

Allow null configuration in AbpAIOptions

pull/23533/head
enisn 1 year ago
parent
commit
a14be2f704
No known key found for this signature in database GPG Key ID: A052619F04155D1C
  1. 17
      framework/src/Volo.Abp.AI/Volo/Abp/AI/AbpAIModule.cs
  2. 3
      framework/src/Volo.Abp.AI/Volo/Abp/AI/AbpAIOptions.cs

17
framework/src/Volo.Abp.AI/Volo/Abp/AI/AbpAIModule.cs

@ -1,9 +1,11 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Extensions.AI;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.ChatCompletion;
using Volo.Abp.Modularity;
namespace Volo.Abp.AI;
@ -65,17 +67,26 @@ public class AbpAIModule : AbpModule
builderConfigurer.Action(workspaceConfig.Kernel.Builder!);
}
context.Services.AddKeyedSingleton<Kernel>(
context.Services.AddKeyedTransient<Kernel>(
AbpAIOptions.GetKernelServiceKeyName(workspaceConfig.Name),
(provider, _) => workspaceConfig.Kernel.Builder!.Build());
if (workspaceConfig.Name == DefaultWorkspaceName)
{
context.Services.AddSingleton<Kernel>(sp => sp.GetRequiredKeyedService<Kernel>(
context.Services.AddTransient<Kernel>(sp => sp.GetRequiredKeyedService<Kernel>(
AbpAIOptions.GetKernelServiceKeyName(workspaceConfig.Name)
)
);
}
if (workspaceConfig.ChatClient?.Builder is null)
{
context.Services.AddKeyedTransient<IChatClient>(
AbpAIOptions.GetChatClientServiceKeyName(workspaceConfig.Name),
(sp, _) => sp.GetKeyedService<Kernel>(AbpAIOptions.GetKernelServiceKeyName(workspaceConfig.Name))?
.GetRequiredService<IChatClient>() ?? throw new InvalidOperationException("Kernel or IChatClient not found with workspace name: " + workspaceConfig.Name)
);
}
}
context.Services.TryAddTransient(typeof(IKernelAccessor<>), typeof(TypedKernelAccessor<>));

3
framework/src/Volo.Abp.AI/Volo/Abp/AI/AbpAIOptions.cs

@ -1,6 +1,3 @@
using System;
using System.Collections.Generic;
namespace Volo.Abp.AI;
public class AbpAIOptions

Loading…
Cancel
Save