Commit 953c3574 by renyizhao

扩展价格显示

parent 8e72bc4d
...@@ -225,6 +225,9 @@ public class AppAiModelController { ...@@ -225,6 +225,9 @@ public class AppAiModelController {
vo.setCompletionRatio(toBigDecimal(pricing.get("completion_ratio"))); vo.setCompletionRatio(toBigDecimal(pricing.get("completion_ratio")));
vo.setCacheRatio(toBigDecimal(pricing.get("cache_ratio"))); vo.setCacheRatio(toBigDecimal(pricing.get("cache_ratio")));
vo.setCreateCacheRatio(toBigDecimal(pricing.get("create_cache_ratio"))); vo.setCreateCacheRatio(toBigDecimal(pricing.get("create_cache_ratio")));
BigDecimal imageRatio = toBigDecimal(pricing.get("image_ratio"));
BigDecimal audioRatio = toBigDecimal(pricing.get("audio_ratio"));
BigDecimal audioCompletionRatio = toBigDecimal(pricing.get("audio_completion_ratio"));
// 分档计费信息 // 分档计费信息
String billingMode = (String) pricing.get("billing_mode"); String billingMode = (String) pricing.get("billing_mode");
...@@ -261,6 +264,18 @@ public class AppAiModelController { ...@@ -261,6 +264,18 @@ public class AppAiModelController {
// 缓存价格 = cache_ratio × 输入价格(输入价格已包含 groupRatio) // 缓存价格 = cache_ratio × 输入价格(输入价格已包含 groupRatio)
vo.setCacheReadPrice(cacheRatio.multiply(inputPrice).setScale(2, RoundingMode.HALF_UP)); vo.setCacheReadPrice(cacheRatio.multiply(inputPrice).setScale(2, RoundingMode.HALF_UP));
vo.setCacheCreatePrice(createCacheRatio.multiply(inputPrice).setScale(2, RoundingMode.HALF_UP)); vo.setCacheCreatePrice(createCacheRatio.multiply(inputPrice).setScale(2, RoundingMode.HALF_UP));
// 图片输入价格 = image_ratio × 输入价格
if (imageRatio != null && imageRatio.compareTo(BigDecimal.ZERO) > 0) {
vo.setImageInputPrice(imageRatio.multiply(inputPrice).setScale(2, RoundingMode.HALF_UP));
}
// 音频输入价格 = audio_ratio × 输入价格
if (audioRatio != null && audioRatio.compareTo(BigDecimal.ZERO) > 0) {
vo.setAudioInputPrice(audioRatio.multiply(inputPrice).setScale(2, RoundingMode.HALF_UP));
}
// 音频补全价格 = audio_completion_ratio × 音频输入价格
if (audioCompletionRatio != null && audioCompletionRatio.compareTo(BigDecimal.ZERO) > 0 && vo.getAudioInputPrice() != null) {
vo.setAudioCompletionPrice(audioCompletionRatio.multiply(vo.getAudioInputPrice()).setScale(2, RoundingMode.HALF_UP));
}
} }
} }
...@@ -473,7 +488,7 @@ public class AppAiModelController { ...@@ -473,7 +488,7 @@ public class AppAiModelController {
/** /**
* 解析分档计费表达式 * 解析分档计费表达式
* 格式: (条件1 ? tier("档位1", ...) : 条件2 ? tier("档位2", ...) : tier("档位3", ...)) * (条件 ? 倍率 : 1) * ... * 格式: (条件1 ? tier("档位1", p*x + c*y + cr*a + cc*b + ...) : 条件2 ? tier("档位2", ...) : tier("档位3", ...)) * (条件 ? 倍率 : 1) * ...
*/ */
private List<AppModelPricingVO.TierVO> parseTieredExpr(String billingExpr, BigDecimal groupRatio) { private List<AppModelPricingVO.TierVO> parseTieredExpr(String billingExpr, BigDecimal groupRatio) {
List<AppModelPricingVO.TierVO> tiers = new java.util.ArrayList<>(); List<AppModelPricingVO.TierVO> tiers = new java.util.ArrayList<>();
...@@ -511,9 +526,9 @@ public class AppAiModelController { ...@@ -511,9 +526,9 @@ public class AppAiModelController {
// 提取分档表达式部分(从开头到最后一个 tier(...) 结束) // 提取分档表达式部分(从开头到最后一个 tier(...) 结束)
String tierExpr = billingExpr.substring(0, lastTierEnd); String tierExpr = billingExpr.substring(0, lastTierEnd);
// 找到所有 tier("名称", p * x + c * y) 的位置 // 匹配 tier("名称", 参数部分) 的正则
java.util.regex.Pattern tierPattern = java.util.regex.Pattern.compile( java.util.regex.Pattern tierPattern = java.util.regex.Pattern.compile(
"tier\\s*\\(\\s*\"([^\"]+)\"\\s*,\\s*p\\s*\\*\\s*([\\d.]+)\\s*\\+\\s*c\\s*\\*\\s*([\\d.]+)\\s*\\)" "tier\\s*\\(\\s*\"([^\"]+)\"\\s*,\\s*((?:[^)]+))\\s*\\)"
); );
java.util.regex.Matcher tierMatcher = tierPattern.matcher(tierExpr); java.util.regex.Matcher tierMatcher = tierPattern.matcher(tierExpr);
...@@ -532,8 +547,10 @@ public class AppAiModelController { ...@@ -532,8 +547,10 @@ public class AppAiModelController {
AppModelPricingVO.TierVO tier = new AppModelPricingVO.TierVO(); AppModelPricingVO.TierVO tier = new AppModelPricingVO.TierVO();
java.util.regex.MatchResult mr = tierMatches.get(i); java.util.regex.MatchResult mr = tierMatches.get(i);
tier.setName(mr.group(1)); tier.setName(mr.group(1));
tier.setInputRatio(new BigDecimal(mr.group(2)).setScale(4, RoundingMode.HALF_UP));
tier.setOutputRatio(new BigDecimal(mr.group(3)).setScale(4, RoundingMode.HALF_UP)); // 解析参数部分,提取各倍率
String params = mr.group(2);
parseTierParams(tier, params);
// 提取条件:从上一个 tier 结束(或表达式开头)到当前 tier 开始的 ? 之前 // 提取条件:从上一个 tier 结束(或表达式开头)到当前 tier 开始的 ? 之前
int tierStart = mr.start(); int tierStart = mr.start();
...@@ -572,6 +589,79 @@ public class AppAiModelController { ...@@ -572,6 +589,79 @@ public class AppAiModelController {
} }
/** /**
* 解析 tier 参数部分,提取各扩展价格倍率
* 格式: p * x + c * y + cr * a + cc * b + cc1h * c1 + img * d + img_o * e + ai * f + ao * g
*/
private void parseTierParams(AppModelPricingVO.TierVO tier, String params) {
if (params == null || params.isEmpty()) {
return;
}
// 提取 p * x
java.util.regex.Pattern pPattern = java.util.regex.Pattern.compile("p\\s*\\*\\s*([\\d.]+)");
java.util.regex.Matcher pMatcher = pPattern.matcher(params);
if (pMatcher.find()) {
tier.setInputRatio(new BigDecimal(pMatcher.group(1)).setScale(4, RoundingMode.HALF_UP));
}
// 提取 c * x
java.util.regex.Pattern cPattern = java.util.regex.Pattern.compile("c\\s*\\*\\s*([\\d.]+)");
java.util.regex.Matcher cMatcher = cPattern.matcher(params);
if (cMatcher.find()) {
tier.setOutputRatio(new BigDecimal(cMatcher.group(1)).setScale(4, RoundingMode.HALF_UP));
}
// 提取 cr * x (缓存读取)
java.util.regex.Pattern crPattern = java.util.regex.Pattern.compile("cr\\s*\\*\\s*([\\d.]+)");
java.util.regex.Matcher crMatcher = crPattern.matcher(params);
if (crMatcher.find()) {
tier.setCacheReadRatio(new BigDecimal(crMatcher.group(1)).setScale(4, RoundingMode.HALF_UP));
}
// 提取 cc * x (缓存创建 5分钟)
java.util.regex.Pattern ccPattern = java.util.regex.Pattern.compile("cc\\s*\\*\\s*([\\d.]+)");
java.util.regex.Matcher ccMatcher = ccPattern.matcher(params);
if (ccMatcher.find()) {
tier.setCacheCreateRatio(new BigDecimal(ccMatcher.group(1)).setScale(4, RoundingMode.HALF_UP));
}
// 提取 cc1h * x (缓存创建 1小时)
java.util.regex.Pattern cc1hPattern = java.util.regex.Pattern.compile("cc1h\\s*\\*\\s*([\\d.]+)");
java.util.regex.Matcher cc1hMatcher = cc1hPattern.matcher(params);
if (cc1hMatcher.find()) {
tier.setCacheCreate1hRatio(new BigDecimal(cc1hMatcher.group(1)).setScale(4, RoundingMode.HALF_UP));
}
// 提取 img * x (图片输入)
java.util.regex.Pattern imgPattern = java.util.regex.Pattern.compile("img\\s*\\*\\s*([\\d.]+)");
java.util.regex.Matcher imgMatcher = imgPattern.matcher(params);
if (imgMatcher.find()) {
tier.setImageInputRatio(new BigDecimal(imgMatcher.group(1)).setScale(4, RoundingMode.HALF_UP));
}
// 提取 img_o * x (图片输出)
java.util.regex.Pattern img_oPattern = java.util.regex.Pattern.compile("img_o\\s*\\*\\s*([\\d.]+)");
java.util.regex.Matcher img_oMatcher = img_oPattern.matcher(params);
if (img_oMatcher.find()) {
tier.setImageOutputRatio(new BigDecimal(img_oMatcher.group(1)).setScale(4, RoundingMode.HALF_UP));
}
// 提取 ai * x (音频输入)
java.util.regex.Pattern aiPattern = java.util.regex.Pattern.compile("ai\\s*\\*\\s*([\\d.]+)");
java.util.regex.Matcher aiMatcher = aiPattern.matcher(params);
if (aiMatcher.find()) {
tier.setAudioInputRatio(new BigDecimal(aiMatcher.group(1)).setScale(4, RoundingMode.HALF_UP));
}
// 提取 ao * x (音频输出)
java.util.regex.Pattern aoPattern = java.util.regex.Pattern.compile("ao\\s*\\*\\s*([\\d.]+)");
java.util.regex.Matcher aoMatcher = aoPattern.matcher(params);
if (aoMatcher.find()) {
tier.setAudioOutputRatio(new BigDecimal(aoMatcher.group(1)).setScale(4, RoundingMode.HALF_UP));
}
}
/**
* 简化条件描述 * 简化条件描述
*/ */
private String simplifyCondition(String condition) { private String simplifyCondition(String condition) {
......
...@@ -62,6 +62,15 @@ public class AppModelPricingVO { ...@@ -62,6 +62,15 @@ public class AppModelPricingVO {
@Schema(description = "缓存创建价格(元/1k tokens),已乘 groupRatio") @Schema(description = "缓存创建价格(元/1k tokens),已乘 groupRatio")
private BigDecimal cacheCreatePrice; private BigDecimal cacheCreatePrice;
@Schema(description = "图片输入价格(元/1k tokens),已乘 groupRatio")
private BigDecimal imageInputPrice;
@Schema(description = "音频输入价格(元/1k tokens),已乘 groupRatio")
private BigDecimal audioInputPrice;
@Schema(description = "音频补全价格(元/1k tokens),已乘 groupRatio")
private BigDecimal audioCompletionPrice;
@Schema(description = "状态:1-启用,0-禁用") @Schema(description = "状态:1-启用,0-禁用")
private Integer status; private Integer status;
...@@ -97,6 +106,21 @@ public class AppModelPricingVO { ...@@ -97,6 +106,21 @@ public class AppModelPricingVO {
private BigDecimal outputRatio; private BigDecimal outputRatio;
@Schema(description = "档位条件描述") @Schema(description = "档位条件描述")
private String conditionDesc; private String conditionDesc;
// 扩展价格倍率
@Schema(description = "缓存读取倍率")
private BigDecimal cacheReadRatio;
@Schema(description = "缓存创建倍率(5分钟)")
private BigDecimal cacheCreateRatio;
@Schema(description = "缓存创建倍率(1小时)")
private BigDecimal cacheCreate1hRatio;
@Schema(description = "图片输入倍率")
private BigDecimal imageInputRatio;
@Schema(description = "图片输出倍率")
private BigDecimal imageOutputRatio;
@Schema(description = "音频输入倍率")
private BigDecimal audioInputRatio;
@Schema(description = "音频输出倍率")
private BigDecimal audioOutputRatio;
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment