feat(importers): add official pricing importers for baichuan lingyiwanwu sensenova and xfyun
This commit is contained in:
64
scripts/import_lingyiwanwu_pricing_test.go
Normal file
64
scripts/import_lingyiwanwu_pricing_test.go
Normal file
@@ -0,0 +1,64 @@
|
||||
//go:build llm_script
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestParseLingyiwanwuPricingCatalogBuildsRecords(t *testing.T) {
|
||||
raw, err := os.ReadFile(filepath.Join("testdata", "lingyiwanwu_pricing_sample.txt"))
|
||||
if err != nil {
|
||||
t.Fatalf("读取 fixture 失败: %v", err)
|
||||
}
|
||||
|
||||
records, err := parseLingyiwanwuPricingCatalog(string(raw))
|
||||
if err != nil {
|
||||
t.Fatalf("parseLingyiwanwuPricingCatalog 返回错误: %v", err)
|
||||
}
|
||||
if len(records) != 2 {
|
||||
t.Fatalf("期望 2 条零一万物价格记录,实际 %d", len(records))
|
||||
}
|
||||
if records[0].ModelID != "yi-yi-lightning" {
|
||||
t.Fatalf("首条 modelID 错误: %q", records[0].ModelID)
|
||||
}
|
||||
if records[0].InputPrice != 0.99 || records[0].OutputPrice != 0.99 {
|
||||
t.Fatalf("yi-lightning 定价错误: %v / %v", records[0].InputPrice, records[0].OutputPrice)
|
||||
}
|
||||
if records[1].ContextLength != 16000 {
|
||||
t.Fatalf("yi-vision-v2 context 错误: %d", records[1].ContextLength)
|
||||
}
|
||||
if records[1].Modality != "multimodal" {
|
||||
t.Fatalf("yi-vision-v2 modality 错误: %q", records[1].Modality)
|
||||
}
|
||||
if records[1].InputPrice != 6 || records[1].OutputPrice != 6 {
|
||||
t.Fatalf("yi-vision-v2 定价错误: %v / %v", records[1].InputPrice, records[1].OutputPrice)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunLingyiwanwuPricingImportDryRunPrintsSummary(t *testing.T) {
|
||||
var out bytes.Buffer
|
||||
err := runLingyiwanwuPricingImport(lingyiwanwuPricingImportConfig{
|
||||
URL: defaultLingyiwanwuPricingURL,
|
||||
Fixture: filepath.Join("testdata", "lingyiwanwu_pricing_sample.txt"),
|
||||
DryRun: true,
|
||||
}, nil, &out)
|
||||
if err != nil {
|
||||
t.Fatalf("runLingyiwanwuPricingImport 返回错误: %v", err)
|
||||
}
|
||||
output := out.String()
|
||||
for _, want := range []string{
|
||||
"source=lingyiwanwu-pricing-import",
|
||||
"models=2",
|
||||
"operator=01.AI API",
|
||||
"dry_run=true",
|
||||
} {
|
||||
if !strings.Contains(output, want) {
|
||||
t.Fatalf("输出缺少 %q,实际: %q", want, output)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user