Browse Source
Merge pull request #24717 from abpframework/10.1-chatclient-fallback
Add fallback to default chat client for unconfigured workspaces
pull/24720/head
Engincan VESKE
2 weeks ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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.GetRequiredKeyedService<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 chatClient = GetRequiredService<IChatClient<NonConfiguredWorkspace>>(); |
|
|
|
|
|
|
|
// Assert
|
|
|
|
chatClient.ShouldNotBeNull(); |
|
|
|
} |
|
|
|
|
|
|
|
public class NonConfiguredWorkspace |
|
|
|
|