feat: 完成兼容处理

This commit is contained in:
ccnetcore
2025-07-18 20:46:30 +08:00
parent ccba2667bc
commit 651f0157dc
8 changed files with 966 additions and 1095 deletions

View File

@@ -22,14 +22,17 @@ public class AiGateWayManager : DomainService
private readonly ILogger<AiGateWayManager> _logger;
private readonly AiMessageManager _aiMessageManager;
private readonly UsageStatisticsManager _usageStatisticsManager;
private readonly ISpecialCompatible _specialCompatible;
public AiGateWayManager(ISqlSugarRepository<AiAppAggregateRoot> aiAppRepository, ILogger<AiGateWayManager> logger,
AiMessageManager aiMessageManager, UsageStatisticsManager usageStatisticsManager)
AiMessageManager aiMessageManager, UsageStatisticsManager usageStatisticsManager,
ISpecialCompatible specialCompatible)
{
_aiAppRepository = aiAppRepository;
_logger = logger;
_aiMessageManager = aiMessageManager;
_usageStatisticsManager = usageStatisticsManager;
_specialCompatible = specialCompatible;
}
/// <summary>
@@ -76,16 +79,11 @@ public class AiGateWayManager : DomainService
ThorChatCompletionsRequest request,
[EnumeratorCancellation] CancellationToken cancellationToken)
{
_specialCompatible.Compatible(request);
var modelDescribe = await GetModelAsync(request.Model);
var chatService =
LazyServiceProvider.GetRequiredKeyedService<IChatCompletionService>(modelDescribe.HandlerName);
//todo 处理极少数不同模型参数不一样
if (request.Model == "o1")
{
request.Temperature = null;
}
await foreach (var result in chatService.CompleteChatStreamAsync(modelDescribe, request, cancellationToken))
{
yield return result;
@@ -108,6 +106,7 @@ public class AiGateWayManager : DomainService
Guid? sessionId = null,
CancellationToken cancellationToken = default)
{
_specialCompatible.Compatible(request);
var response = httpContext.Response;
// 设置响应头,声明是 json
response.ContentType = "application/json; charset=UTF-8";