65 lines
2.1 KiB
Go
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
|
||
|
|
}
|