mirror of https://github.com/abpframework/abp.git
6 changed files with 95 additions and 3 deletions
@ -0,0 +1,37 @@ |
|||
using System; |
|||
using System.Linq; |
|||
|
|||
namespace Volo.Abp.AI; |
|||
|
|||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.Struct)] |
|||
public class ChatClientNameAttribute : Attribute |
|||
{ |
|||
public string Name { get; } |
|||
|
|||
public ChatClientNameAttribute(string name) |
|||
{ |
|||
Check.NotNull(name, nameof(name)); |
|||
|
|||
Name = name; |
|||
} |
|||
|
|||
public static string GetChatClientName<TChatClient>() |
|||
{ |
|||
return GetChatClientName(typeof(TChatClient)); |
|||
} |
|||
|
|||
public static string GetChatClientName(Type chatClientType) |
|||
{ |
|||
var chatClientNameAttribute = chatClientType |
|||
.GetCustomAttributes(true) |
|||
.OfType<ChatClientNameAttribute>() |
|||
.FirstOrDefault(); |
|||
|
|||
if (chatClientNameAttribute != null) |
|||
{ |
|||
return chatClientNameAttribute.Name; |
|||
} |
|||
|
|||
return chatClientType.FullName!; |
|||
} |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
using Microsoft.Extensions.AI; |
|||
|
|||
namespace Volo.Abp.AI; |
|||
|
|||
public interface IChatClient<T> : IChatClient |
|||
where T: class |
|||
{ |
|||
|
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
using System; |
|||
using Microsoft.Extensions.AI; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.AI; |
|||
|
|||
public class TypedChatClient<T> : DelegatingChatClient, IChatClient<T> |
|||
where T : class |
|||
{ |
|||
public TypedChatClient(IServiceProvider serviceProvider) |
|||
: base( |
|||
serviceProvider.GetRequiredKeyedService<IChatClient>( |
|||
AbpAIChatClientOptions.GetChatClientServiceKeyName( |
|||
ChatClientNameAttribute.GetChatClientName<T>())) |
|||
) |
|||
{ |
|||
} |
|||
} |
|||
Loading…
Reference in new issue