Files
llm-intelligence/scripts/ppio_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

65 lines
2.1 KiB
Go

//go:build llm_script
package main
import (
"fmt"
"regexp"
"strings"
)
const defaultPPIOPricingURL = "https://resource.ppio.com/pricing?type=enterprise"
var ppioBlockPattern = regexp.MustCompile(`(?s)([a-z0-9._/-]+)\n([\d,]+)\n(.*?)在线体验`)
var ppioPricePattern = regexp.MustCompile(`(?s)¥\s*([\d.]+)\s*/\s*Mt`)
func parsePPIOPricingCatalog(raw string) ([]officialPricingRecord, error) {
matches := ppioBlockPattern.FindAllStringSubmatch(raw, -1)
records := make([]officialPricingRecord, 0, len(matches))
for _, match := range matches {
modelLine := strings.TrimSpace(match[1])
contextLength := parseContextLengthCommon(match[2])
section := match[3]
if strings.Contains(section, "阶梯计费") {
continue
}
priceMatches := ppioPricePattern.FindAllStringSubmatch(section, -1)
if len(priceMatches) < 2 {
continue
}
inputPrice := mustParseSubscriptionPrice(priceMatches[len(priceMatches)-2][1])
outputPrice := mustParseSubscriptionPrice(priceMatches[len(priceMatches)-1][1])
providerName := providerFromModelPath(modelLine)
providerNameCn, providerCountry, providerWebsite := providerMetadata(providerName)
record := officialPricingRecord{
ModelID: normalizeExternalID("ppio", modelLine),
ModelName: modelLine,
ProviderName: providerName,
ProviderNameCn: providerNameCn,
ProviderCountry: providerCountry,
ProviderWebsite: providerWebsite,
OperatorName: "PPIO Model API",
OperatorNameCn: "PPIO 模型 API",
OperatorCountry: "CN",
OperatorWebsite: "https://ppinfra.com",
OperatorType: "relay",
Region: "CN",
Currency: "CNY",
InputPrice: inputPrice,
OutputPrice: outputPrice,
ContextLength: contextLength,
SourceURL: defaultPPIOPricingURL,
ModelSourceURL: defaultPPIOPricingURL,
DateConfidence: "unknown",
DateSourceKind: "official_product_page",
Modality: detectModality(modelLine),
}
record.IsFree = record.InputPrice == 0 && record.OutputPrice == 0
records = append(records, record)
}
if len(records) == 0 {
return nil, fmt.Errorf("unexpected ppio pricing content")
}
return records, nil
}