feat: 完成用量统计功能模块

This commit is contained in:
ccnetcore
2025-06-27 22:13:26 +08:00
parent 96e275efa6
commit 01a3c81359
20 changed files with 281 additions and 98 deletions

View File

@@ -1,7 +1,10 @@
using SqlSugar;
using Mapster;
using SqlSugar;
using Volo.Abp.Domain.Entities.Auditing;
using Yi.Framework.AiHub.Domain.Entities.ValueObjects;
using Yi.Framework.AiHub.Domain.Shared.Dtos;
namespace Yi.Framework.AiHub.Domain.Entities;
namespace Yi.Framework.AiHub.Domain.Entities.Chat;
[SugarTable("Ai_Message")]
[SugarIndex($"index_{{table}}_{nameof(UserId)}_{nameof(SessionId)}",
@@ -14,21 +17,32 @@ public class MessageAggregateRoot : FullAuditedAggregateRoot<Guid>
{
}
public MessageAggregateRoot(Guid userId, Guid sessionId, string content, string role, string modelId)
public MessageAggregateRoot(Guid userId, Guid sessionId, string content, string role, string modelId,
TokenUsage? tokenUsage)
{
UserId = userId;
SessionId = sessionId;
Content = content;
Role = role;
ModelId = modelId;
if (tokenUsage is not null)
{
this.TokenUsage = tokenUsage.Adapt<TokenUsageValueObject>();
}
}
public Guid UserId { get; set; }
public Guid SessionId { get; set; }
[SugarColumn(ColumnDataType = StaticConfig.CodeFirst_BigString)]
public string Content { get; set; }
public string Role { get; set; }
public decimal DeductCost { get; set; }
public decimal TotalTokens { get; set; }
public string ModelId { get; set; }
public string Remark { get; set; }
public string? Remark { get; set; }
[SugarColumn(IsOwnsOne = true)] public TokenUsageValueObject TokenUsage { get; set; }
}