Browse Source

Implement builders

pull/23533/head
Halil İbrahim Kalkan 1 year ago
parent
commit
b6c3ef1a05
  1. 7
      framework/src/Volo.Abp.AI/Volo/Abp/AI/AbpAIModule.cs
  2. 2
      framework/src/Volo.Abp.AI/Volo/Abp/AI/AbpAIOptions.cs
  3. 8
      framework/src/Volo.Abp.AI/Volo/Abp/AI/BuilderConfigurerList.cs
  4. 3
      framework/src/Volo.Abp.AI/Volo/Abp/AI/ChatClientConfiguration.cs
  5. 16
      framework/src/Volo.Abp.AI/Volo/Abp/AI/ChatClientConfigurationCollection.cs
  6. 14
      framework/src/Volo.Abp.AI/Volo/Abp/AI/NamedAction.cs
  7. 11
      framework/src/Volo.Abp.AI/Volo/Abp/AI/NamedObject.cs
  8. 12
      framework/src/Volo.Abp.AI/Volo/Abp/AI/NamedObjectList.cs

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

@ -9,13 +9,18 @@ public class AbpAIModule : AbpModule
{
var options = context.Services.ExecutePreConfiguredActions<AbpAIOptions>();
foreach (var chatClientConfig in options.ChatClients.GetAll())
foreach (var chatClientConfig in options.ChatClients.Values)
{
if (chatClientConfig.Builder == null)
{
throw new AbpException("ChatClientBuilder is not properly configured. Set the Builder.");
}
foreach (var builderConfigurer in chatClientConfig.BuilderConfigurers)
{
builderConfigurer.Action(chatClientConfig.Builder);
}
context.Services.AddKeyedChatClient(chatClientConfig.Name, provider => chatClientConfig.Builder.Build(provider));
}
}

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

@ -2,5 +2,5 @@ namespace Volo.Abp.AI;
public class AbpAIOptions
{
public ChatClientConfigurationCollection ChatClients { get; } = new();
public ChatClientConfigurationDictionary ChatClients { get; } = new();
}

8
framework/src/Volo.Abp.AI/Volo/Abp/AI/BuilderConfigurerList.cs

@ -0,0 +1,8 @@
using Microsoft.Extensions.AI;
namespace Volo.Abp.AI;
public class BuilderConfigurerList : NamedObjectList<NamedAction<ChatClientBuilder>>
{
}

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

@ -5,7 +5,10 @@ namespace Volo.Abp.AI;
public class ChatClientConfiguration
{
public string Name { get; }
public ChatClientBuilder? Builder { get; set; }
public BuilderConfigurerList BuilderConfigurers { get; } = new();
public ChatClientConfiguration(string name)
{

16
framework/src/Volo.Abp.AI/Volo/Abp/AI/ChatClientConfigurationCollection.cs

@ -1,26 +1,18 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
namespace Volo.Abp.AI;
public class ChatClientConfigurationCollection
public class ChatClientConfigurationDictionary : Dictionary<string, ChatClientConfiguration>
{
private readonly ConcurrentDictionary<string, ChatClientConfiguration> _chatClients = new();
public void Configure(string name, Action<ChatClientConfiguration> configureAction)
{
if (!_chatClients.TryGetValue(name, out var configuration))
if (!this.TryGetValue(name, out var configuration))
{
configuration = new ChatClientConfiguration(name);
_chatClients[name] = configuration;
this[name] = configuration;
}
configureAction(configuration);
}
internal IEnumerable<ChatClientConfiguration> GetAll()
{
return _chatClients.Values;
}
}
}

14
framework/src/Volo.Abp.AI/Volo/Abp/AI/NamedAction.cs

@ -0,0 +1,14 @@
using System;
namespace Volo.Abp.AI;
public class NamedAction<T> : NamedObject //TODO: Move to Core package?
{
public Action<T> Action { get; set; }
public NamedAction(string name, Action<T> action)
: base(name)
{
Action = Check.NotNull(action, nameof(action));
}
}

11
framework/src/Volo.Abp.AI/Volo/Abp/AI/NamedObject.cs

@ -0,0 +1,11 @@
namespace Volo.Abp.AI;
public class NamedObject //TODO: Move to Core package?
{
public string Name { get; }
public NamedObject(string name)
{
Name = Check.NotNullOrWhiteSpace(name, nameof(name));
}
}

12
framework/src/Volo.Abp.AI/Volo/Abp/AI/NamedObjectList.cs

@ -0,0 +1,12 @@
using System.Collections.Generic;
namespace Volo.Abp.AI;
public class NamedObjectList<T> : List<T>
where T : NamedObject
{
public NamedObjectList()
{
}
}
Loading…
Cancel
Save