Browse Source

Refactored AI services

pull/23533/head
Halil İbrahim Kalkan 1 year ago
parent
commit
79260da70f
  1. 14
      framework/src/Volo.Abp.AI/Volo/Abp/AI/AbpAIModule.cs
  2. 2
      framework/src/Volo.Abp.AI/Volo/Abp/AI/AbpAIOptions.cs
  3. 2
      framework/src/Volo.Abp.AI/Volo/Abp/AI/ChatClientConfiguration.cs
  4. 2
      framework/src/Volo.Abp.AI/Volo/Abp/AI/TypedChatClient.cs
  5. 0
      framework/src/Volo.Abp.Core/Volo/Abp/Collections/NamedActionList.cs
  6. 0
      framework/src/Volo.Abp.Core/Volo/Abp/Collections/NamedObjectList.cs
  7. 2
      framework/src/Volo.Abp.Core/Volo/Abp/NamedAction.cs
  8. 4
      framework/src/Volo.Abp.Core/Volo/Abp/NamedObject.cs

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

@ -4,25 +4,17 @@ using Volo.Abp.Modularity;
namespace Volo.Abp.AI;
/* TODO:
* - A factory service (IChatClientFactory) to create a IChatClient by given name
* (currently, we are using a keyed service collection to resolve the IChatClient)
* - We can also inject typed clients, like ICommentSummaryChatClient or IChatClient<CommentSummaryChatClient> (more practical to resolve)
* In this way, we can write specific extension methods to some clients, for prompts.
* -
*/
public class AbpAIModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
var options = context.Services.ExecutePreConfiguredActions<AbpAIChatClientOptions>();
var options = context.Services.ExecutePreConfiguredActions<AbpAIOptions>();
foreach (var chatClientConfig in options.ChatClients.Values)
{
if (chatClientConfig.Builder == null)
{
throw new AbpException("ChatClientBuilder is not properly configured. Set the Builder.");
throw new AbpException("ChatClientBuilder is not properly configured. Set the Builder property.");
}
foreach (var builderConfigurer in chatClientConfig.BuilderConfigurers)
@ -31,7 +23,7 @@ public class AbpAIModule : AbpModule
}
context.Services.AddKeyedChatClient(
AbpAIChatClientOptions.GetChatClientServiceKeyName(chatClientConfig.Name),
AbpAIOptions.GetChatClientServiceKeyName(chatClientConfig.Name),
provider => chatClientConfig.Builder.Build(provider)
);
}

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

@ -1,6 +1,6 @@
namespace Volo.Abp.AI;
public class AbpAIChatClientOptions
public class AbpAIOptions
{
public const string ChatClientServiceKeyNamePrefix = "Abp.AI.ChatClient_";

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

@ -10,6 +10,8 @@ public class ChatClientConfiguration
public ChatClientBuilder? Builder { get; set; }
public BuilderConfigurerList BuilderConfigurers { get; }
// TODO: Base chat client (for inheriting a chat client configuration from some other one)
public ChatClientConfiguration(string name)
{

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

@ -10,7 +10,7 @@ public class TypedChatClient<T> : DelegatingChatClient, IChatClient<T>
public TypedChatClient(IServiceProvider serviceProvider)
: base(
serviceProvider.GetRequiredKeyedService<IChatClient>(
AbpAIChatClientOptions.GetChatClientServiceKeyName(
AbpAIOptions.GetChatClientServiceKeyName(
ChatClientNameAttribute.GetChatClientName<T>()))
)
{

0
framework/src/Volo.Abp.AI/Volo/Abp/AI/NamedActionList.cs → framework/src/Volo.Abp.Core/Volo/Abp/Collections/NamedActionList.cs

0
framework/src/Volo.Abp.AI/Volo/Abp/AI/NamedObjectList.cs → framework/src/Volo.Abp.Core/Volo/Abp/Collections/NamedObjectList.cs

2
framework/src/Volo.Abp.AI/Volo/Abp/AI/NamedAction.cs → framework/src/Volo.Abp.Core/Volo/Abp/NamedAction.cs

@ -1,6 +1,6 @@
using System;
namespace Volo.Abp.AI;
namespace Volo.Abp;
public class NamedAction<T> : NamedObject
{

4
framework/src/Volo.Abp.AI/Volo/Abp/AI/NamedObject.cs → framework/src/Volo.Abp.Core/Volo/Abp/NamedObject.cs

@ -1,6 +1,6 @@
namespace Volo.Abp.AI;
namespace Volo.Abp;
public class NamedObject //TODO: Move to Core package?
public class NamedObject
{
public string Name { get; }
Loading…
Cancel
Save