diff --git a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain.Shared/Attributes/YiAgentToolAttribute.cs b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain.Shared/Attributes/YiAgentToolAttribute.cs new file mode 100644 index 00000000..eae48bf0 --- /dev/null +++ b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain.Shared/Attributes/YiAgentToolAttribute.cs @@ -0,0 +1,16 @@ +namespace Yi.Framework.AiHub.Domain.Shared.Attributes; + +[AttributeUsage(AttributeTargets.Class|AttributeTargets.Method)] +public class YiAgentToolAttribute:Attribute +{ + public YiAgentToolAttribute() + { + } + + public YiAgentToolAttribute(string name) + { + Name = name; + } + + public string Name { get; set; } +} \ No newline at end of file diff --git a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Managers/ChatManager.cs b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Managers/ChatManager.cs index b0a95a01..b4d9110c 100644 --- a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Managers/ChatManager.cs +++ b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Managers/ChatManager.cs @@ -16,6 +16,7 @@ using Yi.Framework.AiHub.Application.Contracts.Dtos.Chat; using Yi.Framework.AiHub.Domain.AiGateWay; using Yi.Framework.AiHub.Domain.Entities.Chat; using Yi.Framework.AiHub.Domain.Entities.OpenApi; +using Yi.Framework.AiHub.Domain.Shared.Attributes; using Yi.Framework.AiHub.Domain.Shared.Consts; using Yi.Framework.AiHub.Domain.Shared.Dtos; using Yi.Framework.AiHub.Domain.Shared.Dtos.OpenAi; @@ -49,18 +50,18 @@ public class ChatManager : DomainService _aiGateWayManager = aiGateWayManager; } - /// - /// agent流式对话 - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// + /// + /// agent流式对话 + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// public async Task AgentCompleteChatStreamAsync(HttpContext httpContext, Guid sessionId, string content, @@ -135,7 +136,9 @@ public class ChatManager : DomainService var toolContents = GetTools(); var chatOptions = new ChatOptions() { - Tools = toolContents.Where(x=>tools.Contains(x.Code)).Select(x => (AITool)x.Tool).ToList(), + Tools = toolContents + .Where(x => tools.Contains(x.Code)) + .Select(x => (AITool)x.Tool).ToList(), ToolMode = ChatToolMode.Auto }; @@ -244,7 +247,7 @@ public class ChatManager : DomainService public List<(string Code, string Name, AIFunction Tool)> GetTools() { var toolClasses = typeof(YiFrameworkAiHubDomainModule).Assembly.GetTypes() - .Where(x => x.GetCustomAttribute() is not null) + .Where(x => x.GetCustomAttribute() is not null) .ToList(); List<(string Code, string Name, AIFunction Tool)> mcpTools = new(); @@ -252,14 +255,15 @@ public class ChatManager : DomainService { var instance = LazyServiceProvider.GetRequiredService(toolClass); var toolMethods = toolClass.GetMethods() - .Where(y => y.GetCustomAttribute() is not null).ToList(); + .Where(y => y.GetCustomAttribute() is not null).ToList(); foreach (var toolMethod in toolMethods) { - var display = toolMethod.GetCustomAttribute()?.DisplayName; + var display = toolMethod.GetCustomAttribute()?.Name; var tool = AIFunctionFactory.Create(toolMethod, instance); mcpTools.add((tool.Name, display, tool)); } } + return mcpTools; } diff --git a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Mcp/DeepThinkTool.cs b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Mcp/DeepThinkTool.cs index 2ac5521d..64afcbef 100644 --- a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Mcp/DeepThinkTool.cs +++ b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Mcp/DeepThinkTool.cs @@ -1,13 +1,14 @@ using System.ComponentModel; using ModelContextProtocol.Server; using Volo.Abp.DependencyInjection; +using Yi.Framework.AiHub.Domain.Shared.Attributes; namespace Yi.Framework.AiHub.Domain.Mcp; -[McpServerToolType] +[YiAgentTool] public class DeepThinkTool:ISingletonDependency { - [McpServerTool, Description("进行深度思考"),DisplayName("深度思考")] + [YiAgentTool("深度思考"),DisplayName("DeepThink"),Description("进行深度思考")] public void DeepThink() { diff --git a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Mcp/OnlineSearchTool.cs b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Mcp/OnlineSearchTool.cs index 7efd2fb9..7935e221 100644 --- a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Mcp/OnlineSearchTool.cs +++ b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Mcp/OnlineSearchTool.cs @@ -1,13 +1,14 @@ using System.ComponentModel; using ModelContextProtocol.Server; using Volo.Abp.DependencyInjection; +using Yi.Framework.AiHub.Domain.Shared.Attributes; namespace Yi.Framework.AiHub.Domain.Mcp; -[McpServerToolType] +[YiAgentTool] public class OnlineSearchTool:ISingletonDependency { - [McpServerTool, Description("进行在线搜索"),DisplayName("在线搜索")] + [YiAgentTool("联网搜索"),DisplayName("OnlineSearch"), Description("进行在线搜索")] public string OnlineSearch(string keyword) { return "奥德赛第一中学学生会会长是:郭老板";