mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-06-29 15:31:05 +08:00
### 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:
@@ -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) {
|
||||
|
||||
80
internal/entity/models/fishaudio_test.go
Normal file
80
internal/entity/models/fishaudio_test.go
Normal 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")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user