2025-08-05 03:56:23 +02:00
|
|
|
package main
|
|
|
|
|
2025-08-08 14:49:14 +02:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"strings"
|
|
|
|
)
|
2025-08-05 03:56:23 +02:00
|
|
|
|
|
|
|
type Model struct {
|
|
|
|
ID string `json:"id"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Description string `json:"description"`
|
|
|
|
SupportedParameters []string `json:"supported_parameters,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
var ModelMap = make(map[string]*Model)
|
|
|
|
|
|
|
|
func LoadModels() ([]*Model, error) {
|
|
|
|
client := OpenRouterClient()
|
|
|
|
|
|
|
|
list, err := client.ListUserModels(context.Background())
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
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-05 03:56:23 +02:00
|
|
|
m := &Model{
|
|
|
|
ID: model.ID,
|
2025-08-08 14:49:14 +02:00
|
|
|
Name: name,
|
2025-08-05 03:56:23 +02:00
|
|
|
Description: model.Description,
|
|
|
|
SupportedParameters: model.SupportedParameters,
|
|
|
|
}
|
|
|
|
|
|
|
|
models[index] = m
|
|
|
|
|
|
|
|
ModelMap[model.ID] = m
|
|
|
|
}
|
|
|
|
|
|
|
|
return models, nil
|
|
|
|
}
|