feat(import): persist official model release metadata
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"database/sql"
|
||||
"log"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
_ "github.com/lib/pq"
|
||||
)
|
||||
@@ -24,10 +25,22 @@ type ModelPricing struct {
|
||||
ContextLength int
|
||||
IsFree bool
|
||||
SourceURL string
|
||||
ReleaseDate string
|
||||
Modality string
|
||||
SceneTags []string
|
||||
}
|
||||
|
||||
func releaseDateValue(raw string) time.Time {
|
||||
if raw == "" {
|
||||
return time.Now()
|
||||
}
|
||||
parsed, err := time.Parse("2006-01-02", raw)
|
||||
if err != nil {
|
||||
return time.Now()
|
||||
}
|
||||
return parsed
|
||||
}
|
||||
|
||||
func main() {
|
||||
dsn := os.Getenv("DATABASE_URL")
|
||||
if dsn == "" {
|
||||
@@ -146,15 +159,23 @@ func main() {
|
||||
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,
|
||||
`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 for %s: %v", p.ModelID, 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
|
||||
|
||||
Reference in New Issue
Block a user