feat: 完成agent功能
This commit is contained in:
@@ -49,7 +49,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>
|
||||
public async Task AgentCompleteChatStreamAsync(HttpContext httpContext,
|
||||
Guid sessionId,
|
||||
string content,
|
||||
@@ -120,11 +131,11 @@ public class ChatManager : DomainService
|
||||
currentThread = agent.GetNewThread();
|
||||
}
|
||||
|
||||
|
||||
//给agent塞入工具
|
||||
var toolContents = GetTools();
|
||||
var chatOptions = new ChatOptions()
|
||||
{
|
||||
Tools = toolContents.Select(x => (AITool)x).ToList(),
|
||||
Tools = toolContents.Where(x=>tools.Contains(x.Code)).Select(x => (AITool)x.Tool).ToList(),
|
||||
ToolMode = ChatToolMode.Auto
|
||||
};
|
||||
|
||||
@@ -230,13 +241,13 @@ public class ChatManager : DomainService
|
||||
}
|
||||
|
||||
|
||||
private List<AIFunction> GetTools()
|
||||
public List<(string Code, string Name, AIFunction Tool)> GetTools()
|
||||
{
|
||||
var toolClasses = typeof(YiFrameworkAiHubDomainModule).Assembly.GetTypes()
|
||||
.Where(x => x.GetCustomAttribute<McpServerToolTypeAttribute>() is not null)
|
||||
.ToList();
|
||||
|
||||
List<AIFunction> mcpTools = new List<AIFunction>();
|
||||
List<(string Code, string Name, AIFunction Tool)> mcpTools = new();
|
||||
foreach (var toolClass in toolClasses)
|
||||
{
|
||||
var instance = LazyServiceProvider.GetRequiredService(toolClass);
|
||||
@@ -244,10 +255,11 @@ public class ChatManager : DomainService
|
||||
.Where(y => y.GetCustomAttribute<McpServerToolAttribute>() is not null).ToList();
|
||||
foreach (var toolMethod in toolMethods)
|
||||
{
|
||||
mcpTools.add(AIFunctionFactory.Create(toolMethod, instance));
|
||||
var display = toolMethod.GetCustomAttribute<DisplayNameAttribute>()?.DisplayName;
|
||||
var tool = AIFunctionFactory.Create(toolMethod, instance);
|
||||
mcpTools.add((tool.Name, display, tool));
|
||||
}
|
||||
}
|
||||
|
||||
return mcpTools;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user