From 389ad566fbefeabfec01ef860498f07726cd7c2e Mon Sep 17 00:00:00 2001 From: colin Date: Fri, 16 Jan 2026 09:12:31 +0800 Subject: [PATCH] feat: Reconstruct the general user message --- .../LINGYUN/Abp/AI/Agent/AgentService.cs | 5 +-- .../LINGYUN/Abp/AI/AbpAICoreModule.cs | 6 ++- .../AI/{ => Internal}/ChatClientFactory.cs | 2 +- .../ChatClientProviderManager.cs | 2 +- .../AI/Internal/DeepSeekChatClientProvider.cs | 15 ++++++++ .../Abp/AI/Internal/DeepSeekKernelProvider.cs | 13 +++++++ .../Abp/AI/{ => Internal}/KernelFactory.cs | 2 +- .../{ => Internal}/KernelProviderManager.cs | 2 +- .../OpenAIChatClientProvider.cs | 6 +-- .../AI/{ => Internal}/OpenAIKernelProvider.cs | 4 +- .../LINGYUN/Abp/AI/Models/TokenUsageInfo.cs | 5 +-- .../LINGYUN/Abp/AI/Models/UserMessage.cs | 37 +++++-------------- .../LINGYUN/Abp/AI/Models/UserTextMessage.cs | 20 ++++++++++ .../Abp/AI/Tokens/InMemoryTokenUsageStore.cs | 9 ----- 14 files changed, 74 insertions(+), 54 deletions(-) rename aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/{ => Internal}/ChatClientFactory.cs (98%) rename aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/{ => Internal}/ChatClientProviderManager.cs (97%) create mode 100644 aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/Internal/DeepSeekChatClientProvider.cs create mode 100644 aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/Internal/DeepSeekKernelProvider.cs rename aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/{ => Internal}/KernelFactory.cs (98%) rename aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/{ => Internal}/KernelProviderManager.cs (97%) rename aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/{ => Internal}/OpenAIChatClientProvider.cs (91%) rename aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/{ => Internal}/OpenAIKernelProvider.cs (89%) create mode 100644 aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/Models/UserTextMessage.cs diff --git a/aspnet-core/modules/ai/LINGYUN.Abp.AI.Agent/LINGYUN/Abp/AI/Agent/AgentService.cs b/aspnet-core/modules/ai/LINGYUN.Abp.AI.Agent/LINGYUN/Abp/AI/Agent/AgentService.cs index 899689c88..17ea6b7a9 100644 --- a/aspnet-core/modules/ai/LINGYUN.Abp.AI.Agent/LINGYUN/Abp/AI/Agent/AgentService.cs +++ b/aspnet-core/modules/ai/LINGYUN.Abp.AI.Agent/LINGYUN/Abp/AI/Agent/AgentService.cs @@ -56,11 +56,11 @@ public class AgentService : IAgentService, IScopedDependency foreach (var chatMessage in historyMessages) { - messages.Add(new ChatMessage(ChatRole.System, chatMessage.Content)); + messages.Add(new ChatMessage(ChatRole.System, chatMessage.GetMessagePrompt())); } } - messages.Add(new ChatMessage(ChatRole.User, message.Content)); + messages.Add(new ChatMessage(ChatRole.User, message.GetMessagePrompt())); return messages; } @@ -84,7 +84,6 @@ public class AgentService : IAgentService, IScopedDependency TotalTokenCount = usage.Details.TotalTokenCount, CachedInputTokenCount = usage.Details.CachedInputTokenCount, InputTokenCount = usage.Details.InputTokenCount, - AdditionalCounts = usage.Details.AdditionalCounts, OutputTokenCount = usage.Details.OutputTokenCount, ReasoningTokenCount = usage.Details.ReasoningTokenCount, }); diff --git a/aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/AbpAICoreModule.cs b/aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/AbpAICoreModule.cs index 3f81bd409..2ab1185a5 100644 --- a/aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/AbpAICoreModule.cs +++ b/aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/AbpAICoreModule.cs @@ -1,4 +1,5 @@ -using LINGYUN.Abp.AI.Localization; +using LINGYUN.Abp.AI.Internal; +using LINGYUN.Abp.AI.Localization; using LINGYUN.Abp.AI.Workspaces; using Microsoft.Extensions.DependencyInjection; using System; @@ -38,7 +39,10 @@ public class AbpAICoreModule : AbpModule Configure(options => { options.ChatClientProviders.Add(); + options.ChatClientProviders.Add(); + options.KernelProviders.Add(); + options.KernelProviders.Add(); }); Configure(options => diff --git a/aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/ChatClientFactory.cs b/aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/Internal/ChatClientFactory.cs similarity index 98% rename from aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/ChatClientFactory.cs rename to aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/Internal/ChatClientFactory.cs index 3f5280dee..a369c05e0 100644 --- a/aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/ChatClientFactory.cs +++ b/aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/Internal/ChatClientFactory.cs @@ -8,7 +8,7 @@ using Volo.Abp.Authorization; using Volo.Abp.DependencyInjection; using Volo.Abp.SimpleStateChecking; -namespace LINGYUN.Abp.AI; +namespace LINGYUN.Abp.AI.Internal; public class ChatClientFactory : IChatClientFactory, IScopedDependency { protected ISimpleStateCheckerManager StateCheckerManager { get; } diff --git a/aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/ChatClientProviderManager.cs b/aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/Internal/ChatClientProviderManager.cs similarity index 97% rename from aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/ChatClientProviderManager.cs rename to aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/Internal/ChatClientProviderManager.cs index 8d3cc80ec..09495b231 100644 --- a/aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/ChatClientProviderManager.cs +++ b/aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/Internal/ChatClientProviderManager.cs @@ -7,7 +7,7 @@ using System.Linq; using Volo.Abp; using Volo.Abp.DependencyInjection; -namespace LINGYUN.Abp.AI; +namespace LINGYUN.Abp.AI.Internal; public class ChatClientProviderManager : IChatClientProviderManager, ISingletonDependency { public List Providers => _lazyProviders.Value; diff --git a/aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/Internal/DeepSeekChatClientProvider.cs b/aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/Internal/DeepSeekChatClientProvider.cs new file mode 100644 index 000000000..bc0863f33 --- /dev/null +++ b/aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/Internal/DeepSeekChatClientProvider.cs @@ -0,0 +1,15 @@ +using System; + +namespace LINGYUN.Abp.AI.Internal; +public class DeepSeekChatClientProvider : OpenAIChatClientProvider +{ + protected override string DefaultEndpoint => "https://api.deepseek.com/v1"; + + public new const string ProviderName = "DeepSeek"; + public override string Name => ProviderName; + public DeepSeekChatClientProvider( + IServiceProvider serviceProvider) + : base(serviceProvider) + { + } +} diff --git a/aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/Internal/DeepSeekKernelProvider.cs b/aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/Internal/DeepSeekKernelProvider.cs new file mode 100644 index 000000000..c27cb0e41 --- /dev/null +++ b/aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/Internal/DeepSeekKernelProvider.cs @@ -0,0 +1,13 @@ +using System; + +namespace LINGYUN.Abp.AI.Internal; +public class DeepSeekKernelProvider : OpenAIKernelProvider +{ + protected override string DefaultEndpoint => "https://api.deepseek.com/v1"; + + public new const string ProviderName = "DeepSeek"; + public override string Name => ProviderName; + public DeepSeekKernelProvider(IServiceProvider serviceProvider) : base(serviceProvider) + { + } +} diff --git a/aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/KernelFactory.cs b/aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/Internal/KernelFactory.cs similarity index 98% rename from aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/KernelFactory.cs rename to aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/Internal/KernelFactory.cs index 5778e7921..23c6aeda7 100644 --- a/aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/KernelFactory.cs +++ b/aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/Internal/KernelFactory.cs @@ -8,7 +8,7 @@ using Volo.Abp.Authorization; using Volo.Abp.DependencyInjection; using Volo.Abp.SimpleStateChecking; -namespace LINGYUN.Abp.AI; +namespace LINGYUN.Abp.AI.Internal; public class KernelFactory : IKernelFactory, IScopedDependency { protected ISimpleStateCheckerManager StateCheckerManager { get; } diff --git a/aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/KernelProviderManager.cs b/aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/Internal/KernelProviderManager.cs similarity index 97% rename from aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/KernelProviderManager.cs rename to aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/Internal/KernelProviderManager.cs index f2beb0025..ab4bd6221 100644 --- a/aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/KernelProviderManager.cs +++ b/aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/Internal/KernelProviderManager.cs @@ -6,7 +6,7 @@ using System.Linq; using Volo.Abp; using Volo.Abp.DependencyInjection; -namespace LINGYUN.Abp.AI; +namespace LINGYUN.Abp.AI.Internal; public class KernelProviderManager : IKernelProviderManager, ISingletonDependency { public List Providers => _lazyProviders.Value; diff --git a/aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/OpenAIChatClientProvider.cs b/aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/Internal/OpenAIChatClientProvider.cs similarity index 91% rename from aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/OpenAIChatClientProvider.cs rename to aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/Internal/OpenAIChatClientProvider.cs index 3501993b1..6f2ab1234 100644 --- a/aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/OpenAIChatClientProvider.cs +++ b/aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/Internal/OpenAIChatClientProvider.cs @@ -6,12 +6,12 @@ using System.ClientModel; using System.Threading.Tasks; using Volo.Abp; -namespace LINGYUN.Abp.AI; +namespace LINGYUN.Abp.AI.Internal; public class OpenAIChatClientProvider : ChatClientProvider { - private const string DefaultEndpoint = "https://api.openai.com/v1"; - public const string ProviderName = "OpenAI"; + protected virtual string DefaultEndpoint => "https://api.openai.com/v1"; + public const string ProviderName = "OpenAI"; public override string Name => ProviderName; public OpenAIChatClientProvider(IServiceProvider serviceProvider) : base(serviceProvider) diff --git a/aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/OpenAIKernelProvider.cs b/aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/Internal/OpenAIKernelProvider.cs similarity index 89% rename from aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/OpenAIKernelProvider.cs rename to aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/Internal/OpenAIKernelProvider.cs index 2f1bb8f61..2eb16859e 100644 --- a/aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/OpenAIKernelProvider.cs +++ b/aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/Internal/OpenAIKernelProvider.cs @@ -6,10 +6,10 @@ using System.ClientModel; using System.Threading.Tasks; using Volo.Abp; -namespace LINGYUN.Abp.AI; +namespace LINGYUN.Abp.AI.Internal; public class OpenAIKernelProvider : KernelProvider { - private const string DefaultEndpoint = "https://api.openai.com/v1"; + protected virtual string DefaultEndpoint { get; set; } = "https://api.openai.com/v1"; public const string ProviderName = "OpenAI"; public override string Name => ProviderName; diff --git a/aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/Models/TokenUsageInfo.cs b/aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/Models/TokenUsageInfo.cs index cdac08043..61c8e0457 100644 --- a/aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/Models/TokenUsageInfo.cs +++ b/aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/Models/TokenUsageInfo.cs @@ -1,6 +1,4 @@ -using System.Collections.Generic; - -namespace LINGYUN.Abp.AI.Models; +namespace LINGYUN.Abp.AI.Models; public class TokenUsageInfo { public string Workspace { get; } @@ -9,7 +7,6 @@ public class TokenUsageInfo public long? TotalTokenCount { get; set; } public long? CachedInputTokenCount { get; set; } public long? ReasoningTokenCount { get; set; } - public IDictionary? AdditionalCounts { get; set; } public TokenUsageInfo(string workspace) { Workspace = workspace; diff --git a/aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/Models/UserMessage.cs b/aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/Models/UserMessage.cs index 1c6a37557..7681ae260 100644 --- a/aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/Models/UserMessage.cs +++ b/aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/Models/UserMessage.cs @@ -1,12 +1,6 @@ -using System.Linq; - -namespace LINGYUN.Abp.AI.Models; -public class UserMessage +namespace LINGYUN.Abp.AI.Models; +public abstract class UserMessage { - /// - /// 消息内容 - /// - public string Content { get; } /// /// 工作区 /// @@ -29,44 +23,31 @@ public class UserMessage /// AI回复消息 /// public string ReplyMessage { get; private set; } - /// - /// 媒体附件 - /// - /// - /// 暂未实现 - /// - public MediaMessage[]? Medias { get; private set; } - public UserMessage( - string workspace, - string content) + protected UserMessage(string workspace) { Workspace = workspace; - Content = content; } - public UserMessage WithMessageId(string id) + public virtual UserMessage WithMessageId(string id) { Id = id; return this; } - public UserMessage WithConversationId(string conversationId) + public virtual UserMessage WithConversationId(string conversationId) { ConversationId = conversationId; return this; } - public UserMessage WithMedia(MediaMessage media) + public virtual UserMessage WithReply(string replyMessage) { - Medias ??= []; - Medias = Medias.Union([media]).ToArray(); - + ReplyMessage = replyMessage; return this; } - public UserMessage WithReply(string replyMessage) + public virtual string GetMessagePrompt() { - ReplyMessage = replyMessage; - return this; + return string.Empty; } } diff --git a/aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/Models/UserTextMessage.cs b/aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/Models/UserTextMessage.cs new file mode 100644 index 000000000..55cb12ae6 --- /dev/null +++ b/aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/Models/UserTextMessage.cs @@ -0,0 +1,20 @@ +namespace LINGYUN.Abp.AI.Models; +public class UserTextMessage : UserMessage +{ + /// + /// 消息内容 + /// + public string Content { get; } + public UserTextMessage( + string workspace, + string content) + : base(workspace) + { + Content = content; + } + + public override string GetMessagePrompt() + { + return Content; + } +} diff --git a/aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/Tokens/InMemoryTokenUsageStore.cs b/aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/Tokens/InMemoryTokenUsageStore.cs index 621f39c06..9c7862de8 100644 --- a/aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/Tokens/InMemoryTokenUsageStore.cs +++ b/aspnet-core/modules/ai/LINGYUN.Abp.AI.Core/LINGYUN/Abp/AI/Tokens/InMemoryTokenUsageStore.cs @@ -25,15 +25,6 @@ public class InMemoryTokenUsageStore : ITokenUsageStore ReasoningTokenCount = usageInfo.Sum(x => x.ReasoningTokenCount), CachedInputTokenCount = usageInfo.Sum(x => x.CachedInputTokenCount), }; - tokenUsageInfo.AdditionalCounts ??= new Dictionary(); - foreach (var item in usageInfo) - { - if (item.AdditionalCounts == null) - { - continue; - } - tokenUsageInfo.AdditionalCounts.AddIfNotContains(item.AdditionalCounts); - } if (!_tokenUsageCache.ContainsKey(usageInfo.Key)) {