Documentation
¶
Overview ¶
Package modelname parses AI model IDs and display names into parts you can compare.
Every lab names things a little differently. Anthropic used to write claude-3-5-sonnet and now writes claude-sonnet-4-5. OpenAI uses dots, OpenRouter puts the vendor in front, Mistral and DeepSeek tack a date code on the end. Parse reads all of those and gives back the same shape, so "claude-3-5-sonnet-20241022" and "Claude Sonnet 4.5" both land in the claude-sonnet family.
m := modelname.Parse("anthropic/claude-sonnet-4-5")
m.Vendor // "anthropic"
m.Family // "claude-sonnet"
m.Version // "4.5"
It's heuristic, not a registry. Most of the test cases are names listed at https://whizi.io/models/, which is a handy place to see what's out there right now.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Compare ¶
Compare orders two models from the same family, oldest first. It returns -1 if a is older, 1 if a is newer and 0 if it can't tell them apart.
Version wins, then the full date, then the short date code. Comparing across families works but doesn't mean much: gpt-5 vs claude-sonnet-4.5 just compares 5 with 4.5.
func Latest ¶
Latest returns the newest ID in ids whose family matches. Handy for picking a default out of a provider's /models list.
Example ¶
package main
import (
"fmt"
"github.com/BoNour/modelname"
)
func main() {
ids := []string{"claude-sonnet-4-5", "claude-3-7-sonnet-20250219", "claude-sonnet-4-6", "gpt-5"}
id, _ := modelname.Latest(ids, "claude-sonnet")
fmt.Println(id)
}
Output: claude-sonnet-4-6
Types ¶
type Model ¶
type Model struct {
ID string // the input, unchanged
Vendor string // "anthropic", "openai", ... or "" if unknown
Family string // name words joined with "-", e.g. "gemini-flash-lite"
Version string // "4.5", "4o", "k2.7"
Size string // parameter count if given: "70b", "35b-a3b"
Date time.Time // only set for full dates like 20241022
Snapshot string // short date codes like "0731" or "2512"
Tags []string // "preview", "latest", "thinking", ...
}
Model is a parsed model name. Fields that weren't in the name are empty.
func Parse ¶
Parse splits a model ID or display name into its parts. It never fails; anything it doesn't recognise ends up in Family.
Example ¶
package main
import (
"fmt"
"github.com/BoNour/modelname"
)
func main() {
m := modelname.Parse("claude-opus-4-1-20250805")
fmt.Println(m.Vendor, m.Family, m.Version, m.Date.Format("2006-01-02"))
}
Output: anthropic claude-opus 4.1 2025-08-05