feat: 支持消息自定义创建时间并完善TokenUsage初始化
- 用户消息创建支持传入创建时间,用于统计与回放 - TokenUsage 为空时自动初始化,避免空引用问题 - 网关记录消息开始时间并传递至消息管理器 - 标记并停用旧的发送消息接口 - 前端版本号更新至 3.6 - 移除未使用的 VITE_BUILD_COMPRESS 类型声明
This commit is contained in:
@@ -127,54 +127,55 @@ public class AiChatService : ApplicationService
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 发送消息
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <param name="sessionId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
[HttpPost("ai-chat/send")]
|
||||
public async Task PostSendAsync([FromBody] ThorChatCompletionsRequest input, [FromQuery] Guid? sessionId,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
//除了免费模型,其他的模型都要校验
|
||||
if (input.Model!=FreeModelId)
|
||||
{
|
||||
//有token,需要黑名单校验
|
||||
if (CurrentUser.IsAuthenticated)
|
||||
{
|
||||
await _aiBlacklistManager.VerifiyAiBlacklist(CurrentUser.GetId());
|
||||
if (!CurrentUser.IsAiVip())
|
||||
{
|
||||
throw new UserFriendlyException("该模型需要VIP用户才能使用,请购买VIP后重新登录重试");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new UserFriendlyException("未登录用户,只能使用未加速的DeepSeek-R1,请登录后重试");
|
||||
}
|
||||
}
|
||||
|
||||
//如果是尊享包服务,需要校验是是否尊享包足够
|
||||
if (CurrentUser.IsAuthenticated)
|
||||
{
|
||||
var isPremium = await _modelManager.IsPremiumModelAsync(input.Model);
|
||||
|
||||
if (isPremium)
|
||||
{
|
||||
// 检查尊享token包用量
|
||||
var availableTokens = await _premiumPackageManager.GetAvailableTokensAsync(CurrentUser.GetId());
|
||||
if (availableTokens <= 0)
|
||||
{
|
||||
throw new UserFriendlyException("尊享token包用量不足,请先购买尊享token包");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//ai网关代理httpcontext
|
||||
await _aiGateWayManager.CompleteChatStreamForStatisticsAsync(_httpContextAccessor.HttpContext, input,
|
||||
CurrentUser.Id, sessionId, null, CancellationToken.None);
|
||||
}
|
||||
// /// <summary>
|
||||
// /// 发送消息
|
||||
// /// </summary>
|
||||
// /// <param name="input"></param>
|
||||
// /// <param name="sessionId"></param>
|
||||
// /// <param name="cancellationToken"></param>
|
||||
// [HttpPost("ai-chat/send")]
|
||||
// [Obsolete]
|
||||
// public async Task PostSendAsync([FromBody] ThorChatCompletionsRequest input, [FromQuery] Guid? sessionId,
|
||||
// CancellationToken cancellationToken)
|
||||
// {
|
||||
// //除了免费模型,其他的模型都要校验
|
||||
// if (input.Model!=FreeModelId)
|
||||
// {
|
||||
// //有token,需要黑名单校验
|
||||
// if (CurrentUser.IsAuthenticated)
|
||||
// {
|
||||
// await _aiBlacklistManager.VerifiyAiBlacklist(CurrentUser.GetId());
|
||||
// if (!CurrentUser.IsAiVip())
|
||||
// {
|
||||
// throw new UserFriendlyException("该模型需要VIP用户才能使用,请购买VIP后重新登录重试");
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// throw new UserFriendlyException("未登录用户,只能使用未加速的DeepSeek-R1,请登录后重试");
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// //如果是尊享包服务,需要校验是是否尊享包足够
|
||||
// if (CurrentUser.IsAuthenticated)
|
||||
// {
|
||||
// var isPremium = await _modelManager.IsPremiumModelAsync(input.Model);
|
||||
//
|
||||
// if (isPremium)
|
||||
// {
|
||||
// // 检查尊享token包用量
|
||||
// var availableTokens = await _premiumPackageManager.GetAvailableTokensAsync(CurrentUser.GetId());
|
||||
// if (availableTokens <= 0)
|
||||
// {
|
||||
// throw new UserFriendlyException("尊享token包用量不足,请先购买尊享token包");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// //ai网关代理httpcontext
|
||||
// await _aiGateWayManager.CompleteChatStreamForStatisticsAsync(_httpContextAccessor.HttpContext, input,
|
||||
// CurrentUser.Id, sessionId, null, CancellationToken.None);
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// 发送消息
|
||||
|
||||
Reference in New Issue
Block a user