diff --git a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application.Contracts/Dtos/Pay/GoodsListOutput.cs b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application.Contracts/Dtos/Pay/GoodsListOutput.cs index 7a25970f..e2602dab 100644 --- a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application.Contracts/Dtos/Pay/GoodsListOutput.cs +++ b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application.Contracts/Dtos/Pay/GoodsListOutput.cs @@ -21,7 +21,7 @@ public class GoodsListOutput /// 商品参考价格 /// public decimal ReferencePrice { get; set; } - + /// /// 商品实际价格(折扣后的价格) /// @@ -31,7 +31,7 @@ public class GoodsListOutput /// 折扣金额(仅尊享包) /// public decimal? DiscountAmount { get; set; } - + /// /// 商品类别 /// @@ -43,9 +43,13 @@ public class GoodsListOutput public string Remark { get; set; } - /// /// 折扣说明(仅尊享包) /// public string? DiscountDescription { get; set; } -} + + /// + /// 商品类型 + /// + public GoodsTypeEnum GoodsType { get; set; } +} \ No newline at end of file diff --git a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/PayService.cs b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/PayService.cs index 7e38d42b..f40a46c3 100644 --- a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/PayService.cs +++ b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/PayService.cs @@ -261,7 +261,8 @@ public class PayService : ApplicationService, IPayService GoodsCategory = goodsType.GetGoodsCategory().ToString(), Remark = goodsType.GetRemark(), DiscountAmount = discountAmount, - DiscountDescription = discountDescription + DiscountDescription = discountDescription, + GoodsType = goodsType }; goodsList.Add(goodsItem); diff --git a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain.Shared/Enums/GoodsTypeEnum.cs b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain.Shared/Enums/GoodsTypeEnum.cs index 73d5f752..98060f58 100644 --- a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain.Shared/Enums/GoodsTypeEnum.cs +++ b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain.Shared/Enums/GoodsTypeEnum.cs @@ -10,11 +10,11 @@ namespace Yi.Framework.AiHub.Domain.Shared.Enums; public class PriceAttribute : Attribute { public decimal Price { get; } - + public decimal ReferencePrice { get; } - + public int ValidMonths { get; } - + public PriceAttribute(double price, int validMonths, double referencePrice) { Price = (decimal)price; @@ -93,39 +93,32 @@ public class TokenAmountAttribute : Attribute public enum GoodsTypeEnum { // VIP服务 - [Price(29.9, 1,29.9)] - [DisplayName("YiXinVip 1 month", "1个月", "灵活选择")] - [GoodsCategory(GoodsCategoryType.Vip)] + [Price(29.9, 1, 29.9)] [DisplayName("YiXinVip 1 month", "1个月", "灵活选择")] [GoodsCategory(GoodsCategoryType.Vip)] YiXinVip1 = 1, - [Price(83.7, 3,27.9)] - [DisplayName("YiXinVip 3 month", "3个月", "短期体验")] - [GoodsCategory(GoodsCategoryType.Vip)] + [Price(83.7, 3, 27.9)] [DisplayName("YiXinVip 3 month", "3个月", "短期体验")] [GoodsCategory(GoodsCategoryType.Vip)] YiXinVip3 = 3, - [Price(155.4, 6,25.9)] - [DisplayName("YiXinVip 6 month", "6个月", "年度热销")] - [GoodsCategory(GoodsCategoryType.Vip)] + [Price(155.4, 6, 25.9)] [DisplayName("YiXinVip 6 month", "6个月", "年度热销")] [GoodsCategory(GoodsCategoryType.Vip)] YiXinVip6 = 6, - [Price(183.2, 8,22.9)] + [Price(183.2, 8, 22.9)] [DisplayName("YiXinVip 8 month", "8个月(推荐)", "限时活动,超高性价比")] [GoodsCategory(GoodsCategoryType.Vip)] YiXinVip8 = 8, // 尊享包服务 - 需要VIP资格才能购买 - [Price(188.9, 0,1750)] + [Price(188.9, 0, 1750)] [DisplayName("YiXinPremiumPackage 5000W Tokens", "5000万Tokens", "简单尝试")] [GoodsCategory(GoodsCategoryType.PremiumPackage)] - [TokenAmount(5000)] + [TokenAmount(50000000)] PremiumPackage5000W = 101, - [Price(248.9, 0,3500)] + [Price(248.9, 0, 3500)] [DisplayName("YiXinPremiumPackage 10000W Tokens", "1亿Tokens(推荐)", "极致性价比")] [GoodsCategory(GoodsCategoryType.PremiumPackage)] - [TokenAmount(10000)] + [TokenAmount(100000000)] PremiumPackage10000W = 102, - } public static class GoodsTypeEnumExtensions @@ -304,6 +297,6 @@ public static class GoodsTypeEnumExtensions var discountedPrice = originalPrice - discount; // 确保价格不为负数,至少为0.01元 - return Math.Max(discountedPrice, 0.01m); + return Math.Round(discountedPrice, 2); } -} +} \ No newline at end of file diff --git a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Managers/AiGateWayManager.cs b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Managers/AiGateWayManager.cs index 5fd0c875..e7e4216e 100644 --- a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Managers/AiGateWayManager.cs +++ b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Managers/AiGateWayManager.cs @@ -139,7 +139,7 @@ public class AiGateWayManager : DomainService await _aiMessageManager.CreateUserMessageAsync(userId.Value, sessionId, new MessageInputDto { - Content = request.Messages?.LastOrDefault().Content ?? string.Empty, + Content = sessionId is null ? "不予存储" : request.Messages?.LastOrDefault().Content ?? string.Empty, ModelId = request.Model, TokenUsage = data.Usage, }); @@ -147,7 +147,8 @@ public class AiGateWayManager : DomainService await _aiMessageManager.CreateSystemMessageAsync(userId.Value, sessionId, new MessageInputDto { - Content = data.Choices?.FirstOrDefault()?.Delta.Content, + Content = + sessionId is null ? "不予存储" : data.Choices?.FirstOrDefault()?.Delta.Content ?? string.Empty, ModelId = request.Model, TokenUsage = data.Usage }); @@ -271,7 +272,7 @@ public class AiGateWayManager : DomainService await _aiMessageManager.CreateUserMessageAsync(userId, sessionId, new MessageInputDto { - Content = request.Messages?.LastOrDefault()?.Content ?? string.Empty, + Content = sessionId is null ? "不予存储" : request.Messages?.LastOrDefault()?.Content ?? string.Empty, ModelId = request.Model, TokenUsage = tokenUsage, }); @@ -279,7 +280,7 @@ public class AiGateWayManager : DomainService await _aiMessageManager.CreateSystemMessageAsync(userId, sessionId, new MessageInputDto { - Content = backupSystemContent.ToString(), + Content = sessionId is null ? "不予存储" : backupSystemContent.ToString(), ModelId = request.Model, TokenUsage = tokenUsage }); @@ -333,7 +334,7 @@ public class AiGateWayManager : DomainService await _aiMessageManager.CreateUserMessageAsync(userId, sessionId, new MessageInputDto { - Content = request.Prompt, + Content = sessionId is null ? "不予存储" : request.Prompt, ModelId = model, TokenUsage = response.Usage, }); @@ -341,13 +342,13 @@ public class AiGateWayManager : DomainService await _aiMessageManager.CreateSystemMessageAsync(userId, sessionId, new MessageInputDto { - Content = response.Results?.FirstOrDefault()?.Url, + Content = sessionId is null ? "不予存储" : response.Results?.FirstOrDefault()?.Url, ModelId = model, TokenUsage = response.Usage }); await _usageStatisticsManager.SetUsageAsync(userId, model, response.Usage); - + // 扣减尊享token包用量 if (userId is not null && PremiumPackageConst.ModeIds.Contains(request.Model)) { @@ -528,7 +529,7 @@ public class AiGateWayManager : DomainService await _aiMessageManager.CreateUserMessageAsync(userId.Value, sessionId, new MessageInputDto { - Content = request.Messages?.FirstOrDefault()?.Content ?? string.Empty, + Content = sessionId is null ? "不予存储" : request.Messages?.FirstOrDefault()?.Content ?? string.Empty, ModelId = request.Model, TokenUsage = data.TokenUsage, }); @@ -536,7 +537,7 @@ public class AiGateWayManager : DomainService await _aiMessageManager.CreateSystemMessageAsync(userId.Value, sessionId, new MessageInputDto { - Content = data.content?.FirstOrDefault()?.text, + Content = sessionId is null ? "不予存储" : data.content?.FirstOrDefault()?.text, ModelId = request.Model, TokenUsage = data.TokenUsage }); @@ -601,35 +602,12 @@ public class AiGateWayManager : DomainService _logger.LogError(e, $"Ai对话异常"); var errorContent = $"对话Ai异常,异常信息:\n当前Ai模型:{request.Model}\n异常信息:{e.Message}\n异常堆栈:{e}"; throw new UserFriendlyException(errorContent); - // var model = new AnthropicStreamDto - // { - // Message = new AnthropicChatCompletionDto - // { - // content = - // [ - // new AnthropicChatCompletionDtoContent - // { - // text = errorContent, - // } - // ], - // }, - // Error = new AnthropicStreamErrorDto - // { - // Type = null, - // Message = errorContent - // } - // }; - // var message = JsonConvert.SerializeObject(model, new JsonSerializerSettings - // { - // ContractResolver = new CamelCasePropertyNamesContractResolver() - // }); - // await response.WriteAsJsonAsync(message, ThorJsonSerializer.DefaultOptions); } await _aiMessageManager.CreateUserMessageAsync(userId, sessionId, new MessageInputDto { - Content = request.Messages?.LastOrDefault()?.Content ?? string.Empty, + Content = sessionId is null ? "不予存储" : request.Messages?.LastOrDefault()?.Content ?? string.Empty, ModelId = request.Model, TokenUsage = tokenUsage, }); @@ -637,7 +615,7 @@ public class AiGateWayManager : DomainService await _aiMessageManager.CreateSystemMessageAsync(userId, sessionId, new MessageInputDto { - Content = backupSystemContent.ToString(), + Content = sessionId is null ? "不予存储" : backupSystemContent.ToString(), ModelId = request.Model, TokenUsage = tokenUsage }); @@ -648,9 +626,9 @@ public class AiGateWayManager : DomainService if (userId.HasValue && tokenUsage is not null) { var totalTokens = tokenUsage.TotalTokens ?? 0; - if (totalTokens > 0) + if (tokenUsage.TotalTokens > 0) { - await PremiumPackageManager.TryConsumeTokensAsync(userId.Value, totalTokens); + await PremiumPackageManager.TryConsumeTokensAsync(userId.Value, totalTokens); } } } diff --git a/Yi.Ai.Vue3/index.html b/Yi.Ai.Vue3/index.html index eb48f78d..5c1b414b 100644 --- a/Yi.Ai.Vue3/index.html +++ b/Yi.Ai.Vue3/index.html @@ -112,7 +112,7 @@
-
意心Ai
+
意心Ai 2.0
海外地址,仅首次访问预计加载约10秒