Skip to content

Commit a75405e

Browse files
authored
fix(openrouter): sort models by name to be more deterministic (#64)
* fix(openrouter): sort models by name to be more deterministic Looks like OpenRouter returns models at a random order. Sort by name to make the process of generating `openrouter.json` more deterministic. Changes between runs can still happen, specially when it comes to cost, but the diff will be small and easier to review. * chore: add a taskfile * chore: re-generate `openrouter.json` with sorted name
1 parent 08db194 commit a75405e

File tree

3 files changed

+1368
-1296
lines changed

3 files changed

+1368
-1296
lines changed

Taskfile.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
version: '3'
2+
3+
tasks:
4+
generate:
5+
desc: Generate OpenRouter models
6+
aliases: [gen]
7+
cmds:
8+
- go run cmd/openrouter/main.go
9+
10+
lint:
11+
desc: Run linters
12+
cmds:
13+
- golangci-lint run ./...
14+
15+
lint:fix:
16+
desc: Run linters and fix issues
17+
cmds:
18+
- golangci-lint run --fix ./...
19+
20+
fmt:
21+
desc: Format code
22+
cmds:
23+
- go fmt ./...
24+
25+
modernize:
26+
desc: Modernize code
27+
cmds:
28+
- modernize ./...

cmd/openrouter/main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"os"
1313
"slices"
1414
"strconv"
15+
"strings"
1516
"time"
1617

1718
"github.com/charmbracelet/catwalk/pkg/catwalk"
@@ -358,6 +359,10 @@ func main() {
358359
model.ID, bestEndpoint.ContextLength, bestEndpoint.ProviderName)
359360
}
360361

362+
slices.SortFunc(openRouterProvider.Models, func(a catwalk.Model, b catwalk.Model) int {
363+
return strings.Compare(a.Name, b.Name)
364+
})
365+
361366
// save the json in internal/providers/config/openrouter.json
362367
data, err := json.MarshalIndent(openRouterProvider, "", " ")
363368
if err != nil {

0 commit comments

Comments
 (0)