feat(imports): add real pricing and subscription collectors

Add plan catalog and subscription schema support, seed baselines, and real importers for core domestic subscriptions plus stable official pricing sources.

This commit also hardens the shared fetch layers so the importers can support live collection and database writes instead of relying on manual placeholders alone.
This commit is contained in:
phamnazage-jpg
2026-05-15 22:32:57 +08:00
parent dd58c18fe3
commit 958245537a
91 changed files with 10474 additions and 1 deletions

View File

@@ -0,0 +1,61 @@
//go:build llm_script
package main
import (
"fmt"
"regexp"
"strings"
)
const defaultSiliconFlowPricingURL = "https://siliconflow.cn/pricing"
var siliconFlowCardPattern = regexp.MustCompile(`(?s)([A-Za-z0-9._/-]+)\n输入 \(元 / M tokens\)\n输出 \(元 / M tokens\)\n(免费|[\d.]+)\n(免费|[\d.]+)`)
func parseSiliconFlowPricingCatalog(raw string) ([]officialPricingRecord, error) {
matches := siliconFlowCardPattern.FindAllStringSubmatch(raw, -1)
if len(matches) == 0 {
return nil, fmt.Errorf("unexpected siliconflow pricing content")
}
records := make([]officialPricingRecord, 0, len(matches))
for _, match := range matches {
modelName := strings.TrimSpace(match[1])
providerName := providerFromModelPath(modelName)
providerNameCn, providerCountry, providerWebsite := providerMetadata(providerName)
inputPrice := parseSiliconFlowPrice(match[2])
outputPrice := parseSiliconFlowPrice(match[3])
record := officialPricingRecord{
ModelID: normalizeExternalID("siliconflow", modelName),
ModelName: modelName,
ProviderName: providerName,
ProviderNameCn: providerNameCn,
ProviderCountry: providerCountry,
ProviderWebsite: providerWebsite,
OperatorName: "SiliconCloud",
OperatorNameCn: "SiliconCloud",
OperatorCountry: "CN",
OperatorWebsite: "https://siliconflow.cn",
OperatorType: "relay",
Region: "CN",
Currency: "CNY",
InputPrice: inputPrice,
OutputPrice: outputPrice,
SourceURL: defaultSiliconFlowPricingURL,
ModelSourceURL: defaultSiliconFlowPricingURL,
DateConfidence: "unknown",
DateSourceKind: "official_product_page",
Modality: detectModality(modelName),
}
record.IsFree = record.InputPrice == 0 && record.OutputPrice == 0
records = append(records, record)
}
return records, nil
}
func parseSiliconFlowPrice(raw string) float64 {
if strings.TrimSpace(raw) == "免费" {
return 0
}
return mustParseSubscriptionPrice(raw)
}