fix(minimax): preserve discovered model ids

This commit is contained in:
octo-patch committed 2026-10-29 01:34:13 +08:00
1 parent f9718c5552
commit 03c8dacd0a
3 files changed
+13 -72

No files matched your search

+1 -1
View File
@@ -78,7 +78,7 @@ func fetchModelListingAt(ctx context.Context, e *config.ProviderEntry, client *h
Client: client,
})
if err == nil {
return currentMiniMaxChoices(models, e), u, nil
return models, u, nil
}
lastErr = err
if !openai.IsModelFetchEndpointMiss(err) && firstHardErr == nil {
-50
View File
@@ -1,50 +0,0 @@
package catalog
import (
"slices"
"strings"
"reasonix/internal/contract/config"
"reasonix/internal/model/openai"
)
// currentMiniMaxChoices filters discovered text choices while keeping explicit
// saved IDs selectable. It does not change the persisted configuration.
func currentMiniMaxChoices(models []openai.ListedModel, entry *config.ProviderEntry) []openai.ListedModel {
out := make([]openai.ListedModel, 0, len(models))
var positions []int
var current []openai.ListedModel
for _, model := range models {
leaf := strings.ToLower(model.ID)
if i := strings.LastIndexByte(leaf, '/'); i >= 0 {
leaf = leaf[i+1:]
}
leaf = strings.TrimSuffix(strings.TrimSuffix(leaf, ":free"), "-free")
active := leaf == "minimax-m3.1-flash" || leaf == "minimax-m3"
series := strings.TrimPrefix(leaf, "minimax-m")
text := leaf == "minimax-text-01" || (series != leaf && len(series) > 0 && series[0] >= '0' && series[0] <= '9')
if text && !active && !entry.HasModel(model.ID) {
continue
}
if active {
positions = append(positions, len(out))
current = append(current, model)
}
out = append(out, model)
}
// Reorder only active MiniMax slots; other vendors retain their positions.
slices.SortStableFunc(current, func(a, b openai.ListedModel) int {
return strings.Compare(flashOrder(a.ID), flashOrder(b.ID))
})
for i, pos := range positions {
out[pos] = current[i]
}
return out
}
func flashOrder(id string) string {
if strings.Contains(strings.ToLower(id), "minimax-m3.1-flash") {
return "0"
}
return "1"
}
+12 -21
View File
@@ -5,35 +5,26 @@ import (
"io"
"net/http"
"net/http/httptest"
"slices"
"reflect"
"testing"
"reasonix/internal/contract/config"
)
func TestMiniMaxDiscoveryFiltersTextAndPreservesSavedAndMedia(t *testing.T) {
func TestMiniMaxDiscoveryPassesUnknownModelsThrough(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
_, _ = io.WriteString(w, `{"data":[{"id":"other-model"},{"id":"MiniMax-M2.7"},{"id":"MiniMax-M3"},{"id":"MiniMax-M3.1-Flash"},{"id":"minimax/minimax-m2.5"},{"id":"minimax-music-2.5"},{"id":"speech-2.8-hd"},{"id":"image-01"}]}`)
_, _ = io.WriteString(w, `{"data":[{"id":"MiniMax-M3"},{"id":"MiniMax-M3.1-Flash"},{"id":"MiniMax-M3.2"},{"id":"MiniMax-M4"}]}`)
}))
defer srv.Close()
for _, saved := range []string{"", "MiniMax-M2.7"} {
entry := &config.ProviderEntry{Name: "fixture", Kind: "openai", BaseURL: srv.URL, Model: saved}
entryWithKey := entry.WithAPIKeyForProbe("test-key")
got, err := FetchModelsVia(context.Background(), &entryWithKey, srv.Client())
if err != nil {
t.Fatal(err)
}
if slices.Contains(got, "minimax/minimax-m2.5") || slices.Contains(got, "MiniMax-M2.7") != (saved != "") {
t.Fatalf("discovery did not distinguish ordinary and saved models: %v", got)
}
if slices.Index(got, "MiniMax-M3.1-Flash") > slices.Index(got, "MiniMax-M3") {
t.Fatalf("Flash must precede M3: %v", got)
}
for _, model := range []string{"other-model", "minimax-music-2.5", "speech-2.8-hd", "image-01"} {
if !slices.Contains(got, model) {
t.Errorf("discovery removed unrelated model %s", model)
}
}
entry := &config.ProviderEntry{Name: "fixture", Kind: "openai", BaseURL: srv.URL}
entryWithKey := entry.WithAPIKeyForProbe("test-key")
got, err := FetchModelsVia(context.Background(), &entryWithKey, srv.Client())
if err != nil {
t.Fatal(err)
}
want := []string{"MiniMax-M3", "MiniMax-M3.1-Flash", "MiniMax-M3.2", "MiniMax-M4"}
if !reflect.DeepEqual(got, want) {
t.Fatalf("discovered models = %v, want %v", got, want)
}
}