1
0
mirror of https://github.com/coalaura/whiskr.git synced 2025-09-09 01:09:54 +00:00
Files
whiskr/models.go
2025-08-11 00:15:58 +02:00

96 lines
1.7 KiB
Go

package main
import (
"context"
"sort"
"strings"
"github.com/revrost/go-openrouter"
)
type Model struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Tags []string `json:"tags,omitempty"`
Reasoning bool `json:"-"`
JSON bool `json:"-"`
}
var ModelMap = make(map[string]*Model)
func LoadModels() ([]*Model, error) {
client := OpenRouterClient()
list, err := client.ListUserModels(context.Background())
if err != nil {
return nil, err
}
sort.Slice(list, func(i, j int) bool {
return list[i].Created > list[j].Created
})
models := make([]*Model, len(list))
for index, model := range list {
name := model.Name
if index := strings.Index(name, ": "); index != -1 {
name = name[index+2:]
}
tags, reasoning, json := GetModelTags(model)
m := &Model{
ID: model.ID,
Name: name,
Description: model.Description,
Tags: tags,
Reasoning: reasoning,
JSON: json,
}
models[index] = m
ModelMap[model.ID] = m
}
return models, nil
}
func GetModelTags(model openrouter.Model) ([]string, bool, bool) {
var (
reasoning bool
json bool
tags []string
)
for _, parameter := range model.SupportedParameters {
switch parameter {
case "reasoning":
reasoning = true
tags = append(tags, "reasoning")
case "response_format":
json = true
tags = append(tags, "json")
case "tools":
tags = append(tags, "tools")
}
}
for _, modality := range model.Architecture.InputModalities {
if modality == "image" {
tags = append(tags, "vision")
}
}
sort.Strings(tags)
return tags, reasoning, json
}