feat: 新增工具调用
This commit is contained in:
@@ -43,11 +43,15 @@ public class AiChatService : ApplicationService
|
||||
private readonly ILogger<AiChatService> _logger;
|
||||
private readonly AiGateWayManager _aiGateWayManager;
|
||||
private readonly PremiumPackageManager _premiumPackageManager;
|
||||
private readonly ChatManager _chatManager;
|
||||
|
||||
public AiChatService(IHttpContextAccessor httpContextAccessor,
|
||||
AiBlacklistManager aiBlacklistManager,
|
||||
ISqlSugarRepository<AiModelEntity> aiModelRepository,
|
||||
ILogger<AiChatService> logger, AiGateWayManager aiGateWayManager, PremiumPackageManager premiumPackageManager)
|
||||
ILogger<AiChatService> logger,
|
||||
AiGateWayManager aiGateWayManager,
|
||||
PremiumPackageManager premiumPackageManager,
|
||||
ChatManager chatManager)
|
||||
{
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
_aiBlacklistManager = aiBlacklistManager;
|
||||
@@ -55,6 +59,7 @@ public class AiChatService : ApplicationService
|
||||
_logger = logger;
|
||||
_aiGateWayManager = aiGateWayManager;
|
||||
_premiumPackageManager = premiumPackageManager;
|
||||
_chatManager = chatManager;
|
||||
}
|
||||
|
||||
|
||||
@@ -140,9 +145,19 @@ public class AiChatService : ApplicationService
|
||||
}
|
||||
}
|
||||
|
||||
//ai网关代理httpcontext
|
||||
await _aiGateWayManager.CompleteChatStreamForStatisticsAsync(_httpContextAccessor.HttpContext, input,
|
||||
CurrentUser.Id, sessionId, null, cancellationToken);
|
||||
// 判断是否有工具调用
|
||||
if (input.Tools != null && input.Tools.Count > 0)
|
||||
{
|
||||
// 使用 ChatManager 处理支持工具调用的对话
|
||||
await _chatManager.CompleteChatWithToolsAsync(_httpContextAccessor.HttpContext, input,
|
||||
CurrentUser.Id, sessionId, null, cancellationToken);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 使用原来的 AiGateWayManager 处理普通对话
|
||||
await _aiGateWayManager.CompleteChatStreamForStatisticsAsync(_httpContextAccessor.HttpContext, input,
|
||||
CurrentUser.Id, sessionId, null, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user