Browse Source

Register ChatClientAccessor and add related tests

Added transient registration for IChatClientAccessor<> in AbpAIModule. Updated ChatClientAccessor to implement ITransientDependency and removed TryRegister from dependency attribute. Introduced unit tests for ChatClientAccessor resolution and behavior. Adjusted MockChatClient's StreamingResponseParts constant for test consistency.
pull/23895/head
Enis Necipoglu 4 months ago
parent
commit
d9463151cd
No known key found for this signature in database GPG Key ID: 1EC55E13241E1680
  1. 1
      framework/src/Volo.Abp.AI/Volo/Abp/AI/AbpAIModule.cs
  2. 6
      framework/src/Volo.Abp.AI/Volo/Abp/AI/ChatClientAccessor.cs
  3. 47
      framework/test/Volo.Abp.AI.Tests/Volo/Abp/AI/ChatClientAccessor_Tests.cs
  4. 2
      framework/test/Volo.Abp.AI.Tests/Volo/Abp/AI/Mocks/MockChatClient.cs

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

@ -34,6 +34,7 @@ public class AbpAIModule : AbpModule
}
context.Services.TryAddTransient(typeof(IChatClient<>), typeof(TypedChatClient<>));
context.Services.TryAddTransient(typeof(IChatClientAccessor<>), typeof(ChatClientAccessor<>));
context.Services.TryAddTransient(typeof(IKernelAccessor<>), typeof(KernelAccessor<>));
}

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

@ -5,9 +5,9 @@ using Volo.Abp.DependencyInjection;
namespace Volo.Abp.AI;
[Dependency(ReplaceServices = true, TryRegister = true)]
[Dependency(ReplaceServices = true)]
[ExposeServices(typeof(IChatClientAccessor))]
public class ChatClientAccessor : IChatClientAccessor
public class ChatClientAccessor : IChatClientAccessor, ITransientDependency
{
public IChatClient? ChatClient { get; }
@ -19,8 +19,6 @@ public class ChatClientAccessor : IChatClientAccessor
}
}
[Dependency(ReplaceServices = true, TryRegister = true)]
[ExposeServices(typeof(IChatClientAccessor))]
public class ChatClientAccessor<TWorkSpace> : IChatClientAccessor<TWorkSpace>
where TWorkSpace : class
{

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

@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Text;
using Shouldly;
using Volo.Abp.AI.Tests.Workspaces;
using Volo.Abp.AutoMapper;
using Volo.Abp.Testing;
using Xunit;
namespace Volo.Abp.AI;
public class ChatClientAccessor_Tests : AbpIntegratedTest<AbpAITestModule>
{
[Fact]
public void Should_Resolve_DefaultChatClientAccessor()
{
// Arrange & Act
var chatClientAccessor = GetRequiredService<IChatClientAccessor>();
// Assert
chatClientAccessor.ShouldNotBeNull();
chatClientAccessor.ChatClient.ShouldNotBeNull();
}
[Fact]
public void Should_Resolve_ChatClientAccessor_For_Workspace()
{
// Arrange & Act
var chatClientAccessor = GetRequiredService<IChatClientAccessor<WordCounter>>();
// Assert
chatClientAccessor.ShouldNotBeNull();
chatClientAccessor.ChatClient.ShouldNotBeNull();
}
[Fact]
public void Should_Resolve_ChatClientAccessor_For_NonConfigured_Workspace()
{
// Arrange & Act
var chatClientAccessor = GetRequiredService<IChatClientAccessor<NonConfiguredWorkspace>>();
// Assert
chatClientAccessor.ShouldNotBeNull();
chatClientAccessor.ChatClient.ShouldBeNull();
}
public class NonConfiguredWorkspace
{
}
}

2
framework/test/Volo.Abp.AI.Tests/Volo/Abp/AI/Mocks/MockChatClient.cs

@ -10,7 +10,7 @@ namespace Volo.Abp.AI.Mocks;
public class MockChatClient : IChatClient
{
public const int StreamingResponseParts = 12;
public const int StreamingResponseParts = 4;
public const string MockResponse = "This is a mock response.";
public void Dispose()

Loading…
Cancel
Save