feat(importers): add official pricing importers for baichuan lingyiwanwu sensenova and xfyun
This commit is contained in:
64
scripts/import_baichuan_pricing_test.go
Normal file
64
scripts/import_baichuan_pricing_test.go
Normal file
@@ -0,0 +1,64 @@
|
||||
//go:build llm_script
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestParseBaichuanPricingCatalogBuildsRecords(t *testing.T) {
|
||||
raw, err := os.ReadFile(filepath.Join("testdata", "baichuan_pricing_sample.txt"))
|
||||
if err != nil {
|
||||
t.Fatalf("读取 fixture 失败: %v", err)
|
||||
}
|
||||
|
||||
records, err := parseBaichuanPricingCatalog(string(raw))
|
||||
if err != nil {
|
||||
t.Fatalf("parseBaichuanPricingCatalog 返回错误: %v", err)
|
||||
}
|
||||
if len(records) != 11 {
|
||||
t.Fatalf("期望 11 条百川价格记录,实际 %d", len(records))
|
||||
}
|
||||
if records[0].ModelID != "baichuan-baichuan-m3-plus" {
|
||||
t.Fatalf("首条 modelID 错误: %q", records[0].ModelID)
|
||||
}
|
||||
if records[0].InputPrice != 5 || records[0].OutputPrice != 9 {
|
||||
t.Fatalf("Baichuan-M3-Plus 定价错误: %v / %v", records[0].InputPrice, records[0].OutputPrice)
|
||||
}
|
||||
if records[4].InputPrice != 15 || records[4].OutputPrice != 15 {
|
||||
t.Fatalf("Baichuan4-Turbo blended 定价错误: %v / %v", records[4].InputPrice, records[4].OutputPrice)
|
||||
}
|
||||
if records[8].ContextLength != 128000 {
|
||||
t.Fatalf("Baichuan3-Turbo-128k context 错误: %d", records[8].ContextLength)
|
||||
}
|
||||
if records[10].InputPrice != 10 || records[10].OutputPrice != 10 {
|
||||
t.Fatalf("Baichuan2-53B 基线定价错误: %v / %v", records[10].InputPrice, records[10].OutputPrice)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunBaichuanPricingImportDryRunPrintsSummary(t *testing.T) {
|
||||
var out bytes.Buffer
|
||||
err := runBaichuanPricingImport(baichuanPricingImportConfig{
|
||||
URL: defaultBaichuanPricingURL,
|
||||
Fixture: filepath.Join("testdata", "baichuan_pricing_sample.txt"),
|
||||
DryRun: true,
|
||||
}, nil, &out)
|
||||
if err != nil {
|
||||
t.Fatalf("runBaichuanPricingImport 返回错误: %v", err)
|
||||
}
|
||||
output := out.String()
|
||||
for _, want := range []string{
|
||||
"source=baichuan-pricing-import",
|
||||
"models=11",
|
||||
"operator=Baichuan API",
|
||||
"dry_run=true",
|
||||
} {
|
||||
if !strings.Contains(output, want) {
|
||||
t.Fatalf("输出缺少 %q,实际: %q", want, output)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user