Browse Source

Add fallback to default chat client for unconfigured workspaces

Updated ChatClientAccessor and TypedChatClient to fallback to the default chat client if a workspace-specific client is not configured. Adjusted tests to verify that the default chat client is resolved for non-configured workspaces.
pull/24717/head
enisn 2 weeks ago
parent
commit
a1acd9f9ca
No known key found for this signature in database GPG Key ID: A052619F04155D1C
  1. 8
      framework/src/Volo.Abp.AI/Volo/Abp/AI/ChatClientAccessor.cs
  2. 6
      framework/src/Volo.Abp.AI/Volo/Abp/AI/TypedChatClient.cs
  3. 14
      framework/test/Volo.Abp.AI.Tests/Volo/Abp/AI/ChatClientAccessor_Tests.cs

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

@ -29,5 +29,13 @@ public class ChatClientAccessor<TWorkSpace> : IChatClientAccessor<TWorkSpace>
ChatClient = serviceProvider.GetKeyedService<IChatClient>( ChatClient = serviceProvider.GetKeyedService<IChatClient>(
AbpAIWorkspaceOptions.GetChatClientServiceKeyName( AbpAIWorkspaceOptions.GetChatClientServiceKeyName(
WorkspaceNameAttribute.GetWorkspaceName<TWorkSpace>())); WorkspaceNameAttribute.GetWorkspaceName<TWorkSpace>()));
// Fallback to default chat client if not configured for the workspace.
if (ChatClient is null)
{
ChatClient = serviceProvider.GetKeyedService<IChatClient>(
AbpAIWorkspaceOptions.GetChatClientServiceKeyName(
AbpAIModule.DefaultWorkspaceName));
}
} }
} }

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

@ -9,9 +9,13 @@ public class TypedChatClient<TWorkSpace> : DelegatingChatClient, IChatClient<TWo
{ {
public TypedChatClient(IServiceProvider serviceProvider) public TypedChatClient(IServiceProvider serviceProvider)
: base( : base(
serviceProvider.GetRequiredKeyedService<IChatClient>( serviceProvider.GetKeyedService<IChatClient>(
AbpAIWorkspaceOptions.GetChatClientServiceKeyName( AbpAIWorkspaceOptions.GetChatClientServiceKeyName(
WorkspaceNameAttribute.GetWorkspaceName<TWorkSpace>())) WorkspaceNameAttribute.GetWorkspaceName<TWorkSpace>()))
??
serviceProvider.GetRequiredKeyedService<IChatClient>(
AbpAIWorkspaceOptions.GetChatClientServiceKeyName(
AbpAIModule.DefaultWorkspaceName))
) )
{ {
} }

14
framework/test/Volo.Abp.AI.Tests/Volo/Abp/AI/ChatClientAccessor_Tests.cs

@ -31,14 +31,24 @@ public class ChatClientAccessor_Tests : AbpIntegratedTest<AbpAITestModule>
} }
[Fact] [Fact]
public void Should_Resolve_ChatClientAccessor_For_NonConfigured_Workspace() public void Should_Resolve_Default_ChatClient_From_NonConfigured_Workspace_Accessor()
{ {
// Arrange & Act // Arrange & Act
var chatClientAccessor = GetRequiredService<IChatClientAccessor<NonConfiguredWorkspace>>(); var chatClientAccessor = GetRequiredService<IChatClientAccessor<NonConfiguredWorkspace>>();
// Assert // Assert
chatClientAccessor.ShouldNotBeNull(); chatClientAccessor.ShouldNotBeNull();
chatClientAccessor.ChatClient.ShouldBeNull(); chatClientAccessor.ChatClient.ShouldNotBeNull();
}
[Fact]
public void Should_Resolve_Default_ChatClient_For_NonConfigured_Workspace()
{
// Arrange & Act
var chatClientAccessor = GetRequiredService<IChatClient<NonConfiguredWorkspace>>();
// Assert
chatClientAccessor.ShouldNotBeNull();
} }
public class NonConfiguredWorkspace public class NonConfiguredWorkspace

Loading…
Cancel
Save