mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-12-06 08:06:50 +00:00
feat(models): give ollama cloud a default model list
C15/E18/E19: add the authoritative ollama_cloud default model catalog (DefaultOllamaCloudModelIDs, /v1/models measured 2026-09-12, 20 entries incl. the two tagged snapshots) and wire it into every default-model path: - service: defaultModelsListCandidateIDs ollama case + composite candidates - handler: defaultModelIDsForPlatform ollama case + composite array, and the /v1/models end-of-chain guard now falls back to the catalog instead of an empty list (Claude leak guard kept) - frontend: getModelsByPlatform 'ollama_cloud' case mirrors the same static table (cross-referencing comments both sides, pinning tests on both sides), and upstreamSyncPlatforms opens real upstream sync E20/E28 verified already done in 656accae0 (ChannelsView arrays + ChannelMonitorView.grok.spec provider count 11).
This commit is contained in:
1 parent
7f80e4365b
commit
b7e6a54c3e
8 files changed
+230
-24
No files matched your search
@@ -1186,10 +1186,10 @@ func (h *GatewayHandler) Models(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// ollama_cloud 无静态默认模型列表(defaultModelIDsForPlatform 返回空):
|
||||
// 账号侧清单缺失时返回空列表,不得回落 Claude 默认模型。
|
||||
// ollama_cloud 账号侧清单缺失时回落实测默认目录(DefaultOllamaCloudModelIDs),
|
||||
// 不得回落 Claude 默认模型。
|
||||
if platform == service.PlatformOllamaCloud {
|
||||
writeModelsListResponse(c, []claude.Model{})
|
||||
writeModelsList(c, platform, service.DefaultOllamaCloudModelIDs())
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1461,14 +1461,11 @@ func defaultModelIDsForPlatform(platform string) []string {
|
||||
case service.PlatformOpenCodeGo:
|
||||
return service.DefaultOpenCodeGoModelIDs()
|
||||
case service.PlatformOllamaCloud:
|
||||
// ollama_cloud 没有静态默认模型列表:可服务模型完全来自账号侧的
|
||||
// model_mapping / extra.allowed_models(缺失时 IsModelSupported 为
|
||||
// deny-all)。default 分支的 Claude 列表对它只会造成虚假广告。
|
||||
return nil
|
||||
return service.DefaultOllamaCloudModelIDs()
|
||||
case service.PlatformComposite:
|
||||
ids := make([]string, 0)
|
||||
seen := make(map[string]struct{})
|
||||
for _, concretePlatform := range []string{service.PlatformAnthropic, service.PlatformGemini, service.PlatformOpenAI, service.PlatformAntigravity, service.PlatformGrok, service.PlatformKimi, service.PlatformZhipu, service.PlatformDeepseek, service.PlatformMiniMax, service.PlatformOpenCodeGo} {
|
||||
for _, concretePlatform := range []string{service.PlatformAnthropic, service.PlatformGemini, service.PlatformOpenAI, service.PlatformAntigravity, service.PlatformGrok, service.PlatformKimi, service.PlatformZhipu, service.PlatformDeepseek, service.PlatformMiniMax, service.PlatformOpenCodeGo, service.PlatformOllamaCloud} {
|
||||
for _, id := range defaultModelIDsForPlatform(concretePlatform) {
|
||||
if _, ok := seen[id]; ok {
|
||||
continue
|
||||
|
||||
@@ -12,11 +12,14 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// ollama_cloud 没有静态默认模型列表:defaultModelIDsForPlatform 不得回落
|
||||
// Claude 列表(default 分支),/models 在账号侧清单缺失时返回空列表。
|
||||
func TestDefaultModelIDsForPlatform_OllamaCloudReturnsEmpty(t *testing.T) {
|
||||
require.Empty(t, defaultModelIDsForPlatform(service.PlatformOllamaCloud))
|
||||
// ollama_cloud 的默认模型目录 = DefaultOllamaCloudModelIDs:defaultModelIDsForPlatform
|
||||
// 不得回落 Claude 列表(default 分支),/models 在账号侧清单缺失时回落该目录。
|
||||
func TestDefaultModelIDsForPlatform_OllamaCloudReturnsDefaultCatalog(t *testing.T) {
|
||||
require.Equal(t, service.DefaultOllamaCloudModelIDs(), defaultModelIDsForPlatform(service.PlatformOllamaCloud))
|
||||
require.NotEmpty(t, defaultModelIDsForPlatform(service.PlatformAnthropic))
|
||||
for _, id := range defaultModelIDsForPlatform(service.PlatformOllamaCloud) {
|
||||
require.NotContains(t, id, "claude")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGatewayModels_OllamaCloudGroupListsAllowedModels(t *testing.T) {
|
||||
@@ -53,8 +56,8 @@ func TestGatewayModels_OllamaCloudGroupListsAllowedModels(t *testing.T) {
|
||||
require.Equal(t, []string{"gpt-oss:120b"}, modelIDsForTest(got.Data))
|
||||
}
|
||||
|
||||
// 账号侧清单缺失(deny-all)时 /models 必须返回空,而不是回落 Claude 列表。
|
||||
func TestGatewayModels_OllamaCloudGroupWithoutListReturnsEmpty(t *testing.T) {
|
||||
// 账号侧清单缺失(deny-all)时 /models 回落 ollama 默认目录,而不是 Claude 列表。
|
||||
func TestGatewayModels_OllamaCloudGroupWithoutListFallsBackToDefaultCatalog(t *testing.T) {
|
||||
gin.SetMode(gin.TestMode)
|
||||
|
||||
groupID := int64(9202)
|
||||
@@ -80,6 +83,37 @@ func TestGatewayModels_OllamaCloudGroupWithoutListReturnsEmpty(t *testing.T) {
|
||||
require.Equal(t, http.StatusOK, rec.Code)
|
||||
var got gatewayModelsResponseForTest
|
||||
require.NoError(t, json.Unmarshal(rec.Body.Bytes(), &got))
|
||||
require.Empty(t, got.Data, "ollama_cloud 不得回落 Claude 默认模型列表")
|
||||
require.NotContains(t, modelIDsForTest(got.Data), "claude-sonnet-4-6")
|
||||
require.Equal(t, service.DefaultOllamaCloudModelIDs(), modelIDsForTest(got.Data),
|
||||
"ollama_cloud 不得回落 Claude 默认模型列表,应回落实测默认目录")
|
||||
}
|
||||
|
||||
// ollama_cloud 分组的 composite 白名单来源不串入 Claude 目录之外的默认回落。
|
||||
func TestGatewayModels_CompositeIncludesOllamaDefaultCatalog(t *testing.T) {
|
||||
gin.SetMode(gin.TestMode)
|
||||
|
||||
groupID := int64(9203)
|
||||
h := newGatewayModelsHandlerForTest(
|
||||
&gatewayModelsAccountRepoStub{byGroup: map[int64][]service.Account{groupID: {}}},
|
||||
)
|
||||
|
||||
rec := httptest.NewRecorder()
|
||||
c, _ := gin.CreateTestContext(rec)
|
||||
c.Request = httptest.NewRequest(http.MethodGet, "/v1/models", nil)
|
||||
c.Set(string(middleware2.ContextKeyAPIKey), &service.APIKey{
|
||||
Group: &service.Group{ID: groupID, Platform: service.PlatformComposite},
|
||||
})
|
||||
|
||||
h.Models(c)
|
||||
|
||||
require.Equal(t, http.StatusOK, rec.Code)
|
||||
var got gatewayModelsResponseForTest
|
||||
require.NoError(t, json.Unmarshal(rec.Body.Bytes(), &got))
|
||||
ids := modelIDsForTest(got.Data)
|
||||
idsSet := make(map[string]struct{}, len(ids))
|
||||
for _, id := range ids {
|
||||
idsSet[id] = struct{}{}
|
||||
}
|
||||
for _, id := range service.DefaultOllamaCloudModelIDs() {
|
||||
require.Contains(t, idsSet, id, "composite /v1/models 兜底须含 ollama 目录条目 %q", id)
|
||||
}
|
||||
}
|
||||
@@ -297,11 +297,7 @@ func defaultModelsListCandidateIDs(platform string) []string {
|
||||
case PlatformOpenCodeGo:
|
||||
return DefaultOpenCodeGoModelIDs()
|
||||
case PlatformOllamaCloud:
|
||||
// ollama_cloud 没有静态默认模型列表:可服务模型完全来自账号侧的
|
||||
// model_mapping / extra.allowed_models(缺失时 IsModelSupported 为
|
||||
// deny-all)。default 分支的 Claude 列表对它只会造成虚假广告;
|
||||
// 显式返回空,与 gateway_handler.defaultModelIDsForPlatform 对齐。
|
||||
return nil
|
||||
return DefaultOllamaCloudModelIDs()
|
||||
case PlatformComposite:
|
||||
return compositeDefaultModelsListCandidateIDs()
|
||||
default:
|
||||
@@ -322,7 +318,7 @@ func defaultAllowImageGenerationForPlatform(platform string) bool {
|
||||
func compositeDefaultModelsListCandidateIDs() []string {
|
||||
seen := make(map[string]struct{})
|
||||
ids := make([]string, 0)
|
||||
for _, platform := range []string{PlatformAnthropic, PlatformGemini, PlatformOpenAI, PlatformAntigravity, PlatformGrok, PlatformKimi, PlatformZhipu, PlatformDeepseek, PlatformMiniMax, PlatformOpenCodeGo} {
|
||||
for _, platform := range []string{PlatformAnthropic, PlatformGemini, PlatformOpenAI, PlatformAntigravity, PlatformGrok, PlatformKimi, PlatformZhipu, PlatformDeepseek, PlatformMiniMax, PlatformOpenCodeGo, PlatformOllamaCloud} {
|
||||
for _, id := range defaultModelsListCandidateIDs(platform) {
|
||||
if _, ok := seen[id]; ok {
|
||||
continue
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package service
|
||||
|
||||
// DefaultOllamaCloudModelIDs 是 Ollama Cloud 的默认模型目录:实测
|
||||
// GET https://ollama.com/v1/models(2026-09-12,HTTP 200,20 个模型,
|
||||
// owned_by 全部为 ollama,含两个带 tag 的快照名)。供分组默认模型列表、
|
||||
// composite 候选与 /v1/models 末尾兜底使用;条目均可被计费价目命中
|
||||
// (见 ollama_cloud_pricing_test.go 的逐名钉测)。
|
||||
//
|
||||
// 前端同源静态表:frontend/src/composables/useModelWhitelist.ts 的
|
||||
// getModelsByPlatform 'ollama_cloud' case 必须与这里保持同一集合,
|
||||
// 两侧各有测试钉住(ollama_cloud_models_test.go / useModelWhitelist.spec.ts),
|
||||
// 改动任一侧须同步另一侧。
|
||||
func DefaultOllamaCloudModelIDs() []string {
|
||||
return []string{
|
||||
"nemotron-3-super",
|
||||
"glm-5.3",
|
||||
"gpt-oss:120b",
|
||||
"glm-5.3-flash",
|
||||
"kimi-k2.6",
|
||||
"kimi-k3",
|
||||
"deepseek-v4.1-flash",
|
||||
"minimax-m2.7",
|
||||
"mistral-large-3:675b",
|
||||
"glm-5.1",
|
||||
"glm-5.2",
|
||||
"gpt-oss:20b",
|
||||
"qwen3.5:397b",
|
||||
"kimi-k2.7-code",
|
||||
"nemotron-3-nano:30b",
|
||||
"minimax-m3",
|
||||
"gemma4:31b",
|
||||
"nemotron-3-ultra",
|
||||
"deepseek-v4-flash:0731",
|
||||
"deepseek-v4-pro:0813",
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
//go:build unit
|
||||
|
||||
package service
|
||||
|
||||
// C15/C14/C22:ollama_cloud 默认模型清单的数据源钉测。
|
||||
//
|
||||
// 权威数据:GET https://ollama.com/v1/models 实测(2026-09-12,HTTP 200,
|
||||
// 20 个模型,含 deepseek-v4-flash:0731 / deepseek-v4-pro:0813 两个带 tag 快照名)。
|
||||
//
|
||||
// 前端同源静态表:frontend/src/composables/useModelWhitelist.ts 的
|
||||
// getModelsByPlatform 'ollama_cloud' case 必须与 DefaultOllamaCloudModelIDs()
|
||||
// 保持同一集合,两侧各有测试钉住(对侧:useModelWhitelist.spec.ts),
|
||||
// 改动任一侧须同步另一侧。
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// TestDefaultOllamaCloudModelIDs 钉住目录的形状:数量、去重、无 claude 串入、
|
||||
// 带 tag 快照名与各家族代表条目不得缺失。
|
||||
func TestDefaultOllamaCloudModelIDs(t *testing.T) {
|
||||
ids := DefaultOllamaCloudModelIDs()
|
||||
|
||||
require.Len(t, ids, 20)
|
||||
|
||||
seen := make(map[string]struct{}, len(ids))
|
||||
for _, id := range ids {
|
||||
require.NotEmpty(t, id)
|
||||
require.NotContains(t, seen, id, "duplicate model id %q", id)
|
||||
seen[id] = struct{}{}
|
||||
require.NotContains(t, id, "claude", "claude 模型不得串入 ollama_cloud 目录: %q", id)
|
||||
}
|
||||
|
||||
for _, key := range []string{
|
||||
"deepseek-v4-flash:0731",
|
||||
"deepseek-v4-pro:0813",
|
||||
"gpt-oss:120b",
|
||||
"gpt-oss:20b",
|
||||
"glm-5.3",
|
||||
"kimi-k3",
|
||||
"minimax-m3",
|
||||
"qwen3.5:397b",
|
||||
} {
|
||||
require.Contains(t, ids, key)
|
||||
}
|
||||
}
|
||||
|
||||
// C15 验收:defaultModelsListCandidateIDs 的 ollama case 返回目录本身;
|
||||
// C14/C22 验收:composite 候选包含全部 ollama 条目。
|
||||
func TestDefaultModelsListCandidateIDs_OllamaCloud(t *testing.T) {
|
||||
ollama := defaultModelsListCandidateIDs(PlatformOllamaCloud)
|
||||
require.Equal(t, DefaultOllamaCloudModelIDs(), ollama)
|
||||
|
||||
composite := defaultModelsListCandidateIDs(PlatformComposite)
|
||||
for _, id := range DefaultOllamaCloudModelIDs() {
|
||||
require.Contains(t, composite, id)
|
||||
}
|
||||
}
|
||||
|
||||
// B2-② 联动断言:目录内每个模型都必须可计费(两级查价非 nil 且单价为正),
|
||||
// 防止清单与价目表漂移后出现「默认列表 ∩ 定价表 = 空」与保存期门禁打架。
|
||||
func TestDefaultOllamaCloudModelIDsAllPriceable(t *testing.T) {
|
||||
bs := newTestBillingService()
|
||||
for _, id := range DefaultOllamaCloudModelIDs() {
|
||||
pricing, err := bs.getModelPricingAt(id, ollamaPricingAt)
|
||||
require.NoError(t, err, "model %s", id)
|
||||
require.NotNil(t, pricing, "model %s must be priceable", id)
|
||||
require.Positive(t, pricing.InputPricePerToken, "model %s", id)
|
||||
require.Positive(t, pricing.OutputPricePerToken, "model %s", id)
|
||||
}
|
||||
}
|
||||
@@ -210,7 +210,10 @@ const upstreamSyncPlatforms = new Set([
|
||||
'zhipu',
|
||||
'deepseek',
|
||||
'minimax',
|
||||
'opencode_go'
|
||||
'opencode_go',
|
||||
// ollama_cloud:后端探测路径已就绪(upstream_models.go 的 IsOllamaCloud 谓词),
|
||||
// 打开真实 /v1/models 上游同步。
|
||||
'ollama_cloud'
|
||||
])
|
||||
const canSyncUpstream = computed(() => {
|
||||
if (props.accountId) {
|
||||
|
||||
@@ -4,9 +4,51 @@ vi.mock('@/api/admin/accounts', () => ({
|
||||
getAntigravityDefaultModelMapping: vi.fn()
|
||||
}))
|
||||
|
||||
import { buildModelMappingObject, getModelsByPlatform, getPresetMappingsByPlatform, splitModelMappingObject } from '../useModelWhitelist'
|
||||
import { buildModelMappingObject, claudeModels, getModelsByPlatform, getPresetMappingsByPlatform, splitModelMappingObject } from '../useModelWhitelist'
|
||||
|
||||
describe('useModelWhitelist', () => {
|
||||
// ollama_cloud 与后端同源静态表(backend/internal/service/ollama_cloud_models.go
|
||||
// DefaultOllamaCloudModelIDs(),/v1/models 实测目录)——集合必须与后端一致,
|
||||
// 两侧各有测试钉住(对侧:ollama_cloud_models_test.go),改任一侧须同步另一侧。
|
||||
const ollamaCloudBackendCatalog = [
|
||||
'nemotron-3-super',
|
||||
'glm-5.3',
|
||||
'gpt-oss:120b',
|
||||
'glm-5.3-flash',
|
||||
'kimi-k2.6',
|
||||
'kimi-k3',
|
||||
'deepseek-v4.1-flash',
|
||||
'minimax-m2.7',
|
||||
'mistral-large-3:675b',
|
||||
'glm-5.1',
|
||||
'glm-5.2',
|
||||
'gpt-oss:20b',
|
||||
'qwen3.5:397b',
|
||||
'kimi-k2.7-code',
|
||||
'nemotron-3-nano:30b',
|
||||
'minimax-m3',
|
||||
'gemma4:31b',
|
||||
'nemotron-3-ultra',
|
||||
'deepseek-v4-flash:0731',
|
||||
'deepseek-v4-pro:0813'
|
||||
]
|
||||
|
||||
it('ollama_cloud 模型列表与后端 DefaultOllamaCloudModelIDs 同一集合', () => {
|
||||
const models = getModelsByPlatform('ollama_cloud')
|
||||
|
||||
expect(models).toEqual(ollamaCloudBackendCatalog)
|
||||
})
|
||||
|
||||
it('ollama_cloud 模型列表不是 Claude 列表且不含 claude 模型', () => {
|
||||
const models = getModelsByPlatform('ollama_cloud')
|
||||
|
||||
expect(models).not.toBe(claudeModels)
|
||||
expect(models).not.toEqual(claudeModels)
|
||||
for (const model of models) {
|
||||
expect(model).not.toContain('claude')
|
||||
}
|
||||
})
|
||||
|
||||
it('openai 模型列表包含 GPT-5.4 官方快照', () => {
|
||||
const models = getModelsByPlatform('openai')
|
||||
|
||||
|
||||
@@ -465,6 +465,31 @@ export function getModelsByPlatform(platform: string): string[] {
|
||||
'qwen3.8-max', 'qwen3.8-flash', 'qwen3.7-max', 'qwen3.7-plus', 'qwen3.6-plus',
|
||||
'hy4-preview', 'hy3', 'omen-alpha'
|
||||
]
|
||||
// 与后端同源静态表:backend/internal/service/ollama_cloud_models.go 的
|
||||
// DefaultOllamaCloudModelIDs()(/v1/models 实测目录)——两侧集合必须一致,
|
||||
// 各有测试钉住(对侧:ollama_cloud_models_test.go),改任一侧须同步另一侧。
|
||||
case 'ollama_cloud': return [
|
||||
'nemotron-3-super',
|
||||
'glm-5.3',
|
||||
'gpt-oss:120b',
|
||||
'glm-5.3-flash',
|
||||
'kimi-k2.6',
|
||||
'kimi-k3',
|
||||
'deepseek-v4.1-flash',
|
||||
'minimax-m2.7',
|
||||
'mistral-large-3:675b',
|
||||
'glm-5.1',
|
||||
'glm-5.2',
|
||||
'gpt-oss:20b',
|
||||
'qwen3.5:397b',
|
||||
'kimi-k2.7-code',
|
||||
'nemotron-3-nano:30b',
|
||||
'minimax-m3',
|
||||
'gemma4:31b',
|
||||
'nemotron-3-ultra',
|
||||
'deepseek-v4-flash:0731',
|
||||
'deepseek-v4-pro:0813'
|
||||
]
|
||||
case 'doubao': return doubaoModels
|
||||
case 'minimax': return minimaxModels
|
||||
case 'baidu': return baiduModels
|
||||
|
||||
Reference in new issue
Block a user