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
No known key found for this signature in database
GPG Key ID: A052619F04155D1C
3 changed files with
25 additions and
3 deletions
framework/src/Volo.Abp.AI/Volo/Abp/AI/ChatClientAccessor.cs
framework/src/Volo.Abp.AI/Volo/Abp/AI/TypedChatClient.cs
framework/test/Volo.Abp.AI.Tests/Volo/Abp/AI/ChatClientAccessor_Tests.cs
@ -29,5 +29,13 @@ public class ChatClientAccessor<TWorkSpace> : IChatClientAccessor<TWorkSpace>
ChatClient = serviceProvider . GetKeyedService < IChatClient > (
AbpAIWorkspaceOptions . GetChatClientServiceKeyName (
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 ) ) ;
}
}
}
@ -9,9 +9,13 @@ public class TypedChatClient<TWorkSpace> : DelegatingChatClient, IChatClient<TWo
{
public TypedChatClient ( IServiceProvider serviceProvider )
: base (
serviceProvider . GetRequired KeyedService < IChatClient > (
serviceProvider . GetKeyedService < IChatClient > (
AbpAIWorkspaceOptions . GetChatClientServiceKeyName (
WorkspaceNameAttribute . GetWorkspaceName < TWorkSpace > ( ) ) )
? ?
serviceProvider . GetRequiredKeyedService < IChatClient > (
AbpAIWorkspaceOptions . GetChatClientServiceKeyName (
AbpAIModule . DefaultWorkspaceName ) )
)
{
}
@ -31,14 +31,24 @@ public class ChatClientAccessor_Tests : AbpIntegratedTest<AbpAITestModule>
}
[Fact]
public void Should_Resolve_ChatClientAccessor_For_NonConfigured_Workspace ( )
public void Should_Resolve_Default_ChatClient_From_NonConfigured_Workspace_Accessor ( )
{
// Arrange & Act
var chatClientAccessor = GetRequiredService < IChatClientAccessor < NonConfiguredWorkspace > > ( ) ;
// Assert
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