feat(go-models): harden ListModels for FishAudio (#15853) (#15957)

### What problem does this PR solve?

Part of #15853 (provider model-list refactor). Final two providers.

- **voyage:** Voyage AI exposes no live model-list endpoint — its public
API only has `/v1/embeddings` and `/v1/rerank` — so the previous
`ListModels` was a `no such method` stub. Replace it with a
static-catalog listing sourced from the loaded provider definition,
carrying each model's `max_tokens`, `model_types`, and embedding
`dimensions`. `list models from voyage` now returns the 13-model catalog
instead of erroring.
- **fishaudio:** route the existing `/model` voice listing through the
shared `ParseListModel` helper for consistency; keep the human-readable
`title` as the model name and fall back to `_id` when a title is blank.

#### Drive-by fix
Shared gitee_test.go `DSModelList` -> `ModelList` compile fix (renamed
in #15900); auto-resolves against the sibling #15853 PRs.

### Type of change

- [x] New Feature (non-breaking change which adds functionality)
- [x] Refactoring

Co-authored-by: Haruko386 <tryeverypossible@163.com>
This commit is contained in:
Hunnyboy1217
2026-06-16 20:56:20 -07:00
committed by GitHub
parent 0aaba0033f
commit fd196f694e
2 changed files with 90 additions and 5 deletions

View File

@@ -379,14 +379,19 @@ func (f *FishAudioModel) ListModels(apiConfig *APIConfig) ([]ListModelResponse,
return nil, fmt.Errorf("failed to parse response: %w", err)
}
models := make([]ListModelResponse, 0, len(result.Items))
modelList := ModelList{Object: "list"}
for _, item := range result.Items {
models = append(models, ListModelResponse{
Name: item.Title,
})
name := strings.TrimSpace(item.Title)
if name == "" {
name = strings.TrimSpace(item.ID)
}
if name == "" {
continue
}
modelList.Models = append(modelList.Models, DSModel{ID: name})
}
return models, nil
return ParseListModel(modelList), nil
}
func (f *FishAudioModel) Balance(apiConfig *APIConfig) (map[string]interface{}, error) {

View File

@@ -0,0 +1,80 @@
//
// Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package models
import (
"io"
"net/http"
"net/http/httptest"
"testing"
)
func newFishAudioForListModelsTest(baseURL string) *FishAudioModel {
return NewFishAudioModel(map[string]string{"default": baseURL}, URLSuffix{Models: "model"})
}
func TestFishAudioListModels(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
t.Errorf("method=%s, want GET", r.Method)
}
if r.URL.Path != "/model" {
t.Errorf("path=%s, want /model", r.URL.Path)
}
if got := r.Header.Get("Authorization"); got != "Bearer test-key" {
t.Errorf("Authorization=%q, want Bearer test-key", got)
}
// Fish Audio voice catalog: each item has _id and a human-readable title.
_, _ = io.WriteString(w, `{"items":[{"_id":"abc123","title":"Energetic Male"},{"_id":"def456","title":"Calm Female"},{"_id":"ghi789","title":""}]}`)
}))
defer srv.Close()
apiKey := "test-key"
models, err := newFishAudioForListModelsTest(srv.URL).ListModels(&APIConfig{ApiKey: &apiKey})
if err != nil {
t.Fatalf("ListModels: %v", err)
}
// Blank title falls back to _id; all three are returned.
if len(models) != 3 {
t.Fatalf("len(models)=%d, want 3", len(models))
}
if models[0].Name != "Energetic Male" || models[1].Name != "Calm Female" {
t.Fatalf("titles=%v, want [Energetic Male, Calm Female]", []string{models[0].Name, models[1].Name})
}
if models[2].Name != "ghi789" {
t.Fatalf("models[2].Name=%q, want fallback to _id ghi789", models[2].Name)
}
}
func TestFishAudioListModelsRequiresAPIKey(t *testing.T) {
if _, err := newFishAudioForListModelsTest("http://unused").ListModels(&APIConfig{}); err == nil {
t.Fatal("ListModels: expected error for missing api key, got nil")
}
}
func TestFishAudioListModelsRejectsHTTPError(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusUnauthorized)
_, _ = io.WriteString(w, `{"error":"unauthorized"}`)
}))
defer srv.Close()
apiKey := "bad-key"
if _, err := newFishAudioForListModelsTest(srv.URL).ListModels(&APIConfig{ApiKey: &apiKey}); err == nil {
t.Fatal("ListModels: expected error for HTTP 401, got nil")
}
}