feat(import): persist official model release metadata

This commit is contained in:
phamnazage-jpg
2026-05-13 21:46:30 +08:00
parent b9ca312366
commit efc3d5cdbd
4 changed files with 120 additions and 11 deletions

View File

@@ -9,6 +9,7 @@ import (
"log"
"os"
"strings"
"time"
_ "github.com/lib/pq"
)
@@ -48,10 +49,22 @@ type ModelPricing struct {
ContextLength int
IsFree bool
SourceURL string
ReleaseDate string
Modality string
SceneTags []string
}
func releaseDateValue(raw string) time.Time {
if strings.TrimSpace(raw) == "" {
return time.Now()
}
parsed, err := time.Parse("2006-01-02", raw)
if err != nil {
return time.Now()
}
return parsed
}
func parseZhipuPrice(s string) float64 {
// Extract price from strings like "6元", "免费", "限时免费"
if strings.Contains(s, "免费") {
@@ -188,16 +201,24 @@ func main() {
var modelID int64
err = db.QueryRow("SELECT id FROM models WHERE external_id = $1", p.ModelID).Scan(&modelID)
if err == sql.ErrNoRows {
err = db.QueryRow(
`INSERT INTO models (external_id, name, provider_id, modality, context_length, status, source, batch_id)
VALUES ($1, $2, $3, $4, $5, 'active', $6, $7) RETURNING id`,
p.ModelID, p.ModelName, providerID, p.Modality, p.ContextLength, p.OperatorName, batchID,
).Scan(&modelID)
err = db.QueryRow(
`INSERT INTO models (external_id, name, provider_id, modality, context_length, status, source, batch_id, source_url, release_date)
VALUES ($1, $2, $3, $4, $5, 'active', $6, $7, $8, $9) RETURNING id`,
p.ModelID, p.ModelName, providerID, p.Modality, p.ContextLength, p.OperatorName, batchID, p.SourceURL, releaseDateValue(p.ReleaseDate),
).Scan(&modelID)
}
if err != nil {
log.Printf("Model error: %v", err)
continue
}
_, _ = db.Exec(
`UPDATE models
SET source_url = COALESCE(NULLIF(source_url, ''), $2),
release_date = COALESCE(release_date, $3),
updated_at = CURRENT_TIMESTAMP
WHERE id = $1`,
modelID, p.SourceURL, releaseDateValue(p.ReleaseDate),
)
// Insert pricing
sourceType := p.OperatorType