Files
llm-intelligence/scripts/ucloud_pricing_lib.go
phamnazage-jpg 958245537a 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.
2026-05-15 22:32:57 +08:00

59 lines
1.9 KiB
Go

//go:build llm_script
package main
import (
"fmt"
"regexp"
"strings"
)
const defaultUCloudPricingURL = "https://www.ucloud-global.com/en/docs/modelverse/price"
var ucloudPricePattern = regexp.MustCompile(`([A-Za-z0-9._/-]+)\s+Input\s+([\d.]+)\s+CNY/(?:million|1K)\s+tokens,\s+Output\s+([\d.]+)\s+CNY/(?:million|1K)\s+tokens`)
func parseUCloudPricingCatalog(raw string) ([]officialPricingRecord, error) {
matches := ucloudPricePattern.FindAllStringSubmatch(raw, -1)
if len(matches) == 0 {
return nil, fmt.Errorf("unexpected ucloud 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 := mustParseSubscriptionPrice(match[2])
outputPrice := mustParseSubscriptionPrice(match[3])
if strings.Contains(strings.ToLower(match[0]), "/1k") {
inputPrice *= 1000
outputPrice *= 1000
}
record := officialPricingRecord{
ModelID: normalizeExternalID("ucloud", modelName),
ModelName: modelName,
ProviderName: providerName,
ProviderNameCn: providerNameCn,
ProviderCountry: providerCountry,
ProviderWebsite: providerWebsite,
OperatorName: "UModelVerse",
OperatorNameCn: "UModelVerse",
OperatorCountry: "CN",
OperatorWebsite: "https://www.ucloud.cn",
OperatorType: "cloud",
Region: "CN",
Currency: "CNY",
InputPrice: inputPrice,
OutputPrice: outputPrice,
SourceURL: defaultUCloudPricingURL,
ModelSourceURL: defaultUCloudPricingURL,
DateConfidence: "unknown",
DateSourceKind: "official_product_page",
Modality: detectModality(modelName),
}
record.IsFree = record.InputPrice == 0 && record.OutputPrice == 0
records = append(records, record)
}
return records, nil
}