Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

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

Hunnyboy1217fd196f694ecc
diff --git a/internal/entity/models/fishaudio.go b/internal/entity/models/fishaudio.go
index 631f3b291a..ca3593fc62 100644
--- a/internal/entity/models/fishaudio.go
+++ b/internal/entity/models/fishaudio.go
@@ -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) {
diff --git a/internal/entity/models/fishaudio_test.go b/internal/entity/models/fishaudio_test.go
new file mode 100644
index 0000000000..123f2d303f
--- /dev/null
+++ b/internal/entity/models/fishaudio_test.go
@@ -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")
+ }
+}