modelname

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 2, 2026 License: MIT Imports: 2 Imported by: 0

README

modelname

Go Reference

Parse AI model names into something you can sort.

m := modelname.Parse("claude-opus-4-1-20250805")

m.Vendor  // "anthropic"
m.Family  // "claude-opus"
m.Version // "4.1"
m.Date    // 2025-08-05

I kept writing the same regex every time a new model came out, and it broke every time a lab changed how they name things. So this is that regex, plus the fixes.

It reads API IDs (gpt-4.1-mini, meta-llama/llama-3.3-70b-instruct:free) and display names (Gemini 3.1 Pro Preview) the same way. Old and new Claude names land in the same family, so claude-3-5-sonnet and claude-sonnet-4-5 can be compared.

Install

go get github.com/BoNour/modelname

Newest in a family

ids := []string{"claude-sonnet-4-5", "claude-3-7-sonnet-20250219", "claude-sonnet-4-6"}
id, _ := modelname.Latest(ids, "claude-sonnet") // "claude-sonnet-4-6"

Compare(a, b) gives you the ordering if you want to sort a whole list.

What it won't do

It doesn't know about every model and it doesn't call any API. It's string parsing. If a name is weird enough it'll put everything in Family and leave Version empty, which is usually the right call.

Most of the test cases are real names from whizi.io/models. If you find one it gets wrong, open an issue with the name.

License

MIT

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

func Compare(a, b Model) int

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

func Latest(ids []string, family string) (string, bool)

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

func Parse(id string) Model

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL