forked from niuniu/llm-intelligence
feat(importers): add official pricing importers for baichuan lingyiwanwu sensenova and xfyun
This commit is contained in:
61
scripts/import_xfyun_pricing_test.go
Normal file
61
scripts/import_xfyun_pricing_test.go
Normal file
@@ -0,0 +1,61 @@
|
||||
//go:build llm_script
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestParseXfyunPricingCatalogBuildsRecords(t *testing.T) {
|
||||
raw, err := os.ReadFile(filepath.Join("testdata", "xfyun_pricing_sample.html"))
|
||||
if err != nil {
|
||||
t.Fatalf("读取 fixture 失败: %v", err)
|
||||
}
|
||||
|
||||
records, err := parseXfyunPricingCatalog(string(raw))
|
||||
if err != nil {
|
||||
t.Fatalf("parseXfyunPricingCatalog 返回错误: %v", err)
|
||||
}
|
||||
if len(records) != 4 {
|
||||
t.Fatalf("期望 4 条讯飞价格记录,实际 %d", len(records))
|
||||
}
|
||||
if records[0].ModelID != "xfyun-spark-x2-x1-5" {
|
||||
t.Fatalf("首条 modelID 错误: %q", records[0].ModelID)
|
||||
}
|
||||
if records[0].InputPrice != 2 || records[0].OutputPrice != 2 {
|
||||
t.Fatalf("Spark X2/X1.5 定价错误: %v / %v", records[0].InputPrice, records[0].OutputPrice)
|
||||
}
|
||||
if records[1].ModelName != "Spark Ultra" || records[1].InputPrice != 0.8 {
|
||||
t.Fatalf("Spark Ultra 解析错误: %+v", records[1])
|
||||
}
|
||||
if !records[3].IsFree || records[3].InputPrice != 0 || records[3].OutputPrice != 0 {
|
||||
t.Fatalf("Spark Lite 免费定价错误: %+v", records[3])
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunXfyunPricingImportDryRunPrintsSummary(t *testing.T) {
|
||||
var out bytes.Buffer
|
||||
err := runXfyunPricingImport(xfyunPricingImportConfig{
|
||||
URL: defaultXfyunPricingURL,
|
||||
Fixture: filepath.Join("testdata", "xfyun_pricing_sample.html"),
|
||||
DryRun: true,
|
||||
}, nil, &out)
|
||||
if err != nil {
|
||||
t.Fatalf("runXfyunPricingImport 返回错误: %v", err)
|
||||
}
|
||||
output := out.String()
|
||||
for _, want := range []string{
|
||||
"source=xfyun-pricing-import",
|
||||
"models=4",
|
||||
"operator=Spark API",
|
||||
"dry_run=true",
|
||||
} {
|
||||
if !strings.Contains(output, want) {
|
||||
t.Fatalf("输出缺少 %q,实际: %q", want, output)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user