forked from niuniu/llm-intelligence
fix(tencent): detect promotional token plans
Relax the Tencent catalog plan matcher so monthly promotional plans are parsed by structure instead of a hard-coded plan-name list. This keeps first-month promotional packages in the catalog and adds a regression sample plus parser test coverage.
This commit is contained in:
@@ -188,22 +188,7 @@ func extractSeriesHeading(line string) string {
|
||||
}
|
||||
|
||||
func tryParseTencentPlan(lines []string, start int, series string) (tencentPlan, int, bool) {
|
||||
if start+4 >= len(lines) {
|
||||
return tencentPlan{}, start, false
|
||||
}
|
||||
if !isTencentPlanName(lines[start]) {
|
||||
return tencentPlan{}, start, false
|
||||
}
|
||||
if !isTencentPlanTier(lines[start+1]) {
|
||||
return tencentPlan{}, start, false
|
||||
}
|
||||
if !strings.Contains(lines[start+2], "订阅月") {
|
||||
return tencentPlan{}, start, false
|
||||
}
|
||||
if !strings.Contains(lines[start+3], "Tokens") {
|
||||
return tencentPlan{}, start, false
|
||||
}
|
||||
if !strings.Contains(lines[start+4], "元/月") {
|
||||
if !looksLikeTencentPlan(lines, start) {
|
||||
return tencentPlan{}, start, false
|
||||
}
|
||||
|
||||
@@ -216,7 +201,7 @@ func tryParseTencentPlan(lines []string, start int, series string) (tencentPlan,
|
||||
}
|
||||
|
||||
nextIndex := start + 4
|
||||
if start+5 < len(lines) && !strings.HasPrefix(lines[start+5], "### ") && !isTencentPlanName(lines[start+5]) {
|
||||
if start+5 < len(lines) && !strings.HasPrefix(lines[start+5], "### ") && !looksLikeTencentPlan(lines, start+5) {
|
||||
plan.Scene = lines[start+5]
|
||||
nextIndex = start + 5
|
||||
}
|
||||
@@ -247,7 +232,7 @@ func tryParseTencentModel(lines []string, start int, series string) (tencentMode
|
||||
if strings.HasPrefix(line, "## ") || strings.HasPrefix(line, "### ") {
|
||||
break
|
||||
}
|
||||
if isTencentPlanName(line) && i+1 < len(lines) && isTencentPlanTier(lines[i+1]) {
|
||||
if looksLikeTencentPlan(lines, i) {
|
||||
break
|
||||
}
|
||||
if i+1 < len(lines) && isTencentModelID(lines[i+1]) && !isReservedTencentLine(line) {
|
||||
@@ -262,19 +247,32 @@ func tryParseTencentModel(lines []string, start int, series string) (tencentMode
|
||||
return model, nextIndex, true
|
||||
}
|
||||
|
||||
func isTencentPlanName(line string) bool {
|
||||
switch line {
|
||||
case "体验套餐", "基础套餐", "进阶套餐", "专业套餐":
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func isTencentPlanTier(line string) bool {
|
||||
return strings.HasPrefix(line, "(") && strings.HasSuffix(line, ")")
|
||||
}
|
||||
|
||||
func looksLikeTencentPlan(lines []string, start int) bool {
|
||||
if start+4 >= len(lines) {
|
||||
return false
|
||||
}
|
||||
if isReservedTencentLine(lines[start]) {
|
||||
return false
|
||||
}
|
||||
if isTencentModelID(lines[start]) {
|
||||
return false
|
||||
}
|
||||
if !isTencentPlanTier(lines[start+1]) {
|
||||
return false
|
||||
}
|
||||
if !strings.Contains(lines[start+2], "订阅月") {
|
||||
return false
|
||||
}
|
||||
if !strings.Contains(lines[start+3], "Tokens") {
|
||||
return false
|
||||
}
|
||||
return strings.Contains(lines[start+4], "元/月")
|
||||
}
|
||||
|
||||
func isReservedTencentLine(line string) bool {
|
||||
if strings.HasPrefix(line, "#") {
|
||||
return true
|
||||
|
||||
Reference in New Issue
Block a user