mirror of https://github.com/abpframework/abp.git
4 changed files with 62 additions and 2 deletions
@ -1,8 +1,22 @@ |
|||||
using Volo.Abp.Modularity; |
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Volo.Abp.Modularity; |
||||
|
|
||||
namespace Volo.Abp.AI; |
namespace Volo.Abp.AI; |
||||
|
|
||||
public class AbpAIModule : AbpModule |
public class AbpAIModule : AbpModule |
||||
{ |
{ |
||||
|
public override void ConfigureServices(ServiceConfigurationContext context) |
||||
|
{ |
||||
|
var options = context.Services.ExecutePreConfiguredActions<AbpAIOptions>(); |
||||
|
|
||||
|
foreach (var chatClientConfig in options.ChatClients.GetAll()) |
||||
|
{ |
||||
|
if (chatClientConfig.Builder == null) |
||||
|
{ |
||||
|
throw new AbpException("ChatClientBuilder is not properly configured. Set the Builder."); |
||||
|
} |
||||
|
|
||||
|
context.Services.AddKeyedChatClient(chatClientConfig.Name, provider => chatClientConfig.Builder.Build(provider)); |
||||
|
} |
||||
|
} |
||||
} |
} |
||||
@ -0,0 +1,6 @@ |
|||||
|
namespace Volo.Abp.AI; |
||||
|
|
||||
|
public class AbpAIOptions |
||||
|
{ |
||||
|
public ChatClientConfigurationCollection ChatClients { get; } = new(); |
||||
|
} |
||||
@ -0,0 +1,14 @@ |
|||||
|
using Microsoft.Extensions.AI; |
||||
|
|
||||
|
namespace Volo.Abp.AI; |
||||
|
|
||||
|
public class ChatClientConfiguration |
||||
|
{ |
||||
|
public string Name { get; } |
||||
|
public ChatClientBuilder? Builder { get; set; } |
||||
|
|
||||
|
public ChatClientConfiguration(string name) |
||||
|
{ |
||||
|
Name = name; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,26 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Concurrent; |
||||
|
using System.Collections.Generic; |
||||
|
|
||||
|
namespace Volo.Abp.AI; |
||||
|
|
||||
|
public class ChatClientConfigurationCollection |
||||
|
{ |
||||
|
private readonly ConcurrentDictionary<string, ChatClientConfiguration> _chatClients = new(); |
||||
|
|
||||
|
public void Configure(string name, Action<ChatClientConfiguration> configureAction) |
||||
|
{ |
||||
|
if (!_chatClients.TryGetValue(name, out var configuration)) |
||||
|
{ |
||||
|
configuration = new ChatClientConfiguration(name); |
||||
|
_chatClients[name] = configuration; |
||||
|
} |
||||
|
|
||||
|
configureAction(configuration); |
||||
|
} |
||||
|
|
||||
|
internal IEnumerable<ChatClientConfiguration> GetAll() |
||||
|
{ |
||||
|
return _chatClients.Values; |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue