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