Fix Go: list providers order issue. (#16616)

### Summary

As title.

---------

Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
Jin Hai
2026-07-03 18:27:32 +08:00
committed by GitHub
parent dde8b6d54c
commit 83d09b16ce
18 changed files with 25 additions and 0 deletions

View File

@@ -1,5 +1,6 @@
{
"name": "Aliyun",
"rank": 983,
"url": {
"default": "https://dashscope.aliyuncs.com",
"singapore": "https://dashscope-intl.aliyuncs.com",

View File

@@ -1,5 +1,6 @@
{
"name": "Anthropic",
"rank": 998,
"url": {
"default": "https://api.anthropic.com"
},

View File

@@ -1,5 +1,6 @@
{
"name": "CoHere",
"rank": 990,
"url": {
"default": "https://api.cohere.com"
},

View File

@@ -1,5 +1,6 @@
{
"name": "DeepSeek",
"rank": 996,
"url": {
"default": "https://api.deepseek.com"
},

View File

@@ -1,5 +1,6 @@
{
"name": "Google",
"rank": 997,
"url": {
"default": "https://generativelanguage.googleapis.com"
},

View File

@@ -1,5 +1,6 @@
{
"name": "HuggingFace",
"rank": 991,
"url": {
"default": "https://router.huggingface.co/v1"
},

View File

@@ -1,5 +1,6 @@
{
"name": "MiniMax",
"rank": 987,
"url": {
"default": "https://api.minimaxi.com/",
"global": "https://api.minimax.io/"

View File

@@ -1,5 +1,6 @@
{
"name": "Moonshot",
"rank": 994,
"url": {
"default": "https://api.moonshot.cn/v1"
},

View File

@@ -1,5 +1,6 @@
{
"name": "ollama",
"rank": 978,
"url_suffix": {
"chat": "api/chat",
"models": "api/tags",

View File

@@ -1,5 +1,6 @@
{
"name": "OpenAI",
"rank": 999,
"url": {
"default": "https://api.openai.com/v1"
},

View File

@@ -1,5 +1,6 @@
{
"name": "OpenRouter",
"rank": 989,
"url": {
"default": "https://openrouter.ai/api/v1"
},

View File

@@ -1,5 +1,6 @@
{
"name": "Replicate",
"rank": 981,
"url": {
"default": "https://api.replicate.com"
},

View File

@@ -1,5 +1,6 @@
{
"name": "SiliconFlow",
"rank": 980,
"url": {
"default": "https://api.siliconflow.cn/v1"
},

View File

@@ -1,5 +1,6 @@
{
"name": "vllm",
"rank": 975,
"url_suffix": {
"chat": "chat/completions",
"models": "models",

View File

@@ -1,5 +1,6 @@
{
"name": "VolcEngine",
"rank": 986,
"url": {
"default": "https://ark.cn-beijing.volces.com/api/v3"
},

View File

@@ -1,5 +1,6 @@
{
"name": "xAI",
"rank": 992,
"url": {
"default": "https://api.x.ai/v1"
},

View File

@@ -1,5 +1,6 @@
{
"name": "ZHIPU-AI",
"rank": 993,
"url": {
"default": "https://open.bigmodel.cn/api/paas/v4"
},

View File

@@ -22,6 +22,7 @@ import (
"fmt"
"os"
"path/filepath"
"sort"
"strings"
)
@@ -174,6 +175,7 @@ type Model struct {
// Provider represents an LLM provider
type Provider struct {
Name string `json:"name"`
Rank int `json:"rank"`
URL map[string]string `json:"url"`
URLSuffix URLSuffix `json:"url_suffix"`
Models []*Model `json:"models"`
@@ -372,6 +374,7 @@ func (pm *ProviderManager) ListProviders() ([]map[string]interface{}, error) {
providerData := map[string]interface{}{
"name": provider.Name,
"rank": provider.Rank,
"url": provider.URL,
"model_types": modelTypes,
"url_suffix": provider.URLSuffix,
@@ -379,6 +382,11 @@ func (pm *ProviderManager) ListProviders() ([]map[string]interface{}, error) {
providers = append(providers, providerData)
}
// Sort providers by rank
sort.Slice(providers, func(i, j int) bool {
return providers[i]["rank"].(int) > providers[j]["rank"].(int)
})
if len(providers) == 0 {
return nil, fmt.Errorf("no providers found")
}