fix: 修复agent报错问题
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// agent流式对话
|
||||
/// </summary>
|
||||
/// <param name="httpContext"></param>
|
||||
/// <param name="sessionId"></param>
|
||||
/// <param name="content"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <param name="tokenId"></param>
|
||||
/// <param name="modelId"></param>
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="tools"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <summary>
|
||||
/// agent流式对话
|
||||
/// </summary>
|
||||
/// <param name="httpContext"></param>
|
||||
/// <param name="sessionId"></param>
|
||||
/// <param name="content"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <param name="tokenId"></param>
|
||||
/// <param name="modelId"></param>
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="tools"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
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<McpServerToolTypeAttribute>() is not null)
|
||||
.Where(x => x.GetCustomAttribute<YiAgentToolAttribute>() 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<McpServerToolAttribute>() is not null).ToList();
|
||||
.Where(y => y.GetCustomAttribute<YiAgentToolAttribute>() is not null).ToList();
|
||||
foreach (var toolMethod in toolMethods)
|
||||
{
|
||||
var display = toolMethod.GetCustomAttribute<DisplayNameAttribute>()?.DisplayName;
|
||||
var display = toolMethod.GetCustomAttribute<YiAgentToolAttribute>()?.Name;
|
||||
var tool = AIFunctionFactory.Create(toolMethod, instance);
|
||||
mcpTools.add((tool.Name, display, tool));
|
||||
}
|
||||
}
|
||||
|
||||
return mcpTools;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user