feat: 兼容了用量使用显示
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using Medallion.Threading;
|
||||
using Volo.Abp.Domain.Services;
|
||||
using Yi.Framework.AiHub.Application.Contracts.Dtos.OpenAi;
|
||||
using Yi.Framework.AiHub.Domain.Entities;
|
||||
using Yi.Framework.SqlSugarCore.Abstractions;
|
||||
|
||||
@@ -17,8 +18,16 @@ public class UsageStatisticsManager : DomainService
|
||||
private IDistributedLockProvider DistributedLock =>
|
||||
LazyServiceProvider.LazyGetRequiredService<IDistributedLockProvider>();
|
||||
|
||||
public async Task SetUsageAsync(Guid userId, string modelId, int inputTokenCount, int outputTokenCount)
|
||||
public async Task SetUsageAsync(Guid userId, string modelId, ThorUsageResponse? tokenUsage)
|
||||
{
|
||||
long inputTokenCount = tokenUsage?.PromptTokens
|
||||
?? tokenUsage.InputTokens
|
||||
?? 0;
|
||||
|
||||
long outputTokenCount = tokenUsage?.CompletionTokens
|
||||
?? tokenUsage.OutputTokens
|
||||
?? 0;
|
||||
|
||||
await using (await DistributedLock.AcquireLockAsync($"UsageStatistics:{userId.ToString()}"))
|
||||
{
|
||||
var entity = await _repository._DbQueryable.FirstAsync(x => x.UserId == userId && x.ModelId == modelId);
|
||||
@@ -37,8 +46,4 @@ public class UsageStatisticsManager : DomainService
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal class LazyServiceProvider
|
||||
{
|
||||
}
|
||||
Reference in New Issue
Block a user