From e179f4444592929f9e95be98713883d6c14a7677 Mon Sep 17 00:00:00 2001 From: lyingbug Date: Wed, 23 Sep 2026 14:20:08 +0800 Subject: [PATCH] refactor(models): separate provider definitions, model catalogs, and runtime configuration (#3589) * refactor(models): separate providers, catalog and runtime configuration * refactor(models): isolate provider definitions and runtime catalogs * docs: exclude refactoring analysis notes from the pull request --- .github/workflows/app.yml | 11 + Makefile | 14 +- frontend/src/api/initialization/index.ts | 14 +- frontend/src/components/ModelEditorDialog.vue | 14 + .../src/components/ResourceSortControl.vue | 4 +- .../src/components/modelEditorFlow.test.ts | 28 + .../src/views/creatChat/creatChat.test.mjs | 1 - .../src/views/knowledge/KnowledgeBase.vue | 2 +- internal/agent/tool_images_test.go | 4 +- internal/application/service/model.go | 4 +- internal/application/service/weknoracloud.go | 6 +- internal/container/container.go | 13 +- internal/handler/dto/model.go | 18 +- internal/handler/dto/model_test.go | 7 +- internal/handler/initialization.go | 32 +- internal/handler/model.go | 7 +- internal/handler/model_catalog.go | 99 +- .../handler/model_catalog_visibility_test.go | 2 - internal/handler/model_secret_extra_test.go | 9 +- internal/handler/model_spec_flow_test.go | 69 + internal/handler/model_test.go | 7 +- .../anthropicmessages_test.go | 5 +- .../models/api/anthropicmessages/request.go | 13 +- internal/models/api/arkembeddings/client.go | 5 +- .../models/api/arkembeddings/golden_test.go | 3 +- internal/models/api/cohererank/client.go | 7 +- internal/models/api/cohererank/golden_test.go | 27 +- .../compat.go => api/compat_settings.go} | 168 +- internal/models/api/credentials.go | 11 + .../models/api/dashscopeembeddings/client.go | 5 +- .../api/dashscopeembeddings/golden_test.go | 3 +- internal/models/api/dashscoperank/client.go | 5 +- .../models/api/dashscoperank/golden_test.go | 13 +- .../embeddings_settings.go} | 18 +- .../models/api/googleembeddings/client.go | 5 +- .../api/googleembeddings/golden_test.go | 13 +- .../api/googlegenai/googlegenai_test.go | 13 +- internal/models/api/googlegenai/request.go | 13 +- internal/models/api/nimrerank/client.go | 7 +- internal/models/api/nimrerank/golden_test.go | 17 +- internal/models/api/openaichataudio/client.go | 7 +- .../models/api/openaichataudio/golden_test.go | 9 +- .../api/openaicompletions/golden_test.go | 84 +- .../models/api/openaicompletions/request.go | 35 +- .../models/api/openaiembeddings/client.go | 7 +- .../api/openaiembeddings/golden_test.go | 29 +- .../openairesponses/openairesponses_test.go | 3 +- .../models/api/openairesponses/request.go | 7 +- .../models/api/openaitranscriptions/client.go | 11 +- .../api/openaitranscriptions/golden_test.go | 25 +- .../rerank.go => api/rerank_settings.go} | 38 +- internal/models/api/tencentlkeap/client.go | 103 + .../transcriptions_settings.go} | 10 +- internal/models/api/types.go | 2 +- .../models/api/volcengineknowledge/client.go | 116 + internal/models/asr/asr.go | 2 + internal/models/asr/catalog_matrix_test.go | 95 + internal/models/asr/protocol.go | 62 +- internal/models/asr/wire_test.go | 4 +- internal/models/capabilities.go | 17 + internal/models/catalog/catalog.go | 128 + .../models/catalog/data/models.generated.json | 5797 +++++++++++++++++ internal/models/catalog/data/overrides.json | 1931 ++++++ internal/models/catalog/data/seed.json | 4542 +++++++++++++ internal/models/catalog/loader.go | 49 + internal/models/catalog/registry.go | 286 - internal/models/chat/chat.go | 58 +- internal/models/chat/llm_debug.go | 3 +- internal/models/chat/ollama.go | 3 +- .../models/embedding/catalog_matrix_test.go | 105 + internal/models/embedding/embedder.go | 11 +- internal/models/embedding/protocol.go | 62 +- internal/models/internal/configcopy/copy.go | 62 + internal/models/legacy_keys.go | 28 + internal/models/model.go | 76 + internal/models/model_type.go | 30 + .../models/parity/catalog_baseline_test.go | 113 + internal/models/parity/parity_test.go | 51 +- internal/models/parity/rerank_test.go | 72 +- .../parity/testdata/catalog-baseline.json | 353 + .../models/parity/volcengine_budget_test.go | 38 + .../aliyun/vendor.go => providers/aliyun.go} | 85 +- .../vendor.go => providers/anthropic.go} | 37 +- .../icon.svg => providers/assets/aliyun.svg} | 0 .../assets/anthropic.svg} | 0 .../assets/azure_openai.svg} | 0 .../assets/deepseek.svg} | 0 .../icon.svg => providers/assets/gemini.svg} | 0 .../icon.svg => providers/assets/generic.svg} | 0 .../assets/gpustack.svg} | 0 .../icon.svg => providers/assets/hunyuan.svg} | 0 .../icon.svg => providers/assets/jina.svg} | 0 .../icon.svg => providers/assets/litellm.svg} | 0 .../icon.svg => providers/assets/lkeap.svg} | 0 .../icon.svg => providers/assets/longcat.svg} | 0 .../icon.svg => providers/assets/mimo.svg} | 0 .../icon.svg => providers/assets/minimax.svg} | 0 .../assets/modelscope.svg} | 0 .../assets/moonshot.svg} | 0 .../icon.svg => providers/assets/novita.svg} | 0 .../icon.svg => providers/assets/nvidia.svg} | 0 .../icon.svg => providers/assets/openai.svg} | 0 .../assets/openrouter.svg} | 0 .../icon.svg => providers/assets/qianfan.svg} | 0 .../icon.svg => providers/assets/qiniu.svg} | 0 .../assets/requesty.svg} | 0 .../assets/siliconflow.svg} | 0 .../assets/volcengine.svg} | 0 .../assets/weknoracloud.svg} | 0 .../icon.svg => providers/assets/zhipu.svg} | 0 .../vendor.go => providers/azure_openai.go} | 76 +- internal/models/providers/builtin.go | 36 + internal/models/providers/compat.go | 18 + .../vendor.go => providers/deepseek.go} | 49 +- .../types.go => providers/definition.go} | 143 +- .../gemini/vendor.go => providers/gemini.go} | 65 +- .../vendor.go => providers/generic.go} | 64 +- .../vendor.go => providers/gpustack.go} | 80 +- .../vendor.go => providers/hunyuan.go} | 45 +- .../jina/vendor.go => providers/jina.go} | 51 +- .../vendor.go => providers/litellm.go} | 68 +- .../lkeap/vendor.go => providers/lkeap.go} | 63 +- .../vendor.go => providers/longcat.go} | 47 +- .../mimo/vendor.go => providers/mimo.go} | 49 +- .../vendor.go => providers/minimax.go} | 69 +- .../vendor.go => providers/modelscope.go} | 47 +- .../vendor.go => providers/moonshot.go} | 45 +- .../novita/vendor.go => providers/novita.go} | 53 +- .../nvidia/vendor.go => providers/nvidia.go} | 71 +- .../openai/vendor.go => providers/openai.go} | 79 +- .../vendor.go => providers/openrouter.go} | 65 +- .../providers_test.go} | 84 +- .../vendor.go => providers/qianfan.go} | 67 +- .../qiniu/vendor.go => providers/qiniu.go} | 45 +- .../vendor.go => providers/requesty.go} | 61 +- .../vendor.go => providers/siliconflow.go} | 69 +- .../vendor.go => providers/volcengine.go} | 91 +- .../vendor.go => providers/weknoracloud.go} | 74 +- .../zhipu/vendor.go => providers/zhipu.go} | 83 +- internal/models/rerank/catalog_matrix_test.go | 89 + internal/models/rerank/lkeap_reranker.go | 117 +- internal/models/rerank/protocol.go | 3 +- internal/models/rerank/protocol_test.go | 19 +- .../models/rerank/provider_detection_test.go | 11 +- internal/models/rerank/reranker.go | 67 +- internal/models/rerank/sdk_clients_test.go | 27 +- internal/models/rerank/volcengine_reranker.go | 120 +- internal/models/rerank/wire_test.go | 7 +- .../{catalog => runtime}/catalog_test.go | 194 +- internal/models/runtime/compat.go | 73 + internal/models/runtime/connection.go | 78 + internal/models/runtime/icon_test.go | 26 + internal/models/runtime/legacy.go | 38 + .../{catalog => runtime}/legacy_rows_test.go | 58 +- .../models/{catalog => runtime}/overlay.go | 234 +- .../{catalog => runtime}/overlay_test.go | 85 +- internal/models/runtime/refactor_test.go | 234 + internal/models/runtime/registry.go | 210 + internal/models/runtime/registry_test.go | 133 + .../models/{catalog => runtime}/resolve.go | 259 +- internal/models/runtime/runtime.go | 78 + internal/models/runtime/snapshot.go | 28 + .../models/{catalog => runtime}/validate.go | 4 +- .../{catalog => runtime}/validate_test.go | 7 +- internal/models/vendors/aliyun/models.json | 62 - internal/models/vendors/all.go | 35 - internal/models/vendors/anthropic/models.json | 17 - .../models/vendors/azure_openai/models.json | 17 - internal/models/vendors/deepseek/models.json | 59 - internal/models/vendors/gemini/models.json | 20 - internal/models/vendors/generic/models.json | 29 - internal/models/vendors/gpustack/models.json | 4 - internal/models/vendors/hunyuan/models.json | 18 - internal/models/vendors/jina/models.json | 18 - internal/models/vendors/litellm/models.json | 4 - internal/models/vendors/lkeap/models.json | 16 - internal/models/vendors/longcat/models.json | 9 - internal/models/vendors/mimo/models.json | 11 - internal/models/vendors/minimax/models.json | 15 - .../models/vendors/modelscope/models.json | 17 - internal/models/vendors/moonshot/models.json | 19 - internal/models/vendors/novita/models.json | 21 - internal/models/vendors/nvidia/models.json | 18 - internal/models/vendors/openai/models.json | 38 - .../models/vendors/openrouter/models.json | 25 - internal/models/vendors/qianfan/models.json | 15 - internal/models/vendors/qiniu/models.json | 16 - internal/models/vendors/requesty/models.json | 20 - .../models/vendors/siliconflow/models.json | 30 - .../models/vendors/volcengine/models.json | 28 - .../models/vendors/weknoracloud/models.json | 4 - internal/models/vendors/zhipu/models.json | 21 - .../models/vlm/remote_api_reasoning_test.go | 2 - internal/models/vlm/spec_override_test.go | 1 - internal/models/vlm/vlm.go | 8 +- internal/router/routes_infra.go | 1 + internal/types/builtin_models_config.go | 2 +- internal/types/model.go | 2 +- scripts/model-catalog/generate.py | 98 + scripts/model-catalog/sources.json | 32 + scripts/model_catalog_diff.py | 32 +- website-docs/02-architecture/01-overview.md | 2 +- website-docs/03-features/06-models.md | 47 +- 203 files changed, 16811 insertions(+), 3380 deletions(-) create mode 100644 internal/handler/model_spec_flow_test.go rename internal/models/{catalog/compat.go => api/compat_settings.go} (70%) create mode 100644 internal/models/api/credentials.go rename internal/models/{catalog/embeddings.go => api/embeddings_settings.go} (89%) rename internal/models/{catalog/rerank.go => api/rerank_settings.go} (75%) create mode 100644 internal/models/api/tencentlkeap/client.go rename internal/models/{catalog/transcriptions.go => api/transcriptions_settings.go} (93%) create mode 100644 internal/models/api/volcengineknowledge/client.go create mode 100644 internal/models/asr/catalog_matrix_test.go create mode 100644 internal/models/capabilities.go create mode 100644 internal/models/catalog/catalog.go create mode 100644 internal/models/catalog/data/models.generated.json create mode 100644 internal/models/catalog/data/overrides.json create mode 100644 internal/models/catalog/data/seed.json create mode 100644 internal/models/catalog/loader.go delete mode 100644 internal/models/catalog/registry.go create mode 100644 internal/models/embedding/catalog_matrix_test.go create mode 100644 internal/models/internal/configcopy/copy.go create mode 100644 internal/models/legacy_keys.go create mode 100644 internal/models/model.go create mode 100644 internal/models/model_type.go create mode 100644 internal/models/parity/catalog_baseline_test.go create mode 100644 internal/models/parity/testdata/catalog-baseline.json create mode 100644 internal/models/parity/volcengine_budget_test.go rename internal/models/{vendors/aliyun/vendor.go => providers/aliyun.go} (80%) rename internal/models/{vendors/anthropic/vendor.go => providers/anthropic.go} (83%) rename internal/models/{vendors/aliyun/icon.svg => providers/assets/aliyun.svg} (100%) rename internal/models/{vendors/anthropic/icon.svg => providers/assets/anthropic.svg} (100%) rename internal/models/{vendors/azure_openai/icon.svg => providers/assets/azure_openai.svg} (100%) rename internal/models/{vendors/deepseek/icon.svg => providers/assets/deepseek.svg} (100%) rename internal/models/{vendors/gemini/icon.svg => providers/assets/gemini.svg} (100%) rename internal/models/{vendors/generic/icon.svg => providers/assets/generic.svg} (100%) rename internal/models/{vendors/gpustack/icon.svg => providers/assets/gpustack.svg} (100%) rename internal/models/{vendors/hunyuan/icon.svg => providers/assets/hunyuan.svg} (100%) rename internal/models/{vendors/jina/icon.svg => providers/assets/jina.svg} (100%) rename internal/models/{vendors/litellm/icon.svg => providers/assets/litellm.svg} (100%) rename internal/models/{vendors/lkeap/icon.svg => providers/assets/lkeap.svg} (100%) rename internal/models/{vendors/longcat/icon.svg => providers/assets/longcat.svg} (100%) rename internal/models/{vendors/mimo/icon.svg => providers/assets/mimo.svg} (100%) rename internal/models/{vendors/minimax/icon.svg => providers/assets/minimax.svg} (100%) rename internal/models/{vendors/modelscope/icon.svg => providers/assets/modelscope.svg} (100%) rename internal/models/{vendors/moonshot/icon.svg => providers/assets/moonshot.svg} (100%) rename internal/models/{vendors/novita/icon.svg => providers/assets/novita.svg} (100%) rename internal/models/{vendors/nvidia/icon.svg => providers/assets/nvidia.svg} (100%) rename internal/models/{vendors/openai/icon.svg => providers/assets/openai.svg} (100%) rename internal/models/{vendors/openrouter/icon.svg => providers/assets/openrouter.svg} (100%) rename internal/models/{vendors/qianfan/icon.svg => providers/assets/qianfan.svg} (100%) rename internal/models/{vendors/qiniu/icon.svg => providers/assets/qiniu.svg} (100%) rename internal/models/{vendors/requesty/icon.svg => providers/assets/requesty.svg} (100%) rename internal/models/{vendors/siliconflow/icon.svg => providers/assets/siliconflow.svg} (100%) rename internal/models/{vendors/volcengine/icon.svg => providers/assets/volcengine.svg} (100%) rename internal/models/{vendors/weknoracloud/icon.svg => providers/assets/weknoracloud.svg} (100%) rename internal/models/{vendors/zhipu/icon.svg => providers/assets/zhipu.svg} (100%) rename internal/models/{vendors/azure_openai/vendor.go => providers/azure_openai.go} (83%) create mode 100644 internal/models/providers/builtin.go create mode 100644 internal/models/providers/compat.go rename internal/models/{vendors/deepseek/vendor.go => providers/deepseek.go} (81%) rename internal/models/{catalog/types.go => providers/definition.go} (68%) rename internal/models/{vendors/gemini/vendor.go => providers/gemini.go} (77%) rename internal/models/{vendors/generic/vendor.go => providers/generic.go} (79%) rename internal/models/{vendors/gpustack/vendor.go => providers/gpustack.go} (77%) rename internal/models/{vendors/hunyuan/vendor.go => providers/hunyuan.go} (83%) rename internal/models/{vendors/jina/vendor.go => providers/jina.go} (74%) rename internal/models/{vendors/litellm/vendor.go => providers/litellm.go} (75%) rename internal/models/{vendors/lkeap/vendor.go => providers/lkeap.go} (80%) rename internal/models/{vendors/longcat/vendor.go => providers/longcat.go} (75%) rename internal/models/{vendors/mimo/vendor.go => providers/mimo.go} (77%) rename internal/models/{vendors/minimax/vendor.go => providers/minimax.go} (71%) rename internal/models/{vendors/modelscope/vendor.go => providers/modelscope.go} (76%) rename internal/models/{vendors/moonshot/vendor.go => providers/moonshot.go} (80%) rename internal/models/{vendors/novita/vendor.go => providers/novita.go} (72%) rename internal/models/{vendors/nvidia/vendor.go => providers/nvidia.go} (78%) rename internal/models/{vendors/openai/vendor.go => providers/openai.go} (76%) rename internal/models/{vendors/openrouter/vendor.go => providers/openrouter.go} (73%) rename internal/models/{vendors/vendors_test.go => providers/providers_test.go} (87%) rename internal/models/{vendors/qianfan/vendor.go => providers/qianfan.go} (76%) rename internal/models/{vendors/qiniu/vendor.go => providers/qiniu.go} (80%) rename internal/models/{vendors/requesty/vendor.go => providers/requesty.go} (74%) rename internal/models/{vendors/siliconflow/vendor.go => providers/siliconflow.go} (67%) rename internal/models/{vendors/volcengine/vendor.go => providers/volcengine.go} (81%) rename internal/models/{vendors/weknoracloud/vendor.go => providers/weknoracloud.go} (73%) rename internal/models/{vendors/zhipu/vendor.go => providers/zhipu.go} (75%) create mode 100644 internal/models/rerank/catalog_matrix_test.go rename internal/models/{catalog => runtime}/catalog_test.go (65%) create mode 100644 internal/models/runtime/compat.go create mode 100644 internal/models/runtime/connection.go create mode 100644 internal/models/runtime/icon_test.go create mode 100644 internal/models/runtime/legacy.go rename internal/models/{catalog => runtime}/legacy_rows_test.go (90%) rename internal/models/{catalog => runtime}/overlay.go (73%) rename internal/models/{catalog => runtime}/overlay_test.go (67%) create mode 100644 internal/models/runtime/refactor_test.go create mode 100644 internal/models/runtime/registry.go create mode 100644 internal/models/runtime/registry_test.go rename internal/models/{catalog => runtime}/resolve.go (62%) create mode 100644 internal/models/runtime/runtime.go create mode 100644 internal/models/runtime/snapshot.go rename internal/models/{catalog => runtime}/validate.go (94%) rename internal/models/{catalog => runtime}/validate_test.go (94%) delete mode 100644 internal/models/vendors/aliyun/models.json delete mode 100644 internal/models/vendors/all.go delete mode 100644 internal/models/vendors/anthropic/models.json delete mode 100644 internal/models/vendors/azure_openai/models.json delete mode 100644 internal/models/vendors/deepseek/models.json delete mode 100644 internal/models/vendors/gemini/models.json delete mode 100644 internal/models/vendors/generic/models.json delete mode 100644 internal/models/vendors/gpustack/models.json delete mode 100644 internal/models/vendors/hunyuan/models.json delete mode 100644 internal/models/vendors/jina/models.json delete mode 100644 internal/models/vendors/litellm/models.json delete mode 100644 internal/models/vendors/lkeap/models.json delete mode 100644 internal/models/vendors/longcat/models.json delete mode 100644 internal/models/vendors/mimo/models.json delete mode 100644 internal/models/vendors/minimax/models.json delete mode 100644 internal/models/vendors/modelscope/models.json delete mode 100644 internal/models/vendors/moonshot/models.json delete mode 100644 internal/models/vendors/novita/models.json delete mode 100644 internal/models/vendors/nvidia/models.json delete mode 100644 internal/models/vendors/openai/models.json delete mode 100644 internal/models/vendors/openrouter/models.json delete mode 100644 internal/models/vendors/qianfan/models.json delete mode 100644 internal/models/vendors/qiniu/models.json delete mode 100644 internal/models/vendors/requesty/models.json delete mode 100644 internal/models/vendors/siliconflow/models.json delete mode 100644 internal/models/vendors/volcengine/models.json delete mode 100644 internal/models/vendors/weknoracloud/models.json delete mode 100644 internal/models/vendors/zhipu/models.json create mode 100644 scripts/model-catalog/generate.py create mode 100644 scripts/model-catalog/sources.json diff --git a/.github/workflows/app.yml b/.github/workflows/app.yml index e83def8c..ebaabe4f 100644 --- a/.github/workflows/app.yml +++ b/.github/workflows/app.yml @@ -24,6 +24,10 @@ on: - "THIRD_PARTY_NOTICES.md" - "licenses/**" - "internal/textconv/data/**" + - "internal/models/catalog/data/**" + - "internal/models/parity/testdata/**" + - "internal/models/providers/assets/**" + - "scripts/model-catalog/**" - "scripts/*license*.sh" - "scripts/git-hooks/**" - "scripts/test-git-hooks.sh" @@ -48,6 +52,10 @@ on: - "THIRD_PARTY_NOTICES.md" - "licenses/**" - "internal/textconv/data/**" + - "internal/models/catalog/data/**" + - "internal/models/parity/testdata/**" + - "internal/models/providers/assets/**" + - "scripts/model-catalog/**" - "scripts/*license*.sh" - "scripts/git-hooks/**" - "scripts/test-git-hooks.sh" @@ -117,6 +125,9 @@ jobs: exit 1 fi + - name: Verify generated model catalog + run: python3 scripts/model-catalog/generate.py --check + - name: Verify Git hook test coverage run: bash ./scripts/test-git-hooks.sh diff --git a/Makefile b/Makefile index 67f74ac7..2f454068 100644 --- a/Makefile +++ b/Makefile @@ -112,12 +112,14 @@ run: build test: go test -v ./... -# Vendor catalog: invariants, legacy-behaviour parity and vendor facts. -# Run this after adding a vendor or editing any models.json. -.PHONY: model-catalog-check +# Generate reviewed metadata + protocol overrides, then verify every model. +.PHONY: model-catalog-generate model-catalog-check +model-catalog-generate: + python3 scripts/model-catalog/generate.py + model-catalog-check: - go test ./internal/models/parity/ ./internal/models/vendors/ ./internal/models/catalog/ ./internal/models/api/... \ - ./internal/models/rerank/ ./internal/models/embedding/ ./internal/models/asr/ + python3 scripts/model-catalog/generate.py --check + go test ./internal/models/... # Vendor catalog: report where our model metadata differs from models.dev. # Development aid only — nothing is fetched at runtime and nothing is written @@ -367,5 +369,3 @@ dev-app: dev-frontend: ./scripts/dev.sh frontend - - diff --git a/frontend/src/api/initialization/index.ts b/frontend/src/api/initialization/index.ts index 7fd1c3db..9f020cd8 100644 --- a/frontend/src/api/initialization/index.ts +++ b/frontend/src/api/initialization/index.ts @@ -1,6 +1,6 @@ import { get, post, put } from '../../utils/request'; import i18n from '@/i18n' -import type { ModelCapabilities, ReasoningEffortLevel } from '../model' +import type { ModelCapabilities, ModelSpecOverride, ReasoningEffortLevel } from '../model' const t = (key: string) => i18n.global.t(key) @@ -305,6 +305,7 @@ export function getCurrentConfigByKB(kbId: string): Promise; extraConfig?: Record; interfaceType?: string; @@ -690,6 +691,7 @@ export function listModelProviders(modelType?: string): Promise { - const query = new URLSearchParams(); - for (const [key, value] of Object.entries(params)) { - if (value !== undefined && value !== null && String(value).trim() !== '') { - query.set(key, String(value).trim()); - } - } return new Promise((resolve, reject) => { - get(`/api/v1/models/catalog/resolve?${query.toString()}`) + post(`/api/v1/models/catalog/resolve`, params) .then((response: any) => { if (response?.success && response?.data) { resolve(response.data as ResolvedModelCatalog); diff --git a/frontend/src/components/ModelEditorDialog.vue b/frontend/src/components/ModelEditorDialog.vue index cdb63d96..de2ea533 100644 --- a/frontend/src/components/ModelEditorDialog.vue +++ b/frontend/src/components/ModelEditorDialog.vue @@ -1003,6 +1003,7 @@ const runResolve = async () => { try { const result = await resolveModelCatalog({ provider, + spec: buildSpec(), model: formData.value.modelName || '', base_url: formData.value.baseUrl || '', model_type: activeModelType.value, @@ -1067,6 +1068,16 @@ const specCompatError = computed(() => { } }) +// Match the parent save path: retain row metadata, replace the edited compat. +const buildSpec = (): ModelSpecOverride => { + if (specCompatError.value) throw new Error(specCompatError.value) + const spec: ModelSpecOverride = { ...(formData.value.spec || {}) } + const text = (formData.value.specCompat || '').trim() + if (text) spec.compat = JSON.parse(text) + else delete spec.compat + return spec +} + const dialogVisible = computed({ get: () => props.visible, set: (val) => { @@ -1303,6 +1314,7 @@ watch( props.visible, formData.value.source, formData.value.provider, formData.value.modelName, formData.value.baseUrl, formData.value.extraConfig?.api, formData.value.extraConfig?.remote_model_name, formData.value.thinkingControl, activeModelType.value, + formData.value.specCompat, JSON.stringify(formData.value.spec), ], () => { if (!props.visible) return @@ -1503,6 +1515,7 @@ watch( formData.value.apiKey, formData.value.appSecret, formData.value.customHeaders, formData.value.dimension, formData.value.supportsDimensionOverride, formData.value.extraConfig, formData.value.thinkingControl, + formData.value.specCompat, formData.value.spec, ], () => { if (!applyingDetectedDimension) invalidateConnectionTest(props.visible && !hydratingForm.value) @@ -1826,6 +1839,7 @@ const checkRemoteAPI = async () => { // 使测试连接走与生产调用相同的目录解析路径。 const extraConfig = buildExtraConfig() const extraPayload = { + spec: buildSpec(), ...(Object.keys(extraConfig).length > 0 ? { extraConfig } : {}), ...(formData.value.appSecret?.trim() ? { appSecret: formData.value.appSecret.trim() } : {}), } diff --git a/frontend/src/components/ResourceSortControl.vue b/frontend/src/components/ResourceSortControl.vue index 87737969..d01272ac 100644 --- a/frontend/src/components/ResourceSortControl.vue +++ b/frontend/src/components/ResourceSortControl.vue @@ -88,7 +88,7 @@ function selectOption(value: ResourceSortValue) { height: 28px; padding: 0 8px; border: 1px solid var(--td-component-stroke); - border-radius: 6px; + border-radius: var(--app-radius-sm); background: var(--td-bg-color-secondarycontainer); color: var(--td-text-color-secondary); font-family: var(--app-font-family); @@ -168,7 +168,7 @@ function selectOption(value: ResourceSortValue) { height: 32px; padding: 0 10px; border: 0; - border-radius: 6px; + border-radius: var(--app-radius-sm); background: transparent; color: var(--td-text-color-primary); font-family: var(--app-font-family); diff --git a/frontend/src/components/modelEditorFlow.test.ts b/frontend/src/components/modelEditorFlow.test.ts index 9ca219a9..ffa68ac2 100644 --- a/frontend/src/components/modelEditorFlow.test.ts +++ b/frontend/src/components/modelEditorFlow.test.ts @@ -884,3 +884,31 @@ test('extraFieldDisplayPlaceholder resolves the vendor placeholder for the activ f.close() } }) + +for (const type of ['chat', 'embedding', 'rerank', 'vllm', 'asr']) { + test(`${type}: connection tests include edited spec and clearing compat`, async () => { + const f = await fixture({ type }) + try { + f.vm.formData.spec = { context_window: 64000, compat: { old: true } } + f.vm.formData.specCompat = '{"custom_option": true}' + await f.vm.checkRemoteAPI() + assert.deepEqual(plain(f.requests[0].spec), { context_window: 64000, compat: { custom_option: true } }) + f.vm.formData.specCompat = '' + await nextTick() + assert.equal(f.vm.remoteChecked, false, 'editing spec invalidates the old connection result') + await f.vm.checkRemoteAPI() + assert.deepEqual(plain(f.requests[1].spec), { context_window: 64000 }) + } finally { f.close() } + }) +} + +test('capability preview includes the same edited spec as connection tests', async () => { + const f = await fixture({ type: 'chat' }) + try { + f.vm.formData.provider = 'openai' + f.vm.formData.spec = { api: 'openai-completions' } + f.vm.formData.specCompat = '{"supports_temperature": false}' + await f.vm.runResolve() + assert.deepEqual(plain(f.resolves.at(-1).spec), { api: 'openai-completions', compat: { supports_temperature: false } }) + } finally { f.close() } +}) diff --git a/frontend/src/views/creatChat/creatChat.test.mjs b/frontend/src/views/creatChat/creatChat.test.mjs index 681e8257..dbffed59 100644 --- a/frontend/src/views/creatChat/creatChat.test.mjs +++ b/frontend/src/views/creatChat/creatChat.test.mjs @@ -22,4 +22,3 @@ test('new-session page has a single project button flush above the composer', () assert.doesNotMatch(source, /t-select/) assert.doesNotMatch(source, /project-dir-picker/) }) - diff --git a/frontend/src/views/knowledge/KnowledgeBase.vue b/frontend/src/views/knowledge/KnowledgeBase.vue index 14df4c09..d39564ae 100644 --- a/frontend/src/views/knowledge/KnowledgeBase.vue +++ b/frontend/src/views/knowledge/KnowledgeBase.vue @@ -2913,7 +2913,7 @@ const handleKBEditorSuccess = (kbIdValue: string) => { height: 32px; padding: 0 10px; border: 0; - border-radius: 6px; + border-radius: var(--app-radius-sm); background: transparent; color: var(--td-text-color-primary); font-family: var(--app-font-family); diff --git a/internal/agent/tool_images_test.go b/internal/agent/tool_images_test.go index 06327786..beddd503 100644 --- a/internal/agent/tool_images_test.go +++ b/internal/agent/tool_images_test.go @@ -6,8 +6,8 @@ import ( "errors" "testing" + "github.com/Tencent/WeKnora/internal/models/api" "github.com/Tencent/WeKnora/internal/models/api/openaicompletions" - "github.com/Tencent/WeKnora/internal/models/catalog" "github.com/Tencent/WeKnora/internal/types" "github.com/stretchr/testify/require" ) @@ -30,7 +30,7 @@ func TestToolImagesReachNextModelTurnAfterAllReplies(t *testing.T) { require.Equal(t, "user", messages[3].Role) require.Equal(t, step.ToolCalls[0].Result.Images, messages[3].Images) require.Contains(t, messages[3].Content, "untrusted tool evidence") - client := openaicompletions.New(openaicompletions.Config{Settings: catalog.DefaultOpenAICompletions()}) + client := openaicompletions.New(openaicompletions.Config{Settings: api.DefaultOpenAICompletions()}) body, err := client.BuildRequestBody(messages, nil, false) require.NoError(t, err) raw, err := json.Marshal(body["messages"]) diff --git a/internal/application/service/model.go b/internal/application/service/model.go index c9ca6a3d..8d842c66 100644 --- a/internal/application/service/model.go +++ b/internal/application/service/model.go @@ -11,9 +11,9 @@ import ( "github.com/Tencent/WeKnora/internal/models/asr" "github.com/Tencent/WeKnora/internal/models/chat" "github.com/Tencent/WeKnora/internal/models/embedding" + "github.com/Tencent/WeKnora/internal/models/providers" "github.com/Tencent/WeKnora/internal/models/rerank" "github.com/Tencent/WeKnora/internal/models/utils/ollama" - "github.com/Tencent/WeKnora/internal/models/vendors/weknoracloud" "github.com/Tencent/WeKnora/internal/models/vlm" "github.com/Tencent/WeKnora/internal/types" "github.com/Tencent/WeKnora/internal/types/interfaces" @@ -70,7 +70,7 @@ func (s *modelService) resolveWeKnoraCloudCredentials(ctx context.Context, param appID = params.AppID appSecret = s.decryptAppSecret(params.AppSecret) - if params.Provider != weknoracloud.ID { + if params.Provider != providers.WeKnoraCloudID { return } if appID != "" && appSecret != "" { diff --git a/internal/application/service/weknoracloud.go b/internal/application/service/weknoracloud.go index 8b51347a..3709bc5e 100644 --- a/internal/application/service/weknoracloud.go +++ b/internal/application/service/weknoracloud.go @@ -8,8 +8,8 @@ import ( "time" "github.com/Tencent/WeKnora/internal/logger" + "github.com/Tencent/WeKnora/internal/models/providers" modelsutils "github.com/Tencent/WeKnora/internal/models/utils" - "github.com/Tencent/WeKnora/internal/models/vendors/weknoracloud" "github.com/Tencent/WeKnora/internal/types" "github.com/Tencent/WeKnora/internal/types/interfaces" "github.com/Tencent/WeKnora/internal/utils" @@ -30,7 +30,7 @@ func NewWeKnoraCloudService( } func IsWeKnoraCloudDocReaderAddr(addr string) bool { - readerURL := strings.TrimRight(weknoracloud.BaseURL, "/") + "/api/v1/doc/reader" + readerURL := strings.TrimRight(providers.WeKnoraCloudBaseURL, "/") + "/api/v1/doc/reader" return strings.TrimSuffix(strings.TrimSpace(addr), "/") == readerURL } @@ -56,7 +56,7 @@ func (s *weKnoraCloudService) SaveCredentials(ctx context.Context, appID, appSec // 注意:health 一般为探活接口,远端常不校验 APPID/SECRET 或签名;HTTP 200 通常只表示 // 「网关/服务可达」,不能严格证明凭证有效。若需强校验,应改为调用必须鉴权的业务接口。 func (s *weKnoraCloudService) verifyCredentials(ctx context.Context, appID, appSecret string) error { - baseURL := strings.TrimRight(weknoracloud.BaseURL, "/") + baseURL := strings.TrimRight(providers.WeKnoraCloudBaseURL, "/") healthURL := baseURL + "/api/v1/health" req, err := http.NewRequestWithContext(ctx, http.MethodGet, healthURL, nil) diff --git a/internal/container/container.go b/internal/container/container.go index 0afec2f8..19392a78 100644 --- a/internal/container/container.go +++ b/internal/container/container.go @@ -18,6 +18,8 @@ import ( "strings" "time" + modelruntime "github.com/Tencent/WeKnora/internal/models/runtime" + sqlite_vec "github.com/asg017/sqlite-vec-go-bindings/cgo" _ "github.com/duckdb/duckdb-go/v2" esv7 "github.com/elastic/go-elasticsearch/v7" @@ -86,11 +88,9 @@ import ( "github.com/Tencent/WeKnora/internal/mcp" "github.com/Tencent/WeKnora/internal/mcpserver" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" "github.com/Tencent/WeKnora/internal/models/embedding" - "github.com/Tencent/WeKnora/internal/models/limiter" + "github.com/Tencent/WeKnora/internal/models/limiter" // register built-in vendors "github.com/Tencent/WeKnora/internal/models/utils/ollama" - _ "github.com/Tencent/WeKnora/internal/models/vendors" // register built-in vendors "github.com/Tencent/WeKnora/internal/router" "github.com/Tencent/WeKnora/internal/sandbox" "github.com/Tencent/WeKnora/internal/storageallowlist" @@ -115,9 +115,8 @@ import ( // - Configured container with all application dependencies registered func BuildContainer(container *dig.Container) *dig.Container { // Deployment-level model catalog overlay (config/models.json, optional). - // Built-in vendors register themselves through the vendors package - // import; the overlay may add vendors or patch built-in ones. - if err := catalog.LoadOverlay(config.ConfigDir()); err != nil { + // Register providers explicitly, then validate and publish one catalog generation. + if err := modelruntime.Initialize(config.ConfigDir()); err != nil { logger.Warnf(context.Background(), "Load models catalog overlay failed: %v", err) } ctx := context.Background() @@ -914,7 +913,7 @@ func initDatabase(cfg *config.Config) (*gorm.DB, error) { // Post-migration: declarative built-in models from config/builtin_models.yaml (optional). // The loader validates each row's catalog parameters through this hook; // the wiring lives here because internal/types cannot import the catalog. - types.ValidateModelParameters = catalog.ValidateRow + types.ValidateModelParameters = modelruntime.ValidateRow if err := types.LoadBuiltinModelsConfig(context.Background(), db, config.ConfigDir()); err != nil { logger.Warnf(context.Background(), "Load builtin models config failed: %v", err) } diff --git a/internal/handler/dto/model.go b/internal/handler/dto/model.go index e982c893..d5705197 100644 --- a/internal/handler/dto/model.go +++ b/internal/handler/dto/model.go @@ -5,7 +5,7 @@ import ( "strings" "time" - "github.com/Tencent/WeKnora/internal/models/catalog" + modelruntime "github.com/Tencent/WeKnora/internal/models/runtime" "github.com/Tencent/WeKnora/internal/types" ) @@ -23,7 +23,7 @@ type VendorRef struct { func (r VendorRef) vendorID() string { id := strings.ToLower(strings.TrimSpace(r.Provider)) if id == "" { - id = catalog.DetectByURL(r.BaseURL) + id = modelruntime.DetectByURL(r.BaseURL) } return id } @@ -35,7 +35,7 @@ func (r VendorRef) names() bool { return strings.TrimSpace(r.Provider) != "" || strings.TrimSpace(r.BaseURL) != "" } -func secretKeysOf(v *catalog.Vendor, into map[string]bool) map[string]bool { +func secretKeysOf(v *modelruntime.Provider, into map[string]bool) map[string]bool { for _, f := range v.ExtraFields { if !f.Secret && f.Type != "password" { continue @@ -49,7 +49,7 @@ func secretKeysOf(v *catalog.Vendor, into map[string]bool) map[string]bool { } // SecretExtraConfigKeys returns the extra_config keys the vendor declares as -// secret (catalog.ExtraField.Secret, or a password input). These are real +// secret (providers.ExtraField.Secret, or a password input). These are real // credentials — LKEAP and Volcengine rerank keep an IAM/CAM secret key there // — so they get the same treatment as api_key / app_secret: never echoed, // only reported as present. @@ -58,7 +58,7 @@ func secretKeysOf(v *catalog.Vendor, into map[string]bool) map[string]bool { // secret for any model type of the vendor is redacted for every row of that // vendor. func SecretExtraConfigKeys(provider, baseURL string) map[string]bool { - v, ok := catalog.Get(VendorRef{Provider: provider, BaseURL: baseURL}.vendorID()) + v, ok := modelruntime.Get(VendorRef{Provider: provider, BaseURL: baseURL}.vendorID()) if !ok { return nil } @@ -76,7 +76,7 @@ func SecretExtraConfigKeys(provider, baseURL string) map[string]bool { // withholding a value that happened to reuse the name. func AllSecretExtraConfigKeys() map[string]bool { var keys map[string]bool - for _, v := range catalog.List() { + for _, v := range modelruntime.List() { keys = secretKeysOf(v, keys) } return keys @@ -195,7 +195,7 @@ type ModelResponse struct { Credentials map[string]CredentialFieldMetadata `json:"credentials,omitempty"` // Capabilities is the catalog view of the model: protocol, whether it // can think and at which levels, context window. Chat models only. - Capabilities *catalog.Capabilities `json:"capabilities,omitempty"` + Capabilities *modelruntime.Capabilities `json:"capabilities,omitempty"` } // ModelParametersDTO carries every parameter field EXCEPT the two secret @@ -307,9 +307,9 @@ func NewModelResponse(ctx context.Context, m *types.Model) *ModelResponse { } } } - var caps *catalog.Capabilities + var caps *modelruntime.Capabilities if m.Type == types.ModelTypeKnowledgeQA || m.Type == types.ModelTypeVLLM { - if resolved, err := catalog.Resolve(catalog.Ref{ + if resolved, err := modelruntime.Resolve(modelruntime.Ref{ Provider: m.Parameters.Provider, Model: m.Name, BaseURL: m.Parameters.BaseURL, ModelType: m.Type, Extra: m.Parameters.ExtraConfig, Override: m.Parameters.Spec, }); err == nil && m.Source == types.ModelSourceRemote { diff --git a/internal/handler/dto/model_test.go b/internal/handler/dto/model_test.go index 6af62834..acda2638 100644 --- a/internal/handler/dto/model_test.go +++ b/internal/handler/dto/model_test.go @@ -6,7 +6,8 @@ import ( "strings" "testing" - "github.com/Tencent/WeKnora/internal/models/catalog" + "github.com/Tencent/WeKnora/internal/models/providers" + modelruntime "github.com/Tencent/WeKnora/internal/models/runtime" "github.com/Tencent/WeKnora/internal/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -122,12 +123,12 @@ func TestModelResponse_ViewerStripsIntegrationDetail(t *testing.T) { func registerSecretExtraVendor(t *testing.T) string { t.Helper() id := "dto-secret-extra-vendor" - catalog.Register(&catalog.Vendor{ + modelruntime.Register(&providers.Definition{ ID: id, Name: "Secret Extra Vendor", ModelTypes: []types.ModelType{types.ModelTypeRerank}, URLPatterns: []string{"secret-extra-vendor.example.com"}, - ExtraFields: []catalog.ExtraField{ + ExtraFields: []providers.ExtraField{ {Key: "secret_key", Label: "Secret Key", Type: "password", Secret: true}, {Key: "region", Label: "Region", Type: "string"}, }, diff --git a/internal/handler/initialization.go b/internal/handler/initialization.go index 9bcb6c40..51bce42c 100644 --- a/internal/handler/initialization.go +++ b/internal/handler/initialization.go @@ -25,10 +25,9 @@ import ( "github.com/Tencent/WeKnora/internal/models/asr" "github.com/Tencent/WeKnora/internal/models/chat" "github.com/Tencent/WeKnora/internal/models/embedding" + "github.com/Tencent/WeKnora/internal/models/providers" "github.com/Tencent/WeKnora/internal/models/rerank" "github.com/Tencent/WeKnora/internal/models/utils/ollama" - "github.com/Tencent/WeKnora/internal/models/vendors/lkeap" - "github.com/Tencent/WeKnora/internal/models/vendors/volcengine" "github.com/Tencent/WeKnora/internal/types" "github.com/Tencent/WeKnora/internal/types/interfaces" "github.com/Tencent/WeKnora/internal/utils" @@ -1764,16 +1763,17 @@ func (h *InitializationHandler) buildConfigResponse(ctx context.Context, models // 所有 provider/model 通用字段都在这里集中声明;若未来新增字段(比如现在的 // custom_headers),只需改一处,生产路径和测试路径会同时生效。 type ModelTestRequest struct { - Source string `json:"source"` // 为空时按需默认为 "remote" - ModelName string `json:"modelName" binding:"required"` - BaseURL string `json:"baseUrl"` - APIKey string `json:"apiKey"` - Provider string `json:"provider"` - InterfaceType string `json:"interfaceType,omitempty"` - Dimension int `json:"dimension,omitempty"` - SupportsDimensionOverride bool `json:"supportsDimensionOverride,omitempty"` - CustomHeaders map[string]string `json:"customHeaders,omitempty"` - ExtraConfig map[string]string `json:"extraConfig,omitempty"` + Spec *types.ModelSpecOverride `json:"spec,omitempty"` + Source string `json:"source"` // 为空时按需默认为 "remote" + ModelName string `json:"modelName" binding:"required"` + BaseURL string `json:"baseUrl"` + APIKey string `json:"apiKey"` + Provider string `json:"provider"` + InterfaceType string `json:"interfaceType,omitempty"` + Dimension int `json:"dimension,omitempty"` + SupportsDimensionOverride bool `json:"supportsDimensionOverride,omitempty"` + CustomHeaders map[string]string `json:"customHeaders,omitempty"` + ExtraConfig map[string]string `json:"extraConfig,omitempty"` // AppSecret 用于 LKEAP / Volcengine Rerank 等需要第二段密钥的场景(对应模型 Parameters.AppSecret)。 AppSecret string `json:"appSecret,omitempty"` // ModelID, when set, instructs the handler to substitute any missing @@ -1806,7 +1806,7 @@ func (h *InitializationHandler) fillSecretsFromStoredModel(ctx context.Context, // secret stored in extra_config (LKEAP / Volcengine secret_key) is // redacted by GET, so "extraConfig is present" does not mean it is // complete. - if req.APIKey != "" && req.AppSecret != "" && req.ExtraConfig != nil && + if req.APIKey != "" && req.AppSecret != "" && req.ExtraConfig != nil && req.Spec != nil && dto.HasAllSecretExtras(req.Provider, req.BaseURL, req.ExtraConfig) { return } @@ -1816,6 +1816,9 @@ func (h *InitializationHandler) fillSecretsFromStoredModel(ctx context.Context, utils.SanitizeForLog(req.ModelID), err) return } + if req.Spec == nil && req.Provider == stored.Parameters.Provider { + req.Spec = stored.Parameters.Spec + } if req.APIKey == "" { req.APIKey = stored.Parameters.APIKey } @@ -1872,6 +1875,7 @@ func (h *InitializationHandler) buildTestModel( Provider: req.Provider, InterfaceType: req.InterfaceType, ExtraConfig: req.ExtraConfig, + Spec: req.Spec, CustomHeaders: req.CustomHeaders, EmbeddingParameters: types.EmbeddingParameters{ Dimension: req.Dimension, @@ -2170,7 +2174,7 @@ func (h *InitializationHandler) CheckRerankModel(c *gin.Context) { model := h.buildTestModel(&req, types.ModelTypeRerank, types.ModelSourceRemote) // LKEAP and Volcengine rerank sign with a key pair stored on the row // itself, not with the tenant's WeKnora Cloud credentials. - if p := model.Parameters.Provider; p == lkeap.ID || p == volcengine.ID { + if p := model.Parameters.Provider; p == providers.LkeapID || p == providers.VolcengineID { appID = "" appSecret = decryptModelAppSecret(model.Parameters.AppSecret) } diff --git a/internal/handler/model.go b/internal/handler/model.go index 2a73e723..778546f5 100644 --- a/internal/handler/model.go +++ b/internal/handler/model.go @@ -8,12 +8,13 @@ import ( "strings" "time" + modelruntime "github.com/Tencent/WeKnora/internal/models/runtime" + "github.com/Tencent/WeKnora/internal/application/service" "github.com/Tencent/WeKnora/internal/errors" "github.com/Tencent/WeKnora/internal/handler/dto" "github.com/Tencent/WeKnora/internal/logger" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" "github.com/Tencent/WeKnora/internal/models/chat" "github.com/Tencent/WeKnora/internal/types" "github.com/Tencent/WeKnora/internal/types/interfaces" @@ -759,7 +760,7 @@ func (h *ModelHandler) DeleteModel(c *gin.Context) { // validateCatalogParameters rejects protocol / compat overrides the catalog // cannot interpret (unknown extra_config.api, unknown compat keys, bad // reasoning levels) so a typo fails at save time instead of at the first -// call. Every model type is checked; see catalog.ValidateRow. +// call. Every model type is checked; see modelruntime.ValidateRow. func validateCatalogParameters(name string, modelType types.ModelType, params *types.ModelParameters) error { - return catalog.ValidateRow(name, modelType, params) + return modelruntime.ValidateRow(name, modelType, params) } diff --git a/internal/handler/model_catalog.go b/internal/handler/model_catalog.go index a1f78796..68ca7497 100644 --- a/internal/handler/model_catalog.go +++ b/internal/handler/model_catalog.go @@ -2,14 +2,17 @@ package handler import ( "encoding/base64" + "encoding/json" "net/http" "strings" "github.com/Tencent/WeKnora/internal/errors" "github.com/Tencent/WeKnora/internal/handler/dto" "github.com/Tencent/WeKnora/internal/logger" + "github.com/Tencent/WeKnora/internal/models" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" + "github.com/Tencent/WeKnora/internal/models/providers" + modelruntime "github.com/Tencent/WeKnora/internal/models/runtime" "github.com/Tencent/WeKnora/internal/types" secutils "github.com/Tencent/WeKnora/internal/utils" "github.com/gin-gonic/gin" @@ -27,19 +30,19 @@ type ModelProviderDTO struct { Descriptions map[string]string `json:"descriptions,omitempty"` Website string `json:"website,omitempty"` // Icon is a data: URI (image/svg+xml;base64) ready for . - Icon string `json:"icon,omitempty"` - API api.API `json:"api"` - Auth catalog.AuthStyle `json:"auth"` - RequiresAuth bool `json:"requiresAuth"` - DefaultURLs map[string]string `json:"defaultUrls"` - ModelTypes []string `json:"modelTypes"` - ExtraFields []catalog.ExtraField `json:"extraFields,omitempty"` + Icon string `json:"icon,omitempty"` + API api.API `json:"api"` + Auth providers.AuthStyle `json:"auth"` + RequiresAuth bool `json:"requiresAuth"` + DefaultURLs map[string]string `json:"defaultUrls"` + ModelTypes []string `json:"modelTypes"` + ExtraFields []providers.ExtraField `json:"extraFields,omitempty"` // CredentialLabels rename the primary credential input for the model // types that do not take a plain API key (signed rerank APIs). - CredentialLabels []catalog.CredentialLabel `json:"credentialLabels,omitempty"` - Models []ModelCatalogEntryDTO `json:"models,omitempty"` - Thinking ProviderThinkingDTO `json:"thinking"` - Order int `json:"order"` + CredentialLabels []providers.CredentialLabel `json:"credentialLabels,omitempty"` + Models []ModelCatalogEntryDTO `json:"models,omitempty"` + Thinking ProviderThinkingDTO `json:"thinking"` + Order int `json:"order"` } // ProviderThinkingDTO summarizes how the vendor encodes thinking so the UI @@ -61,7 +64,7 @@ type ModelCatalogEntryDTO struct { MaxOutputTokens int `json:"max_output_tokens,omitempty"` Dimension int `json:"dimension,omitempty"` ThinkingLevels []api.ReasoningEffort `json:"thinking_levels"` - Cost *catalog.ModelCost `json:"cost,omitempty"` + Cost *models.ModelCost `json:"cost,omitempty"` // Source is the vendor page these facts were read from, so the editor can // send an operator to the documentation for this exact model. Source string `json:"source,omitempty"` @@ -93,7 +96,7 @@ func iconDataURI(svg []byte) string { return "data:image/svg+xml;base64," + base64.StdEncoding.EncodeToString(svg) } -func providerDTO(v *catalog.Vendor, modelType types.ModelType, includeModels bool) ModelProviderDTO { +func providerDTO(v *modelruntime.Provider, modelType types.ModelType, includeModels bool) ModelProviderDTO { defaultURLs := make(map[string]string, len(v.DefaultBaseURLs)) for mt, url := range v.DefaultBaseURLs { defaultURLs[modelTypeToFrontend(mt)] = url @@ -123,7 +126,12 @@ func providerDTO(v *catalog.Vendor, modelType types.ModelType, includeModels boo } // Vendor-level thinking summary: resolve an unknown model so only the // vendor defaults contribute. - if resolved, err := catalog.Resolve(catalog.Ref{Provider: v.ID, Model: "__vendor_default__"}); err == nil { + if resolved, err := v.Resolve( + modelruntime.Ref{ + Provider: v.ID, + Model: "__vendor_default__", + }, + ); err == nil { caps := resolved.Capabilities() dto.Thinking = ProviderThinkingDTO{Format: caps.ThinkingFormat, Levels: caps.ThinkingLevels} } @@ -162,7 +170,7 @@ func providerDTO(v *catalog.Vendor, modelType types.ModelType, includeModels boo // derived from Input), so this covers reasoning VLMs too; // embedding / rerank / ASR entries have no thinking levels. if m.Type == "" || m.Type == "KnowledgeQA" { - if resolved, err := catalog.Resolve(catalog.Ref{Provider: v.ID, Model: m.ID}); err == nil { + if resolved, err := v.Resolve(modelruntime.Ref{Provider: v.ID, Model: m.ID}); err == nil { entry.ThinkingLevels = resolved.Capabilities().ThinkingLevels } } @@ -190,7 +198,7 @@ func (h *ModelHandler) ListModelProviders(c *gin.Context) { var backendType types.ModelType if modelType != "" { - parsed, ok := catalog.ParseModelType(modelType) + parsed, ok := models.ParseModelType(modelType) if !ok { _ = c.Error(errors.NewBadRequestError("unknown model_type")) return @@ -198,11 +206,11 @@ func (h *ModelHandler) ListModelProviders(c *gin.Context) { backendType = parsed } - var vendors []*catalog.Vendor + var vendors []*modelruntime.Provider if backendType != "" { - vendors = catalog.ListByType(backendType) + vendors = modelruntime.ListByType(backendType) } else { - vendors = catalog.List() + vendors = modelruntime.List() } // Default base URLs are the editor's prefill, and only a caller who may // configure integrations can use them. A deployment overlay may also @@ -237,13 +245,40 @@ func (h *ModelHandler) ListModelProviders(c *gin.Context) { // @Security ApiKeyAuth // @Router /models/catalog/resolve [get] func (h *ModelHandler) ResolveModelCatalog(c *gin.Context) { + // POST carries the row spec in the body; GET remains compatible with old clients. + query := c.Query + var spec *types.ModelSpecOverride + if c.Request.Method == http.MethodPost { + var body map[string]json.RawMessage + if err := c.ShouldBindJSON(&body); err != nil { + _ = c.Error(errors.NewBadRequestError(err.Error())) + return + } + values := map[string]string{} + for key, raw := range body { + if key == "spec" { + if err := json.Unmarshal(raw, &spec); err != nil { + _ = c.Error(errors.NewBadRequestError("invalid model spec")) + return + } + continue + } + var value string + if err := json.Unmarshal(raw, &value); err != nil { + _ = c.Error(errors.NewBadRequestError("invalid resolve field: " + key)) + return + } + values[key] = value + } + query = func(key string) string { return values[key] } + } ctx := c.Request.Context() - providerID := strings.TrimSpace(c.Query("provider")) - modelName := strings.TrimSpace(c.Query("model")) - baseURL := strings.TrimSpace(c.Query("base_url")) + providerID := strings.TrimSpace(query("provider")) + modelName := strings.TrimSpace(query("model")) + baseURL := strings.TrimSpace(query("base_url")) modelType := types.ModelTypeKnowledgeQA - if raw := c.Query("model_type"); raw != "" { - if parsed, ok := catalog.ParseModelType(raw); ok { + if raw := query("model_type"); raw != "" { + if parsed, ok := models.ParseModelType(raw); ok { modelType = parsed } } @@ -255,23 +290,23 @@ func (h *ModelHandler) ResolveModelCatalog(c *gin.Context) { // here. Secret fields are never accepted: this is a GET, and a credential // in a query string lands in access logs and browser history. extra := map[string]string{} - for _, key := range []string{catalog.ExtraAPI, catalog.ExtraThinkingControl, catalog.ExtraRemoteModelName} { - if v := strings.TrimSpace(c.Query(key)); v != "" { + for _, key := range []string{models.ExtraAPI, models.ExtraThinkingControl, models.ExtraRemoteModelName} { + if v := strings.TrimSpace(query(key)); v != "" { extra[key] = v } } - if vendor, ok := catalog.Get(providerID); ok { + if vendor, ok := modelruntime.Get(providerID); ok { for _, field := range vendor.ExtraFields { if field.Secret || field.Type == "password" { continue } - if v := strings.TrimSpace(c.Query(field.Key)); v != "" { + if v := strings.TrimSpace(query(field.Key)); v != "" { extra[field.Key] = v } } } - resolved, err := catalog.Resolve(catalog.Ref{ - Provider: providerID, Model: modelName, BaseURL: baseURL, ModelType: modelType, Extra: extra, + resolved, err := modelruntime.Resolve(modelruntime.Ref{ + Provider: providerID, Model: modelName, BaseURL: baseURL, ModelType: modelType, Extra: extra, Override: spec, }) if err != nil { _ = c.Error(errors.NewBadRequestError(err.Error())) @@ -300,7 +335,7 @@ func (h *ModelHandler) ResolveModelCatalog(c *gin.Context) { // normalise several base-URL shapes) report nothing rather than a // path this endpoint would have to guess. if resolved.Vendor.Endpoint != nil { - endpointURL, query := resolved.Vendor.Endpoint(catalog.EndpointRequest{ + endpointURL, query := resolved.Vendor.Endpoint(providers.EndpointRequest{ BaseURL: resolved.BaseURL, Model: resolved.RemoteModel, ModelType: modelType, diff --git a/internal/handler/model_catalog_visibility_test.go b/internal/handler/model_catalog_visibility_test.go index 4ae7b8af..0d3848cd 100644 --- a/internal/handler/model_catalog_visibility_test.go +++ b/internal/handler/model_catalog_visibility_test.go @@ -10,8 +10,6 @@ import ( "github.com/Tencent/WeKnora/internal/types" "github.com/gin-gonic/gin" - - _ "github.com/Tencent/WeKnora/internal/models/vendors" ) // listProvidersAs drives the real handler with one tenant role. diff --git a/internal/handler/model_secret_extra_test.go b/internal/handler/model_secret_extra_test.go index 2fed4ce0..4a170b2b 100644 --- a/internal/handler/model_secret_extra_test.go +++ b/internal/handler/model_secret_extra_test.go @@ -8,7 +8,8 @@ import ( "net/http/httptest" "testing" - "github.com/Tencent/WeKnora/internal/models/catalog" + "github.com/Tencent/WeKnora/internal/models/providers" + modelruntime "github.com/Tencent/WeKnora/internal/models/runtime" "github.com/Tencent/WeKnora/internal/types" "github.com/Tencent/WeKnora/internal/types/interfaces" "github.com/gin-gonic/gin" @@ -43,16 +44,16 @@ const ( func registerSecretExtraVendor(t *testing.T) { t.Helper() - catalog.Register(&catalog.Vendor{ + modelruntime.Register(&providers.Definition{ ID: secretExtraProvider, Name: "Secret Extra Vendor", ModelTypes: []types.ModelType{types.ModelTypeRerank}, - ExtraFields: []catalog.ExtraField{ + ExtraFields: []providers.ExtraField{ {Key: "secret_key", Label: "Secret Key", Type: "password", Secret: true}, {Key: "region", Label: "Region", Type: "string"}, }, }) - catalog.Register(&catalog.Vendor{ + modelruntime.Register(&providers.Definition{ ID: plainExtraProvider, Name: "Plain Extra Vendor", ModelTypes: []types.ModelType{types.ModelTypeRerank}, diff --git a/internal/handler/model_spec_flow_test.go b/internal/handler/model_spec_flow_test.go new file mode 100644 index 00000000..3bc72b6c --- /dev/null +++ b/internal/handler/model_spec_flow_test.go @@ -0,0 +1,69 @@ +package handler + +import ( + "encoding/json" + "net/http" + "net/http/httptest" + "strings" + "testing" + + "github.com/Tencent/WeKnora/internal/types" + "github.com/gin-gonic/gin" + "github.com/stretchr/testify/require" +) + +func TestResolvePostUsesUnsavedSpec(t *testing.T) { + gin.SetMode(gin.TestMode) + recorder := httptest.NewRecorder() + c, _ := gin.CreateTestContext(recorder) + c.Request = httptest.NewRequest(http.MethodPost, "/api/v1/models/catalog/resolve", strings.NewReader(`{ + "provider": "openai", + "model": "gpt-5", + "base_url": "https://api.openai.com/v1", + "spec": { + "api": "openai-completions", + "context_window": 12345, + "compat": { + "supports_temperature": false + } + } +}`)) + c.Request.Header.Set("Content-Type", "application/json") + (&ModelHandler{}).ResolveModelCatalog(c) + require.Empty(t, c.Errors) + var body struct { + Data struct { + API string `json:"api"` + Capabilities struct { + ContextWindow int `json:"context_window"` + } `json:"capabilities"` + } `json:"data"` + } + require.NoError(t, json.Unmarshal(recorder.Body.Bytes(), &body)) + require.Equal(t, "openai-completions", body.Data.API) + require.Equal(t, 12345, body.Data.Capabilities.ContextWindow) +} + +func TestConnectionTestModelCarriesSpecForEveryCapability(t *testing.T) { + spec := &types.ModelSpecOverride{Compat: map[string]any{"path": "/custom"}} + for _, kind := range []types.ModelType{ + types.ModelTypeKnowledgeQA, + types.ModelTypeEmbedding, + types.ModelTypeRerank, + types.ModelTypeASR, + types.ModelTypeVLLM, + } { + row := (&InitializationHandler{}).buildTestModel( + &ModelTestRequest{ + ModelName: "test", + Provider: "generic", + APIKey: "row-key", + Spec: spec, + }, + kind, + types.ModelSourceRemote, + ) + require.Equal(t, spec, row.Parameters.Spec) + require.Equal(t, "row-key", row.Parameters.APIKey) + } +} diff --git a/internal/handler/model_test.go b/internal/handler/model_test.go index b3e51024..91334a10 100644 --- a/internal/handler/model_test.go +++ b/internal/handler/model_test.go @@ -4,7 +4,8 @@ import ( "encoding/json" "testing" - "github.com/Tencent/WeKnora/internal/models/catalog" + "github.com/Tencent/WeKnora/internal/models/providers" + modelruntime "github.com/Tencent/WeKnora/internal/models/runtime" "github.com/Tencent/WeKnora/internal/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -52,11 +53,11 @@ func TestRedactedDebugConfig(t *testing.T) { // credential field is called something the name heuristic cannot guess is // still redacted, because the vendor declared it Secret. func TestRedactedDebugConfigUsesVendorDeclaration(t *testing.T) { - catalog.Register(&catalog.Vendor{ + modelruntime.Register(&providers.Definition{ ID: "handler-debug-redaction-vendor", Name: "Debug Redaction Vendor", ModelTypes: []types.ModelType{types.ModelTypeRerank}, - ExtraFields: []catalog.ExtraField{ + ExtraFields: []providers.ExtraField{ {Key: "signing_material", Label: "Signing Material", Secret: true}, }, }) diff --git a/internal/models/api/anthropicmessages/anthropicmessages_test.go b/internal/models/api/anthropicmessages/anthropicmessages_test.go index 3e03c7db..43e8a5d8 100644 --- a/internal/models/api/anthropicmessages/anthropicmessages_test.go +++ b/internal/models/api/anthropicmessages/anthropicmessages_test.go @@ -9,7 +9,6 @@ import ( "testing" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" "github.com/Tencent/WeKnora/internal/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -23,7 +22,7 @@ func newClient(t *testing.T, baseURL string, mutate func(*Config)) *Client { Auth: api.HeaderAuth("x-api-key", "test-key"), Headers: map[string]string{"anthropic-beta": "test-beta"}, }, - Settings: catalog.DefaultAnthropicMessages(), + Settings: api.DefaultAnthropicMessages(), ThinkingLevels: api.ThinkingLevelMap{}, Reasoning: true, } @@ -98,7 +97,7 @@ func TestBuildRequestBody_BudgetThinkingAndTools(t *testing.T) { func TestBuildRequestBody_AdaptiveEffort(t *testing.T) { c := newClient(t, "https://api.anthropic.com/v1", func(cfg *Config) { - cfg.Settings.ThinkingMode = catalog.AnthropicThinkingAdaptive + cfg.Settings.ThinkingMode = api.AnthropicThinkingAdaptive cfg.Settings.SupportsEffort = true cfg.ThinkingLevels = api.ThinkingLevelMap{api.ReasoningXHigh: api.StringPtr("max")} }) diff --git a/internal/models/api/anthropicmessages/request.go b/internal/models/api/anthropicmessages/request.go index a57e4cc7..93deae6f 100644 --- a/internal/models/api/anthropicmessages/request.go +++ b/internal/models/api/anthropicmessages/request.go @@ -2,7 +2,7 @@ // (https://docs.anthropic.com/en/api/messages). MiniMax, Zhipu, Moonshot and // Volcengine expose the same protocol on an ".../anthropic" base URL, so the // package contains no vendor names: every deviation is a -// catalog.AnthropicMessagesSettings field. +// api.AnthropicMessagesSettings field. package anthropicmessages import ( @@ -12,14 +12,13 @@ import ( "strings" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" "github.com/Tencent/WeKnora/internal/types" ) -// Config is everything the client needs, already resolved by the catalog. +// Config is everything the client needs, already resolved by the api. type Config struct { Endpoint api.Endpoint - Settings catalog.AnthropicMessagesSettings + Settings api.AnthropicMessagesSettings ThinkingLevels api.ThinkingLevelMap Reasoning bool } @@ -142,7 +141,7 @@ func (c *Client) planThinking(opts *api.Options) thinkingPlan { level = levels.Clamp(level) } if !level.Enabled() { - if levels.Supports(api.ReasoningOff) && s.ThinkingMode == catalog.AnthropicThinkingAdaptive { + if levels.Supports(api.ReasoningOff) && s.ThinkingMode == api.AnthropicThinkingAdaptive { return thinkingPlan{body: map[string]any{"type": "disabled"}} } // Budget mode: omitting the thinking object disables it. @@ -150,7 +149,7 @@ func (c *Client) planThinking(opts *api.Options) thinkingPlan { } plan := thinkingPlan{enabled: true} switch s.ThinkingMode { - case catalog.AnthropicThinkingAdaptive: + case api.AnthropicThinkingAdaptive: plan.body = map[string]any{"type": "adaptive"} if level.Graded() && s.SupportsEffort { plan.effort = levels.Value(level) @@ -309,7 +308,7 @@ func (c *Client) betaHeader(plan thinkingPlan, opts *api.Options, userValue stri for _, b := range s.BetaHeaders { add(b) } - if plan.enabled && s.ThinkingMode != catalog.AnthropicThinkingAdaptive && s.InterleavedThinkingBeta != "" && + if plan.enabled && s.ThinkingMode != api.AnthropicThinkingAdaptive && s.InterleavedThinkingBeta != "" && opts != nil && len(opts.Tools) > 0 { add(s.InterleavedThinkingBeta) } diff --git a/internal/models/api/arkembeddings/client.go b/internal/models/api/arkembeddings/client.go index e9bdffd3..a4eb00fa 100644 --- a/internal/models/api/arkembeddings/client.go +++ b/internal/models/api/arkembeddings/client.go @@ -22,13 +22,12 @@ import ( "fmt" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" ) -// Config is everything the client needs, already resolved by the catalog. +// Config is everything the client needs, already resolved by the api. type Config struct { Endpoint api.Endpoint - Settings catalog.EmbeddingsSettings + Settings api.EmbeddingsSettings Dimensions int Retry api.RetryPolicy } diff --git a/internal/models/api/arkembeddings/golden_test.go b/internal/models/api/arkembeddings/golden_test.go index 9fe8a313..00a5ddd7 100644 --- a/internal/models/api/arkembeddings/golden_test.go +++ b/internal/models/api/arkembeddings/golden_test.go @@ -7,7 +7,6 @@ import ( "testing" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -35,7 +34,7 @@ const endpoint = "/api/v3/embeddings/multimodal" func newClient(url string, dims int) *Client { return New(Config{ Endpoint: api.Endpoint{BaseURL: url, Model: "doubao-embedding-vision-251215", Auth: api.BearerAuth("k")}, - Settings: catalog.EmbeddingsSettings{ + Settings: api.EmbeddingsSettings{ SendEncodingFormat: true, DimensionsField: "dimensions", }, Dimensions: dims, diff --git a/internal/models/api/cohererank/client.go b/internal/models/api/cohererank/client.go index a8365048..7aebd347 100644 --- a/internal/models/api/cohererank/client.go +++ b/internal/models/api/cohererank/client.go @@ -5,7 +5,7 @@ // Jina, Zhipu, SiliconFlow, Qianfan, GPUStack, WeKnora Cloud and any // OpenAI-compatible gateway that serves rerank all speak it. Their // differences — which optional fields are accepted, where the endpoint sits, -// what the documented ceilings are — arrive as catalog.RerankSettings; this +// what the documented ceilings are — arrive as api.RerankSettings; this // package contains no vendor names. package cohererank @@ -16,13 +16,12 @@ import ( "strings" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" ) -// Config is everything the client needs, already resolved by the catalog. +// Config is everything the client needs, already resolved by the api. type Config struct { Endpoint api.Endpoint - Settings catalog.RerankSettings + Settings api.RerankSettings } // Client talks the Cohere rerank shape to one endpoint. diff --git a/internal/models/api/cohererank/golden_test.go b/internal/models/api/cohererank/golden_test.go index 7b2ef8b3..23b6c8e3 100644 --- a/internal/models/api/cohererank/golden_test.go +++ b/internal/models/api/cohererank/golden_test.go @@ -8,7 +8,6 @@ import ( "testing" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -40,7 +39,7 @@ const jinaResponse = `{ "usage": {"total_tokens": 32} }` -func newClient(t *testing.T, url string, settings catalog.RerankSettings) *Client { +func newClient(t *testing.T, url string, settings api.RerankSettings) *Client { t.Helper() return New(Config{ Endpoint: api.Endpoint{BaseURL: url, Model: "rerank", Auth: api.BearerAuth("k")}, @@ -63,7 +62,7 @@ func serve(t *testing.T, payload string) (*httptest.Server, *string, *map[string } func TestRequestBodyCarriesOnlyWhatTheVendorDeclares(t *testing.T) { - c := newClient(t, "https://example.invalid/v1", catalog.RerankSettings{}) + c := newClient(t, "https://example.invalid/v1", api.RerankSettings{}) body, err := c.BuildRequestBody("上海天气", []string{"上海气候", "北京美食"}) require.NoError(t, err) @@ -76,7 +75,7 @@ func TestRequestBodyCarriesOnlyWhatTheVendorDeclares(t *testing.T) { func TestRequestBodyAddsTheOptionalFieldsAVendorDeclares(t *testing.T) { c := newClient(t, "https://example.invalid/v1", - catalog.RerankSettings{SendTopN: true, SendReturnDocs: true}) + api.RerankSettings{SendTopN: true, SendReturnDocs: true}) body, err := c.BuildRequestBody("q", []string{"a", "b", "c"}) require.NoError(t, err) @@ -88,7 +87,7 @@ func TestDecodesAStringDocument(t *testing.T) { server, _, _ := serve(t, zhipuResponse) defer server.Close() - c := newClient(t, server.URL, catalog.RerankSettings{}) + c := newClient(t, server.URL, api.RerankSettings{}) got, err := c.Rerank(context.Background(), "上海天气", []string{"北京美食", "上海气候"}) require.NoError(t, err) @@ -102,7 +101,7 @@ func TestDecodesAnObjectDocument(t *testing.T) { server, _, _ := serve(t, jinaResponse) defer server.Close() - c := newClient(t, server.URL, catalog.RerankSettings{}) + c := newClient(t, server.URL, api.RerankSettings{}) got, err := c.Rerank(context.Background(), "上海天气", []string{"上海气候", "北京美食"}) require.NoError(t, err) @@ -118,7 +117,7 @@ func TestDecodesTheScoreAlias(t *testing.T) { server, _, _ := serve(t, `{"results":[{"index":0,"score":0.42}]}`) defer server.Close() - c := newClient(t, server.URL, catalog.RerankSettings{}) + c := newClient(t, server.URL, api.RerankSettings{}) got, err := c.Rerank(context.Background(), "q", []string{"d"}) require.NoError(t, err) require.Len(t, got, 1) @@ -129,7 +128,7 @@ func TestAppendsTheRerankPathToABareBaseURL(t *testing.T) { server, path, _ := serve(t, `{"results":[]}`) defer server.Close() - c := newClient(t, server.URL+"/v1", catalog.RerankSettings{}) + c := newClient(t, server.URL+"/v1", api.RerankSettings{}) _, err := c.Rerank(context.Background(), "q", []string{"d"}) require.NoError(t, err) assert.Equal(t, "/v1/rerank", *path) @@ -141,7 +140,7 @@ func TestDoesNotDoubleTheRerankPath(t *testing.T) { server, path, _ := serve(t, `{"results":[]}`) defer server.Close() - c := newClient(t, server.URL+"/api/paas/v4/rerank", catalog.RerankSettings{}) + c := newClient(t, server.URL+"/api/paas/v4/rerank", api.RerankSettings{}) _, err := c.Rerank(context.Background(), "q", []string{"d"}) require.NoError(t, err) assert.Equal(t, "/api/paas/v4/rerank", *path) @@ -152,7 +151,7 @@ func TestHonoursAVendorDeclaredPath(t *testing.T) { server, path, _ := serve(t, `{"results":[]}`) defer server.Close() - c := newClient(t, server.URL, catalog.RerankSettings{Path: "/api/v1/rerank"}) + c := newClient(t, server.URL, api.RerankSettings{Path: "/api/v1/rerank"}) _, err := c.Rerank(context.Background(), "q", []string{"d"}) require.NoError(t, err) assert.Equal(t, "/api/v1/rerank", *path) @@ -162,7 +161,7 @@ func TestRejectsAnOutOfRangeIndex(t *testing.T) { server, _, _ := serve(t, `{"results":[{"index":9,"relevance_score":0.5}]}`) defer server.Close() - c := newClient(t, server.URL, catalog.RerankSettings{}) + c := newClient(t, server.URL, api.RerankSettings{}) _, err := c.Rerank(context.Background(), "q", []string{"d"}) require.Error(t, err) assert.Contains(t, err.Error(), "out of range") @@ -176,7 +175,7 @@ func TestSurfacesTheVendorErrorBody(t *testing.T) { })) defer server.Close() - c := newClient(t, server.URL, catalog.RerankSettings{}) + c := newClient(t, server.URL, api.RerankSettings{}) _, err := c.Rerank(context.Background(), "q", []string{"d"}) require.Error(t, err) assert.Contains(t, err.Error(), "documents exceeds the limit") @@ -187,14 +186,14 @@ func TestSurfacesTheVendorErrorBody(t *testing.T) { // and the operator opted in, and never by default — sending it unasked is how // an undocumented field ends up on every request to every gateway. func TestTruncatePromptTokensIsAbsentByDefault(t *testing.T) { - c := newClient(t, "https://example.invalid/v1", catalog.RerankSettings{}) + c := newClient(t, "https://example.invalid/v1", api.RerankSettings{}) body, err := c.BuildRequestBody("q", []string{"d"}) require.NoError(t, err) assert.NotContains(t, body, "truncate_prompt_tokens") } func TestTruncatePromptTokensIsSentWhenTheRowOptedIn(t *testing.T) { - c := newClient(t, "https://example.invalid/v1", catalog.RerankSettings{ + c := newClient(t, "https://example.invalid/v1", api.RerankSettings{ AcceptsTruncatePromptTokens: true, TruncatePromptTokens: 512, }) body, err := c.BuildRequestBody("q", []string{"d"}) diff --git a/internal/models/catalog/compat.go b/internal/models/api/compat_settings.go similarity index 70% rename from internal/models/catalog/compat.go rename to internal/models/api/compat_settings.go index f2a479d0..fae87b8c 100644 --- a/internal/models/catalog/compat.go +++ b/internal/models/api/compat_settings.go @@ -1,12 +1,4 @@ -package catalog - -import ( - "encoding/json" - "fmt" - "reflect" - - "github.com/Tencent/WeKnora/internal/models/api" -) +package api // ThinkingFormat names how an OpenAI-compatible vendor encodes the thinking // switch. It is the single most divergent field across vendors, which is @@ -183,7 +175,7 @@ type OpenAIResponsesSettings struct { ExtraBody map[string]any } -// DefaultOpenAIResponses is the api.openai.com baseline. +// DefaultOpenAIResponses is the openai.com baseline. func DefaultOpenAIResponses() OpenAIResponsesSettings { return OpenAIResponsesSettings{ SupportsDeveloperRole: true, @@ -211,21 +203,21 @@ const ( // AnthropicMessagesCompat is the overlay for the Messages protocol. type AnthropicMessagesCompat struct { - ThinkingMode *AnthropicThinkingMode `json:"thinking_mode,omitempty"` - SupportsEffort *bool `json:"supports_effort,omitempty"` - ThinkingBudgets map[api.ReasoningEffort]int `json:"thinking_budgets,omitempty"` - DefaultMaxTokens *int `json:"default_max_tokens,omitempty"` - SupportsTemperature *bool `json:"supports_temperature,omitempty"` - TemperatureWithThinking *bool `json:"temperature_with_thinking,omitempty"` - SupportsTopP *bool `json:"supports_top_p,omitempty"` - SupportsCacheControl *bool `json:"supports_cache_control,omitempty"` - SupportsCacheControlOnTool *bool `json:"supports_cache_control_on_tools,omitempty"` - LongCacheTTL *string `json:"long_cache_ttl,omitempty"` - Version *string `json:"version,omitempty"` - BetaHeaders []string `json:"beta_headers,omitempty"` - InterleavedThinkingBeta *string `json:"interleaved_thinking_beta,omitempty"` - PromptCacheAccounting *bool `json:"prompt_cache_accounting,omitempty"` - ExtraBody map[string]any `json:"extra_body,omitempty"` + ThinkingMode *AnthropicThinkingMode `json:"thinking_mode,omitempty"` + SupportsEffort *bool `json:"supports_effort,omitempty"` + ThinkingBudgets map[ReasoningEffort]int `json:"thinking_budgets,omitempty"` + DefaultMaxTokens *int `json:"default_max_tokens,omitempty"` + SupportsTemperature *bool `json:"supports_temperature,omitempty"` + TemperatureWithThinking *bool `json:"temperature_with_thinking,omitempty"` + SupportsTopP *bool `json:"supports_top_p,omitempty"` + SupportsCacheControl *bool `json:"supports_cache_control,omitempty"` + SupportsCacheControlOnTool *bool `json:"supports_cache_control_on_tools,omitempty"` + LongCacheTTL *string `json:"long_cache_ttl,omitempty"` + Version *string `json:"version,omitempty"` + BetaHeaders []string `json:"beta_headers,omitempty"` + InterleavedThinkingBeta *string `json:"interleaved_thinking_beta,omitempty"` + PromptCacheAccounting *bool `json:"prompt_cache_accounting,omitempty"` + ExtraBody map[string]any `json:"extra_body,omitempty"` } // AnthropicMessagesSettings is the resolved Messages configuration. @@ -233,7 +225,7 @@ type AnthropicMessagesSettings struct { ThinkingMode AnthropicThinkingMode SupportsEffort bool // ThinkingBudgets maps graded levels to budget_tokens for budget mode. - ThinkingBudgets map[api.ReasoningEffort]int + ThinkingBudgets map[ReasoningEffort]int // DefaultMaxTokens is used when the caller set no budget (max_tokens is // mandatory on this protocol). DefaultMaxTokens int @@ -252,18 +244,18 @@ type AnthropicMessagesSettings struct { ExtraBody map[string]any } -// DefaultAnthropicMessages is the api.anthropic.com baseline for the +// DefaultAnthropicMessages is the anthropic.com baseline for the // budget-thinking generation of models. func DefaultAnthropicMessages() AnthropicMessagesSettings { return AnthropicMessagesSettings{ ThinkingMode: AnthropicThinkingBudget, - ThinkingBudgets: map[api.ReasoningEffort]int{ - api.ReasoningMinimal: 1024, - api.ReasoningLow: 2048, - api.ReasoningMedium: 8192, - api.ReasoningHigh: 16384, - api.ReasoningXHigh: 32768, - api.ReasoningMax: 63999, + ThinkingBudgets: map[ReasoningEffort]int{ + ReasoningMinimal: 1024, + ReasoningLow: 2048, + ReasoningMedium: 8192, + ReasoningHigh: 16384, + ReasoningXHigh: 32768, + ReasoningMax: 63999, }, DefaultMaxTokens: 4096, SupportsTemperature: true, @@ -292,20 +284,20 @@ const ( // GoogleGenerativeAICompat is the overlay for the Gemini protocol. type GoogleGenerativeAICompat struct { - ThinkingMode *GoogleThinkingMode `json:"thinking_mode,omitempty"` - ThinkingBudgets map[api.ReasoningEffort]int `json:"thinking_budgets,omitempty"` - IncludeThoughts *bool `json:"include_thoughts,omitempty"` - SupportsSeed *bool `json:"supports_seed,omitempty"` - SupportsPenalty *bool `json:"supports_penalty,omitempty"` - ExtraGeneration map[string]any `json:"extra_generation_config,omitempty"` - PromptCacheAcct *bool `json:"prompt_cache_accounting,omitempty"` - APIVersionPrefix *string `json:"api_version_prefix,omitempty"` + ThinkingMode *GoogleThinkingMode `json:"thinking_mode,omitempty"` + ThinkingBudgets map[ReasoningEffort]int `json:"thinking_budgets,omitempty"` + IncludeThoughts *bool `json:"include_thoughts,omitempty"` + SupportsSeed *bool `json:"supports_seed,omitempty"` + SupportsPenalty *bool `json:"supports_penalty,omitempty"` + ExtraGeneration map[string]any `json:"extra_generation_config,omitempty"` + PromptCacheAcct *bool `json:"prompt_cache_accounting,omitempty"` + APIVersionPrefix *string `json:"api_version_prefix,omitempty"` } // GoogleGenerativeAISettings is the resolved Gemini configuration. type GoogleGenerativeAISettings struct { ThinkingMode GoogleThinkingMode - ThinkingBudgets map[api.ReasoningEffort]int + ThinkingBudgets map[ReasoningEffort]int IncludeThoughts bool SupportsSeed bool SupportsPenalty bool @@ -319,13 +311,13 @@ type GoogleGenerativeAISettings struct { func DefaultGoogleGenerativeAI() GoogleGenerativeAISettings { return GoogleGenerativeAISettings{ ThinkingMode: GoogleThinkingBudget, - ThinkingBudgets: map[api.ReasoningEffort]int{ - api.ReasoningMinimal: 128, - api.ReasoningLow: 2048, - api.ReasoningMedium: 8192, - api.ReasoningHigh: 24576, - api.ReasoningXHigh: 32768, - api.ReasoningMax: 32768, + ThinkingBudgets: map[ReasoningEffort]int{ + ReasoningMinimal: 128, + ReasoningLow: 2048, + ReasoningMedium: 8192, + ReasoningHigh: 24576, + ReasoningXHigh: 32768, + ReasoningMax: 32768, }, IncludeThoughts: true, SupportsSeed: true, @@ -334,79 +326,3 @@ func DefaultGoogleGenerativeAI() GoogleGenerativeAISettings { APIVersionPrefix: "/v1beta", } } - -// VendorCompat carries a vendor's defaults for every protocol it may speak. -type VendorCompat struct { - OpenAICompletions OpenAICompletionsCompat `json:"openai_completions,omitempty"` - OpenAIResponses OpenAIResponsesCompat `json:"openai_responses,omitempty"` - AnthropicMessages AnthropicMessagesCompat `json:"anthropic_messages,omitempty"` - GoogleGenerativeAI GoogleGenerativeAICompat `json:"google_generative_ai,omitempty"` - // Rerank is the rerank protocol overlay. It has no per-protocol variants: - // a vendor serves exactly one rerank dialect. - Rerank RerankCompat `json:"rerank,omitempty"` - // Embeddings is the embedding protocol overlay, likewise one per vendor. - Embeddings EmbeddingsCompat `json:"embeddings,omitempty"` - // Transcriptions is the speech-to-text overlay, likewise one per vendor. - Transcriptions TranscriptionsCompat `json:"transcriptions,omitempty"` -} - -// apply writes the set fields of an overlay struct onto a settings struct -// with matching field names, dereferencing pointers. Slices and maps -// replace the default wholesale (no element merge) except map[string]any -// ExtraBody-style fields, which merge key by key. -func apply(settings any, compat any) { - sv := reflect.ValueOf(settings).Elem() - cv := reflect.ValueOf(compat).Elem() - ct := cv.Type() - for i := 0; i < cv.NumField(); i++ { - field := ct.Field(i) - if !field.IsExported() { - continue - } - target := sv.FieldByName(field.Name) - if !target.IsValid() { - panic(fmt.Sprintf("catalog: overlay field %s.%s has no settings counterpart", ct.Name(), field.Name)) - } - f := cv.Field(i) - switch f.Kind() { - case reflect.Pointer: - if f.IsNil() { - continue - } - if target.Kind() == reflect.Pointer { - target.Set(f) - } else { - target.Set(f.Elem()) - } - case reflect.Slice: - if f.Len() > 0 { - target.Set(f) - } - case reflect.Map: - if f.Len() == 0 { - continue - } - if target.IsNil() { - target.Set(reflect.MakeMap(target.Type())) - } - iter := f.MapRange() - for iter.Next() { - target.SetMapIndex(iter.Key(), iter.Value()) - } - } - } -} - -// decodeCompat unmarshals a flat compat object into the overlay type for an -// API. Unknown keys are rejected so typos in models.json surface early. -func decodeCompat(raw json.RawMessage, into any) error { - if len(raw) == 0 { - return nil - } - dec := json.NewDecoder(bytesReader(raw)) - dec.DisallowUnknownFields() - if err := dec.Decode(into); err != nil { - return fmt.Errorf("decode compat: %w", err) - } - return nil -} diff --git a/internal/models/api/credentials.go b/internal/models/api/credentials.go new file mode 100644 index 00000000..eeb1c816 --- /dev/null +++ b/internal/models/api/credentials.go @@ -0,0 +1,11 @@ +package api + +// Credentials is what the operator stored for one model row. +type Credentials struct { + APIKey string + AppID string + AppSecret string +} + +// Ptr returns a pointer for optional protocol settings. +func Ptr[T any](value T) *T { return &value } diff --git a/internal/models/api/dashscopeembeddings/client.go b/internal/models/api/dashscopeembeddings/client.go index 35883823..3ca33463 100644 --- a/internal/models/api/dashscopeembeddings/client.go +++ b/internal/models/api/dashscopeembeddings/client.go @@ -14,13 +14,12 @@ import ( "fmt" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" ) -// Config is everything the client needs, already resolved by the catalog. +// Config is everything the client needs, already resolved by the api. type Config struct { Endpoint api.Endpoint - Settings catalog.EmbeddingsSettings + Settings api.EmbeddingsSettings Dimensions int Retry api.RetryPolicy } diff --git a/internal/models/api/dashscopeembeddings/golden_test.go b/internal/models/api/dashscopeembeddings/golden_test.go index 1cc92451..d8eaa93e 100644 --- a/internal/models/api/dashscopeembeddings/golden_test.go +++ b/internal/models/api/dashscopeembeddings/golden_test.go @@ -7,7 +7,6 @@ import ( "testing" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -35,7 +34,7 @@ const endpoint = "/api/v1/services/embeddings/multimodal-embedding/multimodal-em func newClient(url string, dims int) *Client { return New(Config{ Endpoint: api.Endpoint{BaseURL: url, Model: "tongyi-embedding-vision-plus", Auth: api.BearerAuth("k")}, - Settings: catalog.EmbeddingsSettings{DimensionsField: "dimension"}, + Settings: api.EmbeddingsSettings{DimensionsField: "dimension"}, Dimensions: dims, }) } diff --git a/internal/models/api/dashscoperank/client.go b/internal/models/api/dashscoperank/client.go index 1f1fc4c0..ccdcfbbf 100644 --- a/internal/models/api/dashscoperank/client.go +++ b/internal/models/api/dashscoperank/client.go @@ -11,13 +11,12 @@ import ( "fmt" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" ) -// Config is everything the client needs, already resolved by the catalog. +// Config is everything the client needs, already resolved by the api. type Config struct { Endpoint api.Endpoint - Settings catalog.RerankSettings + Settings api.RerankSettings } // Client talks DashScope's native rerank to one endpoint. diff --git a/internal/models/api/dashscoperank/golden_test.go b/internal/models/api/dashscoperank/golden_test.go index 675cdca2..42e7b26d 100644 --- a/internal/models/api/dashscoperank/golden_test.go +++ b/internal/models/api/dashscoperank/golden_test.go @@ -8,7 +8,6 @@ import ( "testing" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -29,7 +28,7 @@ const documentedResponse = `{ const endpointURL = "https://dashscope.aliyuncs.com/api/v1/services/rerank/text-rerank/text-rerank" -func newClient(t *testing.T, url string, settings catalog.RerankSettings) *Client { +func newClient(t *testing.T, url string, settings api.RerankSettings) *Client { t.Helper() return New(Config{ Endpoint: api.Endpoint{BaseURL: url, Model: "gte-rerank-v2", Auth: api.BearerAuth("k")}, @@ -38,7 +37,7 @@ func newClient(t *testing.T, url string, settings catalog.RerankSettings) *Clien } func TestRequestBodyMatchesTheDocumentedSchema(t *testing.T) { - c := newClient(t, endpointURL, catalog.RerankSettings{SendReturnDocs: true}) + c := newClient(t, endpointURL, api.RerankSettings{SendReturnDocs: true}) body, err := c.BuildRequestBody("上海天气", []string{"北京美食", "上海气候"}) require.NoError(t, err) @@ -58,7 +57,7 @@ func TestRequestBodyMatchesTheDocumentedSchema(t *testing.T) { // top_n is mandatory in this shape: zero would ask for nothing back, so the // full document count is always sent regardless of vendor settings. func TestTopNAlwaysCarriesTheDocumentCount(t *testing.T) { - c := newClient(t, endpointURL, catalog.RerankSettings{}) + c := newClient(t, endpointURL, api.RerankSettings{}) body, err := c.BuildRequestBody("q", []string{"a", "b", "c", "d"}) require.NoError(t, err) assert.Equal(t, float64(4), body["parameters"].(map[string]any)["top_n"]) @@ -72,7 +71,7 @@ func TestDecodesTheDocumentedResponse(t *testing.T) { })) defer server.Close() - c := newClient(t, server.URL, catalog.RerankSettings{}) + c := newClient(t, server.URL, api.RerankSettings{}) got, err := c.Rerank(context.Background(), "上海天气", []string{"北京美食", "上海气候"}) require.NoError(t, err) @@ -91,7 +90,7 @@ func TestSurfacesAnInBodyError(t *testing.T) { })) defer server.Close() - c := newClient(t, server.URL, catalog.RerankSettings{}) + c := newClient(t, server.URL, api.RerankSettings{}) _, err := c.Rerank(context.Background(), "q", []string{"d"}) require.Error(t, err) assert.Contains(t, err.Error(), "documents is too long") @@ -108,7 +107,7 @@ func TestPostsToTheBaseURLItself(t *testing.T) { })) defer server.Close() - c := newClient(t, server.URL+"/api/v1/services/rerank/text-rerank/text-rerank", catalog.RerankSettings{}) + c := newClient(t, server.URL+"/api/v1/services/rerank/text-rerank/text-rerank", api.RerankSettings{}) _, err := c.Rerank(context.Background(), "q", []string{"d"}) require.NoError(t, err) assert.Equal(t, "/api/v1/services/rerank/text-rerank/text-rerank", gotPath, diff --git a/internal/models/catalog/embeddings.go b/internal/models/api/embeddings_settings.go similarity index 89% rename from internal/models/catalog/embeddings.go rename to internal/models/api/embeddings_settings.go index 87b12b0f..85db5fdc 100644 --- a/internal/models/catalog/embeddings.go +++ b/internal/models/api/embeddings_settings.go @@ -1,6 +1,4 @@ -package catalog - -import "github.com/Tencent/WeKnora/internal/models/api" +package api // EmbeddingsCompat is the overlay form (every field optional) of the // embedding settings. JSON keys are the documented names used in models.json @@ -9,7 +7,7 @@ type EmbeddingsCompat struct { // API overrides the vendor's embedding protocol for one model. Aliyun and // Volcengine each serve two: a text endpoint in the OpenAI shape and a // multimodal one of their own, chosen by which model the row names. - API *api.EmbeddingAPI `json:"api,omitempty"` + API *EmbeddingAPI `json:"api,omitempty"` Path *string `json:"path,omitempty"` SendEncodingFormat *bool `json:"send_encoding_format,omitempty"` DimensionsField *string `json:"dimensions_field,omitempty"` @@ -30,7 +28,7 @@ type EmbeddingsCompat struct { type EmbeddingsSettings struct { // API is the protocol this model speaks, which may differ from the // vendor's default. - API api.EmbeddingAPI + API EmbeddingAPI // Path is appended to the base URL; vendors whose default base URL names // the full endpoint leave it empty. Path string @@ -51,7 +49,7 @@ type EmbeddingsSettings struct { TruncateValue string // InputTypeField names the parameter that distinguishes an indexed // document from a search query, and InputTypeValues maps the neutral - // api.EmbedInputType values onto the vendor's vocabulary. Asymmetric + // EmbedInputType values onto the vendor's vocabulary. Asymmetric // models score the two sides differently and are measurably worse when // both are embedded the same way. InputTypeField string @@ -71,14 +69,14 @@ type EmbeddingsSettings struct { ExtraBody map[string]any } -// BatchLimits renders the documented ceilings for api.SplitBatches. -func (s EmbeddingsSettings) BatchLimits() api.BatchLimits { - return api.BatchLimits{MaxItems: s.MaxBatchSize, MaxItemRunes: s.MaxInputChars} +// BatchLimits renders the documented ceilings for SplitBatches. +func (s EmbeddingsSettings) BatchLimits() BatchLimits { + return BatchLimits{MaxItems: s.MaxBatchSize, MaxItemRunes: s.MaxInputChars} } // InputTypeValue maps a neutral input kind onto the vendor's vocabulary, // returning "" when this vendor does not distinguish the two sides. -func (s EmbeddingsSettings) InputTypeValue(kind api.EmbedInputType) string { +func (s EmbeddingsSettings) InputTypeValue(kind EmbedInputType) string { if s.InputTypeField == "" { return "" } diff --git a/internal/models/api/googleembeddings/client.go b/internal/models/api/googleembeddings/client.go index 60db1330..e44c8185 100644 --- a/internal/models/api/googleembeddings/client.go +++ b/internal/models/api/googleembeddings/client.go @@ -22,13 +22,12 @@ import ( "strings" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" ) -// Config is everything the client needs, already resolved by the catalog. +// Config is everything the client needs, already resolved by the api. type Config struct { Endpoint api.Endpoint - Settings catalog.EmbeddingsSettings + Settings api.EmbeddingsSettings Dimensions int Retry api.RetryPolicy } diff --git a/internal/models/api/googleembeddings/golden_test.go b/internal/models/api/googleembeddings/golden_test.go index 40f8f93a..ab29eb83 100644 --- a/internal/models/api/googleembeddings/golden_test.go +++ b/internal/models/api/googleembeddings/golden_test.go @@ -7,7 +7,6 @@ import ( "testing" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -18,7 +17,7 @@ const documentedResponse = `{"embeddings":[{"values":[0.1,0.2]},{"values":[0.3,0 var retrievalTasks = map[string]string{"document": "RETRIEVAL_DOCUMENT", "query": "RETRIEVAL_QUERY"} -func newClient(url, model string, settings catalog.EmbeddingsSettings, dims int) *Client { +func newClient(url, model string, settings api.EmbeddingsSettings, dims int) *Client { return New(Config{ Endpoint: api.Endpoint{BaseURL: url, Model: model, Auth: api.HeaderAuth("x-goog-api-key", "k")}, Settings: settings, @@ -30,7 +29,7 @@ func newClient(url, model string, settings catalog.EmbeddingsSettings, dims int) // fully qualified models/{id}. func TestRequestBodyForATaskTypeModel(t *testing.T) { c := newClient("https://generativelanguage.googleapis.com/v1beta", "gemini-embedding-001", - catalog.EmbeddingsSettings{ + api.EmbeddingsSettings{ InputTypeField: "taskType", InputTypeValues: retrievalTasks, DimensionsField: "outputDimensionality", }, 768) @@ -56,7 +55,7 @@ func TestRequestBodyForATaskTypeModel(t *testing.T) { // undocumented parameter, so a model that declares none sends none. func TestNoTaskTypeWhereTheModelHasNone(t *testing.T) { c := newClient("https://generativelanguage.googleapis.com/v1beta", "gemini-embedding-2", - catalog.EmbeddingsSettings{}, 0) + api.EmbeddingsSettings{}, 0) req := c.BuildRequestBody([]string{"a"}, api.EmbedDocument)["requests"].([]any)[0].(map[string]any) assert.NotContains(t, req, "embedContentConfig", "no option declared, so no config object") assert.NotContains(t, req, "taskType") @@ -72,7 +71,7 @@ func TestPostsToTheModelsMethod(t *testing.T) { defer server.Close() // An id stored with the prefix must not become models/models/… - c := newClient(server.URL+"/v1beta", "models/gemini-embedding-001", catalog.EmbeddingsSettings{}, 0) + c := newClient(server.URL+"/v1beta", "models/gemini-embedding-001", api.EmbeddingsSettings{}, 0) got, err := c.Embed(context.Background(), []string{"a", "b"}, api.EmbedDocument) require.NoError(t, err) assert.Equal(t, [][]float32{{0.1, 0.2}, {0.3, 0.4}}, got) @@ -80,7 +79,7 @@ func TestPostsToTheModelsMethod(t *testing.T) { // A row that chats through the OpenAI-compatible facade stores // .../v1beta/openai; its embeddings still go to the native method. - c = newClient(server.URL+"/v1beta/openai/", "gemini-embedding-001", catalog.EmbeddingsSettings{}, 0) + c = newClient(server.URL+"/v1beta/openai/", "gemini-embedding-001", api.EmbeddingsSettings{}, 0) _, err = c.Embed(context.Background(), []string{"a", "b"}, api.EmbedDocument) require.NoError(t, err) assert.Equal(t, "/v1beta/models/gemini-embedding-001:batchEmbedContents", path) @@ -94,7 +93,7 @@ func TestShortReplyIsAnError(t *testing.T) { })) defer server.Close() - _, err := newClient(server.URL+"/v1beta", "gemini-embedding-001", catalog.EmbeddingsSettings{}, 0). + _, err := newClient(server.URL+"/v1beta", "gemini-embedding-001", api.EmbeddingsSettings{}, 0). Embed(context.Background(), []string{"a", "b"}, api.EmbedDocument) require.Error(t, err) assert.Contains(t, err.Error(), "1 embeddings for 2 inputs") diff --git a/internal/models/api/googlegenai/googlegenai_test.go b/internal/models/api/googlegenai/googlegenai_test.go index bf0abbf6..4dd545ea 100644 --- a/internal/models/api/googlegenai/googlegenai_test.go +++ b/internal/models/api/googlegenai/googlegenai_test.go @@ -11,7 +11,6 @@ import ( "testing" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" "github.com/Tencent/WeKnora/internal/types" ) @@ -24,7 +23,7 @@ func newTestClient(t *testing.T, baseURL string, mutate func(*Config)) *Client { ModelID: "model-123", Auth: api.HeaderAuth("x-goog-api-key", "test-key"), }, - Settings: catalog.DefaultGoogleGenerativeAI(), + Settings: api.DefaultGoogleGenerativeAI(), Reasoning: true, } if mutate != nil { @@ -196,7 +195,7 @@ func TestBuildRequestBodyGolden(t *testing.T) { { name: "level mode", mutate: func(c *Config) { - c.Settings.ThinkingMode = catalog.GoogleThinkingLevel + c.Settings.ThinkingMode = api.GoogleThinkingLevel c.ThinkingLevels = api.ThinkingLevelMap{api.ReasoningHigh: api.StringPtr("high")} }, thinking: `{"thinkingLevel": "high", "includeThoughts": true}`, @@ -253,26 +252,26 @@ func TestThinkingConfigVariants(t *testing.T) { }, { name: "mode none", - mutate: func(c *Config) { c.Settings.ThinkingMode = catalog.GoogleThinkingNone }, + mutate: func(c *Config) { c.Settings.ThinkingMode = api.GoogleThinkingNone }, opts: &api.Options{ReasoningEffort: api.ReasoningHigh}, want: "", }, { name: "level off unmapped", - mutate: func(c *Config) { c.Settings.ThinkingMode = catalog.GoogleThinkingLevel }, + mutate: func(c *Config) { c.Settings.ThinkingMode = api.GoogleThinkingLevel }, opts: &api.Options{ReasoningEffort: api.ReasoningOff}, want: "", }, { name: "level auto", - mutate: func(c *Config) { c.Settings.ThinkingMode = catalog.GoogleThinkingLevel }, + mutate: func(c *Config) { c.Settings.ThinkingMode = api.GoogleThinkingLevel }, opts: &api.Options{ReasoningEffort: api.ReasoningAuto}, want: `{"includeThoughts": true}`, }, { name: "level clamps unsupported rung", mutate: func(c *Config) { - c.Settings.ThinkingMode = catalog.GoogleThinkingLevel + c.Settings.ThinkingMode = api.GoogleThinkingLevel c.ThinkingLevels = api.ThinkingLevelMap{ api.ReasoningMedium: nil, api.ReasoningHigh: api.StringPtr("high"), diff --git a/internal/models/api/googlegenai/request.go b/internal/models/api/googlegenai/request.go index 7c9b3795..f7fd1ddf 100644 --- a/internal/models/api/googlegenai/request.go +++ b/internal/models/api/googlegenai/request.go @@ -1,6 +1,6 @@ // Package googlegenai implements the native Google Gemini generateContent // wire protocol (https://ai.google.dev/api/generate-content). Every -// model-specific deviation is driven by catalog.GoogleGenerativeAISettings; +// model-specific deviation is driven by api.GoogleGenerativeAISettings; // this package contains no vendor names beyond the protocol itself. package googlegenai @@ -14,13 +14,12 @@ import ( "strings" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" ) -// Config is everything the client needs, already resolved by the catalog. +// Config is everything the client needs, already resolved by the api. type Config struct { Endpoint api.Endpoint - Settings catalog.GoogleGenerativeAISettings + Settings api.GoogleGenerativeAISettings // ThinkingLevels maps neutral levels to the vendor vocabulary // (thinkingLevel values for Gemini 3, "off" support for budget models). ThinkingLevels api.ThinkingLevelMap @@ -469,10 +468,10 @@ func (c *Client) thinkingConfig(opts *api.Options) map[string]any { } mode := s.ThinkingMode if mode == "" { - mode = catalog.GoogleThinkingBudget + mode = api.GoogleThinkingBudget } switch mode { - case catalog.GoogleThinkingBudget: + case api.GoogleThinkingBudget: switch level { case api.ReasoningOff: if levels.Supports(api.ReasoningOff) { @@ -493,7 +492,7 @@ func (c *Client) thinkingConfig(opts *api.Options) map[string]any { } return map[string]any{"thinkingBudget": budget, "includeThoughts": s.IncludeThoughts} } - case catalog.GoogleThinkingLevel: + case api.GoogleThinkingLevel: switch level { case api.ReasoningOff: // Gemini 3 cannot switch thinking off; only send a level when the diff --git a/internal/models/api/nimrerank/client.go b/internal/models/api/nimrerank/client.go index 4eaefbef..5aa80348 100644 --- a/internal/models/api/nimrerank/client.go +++ b/internal/models/api/nimrerank/client.go @@ -3,7 +3,7 @@ // // Two things separate it from the Cohere dialect and both matter to callers. // The score is an unbounded log-odds value that is routinely negative, not a -// 0..1 relevance — catalog.RerankSettings.ScoreScale says so. And `truncate` +// 0..1 relevance — api.RerankSettings.ScoreScale says so. And `truncate` // defaults to "NONE", which means an over-long passage fails the request // instead of being cut, so the vendor sets it explicitly. // @@ -16,13 +16,12 @@ import ( "fmt" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" ) -// Config is everything the client needs, already resolved by the catalog. +// Config is everything the client needs, already resolved by the api. type Config struct { Endpoint api.Endpoint - Settings catalog.RerankSettings + Settings api.RerankSettings } // Client talks NIM reranking to one endpoint. diff --git a/internal/models/api/nimrerank/golden_test.go b/internal/models/api/nimrerank/golden_test.go index daa93f29..e44f1ebd 100644 --- a/internal/models/api/nimrerank/golden_test.go +++ b/internal/models/api/nimrerank/golden_test.go @@ -8,7 +8,6 @@ import ( "testing" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -19,7 +18,7 @@ import ( // https://docs.api.nvidia.com/nim/reference/nvidia-llama-3_2-nv-rerankqa-1b-v2-infer // // Note the negative logit. This protocol does not return a 0..1 relevance -// score, which is why catalog.RerankSettings.ScoreScale exists. +// score, which is why api.RerankSettings.ScoreScale exists. const documentedResponse = `{ "rankings": [ {"index": 2, "logit": 0.226318359375}, @@ -28,7 +27,7 @@ const documentedResponse = `{ ] }` -func newClient(t *testing.T, url string, settings catalog.RerankSettings) *Client { +func newClient(t *testing.T, url string, settings api.RerankSettings) *Client { t.Helper() return New(Config{ Endpoint: api.Endpoint{BaseURL: url, Model: "nvidia/nv-rerankqa-mistral-4b-v3", Auth: api.BearerAuth("k")}, @@ -38,7 +37,7 @@ func newClient(t *testing.T, url string, settings catalog.RerankSettings) *Clien func TestRequestBodyMatchesTheDocumentedSchema(t *testing.T) { c := newClient(t, "https://ai.api.nvidia.com/v1/retrieval/nvidia/reranking", - catalog.RerankSettings{Truncate: "END", ScoreScale: api.ScoreLogit}) + api.RerankSettings{Truncate: "END", ScoreScale: api.ScoreLogit}) body, err := c.BuildRequestBody("q", []string{"d0", "d1"}) require.NoError(t, err) @@ -55,7 +54,7 @@ func TestRequestBodyMatchesTheDocumentedSchema(t *testing.T) { // passage instead of cutting it. A vendor that does not set it must not have // the key invented for it either. func TestTruncateIsOmittedWhenUnset(t *testing.T) { - c := newClient(t, "https://ai.api.nvidia.com/v1/retrieval/nvidia/reranking", catalog.RerankSettings{}) + c := newClient(t, "https://ai.api.nvidia.com/v1/retrieval/nvidia/reranking", api.RerankSettings{}) body, err := c.BuildRequestBody("q", []string{"d0"}) require.NoError(t, err) assert.NotContains(t, body, "truncate") @@ -69,7 +68,7 @@ func TestDecodesTheDocumentedResponse(t *testing.T) { })) defer server.Close() - c := newClient(t, server.URL, catalog.RerankSettings{ScoreScale: api.ScoreLogit}) + c := newClient(t, server.URL, api.RerankSettings{ScoreScale: api.ScoreLogit}) got, err := c.Rerank(context.Background(), "q", []string{"d0", "d1", "d2"}) require.NoError(t, err) @@ -89,7 +88,7 @@ func TestRejectsAnOutOfRangeIndex(t *testing.T) { })) defer server.Close() - c := newClient(t, server.URL, catalog.RerankSettings{}) + c := newClient(t, server.URL, api.RerankSettings{}) _, err := c.Rerank(context.Background(), "q", []string{"d0"}) require.Error(t, err) assert.Contains(t, err.Error(), "out of range") @@ -103,7 +102,7 @@ func TestSurfacesTheVendorErrorBody(t *testing.T) { })) defer server.Close() - c := newClient(t, server.URL, catalog.RerankSettings{}) + c := newClient(t, server.URL, api.RerankSettings{}) _, err := c.Rerank(context.Background(), "q", []string{"d0"}) require.Error(t, err) assert.Contains(t, err.Error(), "input too long") @@ -120,7 +119,7 @@ func TestRequestReachesTheConfiguredURL(t *testing.T) { })) defer server.Close() - c := newClient(t, server.URL+"/v1/retrieval/nvidia/reranking", catalog.RerankSettings{}) + c := newClient(t, server.URL+"/v1/retrieval/nvidia/reranking", api.RerankSettings{}) _, err := c.Rerank(context.Background(), "q", []string{"d0"}) require.NoError(t, err) assert.Equal(t, "/v1/retrieval/nvidia/reranking", gotPath, "the base URL already names the endpoint") diff --git a/internal/models/api/openaichataudio/client.go b/internal/models/api/openaichataudio/client.go index 1e71ddbd..be45425e 100644 --- a/internal/models/api/openaichataudio/client.go +++ b/internal/models/api/openaichataudio/client.go @@ -21,13 +21,12 @@ import ( "strings" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" ) -// Config is everything the client needs, already resolved by the catalog. +// Config is everything the client needs, already resolved by the api. type Config struct { Endpoint api.Endpoint - Settings catalog.TranscriptionsSettings + Settings api.TranscriptionsSettings Retry api.RetryPolicy } @@ -104,7 +103,7 @@ func (c *Client) BuildRequestBody(req api.TranscriptionRequest) (map[string]any, }}, }}, } - if req.Language != "" && c.cfg.Settings.LanguageParam == catalog.LanguageASROptions { + if req.Language != "" && c.cfg.Settings.LanguageParam == api.LanguageASROptions { body["asr_options"] = map[string]any{"language": req.Language} } return body, nil diff --git a/internal/models/api/openaichataudio/golden_test.go b/internal/models/api/openaichataudio/golden_test.go index 8515a02f..e9d1b29f 100644 --- a/internal/models/api/openaichataudio/golden_test.go +++ b/internal/models/api/openaichataudio/golden_test.go @@ -8,7 +8,6 @@ import ( "testing" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -38,10 +37,10 @@ const qwenASRResponse = `{ const withSeconds = `{"choices":[{"message":{"role":"assistant","content":"x"}}],"usage":{"seconds":3}}` func newClient(url, model string) *Client { - return newClientWith(url, model, catalog.TranscriptionsSettings{}) + return newClientWith(url, model, api.TranscriptionsSettings{}) } -func newClientWith(url, model string, settings catalog.TranscriptionsSettings) *Client { +func newClientWith(url, model string, settings api.TranscriptionsSettings) *Client { return New(Config{ Endpoint: api.Endpoint{BaseURL: url, Model: model, Auth: api.BearerAuth("k")}, Settings: settings, @@ -80,7 +79,7 @@ func TestDataURIMediaTypeFollowsTheExtension(t *testing.T) { // sized to exactly the encoded budget without the prefix goes over it. func TestEncodedCeilingCountsTheWholeDataURI(t *testing.T) { const limit = 1024 - c := newClientWith("https://example.invalid", "m", catalog.TranscriptionsSettings{MaxEncodedBytes: limit}) + c := newClientWith("https://example.invalid", "m", api.TranscriptionsSettings{MaxEncodedBytes: limit}) audio := make([]byte, limit*3/4) // base64 of this is exactly limit bytes _, err := c.BuildRequestBody(api.TranscriptionRequest{Audio: audio, FileName: "a.wav"}) require.Error(t, err) @@ -99,7 +98,7 @@ func TestLanguageGoesInASROptionsWhereDeclared(t *testing.T) { assert.NotContains(t, body, "asr_options", "undeclared, so not sent") body, err = newClientWith("https://example.invalid", "m", - catalog.TranscriptionsSettings{LanguageParam: catalog.LanguageASROptions}).BuildRequestBody(req) + api.TranscriptionsSettings{LanguageParam: api.LanguageASROptions}).BuildRequestBody(req) require.NoError(t, err) assert.Equal(t, map[string]any{"language": "zh"}, body["asr_options"]) } diff --git a/internal/models/api/openaicompletions/golden_test.go b/internal/models/api/openaicompletions/golden_test.go index 21cea739..a4f65cf2 100644 --- a/internal/models/api/openaicompletions/golden_test.go +++ b/internal/models/api/openaicompletions/golden_test.go @@ -9,7 +9,6 @@ import ( "testing" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" "github.com/Tencent/WeKnora/internal/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -21,7 +20,7 @@ func newClient(t *testing.T, mutate func(*Config)) *Client { Endpoint: api.Endpoint{ BaseURL: "https://example.com/v1", Model: "m", ModelID: "id", Auth: api.BearerAuth("k"), }, - Settings: catalog.DefaultOpenAICompletions(), + Settings: api.DefaultOpenAICompletions(), ThinkingLevels: api.ThinkingLevelMap{}, } if mutate != nil { @@ -76,7 +75,7 @@ func TestGolden(t *testing.T) { mutate: func(c *Config) { c.Settings.SupportsStore = true c.Settings.SupportsDeveloperRole = true - c.Settings.ThinkingFormat = catalog.ThinkingFormatOpenAI + c.Settings.ThinkingFormat = api.ThinkingFormatOpenAI c.Settings.SupportsReasoningEffort = true }, opts: toolOpts, @@ -94,7 +93,7 @@ func TestGolden(t *testing.T) { c.Reasoning = true c.Settings.SupportsDeveloperRole = true c.Settings.SupportsTemperature = false - c.Settings.ThinkingFormat = catalog.ThinkingFormatOpenAI + c.Settings.ThinkingFormat = api.ThinkingFormatOpenAI c.Settings.SupportsReasoningEffort = true }, opts: &api.Options{Temperature: 0.7, MaxTokens: 10, ReasoningEffort: api.ReasoningMedium}, @@ -105,7 +104,7 @@ func TestGolden(t *testing.T) { { name: "openai gpt-5.1 off maps to reasoning_effort none", mutate: func(c *Config) { - c.Settings.ThinkingFormat = catalog.ThinkingFormatOpenAI + c.Settings.ThinkingFormat = api.ThinkingFormatOpenAI c.Settings.SupportsReasoningEffort = true c.ThinkingLevels = api.ThinkingLevelMap{api.ReasoningOff: api.StringPtr("none")} }, @@ -116,7 +115,7 @@ func TestGolden(t *testing.T) { name: "deepseek: max_tokens, thinking.type + effort clamp, tool_choice required dropped", mutate: func(c *Config) { c.Settings.MaxTokensField = "max_tokens" - c.Settings.ThinkingFormat = catalog.ThinkingFormatThinkingType + c.Settings.ThinkingFormat = api.ThinkingFormatThinkingType c.Settings.SupportsReasoningEffort = true c.Settings.ToolChoiceModes = []string{"none", "auto"} c.ThinkingLevels = api.ThinkingLevelMap{api.ReasoningMedium: api.StringPtr("high")} @@ -131,7 +130,7 @@ func TestGolden(t *testing.T) { { name: "deepseek reasoner: always-on, off request sends nothing", mutate: func(c *Config) { - c.Settings.ThinkingFormat = catalog.ThinkingFormatThinkingType + c.Settings.ThinkingFormat = api.ThinkingFormatThinkingType c.ThinkingLevels = api.ThinkingLevelMap{api.ReasoningOff: nil} }, opts: &api.Options{Thinking: ptrBool(false)}, @@ -140,7 +139,7 @@ func TestGolden(t *testing.T) { { name: "zhipu: thinking disabled explicitly", mutate: func(c *Config) { - c.Settings.ThinkingFormat = catalog.ThinkingFormatThinkingType + c.Settings.ThinkingFormat = api.ThinkingFormatThinkingType }, opts: &api.Options{Thinking: ptrBool(false)}, want: map[string]any{"thinking": map[string]any{"type": "disabled"}}, @@ -148,7 +147,7 @@ func TestGolden(t *testing.T) { { name: "minimax m3: adaptive thinking value", mutate: func(c *Config) { - c.Settings.ThinkingFormat = catalog.ThinkingFormatThinkingType + c.Settings.ThinkingFormat = api.ThinkingFormatThinkingType c.Settings.ThinkingEnabledValue = "adaptive" }, opts: &api.Options{Thinking: ptrBool(true)}, @@ -158,7 +157,7 @@ func TestGolden(t *testing.T) { name: "dashscope hybrid: enable_thinking always sent, budget, non-stream forces off", mutate: func(c *Config) { c.Settings.MaxTokensField = "max_tokens" - c.Settings.ThinkingFormat = catalog.ThinkingFormatEnableThinking + c.Settings.ThinkingFormat = api.ThinkingFormatEnableThinking c.Settings.ThinkingBudgetField = "thinking_budget" c.Settings.ThinkingAlwaysSend = true c.Settings.ThinkingDisableOnNonStream = true @@ -170,7 +169,7 @@ func TestGolden(t *testing.T) { { name: "dashscope qwen3.8: effort and budget are mutually exclusive, budget yields", mutate: func(c *Config) { - c.Settings.ThinkingFormat = catalog.ThinkingFormatEnableThinking + c.Settings.ThinkingFormat = api.ThinkingFormatEnableThinking c.Settings.ThinkingBudgetField = "thinking_budget" c.Settings.ThinkingBudgetExcludesEffort = true c.Settings.SupportsReasoningEffort = true @@ -187,7 +186,7 @@ func TestGolden(t *testing.T) { { name: "dashscope qwen3.8: budget still rides along when no effort is graded", mutate: func(c *Config) { - c.Settings.ThinkingFormat = catalog.ThinkingFormatEnableThinking + c.Settings.ThinkingFormat = api.ThinkingFormatEnableThinking c.Settings.ThinkingBudgetField = "thinking_budget" c.Settings.ThinkingBudgetExcludesEffort = true }, @@ -200,7 +199,7 @@ func TestGolden(t *testing.T) { { name: "dashscope hybrid streaming: enable_thinking true with budget", mutate: func(c *Config) { - c.Settings.ThinkingFormat = catalog.ThinkingFormatEnableThinking + c.Settings.ThinkingFormat = api.ThinkingFormatEnableThinking c.Settings.ThinkingBudgetField = "thinking_budget" c.Settings.ThinkingAlwaysSend = true c.Settings.ThinkingDisableOnNonStream = true @@ -212,7 +211,7 @@ func TestGolden(t *testing.T) { { name: "dashscope: no preference still pins enable_thinking false", mutate: func(c *Config) { - c.Settings.ThinkingFormat = catalog.ThinkingFormatEnableThinking + c.Settings.ThinkingFormat = api.ThinkingFormatEnableThinking c.Settings.ThinkingAlwaysSend = true }, opts: &api.Options{Temperature: 0.1}, @@ -221,7 +220,7 @@ func TestGolden(t *testing.T) { { name: "vllm: chat_template_kwargs", mutate: func(c *Config) { - c.Settings.ThinkingFormat = catalog.ThinkingFormatChatTemplateKwargs + c.Settings.ThinkingFormat = api.ThinkingFormatChatTemplateKwargs }, opts: &api.Options{Thinking: ptrBool(true)}, want: map[string]any{"chat_template_kwargs": map[string]any{"enable_thinking": true}}, @@ -229,7 +228,7 @@ func TestGolden(t *testing.T) { { name: "openrouter: reasoning effort object and enabled=false", mutate: func(c *Config) { - c.Settings.ThinkingFormat = catalog.ThinkingFormatOpenRouter + c.Settings.ThinkingFormat = api.ThinkingFormatOpenRouter c.Settings.SupportsReasoningEffort = true }, opts: &api.Options{ReasoningEffort: api.ReasoningHigh}, @@ -238,7 +237,7 @@ func TestGolden(t *testing.T) { { name: "openrouter: auto enables without effort", mutate: func(c *Config) { - c.Settings.ThinkingFormat = catalog.ThinkingFormatOpenRouter + c.Settings.ThinkingFormat = api.ThinkingFormatOpenRouter c.Settings.SupportsReasoningEffort = true }, opts: &api.Options{ReasoningEffort: api.ReasoningAuto}, @@ -256,7 +255,7 @@ func TestGolden(t *testing.T) { { name: "no thinking preference on a plain vendor sends no thinking fields", mutate: func(c *Config) { - c.Settings.ThinkingFormat = catalog.ThinkingFormatThinkingType + c.Settings.ThinkingFormat = api.ThinkingFormatThinkingType }, opts: &api.Options{Temperature: 0.2}, want: map[string]any{"thinking": nil, "reasoning_effort": nil, "enable_thinking": nil}, @@ -277,6 +276,35 @@ func TestGolden(t *testing.T) { opts: &api.Options{Temperature: 0.2}, want: map[string]any{"enable_search": true, "temperature": 0.2}, }, + { + name: "both caller budget aliases produce only the configured wire field", + opts: &api.Options{MaxTokens: 100, MaxCompletionTokens: 200}, + want: map[string]any{"max_completion_tokens": float64(200), "max_tokens": nil}, + }, + { + name: "extra_body cannot add the legacy budget beside the caller completion budget", + mutate: func(c *Config) { + c.Settings.ExtraBody = map[string]any{"max_tokens": 900, "max_completion_tokens": 800} + }, + opts: &api.Options{MaxTokens: 100}, + want: map[string]any{"max_completion_tokens": float64(100), "max_tokens": nil}, + }, + { + name: "conflicting extra_body budgets follow the configured field without caller options", + mutate: func(c *Config) { + c.Settings.ExtraBody = map[string]any{"max_tokens": 900, "max_completion_tokens": 800} + }, + want: map[string]any{"max_completion_tokens": float64(800), "max_tokens": nil}, + }, + { + name: "legacy budget vendors discard the conflicting completion budget", + mutate: func(c *Config) { + c.Settings.MaxTokensField = "max_tokens" + c.Settings.ExtraBody = map[string]any{"max_completion_tokens": 800} + }, + opts: &api.Options{MaxTokens: 100}, + want: map[string]any{"max_tokens": float64(100), "max_completion_tokens": nil}, + }, } for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { @@ -383,8 +411,8 @@ func TestChat_NonStreamDecoding(t *testing.T) { BaseURL: server.URL + "/v1", Model: "m", Auth: api.BearerAuth("sk"), Headers: map[string]string{"X-Custom": "1", "Authorization": "Bearer evil"}, }, - Settings: func() catalog.OpenAICompletionsSettings { - s := catalog.DefaultOpenAICompletions() + Settings: func() api.OpenAICompletionsSettings { + s := api.DefaultOpenAICompletions() s.PromptCacheAccounting = true return s }(), @@ -409,7 +437,7 @@ func TestChat_HTTPErrorSurfacesBody(t *testing.T) { })) defer server.Close() c := New(Config{ - Endpoint: api.Endpoint{BaseURL: server.URL, Model: "m"}, Settings: catalog.DefaultOpenAICompletions(), + Endpoint: api.Endpoint{BaseURL: server.URL, Model: "m"}, Settings: api.DefaultOpenAICompletions(), }) _, err := c.Chat(context.Background(), []api.Message{{Role: "user", Content: "hi"}}, nil) require.Error(t, err) @@ -451,7 +479,7 @@ func TestChatStream_Sequence(t *testing.T) { defer server.Close() c := New(Config{ - Endpoint: api.Endpoint{BaseURL: server.URL, Model: "m"}, Settings: catalog.DefaultOpenAICompletions(), + Endpoint: api.Endpoint{BaseURL: server.URL, Model: "m"}, Settings: api.DefaultOpenAICompletions(), }) ch, err := c.ChatStream(context.Background(), []api.Message{{Role: "user", Content: "hi"}}, nil) require.NoError(t, err) @@ -527,8 +555,8 @@ func TestChat_ClassifiesCacheStatusWithoutUsageBlock(t *testing.T) { t.Run(tc.name, func(t *testing.T) { c := New(Config{ Endpoint: api.Endpoint{BaseURL: server.URL + "/v1", Model: "m", Auth: api.BearerAuth("sk")}, - Settings: func() catalog.OpenAICompletionsSettings { - s := catalog.DefaultOpenAICompletions() + Settings: func() api.OpenAICompletionsSettings { + s := api.DefaultOpenAICompletions() s.PromptCacheAccounting = tc.accounting return s }(), @@ -554,7 +582,7 @@ func TestChatStream_TolerantDoneSentinel(t *testing.T) { c := New(Config{ Endpoint: api.Endpoint{BaseURL: server.URL + "/v1", Model: "m", Auth: api.BearerAuth("sk")}, - Settings: catalog.DefaultOpenAICompletions(), + Settings: api.DefaultOpenAICompletions(), }) ch, err := c.ChatStream(context.Background(), []api.Message{{Role: "user", Content: "hi"}}, nil) require.NoError(t, err) @@ -586,7 +614,7 @@ func TestChatStream_UndecodableChunkFailsTheStream(t *testing.T) { c := New(Config{ Endpoint: api.Endpoint{BaseURL: server.URL + "/v1", Model: "m", Auth: api.BearerAuth("sk")}, - Settings: catalog.DefaultOpenAICompletions(), + Settings: api.DefaultOpenAICompletions(), }) ch, err := c.ChatStream(context.Background(), []api.Message{{Role: "user", Content: "hi"}}, nil) require.NoError(t, err) @@ -619,7 +647,7 @@ func TestChat_MalformedToolCallIsAnError(t *testing.T) { c := New(Config{ Endpoint: api.Endpoint{BaseURL: server.URL + "/v1", Model: "m", Auth: api.BearerAuth("sk")}, - Settings: catalog.DefaultOpenAICompletions(), + Settings: api.DefaultOpenAICompletions(), }) _, err := c.Chat(context.Background(), []api.Message{{Role: "user", Content: "hi"}}, nil) require.Error(t, err, "a tool call that will not decode must not pass as a plain answer") @@ -642,7 +670,7 @@ func TestChatStream_MalformedToolCallFailsTheStream(t *testing.T) { c := New(Config{ Endpoint: api.Endpoint{BaseURL: server.URL + "/v1", Model: "m", Auth: api.BearerAuth("sk")}, - Settings: catalog.DefaultOpenAICompletions(), + Settings: api.DefaultOpenAICompletions(), }) ch, err := c.ChatStream(context.Background(), []api.Message{{Role: "user", Content: "hi"}}, nil) require.NoError(t, err) diff --git a/internal/models/api/openaicompletions/request.go b/internal/models/api/openaicompletions/request.go index 69f2b2a2..a949891f 100644 --- a/internal/models/api/openaicompletions/request.go +++ b/internal/models/api/openaicompletions/request.go @@ -1,6 +1,6 @@ // Package openaicompletions implements the OpenAI Chat Completions wire // protocol. Every vendor-specific deviation is driven by -// catalog.OpenAICompletionsSettings; this package contains no vendor names. +// api.OpenAICompletionsSettings; this package contains no vendor names. package openaicompletions import ( @@ -9,13 +9,12 @@ import ( "strings" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" ) -// Config is everything the client needs, already resolved by the catalog. +// Config is everything the client needs, already resolved by the api. type Config struct { Endpoint api.Endpoint - Settings catalog.OpenAICompletionsSettings + Settings api.OpenAICompletionsSettings // ThinkingLevels maps neutral levels to the vendor vocabulary. ThinkingLevels api.ThinkingLevelMap // Reasoning marks a reasoning model (developer role, no sampling params @@ -157,7 +156,7 @@ func (c *Client) convertMessages(messages []api.Message) []wireMessage { } // reasoning_details is OpenRouter's format; other vendors reject it. raw, ok := msg.ReasoningMetadata[metadataReasoningDetails] - if ok && len(raw) > 0 && s.ThinkingFormat == catalog.ThinkingFormatOpenRouter { + if ok && len(raw) > 0 && s.ThinkingFormat == api.ThinkingFormatOpenRouter { wm.ReasoningDetails = raw } } @@ -242,6 +241,18 @@ func (c *Client) buildBody(messages []api.Message, opts *api.Options, stream boo body[k] = v } } + // These names are mutually exclusive, including when extra_body supplies + // one or both. Keep the protocol's configured field; an explicit caller + // budget already takes precedence over extra_body above. + if _, legacy := body["max_tokens"]; legacy { + if _, completion := body["max_completion_tokens"]; completion { + if s.MaxTokensField == "max_tokens" { + delete(body, "max_completion_tokens") + } else { + delete(body, "max_tokens") + } + } + } return body, nil } @@ -310,10 +321,10 @@ func (c *Client) applyTools(body map[string]any, opts *api.Options) { } // applyThinking encodes the requested reasoning level in the vendor's -// dialect. See catalog.ThinkingFormat for the dialects. +// dialect. See api.ThinkingFormat for the dialects. func (c *Client) applyThinking(body map[string]any, opts *api.Options, stream bool) { s := c.cfg.Settings - if s.ThinkingFormat == catalog.ThinkingFormatNone || s.ThinkingFormat == "" { + if s.ThinkingFormat == api.ThinkingFormatNone || s.ThinkingFormat == "" { return } levels := c.cfg.ThinkingLevels @@ -357,7 +368,7 @@ func (c *Client) applyThinking(body map[string]any, opts *api.Options, stream bo } switch s.ThinkingFormat { - case catalog.ThinkingFormatOpenAI: + case api.ThinkingFormatOpenAI: if enabled { if effort != "" { body[effortField] = effort @@ -365,7 +376,7 @@ func (c *Client) applyThinking(body map[string]any, opts *api.Options, stream bo } else if v, ok := levels[api.ReasoningOff]; ok && v != nil && *v != "" { body[effortField] = *v } - case catalog.ThinkingFormatThinkingType: + case api.ThinkingFormatThinkingType: if enabled { body["thinking"] = map[string]any{"type": orDefault(s.ThinkingEnabledValue, "enabled")} if effort != "" { @@ -374,14 +385,14 @@ func (c *Client) applyThinking(body map[string]any, opts *api.Options, stream bo } else { body["thinking"] = map[string]any{"type": "disabled"} } - case catalog.ThinkingFormatEnableThinking: + case api.ThinkingFormatEnableThinking: body["enable_thinking"] = enabled if effort != "" { body[effortField] = effort } - case catalog.ThinkingFormatChatTemplateKwargs: + case api.ThinkingFormatChatTemplateKwargs: body["chat_template_kwargs"] = map[string]any{"enable_thinking": enabled} - case catalog.ThinkingFormatOpenRouter: + case api.ThinkingFormatOpenRouter: if enabled { reasoning := map[string]any{} if effort != "" { diff --git a/internal/models/api/openaiembeddings/client.go b/internal/models/api/openaiembeddings/client.go index 94de9b60..49233359 100644 --- a/internal/models/api/openaiembeddings/client.go +++ b/internal/models/api/openaiembeddings/client.go @@ -3,7 +3,7 @@ // answering {data: [{embedding, index}]}. // // The vendors that speak it disagree about everything optional, so nothing -// optional is sent unless catalog.EmbeddingsSettings says the vendor +// optional is sent unless api.EmbeddingsSettings says the vendor // documents it: // // - `dimensions` does not exist on NVIDIA NIM or Volcengine's text endpoint; @@ -21,13 +21,12 @@ import ( "strings" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" ) -// Config is everything the client needs, already resolved by the catalog. +// Config is everything the client needs, already resolved by the api. type Config struct { Endpoint api.Endpoint - Settings catalog.EmbeddingsSettings + Settings api.EmbeddingsSettings // Dimensions is the width the row asked for; it is sent only when the // vendor names a field for it. Dimensions int diff --git a/internal/models/api/openaiembeddings/golden_test.go b/internal/models/api/openaiembeddings/golden_test.go index 72398427..57a1e0e2 100644 --- a/internal/models/api/openaiembeddings/golden_test.go +++ b/internal/models/api/openaiembeddings/golden_test.go @@ -8,7 +8,6 @@ import ( "testing" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -41,7 +40,7 @@ const nimResponse = `{ "usage": {"prompt_tokens": 4, "total_tokens": 4} }` -func newClient(url string, settings catalog.EmbeddingsSettings, dims int) *Client { +func newClient(url string, settings api.EmbeddingsSettings, dims int) *Client { return New(Config{ Endpoint: api.Endpoint{BaseURL: url, Model: "m", Auth: api.BearerAuth("k")}, Settings: settings, @@ -66,7 +65,7 @@ func serve(t *testing.T, payload string) (*httptest.Server, *string, *map[string // The baseline sends model and input and nothing else: those are the only two // fields every vendor in the catalog documents. func TestBaselineSendsOnlyModelAndInput(t *testing.T) { - c := newClient("https://example.invalid/v1", catalog.EmbeddingsSettings{}, 1024) + c := newClient("https://example.invalid/v1", api.EmbeddingsSettings{}, 1024) body := c.BuildRequestBody([]string{"a"}, api.EmbedDocument) assert.Equal(t, map[string]any{"model": "m", "input": []string{"a"}}, body, "a width the row asked for must not be sent to a vendor that names no field for it") @@ -75,7 +74,7 @@ func TestBaselineSendsOnlyModelAndInput(t *testing.T) { // NIM documents no `dimensions`, requires `input_type` and defaults // `truncate` to NONE, which fails a request on over-long input. func TestNIMRequestMatchesItsReference(t *testing.T) { - c := newClient("https://integrate.api.nvidia.com/v1", catalog.EmbeddingsSettings{ + c := newClient("https://integrate.api.nvidia.com/v1", api.EmbeddingsSettings{ SendEncodingFormat: true, InputTypeField: "input_type", InputTypeValues: map[string]string{"document": "passage", "query": "query"}, @@ -94,7 +93,7 @@ func TestNIMRequestMatchesItsReference(t *testing.T) { // Jina spells the same idea `task`, and its truncate is a boolean. func TestJinaRequestMatchesItsReference(t *testing.T) { - c := newClient("https://api.jina.ai/v1", catalog.EmbeddingsSettings{ + c := newClient("https://api.jina.ai/v1", api.EmbeddingsSettings{ DimensionsField: "dimensions", InputTypeField: "task", InputTypeValues: map[string]string{"document": "retrieval.passage", "query": "retrieval.query"}, @@ -112,12 +111,12 @@ func TestJinaRequestMatchesItsReference(t *testing.T) { // truncate_prompt_tokens is a vLLM extension. It appears in no managed // vendor's schema and used to be sent to every one of them, hardcoded to 511. func TestTruncatePromptTokensReachesOnlyVLLMClassRuntimes(t *testing.T) { - managed := newClient("https://api.openai.com/v1", catalog.EmbeddingsSettings{ + managed := newClient("https://api.openai.com/v1", api.EmbeddingsSettings{ TruncatePromptTokens: 511, }, 0) assert.NotContains(t, managed.BuildRequestBody([]string{"a"}, api.EmbedDocument), "truncate_prompt_tokens") - vllm := newClient("http://vllm.internal/v1", catalog.EmbeddingsSettings{ + vllm := newClient("http://vllm.internal/v1", api.EmbeddingsSettings{ AcceptsTruncatePromptTokens: true, TruncatePromptTokens: 512, }, 0) assert.Equal(t, 512, vllm.BuildRequestBody([]string{"a"}, api.EmbedDocument)["truncate_prompt_tokens"]) @@ -127,7 +126,7 @@ func TestDecodesArkTextResponse(t *testing.T) { server, path, body := serve(t, arkTextResponse) defer server.Close() - c := newClient(server.URL+"/api/v3", catalog.EmbeddingsSettings{SendEncodingFormat: true}, 0) + c := newClient(server.URL+"/api/v3", api.EmbeddingsSettings{SendEncodingFormat: true}, 0) got, err := c.Embed(context.Background(), []string{"天很蓝", "海很深"}, api.EmbedDocument) require.NoError(t, err) assert.Equal(t, [][]float32{{0.11, 0.12}, {0.21, 0.22}}, got) @@ -139,7 +138,7 @@ func TestDecodesNIMResponse(t *testing.T) { server, _, _ := serve(t, nimResponse) defer server.Close() - c := newClient(server.URL+"/v1", catalog.EmbeddingsSettings{}, 0) + c := newClient(server.URL+"/v1", api.EmbeddingsSettings{}, 0) got, err := c.Embed(context.Background(), []string{"a"}, api.EmbedQuery) require.NoError(t, err) assert.Equal(t, [][]float32{{0.5, 0.6}}, got) @@ -153,7 +152,7 @@ func TestOutOfOrderIndicesArePlacedByIndex(t *testing.T) { ]}`) defer server.Close() - got, err := newClient(server.URL, catalog.EmbeddingsSettings{}, 0). + got, err := newClient(server.URL, api.EmbeddingsSettings{}, 0). Embed(context.Background(), []string{"a", "b"}, api.EmbedDocument) require.NoError(t, err) assert.Equal(t, [][]float32{{1}, {2}}, got) @@ -165,7 +164,7 @@ func TestReplyWithoutIndicesIsReadInOrder(t *testing.T) { server, _, _ := serve(t, `{"data":[{"embedding":[1]},{"embedding":[2]},{"embedding":[3]}]}`) defer server.Close() - got, err := newClient(server.URL, catalog.EmbeddingsSettings{}, 0). + got, err := newClient(server.URL, api.EmbeddingsSettings{}, 0). Embed(context.Background(), []string{"a", "b", "c"}, api.EmbedDocument) require.NoError(t, err) assert.Equal(t, [][]float32{{1}, {2}, {3}}, got) @@ -177,7 +176,7 @@ func TestRepeatedIndexIsStillAnError(t *testing.T) { server, _, _ := serve(t, `{"data":[{"embedding":[1],"index":0},{"embedding":[2],"index":0}]}`) defer server.Close() - _, err := newClient(server.URL, catalog.EmbeddingsSettings{}, 0). + _, err := newClient(server.URL, api.EmbeddingsSettings{}, 0). Embed(context.Background(), []string{"a", "b"}, api.EmbedDocument) assert.Error(t, err) } @@ -187,7 +186,7 @@ func TestShortReplyIsAnError(t *testing.T) { server, _, _ := serve(t, `{"data":[{"embedding":[1],"index":0}]}`) defer server.Close() - _, err := newClient(server.URL, catalog.EmbeddingsSettings{}, 0). + _, err := newClient(server.URL, api.EmbeddingsSettings{}, 0). Embed(context.Background(), []string{"a", "b"}, api.EmbedDocument) require.Error(t, err) assert.Contains(t, err.Error(), "no embedding returned for input 1") @@ -197,7 +196,7 @@ func TestDoesNotDoubleTheEmbeddingsPath(t *testing.T) { server, path, _ := serve(t, `{"data":[{"embedding":[1],"index":0}]}`) defer server.Close() - _, err := newClient(server.URL+"/openai/v1/embeddings", catalog.EmbeddingsSettings{}, 0). + _, err := newClient(server.URL+"/openai/v1/embeddings", api.EmbeddingsSettings{}, 0). Embed(context.Background(), []string{"a"}, api.EmbedDocument) require.NoError(t, err) assert.Equal(t, "/openai/v1/embeddings", *path) @@ -211,7 +210,7 @@ func TestSurfacesTheVendorErrorBody(t *testing.T) { })) defer server.Close() - _, err := newClient(server.URL, catalog.EmbeddingsSettings{}, 0). + _, err := newClient(server.URL, api.EmbeddingsSettings{}, 0). Embed(context.Background(), []string{"a"}, api.EmbedDocument) require.Error(t, err) assert.Contains(t, err.Error(), "input exceeds 4096 characters") diff --git a/internal/models/api/openairesponses/openairesponses_test.go b/internal/models/api/openairesponses/openairesponses_test.go index 97908f55..1a3b8fd6 100644 --- a/internal/models/api/openairesponses/openairesponses_test.go +++ b/internal/models/api/openairesponses/openairesponses_test.go @@ -11,7 +11,6 @@ import ( "testing" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" "github.com/Tencent/WeKnora/internal/types" ) @@ -30,7 +29,7 @@ func newTestClient(t *testing.T, server *httptest.Server, reasoning bool) *Clien } return New(Config{ Endpoint: ep, - Settings: catalog.DefaultOpenAIResponses(), + Settings: api.DefaultOpenAIResponses(), Reasoning: reasoning, SessionID: "session-fallback", }) diff --git a/internal/models/api/openairesponses/request.go b/internal/models/api/openairesponses/request.go index aaf8cd80..b5e82de1 100644 --- a/internal/models/api/openairesponses/request.go +++ b/internal/models/api/openairesponses/request.go @@ -1,6 +1,6 @@ // Package openairesponses implements the OpenAI Responses wire protocol // (POST /responses). Every vendor-specific deviation is driven by -// catalog.OpenAIResponsesSettings; this package contains no vendor names. +// api.OpenAIResponsesSettings; this package contains no vendor names. package openairesponses import ( @@ -9,13 +9,12 @@ import ( "strings" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" ) -// Config is everything the client needs, already resolved by the catalog. +// Config is everything the client needs, already resolved by the api. type Config struct { Endpoint api.Endpoint - Settings catalog.OpenAIResponsesSettings + Settings api.OpenAIResponsesSettings // ThinkingLevels maps neutral levels to the vendor vocabulary. ThinkingLevels api.ThinkingLevelMap // Reasoning marks a reasoning model: sampling parameters are dropped and diff --git a/internal/models/api/openaitranscriptions/client.go b/internal/models/api/openaitranscriptions/client.go index b09762ca..fcecc568 100644 --- a/internal/models/api/openaitranscriptions/client.go +++ b/internal/models/api/openaitranscriptions/client.go @@ -7,7 +7,7 @@ // model: gpt-4o-transcribe and gpt-4o-mini-transcribe accept only json, // whisper-1 also serves verbose_json, SiliconFlow documents no such field at // all. json is the default everywhere it is documented, so nothing is sent -// unless catalog.TranscriptionsSettings names a format. +// unless api.TranscriptionsSettings names a format. // // https://developers.openai.com/api/reference/resources/audio/subresources/transcriptions/methods/create package openaitranscriptions @@ -18,13 +18,12 @@ import ( "strings" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" ) -// Config is everything the client needs, already resolved by the catalog. +// Config is everything the client needs, already resolved by the api. type Config struct { Endpoint api.Endpoint - Settings catalog.TranscriptionsSettings + Settings api.TranscriptionsSettings Retry api.RetryPolicy } @@ -54,7 +53,7 @@ func (c *Client) FormFields(language string) []api.FormField { if format := c.cfg.Settings.ResponseFormat; format != "" { fields = append(fields, api.FormField{Name: "response_format", Value: format}) } - if language != "" && c.cfg.Settings.LanguageParam == catalog.LanguageForm { + if language != "" && c.cfg.Settings.LanguageParam == api.LanguageForm { fields = append(fields, api.FormField{Name: "language", Value: language}) } return fields @@ -94,7 +93,7 @@ func (c *Client) Transcribe(ctx context.Context, req api.TranscriptionRequest) ( return nil, err } endpoint := c.cfg.Endpoint - if req.Language != "" && c.cfg.Settings.LanguageParam == catalog.LanguageHeader { + if req.Language != "" && c.cfg.Settings.LanguageParam == api.LanguageHeader { headers := make(map[string]string, len(endpoint.Headers)+1) for k, v := range endpoint.Headers { headers[k] = v diff --git a/internal/models/api/openaitranscriptions/golden_test.go b/internal/models/api/openaitranscriptions/golden_test.go index 2e2252b7..6c8f42a2 100644 --- a/internal/models/api/openaitranscriptions/golden_test.go +++ b/internal/models/api/openaitranscriptions/golden_test.go @@ -10,7 +10,6 @@ import ( "testing" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -93,9 +92,9 @@ func serve(t *testing.T, status int, reply string) (*httptest.Server, *captured) return server, got } -func newClient(url, model string, settings catalog.TranscriptionsSettings) *Client { +func newClient(url, model string, settings api.TranscriptionsSettings) *Client { if settings.Path == "" { - settings.Path = catalog.DefaultTranscriptions().Path + settings.Path = api.DefaultTranscriptions().Path } return New(Config{ Endpoint: api.Endpoint{BaseURL: url, Model: model, Auth: api.BearerAuth("k")}, @@ -107,7 +106,7 @@ func newClient(url, model string, settings catalog.TranscriptionsSettings) *Clie // which is the default, so no response_format is sent. func TestBaselineFormIsFileAndModel(t *testing.T) { server, got := serve(t, http.StatusOK, jsonResponse) - out, err := newClient(server.URL+"/v1", "gpt-4o-transcribe", catalog.TranscriptionsSettings{}). + out, err := newClient(server.URL+"/v1", "gpt-4o-transcribe", api.TranscriptionsSettings{}). Transcribe(context.Background(), api.TranscriptionRequest{Audio: []byte("RIFF"), FileName: "meeting.wav"}) require.NoError(t, err) @@ -129,12 +128,12 @@ func TestLanguageGoesWhereTheVendorDeclares(t *testing.T) { wantHeader string }{ {param: "", wantField: "", wantHeader: ""}, - {param: catalog.LanguageForm, wantField: "zh", wantHeader: ""}, - {param: catalog.LanguageHeader, wantField: "", wantHeader: "zh"}, + {param: api.LanguageForm, wantField: "zh", wantHeader: ""}, + {param: api.LanguageHeader, wantField: "", wantHeader: "zh"}, } { t.Run("param="+tc.param, func(t *testing.T) { server, got := serve(t, http.StatusOK, jsonResponse) - _, err := newClient(server.URL, "m", catalog.TranscriptionsSettings{LanguageParam: tc.param}). + _, err := newClient(server.URL, "m", api.TranscriptionsSettings{LanguageParam: tc.param}). Transcribe(context.Background(), api.TranscriptionRequest{ Audio: []byte("x"), FileName: "a.wav", Language: "zh", }) @@ -157,7 +156,7 @@ func TestDurationIsReadFromTheReply(t *testing.T) { } { t.Run(name, func(t *testing.T) { server, _ := serve(t, http.StatusOK, reply) - out, err := newClient(server.URL, "m", catalog.TranscriptionsSettings{}). + out, err := newClient(server.URL, "m", api.TranscriptionsSettings{}). Transcribe(context.Background(), api.TranscriptionRequest{Audio: []byte("x"), FileName: "a.wav"}) require.NoError(t, err) assert.NotZero(t, out.Duration) @@ -167,7 +166,7 @@ func TestDurationIsReadFromTheReply(t *testing.T) { func TestVerboseJSONCarriesSegments(t *testing.T) { server, got := serve(t, http.StatusOK, verboseResponse) - settings := catalog.TranscriptionsSettings{ResponseFormat: "verbose_json"} + settings := api.TranscriptionsSettings{ResponseFormat: "verbose_json"} out, err := newClient(server.URL+"/v1", "whisper-1", settings). Transcribe(context.Background(), api.TranscriptionRequest{Audio: []byte("ID3"), FileName: "a.mp3"}) require.NoError(t, err) @@ -182,7 +181,7 @@ func TestVerboseJSONCarriesSegments(t *testing.T) { // Silence is an empty transcript, and that is a valid answer. func TestEmptyTextIsSilence(t *testing.T) { server, _ := serve(t, http.StatusOK, `{"text": ""}`) - out, err := newClient(server.URL, "m", catalog.TranscriptionsSettings{}). + out, err := newClient(server.URL, "m", api.TranscriptionsSettings{}). Transcribe(context.Background(), api.TranscriptionRequest{Audio: []byte("x"), FileName: "a.wav"}) require.NoError(t, err) assert.Equal(t, "", out.Text) @@ -195,7 +194,7 @@ func TestEmptyTextIsSilence(t *testing.T) { func TestReplyWithoutTextIsAnError(t *testing.T) { server, _ := serve(t, http.StatusOK, `{"status_code": 500, "detail": "Failed to transcribe audio, boom", "headers": null}`) - _, err := newClient(server.URL, "m", catalog.TranscriptionsSettings{}). + _, err := newClient(server.URL, "m", api.TranscriptionsSettings{}). Transcribe(context.Background(), api.TranscriptionRequest{Audio: []byte("x"), FileName: "a.wav"}) require.Error(t, err) assert.Contains(t, err.Error(), "Failed to transcribe audio") @@ -204,7 +203,7 @@ func TestReplyWithoutTextIsAnError(t *testing.T) { func TestSurfacesTheVendorErrorBody(t *testing.T) { // A stand-in rejection in OpenAI's error envelope. server, _ := serve(t, http.StatusBadRequest, `{"error":{"message":"stand-in rejection"}}`) - _, err := newClient(server.URL, "gpt-4o-transcribe", catalog.TranscriptionsSettings{}). + _, err := newClient(server.URL, "gpt-4o-transcribe", api.TranscriptionsSettings{}). Transcribe(context.Background(), api.TranscriptionRequest{Audio: []byte("x"), FileName: "a.wav"}) require.Error(t, err) assert.Contains(t, err.Error(), "stand-in rejection") @@ -212,7 +211,7 @@ func TestSurfacesTheVendorErrorBody(t *testing.T) { func TestDoesNotDoubleThePath(t *testing.T) { server, got := serve(t, http.StatusOK, jsonResponse) - _, err := newClient(server.URL+"/v1/audio/transcriptions", "m", catalog.TranscriptionsSettings{}). + _, err := newClient(server.URL+"/v1/audio/transcriptions", "m", api.TranscriptionsSettings{}). Transcribe(context.Background(), api.TranscriptionRequest{Audio: []byte("x"), FileName: "a.wav"}) require.NoError(t, err) assert.Equal(t, "/v1/audio/transcriptions", got.path) diff --git a/internal/models/catalog/rerank.go b/internal/models/api/rerank_settings.go similarity index 75% rename from internal/models/catalog/rerank.go rename to internal/models/api/rerank_settings.go index dec19f6d..48bf64c7 100644 --- a/internal/models/catalog/rerank.go +++ b/internal/models/api/rerank_settings.go @@ -1,22 +1,20 @@ -package catalog - -import "github.com/Tencent/WeKnora/internal/models/api" +package api // RerankCompat is the overlay form (every field optional) of the rerank // settings. JSON keys are the documented names used in models.json and // config/models.json. type RerankCompat struct { - Path *string `json:"path,omitempty"` - SendTopN *bool `json:"send_top_n,omitempty"` - SendReturnDocs *bool `json:"send_return_documents,omitempty"` - ScoreScale *api.ScoreScale `json:"score_scale,omitempty"` - Truncate *string `json:"truncate,omitempty"` - MaxDocuments *int `json:"max_documents,omitempty"` - MaxQueryChars *int `json:"max_query_chars,omitempty"` - MaxDocumentChars *int `json:"max_document_chars,omitempty"` - MaxRequestChars *int `json:"max_request_chars,omitempty"` - MaxConcurrency *int `json:"max_concurrency,omitempty"` - RequestTimeout *int `json:"request_timeout_seconds,omitempty"` + Path *string `json:"path,omitempty"` + SendTopN *bool `json:"send_top_n,omitempty"` + SendReturnDocs *bool `json:"send_return_documents,omitempty"` + ScoreScale *ScoreScale `json:"score_scale,omitempty"` + Truncate *string `json:"truncate,omitempty"` + MaxDocuments *int `json:"max_documents,omitempty"` + MaxQueryChars *int `json:"max_query_chars,omitempty"` + MaxDocumentChars *int `json:"max_document_chars,omitempty"` + MaxRequestChars *int `json:"max_request_chars,omitempty"` + MaxConcurrency *int `json:"max_concurrency,omitempty"` + RequestTimeout *int `json:"request_timeout_seconds,omitempty"` // AcceptsTruncatePromptTokens marks a vLLM-class runtime. AcceptsTruncatePromptTokens *bool `json:"accepts_truncate_prompt_tokens,omitempty"` // UnsupportedReason marks a model this build cannot call. @@ -35,9 +33,9 @@ type RerankSettings struct { // SendReturnDocs asks the vendor to echo the document text. Callers index // into their own slice, so this is off unless a vendor needs it. SendReturnDocs bool - // ScoreScale says what the returned numbers mean. See api.ScoreScale: + // ScoreScale says what the returned numbers mean. See ScoreScale: // getting this wrong makes a relevance threshold meaningless. - ScoreScale api.ScoreScale + ScoreScale ScoreScale // Truncate is the vendor's server-side truncation setting for // over-long input ("END" on NIM). Empty sends nothing. Truncate string @@ -74,9 +72,9 @@ type RerankSettings struct { ExtraBody map[string]any } -// BatchLimits renders the documented ceilings for api.SplitBatches. -func (s RerankSettings) BatchLimits() api.BatchLimits { - return api.BatchLimits{ +// BatchLimits renders the documented ceilings for SplitBatches. +func (s RerankSettings) BatchLimits() BatchLimits { + return BatchLimits{ MaxItems: s.MaxDocuments, MaxItemRunes: s.MaxDocumentChars, MaxTotalRunes: s.MaxRequestChars, @@ -87,6 +85,6 @@ func (s RerankSettings) BatchLimits() api.BatchLimits { // 0..1 relevance score, enforce no ceiling the vendor did not state. func DefaultRerank() RerankSettings { return RerankSettings{ - ScoreScale: api.ScoreProbability, + ScoreScale: ScoreProbability, } } diff --git a/internal/models/api/tencentlkeap/client.go b/internal/models/api/tencentlkeap/client.go new file mode 100644 index 00000000..373586dc --- /dev/null +++ b/internal/models/api/tencentlkeap/client.go @@ -0,0 +1,103 @@ +// Package tencentlkeap implements Tencent RunRerank through its official SDK. +package tencentlkeap + +import ( + "context" + "fmt" + "strings" + + "github.com/Tencent/WeKnora/internal/models/api" + "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common" + "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile" + lkeap "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/lkeap/v20240522" +) + +// SDK defaults follow the managed rerank service. +const ( + // LKEAPRerankEndpoint 腾讯云知识引擎原子能力 Rerank API 域名 + LKEAPRerankEndpoint = "lkeap.tencentcloudapi.com" + // LKEAPDefaultRegion RunRerank 支持的地域,默认广州 + LKEAPDefaultRegion = "ap-guangzhou" + // LKEAPDefaultRerankModel 默认 rerank 模型名 + LKEAPDefaultRerankModel = "lke-reranker-base" +) + +// Config contains resolved connection parameters for the SDK client. +type Config struct{ SecretID, SecretKey, Region, Model, Endpoint, Scheme string } + +// lkeapClient calls Tencent Cloud's RunRerank action through the official +// SDK, which owns the TC3 signing this API requires. It implements +// api.Reranker and nothing else: the per-request ceilings (60 documents, +// 2000 characters for Query plus Docs together) are declared on the vendor +// and enforced by protocolReranker, like every other vendor's. +type lkeapClient struct { + modelName string + client *lkeap.Client +} + +// New creates an authenticated rerank protocol client. +func New(config Config) (api.Reranker, error) { + secretID, secretKey := strings.TrimSpace(config.SecretID), strings.TrimSpace(config.SecretKey) + if secretID == "" || secretKey == "" { + return nil, fmt.Errorf("secret_id and secret_key are required for LKEAP rerank (set API Key and Secret Key)") + } + region := strings.TrimSpace(config.Region) + if region == "" { + region = LKEAPDefaultRegion + } + if config.Endpoint == "" { + config.Endpoint = LKEAPRerankEndpoint + } + if config.Scheme == "" { + config.Scheme = "HTTPS" + } + + credential := common.NewCredential(secretID, secretKey) + cpf := profile.NewClientProfile() + cpf.HttpProfile.Endpoint = config.Endpoint + cpf.HttpProfile.Scheme = config.Scheme + + client, err := lkeap.NewClient(credential, region, cpf) + if err != nil { + return nil, fmt.Errorf("create LKEAP client: %w", err) + } + + modelName := strings.TrimSpace(config.Model) + if modelName == "" { + modelName = LKEAPDefaultRerankModel + } + return &lkeapClient{modelName: modelName, client: client}, nil +} + +// Rerank scores one batch. RunRerank answers a bare score list in input +// order rather than an indexed, sorted result set. +func (r *lkeapClient) Rerank( + ctx context.Context, query string, documents []string, +) ([]api.RerankResult, error) { + req := lkeap.NewRunRerankRequest() + req.Query = common.StringPtr(query) + req.Docs = common.StringPtrs(documents) + req.Model = common.StringPtr(r.modelName) + + resp, err := r.client.RunRerankWithContext(ctx, req) + if err != nil { + return nil, fmt.Errorf("LKEAP RunRerank: %w", err) + } + if resp == nil || resp.Response == nil || len(resp.Response.ScoreList) == 0 { + return nil, fmt.Errorf("LKEAP rerank API returned empty score list") + } + scores := resp.Response.ScoreList + if len(scores) != len(documents) { + return nil, fmt.Errorf("LKEAP rerank score count mismatch: got %d scores for %d documents", + len(scores), len(documents)) + } + + results := make([]api.RerankResult, len(documents)) + for i, score := range scores { + results[i] = api.RerankResult{Index: i, Text: documents[i]} + if score != nil { + results[i].Score = *score + } + } + return results, nil +} diff --git a/internal/models/catalog/transcriptions.go b/internal/models/api/transcriptions_settings.go similarity index 93% rename from internal/models/catalog/transcriptions.go rename to internal/models/api/transcriptions_settings.go index 0a7b74ce..2ce538f2 100644 --- a/internal/models/catalog/transcriptions.go +++ b/internal/models/api/transcriptions_settings.go @@ -1,6 +1,4 @@ -package catalog - -import "github.com/Tencent/WeKnora/internal/models/api" +package api // Where a transcription protocol puts the operator's language hint. Each // vendor documents one place, or none. @@ -19,8 +17,8 @@ const ( // TranscriptionsCompat is the overlay form (every field optional) of the // speech-to-text settings. JSON keys are the names used in models.json. type TranscriptionsCompat struct { - API *api.TranscriptionAPI `json:"api,omitempty"` - Path *string `json:"path,omitempty"` + API *TranscriptionAPI `json:"api,omitempty"` + Path *string `json:"path,omitempty"` // ResponseFormat is sent as response_format when non-empty. OpenAI's // gpt-4o-transcribe and gpt-4o-mini-transcribe accept only json, which is // also the default, so most models leave it unset. @@ -43,7 +41,7 @@ type TranscriptionsCompat struct { // TranscriptionsSettings is the resolved (fully defaulted) form. type TranscriptionsSettings struct { - API api.TranscriptionAPI + API TranscriptionAPI Path string ResponseFormat string LanguageParam string diff --git a/internal/models/api/types.go b/internal/models/api/types.go index ae37d9ec..7050e422 100644 --- a/internal/models/api/types.go +++ b/internal/models/api/types.go @@ -5,7 +5,7 @@ // tool-call assembly, prompt-cache bookkeeping and usage logging. // // Protocol packages live under api/; vendor facts live in -// internal/models/catalog and internal/models/vendors. This package must not +// internal/models/catalog and internal/models/providers. This package must not // import either of them. package api diff --git a/internal/models/api/volcengineknowledge/client.go b/internal/models/api/volcengineknowledge/client.go new file mode 100644 index 00000000..7f6d4817 --- /dev/null +++ b/internal/models/api/volcengineknowledge/client.go @@ -0,0 +1,116 @@ +// Package volcengineknowledge implements Volcengine Knowledge Service rerank through its official SDK. +package volcengineknowledge + +import ( + "context" + "fmt" + "net/http" + "strings" + "time" + + "github.com/Tencent/WeKnora/internal/models/api" + "github.com/volcengine/vikingdb-go-sdk/knowledge" + knowledgemodel "github.com/volcengine/vikingdb-go-sdk/knowledge/model" +) + +// SDK defaults follow the managed rerank service. +const ( + DefaultModel = "doubao-seed-rerank" + DefaultRegion = "cn-beijing" + // DefaultInstruction is the console's default instruction, verbatim: "如需对齐控制台效果,请使用 + // 相同指令" (https://docs.volcengine.com/docs/vector_database_vikingdb/Rerank). + DefaultInstruction = "Whether the document answers the query " + + "or matches the content retrieval intent" +) + +// volcengineClient calls the managed Knowledge Service rerank through the +// vikingdb SDK, which owns the AK/SK signing. It implements api.Reranker and +// nothing else: the 200-document ceiling and the batch concurrency are +// declared on the vendor and enforced by protocolReranker. +type volcengineClient struct { + modelName string + instruction string + client *knowledge.Client +} + +// Config contains resolved connection parameters for the SDK client. +type Config struct { + AccessKey, SecretKey, BaseURL, Model, Region, Instruction string + Client *http.Client +} + +// New creates an authenticated rerank protocol client. +func New(config Config) (api.Reranker, error) { + accessKey, secretKey := strings.TrimSpace(config.AccessKey), strings.TrimSpace(config.SecretKey) + if accessKey == "" || secretKey == "" { + return nil, fmt.Errorf("access key and secret key are required for Volcengine rerank") + } + baseURL := config.BaseURL + modelName := strings.TrimSpace(config.Model) + if modelName == "" { + modelName = DefaultModel + } + region := strings.TrimSpace(config.Region) + if region == "" { + region = DefaultRegion + } + instruction := strings.TrimSpace(config.Instruction) + if instruction == "" { + instruction = DefaultInstruction + } + if config.Client == nil { + config.Client = api.HTTPClient + } + + client, err := knowledge.New( + knowledge.AuthIAM(accessKey, secretKey), + knowledge.WithEndpoint(baseURL), + knowledge.WithRegion(region), + knowledge.WithTimeout(30*time.Second), + knowledge.WithHTTPClient(config.Client), + knowledge.WithMaxRetries(1), + ) + if err != nil { + return nil, fmt.Errorf("create Volcengine rerank client: %w", err) + } + return &volcengineClient{modelName: modelName, instruction: instruction, client: client}, nil +} + +// Rerank scores one batch. Every document is paired with the same query and +// instruction, and the reply is a score list in input order. +func (r *volcengineClient) Rerank( + ctx context.Context, query string, documents []string, +) ([]api.RerankResult, error) { + data := make([]knowledgemodel.RerankDataItem, len(documents)) + for i := range documents { + data[i] = knowledgemodel.RerankDataItem{Query: query, Content: &documents[i]} + } + request := knowledgemodel.RerankRequest{ + Datas: data, + RerankModel: &r.modelName, + RerankInstruction: &r.instruction, + } + + response, err := r.client.Rerank(ctx, request) + if err != nil { + return nil, fmt.Errorf("call Volcengine rerank: %w", err) + } + if response == nil || response.Data == nil { + return nil, fmt.Errorf("volcengine rerank returned an empty response") + } + if response.Code != 0 { + return nil, fmt.Errorf("volcengine rerank API error %d: %s", response.Code, response.Message) + } + if len(response.Data.Scores) != len(documents) { + return nil, fmt.Errorf( + "volcengine rerank score count mismatch: got %d scores for %d documents", + len(response.Data.Scores), len(documents), + ) + } + + results := make([]api.RerankResult, len(documents)) + for i, score := range response.Data.Scores { + results[i] = api.RerankResult{Index: i, Score: score, Text: documents[i]} + } + return results, nil +} diff --git a/internal/models/asr/asr.go b/internal/models/asr/asr.go index 913e5e22..ead7efb9 100644 --- a/internal/models/asr/asr.go +++ b/internal/models/asr/asr.go @@ -60,6 +60,7 @@ type Config struct { // Provider is the vendor id stored on the row; empty detects it from // BaseURL. Provider string + Spec *types.ModelSpecOverride `json:"spec,omitempty"` ExtraConfig map[string]string // CustomHeaders 允许在调用远程 API 时附加自定义 HTTP 请求头(类似 OpenAI Python SDK 的 extra_headers)。 CustomHeaders map[string]string @@ -79,6 +80,7 @@ func ConfigFromModel(m *types.Model) *Config { ModelName: m.Name, Source: m.Source, Provider: m.Parameters.Provider, + Spec: m.Parameters.Spec, ExtraConfig: m.Parameters.ExtraConfig, CustomHeaders: m.Parameters.CustomHeaders, } diff --git a/internal/models/asr/catalog_matrix_test.go b/internal/models/asr/catalog_matrix_test.go new file mode 100644 index 00000000..36daa099 --- /dev/null +++ b/internal/models/asr/catalog_matrix_test.go @@ -0,0 +1,95 @@ +package asr + +import ( + "context" + "net/url" + "strings" + "testing" + + modelruntime "github.com/Tencent/WeKnora/internal/models/runtime" + "github.com/Tencent/WeKnora/internal/types" + "github.com/stretchr/testify/require" +) + +func TestEveryCatalogASRTransport(t *testing.T) { + for _, v := range modelruntime.List() { + for _, m := range v.Models() { + if m.Type != types.ModelTypeASR { + continue + } + names := append([]string{m.ID}, m.Aliases...) + if m.ID == "" { + names[0] = strings.ReplaceAll(m.Match, "*", "snapshot") + } + for _, name := range names { + t.Run(v.ID+"/"+name, func(t *testing.T) { + address, _, calls := upstream(t) + base, err := url.Parse(v.GetDefaultURL(types.ModelTypeASR)) + require.NoError(t, err) + client, err := newASR( + &Config{ + Source: types.ModelSourceRemote, + Provider: v.ID, + ModelName: name, + ModelID: "row-id", + BaseURL: address + base.Path, + APIKey: "row-key", + }, + ) + if strings.Contains(string(m.Compat), "unsupported_reason") { + require.Error(t, err) + require.Zero(t, calls.Load()) + return + } + require.NoError(t, err) + result, err := client.Transcribe( + WithLanguage( + context.Background(), + "zh", + ), + []byte( + "RIFF", + ), + "sample.wav", + ) + require.NoError(t, err) + require.Equal(t, "hello", strings.TrimSpace(result.Text)) + require.EqualValues(t, 1, calls.Load()) + require.Equal(t, "row-id", client.GetModelID()) + }) + } + } + } +} + +func TestStoredASRSpecReachesWire(t *testing.T) { + address, got, _ := upstream(t) + row := &types.Model{ + ID: "stable-id", + Name: "custom", + Source: types.ModelSourceRemote, + Parameters: types.ModelParameters{ + Provider: "generic", + BaseURL: address, + APIKey: "model-key", + Spec: &types.ModelSpecOverride{ + Compat: map[string]any{ + "path": "/custom-transcriptions", + "response_format": "verbose_json", + "language_param": "header", + }, + }, + }, + } + client, err := newASR(ConfigFromModel(row)) + require.NoError(t, err) + result, err := client.Transcribe(WithLanguage(context.Background(), "zh"), []byte("RIFF"), "sample.wav") + require.NoError(t, err) + require.Equal(t, "/custom-transcriptions", got.path) + require.Equal(t, "verbose_json", got.fields["response_format"]) + require.Equal(t, "zh", got.language) + require.Len(t, result.Segments, 1) + row.Parameters.Spec.Compat = map[string]any{"misspelled_option": true} + _, err = newASR(ConfigFromModel(row)) + require.ErrorContains(t, err, "unknown field") +} diff --git a/internal/models/asr/protocol.go b/internal/models/asr/protocol.go index b16b56ae..d78b62bf 100644 --- a/internal/models/asr/protocol.go +++ b/internal/models/asr/protocol.go @@ -12,10 +12,8 @@ import ( "github.com/Tencent/WeKnora/internal/models/api" "github.com/Tencent/WeKnora/internal/models/api/openaichataudio" "github.com/Tencent/WeKnora/internal/models/api/openaitranscriptions" - "github.com/Tencent/WeKnora/internal/models/catalog" - // catalog.Resolve answers from the vendor catalog, which is empty until - // the vendor packages have run their init. - _ "github.com/Tencent/WeKnora/internal/models/vendors" + "github.com/Tencent/WeKnora/internal/models/providers" + modelruntime "github.com/Tencent/WeKnora/internal/models/runtime" "github.com/Tencent/WeKnora/internal/types" ) @@ -36,12 +34,13 @@ func newASR(config *Config) (ASR, error) { if strings.TrimSpace(config.ModelName) == "" { return nil, fmt.Errorf("model name is required") } - resolved, err := catalog.Resolve(catalog.Ref{ + resolved, err := modelruntime.Resolve(modelruntime.Ref{ Provider: config.Provider, Model: config.ModelName, BaseURL: config.BaseURL, ModelType: types.ModelTypeASR, Extra: config.ExtraConfig, + Override: config.Spec, }) if err != nil { return nil, err @@ -55,12 +54,13 @@ func newASR(config *Config) (ASR, error) { if strings.TrimSpace(config.Provider) != "" { return nil, fmt.Errorf("%s does not offer speech recognition in this build", resolved.Vendor.Name) } - resolved, err = catalog.Resolve(catalog.Ref{ - Provider: catalog.GenericID, + resolved, err = modelruntime.Resolve(modelruntime.Ref{ + Provider: providers.GenericID, Model: config.ModelName, BaseURL: config.BaseURL, ModelType: types.ModelTypeASR, Extra: config.ExtraConfig, + Override: config.Spec, }) if err != nil { return nil, err @@ -71,42 +71,22 @@ func newASR(config *Config) (ASR, error) { } vendor := resolved.Vendor - creds := catalog.Credentials{APIKey: config.APIKey} - if creds.APIKey == "" { - creds.APIKey = vendor.DefaultAPIKey + endpoint, err := resolved.Endpoint(types.ModelTypeASR, modelruntime.Connection{ + ModelID: config.ModelID, + Credentials: api.Credentials{APIKey: config.APIKey}, + Headers: config.CustomHeaders, + Extra: config.ExtraConfig, + Client: newASRHTTPClient(time.Duration(resolved.Transcriptions.RequestTimeout) * time.Second), + }) + if err != nil { + return nil, err } - // Vendor headers first so a user header cannot silently replace a vendor - // beta flag, matching chat.NewRemoteChat. - headers := make(map[string]string, len(vendor.Headers)+len(config.CustomHeaders)) - for k, v := range vendor.Headers { - headers[k] = v - } - for k, v := range config.CustomHeaders { - headers[k] = v - } - settings := resolved.Transcriptions - endpoint := api.Endpoint{ - BaseURL: resolved.BaseURL, - Model: resolved.RemoteModel, - ModelID: config.ModelID, - Auth: vendor.AuthFunc(vendor.API, creds), - Headers: headers, - Client: newASRHTTPClient(time.Duration(settings.RequestTimeout) * time.Second), - } - if vendor.Endpoint != nil { - if url, query := vendor.Endpoint(catalog.EndpointRequest{ - BaseURL: resolved.BaseURL, - Model: resolved.RemoteModel, - ModelType: types.ModelTypeASR, - API: vendor.API, - Extra: config.ExtraConfig, - }); url != "" { - if err := validateASRBaseURL(url); err != nil { - return nil, err - } - endpoint.URL, endpoint.Query = url, query + if endpoint.URL != "" { + if err := validateASRBaseURL(endpoint.URL); err != nil { + return nil, err } } + settings := resolved.Transcriptions var client api.Transcriber switch resolved.TranscriptionAPI { @@ -136,7 +116,7 @@ func newASR(config *Config) (ASR, error) { // upload the vendor has documented it will not take, before sending it. type protocolASR struct { inner api.Transcriber - settings catalog.TranscriptionsSettings + settings api.TranscriptionsSettings vendor string endpoint string modelName string diff --git a/internal/models/asr/wire_test.go b/internal/models/asr/wire_test.go index 503921fa..05e0c5db 100644 --- a/internal/models/asr/wire_test.go +++ b/internal/models/asr/wire_test.go @@ -11,7 +11,7 @@ import ( "sync/atomic" "testing" - "github.com/Tencent/WeKnora/internal/models/catalog" + modelruntime "github.com/Tencent/WeKnora/internal/models/runtime" "github.com/Tencent/WeKnora/internal/types" secutils "github.com/Tencent/WeKnora/internal/utils" "github.com/stretchr/testify/assert" @@ -260,7 +260,7 @@ func TestVendorsWithoutASRAreNotRoutedThroughTheirHooks(t *testing.T) { // host detects as Azure while the request still reaches the test server. url, got, _ := upstream(t) base := url + "/openai.azure.com/v1" - require.Equal(t, "azure_openai", catalog.DetectByURL(base)) + require.Equal(t, "azure_openai", modelruntime.DetectByURL(base)) a, err := NewASR(&Config{ Source: types.ModelSourceRemote, BaseURL: base, ModelName: "whisper", APIKey: "k", }) diff --git a/internal/models/capabilities.go b/internal/models/capabilities.go new file mode 100644 index 00000000..bdde0f4c --- /dev/null +++ b/internal/models/capabilities.go @@ -0,0 +1,17 @@ +package models + +import "github.com/Tencent/WeKnora/internal/models/api" + +// Capabilities is the UI-facing summary of a resolved model. +type Capabilities struct { + Provider string `json:"provider"` + API api.API `json:"api"` + Cataloged bool `json:"cataloged"` + Reasoning bool `json:"reasoning"` + ThinkingLevels []api.ReasoningEffort `json:"thinking_levels"` + ThinkingFormat string `json:"thinking_format"` + Input []string `json:"input,omitempty"` + ContextWindow int `json:"context_window,omitempty"` + MaxOutputTokens int `json:"max_output_tokens,omitempty"` + MaxTokensField string `json:"max_tokens_field,omitempty"` +} diff --git a/internal/models/catalog/catalog.go b/internal/models/catalog/catalog.go new file mode 100644 index 00000000..8ae280df --- /dev/null +++ b/internal/models/catalog/catalog.go @@ -0,0 +1,128 @@ +// Package catalog loads and queries model metadata. It has no provider behavior or global registry. +package catalog + +import ( + "strings" + + "github.com/Tencent/WeKnora/internal/models" + "github.com/Tencent/WeKnora/internal/models/internal/configcopy" + "github.com/Tencent/WeKnora/internal/types" +) + +// Catalog is an immutable model index for one provider. Queries return owned copies. +type Catalog struct{ entries []models.ModelSpec } + +// New builds an immutable index from an owned copy of the supplied entries. +func New(entries []models.ModelSpec) *Catalog { return &Catalog{entries: configcopy.Clone(entries)} } + +// Models returns independent copies of all entries, including hidden rules. +func (c *Catalog) Models() []models.ModelSpec { return configcopy.Clone(c.entries) } + +// ModelsByType returns the vendor's catalog entries for a model type, +// hiding deprecated and pattern-only entries. +func (c *Catalog) ModelsByType(modelType types.ModelType) []models.ModelSpec { + out := make([]models.ModelSpec, 0) + for _, m := range c.entries { + if m.Deprecated || m.ID == "" { + continue + } + mt := m.Type + if mt == "" { + mt = types.ModelTypeKnowledgeQA + } + switch modelType { + case types.ModelTypeVLLM: + // VLM pickers list chat models that accept images. + if mt == types.ModelTypeKnowledgeQA && m.AcceptsImages() { + out = append(out, configcopy.Clone(m)) + } + default: + if mt == modelType { + out = append(out, configcopy.Clone(m)) + } + } + } + return out +} + +// FindModel looks a model name up among the vendor's entries of one model +// type: exact id, then aliases, then glob patterns (longest literal prefix +// wins). Matching is case-insensitive. +// +// The type is part of the key because families share prefixes across types. +// Aliyun's qwen3* chat glob also matches qwen3.8-text-embedding, and gpt-5* +// matches gpt-5-embed; an untyped lookup would hand an embedding row the chat +// family's compat, which the embedding overlay rejects, and the row could not +// be built at all. A VLM row is a chat model that accepts images, so it looks +// among the chat entries. +func (c *Catalog) FindModel(name string, modelType types.ModelType) (models.ModelSpec, bool) { + needle := strings.ToLower(strings.TrimSpace(name)) + if needle == "" { + return models.ModelSpec{}, false + } + want := EntryType(modelType) + var candidates []models.ModelSpec + for _, m := range c.entries { + if EntryType(m.Type) == want { + candidates = append(candidates, m) + } + } + for _, m := range candidates { + if strings.ToLower(m.ID) == needle { + return configcopy.Clone(m), true + } + } + for _, m := range candidates { + for _, alias := range m.Aliases { + if strings.ToLower(alias) == needle { + return configcopy.Clone(m), true + } + } + } + var best models.ModelSpec + bestScore := -1 + for _, m := range candidates { + if m.Match == "" { + continue + } + if globMatch(strings.ToLower(m.Match), needle) { + score := len(strings.TrimRight(strings.SplitN(m.Match, "*", 2)[0], "*")) + if score > bestScore { + best, bestScore = m, score + } + } + } + if bestScore >= 0 { + return configcopy.Clone(best), true + } + return models.ModelSpec{}, false +} + +// EntryType folds a model type onto the catalog entries that describe it: +// chat entries leave Type empty, and VLM rows use them too. +func EntryType(t types.ModelType) types.ModelType { + if t == "" || t == types.ModelTypeVLLM { + return types.ModelTypeKnowledgeQA + } + return t +} + +// globMatch supports '*' wildcards only. +func globMatch(pattern, s string) bool { + parts := strings.Split(pattern, "*") + if len(parts) == 1 { + return pattern == s + } + if !strings.HasPrefix(s, parts[0]) { + return false + } + s = s[len(parts[0]):] + for i := 1; i < len(parts)-1; i++ { + idx := strings.Index(s, parts[i]) + if idx < 0 { + return false + } + s = s[idx+len(parts[i]):] + } + return strings.HasSuffix(s, parts[len(parts)-1]) +} diff --git a/internal/models/catalog/data/models.generated.json b/internal/models/catalog/data/models.generated.json new file mode 100644 index 00000000..1b895982 --- /dev/null +++ b/internal/models/catalog/data/models.generated.json @@ -0,0 +1,5797 @@ +{ + "version": 1, + "providers": { + "aliyun": [ + { + "name": "Qwen3 family (hybrid thinking)", + "match": "qwen3*", + "reasoning": true, + "input": [ + "text" + ], + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true + } + }, + { + "name": "Qwen3.5 family (hybrid thinking)", + "match": "qwen3.5*", + "reasoning": true, + "input": [ + "text", + "image" + ], + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true + } + }, + { + "name": "Qwen3.6 family (hybrid thinking)", + "match": "qwen3.6*", + "reasoning": true, + "input": [ + "text", + "image" + ], + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true + } + }, + { + "name": "Qwen3.7 family (hybrid thinking)", + "match": "qwen3.7*", + "reasoning": true, + "input": [ + "text", + "image" + ], + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true + } + }, + { + "name": "Qwen3.8 family (hybrid thinking)", + "match": "qwen3.8*", + "reasoning": true, + "input": [ + "text", + "image" + ], + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true, + "supports_reasoning_effort": true, + "thinking_budget_excludes_effort": true + }, + "thinking_levels": { + "minimal": "low", + "low": "low", + "medium": "medium", + "high": "medium", + "xhigh": "xhigh", + "max": "xhigh" + } + }, + { + "name": "qwen-plus family (hybrid thinking)", + "match": "qwen-plus*", + "reasoning": true, + "input": [ + "text" + ], + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true + } + }, + { + "name": "qwen-max family (hybrid thinking)", + "match": "qwen-max*", + "reasoning": true, + "input": [ + "text" + ], + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true + } + }, + { + "name": "qwen-turbo family (hybrid thinking)", + "match": "qwen-turbo*", + "reasoning": true, + "input": [ + "text" + ], + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true + } + }, + { + "name": "qwen-flash family (hybrid thinking)", + "match": "qwen-flash*", + "reasoning": true, + "input": [ + "text" + ], + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true + } + }, + { + "name": "DeepSeek V3 family on DashScope (hybrid thinking)", + "match": "deepseek-v3*", + "reasoning": true, + "input": [ + "text" + ], + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true + } + }, + { + "name": "DeepSeek V4 family on DashScope (hybrid thinking)", + "match": "deepseek-v4*", + "reasoning": true, + "input": [ + "text" + ], + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true + } + }, + { + "name": "Kimi K2 family on DashScope (hybrid thinking)", + "match": "kimi-k2*", + "reasoning": true, + "input": [ + "text", + "image" + ], + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true + } + }, + { + "name": "GLM-5 family on DashScope (hybrid thinking)", + "match": "glm-5*", + "reasoning": true, + "input": [ + "text" + ], + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true + } + }, + { + "id": "qwen3.8-max", + "name": "Qwen3.8 Max", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 1000000, + "max_output_tokens": 131072, + "cost": { + "input": 1.77744, + "output": 5.33231, + "cache_read": 0.22218, + "cache_write": 2.22179 + }, + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true, + "supports_reasoning_effort": true, + "thinking_budget_excludes_effort": true + }, + "thinking_levels": { + "minimal": "low", + "low": "low", + "medium": "medium", + "high": "medium", + "xhigh": "xhigh", + "max": "xhigh" + } + }, + { + "id": "qwen3.8-flash", + "name": "Qwen3.8 Flash", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 1000000, + "max_output_tokens": 131072, + "cost": { + "input": 0.11875, + "output": 0.40073, + "cache_read": 0.01187, + "cache_write": 0.14844 + }, + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true, + "supports_reasoning_effort": true, + "thinking_budget_excludes_effort": true + }, + "thinking_levels": { + "minimal": "low", + "low": "low", + "medium": "medium", + "high": "medium", + "xhigh": "xhigh", + "max": "xhigh" + } + }, + { + "id": "qwen3.7-max", + "name": "Qwen3.7 Max", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1000000, + "max_output_tokens": 65536, + "cost": { + "input": 2.5, + "output": 7.5, + "cache_read": 0.5, + "cache_write": 3.125 + }, + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true + } + }, + { + "id": "qwen3.7-plus", + "name": "Qwen3.7 Plus", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 1000000, + "max_output_tokens": 64000, + "cost": { + "input": 0.5, + "output": 3, + "cache_read": 0.05, + "cache_write": 0.625 + }, + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true + } + }, + { + "id": "qwen3.7-flash", + "name": "Qwen3.7 Flash", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 1000000, + "max_output_tokens": 65536, + "cost": { + "input": 0.02962, + "output": 0.1185, + "cache_read": 0.002962, + "cache_write": 0.03703 + }, + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true + } + }, + { + "id": "qwen3.6-plus", + "name": "Qwen3.6 Plus", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 1000000, + "max_output_tokens": 65536, + "cost": { + "input": 0.5, + "output": 3, + "cache_read": 0.05, + "cache_write": 0.625 + }, + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true + } + }, + { + "id": "qwen3.6-flash", + "name": "Qwen3.6 Flash", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 1000000, + "max_output_tokens": 65536, + "cost": { + "input": 0.1875, + "output": 1.125, + "cache_write": 0.234375 + }, + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true + } + }, + { + "id": "qwen3.5-plus", + "name": "Qwen3.5 Plus", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 1000000, + "max_output_tokens": 65536, + "cost": { + "input": 0.287, + "output": 1.722 + }, + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true + } + }, + { + "id": "qwen3.5-flash", + "name": "Qwen3.5 Flash", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 1000000, + "max_output_tokens": 65536, + "cost": { + "input": 0.172, + "output": 1.033 + }, + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true + } + }, + { + "id": "qwen3-max", + "name": "Qwen3 Max", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 262144, + "max_output_tokens": 65536, + "cost": { + "input": 1.291, + "output": 7.749 + }, + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true + } + }, + { + "id": "qwen3-vl-plus", + "name": "Qwen3 VL Plus", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 262144, + "max_output_tokens": 32768, + "cost": { + "input": 0.143353, + "output": 1.433525 + }, + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true + } + }, + { + "id": "qwen-plus", + "name": "Qwen Plus", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1000000, + "max_output_tokens": 32768, + "cost": { + "input": 0.115, + "output": 0.287, + "cache_read": 0.012, + "cache_write": 0.144 + }, + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true + } + }, + { + "id": "qwen-max", + "name": "Qwen Max", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 131072, + "max_output_tokens": 8192, + "cost": { + "input": 0.345, + "output": 1.377 + }, + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true + } + }, + { + "id": "qwen-turbo", + "name": "Qwen Turbo", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1000000, + "max_output_tokens": 16384, + "cost": { + "input": 0.044, + "output": 0.087 + }, + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true + } + }, + { + "id": "qwen-flash", + "name": "Qwen Flash", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1000000, + "max_output_tokens": 32768, + "cost": { + "input": 0.022, + "output": 0.216 + }, + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true + } + }, + { + "id": "qwen-vl-max", + "name": "Qwen VL Max", + "reasoning": false, + "input": [ + "text", + "image" + ], + "context_window": 131072, + "max_output_tokens": 8192, + "cost": { + "input": 0.23, + "output": 0.574 + }, + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking" + }, + { + "id": "qwen-vl-plus", + "name": "Qwen VL Plus", + "reasoning": false, + "input": [ + "text", + "image" + ], + "context_window": 131072, + "max_output_tokens": 8192, + "cost": { + "input": 0.115, + "output": 0.287 + }, + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking" + }, + { + "id": "qwq-plus", + "name": "QwQ Plus", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 131072, + "max_output_tokens": 8192, + "cost": { + "input": 0.23, + "output": 0.574 + }, + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking", + "thinking_levels": { + "off": null + } + }, + { + "id": "qwq-32b", + "name": "QwQ 32B", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 131072, + "max_output_tokens": 8192, + "cost": { + "input": 0.287, + "output": 0.861 + }, + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking", + "thinking_levels": { + "off": null + } + }, + { + "id": "deepseek-v4-pro", + "name": "DeepSeek V4 Pro", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1000000, + "max_output_tokens": 393216, + "cost": { + "input": 0.435, + "output": 0.87, + "cache_read": 0.003625 + }, + "source": "https://help.aliyun.com/zh/model-studio/deepseek-api", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true, + "supports_reasoning_effort": true + }, + "thinking_levels": { + "minimal": "high", + "low": "high", + "medium": "high", + "high": "high", + "xhigh": "max", + "max": "max" + } + }, + { + "id": "deepseek-v4-flash", + "name": "DeepSeek V4 Flash", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1000000, + "max_output_tokens": 393216, + "cost": { + "input": 0.14, + "output": 0.28, + "cache_read": 0.0028 + }, + "source": "https://help.aliyun.com/zh/model-studio/deepseek-api", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true, + "supports_reasoning_effort": true + }, + "thinking_levels": { + "minimal": "high", + "low": "high", + "medium": "high", + "high": "high", + "xhigh": "max", + "max": "max" + } + }, + { + "id": "deepseek-r1", + "name": "DeepSeek R1", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 131072, + "max_output_tokens": 16384, + "cost": { + "input": 0.574, + "output": 2.294 + }, + "source": "https://help.aliyun.com/zh/model-studio/deepseek-api", + "thinking_levels": { + "off": null + } + }, + { + "id": "kimi-k3", + "name": "Kimi K3", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 1048576, + "max_output_tokens": 1048576, + "cost": { + "input": 2.827, + "output": 14.133, + "cache_read": 0.283 + }, + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking", + "thinking_levels": { + "off": null + } + }, + { + "id": "kimi-k2.6", + "name": "Kimi K2.6", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 262144, + "max_output_tokens": 16384, + "cost": { + "input": 0.929, + "output": 3.858 + }, + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true + } + }, + { + "id": "glm-5.3", + "name": "GLM-5.3", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1000000, + "max_output_tokens": 131072, + "cost": { + "input": 1.1, + "output": 3.851, + "cache_read": 0.275 + }, + "source": "https://docs.bigmodel.cn/cn/guide/models/text/glm-5.3", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true, + "supports_reasoning_effort": true + }, + "thinking_levels": { + "off": null, + "minimal": "low", + "low": "low", + "medium": "high", + "high": "high", + "xhigh": "max", + "max": "max" + } + }, + { + "id": "qwen3.7-text-embedding", + "name": "Qwen3.7 Text Embedding", + "type": "Embedding", + "dimension": 1024, + "source": "https://help.aliyun.com/zh/model-studio/embedding", + "compat": { + "max_batch_size": 20 + } + }, + { + "id": "qwen3.7-text-embedding-flash", + "name": "Qwen3.7 Text Embedding Flash", + "type": "Embedding", + "dimension": 1024, + "source": "https://help.aliyun.com/zh/model-studio/embedding", + "compat": { + "max_batch_size": 20 + } + }, + { + "id": "text-embedding-v4", + "name": "Tongyi text-embedding-v4", + "type": "Embedding", + "dimension": 1024, + "source": "https://help.aliyun.com/zh/model-studio/embedding", + "compat": { + "max_batch_size": 10 + } + }, + { + "id": "text-embedding-v3", + "name": "Tongyi text-embedding-v3", + "type": "Embedding", + "dimension": 1024, + "source": "https://help.aliyun.com/zh/model-studio/embedding", + "compat": { + "max_batch_size": 10 + } + }, + { + "name": "text-embedding-v2 (fixed 1536 dimensions)", + "match": "text-embedding-v2", + "type": "Embedding", + "source": "https://help.aliyun.com/zh/model-studio/embedding-interfaces-compatible-with-openai", + "compat": { + "dimensions_field": "", + "max_batch_size": 25 + } + }, + { + "name": "text-embedding-v1 (fixed 1536 dimensions)", + "match": "text-embedding-v1", + "type": "Embedding", + "source": "https://help.aliyun.com/zh/model-studio/embedding-interfaces-compatible-with-openai", + "compat": { + "dimensions_field": "", + "max_batch_size": 25 + } + }, + { + "id": "tongyi-embedding-vision-plus", + "name": "Tongyi Embedding Vision Plus", + "type": "Embedding", + "dimension": 1152, + "source": "https://help.aliyun.com/zh/model-studio/multimodal-embedding-api-reference", + "compat": { + "api": "dashscope-embeddings", + "dimensions_field": "" + } + }, + { + "name": "tongyi-embedding-vision-flash (fixed 768 dimensions)", + "match": "tongyi-embedding-vision-flash", + "type": "Embedding", + "source": "https://help.aliyun.com/zh/model-studio/multimodal-embedding-api-reference", + "compat": { + "api": "dashscope-embeddings", + "dimensions_field": "" + } + }, + { + "name": "tongyi-embedding-vision snapshots", + "match": "tongyi-embedding-vision*", + "type": "Embedding", + "source": "https://help.aliyun.com/zh/model-studio/multimodal-embedding-api-reference", + "compat": { + "api": "dashscope-embeddings", + "dimensions_field": "dimension", + "max_batch_size": 20 + } + }, + { + "name": "qwen3-vl-embedding (independent vectors by default)", + "match": "qwen3-vl-embedding*", + "type": "Embedding", + "source": "https://help.aliyun.com/zh/model-studio/multimodal-embedding-api-reference", + "compat": { + "api": "dashscope-embeddings", + "dimensions_field": "dimension", + "max_batch_size": 20 + } + }, + { + "name": "qwen2.5-vl-embedding (fused vectors only)", + "match": "qwen2.5-vl-embedding*", + "type": "Embedding", + "source": "https://help.aliyun.com/zh/model-studio/multimodal-embedding-api-reference", + "compat": { + "api": "dashscope-embeddings", + "dimensions_field": "dimension", + "max_batch_size": 1 + } + }, + { + "name": "multimodal-embedding-v1", + "match": "multimodal-embedding*", + "type": "Embedding", + "source": "https://help.aliyun.com/zh/model-studio/multimodal-embedding-api-reference", + "compat": { + "api": "dashscope-embeddings", + "dimensions_field": "", + "max_batch_size": 20 + } + }, + { + "id": "qwen3-rerank", + "name": "Qwen3 Rerank (separate endpoint, not implemented)", + "type": "Rerank", + "deprecated": true, + "source": "https://help.aliyun.com/zh/model-studio/text-rerank-api", + "compat": { + "unsupported_reason": "qwen3-rerank speaks a different protocol (/compatible-api/v1/reranks, flat request, results at the top level) that no protocol package implements yet" + } + }, + { + "id": "gte-rerank-v2", + "name": "GTE Rerank v2", + "type": "Rerank", + "source": "https://help.aliyun.com/zh/model-studio/text-rerank-api" + }, + { + "id": "qwen3-asr-flash", + "name": "Qwen3 ASR Flash", + "type": "ASR", + "source": "https://help.aliyun.com/zh/model-studio/qwen-asr-api-reference", + "compat": { + "api": "openai-chat-audio", + "max_encoded_bytes": 10485760, + "language_param": "asr_options" + } + }, + { + "name": "Other Alibaba recognition models (not callable with the audio in the request)", + "match": "*", + "type": "ASR", + "source": "https://help.aliyun.com/zh/model-studio/qwen-asr-api-reference", + "compat": { + "unsupported_reason": "Alibaba's other recognition models take a public file URL or run as asynchronous tasks; only qwen3-asr-flash accepts the audio in the request" + } + } + ], + "anthropic": [ + { + "id": "claude-fable-5-1", + "name": "Claude Fable 5.1", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 1000000, + "max_output_tokens": 128000, + "cost": { + "input": 10, + "output": 50, + "cache_read": 0.25, + "cache_write": 12.5 + }, + "source": "https://docs.anthropic.com/en/docs/about-claude/models", + "api": "anthropic-messages", + "compat": { + "thinking_mode": "adaptive", + "supports_effort": true + }, + "thinking_levels": { + "off": null, + "minimal": "low", + "low": "low", + "medium": "medium", + "high": "high", + "xhigh": "xhigh", + "max": "max" + } + }, + { + "id": "claude-opus-5", + "name": "Claude Opus 5", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 1000000, + "max_output_tokens": 128000, + "cost": { + "input": 5, + "output": 25, + "cache_read": 0.5, + "cache_write": 6.25 + }, + "source": "https://platform.claude.com/docs/en/build-with-claude/thinking-troubleshooting#supported-models", + "api": "anthropic-messages", + "compat": { + "thinking_mode": "adaptive", + "supports_effort": true + }, + "thinking_levels": { + "minimal": "low", + "low": "low", + "medium": "medium", + "high": "high", + "xhigh": "xhigh", + "max": "max" + } + }, + { + "id": "claude-sonnet-5", + "name": "Claude Sonnet 5", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 1000000, + "max_output_tokens": 128000, + "cost": { + "input": 2, + "output": 10, + "cache_read": 0.2, + "cache_write": 2.5 + }, + "source": "https://docs.anthropic.com/en/docs/about-claude/models", + "api": "anthropic-messages", + "compat": { + "thinking_mode": "adaptive", + "supports_effort": true + }, + "thinking_levels": { + "minimal": "low", + "low": "low", + "medium": "medium", + "high": "high", + "xhigh": "xhigh", + "max": "max" + } + }, + { + "id": "claude-fable-5", + "name": "Claude Fable 5", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 1000000, + "max_output_tokens": 128000, + "cost": { + "input": 10, + "output": 50, + "cache_read": 1, + "cache_write": 12.5 + }, + "source": "https://docs.anthropic.com/en/docs/about-claude/models", + "api": "anthropic-messages", + "compat": { + "thinking_mode": "adaptive", + "supports_effort": true + }, + "thinking_levels": { + "off": null, + "minimal": "low", + "low": "low", + "medium": "medium", + "high": "high", + "xhigh": "xhigh", + "max": "max" + } + }, + { + "id": "claude-opus-4-8", + "name": "Claude Opus 4.8", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 1000000, + "max_output_tokens": 128000, + "cost": { + "input": 5, + "output": 25, + "cache_read": 0.5, + "cache_write": 6.25 + }, + "source": "https://platform.claude.com/docs/en/build-with-claude/thinking-troubleshooting#supported-models", + "api": "anthropic-messages", + "compat": { + "thinking_mode": "adaptive", + "supports_effort": true + }, + "thinking_levels": { + "minimal": "low", + "low": "low", + "medium": "medium", + "high": "high", + "xhigh": "xhigh", + "max": "max" + } + }, + { + "id": "claude-opus-4-7", + "name": "Claude Opus 4.7", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 1000000, + "max_output_tokens": 128000, + "cost": { + "input": 5, + "output": 25, + "cache_read": 0.5, + "cache_write": 6.25 + }, + "source": "https://platform.claude.com/docs/en/build-with-claude/thinking-troubleshooting#supported-models", + "api": "anthropic-messages", + "compat": { + "thinking_mode": "adaptive", + "supports_effort": true + }, + "thinking_levels": { + "minimal": "low", + "low": "low", + "medium": "medium", + "high": "high", + "xhigh": "xhigh", + "max": "max" + } + }, + { + "id": "claude-sonnet-4-6", + "name": "Claude Sonnet 4.6", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 1000000, + "max_output_tokens": 128000, + "cost": { + "input": 3, + "output": 15, + "cache_read": 0.3, + "cache_write": 3.75 + }, + "source": "https://docs.anthropic.com/en/docs/about-claude/models", + "api": "anthropic-messages", + "compat": { + "thinking_mode": "adaptive", + "supports_effort": true + }, + "thinking_levels": { + "minimal": "low", + "low": "low", + "medium": "medium", + "high": "high", + "xhigh": "max", + "max": "max" + } + }, + { + "id": "claude-opus-4-6", + "name": "Claude Opus 4.6", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 1000000, + "max_output_tokens": 128000, + "cost": { + "input": 5, + "output": 25, + "cache_read": 0.5, + "cache_write": 6.25 + }, + "source": "https://docs.anthropic.com/en/docs/about-claude/models", + "api": "anthropic-messages", + "compat": { + "thinking_mode": "adaptive", + "supports_effort": true + }, + "thinking_levels": { + "minimal": "low", + "low": "low", + "medium": "medium", + "high": "high", + "xhigh": "max", + "max": "max" + } + }, + { + "id": "claude-opus-4-5", + "name": "Claude Opus 4.5", + "aliases": [ + "claude-opus-4-5-20251101" + ], + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 200000, + "max_output_tokens": 64000, + "cost": { + "input": 5, + "output": 25, + "cache_read": 0.5, + "cache_write": 6.25 + }, + "source": "https://platform.claude.com/docs/en/build-with-claude/effort", + "api": "anthropic-messages", + "compat": { + "supports_effort": true + } + }, + { + "id": "claude-sonnet-4-5", + "name": "Claude Sonnet 4.5", + "aliases": [ + "claude-sonnet-4-5-20250929" + ], + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 200000, + "max_output_tokens": 64000, + "cost": { + "input": 3, + "output": 15, + "cache_read": 0.3, + "cache_write": 3.75 + }, + "source": "https://platform.claude.com/docs/en/models/sonnet-4-5/overview", + "api": "anthropic-messages" + }, + { + "id": "claude-haiku-4-5", + "name": "Claude Haiku 4.5", + "aliases": [ + "claude-haiku-4-5-20251001" + ], + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 200000, + "max_output_tokens": 64000, + "cost": { + "input": 1, + "output": 5, + "cache_read": 0.1, + "cache_write": 1.25 + }, + "source": "https://docs.anthropic.com/en/docs/about-claude/models", + "api": "anthropic-messages" + } + ], + "azure_openai": [ + { + "name": "GPT-6 deployments (reasoning, thinking always on)", + "match": "gpt-6*", + "reasoning": true, + "input": [ + "text", + "image" + ], + "source": "https://learn.microsoft.com/azure/ai-foundry/openai/how-to/reasoning", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": null, + "minimal": "low", + "xhigh": "xhigh", + "max": "xhigh" + } + }, + { + "name": "GPT-5 deployments (reasoning, no sampling parameters)", + "match": "gpt-5*", + "reasoning": true, + "input": [ + "text", + "image" + ], + "source": "https://learn.microsoft.com/azure/ai-foundry/openai/how-to/reasoning", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": "none", + "minimal": "low" + } + }, + { + "id": "gpt-5", + "name": "GPT-5 deployment (thinking cannot be disabled)", + "reasoning": true, + "input": [ + "text", + "image" + ], + "source": "https://developers.openai.com/api/docs/models/gpt-5", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": null, + "xhigh": "high", + "max": "high" + } + }, + { + "id": "gpt-5-mini", + "name": "GPT-5 Mini deployment (thinking cannot be disabled)", + "reasoning": true, + "input": [ + "text", + "image" + ], + "source": "https://developers.openai.com/api/docs/models/gpt-5-mini", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": null, + "xhigh": "high", + "max": "high" + } + }, + { + "id": "gpt-5-nano", + "name": "GPT-5 Nano deployment (thinking cannot be disabled)", + "reasoning": true, + "input": [ + "text", + "image" + ], + "source": "https://developers.openai.com/api/docs/models/gpt-5-nano", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": null, + "xhigh": "high", + "max": "high" + } + }, + { + "name": "o1 deployments (always-on reasoning)", + "match": "o1*", + "reasoning": true, + "input": [ + "text", + "image" + ], + "source": "https://learn.microsoft.com/azure/ai-foundry/openai/how-to/reasoning", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": null, + "minimal": "low", + "xhigh": "high", + "max": "high" + } + }, + { + "name": "o3 deployments (always-on reasoning)", + "match": "o3*", + "reasoning": true, + "input": [ + "text", + "image" + ], + "source": "https://learn.microsoft.com/azure/ai-foundry/openai/how-to/reasoning", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": null, + "minimal": "low", + "xhigh": "high", + "max": "high" + } + }, + { + "name": "o4 deployments (always-on reasoning)", + "match": "o4*", + "reasoning": true, + "input": [ + "text", + "image" + ], + "source": "https://learn.microsoft.com/azure/ai-foundry/openai/how-to/reasoning", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": null, + "minimal": "low", + "xhigh": "high", + "max": "high" + } + }, + { + "name": "GPT-4o deployments", + "match": "gpt-4o*", + "reasoning": false, + "input": [ + "text", + "image" + ], + "source": "https://learn.microsoft.com/azure/ai-foundry/openai/how-to/reasoning" + }, + { + "name": "GPT-4.1 deployments", + "match": "gpt-4.1*", + "reasoning": false, + "input": [ + "text", + "image" + ], + "source": "https://learn.microsoft.com/azure/ai-foundry/openai/how-to/reasoning" + }, + { + "name": "text-embedding-3 deployments", + "match": "text-embedding-3*", + "type": "Embedding", + "source": "https://learn.microsoft.com/azure/ai-foundry/openai/how-to/reasoning" + } + ], + "deepseek": [ + { + "id": "deepseek-v4-pro", + "name": "DeepSeek V4 Pro", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1000000, + "max_output_tokens": 384000, + "cost": { + "input": 0.66, + "output": 1.98, + "cache_read": 0.022 + }, + "source": "https://api-docs.deepseek.com/quick_start/pricing", + "thinking_levels": { + "minimal": "high", + "low": "high", + "medium": "high", + "high": "high", + "xhigh": "max", + "max": "max" + } + }, + { + "id": "deepseek-flash", + "name": "DeepSeek V4.1 Flash", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 1000000, + "max_output_tokens": 384000, + "cost": { + "input": 0.15, + "output": 0.6, + "cache_read": 0.003 + }, + "source": "https://api-docs.deepseek.com/quick_start/pricing" + }, + { + "id": "deepseek-v4-flash", + "name": "DeepSeek V4 Flash (retired name, served by V4.1 Flash)", + "deprecated": true, + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 1000000, + "max_output_tokens": 384000, + "cost": { + "input": 0.15, + "output": 0.6, + "cache_read": 0.003 + }, + "source": "https://api-docs.deepseek.com/quick_start/pricing" + }, + { + "id": "deepseek-chat", + "name": "DeepSeek Chat (retired 2026-07-24, non-thinking alias)", + "deprecated": true, + "reasoning": false, + "input": [ + "text" + ], + "context_window": 128000, + "max_output_tokens": 8192, + "source": "https://api-docs.deepseek.com/news/news260424/" + }, + { + "id": "deepseek-reasoner", + "name": "DeepSeek Reasoner (retired 2026-07-24, thinking alias)", + "deprecated": true, + "reasoning": true, + "input": [ + "text" + ], + "context_window": 128000, + "max_output_tokens": 65536, + "source": "https://api-docs.deepseek.com/news/news260424/", + "thinking_levels": { + "off": null + } + } + ], + "gemini": [ + { + "name": "Gemini 3 family (thinkingLevel)", + "match": "gemini-3*", + "reasoning": true, + "input": [ + "text", + "image", + "audio", + "video" + ], + "source": "https://ai.google.dev/gemini-api/docs/thinking", + "api": "google-generative-ai", + "compat": { + "thinking_mode": "level" + }, + "thinking_levels": { + "off": null, + "minimal": "low", + "low": "low", + "medium": "high", + "high": "high", + "xhigh": "high", + "max": "high" + } + }, + { + "id": "gemini-3.8-flash", + "name": "Gemini 3.8 Flash", + "reasoning": true, + "input": [ + "text", + "image", + "audio", + "video" + ], + "context_window": 1048576, + "max_output_tokens": 65536, + "cost": { + "input": 0.75, + "output": 3.75, + "cache_read": 0.075 + }, + "source": "https://ai.google.dev/gemini-api/docs/thinking", + "api": "google-generative-ai", + "compat": { + "thinking_mode": "level" + }, + "thinking_levels": { + "off": null, + "minimal": "low", + "low": "low", + "medium": "medium", + "high": "high", + "xhigh": "high", + "max": "high" + } + }, + { + "id": "gemini-3.7-flash", + "name": "Gemini 3.7 Flash", + "reasoning": true, + "input": [ + "text", + "image", + "audio", + "video" + ], + "context_window": 1048576, + "max_output_tokens": 65536, + "cost": { + "input": 0.75, + "output": 3.75, + "cache_read": 0.075 + }, + "source": "https://ai.google.dev/gemini-api/docs/thinking", + "api": "google-generative-ai", + "compat": { + "thinking_mode": "level" + }, + "thinking_levels": { + "off": null, + "minimal": "low", + "low": "low", + "medium": "medium", + "high": "high", + "xhigh": "high", + "max": "high" + } + }, + { + "id": "gemini-3.6-flash", + "name": "Gemini 3.6 Flash", + "reasoning": true, + "input": [ + "text", + "image", + "audio", + "video" + ], + "context_window": 1048576, + "max_output_tokens": 65536, + "cost": { + "input": 0.75, + "output": 3.75, + "cache_read": 0.075 + }, + "source": "https://ai.google.dev/gemini-api/docs/thinking", + "api": "google-generative-ai", + "compat": { + "thinking_mode": "level" + }, + "thinking_levels": { + "off": null, + "minimal": "minimal", + "low": "low", + "medium": "medium", + "high": "high", + "xhigh": "high", + "max": "high" + } + }, + { + "id": "gemini-3.5-flash", + "name": "Gemini 3.5 Flash", + "reasoning": true, + "input": [ + "text", + "image", + "audio", + "video" + ], + "context_window": 1048576, + "max_output_tokens": 65536, + "cost": { + "input": 1.5, + "output": 9, + "cache_read": 0.15 + }, + "source": "https://ai.google.dev/gemini-api/docs/thinking", + "api": "google-generative-ai", + "compat": { + "thinking_mode": "level" + }, + "thinking_levels": { + "off": null, + "minimal": "minimal", + "low": "low", + "medium": "medium", + "high": "high", + "xhigh": "high", + "max": "high" + } + }, + { + "id": "gemini-3.5-flash-lite", + "name": "Gemini 3.5 Flash Lite", + "reasoning": true, + "input": [ + "text", + "image", + "audio", + "video" + ], + "context_window": 1048576, + "max_output_tokens": 65536, + "cost": { + "input": 0.3, + "output": 2.5, + "cache_read": 0.03 + }, + "source": "https://ai.google.dev/gemini-api/docs/thinking", + "api": "google-generative-ai", + "compat": { + "thinking_mode": "level" + }, + "thinking_levels": { + "off": null, + "minimal": "minimal", + "low": "low", + "medium": "medium", + "high": "high", + "xhigh": "high", + "max": "high" + } + }, + { + "id": "gemini-3.1-pro-preview", + "name": "Gemini 3.1 Pro Preview", + "reasoning": true, + "input": [ + "text", + "image", + "audio", + "video" + ], + "context_window": 1048576, + "max_output_tokens": 65536, + "cost": { + "input": 2, + "output": 12, + "cache_read": 0.2 + }, + "source": "https://ai.google.dev/gemini-api/docs/thinking", + "api": "google-generative-ai", + "compat": { + "thinking_mode": "level" + }, + "thinking_levels": { + "off": null, + "minimal": "low", + "low": "low", + "medium": "medium", + "high": "high", + "xhigh": "high", + "max": "high" + } + }, + { + "id": "gemini-3.1-flash-lite", + "name": "Gemini 3.1 Flash Lite", + "reasoning": true, + "input": [ + "text", + "image", + "audio", + "video" + ], + "context_window": 1048576, + "max_output_tokens": 65536, + "cost": { + "input": 0.25, + "output": 1.5, + "cache_read": 0.025 + }, + "source": "https://ai.google.dev/gemini-api/docs/thinking", + "api": "google-generative-ai", + "compat": { + "thinking_mode": "level" + }, + "thinking_levels": { + "off": null, + "minimal": "minimal", + "low": "low", + "medium": "medium", + "high": "high", + "xhigh": "high", + "max": "high" + } + }, + { + "id": "gemini-3-flash-preview", + "name": "Gemini 3 Flash Preview", + "reasoning": true, + "input": [ + "text", + "image", + "audio", + "video" + ], + "context_window": 1048576, + "max_output_tokens": 65536, + "cost": { + "input": 0.5, + "output": 3, + "cache_read": 0.05 + }, + "source": "https://ai.google.dev/gemini-api/docs/thinking", + "api": "google-generative-ai", + "compat": { + "thinking_mode": "level" + }, + "thinking_levels": { + "off": null, + "minimal": "minimal", + "low": "low", + "medium": "medium", + "high": "high", + "xhigh": "high", + "max": "high" + } + }, + { + "id": "gemini-2.5-pro", + "name": "Gemini 2.5 Pro", + "reasoning": true, + "input": [ + "text", + "image", + "audio", + "video" + ], + "context_window": 1048576, + "max_output_tokens": 65536, + "cost": { + "input": 1.25, + "output": 10, + "cache_read": 0.125 + }, + "source": "https://ai.google.dev/gemini-api/docs/thinking", + "api": "google-generative-ai", + "compat": { + "thinking_mode": "budget" + }, + "thinking_levels": { + "off": null + } + }, + { + "id": "gemini-2.5-flash", + "name": "Gemini 2.5 Flash", + "reasoning": true, + "input": [ + "text", + "image", + "audio", + "video" + ], + "context_window": 1048576, + "max_output_tokens": 65536, + "cost": { + "input": 0.3, + "output": 2.5, + "cache_read": 0.03 + }, + "source": "https://ai.google.dev/gemini-api/docs/thinking", + "api": "google-generative-ai", + "compat": { + "thinking_mode": "budget" + } + }, + { + "id": "gemini-2.5-flash-lite", + "name": "Gemini 2.5 Flash Lite", + "reasoning": true, + "input": [ + "text", + "image", + "audio", + "video" + ], + "context_window": 1048576, + "max_output_tokens": 65536, + "cost": { + "input": 0.1, + "output": 0.4, + "cache_read": 0.01 + }, + "source": "https://ai.google.dev/gemini-api/docs/thinking", + "api": "google-generative-ai", + "compat": { + "thinking_mode": "budget" + } + }, + { + "id": "gemini-embedding-001", + "name": "Gemini Embedding 001", + "type": "Embedding", + "dimension": 3072, + "context_window": 2048, + "cost": { + "input": 0.15, + "output": 0 + }, + "source": "https://ai.google.dev/gemini-api/docs/embeddings" + }, + { + "id": "gemini-embedding-2", + "name": "Gemini Embedding 2", + "aliases": [ + "gemini-embedding-2-preview" + ], + "type": "Embedding", + "input": [ + "text", + "image", + "audio", + "video" + ], + "dimension": 3072, + "context_window": 8192, + "cost": { + "input": 0.2, + "output": 0 + }, + "source": "https://ai.google.dev/gemini-api/docs/embeddings" + } + ], + "generic": [ + { + "match": "gpt-5*", + "reasoning": true, + "source": "https://platform.openai.com/docs/guides/reasoning", + "compat": { + "max_tokens_field": "max_completion_tokens", + "supports_temperature": false, + "thinking_format": "openai", + "supports_reasoning_effort": true + } + }, + { + "match": "o1*", + "reasoning": true, + "source": "https://platform.openai.com/docs/guides/reasoning", + "compat": { + "max_tokens_field": "max_completion_tokens", + "supports_temperature": false, + "thinking_format": "openai", + "supports_reasoning_effort": true + }, + "thinking_levels": { + "off": null, + "minimal": "low", + "xhigh": "high", + "max": "high" + } + }, + { + "match": "o3*", + "reasoning": true, + "source": "https://platform.openai.com/docs/guides/reasoning", + "compat": { + "max_tokens_field": "max_completion_tokens", + "supports_temperature": false, + "thinking_format": "openai", + "supports_reasoning_effort": true + }, + "thinking_levels": { + "off": null, + "minimal": "low", + "xhigh": "high", + "max": "high" + } + }, + { + "match": "o4*", + "reasoning": true, + "source": "https://platform.openai.com/docs/guides/reasoning", + "compat": { + "max_tokens_field": "max_completion_tokens", + "supports_temperature": false, + "thinking_format": "openai", + "supports_reasoning_effort": true + }, + "thinking_levels": { + "off": null, + "minimal": "low", + "xhigh": "high", + "max": "high" + } + } + ], + "gpustack": [], + "hunyuan": [ + { + "name": "Hunyuan T1 family (always-on reasoning)", + "match": "hunyuan-t1*", + "reasoning": true, + "input": [ + "text" + ], + "source": "https://cloud.tencent.com/document/product/1729/104753", + "thinking_levels": { + "off": null + } + }, + { + "id": "hunyuan-t1-latest", + "name": "Hunyuan T1", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 32000, + "source": "https://cloud.tencent.com/document/product/1729/104753", + "thinking_levels": { + "off": null + } + }, + { + "id": "hunyuan-t1-vision-20250916", + "name": "Hunyuan T1 Vision (deep thinking)", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 28000, + "max_output_tokens": 20000, + "source": "https://cloud.tencent.com/document/product/1729/104753", + "thinking_levels": { + "off": null + } + }, + { + "id": "hunyuan-turbos-latest", + "name": "Hunyuan TurboS", + "reasoning": false, + "input": [ + "text" + ], + "context_window": 32000, + "max_output_tokens": 8000, + "cost": { + "input": 0.11, + "output": 0.28 + }, + "source": "https://cloud.tencent.com/document/product/1729/104753" + }, + { + "id": "hunyuan-a13b", + "name": "Hunyuan A13B (hybrid thinking)", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 224000, + "max_output_tokens": 32000, + "source": "https://cloud.tencent.com/document/product/1729/104753" + }, + { + "id": "hunyuan-2.0-thinking-20251109", + "name": "Hunyuan 2.0 Thinking", + "reasoning": true, + "input": [ + "text" + ], + "source": "https://cloud.tencent.com/document/product/1729/127293" + }, + { + "id": "hunyuan-2.0-instruct-20251111", + "name": "Hunyuan 2.0 Instruct", + "reasoning": false, + "input": [ + "text" + ], + "source": "https://cloud.tencent.com/document/product/1729/127293" + }, + { + "id": "hunyuan-vision-1.5-instruct", + "name": "Hunyuan Vision 1.5 Instruct (fast thinking)", + "reasoning": false, + "input": [ + "text", + "image" + ], + "context_window": 24000, + "max_output_tokens": 16000, + "source": "https://cloud.tencent.com/document/product/1729/104753" + }, + { + "id": "hunyuan-turbos-vision-video", + "name": "Hunyuan TurboS Vision Video", + "reasoning": false, + "input": [ + "text", + "image", + "video" + ], + "context_window": 24000, + "max_output_tokens": 8000, + "source": "https://cloud.tencent.com/document/product/1729/104753" + }, + { + "id": "hunyuan-turbos-vision", + "name": "Hunyuan TurboS Vision", + "reasoning": false, + "input": [ + "text", + "image" + ], + "context_window": 32000, + "max_output_tokens": 8000, + "source": "https://cloud.tencent.com/document/product/1729/104753" + }, + { + "id": "hunyuan-lite", + "name": "Hunyuan Lite", + "reasoning": false, + "input": [ + "text" + ], + "context_window": 256000, + "max_output_tokens": 6000, + "cost": { + "input": 0, + "output": 0 + }, + "source": "https://cloud.tencent.com/document/product/1729/104753" + }, + { + "id": "hunyuan-embedding", + "name": "Hunyuan Embedding", + "type": "Embedding", + "dimension": 1024, + "source": "https://cloud.tencent.com/document/product/1729/111007" + } + ], + "jina": [ + { + "id": "jina-embeddings-v5-omni-small", + "name": "Jina Embeddings v5 Omni Small (multimodal)", + "type": "Embedding", + "input": [ + "text", + "image" + ], + "dimension": 1024, + "context_window": 32768, + "source": "https://jina.ai/models/" + }, + { + "id": "jina-embeddings-v5-omni-nano", + "name": "Jina Embeddings v5 Omni Nano (multimodal)", + "type": "Embedding", + "input": [ + "text", + "image" + ], + "dimension": 768, + "context_window": 8192, + "source": "https://jina.ai/models/" + }, + { + "id": "jina-embeddings-v5-text-small", + "name": "Jina Embeddings v5 Text Small", + "type": "Embedding", + "dimension": 1024, + "context_window": 32768, + "source": "https://jina.ai/models/" + }, + { + "id": "jina-embeddings-v5-text-nano", + "name": "Jina Embeddings v5 Text Nano", + "type": "Embedding", + "dimension": 768, + "context_window": 8192, + "source": "https://jina.ai/models/" + }, + { + "id": "jina-embeddings-v4", + "name": "Jina Embeddings v4", + "type": "Embedding", + "dimension": 2048, + "context_window": 32768, + "source": "https://jina.ai/models/jina-embeddings-v4/" + }, + { + "id": "jina-embeddings-v3", + "name": "Jina Embeddings v3", + "type": "Embedding", + "dimension": 1024, + "context_window": 8192, + "source": "https://jina.ai/models/jina-embeddings-v3/" + }, + { + "id": "jina-code-embeddings-1.5b", + "name": "Jina Code Embeddings 1.5B", + "type": "Embedding", + "dimension": 1536, + "context_window": 32768, + "source": "https://jina.ai/models/" + }, + { + "id": "jina-code-embeddings-0.5b", + "name": "Jina Code Embeddings 0.5B", + "type": "Embedding", + "dimension": 896, + "context_window": 32768, + "source": "https://jina.ai/models/" + }, + { + "id": "jina-reranker-v3.5", + "name": "Jina Reranker v3.5", + "type": "Rerank", + "context_window": 131072, + "source": "https://jina.ai/reranker/" + }, + { + "id": "jina-reranker-v3", + "name": "Jina Reranker v3", + "type": "Rerank", + "context_window": 131072, + "source": "https://jina.ai/models/jina-reranker-v3/" + }, + { + "id": "jina-reranker-m0", + "name": "Jina Reranker m0 (multimodal)", + "type": "Rerank", + "context_window": 10000, + "source": "https://jina.ai/reranker/" + }, + { + "id": "jina-reranker-v2-base-multilingual", + "name": "Jina Reranker v2 Base Multilingual", + "type": "Rerank", + "context_window": 1024, + "source": "https://jina.ai/reranker/" + } + ], + "litellm": [], + "lkeap": [ + { + "name": "DeepSeek R1 family (always-on reasoning)", + "match": "*deepseek-r1*", + "reasoning": true, + "input": [ + "text" + ], + "source": "https://cloud.tencent.com/document/product/1772/115963", + "thinking_levels": { + "off": null + } + }, + { + "name": "DeepSeek V3 family (thinking switch)", + "match": "*deepseek-v3*", + "reasoning": true, + "input": [ + "text" + ], + "source": "https://cloud.tencent.com/document/product/1772/115963" + }, + { + "id": "deepseek-v3.2", + "name": "DeepSeek V3.2", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 131072, + "max_output_tokens": 32768, + "source": "https://cloud.tencent.com/document/product/1772/115963" + }, + { + "id": "deepseek-v3.1-terminus", + "name": "DeepSeek V3.1 Terminus", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 131072, + "max_output_tokens": 32768, + "source": "https://cloud.tencent.com/document/product/1772/115963" + }, + { + "id": "deepseek-r1-0528", + "name": "DeepSeek R1 (0528)", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 131072, + "max_output_tokens": 16384, + "source": "https://cloud.tencent.com/document/product/1772/115963", + "thinking_levels": { + "off": null + } + }, + { + "id": "deepseek-v3-0324", + "name": "DeepSeek V3 (0324)", + "reasoning": false, + "input": [ + "text" + ], + "context_window": 131072, + "max_output_tokens": 16384, + "source": "https://cloud.tencent.com/document/product/1772/115963" + }, + { + "id": "deepseek-r1", + "name": "DeepSeek R1", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 65536, + "max_output_tokens": 16384, + "source": "https://cloud.tencent.com/document/product/1772/115963", + "thinking_levels": { + "off": null + } + }, + { + "id": "deepseek-v3", + "name": "DeepSeek V3", + "reasoning": false, + "input": [ + "text" + ], + "context_window": 65536, + "max_output_tokens": 16384, + "source": "https://cloud.tencent.com/document/product/1772/115963" + }, + { + "id": "deepseek-v3.1", + "name": "DeepSeek V3.1", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 131072, + "max_output_tokens": 32768, + "source": "https://cloud.tencent.com/document/product/1772/115963" + }, + { + "id": "lke-reranker-base", + "name": "LKE Reranker Base", + "type": "Rerank", + "source": "https://cloud.tencent.com/document/product/1772/115339" + } + ], + "longcat": [ + { + "id": "LongCat-2.0", + "name": "LongCat 2.0", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1000000, + "max_output_tokens": 131072, + "cost": { + "input": 0.75, + "output": 2.95, + "cache_read": 0.015 + }, + "source": "https://longcat.chat/platform/docs/zh/api/chat.html" + }, + { + "id": "LongCat-Flash-Chat", + "name": "LongCat Flash Chat (retired 2026-05-29)", + "deprecated": true, + "reasoning": false, + "input": [ + "text" + ], + "context_window": 262144, + "max_output_tokens": 8192, + "source": "https://longcat.chat/platform/docs/zh/ChangeLog.html" + }, + { + "id": "LongCat-Flash-Thinking", + "name": "LongCat Flash Thinking (retired 2026-05-29)", + "deprecated": true, + "reasoning": true, + "input": [ + "text" + ], + "context_window": 131072, + "max_output_tokens": 65536, + "source": "https://longcat.chat/platform/docs/zh/ChangeLog.html", + "thinking_levels": { + "off": null + } + } + ], + "mimo": [ + { + "id": "mimo-v2.5-pro", + "name": "MiMo V2.5 Pro", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1048576, + "max_output_tokens": 131072, + "cost": { + "input": 0.435, + "output": 0.87, + "cache_read": 0.0036 + }, + "source": "https://mimo.mi.com/static/docs/price/pay-as-you-go.md" + }, + { + "id": "mimo-v2.5", + "name": "MiMo V2.5", + "reasoning": true, + "input": [ + "text", + "image", + "audio", + "video" + ], + "context_window": 1048576, + "max_output_tokens": 131072, + "cost": { + "input": 0.14, + "output": 0.28, + "cache_read": 0.0028 + }, + "source": "https://mimo.mi.com/static/docs/price/pay-as-you-go.md" + }, + { + "id": "mimo-v2.5-pro-ultraspeed", + "name": "MiMo V2.5 Pro Ultraspeed", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1048576, + "max_output_tokens": 131072, + "cost": { + "input": 1.305, + "output": 2.61, + "cache_read": 0.0108 + }, + "source": "https://mimo.mi.com/static/docs/news/latest/beta-extended.md" + }, + { + "id": "mimo-v2-flash", + "name": "MiMo V2 Flash (retired 2026-06-30)", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 256000, + "max_output_tokens": 256000, + "cost": { + "input": 0.1, + "output": 0.3, + "cache_read": 0.01 + }, + "deprecated": true, + "source": "https://mimo.mi.com/static/docs/updates/deprecate.md" + }, + { + "id": "mimo-v2.5-asr", + "name": "MiMo V2.5 ASR", + "type": "ASR", + "source": "https://mimo.mi.com/docs/en-US/quick-start/usage-guide/audio/Speech-Recognition" + } + ], + "minimax": [ + { + "id": "MiniMax-M3", + "name": "MiniMax M3", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 1000000, + "max_output_tokens": 512000, + "cost": { + "input": 0.3, + "output": 1.2, + "cache_read": 0.06 + }, + "source": "https://platform.minimax.io/docs/guides/text-generation" + }, + { + "id": "MiniMax-M2.7", + "name": "MiniMax M2.7", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 204800, + "max_output_tokens": 131072, + "cost": { + "input": 0.3, + "output": 1.2, + "cache_read": 0.06, + "cache_write": 0.375 + }, + "source": "https://platform.minimax.io/docs/api-reference/text-openai-api", + "thinking_levels": { + "off": null + } + }, + { + "id": "MiniMax-M2.7-highspeed", + "name": "MiniMax M2.7 Highspeed", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 204800, + "max_output_tokens": 131072, + "cost": { + "input": 0.6, + "output": 2.4, + "cache_read": 0.06, + "cache_write": 0.375 + }, + "source": "https://platform.minimax.io/docs/api-reference/text-openai-api", + "thinking_levels": { + "off": null + } + }, + { + "id": "MiniMax-M2.5", + "name": "MiniMax M2.5", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 204800, + "max_output_tokens": 131072, + "cost": { + "input": 0.3, + "output": 1.2, + "cache_read": 0.03, + "cache_write": 0.375 + }, + "source": "https://platform.minimax.io/docs/api-reference/text-openai-api", + "thinking_levels": { + "off": null + } + }, + { + "id": "MiniMax-M2.5-highspeed", + "name": "MiniMax M2.5 Highspeed", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 204800, + "max_output_tokens": 131072, + "cost": { + "input": 0.6, + "output": 2.4, + "cache_read": 0.06, + "cache_write": 0.375 + }, + "source": "https://platform.minimax.io/docs/api-reference/text-openai-api", + "thinking_levels": { + "off": null + } + }, + { + "id": "MiniMax-M2.1", + "name": "MiniMax M2.1", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 204800, + "max_output_tokens": 131072, + "cost": { + "input": 0.3, + "output": 1.2, + "cache_read": 0.03, + "cache_write": 0.375 + }, + "source": "https://platform.minimax.io/docs/api-reference/text-openai-api", + "thinking_levels": { + "off": null + } + }, + { + "id": "MiniMax-M2.1-highspeed", + "name": "MiniMax M2.1 Highspeed", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 204800, + "max_output_tokens": 131072, + "source": "https://platform.minimax.io/docs/guides/text-generation", + "thinking_levels": { + "off": null + } + }, + { + "id": "MiniMax-M2", + "name": "MiniMax M2", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 204800, + "max_output_tokens": 131072, + "cost": { + "input": 0.3, + "output": 1.2 + }, + "source": "https://platform.minimax.io/docs/api-reference/text-openai-api", + "thinking_levels": { + "off": null + } + }, + { + "id": "asr-1.0", + "name": "MiniMax ASR 1.0", + "type": "ASR", + "source": "https://platform.minimax.io/docs/api-reference/speech-to-text" + } + ], + "modelscope": [ + { + "id": "ZhipuAI/GLM-4.6", + "name": "GLM-4.6", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 202752, + "max_output_tokens": 98304, + "cost": { + "input": 0, + "output": 0 + }, + "source": "https://modelscope.cn/models/ZhipuAI/GLM-4.6" + }, + { + "id": "ZhipuAI/GLM-4.5", + "name": "GLM-4.5", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 131072, + "max_output_tokens": 98304, + "cost": { + "input": 0, + "output": 0 + }, + "source": "https://modelscope.cn/models/ZhipuAI/GLM-4.5" + }, + { + "id": "Qwen/Qwen3-235B-A22B-Instruct-2507", + "name": "Qwen3 235B-A22B Instruct 2507", + "reasoning": false, + "input": [ + "text" + ], + "context_window": 262144, + "max_output_tokens": 131072, + "cost": { + "input": 0, + "output": 0 + }, + "source": "https://modelscope.cn/models/Qwen/Qwen3-235B-A22B-Instruct-2507" + }, + { + "id": "Qwen/Qwen3-235B-A22B-Thinking-2507", + "name": "Qwen3 235B-A22B Thinking 2507", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 262144, + "max_output_tokens": 131072, + "cost": { + "input": 0, + "output": 0 + }, + "source": "https://modelscope.cn/models/Qwen/Qwen3-235B-A22B-Thinking-2507", + "thinking_levels": { + "off": null + } + }, + { + "id": "Qwen/Qwen3-30B-A3B-Instruct-2507", + "name": "Qwen3 30B-A3B Instruct 2507", + "reasoning": false, + "input": [ + "text" + ], + "context_window": 262144, + "max_output_tokens": 16384, + "cost": { + "input": 0, + "output": 0 + }, + "source": "https://modelscope.cn/models/Qwen/Qwen3-30B-A3B-Instruct-2507" + }, + { + "id": "Qwen/Qwen3-30B-A3B-Thinking-2507", + "name": "Qwen3 30B-A3B Thinking 2507", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 262144, + "max_output_tokens": 32768, + "cost": { + "input": 0, + "output": 0 + }, + "source": "https://modelscope.cn/models/Qwen/Qwen3-30B-A3B-Thinking-2507", + "thinking_levels": { + "off": null + } + }, + { + "id": "Qwen/Qwen3-Coder-30B-A3B-Instruct", + "name": "Qwen3 Coder 30B-A3B Instruct", + "reasoning": false, + "input": [ + "text" + ], + "context_window": 262144, + "max_output_tokens": 65536, + "cost": { + "input": 0, + "output": 0 + }, + "source": "https://modelscope.cn/models/Qwen/Qwen3-Coder-30B-A3B-Instruct" + }, + { + "id": "Qwen/Qwen3-8B", + "name": "Qwen3 8B (hybrid thinking)", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 131072, + "max_output_tokens": 32768, + "cost": { + "input": 0, + "output": 0 + }, + "source": "https://modelscope.cn/models/Qwen/Qwen3-8B" + }, + { + "id": "Qwen/Qwen3-VL-235B-A22B-Instruct", + "name": "Qwen3 VL 235B-A22B Instruct", + "reasoning": false, + "input": [ + "text", + "image" + ], + "context_window": 262144, + "max_output_tokens": 32768, + "cost": { + "input": 0, + "output": 0 + }, + "source": "https://modelscope.cn/models/Qwen/Qwen3-VL-235B-A22B-Instruct" + }, + { + "id": "Qwen/Qwen3-Embedding-8B", + "name": "Qwen3 Embedding 8B", + "type": "Embedding", + "dimension": 4096, + "source": "https://modelscope.cn/models/Qwen/Qwen3-Embedding-8B" + }, + { + "id": "Qwen/Qwen3-Embedding-0.6B", + "name": "Qwen3 Embedding 0.6B", + "type": "Embedding", + "dimension": 1024, + "source": "https://modelscope.cn/models/Qwen/Qwen3-Embedding-0.6B" + } + ], + "moonshot": [ + { + "id": "kimi-k3", + "name": "Kimi K3", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 1048576, + "max_output_tokens": 131072, + "cost": { + "input": 3, + "output": 15, + "cache_read": 0.3 + }, + "source": "https://platform.kimi.com/docs/guide/kimi-k3-quickstart", + "compat": { + "thinking_format": "openai", + "supports_reasoning_effort": true, + "supports_temperature": false, + "tool_choice_modes": [ + "none", + "auto", + "required" + ] + }, + "thinking_levels": { + "off": null, + "minimal": "low", + "low": "low", + "medium": "high", + "high": "high", + "xhigh": "max", + "max": "max" + } + }, + { + "id": "kimi-k2.7-code", + "name": "Kimi K2.7 Code", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 262144, + "max_output_tokens": 262144, + "cost": { + "input": 0.95, + "output": 4, + "cache_read": 0.19 + }, + "source": "https://platform.kimi.com/docs/guide/kimi-k2-7-code-quickstart", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": null + } + }, + { + "id": "kimi-k2.7-code-highspeed", + "name": "Kimi K2.7 Code Highspeed", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 262144, + "max_output_tokens": 262144, + "cost": { + "input": 1.9, + "output": 8, + "cache_read": 0.38 + }, + "source": "https://platform.kimi.com/docs/guide/kimi-k2-7-code-quickstart", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": null + } + }, + { + "id": "kimi-k2.6", + "name": "Kimi K2.6", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 262144, + "max_output_tokens": 262144, + "cost": { + "input": 0.95, + "output": 4, + "cache_read": 0.16 + }, + "source": "https://platform.kimi.com/docs/guide/kimi-k2-6-quickstart", + "compat": { + "supports_temperature": false + } + }, + { + "name": "moonshot-v1 family (retired 2026-08-31)", + "match": "moonshot-v1*", + "reasoning": false, + "input": [ + "text" + ], + "deprecated": true, + "source": "https://platform.kimi.com/docs/models", + "compat": { + "fixed_temperature": 1 + } + }, + { + "id": "kimi-k2.5", + "name": "Kimi K2.5 (retired 2026-08-31)", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 262144, + "max_output_tokens": 262144, + "cost": { + "input": 0.6, + "output": 3, + "cache_read": 0.1 + }, + "deprecated": true, + "source": "https://platform.kimi.com/docs/models", + "compat": { + "supports_temperature": false + } + }, + { + "id": "kimi-k2-thinking", + "name": "Kimi K2 Thinking (retired 2026-08-31)", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 262144, + "max_output_tokens": 16384, + "cost": { + "input": 0.574, + "output": 2.294 + }, + "deprecated": true, + "source": "https://platform.kimi.com/docs/models", + "thinking_levels": { + "off": null + } + }, + { + "id": "kimi-k2-turbo-preview", + "name": "Kimi K2 Turbo (retired 2026-08-31)", + "reasoning": false, + "input": [ + "text" + ], + "context_window": 262144, + "max_output_tokens": 16384, + "deprecated": true, + "source": "https://platform.kimi.com/docs/models" + }, + { + "id": "moonshot-v1-8k", + "name": "Moonshot v1 8K (retired 2026-08-31)", + "reasoning": false, + "input": [ + "text" + ], + "context_window": 8192, + "max_output_tokens": 8192, + "deprecated": true, + "source": "https://platform.kimi.com/docs/models", + "compat": { + "fixed_temperature": 1 + } + }, + { + "id": "moonshot-v1-32k", + "name": "Moonshot v1 32K (retired 2026-08-31)", + "reasoning": false, + "input": [ + "text" + ], + "context_window": 32768, + "max_output_tokens": 32768, + "deprecated": true, + "source": "https://platform.kimi.com/docs/models", + "compat": { + "fixed_temperature": 1 + } + }, + { + "id": "moonshot-v1-128k", + "name": "Moonshot v1 128K (retired 2026-08-31)", + "reasoning": false, + "input": [ + "text" + ], + "context_window": 131072, + "max_output_tokens": 131072, + "deprecated": true, + "source": "https://platform.kimi.com/docs/models", + "compat": { + "fixed_temperature": 1 + } + }, + { + "id": "moonshot-v1-8k-vision-preview", + "name": "Moonshot v1 8K Vision (retired 2026-08-31)", + "reasoning": false, + "input": [ + "text", + "image" + ], + "context_window": 8192, + "max_output_tokens": 8192, + "deprecated": true, + "source": "https://platform.kimi.com/docs/models", + "compat": { + "fixed_temperature": 1 + } + } + ], + "novita": [ + { + "id": "moonshotai/kimi-k3", + "name": "Kimi K3", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 1048576, + "max_output_tokens": 1048576, + "cost": { + "input": 3, + "output": 15, + "cache_read": 0.3 + }, + "source": "https://docs.novita.ai/api-reference/model-apis-llm-chat-completions-api" + }, + { + "id": "zai-org/glm-5.2", + "name": "GLM-5.2", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1048576, + "max_output_tokens": 131072, + "cost": { + "input": 1.4, + "output": 4.4, + "cache_read": 0.26 + }, + "source": "https://docs.novita.ai/api-reference/model-apis-llm-chat-completions-api" + }, + { + "id": "zai-org/glm-5.1", + "name": "GLM-5.1", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 204800, + "max_output_tokens": 131072, + "cost": { + "input": 1.38, + "output": 4.4, + "cache_read": 0.26 + }, + "source": "https://docs.novita.ai/api-reference/model-apis-llm-chat-completions-api" + }, + { + "id": "deepseek/deepseek-v4-pro", + "name": "DeepSeek V4 Pro", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1048576, + "max_output_tokens": 393216, + "cost": { + "input": 1.6, + "output": 3.2, + "cache_read": 0.135 + }, + "source": "https://docs.novita.ai/api-reference/model-apis-llm-chat-completions-api" + }, + { + "id": "deepseek/deepseek-v4-flash", + "name": "DeepSeek V4 Flash", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1048576, + "max_output_tokens": 393216, + "cost": { + "input": 0.14, + "output": 0.28, + "cache_read": 0.028 + }, + "source": "https://docs.novita.ai/api-reference/model-apis-llm-chat-completions-api" + }, + { + "id": "moonshotai/kimi-k2.6", + "name": "Kimi K2.6", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 262144, + "max_output_tokens": 262144, + "cost": { + "input": 0.8, + "output": 3.4, + "cache_read": 0.16 + }, + "source": "https://docs.novita.ai/api-reference/model-apis-llm-chat-completions-api" + }, + { + "id": "moonshotai/kimi-k2.7-code", + "name": "Kimi K2.7 Code", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 262144, + "max_output_tokens": 262144, + "cost": { + "input": 0.95, + "output": 4, + "cache_read": 0.19 + }, + "source": "https://docs.novita.ai/api-reference/model-apis-llm-chat-completions-api" + }, + { + "id": "qwen/qwen3.7-max", + "name": "Qwen3.7 Max", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1000000, + "max_output_tokens": 65536, + "cost": { + "input": 1.25, + "output": 3.75, + "cache_read": 0.25, + "cache_write": 1.5625 + }, + "source": "https://docs.novita.ai/api-reference/model-apis-llm-chat-completions-api" + }, + { + "id": "qwen/qwen3.5-397b-a17b", + "name": "Qwen3.5 397B-A17B", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 262144, + "max_output_tokens": 65536, + "cost": { + "input": 0.6, + "output": 3.6 + }, + "source": "https://docs.novita.ai/api-reference/model-apis-llm-chat-completions-api" + }, + { + "id": "minimax/minimax-m2.7", + "name": "MiniMax M2.7", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 204800, + "max_output_tokens": 131072, + "cost": { + "input": 0.3, + "output": 1.2, + "cache_read": 0.06 + }, + "source": "https://docs.novita.ai/api-reference/model-apis-llm-chat-completions-api", + "thinking_levels": { + "off": null + } + }, + { + "id": "xiaomimimo/mimo-v2.5-pro", + "name": "MiMo V2.5 Pro", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1048576, + "max_output_tokens": 131072, + "cost": { + "input": 0.522, + "output": 1.044, + "cache_read": 0.0043 + }, + "source": "https://docs.novita.ai/api-reference/model-apis-llm-chat-completions-api", + "thinking_levels": { + "off": null + } + }, + { + "id": "google/gemma-4-31b-it", + "name": "Gemma 4 31B IT", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 262144, + "max_output_tokens": 131072, + "cost": { + "input": 0.14, + "output": 0.4 + }, + "source": "https://docs.novita.ai/api-reference/model-apis-llm-chat-completions-api" + }, + { + "id": "qwen/qwen3-embedding-0.6b", + "name": "Qwen3 Embedding 0.6B", + "type": "Embedding", + "dimension": 1024, + "context_window": 32768, + "source": "https://docs.novita.ai/api-reference/model-apis-llm-chat-completions-api" + }, + { + "id": "qwen/qwen3-embedding-8b", + "name": "Qwen3 Embedding 8B", + "type": "Embedding", + "dimension": 4096, + "context_window": 32768, + "source": "https://docs.novita.ai/api-reference/model-apis-llm-chat-completions-api" + }, + { + "id": "baai/bge-m3", + "name": "BGE-M3", + "type": "Embedding", + "dimension": 1024, + "context_window": 8192, + "source": "https://docs.novita.ai/api-reference/model-apis-llm-chat-completions-api" + } + ], + "nvidia": [ + { + "id": "nvidia/nemotron-3-ultra-550b-a55b", + "name": "Nemotron 3 Ultra 550B-A55B", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1000000, + "max_output_tokens": 65536, + "cost": { + "input": 0.5, + "output": 2.5, + "cache_read": 0.15 + }, + "source": "https://build.nvidia.com" + }, + { + "id": "nvidia/nemotron-3-super-120b-a12b", + "name": "Nemotron 3 Super 120B-A12B", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1000000, + "max_output_tokens": 262144, + "cost": { + "input": 0.2, + "output": 0.8 + }, + "source": "https://build.nvidia.com" + }, + { + "id": "nvidia/nemotron-3.5-lightning-30b-a3b", + "name": "Nemotron 3.5 Lightning 30B-A3B", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 262144, + "max_output_tokens": 262144, + "cost": { + "input": 0, + "output": 0 + }, + "source": "https://build.nvidia.com" + }, + { + "id": "z-ai/glm-5.3", + "name": "GLM-5.3", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1000000, + "max_output_tokens": 131072, + "cost": { + "input": 0, + "output": 0 + }, + "source": "https://build.nvidia.com", + "compat": { + "thinking_format": "openai", + "supports_reasoning_effort": true + }, + "thinking_levels": { + "off": null, + "minimal": "low", + "medium": "high", + "xhigh": "max", + "max": "max" + } + }, + { + "id": "deepseek-ai/deepseek-v4-pro-0813", + "name": "DeepSeek V4 Pro", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1048576, + "max_output_tokens": 393216, + "cost": { + "input": 0.435, + "output": 0.87, + "cache_read": 0.003625 + }, + "source": "https://build.nvidia.com" + }, + { + "id": "deepseek-ai/deepseek-v4-flash-0731", + "name": "DeepSeek V4 Flash", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1048576, + "max_output_tokens": 393216, + "cost": { + "input": 0.14, + "output": 0.28, + "cache_read": 0.0028 + }, + "source": "https://build.nvidia.com" + }, + { + "id": "moonshotai/kimi-k3", + "name": "Kimi K3", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 1048576, + "max_output_tokens": 131072, + "cost": { + "input": 0, + "output": 0 + }, + "source": "https://build.nvidia.com", + "compat": { + "max_tokens_field": "max_completion_tokens", + "thinking_format": "openai", + "supports_reasoning_effort": true + }, + "thinking_levels": { + "off": null, + "minimal": "low", + "medium": "high", + "xhigh": "max", + "max": "max" + } + }, + { + "id": "moonshotai/kimi-k2.6", + "name": "Kimi K2.6", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 262144, + "max_output_tokens": 262144, + "cost": { + "input": 0, + "output": 0 + }, + "source": "https://build.nvidia.com" + }, + { + "id": "google/gemma-4-31b-it", + "name": "Gemma 4 31B IT", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 256000, + "max_output_tokens": 16384, + "cost": { + "input": 0, + "output": 0 + }, + "source": "https://build.nvidia.com", + "compat": { + "max_tokens_field": "max_completion_tokens", + "thinking_format": "none" + } + }, + { + "id": "nvidia/nemotron-3-embed-1b", + "name": "Nemotron 3 Embed 1B", + "type": "Embedding", + "dimension": 2048, + "context_window": 4096, + "source": "https://docs.api.nvidia.com/nim/reference/nvidia-nemotron-3-embed-1b-infer" + }, + { + "id": "nvidia/llama-nemotron-rerank-vl-1b-v2", + "name": "Llama Nemotron Rerank VL 1B v2", + "type": "Rerank", + "source": "https://build.nvidia.com" + }, + { + "id": "nvidia/nv-rerankqa-mistral-4b-v3", + "name": "NV-RerankQA Mistral 4B v3", + "type": "Rerank", + "source": "https://build.nvidia.com" + } + ], + "openai": [ + { + "name": "GPT-6 family (reasoning, no sampling parameters, thinking always on)", + "match": "gpt-6*", + "reasoning": true, + "input": [ + "text", + "image" + ], + "source": "https://developers.openai.com/api/docs/guides/latest-model", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": null, + "minimal": "low", + "xhigh": "xhigh", + "max": "max" + } + }, + { + "name": "GPT-5 family (reasoning, no sampling parameters)", + "match": "gpt-5*", + "reasoning": true, + "input": [ + "text", + "image" + ], + "source": "https://developers.openai.com/api/docs/guides/reasoning", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": "none", + "minimal": "low" + } + }, + { + "name": "o1 family (always-on reasoning)", + "match": "o1*", + "reasoning": true, + "input": [ + "text", + "image" + ], + "source": "https://developers.openai.com/api/docs/models", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": null, + "minimal": "low", + "xhigh": "high", + "max": "high" + } + }, + { + "name": "o3 family (always-on reasoning)", + "match": "o3*", + "reasoning": true, + "input": [ + "text", + "image" + ], + "source": "https://developers.openai.com/api/docs/models", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": null, + "minimal": "low", + "xhigh": "high", + "max": "high" + } + }, + { + "name": "o4 family (always-on reasoning)", + "match": "o4*", + "reasoning": true, + "input": [ + "text", + "image" + ], + "source": "https://developers.openai.com/api/docs/models", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": null, + "minimal": "low", + "xhigh": "high", + "max": "high" + } + }, + { + "id": "gpt-6-astra", + "name": "GPT-6 Astra", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 1050000, + "max_output_tokens": 128000, + "cost": { + "input": 10, + "output": 50, + "cache_read": 1, + "cache_write": 12.5 + }, + "source": "https://developers.openai.com/api/docs/models", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": null, + "minimal": "low", + "xhigh": "xhigh", + "max": "max" + } + }, + { + "id": "gpt-5.6-terra", + "name": "GPT-5.6 Terra", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 1050000, + "max_output_tokens": 128000, + "cost": { + "input": 2, + "output": 12, + "cache_read": 0.2, + "cache_write": 2.5 + }, + "source": "https://developers.openai.com/api/docs/models", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": "none", + "minimal": "low", + "xhigh": "xhigh", + "max": "max" + } + }, + { + "id": "gpt-5.6-sol", + "name": "GPT-5.6 Sol", + "aliases": [ + "gpt-5.6" + ], + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 1050000, + "max_output_tokens": 128000, + "cost": { + "input": 4, + "output": 20, + "cache_read": 0.4, + "cache_write": 5 + }, + "source": "https://developers.openai.com/api/docs/models", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": "none", + "minimal": "low", + "xhigh": "xhigh", + "max": "max" + } + }, + { + "id": "gpt-5.6-luna", + "name": "GPT-5.6 Luna", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 1050000, + "max_output_tokens": 128000, + "cost": { + "input": 0.2, + "output": 1.2, + "cache_read": 0.02, + "cache_write": 0.25 + }, + "source": "https://developers.openai.com/api/docs/models", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": "none", + "minimal": "low", + "xhigh": "xhigh", + "max": "max" + } + }, + { + "id": "gpt-5.5", + "name": "GPT-5.5", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 1050000, + "max_output_tokens": 128000, + "cost": { + "input": 5, + "output": 30, + "cache_read": 0.5 + }, + "source": "https://developers.openai.com/api/docs/models", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": "none", + "minimal": "low", + "xhigh": "xhigh", + "max": "xhigh" + } + }, + { + "id": "gpt-5.4", + "name": "GPT-5.4", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 1050000, + "max_output_tokens": 128000, + "cost": { + "input": 2.5, + "output": 15, + "cache_read": 0.25 + }, + "source": "https://developers.openai.com/api/docs/models", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": "none", + "minimal": "low", + "xhigh": "xhigh", + "max": "xhigh" + } + }, + { + "id": "gpt-5.4-mini", + "name": "GPT-5.4 Mini", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 400000, + "max_output_tokens": 128000, + "cost": { + "input": 0.75, + "output": 4.5, + "cache_read": 0.075 + }, + "source": "https://developers.openai.com/api/docs/models", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": "none", + "minimal": "low", + "xhigh": "xhigh", + "max": "xhigh" + } + }, + { + "id": "gpt-5.4-nano", + "name": "GPT-5.4 Nano", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 400000, + "max_output_tokens": 128000, + "cost": { + "input": 0.2, + "output": 1.25, + "cache_read": 0.02 + }, + "source": "https://developers.openai.com/api/docs/models", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": "none", + "minimal": "low", + "xhigh": "xhigh", + "max": "xhigh" + } + }, + { + "id": "gpt-5.2", + "name": "GPT-5.2", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 400000, + "max_output_tokens": 128000, + "cost": { + "input": 1.75, + "output": 14, + "cache_read": 0.175 + }, + "source": "https://developers.openai.com/api/docs/models", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": "none", + "minimal": "low", + "xhigh": "xhigh", + "max": "xhigh" + } + }, + { + "id": "gpt-5.1", + "name": "GPT-5.1", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 400000, + "max_output_tokens": 128000, + "cost": { + "input": 1.25, + "output": 10, + "cache_read": 0.125 + }, + "source": "https://developers.openai.com/api/docs/models", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": "none", + "minimal": "low", + "xhigh": "high", + "max": "high" + } + }, + { + "id": "gpt-5", + "name": "GPT-5", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 400000, + "max_output_tokens": 128000, + "cost": { + "input": 1.25, + "output": 10, + "cache_read": 0.125 + }, + "source": "https://developers.openai.com/api/docs/models", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": null, + "xhigh": "high", + "max": "high" + } + }, + { + "id": "gpt-5-mini", + "name": "GPT-5 Mini", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 400000, + "max_output_tokens": 128000, + "cost": { + "input": 0.25, + "output": 2, + "cache_read": 0.025 + }, + "source": "https://developers.openai.com/api/docs/models", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": null, + "xhigh": "high", + "max": "high" + } + }, + { + "id": "gpt-5-nano", + "name": "GPT-5 Nano", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 400000, + "max_output_tokens": 128000, + "cost": { + "input": 0.05, + "output": 0.4, + "cache_read": 0.005 + }, + "source": "https://developers.openai.com/api/docs/models", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": null, + "xhigh": "high", + "max": "high" + } + }, + { + "id": "o3", + "name": "o3", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 200000, + "max_output_tokens": 100000, + "cost": { + "input": 2, + "output": 8, + "cache_read": 0.5 + }, + "source": "https://developers.openai.com/api/docs/models", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": null, + "minimal": "low", + "xhigh": "high", + "max": "high" + } + }, + { + "id": "gpt-4.1", + "name": "GPT-4.1", + "reasoning": false, + "input": [ + "text", + "image" + ], + "context_window": 1047576, + "max_output_tokens": 32768, + "cost": { + "input": 2, + "output": 8, + "cache_read": 0.5 + }, + "source": "https://developers.openai.com/api/docs/models" + }, + { + "id": "gpt-4.1-mini", + "name": "GPT-4.1 Mini", + "reasoning": false, + "input": [ + "text", + "image" + ], + "context_window": 1047576, + "max_output_tokens": 32768, + "cost": { + "input": 0.4, + "output": 1.6, + "cache_read": 0.1 + }, + "source": "https://developers.openai.com/api/docs/models" + }, + { + "id": "gpt-4o", + "name": "GPT-4o", + "aliases": [ + "gpt-4o-2024-11-20", + "gpt-4o-2024-08-06" + ], + "reasoning": false, + "input": [ + "text", + "image" + ], + "context_window": 128000, + "max_output_tokens": 16384, + "cost": { + "input": 2.5, + "output": 10, + "cache_read": 1.25 + }, + "source": "https://developers.openai.com/api/docs/models" + }, + { + "id": "gpt-4o-mini", + "name": "GPT-4o Mini", + "reasoning": false, + "input": [ + "text", + "image" + ], + "context_window": 128000, + "max_output_tokens": 16384, + "cost": { + "input": 0.15, + "output": 0.6, + "cache_read": 0.075 + }, + "source": "https://developers.openai.com/api/docs/models" + }, + { + "id": "text-embedding-3-small", + "name": "text-embedding-3-small", + "type": "Embedding", + "dimension": 1536, + "context_window": 8191, + "cost": { + "input": 0.02, + "output": 0 + }, + "source": "https://developers.openai.com/api/docs/models" + }, + { + "id": "text-embedding-3-large", + "name": "text-embedding-3-large", + "type": "Embedding", + "dimension": 3072, + "context_window": 8191, + "cost": { + "input": 0.13, + "output": 0 + }, + "source": "https://developers.openai.com/api/docs/models" + }, + { + "id": "whisper-1", + "name": "Whisper", + "type": "ASR", + "source": "https://developers.openai.com/api/reference/resources/audio/subresources/transcriptions/methods/create", + "compat": { + "response_format": "verbose_json" + } + }, + { + "id": "gpt-transcribe", + "name": "GPT Transcribe", + "type": "ASR", + "source": "https://developers.openai.com/api/reference/resources/audio/subresources/transcriptions/methods/create" + }, + { + "id": "gpt-4o-transcribe", + "name": "GPT-4o Transcribe", + "type": "ASR", + "source": "https://developers.openai.com/api/reference/resources/audio/subresources/transcriptions/methods/create" + }, + { + "id": "gpt-4o-mini-transcribe", + "name": "GPT-4o mini Transcribe", + "type": "ASR", + "source": "https://developers.openai.com/api/reference/resources/audio/subresources/transcriptions/methods/create" + }, + { + "id": "text-embedding-ada-002", + "name": "text-embedding-ada-002", + "type": "Embedding", + "dimension": 1536, + "context_window": 8192, + "cost": { + "input": 0.1, + "output": 0 + }, + "source": "https://developers.openai.com/api/docs/models", + "compat": { + "dimensions_field": "" + } + } + ], + "openrouter": [ + { + "name": "Anthropic models (cache_control breakpoints, thinking always on)", + "match": "anthropic/*", + "reasoning": true, + "input": [ + "text", + "image" + ], + "source": "https://openrouter.ai/docs/guides/best-practices/reasoning-tokens", + "compat": { + "cache_control_format": "anthropic" + }, + "thinking_levels": { + "off": null, + "minimal": "low", + "xhigh": "xhigh", + "max": "max" + } + }, + { + "id": "openai/gpt-5.5", + "name": "GPT-5.5", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 1050000, + "max_output_tokens": 128000, + "cost": { + "input": 5, + "output": 30, + "cache_read": 0.5 + }, + "source": "https://openrouter.ai/docs/guides/best-practices/reasoning-tokens", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": "none", + "minimal": "low", + "xhigh": "xhigh", + "max": "xhigh" + } + }, + { + "id": "openai/gpt-5.4", + "name": "GPT-5.4", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 1050000, + "max_output_tokens": 128000, + "cost": { + "input": 2.5, + "output": 15, + "cache_read": 0.25 + }, + "source": "https://openrouter.ai/docs/guides/best-practices/reasoning-tokens", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": "none", + "minimal": "low", + "xhigh": "xhigh", + "max": "xhigh" + } + }, + { + "id": "anthropic/claude-opus-5", + "name": "Claude Opus 5", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 1000000, + "max_output_tokens": 128000, + "cost": { + "input": 5, + "output": 25, + "cache_read": 0.5, + "cache_write": 6.25 + }, + "source": "https://openrouter.ai/docs/guides/best-practices/reasoning-tokens", + "compat": { + "cache_control_format": "anthropic" + }, + "thinking_levels": { + "off": null, + "minimal": "low", + "xhigh": "xhigh", + "max": "max" + } + }, + { + "id": "anthropic/claude-sonnet-5", + "name": "Claude Sonnet 5", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 1000000, + "max_output_tokens": 128000, + "cost": { + "input": 2, + "output": 10, + "cache_read": 0.2, + "cache_write": 2.5 + }, + "source": "https://openrouter.ai/docs/guides/best-practices/reasoning-tokens", + "compat": { + "cache_control_format": "anthropic" + }, + "thinking_levels": { + "off": null, + "minimal": "low", + "xhigh": "xhigh", + "max": "max" + } + }, + { + "id": "anthropic/claude-sonnet-4.6", + "name": "Claude Sonnet 4.6", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 1000000, + "max_output_tokens": 128000, + "cost": { + "input": 3, + "output": 15, + "cache_read": 0.3, + "cache_write": 3.75 + }, + "source": "https://openrouter.ai/docs/guides/best-practices/reasoning-tokens", + "compat": { + "cache_control_format": "anthropic" + }, + "thinking_levels": { + "off": null, + "minimal": "low", + "xhigh": "max", + "max": "max" + } + }, + { + "id": "google/gemini-3.8-flash", + "name": "Gemini 3.8 Flash", + "reasoning": true, + "input": [ + "text", + "image", + "audio", + "video" + ], + "context_window": 1048576, + "max_output_tokens": 65536, + "cost": { + "input": 0.75, + "output": 3.75, + "cache_read": 0.075, + "cache_write": 0.041667 + }, + "source": "https://openrouter.ai/docs/guides/best-practices/reasoning-tokens", + "thinking_levels": { + "off": null, + "minimal": "low", + "xhigh": "high", + "max": "high" + } + }, + { + "id": "google/gemini-3.1-pro-preview", + "name": "Gemini 3.1 Pro Preview", + "reasoning": true, + "input": [ + "text", + "image", + "audio", + "video" + ], + "context_window": 1048576, + "max_output_tokens": 65536, + "cost": { + "input": 2, + "output": 12, + "cache_read": 0.2, + "cache_write": 0.375 + }, + "source": "https://openrouter.ai/docs/guides/best-practices/reasoning-tokens", + "thinking_levels": { + "off": null, + "minimal": "low", + "xhigh": "high", + "max": "high" + } + }, + { + "id": "deepseek/deepseek-v4-pro", + "name": "DeepSeek V4 Pro", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1048576, + "max_output_tokens": 384000, + "cost": { + "input": 1.6, + "output": 3.2, + "cache_read": 0.135 + }, + "source": "https://openrouter.ai/docs/guides/best-practices/reasoning-tokens", + "thinking_levels": { + "minimal": "high", + "low": "high", + "medium": "high", + "high": "high", + "xhigh": "xhigh", + "max": "xhigh" + } + }, + { + "id": "deepseek/deepseek-v4-flash", + "name": "DeepSeek V4 Flash", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1048576, + "max_output_tokens": 384000, + "cost": { + "input": 0.07, + "output": 0.14, + "cache_read": 0.014 + }, + "source": "https://openrouter.ai/docs/guides/best-practices/reasoning-tokens", + "thinking_levels": { + "minimal": "high", + "low": "high", + "medium": "high", + "high": "high", + "xhigh": "xhigh", + "max": "xhigh" + } + }, + { + "id": "z-ai/glm-5.3", + "name": "GLM-5.3", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1310720, + "max_output_tokens": 131072, + "cost": { + "input": 1.4, + "output": 4.4, + "cache_read": 0.26 + }, + "source": "https://openrouter.ai/docs/guides/best-practices/reasoning-tokens", + "thinking_levels": { + "off": null, + "minimal": "low", + "medium": "high", + "xhigh": "max", + "max": "max" + } + }, + { + "id": "moonshotai/kimi-k3", + "name": "Kimi K3", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 1048576, + "max_output_tokens": 943718, + "cost": { + "input": 3, + "output": 15, + "cache_read": 0.3 + }, + "source": "https://openrouter.ai/docs/guides/best-practices/reasoning-tokens", + "thinking_levels": { + "minimal": "low", + "medium": "high", + "xhigh": "max", + "max": "max" + } + }, + { + "id": "qwen/qwen3.7-max", + "name": "Qwen3.7 Max", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1000000, + "max_output_tokens": 131072, + "cost": { + "input": 1.475, + "output": 4.425, + "cache_read": 0.295, + "cache_write": 1.84375 + }, + "source": "https://openrouter.ai/docs/guides/best-practices/reasoning-tokens" + }, + { + "id": "minimax/minimax-m3", + "name": "MiniMax M3", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 1048576, + "max_output_tokens": 512000, + "cost": { + "input": 0.3, + "output": 1.2, + "cache_read": 0.06 + }, + "source": "https://openrouter.ai/docs/guides/best-practices/reasoning-tokens" + }, + { + "id": "x-ai/grok-4.6", + "name": "Grok 4.6", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 500000, + "max_output_tokens": 450000, + "cost": { + "input": 2, + "output": 6, + "cache_read": 0.5 + }, + "source": "https://openrouter.ai/docs/guides/best-practices/reasoning-tokens", + "thinking_levels": { + "off": null, + "minimal": "low", + "xhigh": "xhigh", + "max": "xhigh" + } + }, + { + "id": "openai/text-embedding-3-small", + "name": "text-embedding-3-small", + "type": "Embedding", + "dimension": 1536, + "context_window": 8192, + "source": "https://openrouter.ai/docs/api_reference/embeddings" + }, + { + "id": "openai/text-embedding-3-large", + "name": "text-embedding-3-large", + "type": "Embedding", + "dimension": 3072, + "context_window": 8192, + "source": "https://openrouter.ai/docs/api_reference/embeddings" + }, + { + "id": "cohere/rerank-v3.5", + "name": "Cohere Rerank v3.5", + "type": "Rerank", + "source": "https://openrouter.ai/docs/api/api-reference/rerank/submit-a-rerank-request" + }, + { + "id": "openai/whisper-large-v3", + "name": "Whisper Large v3", + "type": "ASR", + "source": "https://openrouter.ai/docs/api/api-reference/stt/create-transcription" + } + ], + "qianfan": [ + { + "id": "ernie-5.0-thinking-preview", + "name": "ERNIE 5.0 Thinking Preview", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 128000, + "max_output_tokens": 65536, + "source": "https://cloud.baidu.com/doc/qianfan-docs/s/Wm95lyynv" + }, + { + "id": "ernie-4.5-turbo-128k", + "name": "ERNIE 4.5 Turbo 128K", + "reasoning": false, + "input": [ + "text" + ], + "context_window": 128000, + "max_output_tokens": 12288, + "source": "https://cloud.baidu.com/doc/qianfan-docs/s/7m95lyy43" + }, + { + "id": "ernie-4.5-turbo-vl-32k", + "name": "ERNIE 4.5 Turbo VL 32K", + "reasoning": false, + "input": [ + "text", + "image" + ], + "context_window": 32000, + "max_output_tokens": 12288, + "source": "https://cloud.baidu.com/doc/qianfan-docs/s/7m95lyy43" + }, + { + "id": "ernie-x1-turbo-32k", + "name": "ERNIE X1 Turbo 32K", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 32000, + "max_output_tokens": 16000, + "source": "https://cloud.baidu.com/doc/qianfan-docs/s/7m95lyy43", + "thinking_levels": { + "off": null + } + }, + { + "id": "deepseek-v3.2", + "name": "DeepSeek V3.2 (Qianfan)", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 128000, + "max_output_tokens": 32000, + "source": "https://cloud.baidu.com/doc/qianfan-docs/s/Wm95lyynv", + "compat": { + "thinking_format": "thinking-type" + } + }, + { + "id": "embedding-v1", + "name": "Embedding-V1", + "type": "Embedding", + "dimension": 384, + "source": "https://cloud.baidu.com/doc/qianfan-api/s/Fm7u3ropn" + }, + { + "id": "bge-large-zh", + "name": "BGE Large ZH", + "type": "Embedding", + "dimension": 1024, + "source": "https://cloud.baidu.com/doc/qianfan-api/s/Fm7u3ropn" + }, + { + "id": "tao-8k", + "name": "Tao-8K", + "type": "Embedding", + "dimension": 1024, + "source": "https://cloud.baidu.com/doc/qianfan/s/rmh4stp0j", + "compat": { + "max_batch_size": 1 + } + }, + { + "id": "bce-reranker-base", + "name": "BCE Reranker Base", + "type": "Rerank", + "source": "https://cloud.baidu.com/doc/qianfan-docs/s/7m95lyy43" + } + ], + "qiniu": [ + { + "id": "qwen3.5-397b-a17b", + "name": "Qwen3.5 397B-A17B", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 256000, + "max_output_tokens": 64000, + "source": "https://www.qiniu.com/ai/models" + }, + { + "id": "z-ai/glm-5", + "name": "GLM-5", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 200000, + "max_output_tokens": 128000, + "source": "https://www.qiniu.com/ai/models" + }, + { + "id": "z-ai/glm-4.7", + "name": "GLM-4.7", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 200000, + "max_output_tokens": 200000, + "source": "https://api.qnaigc.com/v1/market/models" + }, + { + "id": "minimax/minimax-m2.5", + "name": "MiniMax M2.5", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 204800, + "max_output_tokens": 128000, + "source": "https://www.qiniu.com/ai/models" + }, + { + "id": "doubao-seed-2.0-pro", + "name": "Doubao Seed 2.0 Pro", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 256000, + "max_output_tokens": 128000, + "source": "https://www.qiniu.com/ai/models" + }, + { + "id": "moonshotai/kimi-k2.5", + "name": "Kimi K2.5", + "reasoning": false, + "input": [ + "text", + "image", + "video" + ], + "context_window": 256000, + "max_output_tokens": 256000, + "source": "https://www.qiniu.com/ai/models" + }, + { + "id": "xiaomi/mimo-v2-flash", + "name": "MiMo V2 Flash", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 256000, + "max_output_tokens": 256000, + "cost": { + "input": 0.1, + "output": 0.3, + "cache_read": 0.01 + }, + "source": "https://www.qiniu.com/ai/models" + }, + { + "id": "deepseek/deepseek-v3.2-251201", + "name": "DeepSeek V3.2 (251201)", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 128000, + "max_output_tokens": 32000, + "source": "https://apidocs.qnaigc.com/397639742e0" + }, + { + "id": "deepseek-r1", + "name": "DeepSeek R1", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 128000, + "max_output_tokens": 32000, + "source": "https://api.qnaigc.com/v1/market/models", + "thinking_levels": { + "off": null + } + }, + { + "id": "deepseek-v3", + "name": "DeepSeek V3", + "reasoning": false, + "input": [ + "text" + ], + "context_window": 128000, + "max_output_tokens": 16000, + "source": "https://www.qiniu.com/ai/models" + } + ], + "requesty": [ + { + "id": "openai/gpt-6-astra", + "name": "GPT-6 Astra", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 1050000, + "max_output_tokens": 128000, + "source": "https://docs.requesty.ai/frameworks/openai", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": null, + "minimal": "min", + "xhigh": "xhigh", + "max": "xhigh" + } + }, + { + "id": "openai/gpt-5.5", + "name": "GPT-5.5", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 1050000, + "max_output_tokens": 128000, + "source": "https://docs.requesty.ai/frameworks/openai", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": "none", + "minimal": "min", + "xhigh": "xhigh", + "max": "xhigh" + } + }, + { + "id": "openai/gpt-5.4", + "name": "GPT-5.4", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 1050000, + "max_output_tokens": 128000, + "source": "https://docs.requesty.ai/frameworks/openai", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": "none", + "minimal": "min", + "xhigh": "xhigh", + "max": "xhigh" + } + }, + { + "id": "anthropic/claude-opus-5", + "name": "Claude Opus 5", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 1000000, + "max_output_tokens": 128000, + "source": "https://docs.requesty.ai/frameworks/openai", + "thinking_levels": { + "off": null, + "minimal": "low", + "xhigh": "xhigh", + "max": "max" + } + }, + { + "id": "anthropic/claude-sonnet-5", + "name": "Claude Sonnet 5", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 1000000, + "max_output_tokens": 128000, + "source": "https://docs.requesty.ai/frameworks/openai", + "thinking_levels": { + "off": null, + "minimal": "low", + "xhigh": "xhigh", + "max": "max" + } + }, + { + "id": "vertex/gemini-3.8-flash", + "name": "Gemini 3.8 Flash (Vertex)", + "reasoning": true, + "input": [ + "text", + "image", + "audio", + "video" + ], + "context_window": 1048576, + "max_output_tokens": 65536, + "source": "https://docs.requesty.ai/frameworks/openai", + "thinking_levels": { + "off": null, + "minimal": "min", + "xhigh": "high", + "max": "high" + } + }, + { + "id": "google/gemini-3.1-pro-preview", + "name": "Gemini 3.1 Pro Preview", + "reasoning": true, + "input": [ + "text", + "image", + "audio", + "video" + ], + "context_window": 1048576, + "max_output_tokens": 65536, + "source": "https://docs.requesty.ai/frameworks/openai", + "thinking_levels": { + "off": null, + "minimal": "min", + "xhigh": "high", + "max": "high" + } + }, + { + "id": "google/gemini-3.6-flash", + "name": "Gemini 3.6 Flash", + "reasoning": true, + "input": [ + "text", + "image", + "audio", + "video" + ], + "context_window": 1048576, + "max_output_tokens": 65536, + "source": "https://docs.requesty.ai/frameworks/openai", + "thinking_levels": { + "off": null, + "minimal": "min", + "xhigh": "high", + "max": "high" + } + }, + { + "id": "deepseek/deepseek-v4-pro-0813", + "name": "DeepSeek V4 Pro", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1000000, + "max_output_tokens": 131072, + "source": "https://docs.requesty.ai/frameworks/openai" + }, + { + "id": "zai/glm-5.2", + "name": "GLM-5.2", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1048576, + "max_output_tokens": 131072, + "source": "https://docs.requesty.ai/frameworks/openai" + }, + { + "id": "moonshot/kimi-k3", + "name": "Kimi K3", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 1048576, + "max_output_tokens": 262144, + "source": "https://docs.requesty.ai/frameworks/openai" + }, + { + "id": "openai/gpt-4o-transcribe", + "name": "GPT-4o Transcribe", + "type": "ASR", + "source": "https://docs.requesty.ai/api-reference/endpoint/audio-transcriptions-create" + }, + { + "id": "openai/gpt-4o-mini-transcribe", + "name": "GPT-4o mini Transcribe", + "type": "ASR", + "source": "https://docs.requesty.ai/api-reference/endpoint/audio-transcriptions-create" + }, + { + "id": "openai/whisper-1", + "name": "Whisper", + "type": "ASR", + "source": "https://docs.requesty.ai/api-reference/endpoint/audio-transcriptions-create", + "compat": { + "response_format": "verbose_json" + } + } + ], + "siliconflow": [ + { + "name": "DeepSeek V4 family (reasoning_effort high | max)", + "match": "deepseek-ai/DeepSeek-V4*", + "reasoning": true, + "input": [ + "text" + ], + "source": "https://docs.siliconflow.cn/cn/api-reference/chat-completions/chat-completions", + "thinking_levels": { + "minimal": "high", + "low": "high", + "medium": "high", + "high": "high", + "xhigh": "max", + "max": "max" + } + }, + { + "name": "DeepSeek V4 Pro-tier family (reasoning_effort high | max)", + "match": "Pro/deepseek-ai/DeepSeek-V4*", + "reasoning": true, + "input": [ + "text" + ], + "source": "https://docs.siliconflow.cn/cn/api-reference/chat-completions/chat-completions", + "thinking_levels": { + "minimal": "high", + "low": "high", + "medium": "high", + "high": "high", + "xhigh": "max", + "max": "max" + } + }, + { + "id": "deepseek-ai/DeepSeek-V4-Pro", + "name": "DeepSeek V4 Pro", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1049000, + "max_output_tokens": 393000, + "cost": { + "input": 1.74, + "output": 3.48, + "cache_read": 0.145 + }, + "source": "https://docs.siliconflow.cn/cn/api-reference/chat-completions/chat-completions", + "thinking_levels": { + "minimal": "high", + "low": "high", + "medium": "high", + "high": "high", + "xhigh": "max", + "max": "max" + } + }, + { + "id": "deepseek-ai/DeepSeek-V4-Flash", + "name": "DeepSeek V4 Flash", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1000000, + "max_output_tokens": 384000, + "cost": { + "input": 0.14, + "output": 0.28, + "cache_read": 0.003 + }, + "source": "https://docs.siliconflow.cn/cn/api-reference/chat-completions/chat-completions", + "thinking_levels": { + "minimal": "high", + "low": "high", + "medium": "high", + "high": "high", + "xhigh": "max", + "max": "max" + } + }, + { + "id": "zai-org/GLM-5.2", + "name": "GLM-5.2", + "aliases": [ + "Pro/zai-org/GLM-5.2" + ], + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1049000, + "max_output_tokens": 262000, + "cost": { + "input": 1.4, + "output": 4.4, + "cache_read": 0.26 + }, + "source": "https://docs.siliconflow.cn/cn/api-reference/chat-completions/chat-completions", + "thinking_levels": { + "minimal": "high", + "low": "high", + "medium": "high", + "high": "high", + "xhigh": "max", + "max": "max" + } + }, + { + "id": "Pro/zai-org/GLM-5.1", + "name": "GLM-5.1 (Pro)", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 205000, + "max_output_tokens": 205000, + "cost": { + "input": 1.4, + "output": 4.4, + "cache_read": 0.26 + }, + "source": "https://docs.siliconflow.cn/cn/api-reference/chat-completions/chat-completions", + "compat": { + "supports_reasoning_effort": false + } + }, + { + "id": "Pro/zai-org/GLM-5", + "name": "GLM-5 (Pro)", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 205000, + "max_output_tokens": 205000, + "cost": { + "input": 1, + "output": 3.2 + }, + "source": "https://docs.siliconflow.cn/cn/api-reference/chat-completions/chat-completions", + "compat": { + "supports_reasoning_effort": false + } + }, + { + "id": "Pro/moonshotai/Kimi-K2.6", + "name": "Kimi K2.6 (Pro)", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 262000, + "max_output_tokens": 262000, + "cost": { + "input": 0.95, + "output": 4, + "cache_read": 0.16 + }, + "source": "https://docs.siliconflow.cn/cn/api-reference/chat-completions/chat-completions", + "compat": { + "supports_reasoning_effort": false + } + }, + { + "id": "Pro/moonshotai/Kimi-K2.5", + "name": "Kimi K2.5 (Pro)", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 262000, + "max_output_tokens": 262000, + "cost": { + "input": 0.45, + "output": 2.25, + "cache_read": 0.07 + }, + "source": "https://docs.siliconflow.cn/cn/api-reference/chat-completions/chat-completions", + "compat": { + "supports_reasoning_effort": false + } + }, + { + "id": "Qwen/Qwen3.5-397B-A17B", + "name": "Qwen3.5 397B-A17B", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 262144, + "max_output_tokens": 65536, + "cost": { + "input": 0.29, + "output": 1.74 + }, + "source": "https://docs.siliconflow.cn/cn/api-reference/chat-completions/chat-completions", + "compat": { + "supports_reasoning_effort": false + } + }, + { + "id": "Qwen/Qwen3.5-122B-A10B", + "name": "Qwen3.5 122B-A10B", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 262144, + "max_output_tokens": 65536, + "cost": { + "input": 0.29, + "output": 2.32 + }, + "source": "https://docs.siliconflow.cn/cn/api-reference/chat-completions/chat-completions", + "compat": { + "supports_reasoning_effort": false + } + }, + { + "id": "Qwen/Qwen3.5-35B-A3B", + "name": "Qwen3.5 35B-A3B", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 262144, + "max_output_tokens": 65536, + "cost": { + "input": 0.23, + "output": 1.86 + }, + "source": "https://docs.siliconflow.cn/cn/api-reference/chat-completions/chat-completions", + "compat": { + "supports_reasoning_effort": false + } + }, + { + "id": "Qwen/Qwen3.6-35B-A3B", + "name": "Qwen3.6 35B-A3B", + "reasoning": false, + "input": [ + "text", + "image", + "video" + ], + "context_window": 262144, + "max_output_tokens": 65536, + "cost": { + "input": 0.23, + "output": 1.86 + }, + "source": "https://docs.siliconflow.cn/cn/api-reference/chat-completions/chat-completions" + }, + { + "id": "deepseek-ai/DeepSeek-V3.2", + "name": "DeepSeek V3.2", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 164000, + "max_output_tokens": 164000, + "cost": { + "input": 0.27, + "output": 0.42 + }, + "source": "https://docs.siliconflow.cn/cn/api-reference/chat-completions/chat-completions", + "compat": { + "supports_reasoning_effort": false + } + }, + { + "id": "Pro/MiniMaxAI/MiniMax-M2.5", + "name": "MiniMax M2.5 (Pro)", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 204800, + "max_output_tokens": 131000, + "cost": { + "input": 0.3, + "output": 1.22 + }, + "source": "https://platform.minimax.io/docs/api-reference/text-openai-api", + "compat": { + "supports_reasoning_effort": false + } + }, + { + "id": "Qwen/Qwen3-VL-32B-Instruct", + "name": "Qwen3 VL 32B Instruct", + "reasoning": false, + "input": [ + "text", + "image" + ], + "context_window": 262000, + "max_output_tokens": 262000, + "cost": { + "input": 0.2, + "output": 0.6 + }, + "source": "https://docs.siliconflow.cn/cn/api-reference/chat-completions/chat-completions" + }, + { + "id": "BAAI/bge-m3", + "name": "BGE-M3", + "type": "Embedding", + "dimension": 1024, + "source": "https://api-docs.siliconflow.cn/docs/api/embeddings-post", + "compat": { + "dimensions_field": "" + } + }, + { + "id": "Qwen/Qwen3-Embedding-8B", + "name": "Qwen3 Embedding 8B", + "type": "Embedding", + "dimension": 4096, + "source": "https://api-docs.siliconflow.cn/docs/api/embeddings-post" + }, + { + "id": "Qwen/Qwen3-Embedding-4B", + "name": "Qwen3 Embedding 4B", + "type": "Embedding", + "dimension": 2560, + "source": "https://api-docs.siliconflow.cn/docs/api/embeddings-post" + }, + { + "id": "Qwen/Qwen3-Embedding-0.6B", + "name": "Qwen3 Embedding 0.6B", + "type": "Embedding", + "dimension": 1024, + "source": "https://api-docs.siliconflow.cn/docs/api/embeddings-post" + }, + { + "id": "BAAI/bge-reranker-v2-m3", + "name": "BGE Reranker v2 M3", + "type": "Rerank", + "source": "https://api-docs.siliconflow.cn/docs/api/rerank-post" + }, + { + "id": "Qwen/Qwen3-Reranker-8B", + "name": "Qwen3 Reranker 8B", + "type": "Rerank", + "source": "https://api-docs.siliconflow.cn/docs/api/rerank-post" + }, + { + "id": "FunAudioLLM/SenseVoiceSmall", + "name": "SenseVoice Small", + "type": "ASR", + "source": "https://api-docs.siliconflow.cn/docs/api/audio-transcriptions-post" + }, + { + "id": "TeleAI/TeleSpeechASR", + "name": "TeleSpeechASR", + "type": "ASR", + "source": "https://api-docs.siliconflow.cn/docs/api/audio-transcriptions-post" + } + ], + "volcengine": [ + { + "id": "doubao-seed-2-1-pro-260915", + "name": "Doubao Seed 2.1 Pro (260915)", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 1024000, + "max_output_tokens": 256000, + "source": "https://docs.volcengine.com/docs/ark/model-list?lang=zh" + }, + { + "id": "doubao-seed-2-1-pro-260628", + "name": "Doubao Seed 2.1 Pro", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 256000, + "max_output_tokens": 256000, + "cost": { + "input": 0.8906, + "output": 4.45301, + "cache_read": 0.17812 + }, + "source": "https://www.volcengine.com/docs/82379/1494384" + }, + { + "id": "doubao-seed-2-1-turbo-260628", + "name": "Doubao Seed 2.1 Turbo", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 256000, + "max_output_tokens": 256000, + "cost": { + "input": 0.4453, + "output": 2.22651, + "cache_read": 0.08906 + }, + "source": "https://www.volcengine.com/docs/82379/1494384" + }, + { + "id": "doubao-seed-2-0-pro-260215", + "name": "Doubao Seed 2.0 Pro", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 256000, + "max_output_tokens": 131072, + "cost": { + "input": 0.47499, + "output": 2.37494, + "cache_read": 0.095 + }, + "source": "https://docs.volcengine.com/docs/ark/model-list?lang=zh", + "compat": { + "fixed_temperature": 1 + } + }, + { + "id": "doubao-seed-2-0-lite-260428", + "name": "Doubao Seed 2.0 Lite", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 256000, + "max_output_tokens": 131072, + "cost": { + "input": 0.08906, + "output": 0.53436, + "cache_read": 0.01781 + }, + "source": "https://www.volcengine.com/docs/82379/1494384" + }, + { + "id": "doubao-seed-2-0-mini-260428", + "name": "Doubao Seed 2.0 Mini", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 256000, + "max_output_tokens": 131072, + "cost": { + "input": 0.02969, + "output": 0.29687, + "cache_read": 0.00594 + }, + "source": "https://www.volcengine.com/docs/82379/1494384" + }, + { + "id": "doubao-seed-2-0-code-preview-260215", + "name": "Doubao Seed 2.0 Code Preview", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 262144, + "max_output_tokens": 131072, + "cost": { + "input": 0.47499, + "output": 2.37494, + "cache_read": 0.095 + }, + "source": "https://www.volcengine.com/docs/82379/1494384" + }, + { + "id": "doubao-seed-1-8-251228", + "name": "Doubao Seed 1.8 (retiring)", + "deprecated": true, + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 256000, + "max_output_tokens": 32768, + "cost": { + "input": 0.11875, + "output": 1.18747, + "cache_read": 0.02375 + }, + "source": "https://docs.volcengine.com/docs/ark/model-list?lang=zh" + }, + { + "id": "doubao-seed-1-6-251015", + "name": "Doubao Seed 1.6 (retiring)", + "deprecated": true, + "reasoning": true, + "input": [ + "text" + ], + "context_window": 256000, + "max_output_tokens": 32768, + "cost": { + "input": 0.11875, + "output": 1.18747, + "cache_read": 0.02375 + }, + "source": "https://docs.volcengine.com/docs/ark/model-list?lang=zh" + }, + { + "id": "doubao-seed-1-6-flash-250828", + "name": "Doubao Seed 1.6 Flash (retiring)", + "deprecated": true, + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 256000, + "max_output_tokens": 32768, + "cost": { + "input": 0.02227, + "output": 0.22265, + "cache_read": 0.00445 + }, + "source": "https://docs.volcengine.com/docs/ark/deep-thinking?lang=zh", + "compat": { + "supports_reasoning_effort": false + } + }, + { + "id": "doubao-seed-1-6-vision-250815", + "name": "Doubao Seed 1.6 Vision (retiring)", + "deprecated": true, + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 256000, + "max_output_tokens": 32768, + "cost": { + "input": 0.11875, + "output": 1.18747, + "cache_read": 0.02375 + }, + "source": "https://docs.volcengine.com/docs/ark/deep-thinking?lang=zh", + "compat": { + "supports_reasoning_effort": false + } + }, + { + "id": "deepseek-v4-1-flash-260910", + "name": "DeepSeek V4.1 Flash (Ark)", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 1000000, + "max_output_tokens": 393216, + "source": "https://docs.volcengine.com/docs/ark/model-list?lang=zh" + }, + { + "id": "deepseek-v4-pro-ga-260813", + "name": "DeepSeek V4 Pro (Ark)", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1000000, + "max_output_tokens": 393216, + "cost": { + "input": 1.3359, + "output": 4.00771, + "cache_read": 0.04453 + }, + "source": "https://www.volcengine.com/docs/82379/1494384" + }, + { + "id": "deepseek-v4-flash-ga-260731", + "name": "DeepSeek V4 Flash (Ark)", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1000000, + "max_output_tokens": 393216, + "cost": { + "input": 0.4453, + "output": 1.3359, + "cache_read": 0.01484 + }, + "source": "https://www.volcengine.com/docs/82379/1494384" + }, + { + "id": "glm-5-3-flash-260828", + "name": "GLM-5.3 Flash (Ark)", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 1000000, + "max_output_tokens": 131072, + "cost": { + "input": 0.11875, + "output": 0.41563, + "cache_read": 0.03414 + }, + "source": "https://docs.volcengine.com/docs/ark/deep-thinking?lang=zh", + "thinking_levels": { + "off": null, + "minimal": "low", + "low": "low", + "medium": "high", + "high": "high", + "xhigh": "max", + "max": "max" + } + }, + { + "id": "glm-5-2-260617", + "name": "GLM-5.2 (Ark)", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1000000, + "max_output_tokens": 131072, + "cost": { + "input": 1.18747, + "output": 4.15615, + "cache_read": 0.29687 + }, + "source": "https://www.volcengine.com/docs/82379/1494384" + }, + { + "name": "Retired doubao-embedding text models", + "match": "doubao-embedding-text*", + "type": "Embedding", + "source": "https://docs.volcengine.com/docs/ark/TextVectorizationAPI?lang=zh", + "compat": { + "api": "openai-embeddings", + "dimensions_field": "", + "max_batch_size": 4 + } + }, + { + "name": "Retired doubao-embedding-large text models", + "match": "doubao-embedding-large-text*", + "type": "Embedding", + "source": "https://docs.volcengine.com/docs/ark/TextVectorizationAPI?lang=zh", + "compat": { + "api": "openai-embeddings", + "dimensions_field": "", + "max_batch_size": 4 + } + }, + { + "id": "doubao-embedding-vision-251215", + "name": "Doubao Embedding Vision (251215)", + "type": "Embedding", + "dimension": 2048, + "source": "https://docs.volcengine.com/docs/ark/multimodal-vectorization-api?lang=zh" + }, + { + "id": "doubao-embedding-vision-250615", + "name": "Doubao Embedding Vision", + "type": "Embedding", + "dimension": 2048, + "source": "https://docs.volcengine.com/docs/ark/multimodal-vectorization-api?lang=zh" + }, + { + "id": "doubao-seed-rerank", + "name": "Doubao Seed Rerank", + "type": "Rerank", + "source": "https://www.volcengine.com/docs/84313/1254474" + }, + { + "id": "base-multilingual-rerank", + "name": "Base Multilingual Rerank", + "type": "Rerank", + "source": "https://www.volcengine.com/docs/84313/1254474" + } + ], + "weknoracloud": [], + "zhipu": [ + { + "id": "glm-5.3", + "name": "GLM-5.3", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1000000, + "max_output_tokens": 131072, + "cost": { + "input": 1.4, + "output": 4.4, + "cache_read": 0.26 + }, + "source": "https://docs.bigmodel.cn/cn/guide/models/text/glm-5.3", + "thinking_levels": { + "off": null, + "minimal": "low", + "low": "low", + "medium": "high", + "high": "high", + "xhigh": "max", + "max": "max" + } + }, + { + "id": "glm-5.3-flash", + "name": "GLM-5.3 Flash", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 1000000, + "max_output_tokens": 131072, + "cost": { + "input": 0.075, + "output": 0.25, + "cache_read": 0.015 + }, + "source": "https://docs.bigmodel.cn/cn/guide/models/vlm/glm-5.3-flash", + "thinking_levels": { + "off": null, + "minimal": "low", + "low": "low", + "medium": "high", + "high": "high", + "xhigh": "max", + "max": "max" + } + }, + { + "id": "glm-5.2", + "name": "GLM-5.2", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1000000, + "max_output_tokens": 131072, + "cost": { + "input": 1.4, + "output": 4.4, + "cache_read": 0.26 + }, + "source": "https://docs.bigmodel.cn/cn/guide/models/text/glm-5.2", + "thinking_levels": { + "low": "low", + "medium": "high", + "high": "high", + "xhigh": "max", + "max": "max" + } + }, + { + "id": "glm-5.1", + "name": "GLM-5.1", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 200000, + "max_output_tokens": 131072, + "cost": { + "input": 1.4, + "output": 4.4, + "cache_read": 0.26 + }, + "source": "https://docs.bigmodel.cn/api-reference/模型-api/对话补全", + "compat": { + "supports_reasoning_effort": false + } + }, + { + "id": "glm-5", + "name": "GLM-5", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 204800, + "max_output_tokens": 131072, + "cost": { + "input": 1, + "output": 3.2, + "cache_read": 0.2 + }, + "source": "https://docs.bigmodel.cn/api-reference/模型-api/对话补全", + "compat": { + "supports_reasoning_effort": false + } + }, + { + "id": "glm-5v-turbo", + "name": "GLM-5V Turbo", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 200000, + "max_output_tokens": 131072, + "cost": { + "input": 5, + "output": 22, + "cache_read": 1.2 + }, + "source": "https://docs.bigmodel.cn/api-reference/模型-api/对话补全", + "compat": { + "supports_reasoning_effort": false + } + }, + { + "id": "glm-4.7", + "name": "GLM-4.7", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 204800, + "max_output_tokens": 131072, + "cost": { + "input": 0.6, + "output": 2.2, + "cache_read": 0.11 + }, + "source": "https://docs.bigmodel.cn/api-reference/模型-api/对话补全", + "compat": { + "supports_reasoning_effort": false + } + }, + { + "id": "glm-4.7-flash", + "name": "GLM-4.7 Flash", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 200000, + "max_output_tokens": 131072, + "cost": { + "input": 0, + "output": 0 + }, + "source": "https://docs.bigmodel.cn/api-reference/模型-api/对话补全", + "compat": { + "supports_reasoning_effort": false + } + }, + { + "id": "glm-4.6v", + "name": "GLM-4.6V", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 128000, + "max_output_tokens": 32768, + "cost": { + "input": 0.3, + "output": 0.9 + }, + "source": "https://docs.bigmodel.cn/api-reference/模型-api/对话补全", + "compat": { + "supports_reasoning_effort": false + } + }, + { + "id": "glm-4.6", + "name": "GLM-4.6", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 204800, + "max_output_tokens": 131072, + "cost": { + "input": 0.6, + "output": 2.2, + "cache_read": 0.11 + }, + "source": "https://docs.bigmodel.cn/api-reference/模型-api/对话补全", + "compat": { + "supports_reasoning_effort": false + } + }, + { + "id": "glm-4.5-air", + "name": "GLM-4.5 Air", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 131072, + "max_output_tokens": 98304, + "cost": { + "input": 0.2, + "output": 1.1, + "cache_read": 0.03 + }, + "source": "https://docs.bigmodel.cn/api-reference/模型-api/对话补全", + "compat": { + "supports_reasoning_effort": false + } + }, + { + "id": "embedding-3", + "name": "Embedding-3", + "type": "Embedding", + "dimension": 2048, + "source": "https://docs.bigmodel.cn/api-reference/模型-api/文本嵌入", + "compat": { + "max_batch_size": 64 + } + }, + { + "id": "embedding-2", + "name": "Embedding-2", + "type": "Embedding", + "dimension": 1024, + "source": "https://docs.bigmodel.cn/api-reference/模型-api/文本嵌入", + "compat": { + "dimensions_field": "" + } + }, + { + "id": "rerank", + "name": "Rerank", + "type": "Rerank", + "source": "https://docs.bigmodel.cn/api-reference/模型-api/文本重排序" + }, + { + "id": "glm-asr-2512", + "name": "GLM-ASR-2512 (at most 30 s per file)", + "type": "ASR", + "source": "https://docs.bigmodel.cn/api-reference/模型-api/语音转文本" + } + ] + } +} diff --git a/internal/models/catalog/data/overrides.json b/internal/models/catalog/data/overrides.json new file mode 100644 index 00000000..45a44d6c --- /dev/null +++ b/internal/models/catalog/data/overrides.json @@ -0,0 +1,1931 @@ +{ + "version": 1, + "providers": { + "aliyun": [ + { + "match": "qwen3*", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true + } + }, + { + "match": "qwen3.5*", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true + } + }, + { + "match": "qwen3.6*", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true + } + }, + { + "match": "qwen3.7*", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true + } + }, + { + "match": "qwen3.8*", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true, + "supports_reasoning_effort": true, + "thinking_budget_excludes_effort": true + }, + "thinking_levels": { + "minimal": "low", + "low": "low", + "medium": "medium", + "high": "medium", + "xhigh": "xhigh", + "max": "xhigh" + } + }, + { + "match": "qwen-plus*", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true + } + }, + { + "match": "qwen-max*", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true + } + }, + { + "match": "qwen-turbo*", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true + } + }, + { + "match": "qwen-flash*", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true + } + }, + { + "match": "deepseek-v3*", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true + } + }, + { + "match": "deepseek-v4*", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true + } + }, + { + "match": "kimi-k2*", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true + } + }, + { + "match": "glm-5*", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true + } + }, + { + "id": "qwen3.8-max", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true, + "supports_reasoning_effort": true, + "thinking_budget_excludes_effort": true + }, + "thinking_levels": { + "minimal": "low", + "low": "low", + "medium": "medium", + "high": "medium", + "xhigh": "xhigh", + "max": "xhigh" + } + }, + { + "id": "qwen3.8-flash", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true, + "supports_reasoning_effort": true, + "thinking_budget_excludes_effort": true + }, + "thinking_levels": { + "minimal": "low", + "low": "low", + "medium": "medium", + "high": "medium", + "xhigh": "xhigh", + "max": "xhigh" + } + }, + { + "id": "qwen3.7-max", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true + } + }, + { + "id": "qwen3.7-plus", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true + } + }, + { + "id": "qwen3.7-flash", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true + } + }, + { + "id": "qwen3.6-plus", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true + } + }, + { + "id": "qwen3.6-flash", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true + } + }, + { + "id": "qwen3.5-plus", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true + } + }, + { + "id": "qwen3.5-flash", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true + } + }, + { + "id": "qwen3-max", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true + } + }, + { + "id": "qwen3-vl-plus", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true + } + }, + { + "id": "qwen-plus", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true + } + }, + { + "id": "qwen-max", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true + } + }, + { + "id": "qwen-turbo", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true + } + }, + { + "id": "qwen-flash", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true + } + }, + { + "id": "qwq-plus", + "thinking_levels": { + "off": null + } + }, + { + "id": "qwq-32b", + "thinking_levels": { + "off": null + } + }, + { + "id": "deepseek-v4-pro", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true, + "supports_reasoning_effort": true + }, + "thinking_levels": { + "minimal": "high", + "low": "high", + "medium": "high", + "high": "high", + "xhigh": "max", + "max": "max" + } + }, + { + "id": "deepseek-v4-flash", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true, + "supports_reasoning_effort": true + }, + "thinking_levels": { + "minimal": "high", + "low": "high", + "medium": "high", + "high": "high", + "xhigh": "max", + "max": "max" + } + }, + { + "id": "deepseek-r1", + "thinking_levels": { + "off": null + } + }, + { + "id": "kimi-k3", + "thinking_levels": { + "off": null + } + }, + { + "id": "kimi-k2.6", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true + } + }, + { + "id": "glm-5.3", + "compat": { + "thinking_always_send": true, + "thinking_disable_on_non_stream": true, + "supports_reasoning_effort": true + }, + "thinking_levels": { + "off": null, + "minimal": "low", + "low": "low", + "medium": "high", + "high": "high", + "xhigh": "max", + "max": "max" + } + }, + { + "id": "qwen3.7-text-embedding", + "type": "Embedding", + "compat": { + "max_batch_size": 20 + } + }, + { + "id": "qwen3.7-text-embedding-flash", + "type": "Embedding", + "compat": { + "max_batch_size": 20 + } + }, + { + "id": "text-embedding-v4", + "type": "Embedding", + "compat": { + "max_batch_size": 10 + } + }, + { + "id": "text-embedding-v3", + "type": "Embedding", + "compat": { + "max_batch_size": 10 + } + }, + { + "match": "text-embedding-v2", + "type": "Embedding", + "compat": { + "dimensions_field": "", + "max_batch_size": 25 + } + }, + { + "match": "text-embedding-v1", + "type": "Embedding", + "compat": { + "dimensions_field": "", + "max_batch_size": 25 + } + }, + { + "id": "tongyi-embedding-vision-plus", + "type": "Embedding", + "compat": { + "api": "dashscope-embeddings", + "dimensions_field": "" + } + }, + { + "match": "tongyi-embedding-vision-flash", + "type": "Embedding", + "compat": { + "api": "dashscope-embeddings", + "dimensions_field": "" + } + }, + { + "match": "tongyi-embedding-vision*", + "type": "Embedding", + "compat": { + "api": "dashscope-embeddings", + "dimensions_field": "dimension", + "max_batch_size": 20 + } + }, + { + "match": "qwen3-vl-embedding*", + "type": "Embedding", + "compat": { + "api": "dashscope-embeddings", + "dimensions_field": "dimension", + "max_batch_size": 20 + } + }, + { + "match": "qwen2.5-vl-embedding*", + "type": "Embedding", + "compat": { + "api": "dashscope-embeddings", + "dimensions_field": "dimension", + "max_batch_size": 1 + } + }, + { + "match": "multimodal-embedding*", + "type": "Embedding", + "compat": { + "api": "dashscope-embeddings", + "dimensions_field": "", + "max_batch_size": 20 + } + }, + { + "id": "qwen3-rerank", + "type": "Rerank", + "compat": { + "unsupported_reason": "qwen3-rerank speaks a different protocol (/compatible-api/v1/reranks, flat request, results at the top level) that no protocol package implements yet" + } + }, + { + "id": "qwen3-asr-flash", + "type": "ASR", + "compat": { + "api": "openai-chat-audio", + "max_encoded_bytes": 10485760, + "language_param": "asr_options" + } + }, + { + "match": "*", + "type": "ASR", + "compat": { + "unsupported_reason": "Alibaba's other recognition models take a public file URL or run as asynchronous tasks; only qwen3-asr-flash accepts the audio in the request" + } + } + ], + "anthropic": [ + { + "id": "claude-fable-5-1", + "api": "anthropic-messages", + "compat": { + "thinking_mode": "adaptive", + "supports_effort": true + }, + "thinking_levels": { + "off": null, + "minimal": "low", + "low": "low", + "medium": "medium", + "high": "high", + "xhigh": "xhigh", + "max": "max" + } + }, + { + "id": "claude-opus-5", + "api": "anthropic-messages", + "compat": { + "thinking_mode": "adaptive", + "supports_effort": true + }, + "thinking_levels": { + "minimal": "low", + "low": "low", + "medium": "medium", + "high": "high", + "xhigh": "xhigh", + "max": "max" + } + }, + { + "id": "claude-sonnet-5", + "api": "anthropic-messages", + "compat": { + "thinking_mode": "adaptive", + "supports_effort": true + }, + "thinking_levels": { + "minimal": "low", + "low": "low", + "medium": "medium", + "high": "high", + "xhigh": "xhigh", + "max": "max" + } + }, + { + "id": "claude-fable-5", + "api": "anthropic-messages", + "compat": { + "thinking_mode": "adaptive", + "supports_effort": true + }, + "thinking_levels": { + "off": null, + "minimal": "low", + "low": "low", + "medium": "medium", + "high": "high", + "xhigh": "xhigh", + "max": "max" + } + }, + { + "id": "claude-opus-4-8", + "api": "anthropic-messages", + "compat": { + "thinking_mode": "adaptive", + "supports_effort": true + }, + "thinking_levels": { + "minimal": "low", + "low": "low", + "medium": "medium", + "high": "high", + "xhigh": "xhigh", + "max": "max" + } + }, + { + "id": "claude-opus-4-7", + "api": "anthropic-messages", + "compat": { + "thinking_mode": "adaptive", + "supports_effort": true + }, + "thinking_levels": { + "minimal": "low", + "low": "low", + "medium": "medium", + "high": "high", + "xhigh": "xhigh", + "max": "max" + } + }, + { + "id": "claude-sonnet-4-6", + "api": "anthropic-messages", + "compat": { + "thinking_mode": "adaptive", + "supports_effort": true + }, + "thinking_levels": { + "minimal": "low", + "low": "low", + "medium": "medium", + "high": "high", + "xhigh": "max", + "max": "max" + } + }, + { + "id": "claude-opus-4-6", + "api": "anthropic-messages", + "compat": { + "thinking_mode": "adaptive", + "supports_effort": true + }, + "thinking_levels": { + "minimal": "low", + "low": "low", + "medium": "medium", + "high": "high", + "xhigh": "max", + "max": "max" + } + }, + { + "id": "claude-opus-4-5", + "api": "anthropic-messages", + "compat": { + "supports_effort": true + } + }, + { + "id": "claude-sonnet-4-5", + "api": "anthropic-messages" + }, + { + "id": "claude-haiku-4-5", + "api": "anthropic-messages" + } + ], + "azure_openai": [ + { + "match": "gpt-6*", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": null, + "minimal": "low", + "xhigh": "xhigh", + "max": "xhigh" + } + }, + { + "match": "gpt-5*", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": "none", + "minimal": "low" + } + }, + { + "id": "gpt-5", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": null, + "xhigh": "high", + "max": "high" + } + }, + { + "id": "gpt-5-mini", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": null, + "xhigh": "high", + "max": "high" + } + }, + { + "id": "gpt-5-nano", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": null, + "xhigh": "high", + "max": "high" + } + }, + { + "match": "o1*", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": null, + "minimal": "low", + "xhigh": "high", + "max": "high" + } + }, + { + "match": "o3*", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": null, + "minimal": "low", + "xhigh": "high", + "max": "high" + } + }, + { + "match": "o4*", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": null, + "minimal": "low", + "xhigh": "high", + "max": "high" + } + } + ], + "deepseek": [ + { + "id": "deepseek-v4-pro", + "thinking_levels": { + "minimal": "high", + "low": "high", + "medium": "high", + "high": "high", + "xhigh": "max", + "max": "max" + } + }, + { + "id": "deepseek-reasoner", + "thinking_levels": { + "off": null + } + } + ], + "gemini": [ + { + "match": "gemini-3*", + "api": "google-generative-ai", + "compat": { + "thinking_mode": "level" + }, + "thinking_levels": { + "off": null, + "minimal": "low", + "low": "low", + "medium": "high", + "high": "high", + "xhigh": "high", + "max": "high" + } + }, + { + "id": "gemini-3.8-flash", + "api": "google-generative-ai", + "compat": { + "thinking_mode": "level" + }, + "thinking_levels": { + "off": null, + "minimal": "low", + "low": "low", + "medium": "medium", + "high": "high", + "xhigh": "high", + "max": "high" + } + }, + { + "id": "gemini-3.7-flash", + "api": "google-generative-ai", + "compat": { + "thinking_mode": "level" + }, + "thinking_levels": { + "off": null, + "minimal": "low", + "low": "low", + "medium": "medium", + "high": "high", + "xhigh": "high", + "max": "high" + } + }, + { + "id": "gemini-3.6-flash", + "api": "google-generative-ai", + "compat": { + "thinking_mode": "level" + }, + "thinking_levels": { + "off": null, + "minimal": "minimal", + "low": "low", + "medium": "medium", + "high": "high", + "xhigh": "high", + "max": "high" + } + }, + { + "id": "gemini-3.5-flash", + "api": "google-generative-ai", + "compat": { + "thinking_mode": "level" + }, + "thinking_levels": { + "off": null, + "minimal": "minimal", + "low": "low", + "medium": "medium", + "high": "high", + "xhigh": "high", + "max": "high" + } + }, + { + "id": "gemini-3.5-flash-lite", + "api": "google-generative-ai", + "compat": { + "thinking_mode": "level" + }, + "thinking_levels": { + "off": null, + "minimal": "minimal", + "low": "low", + "medium": "medium", + "high": "high", + "xhigh": "high", + "max": "high" + } + }, + { + "id": "gemini-3.1-pro-preview", + "api": "google-generative-ai", + "compat": { + "thinking_mode": "level" + }, + "thinking_levels": { + "off": null, + "minimal": "low", + "low": "low", + "medium": "medium", + "high": "high", + "xhigh": "high", + "max": "high" + } + }, + { + "id": "gemini-3.1-flash-lite", + "api": "google-generative-ai", + "compat": { + "thinking_mode": "level" + }, + "thinking_levels": { + "off": null, + "minimal": "minimal", + "low": "low", + "medium": "medium", + "high": "high", + "xhigh": "high", + "max": "high" + } + }, + { + "id": "gemini-3-flash-preview", + "api": "google-generative-ai", + "compat": { + "thinking_mode": "level" + }, + "thinking_levels": { + "off": null, + "minimal": "minimal", + "low": "low", + "medium": "medium", + "high": "high", + "xhigh": "high", + "max": "high" + } + }, + { + "id": "gemini-2.5-pro", + "api": "google-generative-ai", + "compat": { + "thinking_mode": "budget" + }, + "thinking_levels": { + "off": null + } + }, + { + "id": "gemini-2.5-flash", + "api": "google-generative-ai", + "compat": { + "thinking_mode": "budget" + } + }, + { + "id": "gemini-2.5-flash-lite", + "api": "google-generative-ai", + "compat": { + "thinking_mode": "budget" + } + } + ], + "generic": [ + { + "match": "gpt-5*", + "compat": { + "max_tokens_field": "max_completion_tokens", + "supports_temperature": false, + "thinking_format": "openai", + "supports_reasoning_effort": true + } + }, + { + "match": "o1*", + "compat": { + "max_tokens_field": "max_completion_tokens", + "supports_temperature": false, + "thinking_format": "openai", + "supports_reasoning_effort": true + }, + "thinking_levels": { + "off": null, + "minimal": "low", + "xhigh": "high", + "max": "high" + } + }, + { + "match": "o3*", + "compat": { + "max_tokens_field": "max_completion_tokens", + "supports_temperature": false, + "thinking_format": "openai", + "supports_reasoning_effort": true + }, + "thinking_levels": { + "off": null, + "minimal": "low", + "xhigh": "high", + "max": "high" + } + }, + { + "match": "o4*", + "compat": { + "max_tokens_field": "max_completion_tokens", + "supports_temperature": false, + "thinking_format": "openai", + "supports_reasoning_effort": true + }, + "thinking_levels": { + "off": null, + "minimal": "low", + "xhigh": "high", + "max": "high" + } + } + ], + "hunyuan": [ + { + "match": "hunyuan-t1*", + "thinking_levels": { + "off": null + } + }, + { + "id": "hunyuan-t1-latest", + "thinking_levels": { + "off": null + } + }, + { + "id": "hunyuan-t1-vision-20250916", + "thinking_levels": { + "off": null + } + } + ], + "lkeap": [ + { + "match": "*deepseek-r1*", + "thinking_levels": { + "off": null + } + }, + { + "id": "deepseek-r1-0528", + "thinking_levels": { + "off": null + } + }, + { + "id": "deepseek-r1", + "thinking_levels": { + "off": null + } + } + ], + "longcat": [ + { + "id": "LongCat-Flash-Thinking", + "thinking_levels": { + "off": null + } + } + ], + "minimax": [ + { + "id": "MiniMax-M2.7", + "thinking_levels": { + "off": null + } + }, + { + "id": "MiniMax-M2.7-highspeed", + "thinking_levels": { + "off": null + } + }, + { + "id": "MiniMax-M2.5", + "thinking_levels": { + "off": null + } + }, + { + "id": "MiniMax-M2.5-highspeed", + "thinking_levels": { + "off": null + } + }, + { + "id": "MiniMax-M2.1", + "thinking_levels": { + "off": null + } + }, + { + "id": "MiniMax-M2.1-highspeed", + "thinking_levels": { + "off": null + } + }, + { + "id": "MiniMax-M2", + "thinking_levels": { + "off": null + } + } + ], + "modelscope": [ + { + "id": "Qwen/Qwen3-235B-A22B-Thinking-2507", + "thinking_levels": { + "off": null + } + }, + { + "id": "Qwen/Qwen3-30B-A3B-Thinking-2507", + "thinking_levels": { + "off": null + } + } + ], + "moonshot": [ + { + "id": "kimi-k3", + "compat": { + "thinking_format": "openai", + "supports_reasoning_effort": true, + "supports_temperature": false, + "tool_choice_modes": [ + "none", + "auto", + "required" + ] + }, + "thinking_levels": { + "off": null, + "minimal": "low", + "low": "low", + "medium": "high", + "high": "high", + "xhigh": "max", + "max": "max" + } + }, + { + "id": "kimi-k2.7-code", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": null + } + }, + { + "id": "kimi-k2.7-code-highspeed", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": null + } + }, + { + "id": "kimi-k2.6", + "compat": { + "supports_temperature": false + } + }, + { + "match": "moonshot-v1*", + "compat": { + "fixed_temperature": 1 + } + }, + { + "id": "kimi-k2.5", + "compat": { + "supports_temperature": false + } + }, + { + "id": "kimi-k2-thinking", + "thinking_levels": { + "off": null + } + }, + { + "id": "moonshot-v1-8k", + "compat": { + "fixed_temperature": 1 + } + }, + { + "id": "moonshot-v1-32k", + "compat": { + "fixed_temperature": 1 + } + }, + { + "id": "moonshot-v1-128k", + "compat": { + "fixed_temperature": 1 + } + }, + { + "id": "moonshot-v1-8k-vision-preview", + "compat": { + "fixed_temperature": 1 + } + } + ], + "novita": [ + { + "id": "minimax/minimax-m2.7", + "thinking_levels": { + "off": null + } + }, + { + "id": "xiaomimimo/mimo-v2.5-pro", + "thinking_levels": { + "off": null + } + } + ], + "nvidia": [ + { + "id": "z-ai/glm-5.3", + "compat": { + "thinking_format": "openai", + "supports_reasoning_effort": true + }, + "thinking_levels": { + "off": null, + "minimal": "low", + "medium": "high", + "xhigh": "max", + "max": "max" + } + }, + { + "id": "moonshotai/kimi-k3", + "compat": { + "max_tokens_field": "max_completion_tokens", + "thinking_format": "openai", + "supports_reasoning_effort": true + }, + "thinking_levels": { + "off": null, + "minimal": "low", + "medium": "high", + "xhigh": "max", + "max": "max" + } + }, + { + "id": "google/gemma-4-31b-it", + "compat": { + "max_tokens_field": "max_completion_tokens", + "thinking_format": "none" + } + } + ], + "openai": [ + { + "match": "gpt-6*", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": null, + "minimal": "low", + "xhigh": "xhigh", + "max": "max" + } + }, + { + "match": "gpt-5*", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": "none", + "minimal": "low" + } + }, + { + "match": "o1*", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": null, + "minimal": "low", + "xhigh": "high", + "max": "high" + } + }, + { + "match": "o3*", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": null, + "minimal": "low", + "xhigh": "high", + "max": "high" + } + }, + { + "match": "o4*", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": null, + "minimal": "low", + "xhigh": "high", + "max": "high" + } + }, + { + "id": "gpt-6-astra", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": null, + "minimal": "low", + "xhigh": "xhigh", + "max": "max" + } + }, + { + "id": "gpt-5.6-terra", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": "none", + "minimal": "low", + "xhigh": "xhigh", + "max": "max" + } + }, + { + "id": "gpt-5.6-sol", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": "none", + "minimal": "low", + "xhigh": "xhigh", + "max": "max" + } + }, + { + "id": "gpt-5.6-luna", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": "none", + "minimal": "low", + "xhigh": "xhigh", + "max": "max" + } + }, + { + "id": "gpt-5.5", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": "none", + "minimal": "low", + "xhigh": "xhigh", + "max": "xhigh" + } + }, + { + "id": "gpt-5.4", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": "none", + "minimal": "low", + "xhigh": "xhigh", + "max": "xhigh" + } + }, + { + "id": "gpt-5.4-mini", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": "none", + "minimal": "low", + "xhigh": "xhigh", + "max": "xhigh" + } + }, + { + "id": "gpt-5.4-nano", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": "none", + "minimal": "low", + "xhigh": "xhigh", + "max": "xhigh" + } + }, + { + "id": "gpt-5.2", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": "none", + "minimal": "low", + "xhigh": "xhigh", + "max": "xhigh" + } + }, + { + "id": "gpt-5.1", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": "none", + "minimal": "low", + "xhigh": "high", + "max": "high" + } + }, + { + "id": "gpt-5", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": null, + "xhigh": "high", + "max": "high" + } + }, + { + "id": "gpt-5-mini", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": null, + "xhigh": "high", + "max": "high" + } + }, + { + "id": "gpt-5-nano", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": null, + "xhigh": "high", + "max": "high" + } + }, + { + "id": "o3", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": null, + "minimal": "low", + "xhigh": "high", + "max": "high" + } + }, + { + "id": "whisper-1", + "type": "ASR", + "compat": { + "response_format": "verbose_json" + } + }, + { + "id": "text-embedding-ada-002", + "type": "Embedding", + "compat": { + "dimensions_field": "" + } + } + ], + "openrouter": [ + { + "match": "anthropic/*", + "compat": { + "cache_control_format": "anthropic" + }, + "thinking_levels": { + "off": null, + "minimal": "low", + "xhigh": "xhigh", + "max": "max" + } + }, + { + "id": "openai/gpt-5.5", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": "none", + "minimal": "low", + "xhigh": "xhigh", + "max": "xhigh" + } + }, + { + "id": "openai/gpt-5.4", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": "none", + "minimal": "low", + "xhigh": "xhigh", + "max": "xhigh" + } + }, + { + "id": "anthropic/claude-opus-5", + "compat": { + "cache_control_format": "anthropic" + }, + "thinking_levels": { + "off": null, + "minimal": "low", + "xhigh": "xhigh", + "max": "max" + } + }, + { + "id": "anthropic/claude-sonnet-5", + "compat": { + "cache_control_format": "anthropic" + }, + "thinking_levels": { + "off": null, + "minimal": "low", + "xhigh": "xhigh", + "max": "max" + } + }, + { + "id": "anthropic/claude-sonnet-4.6", + "compat": { + "cache_control_format": "anthropic" + }, + "thinking_levels": { + "off": null, + "minimal": "low", + "xhigh": "max", + "max": "max" + } + }, + { + "id": "google/gemini-3.8-flash", + "thinking_levels": { + "off": null, + "minimal": "low", + "xhigh": "high", + "max": "high" + } + }, + { + "id": "google/gemini-3.1-pro-preview", + "thinking_levels": { + "off": null, + "minimal": "low", + "xhigh": "high", + "max": "high" + } + }, + { + "id": "deepseek/deepseek-v4-pro", + "thinking_levels": { + "minimal": "high", + "low": "high", + "medium": "high", + "high": "high", + "xhigh": "xhigh", + "max": "xhigh" + } + }, + { + "id": "deepseek/deepseek-v4-flash", + "thinking_levels": { + "minimal": "high", + "low": "high", + "medium": "high", + "high": "high", + "xhigh": "xhigh", + "max": "xhigh" + } + }, + { + "id": "z-ai/glm-5.3", + "thinking_levels": { + "off": null, + "minimal": "low", + "medium": "high", + "xhigh": "max", + "max": "max" + } + }, + { + "id": "moonshotai/kimi-k3", + "thinking_levels": { + "minimal": "low", + "medium": "high", + "xhigh": "max", + "max": "max" + } + }, + { + "id": "x-ai/grok-4.6", + "thinking_levels": { + "off": null, + "minimal": "low", + "xhigh": "xhigh", + "max": "xhigh" + } + } + ], + "qianfan": [ + { + "id": "ernie-x1-turbo-32k", + "thinking_levels": { + "off": null + } + }, + { + "id": "deepseek-v3.2", + "compat": { + "thinking_format": "thinking-type" + } + }, + { + "id": "tao-8k", + "type": "Embedding", + "compat": { + "max_batch_size": 1 + } + } + ], + "qiniu": [ + { + "id": "deepseek-r1", + "thinking_levels": { + "off": null + } + } + ], + "requesty": [ + { + "id": "openai/gpt-6-astra", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": null, + "minimal": "min", + "xhigh": "xhigh", + "max": "xhigh" + } + }, + { + "id": "openai/gpt-5.5", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": "none", + "minimal": "min", + "xhigh": "xhigh", + "max": "xhigh" + } + }, + { + "id": "openai/gpt-5.4", + "compat": { + "supports_temperature": false + }, + "thinking_levels": { + "off": "none", + "minimal": "min", + "xhigh": "xhigh", + "max": "xhigh" + } + }, + { + "id": "anthropic/claude-opus-5", + "thinking_levels": { + "off": null, + "minimal": "low", + "xhigh": "xhigh", + "max": "max" + } + }, + { + "id": "anthropic/claude-sonnet-5", + "thinking_levels": { + "off": null, + "minimal": "low", + "xhigh": "xhigh", + "max": "max" + } + }, + { + "id": "vertex/gemini-3.8-flash", + "thinking_levels": { + "off": null, + "minimal": "min", + "xhigh": "high", + "max": "high" + } + }, + { + "id": "google/gemini-3.1-pro-preview", + "thinking_levels": { + "off": null, + "minimal": "min", + "xhigh": "high", + "max": "high" + } + }, + { + "id": "google/gemini-3.6-flash", + "thinking_levels": { + "off": null, + "minimal": "min", + "xhigh": "high", + "max": "high" + } + }, + { + "id": "openai/whisper-1", + "type": "ASR", + "compat": { + "response_format": "verbose_json" + } + } + ], + "siliconflow": [ + { + "match": "deepseek-ai/DeepSeek-V4*", + "thinking_levels": { + "minimal": "high", + "low": "high", + "medium": "high", + "high": "high", + "xhigh": "max", + "max": "max" + } + }, + { + "match": "Pro/deepseek-ai/DeepSeek-V4*", + "thinking_levels": { + "minimal": "high", + "low": "high", + "medium": "high", + "high": "high", + "xhigh": "max", + "max": "max" + } + }, + { + "id": "deepseek-ai/DeepSeek-V4-Pro", + "thinking_levels": { + "minimal": "high", + "low": "high", + "medium": "high", + "high": "high", + "xhigh": "max", + "max": "max" + } + }, + { + "id": "deepseek-ai/DeepSeek-V4-Flash", + "thinking_levels": { + "minimal": "high", + "low": "high", + "medium": "high", + "high": "high", + "xhigh": "max", + "max": "max" + } + }, + { + "id": "zai-org/GLM-5.2", + "thinking_levels": { + "minimal": "high", + "low": "high", + "medium": "high", + "high": "high", + "xhigh": "max", + "max": "max" + } + }, + { + "id": "Pro/zai-org/GLM-5.1", + "compat": { + "supports_reasoning_effort": false + } + }, + { + "id": "Pro/zai-org/GLM-5", + "compat": { + "supports_reasoning_effort": false + } + }, + { + "id": "Pro/moonshotai/Kimi-K2.6", + "compat": { + "supports_reasoning_effort": false + } + }, + { + "id": "Pro/moonshotai/Kimi-K2.5", + "compat": { + "supports_reasoning_effort": false + } + }, + { + "id": "Qwen/Qwen3.5-397B-A17B", + "compat": { + "supports_reasoning_effort": false + } + }, + { + "id": "Qwen/Qwen3.5-122B-A10B", + "compat": { + "supports_reasoning_effort": false + } + }, + { + "id": "Qwen/Qwen3.5-35B-A3B", + "compat": { + "supports_reasoning_effort": false + } + }, + { + "id": "deepseek-ai/DeepSeek-V3.2", + "compat": { + "supports_reasoning_effort": false + } + }, + { + "id": "Pro/MiniMaxAI/MiniMax-M2.5", + "compat": { + "supports_reasoning_effort": false + } + }, + { + "id": "BAAI/bge-m3", + "type": "Embedding", + "compat": { + "dimensions_field": "" + } + } + ], + "volcengine": [ + { + "id": "doubao-seed-2-0-pro-260215", + "compat": { + "fixed_temperature": 1 + } + }, + { + "id": "doubao-seed-1-6-flash-250828", + "compat": { + "supports_reasoning_effort": false + } + }, + { + "id": "doubao-seed-1-6-vision-250815", + "compat": { + "supports_reasoning_effort": false + } + }, + { + "id": "glm-5-3-flash-260828", + "thinking_levels": { + "off": null, + "minimal": "low", + "low": "low", + "medium": "high", + "high": "high", + "xhigh": "max", + "max": "max" + } + }, + { + "match": "doubao-embedding-text*", + "type": "Embedding", + "compat": { + "api": "openai-embeddings", + "dimensions_field": "", + "max_batch_size": 4 + } + }, + { + "match": "doubao-embedding-large-text*", + "type": "Embedding", + "compat": { + "api": "openai-embeddings", + "dimensions_field": "", + "max_batch_size": 4 + } + } + ], + "zhipu": [ + { + "id": "glm-5.3", + "thinking_levels": { + "off": null, + "minimal": "low", + "low": "low", + "medium": "high", + "high": "high", + "xhigh": "max", + "max": "max" + } + }, + { + "id": "glm-5.3-flash", + "thinking_levels": { + "off": null, + "minimal": "low", + "low": "low", + "medium": "high", + "high": "high", + "xhigh": "max", + "max": "max" + } + }, + { + "id": "glm-5.2", + "thinking_levels": { + "low": "low", + "medium": "high", + "high": "high", + "xhigh": "max", + "max": "max" + } + }, + { + "id": "glm-5.1", + "compat": { + "supports_reasoning_effort": false + } + }, + { + "id": "glm-5", + "compat": { + "supports_reasoning_effort": false + } + }, + { + "id": "glm-5v-turbo", + "compat": { + "supports_reasoning_effort": false + } + }, + { + "id": "glm-4.7", + "compat": { + "supports_reasoning_effort": false + } + }, + { + "id": "glm-4.7-flash", + "compat": { + "supports_reasoning_effort": false + } + }, + { + "id": "glm-4.6v", + "compat": { + "supports_reasoning_effort": false + } + }, + { + "id": "glm-4.6", + "compat": { + "supports_reasoning_effort": false + } + }, + { + "id": "glm-4.5-air", + "compat": { + "supports_reasoning_effort": false + } + }, + { + "id": "embedding-3", + "type": "Embedding", + "compat": { + "max_batch_size": 64 + } + }, + { + "id": "embedding-2", + "type": "Embedding", + "compat": { + "dimensions_field": "" + } + } + ] + } +} diff --git a/internal/models/catalog/data/seed.json b/internal/models/catalog/data/seed.json new file mode 100644 index 00000000..0ba5aaa4 --- /dev/null +++ b/internal/models/catalog/data/seed.json @@ -0,0 +1,4542 @@ +{ + "version": 1, + "providers": { + "aliyun": [ + { + "name": "Qwen3 family (hybrid thinking)", + "match": "qwen3*", + "reasoning": true, + "input": [ + "text" + ], + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking" + }, + { + "name": "Qwen3.5 family (hybrid thinking)", + "match": "qwen3.5*", + "reasoning": true, + "input": [ + "text", + "image" + ], + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking" + }, + { + "name": "Qwen3.6 family (hybrid thinking)", + "match": "qwen3.6*", + "reasoning": true, + "input": [ + "text", + "image" + ], + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking" + }, + { + "name": "Qwen3.7 family (hybrid thinking)", + "match": "qwen3.7*", + "reasoning": true, + "input": [ + "text", + "image" + ], + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking" + }, + { + "name": "Qwen3.8 family (hybrid thinking)", + "match": "qwen3.8*", + "reasoning": true, + "input": [ + "text", + "image" + ], + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking" + }, + { + "name": "qwen-plus family (hybrid thinking)", + "match": "qwen-plus*", + "reasoning": true, + "input": [ + "text" + ], + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking" + }, + { + "name": "qwen-max family (hybrid thinking)", + "match": "qwen-max*", + "reasoning": true, + "input": [ + "text" + ], + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking" + }, + { + "name": "qwen-turbo family (hybrid thinking)", + "match": "qwen-turbo*", + "reasoning": true, + "input": [ + "text" + ], + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking" + }, + { + "name": "qwen-flash family (hybrid thinking)", + "match": "qwen-flash*", + "reasoning": true, + "input": [ + "text" + ], + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking" + }, + { + "name": "DeepSeek V3 family on DashScope (hybrid thinking)", + "match": "deepseek-v3*", + "reasoning": true, + "input": [ + "text" + ], + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking" + }, + { + "name": "DeepSeek V4 family on DashScope (hybrid thinking)", + "match": "deepseek-v4*", + "reasoning": true, + "input": [ + "text" + ], + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking" + }, + { + "name": "Kimi K2 family on DashScope (hybrid thinking)", + "match": "kimi-k2*", + "reasoning": true, + "input": [ + "text", + "image" + ], + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking" + }, + { + "name": "GLM-5 family on DashScope (hybrid thinking)", + "match": "glm-5*", + "reasoning": true, + "input": [ + "text" + ], + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking" + }, + { + "id": "qwen3.8-max", + "name": "Qwen3.8 Max", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 1000000, + "max_output_tokens": 131072, + "cost": { + "input": 1.77744, + "output": 5.33231, + "cache_read": 0.22218, + "cache_write": 2.22179 + }, + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking" + }, + { + "id": "qwen3.8-flash", + "name": "Qwen3.8 Flash", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 1000000, + "max_output_tokens": 131072, + "cost": { + "input": 0.11875, + "output": 0.40073, + "cache_read": 0.01187, + "cache_write": 0.14844 + }, + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking" + }, + { + "id": "qwen3.7-max", + "name": "Qwen3.7 Max", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1000000, + "max_output_tokens": 65536, + "cost": { + "input": 2.5, + "output": 7.5, + "cache_read": 0.5, + "cache_write": 3.125 + }, + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking" + }, + { + "id": "qwen3.7-plus", + "name": "Qwen3.7 Plus", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 1000000, + "max_output_tokens": 64000, + "cost": { + "input": 0.5, + "output": 3, + "cache_read": 0.05, + "cache_write": 0.625 + }, + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking" + }, + { + "id": "qwen3.7-flash", + "name": "Qwen3.7 Flash", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 1000000, + "max_output_tokens": 65536, + "cost": { + "input": 0.02962, + "output": 0.1185, + "cache_read": 0.002962, + "cache_write": 0.03703 + }, + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking" + }, + { + "id": "qwen3.6-plus", + "name": "Qwen3.6 Plus", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 1000000, + "max_output_tokens": 65536, + "cost": { + "input": 0.5, + "output": 3, + "cache_read": 0.05, + "cache_write": 0.625 + }, + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking" + }, + { + "id": "qwen3.6-flash", + "name": "Qwen3.6 Flash", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 1000000, + "max_output_tokens": 65536, + "cost": { + "input": 0.1875, + "output": 1.125, + "cache_write": 0.234375 + }, + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking" + }, + { + "id": "qwen3.5-plus", + "name": "Qwen3.5 Plus", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 1000000, + "max_output_tokens": 65536, + "cost": { + "input": 0.287, + "output": 1.722 + }, + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking" + }, + { + "id": "qwen3.5-flash", + "name": "Qwen3.5 Flash", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 1000000, + "max_output_tokens": 65536, + "cost": { + "input": 0.172, + "output": 1.033 + }, + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking" + }, + { + "id": "qwen3-max", + "name": "Qwen3 Max", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 262144, + "max_output_tokens": 65536, + "cost": { + "input": 1.291, + "output": 7.749 + }, + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking" + }, + { + "id": "qwen3-vl-plus", + "name": "Qwen3 VL Plus", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 262144, + "max_output_tokens": 32768, + "cost": { + "input": 0.143353, + "output": 1.433525 + }, + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking" + }, + { + "id": "qwen-plus", + "name": "Qwen Plus", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1000000, + "max_output_tokens": 32768, + "cost": { + "input": 0.115, + "output": 0.287, + "cache_read": 0.012, + "cache_write": 0.144 + }, + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking" + }, + { + "id": "qwen-max", + "name": "Qwen Max", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 131072, + "max_output_tokens": 8192, + "cost": { + "input": 0.345, + "output": 1.377 + }, + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking" + }, + { + "id": "qwen-turbo", + "name": "Qwen Turbo", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1000000, + "max_output_tokens": 16384, + "cost": { + "input": 0.044, + "output": 0.087 + }, + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking" + }, + { + "id": "qwen-flash", + "name": "Qwen Flash", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1000000, + "max_output_tokens": 32768, + "cost": { + "input": 0.022, + "output": 0.216 + }, + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking" + }, + { + "id": "qwen-vl-max", + "name": "Qwen VL Max", + "reasoning": false, + "input": [ + "text", + "image" + ], + "context_window": 131072, + "max_output_tokens": 8192, + "cost": { + "input": 0.23, + "output": 0.574 + }, + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking" + }, + { + "id": "qwen-vl-plus", + "name": "Qwen VL Plus", + "reasoning": false, + "input": [ + "text", + "image" + ], + "context_window": 131072, + "max_output_tokens": 8192, + "cost": { + "input": 0.115, + "output": 0.287 + }, + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking" + }, + { + "id": "qwq-plus", + "name": "QwQ Plus", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 131072, + "max_output_tokens": 8192, + "cost": { + "input": 0.23, + "output": 0.574 + }, + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking" + }, + { + "id": "qwq-32b", + "name": "QwQ 32B", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 131072, + "max_output_tokens": 8192, + "cost": { + "input": 0.287, + "output": 0.861 + }, + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking" + }, + { + "id": "deepseek-v4-pro", + "name": "DeepSeek V4 Pro", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1000000, + "max_output_tokens": 393216, + "cost": { + "input": 0.435, + "output": 0.87, + "cache_read": 0.003625 + }, + "source": "https://help.aliyun.com/zh/model-studio/deepseek-api" + }, + { + "id": "deepseek-v4-flash", + "name": "DeepSeek V4 Flash", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1000000, + "max_output_tokens": 393216, + "cost": { + "input": 0.14, + "output": 0.28, + "cache_read": 0.0028 + }, + "source": "https://help.aliyun.com/zh/model-studio/deepseek-api" + }, + { + "id": "deepseek-r1", + "name": "DeepSeek R1", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 131072, + "max_output_tokens": 16384, + "cost": { + "input": 0.574, + "output": 2.294 + }, + "source": "https://help.aliyun.com/zh/model-studio/deepseek-api" + }, + { + "id": "kimi-k3", + "name": "Kimi K3", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 1048576, + "max_output_tokens": 1048576, + "cost": { + "input": 2.827, + "output": 14.133, + "cache_read": 0.283 + }, + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking" + }, + { + "id": "kimi-k2.6", + "name": "Kimi K2.6", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 262144, + "max_output_tokens": 16384, + "cost": { + "input": 0.929, + "output": 3.858 + }, + "source": "https://help.aliyun.com/zh/model-studio/deep-thinking" + }, + { + "id": "glm-5.3", + "name": "GLM-5.3", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1000000, + "max_output_tokens": 131072, + "cost": { + "input": 1.1, + "output": 3.851, + "cache_read": 0.275 + }, + "source": "https://docs.bigmodel.cn/cn/guide/models/text/glm-5.3" + }, + { + "id": "qwen3.7-text-embedding", + "name": "Qwen3.7 Text Embedding", + "type": "Embedding", + "dimension": 1024, + "source": "https://help.aliyun.com/zh/model-studio/embedding" + }, + { + "id": "qwen3.7-text-embedding-flash", + "name": "Qwen3.7 Text Embedding Flash", + "type": "Embedding", + "dimension": 1024, + "source": "https://help.aliyun.com/zh/model-studio/embedding" + }, + { + "id": "text-embedding-v4", + "name": "Tongyi text-embedding-v4", + "type": "Embedding", + "dimension": 1024, + "source": "https://help.aliyun.com/zh/model-studio/embedding" + }, + { + "id": "text-embedding-v3", + "name": "Tongyi text-embedding-v3", + "type": "Embedding", + "dimension": 1024, + "source": "https://help.aliyun.com/zh/model-studio/embedding" + }, + { + "name": "text-embedding-v2 (fixed 1536 dimensions)", + "match": "text-embedding-v2", + "type": "Embedding", + "source": "https://help.aliyun.com/zh/model-studio/embedding-interfaces-compatible-with-openai" + }, + { + "name": "text-embedding-v1 (fixed 1536 dimensions)", + "match": "text-embedding-v1", + "type": "Embedding", + "source": "https://help.aliyun.com/zh/model-studio/embedding-interfaces-compatible-with-openai" + }, + { + "id": "tongyi-embedding-vision-plus", + "name": "Tongyi Embedding Vision Plus", + "type": "Embedding", + "dimension": 1152, + "source": "https://help.aliyun.com/zh/model-studio/multimodal-embedding-api-reference" + }, + { + "name": "tongyi-embedding-vision-flash (fixed 768 dimensions)", + "match": "tongyi-embedding-vision-flash", + "type": "Embedding", + "source": "https://help.aliyun.com/zh/model-studio/multimodal-embedding-api-reference" + }, + { + "name": "tongyi-embedding-vision snapshots", + "match": "tongyi-embedding-vision*", + "type": "Embedding", + "source": "https://help.aliyun.com/zh/model-studio/multimodal-embedding-api-reference" + }, + { + "name": "qwen3-vl-embedding (independent vectors by default)", + "match": "qwen3-vl-embedding*", + "type": "Embedding", + "source": "https://help.aliyun.com/zh/model-studio/multimodal-embedding-api-reference" + }, + { + "name": "qwen2.5-vl-embedding (fused vectors only)", + "match": "qwen2.5-vl-embedding*", + "type": "Embedding", + "source": "https://help.aliyun.com/zh/model-studio/multimodal-embedding-api-reference" + }, + { + "name": "multimodal-embedding-v1", + "match": "multimodal-embedding*", + "type": "Embedding", + "source": "https://help.aliyun.com/zh/model-studio/multimodal-embedding-api-reference" + }, + { + "id": "qwen3-rerank", + "name": "Qwen3 Rerank (separate endpoint, not implemented)", + "type": "Rerank", + "deprecated": true, + "source": "https://help.aliyun.com/zh/model-studio/text-rerank-api" + }, + { + "id": "gte-rerank-v2", + "name": "GTE Rerank v2", + "type": "Rerank", + "source": "https://help.aliyun.com/zh/model-studio/text-rerank-api" + }, + { + "id": "qwen3-asr-flash", + "name": "Qwen3 ASR Flash", + "type": "ASR", + "source": "https://help.aliyun.com/zh/model-studio/qwen-asr-api-reference" + }, + { + "name": "Other Alibaba recognition models (not callable with the audio in the request)", + "match": "*", + "type": "ASR", + "source": "https://help.aliyun.com/zh/model-studio/qwen-asr-api-reference" + } + ], + "anthropic": [ + { + "id": "claude-fable-5-1", + "name": "Claude Fable 5.1", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 1000000, + "max_output_tokens": 128000, + "cost": { + "input": 10, + "output": 50, + "cache_read": 0.25, + "cache_write": 12.5 + }, + "source": "https://docs.anthropic.com/en/docs/about-claude/models" + }, + { + "id": "claude-opus-5", + "name": "Claude Opus 5", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 1000000, + "max_output_tokens": 128000, + "cost": { + "input": 5, + "output": 25, + "cache_read": 0.5, + "cache_write": 6.25 + }, + "source": "https://platform.claude.com/docs/en/build-with-claude/thinking-troubleshooting#supported-models" + }, + { + "id": "claude-sonnet-5", + "name": "Claude Sonnet 5", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 1000000, + "max_output_tokens": 128000, + "cost": { + "input": 2, + "output": 10, + "cache_read": 0.2, + "cache_write": 2.5 + }, + "source": "https://docs.anthropic.com/en/docs/about-claude/models" + }, + { + "id": "claude-fable-5", + "name": "Claude Fable 5", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 1000000, + "max_output_tokens": 128000, + "cost": { + "input": 10, + "output": 50, + "cache_read": 1, + "cache_write": 12.5 + }, + "source": "https://docs.anthropic.com/en/docs/about-claude/models" + }, + { + "id": "claude-opus-4-8", + "name": "Claude Opus 4.8", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 1000000, + "max_output_tokens": 128000, + "cost": { + "input": 5, + "output": 25, + "cache_read": 0.5, + "cache_write": 6.25 + }, + "source": "https://platform.claude.com/docs/en/build-with-claude/thinking-troubleshooting#supported-models" + }, + { + "id": "claude-opus-4-7", + "name": "Claude Opus 4.7", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 1000000, + "max_output_tokens": 128000, + "cost": { + "input": 5, + "output": 25, + "cache_read": 0.5, + "cache_write": 6.25 + }, + "source": "https://platform.claude.com/docs/en/build-with-claude/thinking-troubleshooting#supported-models" + }, + { + "id": "claude-sonnet-4-6", + "name": "Claude Sonnet 4.6", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 1000000, + "max_output_tokens": 128000, + "cost": { + "input": 3, + "output": 15, + "cache_read": 0.3, + "cache_write": 3.75 + }, + "source": "https://docs.anthropic.com/en/docs/about-claude/models" + }, + { + "id": "claude-opus-4-6", + "name": "Claude Opus 4.6", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 1000000, + "max_output_tokens": 128000, + "cost": { + "input": 5, + "output": 25, + "cache_read": 0.5, + "cache_write": 6.25 + }, + "source": "https://docs.anthropic.com/en/docs/about-claude/models" + }, + { + "id": "claude-opus-4-5", + "name": "Claude Opus 4.5", + "aliases": [ + "claude-opus-4-5-20251101" + ], + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 200000, + "max_output_tokens": 64000, + "cost": { + "input": 5, + "output": 25, + "cache_read": 0.5, + "cache_write": 6.25 + }, + "source": "https://platform.claude.com/docs/en/build-with-claude/effort" + }, + { + "id": "claude-sonnet-4-5", + "name": "Claude Sonnet 4.5", + "aliases": [ + "claude-sonnet-4-5-20250929" + ], + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 200000, + "max_output_tokens": 64000, + "cost": { + "input": 3, + "output": 15, + "cache_read": 0.3, + "cache_write": 3.75 + }, + "source": "https://platform.claude.com/docs/en/models/sonnet-4-5/overview" + }, + { + "id": "claude-haiku-4-5", + "name": "Claude Haiku 4.5", + "aliases": [ + "claude-haiku-4-5-20251001" + ], + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 200000, + "max_output_tokens": 64000, + "cost": { + "input": 1, + "output": 5, + "cache_read": 0.1, + "cache_write": 1.25 + }, + "source": "https://docs.anthropic.com/en/docs/about-claude/models" + } + ], + "azure_openai": [ + { + "name": "GPT-6 deployments (reasoning, thinking always on)", + "match": "gpt-6*", + "reasoning": true, + "input": [ + "text", + "image" + ], + "source": "https://learn.microsoft.com/azure/ai-foundry/openai/how-to/reasoning" + }, + { + "name": "GPT-5 deployments (reasoning, no sampling parameters)", + "match": "gpt-5*", + "reasoning": true, + "input": [ + "text", + "image" + ], + "source": "https://learn.microsoft.com/azure/ai-foundry/openai/how-to/reasoning" + }, + { + "id": "gpt-5", + "name": "GPT-5 deployment (thinking cannot be disabled)", + "reasoning": true, + "input": [ + "text", + "image" + ], + "source": "https://developers.openai.com/api/docs/models/gpt-5" + }, + { + "id": "gpt-5-mini", + "name": "GPT-5 Mini deployment (thinking cannot be disabled)", + "reasoning": true, + "input": [ + "text", + "image" + ], + "source": "https://developers.openai.com/api/docs/models/gpt-5-mini" + }, + { + "id": "gpt-5-nano", + "name": "GPT-5 Nano deployment (thinking cannot be disabled)", + "reasoning": true, + "input": [ + "text", + "image" + ], + "source": "https://developers.openai.com/api/docs/models/gpt-5-nano" + }, + { + "name": "o1 deployments (always-on reasoning)", + "match": "o1*", + "reasoning": true, + "input": [ + "text", + "image" + ], + "source": "https://learn.microsoft.com/azure/ai-foundry/openai/how-to/reasoning" + }, + { + "name": "o3 deployments (always-on reasoning)", + "match": "o3*", + "reasoning": true, + "input": [ + "text", + "image" + ], + "source": "https://learn.microsoft.com/azure/ai-foundry/openai/how-to/reasoning" + }, + { + "name": "o4 deployments (always-on reasoning)", + "match": "o4*", + "reasoning": true, + "input": [ + "text", + "image" + ], + "source": "https://learn.microsoft.com/azure/ai-foundry/openai/how-to/reasoning" + }, + { + "name": "GPT-4o deployments", + "match": "gpt-4o*", + "reasoning": false, + "input": [ + "text", + "image" + ], + "source": "https://learn.microsoft.com/azure/ai-foundry/openai/how-to/reasoning" + }, + { + "name": "GPT-4.1 deployments", + "match": "gpt-4.1*", + "reasoning": false, + "input": [ + "text", + "image" + ], + "source": "https://learn.microsoft.com/azure/ai-foundry/openai/how-to/reasoning" + }, + { + "name": "text-embedding-3 deployments", + "match": "text-embedding-3*", + "type": "Embedding", + "source": "https://learn.microsoft.com/azure/ai-foundry/openai/how-to/reasoning" + } + ], + "deepseek": [ + { + "id": "deepseek-v4-pro", + "name": "DeepSeek V4 Pro", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1000000, + "max_output_tokens": 384000, + "cost": { + "input": 0.66, + "output": 1.98, + "cache_read": 0.022 + }, + "source": "https://api-docs.deepseek.com/quick_start/pricing" + }, + { + "id": "deepseek-flash", + "name": "DeepSeek V4.1 Flash", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 1000000, + "max_output_tokens": 384000, + "cost": { + "input": 0.15, + "output": 0.6, + "cache_read": 0.003 + }, + "source": "https://api-docs.deepseek.com/quick_start/pricing" + }, + { + "id": "deepseek-v4-flash", + "name": "DeepSeek V4 Flash (retired name, served by V4.1 Flash)", + "deprecated": true, + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 1000000, + "max_output_tokens": 384000, + "cost": { + "input": 0.15, + "output": 0.6, + "cache_read": 0.003 + }, + "source": "https://api-docs.deepseek.com/quick_start/pricing" + }, + { + "id": "deepseek-chat", + "name": "DeepSeek Chat (retired 2026-07-24, non-thinking alias)", + "deprecated": true, + "reasoning": false, + "input": [ + "text" + ], + "context_window": 128000, + "max_output_tokens": 8192, + "source": "https://api-docs.deepseek.com/news/news260424/" + }, + { + "id": "deepseek-reasoner", + "name": "DeepSeek Reasoner (retired 2026-07-24, thinking alias)", + "deprecated": true, + "reasoning": true, + "input": [ + "text" + ], + "context_window": 128000, + "max_output_tokens": 65536, + "source": "https://api-docs.deepseek.com/news/news260424/" + } + ], + "gemini": [ + { + "name": "Gemini 3 family (thinkingLevel)", + "match": "gemini-3*", + "reasoning": true, + "input": [ + "text", + "image", + "audio", + "video" + ], + "source": "https://ai.google.dev/gemini-api/docs/thinking" + }, + { + "id": "gemini-3.8-flash", + "name": "Gemini 3.8 Flash", + "reasoning": true, + "input": [ + "text", + "image", + "audio", + "video" + ], + "context_window": 1048576, + "max_output_tokens": 65536, + "cost": { + "input": 0.75, + "output": 3.75, + "cache_read": 0.075 + }, + "source": "https://ai.google.dev/gemini-api/docs/thinking" + }, + { + "id": "gemini-3.7-flash", + "name": "Gemini 3.7 Flash", + "reasoning": true, + "input": [ + "text", + "image", + "audio", + "video" + ], + "context_window": 1048576, + "max_output_tokens": 65536, + "cost": { + "input": 0.75, + "output": 3.75, + "cache_read": 0.075 + }, + "source": "https://ai.google.dev/gemini-api/docs/thinking" + }, + { + "id": "gemini-3.6-flash", + "name": "Gemini 3.6 Flash", + "reasoning": true, + "input": [ + "text", + "image", + "audio", + "video" + ], + "context_window": 1048576, + "max_output_tokens": 65536, + "cost": { + "input": 0.75, + "output": 3.75, + "cache_read": 0.075 + }, + "source": "https://ai.google.dev/gemini-api/docs/thinking" + }, + { + "id": "gemini-3.5-flash", + "name": "Gemini 3.5 Flash", + "reasoning": true, + "input": [ + "text", + "image", + "audio", + "video" + ], + "context_window": 1048576, + "max_output_tokens": 65536, + "cost": { + "input": 1.5, + "output": 9, + "cache_read": 0.15 + }, + "source": "https://ai.google.dev/gemini-api/docs/thinking" + }, + { + "id": "gemini-3.5-flash-lite", + "name": "Gemini 3.5 Flash Lite", + "reasoning": true, + "input": [ + "text", + "image", + "audio", + "video" + ], + "context_window": 1048576, + "max_output_tokens": 65536, + "cost": { + "input": 0.3, + "output": 2.5, + "cache_read": 0.03 + }, + "source": "https://ai.google.dev/gemini-api/docs/thinking" + }, + { + "id": "gemini-3.1-pro-preview", + "name": "Gemini 3.1 Pro Preview", + "reasoning": true, + "input": [ + "text", + "image", + "audio", + "video" + ], + "context_window": 1048576, + "max_output_tokens": 65536, + "cost": { + "input": 2, + "output": 12, + "cache_read": 0.2 + }, + "source": "https://ai.google.dev/gemini-api/docs/thinking" + }, + { + "id": "gemini-3.1-flash-lite", + "name": "Gemini 3.1 Flash Lite", + "reasoning": true, + "input": [ + "text", + "image", + "audio", + "video" + ], + "context_window": 1048576, + "max_output_tokens": 65536, + "cost": { + "input": 0.25, + "output": 1.5, + "cache_read": 0.025 + }, + "source": "https://ai.google.dev/gemini-api/docs/thinking" + }, + { + "id": "gemini-3-flash-preview", + "name": "Gemini 3 Flash Preview", + "reasoning": true, + "input": [ + "text", + "image", + "audio", + "video" + ], + "context_window": 1048576, + "max_output_tokens": 65536, + "cost": { + "input": 0.5, + "output": 3, + "cache_read": 0.05 + }, + "source": "https://ai.google.dev/gemini-api/docs/thinking" + }, + { + "id": "gemini-2.5-pro", + "name": "Gemini 2.5 Pro", + "reasoning": true, + "input": [ + "text", + "image", + "audio", + "video" + ], + "context_window": 1048576, + "max_output_tokens": 65536, + "cost": { + "input": 1.25, + "output": 10, + "cache_read": 0.125 + }, + "source": "https://ai.google.dev/gemini-api/docs/thinking" + }, + { + "id": "gemini-2.5-flash", + "name": "Gemini 2.5 Flash", + "reasoning": true, + "input": [ + "text", + "image", + "audio", + "video" + ], + "context_window": 1048576, + "max_output_tokens": 65536, + "cost": { + "input": 0.3, + "output": 2.5, + "cache_read": 0.03 + }, + "source": "https://ai.google.dev/gemini-api/docs/thinking" + }, + { + "id": "gemini-2.5-flash-lite", + "name": "Gemini 2.5 Flash Lite", + "reasoning": true, + "input": [ + "text", + "image", + "audio", + "video" + ], + "context_window": 1048576, + "max_output_tokens": 65536, + "cost": { + "input": 0.1, + "output": 0.4, + "cache_read": 0.01 + }, + "source": "https://ai.google.dev/gemini-api/docs/thinking" + }, + { + "id": "gemini-embedding-001", + "name": "Gemini Embedding 001", + "type": "Embedding", + "dimension": 3072, + "context_window": 2048, + "cost": { + "input": 0.15, + "output": 0 + }, + "source": "https://ai.google.dev/gemini-api/docs/embeddings" + }, + { + "id": "gemini-embedding-2", + "name": "Gemini Embedding 2", + "aliases": [ + "gemini-embedding-2-preview" + ], + "type": "Embedding", + "input": [ + "text", + "image", + "audio", + "video" + ], + "dimension": 3072, + "context_window": 8192, + "cost": { + "input": 0.2, + "output": 0 + }, + "source": "https://ai.google.dev/gemini-api/docs/embeddings" + } + ], + "generic": [ + { + "match": "gpt-5*", + "reasoning": true, + "source": "https://platform.openai.com/docs/guides/reasoning" + }, + { + "match": "o1*", + "reasoning": true, + "source": "https://platform.openai.com/docs/guides/reasoning" + }, + { + "match": "o3*", + "reasoning": true, + "source": "https://platform.openai.com/docs/guides/reasoning" + }, + { + "match": "o4*", + "reasoning": true, + "source": "https://platform.openai.com/docs/guides/reasoning" + } + ], + "gpustack": [], + "hunyuan": [ + { + "name": "Hunyuan T1 family (always-on reasoning)", + "match": "hunyuan-t1*", + "reasoning": true, + "input": [ + "text" + ], + "source": "https://cloud.tencent.com/document/product/1729/104753" + }, + { + "id": "hunyuan-t1-latest", + "name": "Hunyuan T1", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 32000, + "source": "https://cloud.tencent.com/document/product/1729/104753" + }, + { + "id": "hunyuan-t1-vision-20250916", + "name": "Hunyuan T1 Vision (deep thinking)", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 28000, + "max_output_tokens": 20000, + "source": "https://cloud.tencent.com/document/product/1729/104753" + }, + { + "id": "hunyuan-turbos-latest", + "name": "Hunyuan TurboS", + "reasoning": false, + "input": [ + "text" + ], + "context_window": 32000, + "max_output_tokens": 8000, + "cost": { + "input": 0.11, + "output": 0.28 + }, + "source": "https://cloud.tencent.com/document/product/1729/104753" + }, + { + "id": "hunyuan-a13b", + "name": "Hunyuan A13B (hybrid thinking)", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 224000, + "max_output_tokens": 32000, + "source": "https://cloud.tencent.com/document/product/1729/104753" + }, + { + "id": "hunyuan-2.0-thinking-20251109", + "name": "Hunyuan 2.0 Thinking", + "reasoning": true, + "input": [ + "text" + ], + "source": "https://cloud.tencent.com/document/product/1729/127293" + }, + { + "id": "hunyuan-2.0-instruct-20251111", + "name": "Hunyuan 2.0 Instruct", + "reasoning": false, + "input": [ + "text" + ], + "source": "https://cloud.tencent.com/document/product/1729/127293" + }, + { + "id": "hunyuan-vision-1.5-instruct", + "name": "Hunyuan Vision 1.5 Instruct (fast thinking)", + "reasoning": false, + "input": [ + "text", + "image" + ], + "context_window": 24000, + "max_output_tokens": 16000, + "source": "https://cloud.tencent.com/document/product/1729/104753" + }, + { + "id": "hunyuan-turbos-vision-video", + "name": "Hunyuan TurboS Vision Video", + "reasoning": false, + "input": [ + "text", + "image", + "video" + ], + "context_window": 24000, + "max_output_tokens": 8000, + "source": "https://cloud.tencent.com/document/product/1729/104753" + }, + { + "id": "hunyuan-turbos-vision", + "name": "Hunyuan TurboS Vision", + "reasoning": false, + "input": [ + "text", + "image" + ], + "context_window": 32000, + "max_output_tokens": 8000, + "source": "https://cloud.tencent.com/document/product/1729/104753" + }, + { + "id": "hunyuan-lite", + "name": "Hunyuan Lite", + "reasoning": false, + "input": [ + "text" + ], + "context_window": 256000, + "max_output_tokens": 6000, + "cost": { + "input": 0, + "output": 0 + }, + "source": "https://cloud.tencent.com/document/product/1729/104753" + }, + { + "id": "hunyuan-embedding", + "name": "Hunyuan Embedding", + "type": "Embedding", + "dimension": 1024, + "source": "https://cloud.tencent.com/document/product/1729/111007" + } + ], + "jina": [ + { + "id": "jina-embeddings-v5-omni-small", + "name": "Jina Embeddings v5 Omni Small (multimodal)", + "type": "Embedding", + "input": [ + "text", + "image" + ], + "dimension": 1024, + "context_window": 32768, + "source": "https://jina.ai/models/" + }, + { + "id": "jina-embeddings-v5-omni-nano", + "name": "Jina Embeddings v5 Omni Nano (multimodal)", + "type": "Embedding", + "input": [ + "text", + "image" + ], + "dimension": 768, + "context_window": 8192, + "source": "https://jina.ai/models/" + }, + { + "id": "jina-embeddings-v5-text-small", + "name": "Jina Embeddings v5 Text Small", + "type": "Embedding", + "dimension": 1024, + "context_window": 32768, + "source": "https://jina.ai/models/" + }, + { + "id": "jina-embeddings-v5-text-nano", + "name": "Jina Embeddings v5 Text Nano", + "type": "Embedding", + "dimension": 768, + "context_window": 8192, + "source": "https://jina.ai/models/" + }, + { + "id": "jina-embeddings-v4", + "name": "Jina Embeddings v4", + "type": "Embedding", + "dimension": 2048, + "context_window": 32768, + "source": "https://jina.ai/models/jina-embeddings-v4/" + }, + { + "id": "jina-embeddings-v3", + "name": "Jina Embeddings v3", + "type": "Embedding", + "dimension": 1024, + "context_window": 8192, + "source": "https://jina.ai/models/jina-embeddings-v3/" + }, + { + "id": "jina-code-embeddings-1.5b", + "name": "Jina Code Embeddings 1.5B", + "type": "Embedding", + "dimension": 1536, + "context_window": 32768, + "source": "https://jina.ai/models/" + }, + { + "id": "jina-code-embeddings-0.5b", + "name": "Jina Code Embeddings 0.5B", + "type": "Embedding", + "dimension": 896, + "context_window": 32768, + "source": "https://jina.ai/models/" + }, + { + "id": "jina-reranker-v3.5", + "name": "Jina Reranker v3.5", + "type": "Rerank", + "context_window": 131072, + "source": "https://jina.ai/reranker/" + }, + { + "id": "jina-reranker-v3", + "name": "Jina Reranker v3", + "type": "Rerank", + "context_window": 131072, + "source": "https://jina.ai/models/jina-reranker-v3/" + }, + { + "id": "jina-reranker-m0", + "name": "Jina Reranker m0 (multimodal)", + "type": "Rerank", + "context_window": 10000, + "source": "https://jina.ai/reranker/" + }, + { + "id": "jina-reranker-v2-base-multilingual", + "name": "Jina Reranker v2 Base Multilingual", + "type": "Rerank", + "context_window": 1024, + "source": "https://jina.ai/reranker/" + } + ], + "litellm": [], + "lkeap": [ + { + "name": "DeepSeek R1 family (always-on reasoning)", + "match": "*deepseek-r1*", + "reasoning": true, + "input": [ + "text" + ], + "source": "https://cloud.tencent.com/document/product/1772/115963" + }, + { + "name": "DeepSeek V3 family (thinking switch)", + "match": "*deepseek-v3*", + "reasoning": true, + "input": [ + "text" + ], + "source": "https://cloud.tencent.com/document/product/1772/115963" + }, + { + "id": "deepseek-v3.2", + "name": "DeepSeek V3.2", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 131072, + "max_output_tokens": 32768, + "source": "https://cloud.tencent.com/document/product/1772/115963" + }, + { + "id": "deepseek-v3.1-terminus", + "name": "DeepSeek V3.1 Terminus", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 131072, + "max_output_tokens": 32768, + "source": "https://cloud.tencent.com/document/product/1772/115963" + }, + { + "id": "deepseek-r1-0528", + "name": "DeepSeek R1 (0528)", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 131072, + "max_output_tokens": 16384, + "source": "https://cloud.tencent.com/document/product/1772/115963" + }, + { + "id": "deepseek-v3-0324", + "name": "DeepSeek V3 (0324)", + "reasoning": false, + "input": [ + "text" + ], + "context_window": 131072, + "max_output_tokens": 16384, + "source": "https://cloud.tencent.com/document/product/1772/115963" + }, + { + "id": "deepseek-r1", + "name": "DeepSeek R1", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 65536, + "max_output_tokens": 16384, + "source": "https://cloud.tencent.com/document/product/1772/115963" + }, + { + "id": "deepseek-v3", + "name": "DeepSeek V3", + "reasoning": false, + "input": [ + "text" + ], + "context_window": 65536, + "max_output_tokens": 16384, + "source": "https://cloud.tencent.com/document/product/1772/115963" + }, + { + "id": "deepseek-v3.1", + "name": "DeepSeek V3.1", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 131072, + "max_output_tokens": 32768, + "source": "https://cloud.tencent.com/document/product/1772/115963" + }, + { + "id": "lke-reranker-base", + "name": "LKE Reranker Base", + "type": "Rerank", + "source": "https://cloud.tencent.com/document/product/1772/115339" + } + ], + "longcat": [ + { + "id": "LongCat-2.0", + "name": "LongCat 2.0", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1000000, + "max_output_tokens": 131072, + "cost": { + "input": 0.75, + "output": 2.95, + "cache_read": 0.015 + }, + "source": "https://longcat.chat/platform/docs/zh/api/chat.html" + }, + { + "id": "LongCat-Flash-Chat", + "name": "LongCat Flash Chat (retired 2026-05-29)", + "deprecated": true, + "reasoning": false, + "input": [ + "text" + ], + "context_window": 262144, + "max_output_tokens": 8192, + "source": "https://longcat.chat/platform/docs/zh/ChangeLog.html" + }, + { + "id": "LongCat-Flash-Thinking", + "name": "LongCat Flash Thinking (retired 2026-05-29)", + "deprecated": true, + "reasoning": true, + "input": [ + "text" + ], + "context_window": 131072, + "max_output_tokens": 65536, + "source": "https://longcat.chat/platform/docs/zh/ChangeLog.html" + } + ], + "mimo": [ + { + "id": "mimo-v2.5-pro", + "name": "MiMo V2.5 Pro", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1048576, + "max_output_tokens": 131072, + "cost": { + "input": 0.435, + "output": 0.87, + "cache_read": 0.0036 + }, + "source": "https://mimo.mi.com/static/docs/price/pay-as-you-go.md" + }, + { + "id": "mimo-v2.5", + "name": "MiMo V2.5", + "reasoning": true, + "input": [ + "text", + "image", + "audio", + "video" + ], + "context_window": 1048576, + "max_output_tokens": 131072, + "cost": { + "input": 0.14, + "output": 0.28, + "cache_read": 0.0028 + }, + "source": "https://mimo.mi.com/static/docs/price/pay-as-you-go.md" + }, + { + "id": "mimo-v2.5-pro-ultraspeed", + "name": "MiMo V2.5 Pro Ultraspeed", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1048576, + "max_output_tokens": 131072, + "cost": { + "input": 1.305, + "output": 2.61, + "cache_read": 0.0108 + }, + "source": "https://mimo.mi.com/static/docs/news/latest/beta-extended.md" + }, + { + "id": "mimo-v2-flash", + "name": "MiMo V2 Flash (retired 2026-06-30)", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 256000, + "max_output_tokens": 256000, + "cost": { + "input": 0.1, + "output": 0.3, + "cache_read": 0.01 + }, + "deprecated": true, + "source": "https://mimo.mi.com/static/docs/updates/deprecate.md" + }, + { + "id": "mimo-v2.5-asr", + "name": "MiMo V2.5 ASR", + "type": "ASR", + "source": "https://mimo.mi.com/docs/en-US/quick-start/usage-guide/audio/Speech-Recognition" + } + ], + "minimax": [ + { + "id": "MiniMax-M3", + "name": "MiniMax M3", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 1000000, + "max_output_tokens": 512000, + "cost": { + "input": 0.3, + "output": 1.2, + "cache_read": 0.06 + }, + "source": "https://platform.minimax.io/docs/guides/text-generation" + }, + { + "id": "MiniMax-M2.7", + "name": "MiniMax M2.7", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 204800, + "max_output_tokens": 131072, + "cost": { + "input": 0.3, + "output": 1.2, + "cache_read": 0.06, + "cache_write": 0.375 + }, + "source": "https://platform.minimax.io/docs/api-reference/text-openai-api" + }, + { + "id": "MiniMax-M2.7-highspeed", + "name": "MiniMax M2.7 Highspeed", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 204800, + "max_output_tokens": 131072, + "cost": { + "input": 0.6, + "output": 2.4, + "cache_read": 0.06, + "cache_write": 0.375 + }, + "source": "https://platform.minimax.io/docs/api-reference/text-openai-api" + }, + { + "id": "MiniMax-M2.5", + "name": "MiniMax M2.5", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 204800, + "max_output_tokens": 131072, + "cost": { + "input": 0.3, + "output": 1.2, + "cache_read": 0.03, + "cache_write": 0.375 + }, + "source": "https://platform.minimax.io/docs/api-reference/text-openai-api" + }, + { + "id": "MiniMax-M2.5-highspeed", + "name": "MiniMax M2.5 Highspeed", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 204800, + "max_output_tokens": 131072, + "cost": { + "input": 0.6, + "output": 2.4, + "cache_read": 0.06, + "cache_write": 0.375 + }, + "source": "https://platform.minimax.io/docs/api-reference/text-openai-api" + }, + { + "id": "MiniMax-M2.1", + "name": "MiniMax M2.1", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 204800, + "max_output_tokens": 131072, + "cost": { + "input": 0.3, + "output": 1.2, + "cache_read": 0.03, + "cache_write": 0.375 + }, + "source": "https://platform.minimax.io/docs/api-reference/text-openai-api" + }, + { + "id": "MiniMax-M2.1-highspeed", + "name": "MiniMax M2.1 Highspeed", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 204800, + "max_output_tokens": 131072, + "source": "https://platform.minimax.io/docs/guides/text-generation" + }, + { + "id": "MiniMax-M2", + "name": "MiniMax M2", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 204800, + "max_output_tokens": 131072, + "cost": { + "input": 0.3, + "output": 1.2 + }, + "source": "https://platform.minimax.io/docs/api-reference/text-openai-api" + }, + { + "id": "asr-1.0", + "name": "MiniMax ASR 1.0", + "type": "ASR", + "source": "https://platform.minimax.io/docs/api-reference/speech-to-text" + } + ], + "modelscope": [ + { + "id": "ZhipuAI/GLM-4.6", + "name": "GLM-4.6", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 202752, + "max_output_tokens": 98304, + "cost": { + "input": 0, + "output": 0 + }, + "source": "https://modelscope.cn/models/ZhipuAI/GLM-4.6" + }, + { + "id": "ZhipuAI/GLM-4.5", + "name": "GLM-4.5", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 131072, + "max_output_tokens": 98304, + "cost": { + "input": 0, + "output": 0 + }, + "source": "https://modelscope.cn/models/ZhipuAI/GLM-4.5" + }, + { + "id": "Qwen/Qwen3-235B-A22B-Instruct-2507", + "name": "Qwen3 235B-A22B Instruct 2507", + "reasoning": false, + "input": [ + "text" + ], + "context_window": 262144, + "max_output_tokens": 131072, + "cost": { + "input": 0, + "output": 0 + }, + "source": "https://modelscope.cn/models/Qwen/Qwen3-235B-A22B-Instruct-2507" + }, + { + "id": "Qwen/Qwen3-235B-A22B-Thinking-2507", + "name": "Qwen3 235B-A22B Thinking 2507", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 262144, + "max_output_tokens": 131072, + "cost": { + "input": 0, + "output": 0 + }, + "source": "https://modelscope.cn/models/Qwen/Qwen3-235B-A22B-Thinking-2507" + }, + { + "id": "Qwen/Qwen3-30B-A3B-Instruct-2507", + "name": "Qwen3 30B-A3B Instruct 2507", + "reasoning": false, + "input": [ + "text" + ], + "context_window": 262144, + "max_output_tokens": 16384, + "cost": { + "input": 0, + "output": 0 + }, + "source": "https://modelscope.cn/models/Qwen/Qwen3-30B-A3B-Instruct-2507" + }, + { + "id": "Qwen/Qwen3-30B-A3B-Thinking-2507", + "name": "Qwen3 30B-A3B Thinking 2507", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 262144, + "max_output_tokens": 32768, + "cost": { + "input": 0, + "output": 0 + }, + "source": "https://modelscope.cn/models/Qwen/Qwen3-30B-A3B-Thinking-2507" + }, + { + "id": "Qwen/Qwen3-Coder-30B-A3B-Instruct", + "name": "Qwen3 Coder 30B-A3B Instruct", + "reasoning": false, + "input": [ + "text" + ], + "context_window": 262144, + "max_output_tokens": 65536, + "cost": { + "input": 0, + "output": 0 + }, + "source": "https://modelscope.cn/models/Qwen/Qwen3-Coder-30B-A3B-Instruct" + }, + { + "id": "Qwen/Qwen3-8B", + "name": "Qwen3 8B (hybrid thinking)", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 131072, + "max_output_tokens": 32768, + "cost": { + "input": 0, + "output": 0 + }, + "source": "https://modelscope.cn/models/Qwen/Qwen3-8B" + }, + { + "id": "Qwen/Qwen3-VL-235B-A22B-Instruct", + "name": "Qwen3 VL 235B-A22B Instruct", + "reasoning": false, + "input": [ + "text", + "image" + ], + "context_window": 262144, + "max_output_tokens": 32768, + "cost": { + "input": 0, + "output": 0 + }, + "source": "https://modelscope.cn/models/Qwen/Qwen3-VL-235B-A22B-Instruct" + }, + { + "id": "Qwen/Qwen3-Embedding-8B", + "name": "Qwen3 Embedding 8B", + "type": "Embedding", + "dimension": 4096, + "source": "https://modelscope.cn/models/Qwen/Qwen3-Embedding-8B" + }, + { + "id": "Qwen/Qwen3-Embedding-0.6B", + "name": "Qwen3 Embedding 0.6B", + "type": "Embedding", + "dimension": 1024, + "source": "https://modelscope.cn/models/Qwen/Qwen3-Embedding-0.6B" + } + ], + "moonshot": [ + { + "id": "kimi-k3", + "name": "Kimi K3", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 1048576, + "max_output_tokens": 131072, + "cost": { + "input": 3, + "output": 15, + "cache_read": 0.3 + }, + "source": "https://platform.kimi.com/docs/guide/kimi-k3-quickstart" + }, + { + "id": "kimi-k2.7-code", + "name": "Kimi K2.7 Code", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 262144, + "max_output_tokens": 262144, + "cost": { + "input": 0.95, + "output": 4, + "cache_read": 0.19 + }, + "source": "https://platform.kimi.com/docs/guide/kimi-k2-7-code-quickstart" + }, + { + "id": "kimi-k2.7-code-highspeed", + "name": "Kimi K2.7 Code Highspeed", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 262144, + "max_output_tokens": 262144, + "cost": { + "input": 1.9, + "output": 8, + "cache_read": 0.38 + }, + "source": "https://platform.kimi.com/docs/guide/kimi-k2-7-code-quickstart" + }, + { + "id": "kimi-k2.6", + "name": "Kimi K2.6", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 262144, + "max_output_tokens": 262144, + "cost": { + "input": 0.95, + "output": 4, + "cache_read": 0.16 + }, + "source": "https://platform.kimi.com/docs/guide/kimi-k2-6-quickstart" + }, + { + "name": "moonshot-v1 family (retired 2026-08-31)", + "match": "moonshot-v1*", + "reasoning": false, + "input": [ + "text" + ], + "deprecated": true, + "source": "https://platform.kimi.com/docs/models" + }, + { + "id": "kimi-k2.5", + "name": "Kimi K2.5 (retired 2026-08-31)", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 262144, + "max_output_tokens": 262144, + "cost": { + "input": 0.6, + "output": 3, + "cache_read": 0.1 + }, + "deprecated": true, + "source": "https://platform.kimi.com/docs/models" + }, + { + "id": "kimi-k2-thinking", + "name": "Kimi K2 Thinking (retired 2026-08-31)", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 262144, + "max_output_tokens": 16384, + "cost": { + "input": 0.574, + "output": 2.294 + }, + "deprecated": true, + "source": "https://platform.kimi.com/docs/models" + }, + { + "id": "kimi-k2-turbo-preview", + "name": "Kimi K2 Turbo (retired 2026-08-31)", + "reasoning": false, + "input": [ + "text" + ], + "context_window": 262144, + "max_output_tokens": 16384, + "deprecated": true, + "source": "https://platform.kimi.com/docs/models" + }, + { + "id": "moonshot-v1-8k", + "name": "Moonshot v1 8K (retired 2026-08-31)", + "reasoning": false, + "input": [ + "text" + ], + "context_window": 8192, + "max_output_tokens": 8192, + "deprecated": true, + "source": "https://platform.kimi.com/docs/models" + }, + { + "id": "moonshot-v1-32k", + "name": "Moonshot v1 32K (retired 2026-08-31)", + "reasoning": false, + "input": [ + "text" + ], + "context_window": 32768, + "max_output_tokens": 32768, + "deprecated": true, + "source": "https://platform.kimi.com/docs/models" + }, + { + "id": "moonshot-v1-128k", + "name": "Moonshot v1 128K (retired 2026-08-31)", + "reasoning": false, + "input": [ + "text" + ], + "context_window": 131072, + "max_output_tokens": 131072, + "deprecated": true, + "source": "https://platform.kimi.com/docs/models" + }, + { + "id": "moonshot-v1-8k-vision-preview", + "name": "Moonshot v1 8K Vision (retired 2026-08-31)", + "reasoning": false, + "input": [ + "text", + "image" + ], + "context_window": 8192, + "max_output_tokens": 8192, + "deprecated": true, + "source": "https://platform.kimi.com/docs/models" + } + ], + "novita": [ + { + "id": "moonshotai/kimi-k3", + "name": "Kimi K3", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 1048576, + "max_output_tokens": 1048576, + "cost": { + "input": 3, + "output": 15, + "cache_read": 0.3 + }, + "source": "https://docs.novita.ai/api-reference/model-apis-llm-chat-completions-api" + }, + { + "id": "zai-org/glm-5.2", + "name": "GLM-5.2", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1048576, + "max_output_tokens": 131072, + "cost": { + "input": 1.4, + "output": 4.4, + "cache_read": 0.26 + }, + "source": "https://docs.novita.ai/api-reference/model-apis-llm-chat-completions-api" + }, + { + "id": "zai-org/glm-5.1", + "name": "GLM-5.1", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 204800, + "max_output_tokens": 131072, + "cost": { + "input": 1.38, + "output": 4.4, + "cache_read": 0.26 + }, + "source": "https://docs.novita.ai/api-reference/model-apis-llm-chat-completions-api" + }, + { + "id": "deepseek/deepseek-v4-pro", + "name": "DeepSeek V4 Pro", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1048576, + "max_output_tokens": 393216, + "cost": { + "input": 1.6, + "output": 3.2, + "cache_read": 0.135 + }, + "source": "https://docs.novita.ai/api-reference/model-apis-llm-chat-completions-api" + }, + { + "id": "deepseek/deepseek-v4-flash", + "name": "DeepSeek V4 Flash", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1048576, + "max_output_tokens": 393216, + "cost": { + "input": 0.14, + "output": 0.28, + "cache_read": 0.028 + }, + "source": "https://docs.novita.ai/api-reference/model-apis-llm-chat-completions-api" + }, + { + "id": "moonshotai/kimi-k2.6", + "name": "Kimi K2.6", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 262144, + "max_output_tokens": 262144, + "cost": { + "input": 0.8, + "output": 3.4, + "cache_read": 0.16 + }, + "source": "https://docs.novita.ai/api-reference/model-apis-llm-chat-completions-api" + }, + { + "id": "moonshotai/kimi-k2.7-code", + "name": "Kimi K2.7 Code", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 262144, + "max_output_tokens": 262144, + "cost": { + "input": 0.95, + "output": 4, + "cache_read": 0.19 + }, + "source": "https://docs.novita.ai/api-reference/model-apis-llm-chat-completions-api" + }, + { + "id": "qwen/qwen3.7-max", + "name": "Qwen3.7 Max", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1000000, + "max_output_tokens": 65536, + "cost": { + "input": 1.25, + "output": 3.75, + "cache_read": 0.25, + "cache_write": 1.5625 + }, + "source": "https://docs.novita.ai/api-reference/model-apis-llm-chat-completions-api" + }, + { + "id": "qwen/qwen3.5-397b-a17b", + "name": "Qwen3.5 397B-A17B", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 262144, + "max_output_tokens": 65536, + "cost": { + "input": 0.6, + "output": 3.6 + }, + "source": "https://docs.novita.ai/api-reference/model-apis-llm-chat-completions-api" + }, + { + "id": "minimax/minimax-m2.7", + "name": "MiniMax M2.7", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 204800, + "max_output_tokens": 131072, + "cost": { + "input": 0.3, + "output": 1.2, + "cache_read": 0.06 + }, + "source": "https://docs.novita.ai/api-reference/model-apis-llm-chat-completions-api" + }, + { + "id": "xiaomimimo/mimo-v2.5-pro", + "name": "MiMo V2.5 Pro", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1048576, + "max_output_tokens": 131072, + "cost": { + "input": 0.522, + "output": 1.044, + "cache_read": 0.0043 + }, + "source": "https://docs.novita.ai/api-reference/model-apis-llm-chat-completions-api" + }, + { + "id": "google/gemma-4-31b-it", + "name": "Gemma 4 31B IT", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 262144, + "max_output_tokens": 131072, + "cost": { + "input": 0.14, + "output": 0.4 + }, + "source": "https://docs.novita.ai/api-reference/model-apis-llm-chat-completions-api" + }, + { + "id": "qwen/qwen3-embedding-0.6b", + "name": "Qwen3 Embedding 0.6B", + "type": "Embedding", + "dimension": 1024, + "context_window": 32768, + "source": "https://docs.novita.ai/api-reference/model-apis-llm-chat-completions-api" + }, + { + "id": "qwen/qwen3-embedding-8b", + "name": "Qwen3 Embedding 8B", + "type": "Embedding", + "dimension": 4096, + "context_window": 32768, + "source": "https://docs.novita.ai/api-reference/model-apis-llm-chat-completions-api" + }, + { + "id": "baai/bge-m3", + "name": "BGE-M3", + "type": "Embedding", + "dimension": 1024, + "context_window": 8192, + "source": "https://docs.novita.ai/api-reference/model-apis-llm-chat-completions-api" + } + ], + "nvidia": [ + { + "id": "nvidia/nemotron-3-ultra-550b-a55b", + "name": "Nemotron 3 Ultra 550B-A55B", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1000000, + "max_output_tokens": 65536, + "cost": { + "input": 0.5, + "output": 2.5, + "cache_read": 0.15 + }, + "source": "https://build.nvidia.com" + }, + { + "id": "nvidia/nemotron-3-super-120b-a12b", + "name": "Nemotron 3 Super 120B-A12B", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1000000, + "max_output_tokens": 262144, + "cost": { + "input": 0.2, + "output": 0.8 + }, + "source": "https://build.nvidia.com" + }, + { + "id": "nvidia/nemotron-3.5-lightning-30b-a3b", + "name": "Nemotron 3.5 Lightning 30B-A3B", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 262144, + "max_output_tokens": 262144, + "cost": { + "input": 0, + "output": 0 + }, + "source": "https://build.nvidia.com" + }, + { + "id": "z-ai/glm-5.3", + "name": "GLM-5.3", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1000000, + "max_output_tokens": 131072, + "cost": { + "input": 0, + "output": 0 + }, + "source": "https://build.nvidia.com" + }, + { + "id": "deepseek-ai/deepseek-v4-pro-0813", + "name": "DeepSeek V4 Pro", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1048576, + "max_output_tokens": 393216, + "cost": { + "input": 0.435, + "output": 0.87, + "cache_read": 0.003625 + }, + "source": "https://build.nvidia.com" + }, + { + "id": "deepseek-ai/deepseek-v4-flash-0731", + "name": "DeepSeek V4 Flash", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1048576, + "max_output_tokens": 393216, + "cost": { + "input": 0.14, + "output": 0.28, + "cache_read": 0.0028 + }, + "source": "https://build.nvidia.com" + }, + { + "id": "moonshotai/kimi-k3", + "name": "Kimi K3", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 1048576, + "max_output_tokens": 131072, + "cost": { + "input": 0, + "output": 0 + }, + "source": "https://build.nvidia.com" + }, + { + "id": "moonshotai/kimi-k2.6", + "name": "Kimi K2.6", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 262144, + "max_output_tokens": 262144, + "cost": { + "input": 0, + "output": 0 + }, + "source": "https://build.nvidia.com" + }, + { + "id": "google/gemma-4-31b-it", + "name": "Gemma 4 31B IT", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 256000, + "max_output_tokens": 16384, + "cost": { + "input": 0, + "output": 0 + }, + "source": "https://build.nvidia.com" + }, + { + "id": "nvidia/nemotron-3-embed-1b", + "name": "Nemotron 3 Embed 1B", + "type": "Embedding", + "dimension": 2048, + "context_window": 4096, + "source": "https://docs.api.nvidia.com/nim/reference/nvidia-nemotron-3-embed-1b-infer" + }, + { + "id": "nvidia/llama-nemotron-rerank-vl-1b-v2", + "name": "Llama Nemotron Rerank VL 1B v2", + "type": "Rerank", + "source": "https://build.nvidia.com" + }, + { + "id": "nvidia/nv-rerankqa-mistral-4b-v3", + "name": "NV-RerankQA Mistral 4B v3", + "type": "Rerank", + "source": "https://build.nvidia.com" + } + ], + "openai": [ + { + "name": "GPT-6 family (reasoning, no sampling parameters, thinking always on)", + "match": "gpt-6*", + "reasoning": true, + "input": [ + "text", + "image" + ], + "source": "https://developers.openai.com/api/docs/guides/latest-model" + }, + { + "name": "GPT-5 family (reasoning, no sampling parameters)", + "match": "gpt-5*", + "reasoning": true, + "input": [ + "text", + "image" + ], + "source": "https://developers.openai.com/api/docs/guides/reasoning" + }, + { + "name": "o1 family (always-on reasoning)", + "match": "o1*", + "reasoning": true, + "input": [ + "text", + "image" + ], + "source": "https://developers.openai.com/api/docs/models" + }, + { + "name": "o3 family (always-on reasoning)", + "match": "o3*", + "reasoning": true, + "input": [ + "text", + "image" + ], + "source": "https://developers.openai.com/api/docs/models" + }, + { + "name": "o4 family (always-on reasoning)", + "match": "o4*", + "reasoning": true, + "input": [ + "text", + "image" + ], + "source": "https://developers.openai.com/api/docs/models" + }, + { + "id": "gpt-6-astra", + "name": "GPT-6 Astra", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 1050000, + "max_output_tokens": 128000, + "cost": { + "input": 10, + "output": 50, + "cache_read": 1, + "cache_write": 12.5 + }, + "source": "https://developers.openai.com/api/docs/models" + }, + { + "id": "gpt-5.6-terra", + "name": "GPT-5.6 Terra", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 1050000, + "max_output_tokens": 128000, + "cost": { + "input": 2, + "output": 12, + "cache_read": 0.2, + "cache_write": 2.5 + }, + "source": "https://developers.openai.com/api/docs/models" + }, + { + "id": "gpt-5.6-sol", + "name": "GPT-5.6 Sol", + "aliases": [ + "gpt-5.6" + ], + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 1050000, + "max_output_tokens": 128000, + "cost": { + "input": 4, + "output": 20, + "cache_read": 0.4, + "cache_write": 5 + }, + "source": "https://developers.openai.com/api/docs/models" + }, + { + "id": "gpt-5.6-luna", + "name": "GPT-5.6 Luna", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 1050000, + "max_output_tokens": 128000, + "cost": { + "input": 0.2, + "output": 1.2, + "cache_read": 0.02, + "cache_write": 0.25 + }, + "source": "https://developers.openai.com/api/docs/models" + }, + { + "id": "gpt-5.5", + "name": "GPT-5.5", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 1050000, + "max_output_tokens": 128000, + "cost": { + "input": 5, + "output": 30, + "cache_read": 0.5 + }, + "source": "https://developers.openai.com/api/docs/models" + }, + { + "id": "gpt-5.4", + "name": "GPT-5.4", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 1050000, + "max_output_tokens": 128000, + "cost": { + "input": 2.5, + "output": 15, + "cache_read": 0.25 + }, + "source": "https://developers.openai.com/api/docs/models" + }, + { + "id": "gpt-5.4-mini", + "name": "GPT-5.4 Mini", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 400000, + "max_output_tokens": 128000, + "cost": { + "input": 0.75, + "output": 4.5, + "cache_read": 0.075 + }, + "source": "https://developers.openai.com/api/docs/models" + }, + { + "id": "gpt-5.4-nano", + "name": "GPT-5.4 Nano", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 400000, + "max_output_tokens": 128000, + "cost": { + "input": 0.2, + "output": 1.25, + "cache_read": 0.02 + }, + "source": "https://developers.openai.com/api/docs/models" + }, + { + "id": "gpt-5.2", + "name": "GPT-5.2", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 400000, + "max_output_tokens": 128000, + "cost": { + "input": 1.75, + "output": 14, + "cache_read": 0.175 + }, + "source": "https://developers.openai.com/api/docs/models" + }, + { + "id": "gpt-5.1", + "name": "GPT-5.1", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 400000, + "max_output_tokens": 128000, + "cost": { + "input": 1.25, + "output": 10, + "cache_read": 0.125 + }, + "source": "https://developers.openai.com/api/docs/models" + }, + { + "id": "gpt-5", + "name": "GPT-5", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 400000, + "max_output_tokens": 128000, + "cost": { + "input": 1.25, + "output": 10, + "cache_read": 0.125 + }, + "source": "https://developers.openai.com/api/docs/models" + }, + { + "id": "gpt-5-mini", + "name": "GPT-5 Mini", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 400000, + "max_output_tokens": 128000, + "cost": { + "input": 0.25, + "output": 2, + "cache_read": 0.025 + }, + "source": "https://developers.openai.com/api/docs/models" + }, + { + "id": "gpt-5-nano", + "name": "GPT-5 Nano", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 400000, + "max_output_tokens": 128000, + "cost": { + "input": 0.05, + "output": 0.4, + "cache_read": 0.005 + }, + "source": "https://developers.openai.com/api/docs/models" + }, + { + "id": "o3", + "name": "o3", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 200000, + "max_output_tokens": 100000, + "cost": { + "input": 2, + "output": 8, + "cache_read": 0.5 + }, + "source": "https://developers.openai.com/api/docs/models" + }, + { + "id": "gpt-4.1", + "name": "GPT-4.1", + "reasoning": false, + "input": [ + "text", + "image" + ], + "context_window": 1047576, + "max_output_tokens": 32768, + "cost": { + "input": 2, + "output": 8, + "cache_read": 0.5 + }, + "source": "https://developers.openai.com/api/docs/models" + }, + { + "id": "gpt-4.1-mini", + "name": "GPT-4.1 Mini", + "reasoning": false, + "input": [ + "text", + "image" + ], + "context_window": 1047576, + "max_output_tokens": 32768, + "cost": { + "input": 0.4, + "output": 1.6, + "cache_read": 0.1 + }, + "source": "https://developers.openai.com/api/docs/models" + }, + { + "id": "gpt-4o", + "name": "GPT-4o", + "aliases": [ + "gpt-4o-2024-11-20", + "gpt-4o-2024-08-06" + ], + "reasoning": false, + "input": [ + "text", + "image" + ], + "context_window": 128000, + "max_output_tokens": 16384, + "cost": { + "input": 2.5, + "output": 10, + "cache_read": 1.25 + }, + "source": "https://developers.openai.com/api/docs/models" + }, + { + "id": "gpt-4o-mini", + "name": "GPT-4o Mini", + "reasoning": false, + "input": [ + "text", + "image" + ], + "context_window": 128000, + "max_output_tokens": 16384, + "cost": { + "input": 0.15, + "output": 0.6, + "cache_read": 0.075 + }, + "source": "https://developers.openai.com/api/docs/models" + }, + { + "id": "text-embedding-3-small", + "name": "text-embedding-3-small", + "type": "Embedding", + "dimension": 1536, + "context_window": 8191, + "cost": { + "input": 0.02, + "output": 0 + }, + "source": "https://developers.openai.com/api/docs/models" + }, + { + "id": "text-embedding-3-large", + "name": "text-embedding-3-large", + "type": "Embedding", + "dimension": 3072, + "context_window": 8191, + "cost": { + "input": 0.13, + "output": 0 + }, + "source": "https://developers.openai.com/api/docs/models" + }, + { + "id": "whisper-1", + "name": "Whisper", + "type": "ASR", + "source": "https://developers.openai.com/api/reference/resources/audio/subresources/transcriptions/methods/create" + }, + { + "id": "gpt-transcribe", + "name": "GPT Transcribe", + "type": "ASR", + "source": "https://developers.openai.com/api/reference/resources/audio/subresources/transcriptions/methods/create" + }, + { + "id": "gpt-4o-transcribe", + "name": "GPT-4o Transcribe", + "type": "ASR", + "source": "https://developers.openai.com/api/reference/resources/audio/subresources/transcriptions/methods/create" + }, + { + "id": "gpt-4o-mini-transcribe", + "name": "GPT-4o mini Transcribe", + "type": "ASR", + "source": "https://developers.openai.com/api/reference/resources/audio/subresources/transcriptions/methods/create" + }, + { + "id": "text-embedding-ada-002", + "name": "text-embedding-ada-002", + "type": "Embedding", + "dimension": 1536, + "context_window": 8192, + "cost": { + "input": 0.1, + "output": 0 + }, + "source": "https://developers.openai.com/api/docs/models" + } + ], + "openrouter": [ + { + "name": "Anthropic models (cache_control breakpoints, thinking always on)", + "match": "anthropic/*", + "reasoning": true, + "input": [ + "text", + "image" + ], + "source": "https://openrouter.ai/docs/guides/best-practices/reasoning-tokens" + }, + { + "id": "openai/gpt-5.5", + "name": "GPT-5.5", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 1050000, + "max_output_tokens": 128000, + "cost": { + "input": 5, + "output": 30, + "cache_read": 0.5 + }, + "source": "https://openrouter.ai/docs/guides/best-practices/reasoning-tokens" + }, + { + "id": "openai/gpt-5.4", + "name": "GPT-5.4", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 1050000, + "max_output_tokens": 128000, + "cost": { + "input": 2.5, + "output": 15, + "cache_read": 0.25 + }, + "source": "https://openrouter.ai/docs/guides/best-practices/reasoning-tokens" + }, + { + "id": "anthropic/claude-opus-5", + "name": "Claude Opus 5", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 1000000, + "max_output_tokens": 128000, + "cost": { + "input": 5, + "output": 25, + "cache_read": 0.5, + "cache_write": 6.25 + }, + "source": "https://openrouter.ai/docs/guides/best-practices/reasoning-tokens" + }, + { + "id": "anthropic/claude-sonnet-5", + "name": "Claude Sonnet 5", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 1000000, + "max_output_tokens": 128000, + "cost": { + "input": 2, + "output": 10, + "cache_read": 0.2, + "cache_write": 2.5 + }, + "source": "https://openrouter.ai/docs/guides/best-practices/reasoning-tokens" + }, + { + "id": "anthropic/claude-sonnet-4.6", + "name": "Claude Sonnet 4.6", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 1000000, + "max_output_tokens": 128000, + "cost": { + "input": 3, + "output": 15, + "cache_read": 0.3, + "cache_write": 3.75 + }, + "source": "https://openrouter.ai/docs/guides/best-practices/reasoning-tokens" + }, + { + "id": "google/gemini-3.8-flash", + "name": "Gemini 3.8 Flash", + "reasoning": true, + "input": [ + "text", + "image", + "audio", + "video" + ], + "context_window": 1048576, + "max_output_tokens": 65536, + "cost": { + "input": 0.75, + "output": 3.75, + "cache_read": 0.075, + "cache_write": 0.041667 + }, + "source": "https://openrouter.ai/docs/guides/best-practices/reasoning-tokens" + }, + { + "id": "google/gemini-3.1-pro-preview", + "name": "Gemini 3.1 Pro Preview", + "reasoning": true, + "input": [ + "text", + "image", + "audio", + "video" + ], + "context_window": 1048576, + "max_output_tokens": 65536, + "cost": { + "input": 2, + "output": 12, + "cache_read": 0.2, + "cache_write": 0.375 + }, + "source": "https://openrouter.ai/docs/guides/best-practices/reasoning-tokens" + }, + { + "id": "deepseek/deepseek-v4-pro", + "name": "DeepSeek V4 Pro", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1048576, + "max_output_tokens": 384000, + "cost": { + "input": 1.6, + "output": 3.2, + "cache_read": 0.135 + }, + "source": "https://openrouter.ai/docs/guides/best-practices/reasoning-tokens" + }, + { + "id": "deepseek/deepseek-v4-flash", + "name": "DeepSeek V4 Flash", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1048576, + "max_output_tokens": 384000, + "cost": { + "input": 0.07, + "output": 0.14, + "cache_read": 0.014 + }, + "source": "https://openrouter.ai/docs/guides/best-practices/reasoning-tokens" + }, + { + "id": "z-ai/glm-5.3", + "name": "GLM-5.3", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1310720, + "max_output_tokens": 131072, + "cost": { + "input": 1.4, + "output": 4.4, + "cache_read": 0.26 + }, + "source": "https://openrouter.ai/docs/guides/best-practices/reasoning-tokens" + }, + { + "id": "moonshotai/kimi-k3", + "name": "Kimi K3", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 1048576, + "max_output_tokens": 943718, + "cost": { + "input": 3, + "output": 15, + "cache_read": 0.3 + }, + "source": "https://openrouter.ai/docs/guides/best-practices/reasoning-tokens" + }, + { + "id": "qwen/qwen3.7-max", + "name": "Qwen3.7 Max", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1000000, + "max_output_tokens": 131072, + "cost": { + "input": 1.475, + "output": 4.425, + "cache_read": 0.295, + "cache_write": 1.84375 + }, + "source": "https://openrouter.ai/docs/guides/best-practices/reasoning-tokens" + }, + { + "id": "minimax/minimax-m3", + "name": "MiniMax M3", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 1048576, + "max_output_tokens": 512000, + "cost": { + "input": 0.3, + "output": 1.2, + "cache_read": 0.06 + }, + "source": "https://openrouter.ai/docs/guides/best-practices/reasoning-tokens" + }, + { + "id": "x-ai/grok-4.6", + "name": "Grok 4.6", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 500000, + "max_output_tokens": 450000, + "cost": { + "input": 2, + "output": 6, + "cache_read": 0.5 + }, + "source": "https://openrouter.ai/docs/guides/best-practices/reasoning-tokens" + }, + { + "id": "openai/text-embedding-3-small", + "name": "text-embedding-3-small", + "type": "Embedding", + "dimension": 1536, + "context_window": 8192, + "source": "https://openrouter.ai/docs/api_reference/embeddings" + }, + { + "id": "openai/text-embedding-3-large", + "name": "text-embedding-3-large", + "type": "Embedding", + "dimension": 3072, + "context_window": 8192, + "source": "https://openrouter.ai/docs/api_reference/embeddings" + }, + { + "id": "cohere/rerank-v3.5", + "name": "Cohere Rerank v3.5", + "type": "Rerank", + "source": "https://openrouter.ai/docs/api/api-reference/rerank/submit-a-rerank-request" + }, + { + "id": "openai/whisper-large-v3", + "name": "Whisper Large v3", + "type": "ASR", + "source": "https://openrouter.ai/docs/api/api-reference/stt/create-transcription" + } + ], + "qianfan": [ + { + "id": "ernie-5.0-thinking-preview", + "name": "ERNIE 5.0 Thinking Preview", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 128000, + "max_output_tokens": 65536, + "source": "https://cloud.baidu.com/doc/qianfan-docs/s/Wm95lyynv" + }, + { + "id": "ernie-4.5-turbo-128k", + "name": "ERNIE 4.5 Turbo 128K", + "reasoning": false, + "input": [ + "text" + ], + "context_window": 128000, + "max_output_tokens": 12288, + "source": "https://cloud.baidu.com/doc/qianfan-docs/s/7m95lyy43" + }, + { + "id": "ernie-4.5-turbo-vl-32k", + "name": "ERNIE 4.5 Turbo VL 32K", + "reasoning": false, + "input": [ + "text", + "image" + ], + "context_window": 32000, + "max_output_tokens": 12288, + "source": "https://cloud.baidu.com/doc/qianfan-docs/s/7m95lyy43" + }, + { + "id": "ernie-x1-turbo-32k", + "name": "ERNIE X1 Turbo 32K", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 32000, + "max_output_tokens": 16000, + "source": "https://cloud.baidu.com/doc/qianfan-docs/s/7m95lyy43" + }, + { + "id": "deepseek-v3.2", + "name": "DeepSeek V3.2 (Qianfan)", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 128000, + "max_output_tokens": 32000, + "source": "https://cloud.baidu.com/doc/qianfan-docs/s/Wm95lyynv" + }, + { + "id": "embedding-v1", + "name": "Embedding-V1", + "type": "Embedding", + "dimension": 384, + "source": "https://cloud.baidu.com/doc/qianfan-api/s/Fm7u3ropn" + }, + { + "id": "bge-large-zh", + "name": "BGE Large ZH", + "type": "Embedding", + "dimension": 1024, + "source": "https://cloud.baidu.com/doc/qianfan-api/s/Fm7u3ropn" + }, + { + "id": "tao-8k", + "name": "Tao-8K", + "type": "Embedding", + "dimension": 1024, + "source": "https://cloud.baidu.com/doc/qianfan/s/rmh4stp0j" + }, + { + "id": "bce-reranker-base", + "name": "BCE Reranker Base", + "type": "Rerank", + "source": "https://cloud.baidu.com/doc/qianfan-docs/s/7m95lyy43" + } + ], + "qiniu": [ + { + "id": "qwen3.5-397b-a17b", + "name": "Qwen3.5 397B-A17B", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 256000, + "max_output_tokens": 64000, + "source": "https://www.qiniu.com/ai/models" + }, + { + "id": "z-ai/glm-5", + "name": "GLM-5", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 200000, + "max_output_tokens": 128000, + "source": "https://www.qiniu.com/ai/models" + }, + { + "id": "z-ai/glm-4.7", + "name": "GLM-4.7", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 200000, + "max_output_tokens": 200000, + "source": "https://api.qnaigc.com/v1/market/models" + }, + { + "id": "minimax/minimax-m2.5", + "name": "MiniMax M2.5", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 204800, + "max_output_tokens": 128000, + "source": "https://www.qiniu.com/ai/models" + }, + { + "id": "doubao-seed-2.0-pro", + "name": "Doubao Seed 2.0 Pro", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 256000, + "max_output_tokens": 128000, + "source": "https://www.qiniu.com/ai/models" + }, + { + "id": "moonshotai/kimi-k2.5", + "name": "Kimi K2.5", + "reasoning": false, + "input": [ + "text", + "image", + "video" + ], + "context_window": 256000, + "max_output_tokens": 256000, + "source": "https://www.qiniu.com/ai/models" + }, + { + "id": "xiaomi/mimo-v2-flash", + "name": "MiMo V2 Flash", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 256000, + "max_output_tokens": 256000, + "cost": { + "input": 0.1, + "output": 0.3, + "cache_read": 0.01 + }, + "source": "https://www.qiniu.com/ai/models" + }, + { + "id": "deepseek/deepseek-v3.2-251201", + "name": "DeepSeek V3.2 (251201)", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 128000, + "max_output_tokens": 32000, + "source": "https://apidocs.qnaigc.com/397639742e0" + }, + { + "id": "deepseek-r1", + "name": "DeepSeek R1", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 128000, + "max_output_tokens": 32000, + "source": "https://api.qnaigc.com/v1/market/models" + }, + { + "id": "deepseek-v3", + "name": "DeepSeek V3", + "reasoning": false, + "input": [ + "text" + ], + "context_window": 128000, + "max_output_tokens": 16000, + "source": "https://www.qiniu.com/ai/models" + } + ], + "requesty": [ + { + "id": "openai/gpt-6-astra", + "name": "GPT-6 Astra", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 1050000, + "max_output_tokens": 128000, + "source": "https://docs.requesty.ai/frameworks/openai" + }, + { + "id": "openai/gpt-5.5", + "name": "GPT-5.5", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 1050000, + "max_output_tokens": 128000, + "source": "https://docs.requesty.ai/frameworks/openai" + }, + { + "id": "openai/gpt-5.4", + "name": "GPT-5.4", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 1050000, + "max_output_tokens": 128000, + "source": "https://docs.requesty.ai/frameworks/openai" + }, + { + "id": "anthropic/claude-opus-5", + "name": "Claude Opus 5", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 1000000, + "max_output_tokens": 128000, + "source": "https://docs.requesty.ai/frameworks/openai" + }, + { + "id": "anthropic/claude-sonnet-5", + "name": "Claude Sonnet 5", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 1000000, + "max_output_tokens": 128000, + "source": "https://docs.requesty.ai/frameworks/openai" + }, + { + "id": "vertex/gemini-3.8-flash", + "name": "Gemini 3.8 Flash (Vertex)", + "reasoning": true, + "input": [ + "text", + "image", + "audio", + "video" + ], + "context_window": 1048576, + "max_output_tokens": 65536, + "source": "https://docs.requesty.ai/frameworks/openai" + }, + { + "id": "google/gemini-3.1-pro-preview", + "name": "Gemini 3.1 Pro Preview", + "reasoning": true, + "input": [ + "text", + "image", + "audio", + "video" + ], + "context_window": 1048576, + "max_output_tokens": 65536, + "source": "https://docs.requesty.ai/frameworks/openai" + }, + { + "id": "google/gemini-3.6-flash", + "name": "Gemini 3.6 Flash", + "reasoning": true, + "input": [ + "text", + "image", + "audio", + "video" + ], + "context_window": 1048576, + "max_output_tokens": 65536, + "source": "https://docs.requesty.ai/frameworks/openai" + }, + { + "id": "deepseek/deepseek-v4-pro-0813", + "name": "DeepSeek V4 Pro", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1000000, + "max_output_tokens": 131072, + "source": "https://docs.requesty.ai/frameworks/openai" + }, + { + "id": "zai/glm-5.2", + "name": "GLM-5.2", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1048576, + "max_output_tokens": 131072, + "source": "https://docs.requesty.ai/frameworks/openai" + }, + { + "id": "moonshot/kimi-k3", + "name": "Kimi K3", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 1048576, + "max_output_tokens": 262144, + "source": "https://docs.requesty.ai/frameworks/openai" + }, + { + "id": "openai/gpt-4o-transcribe", + "name": "GPT-4o Transcribe", + "type": "ASR", + "source": "https://docs.requesty.ai/api-reference/endpoint/audio-transcriptions-create" + }, + { + "id": "openai/gpt-4o-mini-transcribe", + "name": "GPT-4o mini Transcribe", + "type": "ASR", + "source": "https://docs.requesty.ai/api-reference/endpoint/audio-transcriptions-create" + }, + { + "id": "openai/whisper-1", + "name": "Whisper", + "type": "ASR", + "source": "https://docs.requesty.ai/api-reference/endpoint/audio-transcriptions-create" + } + ], + "siliconflow": [ + { + "name": "DeepSeek V4 family (reasoning_effort high | max)", + "match": "deepseek-ai/DeepSeek-V4*", + "reasoning": true, + "input": [ + "text" + ], + "source": "https://docs.siliconflow.cn/cn/api-reference/chat-completions/chat-completions" + }, + { + "name": "DeepSeek V4 Pro-tier family (reasoning_effort high | max)", + "match": "Pro/deepseek-ai/DeepSeek-V4*", + "reasoning": true, + "input": [ + "text" + ], + "source": "https://docs.siliconflow.cn/cn/api-reference/chat-completions/chat-completions" + }, + { + "id": "deepseek-ai/DeepSeek-V4-Pro", + "name": "DeepSeek V4 Pro", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1049000, + "max_output_tokens": 393000, + "cost": { + "input": 1.74, + "output": 3.48, + "cache_read": 0.145 + }, + "source": "https://docs.siliconflow.cn/cn/api-reference/chat-completions/chat-completions" + }, + { + "id": "deepseek-ai/DeepSeek-V4-Flash", + "name": "DeepSeek V4 Flash", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1000000, + "max_output_tokens": 384000, + "cost": { + "input": 0.14, + "output": 0.28, + "cache_read": 0.003 + }, + "source": "https://docs.siliconflow.cn/cn/api-reference/chat-completions/chat-completions" + }, + { + "id": "zai-org/GLM-5.2", + "name": "GLM-5.2", + "aliases": [ + "Pro/zai-org/GLM-5.2" + ], + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1049000, + "max_output_tokens": 262000, + "cost": { + "input": 1.4, + "output": 4.4, + "cache_read": 0.26 + }, + "source": "https://docs.siliconflow.cn/cn/api-reference/chat-completions/chat-completions" + }, + { + "id": "Pro/zai-org/GLM-5.1", + "name": "GLM-5.1 (Pro)", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 205000, + "max_output_tokens": 205000, + "cost": { + "input": 1.4, + "output": 4.4, + "cache_read": 0.26 + }, + "source": "https://docs.siliconflow.cn/cn/api-reference/chat-completions/chat-completions" + }, + { + "id": "Pro/zai-org/GLM-5", + "name": "GLM-5 (Pro)", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 205000, + "max_output_tokens": 205000, + "cost": { + "input": 1, + "output": 3.2 + }, + "source": "https://docs.siliconflow.cn/cn/api-reference/chat-completions/chat-completions" + }, + { + "id": "Pro/moonshotai/Kimi-K2.6", + "name": "Kimi K2.6 (Pro)", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 262000, + "max_output_tokens": 262000, + "cost": { + "input": 0.95, + "output": 4, + "cache_read": 0.16 + }, + "source": "https://docs.siliconflow.cn/cn/api-reference/chat-completions/chat-completions" + }, + { + "id": "Pro/moonshotai/Kimi-K2.5", + "name": "Kimi K2.5 (Pro)", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 262000, + "max_output_tokens": 262000, + "cost": { + "input": 0.45, + "output": 2.25, + "cache_read": 0.07 + }, + "source": "https://docs.siliconflow.cn/cn/api-reference/chat-completions/chat-completions" + }, + { + "id": "Qwen/Qwen3.5-397B-A17B", + "name": "Qwen3.5 397B-A17B", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 262144, + "max_output_tokens": 65536, + "cost": { + "input": 0.29, + "output": 1.74 + }, + "source": "https://docs.siliconflow.cn/cn/api-reference/chat-completions/chat-completions" + }, + { + "id": "Qwen/Qwen3.5-122B-A10B", + "name": "Qwen3.5 122B-A10B", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 262144, + "max_output_tokens": 65536, + "cost": { + "input": 0.29, + "output": 2.32 + }, + "source": "https://docs.siliconflow.cn/cn/api-reference/chat-completions/chat-completions" + }, + { + "id": "Qwen/Qwen3.5-35B-A3B", + "name": "Qwen3.5 35B-A3B", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 262144, + "max_output_tokens": 65536, + "cost": { + "input": 0.23, + "output": 1.86 + }, + "source": "https://docs.siliconflow.cn/cn/api-reference/chat-completions/chat-completions" + }, + { + "id": "Qwen/Qwen3.6-35B-A3B", + "name": "Qwen3.6 35B-A3B", + "reasoning": false, + "input": [ + "text", + "image", + "video" + ], + "context_window": 262144, + "max_output_tokens": 65536, + "cost": { + "input": 0.23, + "output": 1.86 + }, + "source": "https://docs.siliconflow.cn/cn/api-reference/chat-completions/chat-completions" + }, + { + "id": "deepseek-ai/DeepSeek-V3.2", + "name": "DeepSeek V3.2", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 164000, + "max_output_tokens": 164000, + "cost": { + "input": 0.27, + "output": 0.42 + }, + "source": "https://docs.siliconflow.cn/cn/api-reference/chat-completions/chat-completions" + }, + { + "id": "Pro/MiniMaxAI/MiniMax-M2.5", + "name": "MiniMax M2.5 (Pro)", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 204800, + "max_output_tokens": 131000, + "cost": { + "input": 0.3, + "output": 1.22 + }, + "source": "https://platform.minimax.io/docs/api-reference/text-openai-api" + }, + { + "id": "Qwen/Qwen3-VL-32B-Instruct", + "name": "Qwen3 VL 32B Instruct", + "reasoning": false, + "input": [ + "text", + "image" + ], + "context_window": 262000, + "max_output_tokens": 262000, + "cost": { + "input": 0.2, + "output": 0.6 + }, + "source": "https://docs.siliconflow.cn/cn/api-reference/chat-completions/chat-completions" + }, + { + "id": "BAAI/bge-m3", + "name": "BGE-M3", + "type": "Embedding", + "dimension": 1024, + "source": "https://api-docs.siliconflow.cn/docs/api/embeddings-post" + }, + { + "id": "Qwen/Qwen3-Embedding-8B", + "name": "Qwen3 Embedding 8B", + "type": "Embedding", + "dimension": 4096, + "source": "https://api-docs.siliconflow.cn/docs/api/embeddings-post" + }, + { + "id": "Qwen/Qwen3-Embedding-4B", + "name": "Qwen3 Embedding 4B", + "type": "Embedding", + "dimension": 2560, + "source": "https://api-docs.siliconflow.cn/docs/api/embeddings-post" + }, + { + "id": "Qwen/Qwen3-Embedding-0.6B", + "name": "Qwen3 Embedding 0.6B", + "type": "Embedding", + "dimension": 1024, + "source": "https://api-docs.siliconflow.cn/docs/api/embeddings-post" + }, + { + "id": "BAAI/bge-reranker-v2-m3", + "name": "BGE Reranker v2 M3", + "type": "Rerank", + "source": "https://api-docs.siliconflow.cn/docs/api/rerank-post" + }, + { + "id": "Qwen/Qwen3-Reranker-8B", + "name": "Qwen3 Reranker 8B", + "type": "Rerank", + "source": "https://api-docs.siliconflow.cn/docs/api/rerank-post" + }, + { + "id": "FunAudioLLM/SenseVoiceSmall", + "name": "SenseVoice Small", + "type": "ASR", + "source": "https://api-docs.siliconflow.cn/docs/api/audio-transcriptions-post" + }, + { + "id": "TeleAI/TeleSpeechASR", + "name": "TeleSpeechASR", + "type": "ASR", + "source": "https://api-docs.siliconflow.cn/docs/api/audio-transcriptions-post" + } + ], + "volcengine": [ + { + "id": "doubao-seed-2-1-pro-260915", + "name": "Doubao Seed 2.1 Pro (260915)", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 1024000, + "max_output_tokens": 256000, + "source": "https://docs.volcengine.com/docs/ark/model-list?lang=zh" + }, + { + "id": "doubao-seed-2-1-pro-260628", + "name": "Doubao Seed 2.1 Pro", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 256000, + "max_output_tokens": 256000, + "cost": { + "input": 0.8906, + "output": 4.45301, + "cache_read": 0.17812 + }, + "source": "https://www.volcengine.com/docs/82379/1494384" + }, + { + "id": "doubao-seed-2-1-turbo-260628", + "name": "Doubao Seed 2.1 Turbo", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 256000, + "max_output_tokens": 256000, + "cost": { + "input": 0.4453, + "output": 2.22651, + "cache_read": 0.08906 + }, + "source": "https://www.volcengine.com/docs/82379/1494384" + }, + { + "id": "doubao-seed-2-0-pro-260215", + "name": "Doubao Seed 2.0 Pro", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 256000, + "max_output_tokens": 131072, + "cost": { + "input": 0.47499, + "output": 2.37494, + "cache_read": 0.095 + }, + "source": "https://docs.volcengine.com/docs/ark/model-list?lang=zh" + }, + { + "id": "doubao-seed-2-0-lite-260428", + "name": "Doubao Seed 2.0 Lite", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 256000, + "max_output_tokens": 131072, + "cost": { + "input": 0.08906, + "output": 0.53436, + "cache_read": 0.01781 + }, + "source": "https://www.volcengine.com/docs/82379/1494384" + }, + { + "id": "doubao-seed-2-0-mini-260428", + "name": "Doubao Seed 2.0 Mini", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 256000, + "max_output_tokens": 131072, + "cost": { + "input": 0.02969, + "output": 0.29687, + "cache_read": 0.00594 + }, + "source": "https://www.volcengine.com/docs/82379/1494384" + }, + { + "id": "doubao-seed-2-0-code-preview-260215", + "name": "Doubao Seed 2.0 Code Preview", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 262144, + "max_output_tokens": 131072, + "cost": { + "input": 0.47499, + "output": 2.37494, + "cache_read": 0.095 + }, + "source": "https://www.volcengine.com/docs/82379/1494384" + }, + { + "id": "doubao-seed-1-8-251228", + "name": "Doubao Seed 1.8 (retiring)", + "deprecated": true, + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 256000, + "max_output_tokens": 32768, + "cost": { + "input": 0.11875, + "output": 1.18747, + "cache_read": 0.02375 + }, + "source": "https://docs.volcengine.com/docs/ark/model-list?lang=zh" + }, + { + "id": "doubao-seed-1-6-251015", + "name": "Doubao Seed 1.6 (retiring)", + "deprecated": true, + "reasoning": true, + "input": [ + "text" + ], + "context_window": 256000, + "max_output_tokens": 32768, + "cost": { + "input": 0.11875, + "output": 1.18747, + "cache_read": 0.02375 + }, + "source": "https://docs.volcengine.com/docs/ark/model-list?lang=zh" + }, + { + "id": "doubao-seed-1-6-flash-250828", + "name": "Doubao Seed 1.6 Flash (retiring)", + "deprecated": true, + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 256000, + "max_output_tokens": 32768, + "cost": { + "input": 0.02227, + "output": 0.22265, + "cache_read": 0.00445 + }, + "source": "https://docs.volcengine.com/docs/ark/deep-thinking?lang=zh" + }, + { + "id": "doubao-seed-1-6-vision-250815", + "name": "Doubao Seed 1.6 Vision (retiring)", + "deprecated": true, + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 256000, + "max_output_tokens": 32768, + "cost": { + "input": 0.11875, + "output": 1.18747, + "cache_read": 0.02375 + }, + "source": "https://docs.volcengine.com/docs/ark/deep-thinking?lang=zh" + }, + { + "id": "deepseek-v4-1-flash-260910", + "name": "DeepSeek V4.1 Flash (Ark)", + "reasoning": true, + "input": [ + "text", + "image" + ], + "context_window": 1000000, + "max_output_tokens": 393216, + "source": "https://docs.volcengine.com/docs/ark/model-list?lang=zh" + }, + { + "id": "deepseek-v4-pro-ga-260813", + "name": "DeepSeek V4 Pro (Ark)", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1000000, + "max_output_tokens": 393216, + "cost": { + "input": 1.3359, + "output": 4.00771, + "cache_read": 0.04453 + }, + "source": "https://www.volcengine.com/docs/82379/1494384" + }, + { + "id": "deepseek-v4-flash-ga-260731", + "name": "DeepSeek V4 Flash (Ark)", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1000000, + "max_output_tokens": 393216, + "cost": { + "input": 0.4453, + "output": 1.3359, + "cache_read": 0.01484 + }, + "source": "https://www.volcengine.com/docs/82379/1494384" + }, + { + "id": "glm-5-3-flash-260828", + "name": "GLM-5.3 Flash (Ark)", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 1000000, + "max_output_tokens": 131072, + "cost": { + "input": 0.11875, + "output": 0.41563, + "cache_read": 0.03414 + }, + "source": "https://docs.volcengine.com/docs/ark/deep-thinking?lang=zh" + }, + { + "id": "glm-5-2-260617", + "name": "GLM-5.2 (Ark)", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1000000, + "max_output_tokens": 131072, + "cost": { + "input": 1.18747, + "output": 4.15615, + "cache_read": 0.29687 + }, + "source": "https://www.volcengine.com/docs/82379/1494384" + }, + { + "name": "Retired doubao-embedding text models", + "match": "doubao-embedding-text*", + "type": "Embedding", + "source": "https://docs.volcengine.com/docs/ark/TextVectorizationAPI?lang=zh" + }, + { + "name": "Retired doubao-embedding-large text models", + "match": "doubao-embedding-large-text*", + "type": "Embedding", + "source": "https://docs.volcengine.com/docs/ark/TextVectorizationAPI?lang=zh" + }, + { + "id": "doubao-embedding-vision-251215", + "name": "Doubao Embedding Vision (251215)", + "type": "Embedding", + "dimension": 2048, + "source": "https://docs.volcengine.com/docs/ark/multimodal-vectorization-api?lang=zh" + }, + { + "id": "doubao-embedding-vision-250615", + "name": "Doubao Embedding Vision", + "type": "Embedding", + "dimension": 2048, + "source": "https://docs.volcengine.com/docs/ark/multimodal-vectorization-api?lang=zh" + }, + { + "id": "doubao-seed-rerank", + "name": "Doubao Seed Rerank", + "type": "Rerank", + "source": "https://www.volcengine.com/docs/84313/1254474" + }, + { + "id": "base-multilingual-rerank", + "name": "Base Multilingual Rerank", + "type": "Rerank", + "source": "https://www.volcengine.com/docs/84313/1254474" + } + ], + "weknoracloud": [], + "zhipu": [ + { + "id": "glm-5.3", + "name": "GLM-5.3", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1000000, + "max_output_tokens": 131072, + "cost": { + "input": 1.4, + "output": 4.4, + "cache_read": 0.26 + }, + "source": "https://docs.bigmodel.cn/cn/guide/models/text/glm-5.3" + }, + { + "id": "glm-5.3-flash", + "name": "GLM-5.3 Flash", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 1000000, + "max_output_tokens": 131072, + "cost": { + "input": 0.075, + "output": 0.25, + "cache_read": 0.015 + }, + "source": "https://docs.bigmodel.cn/cn/guide/models/vlm/glm-5.3-flash" + }, + { + "id": "glm-5.2", + "name": "GLM-5.2", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 1000000, + "max_output_tokens": 131072, + "cost": { + "input": 1.4, + "output": 4.4, + "cache_read": 0.26 + }, + "source": "https://docs.bigmodel.cn/cn/guide/models/text/glm-5.2" + }, + { + "id": "glm-5.1", + "name": "GLM-5.1", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 200000, + "max_output_tokens": 131072, + "cost": { + "input": 1.4, + "output": 4.4, + "cache_read": 0.26 + }, + "source": "https://docs.bigmodel.cn/api-reference/模型-api/对话补全" + }, + { + "id": "glm-5", + "name": "GLM-5", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 204800, + "max_output_tokens": 131072, + "cost": { + "input": 1, + "output": 3.2, + "cache_read": 0.2 + }, + "source": "https://docs.bigmodel.cn/api-reference/模型-api/对话补全" + }, + { + "id": "glm-5v-turbo", + "name": "GLM-5V Turbo", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 200000, + "max_output_tokens": 131072, + "cost": { + "input": 5, + "output": 22, + "cache_read": 1.2 + }, + "source": "https://docs.bigmodel.cn/api-reference/模型-api/对话补全" + }, + { + "id": "glm-4.7", + "name": "GLM-4.7", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 204800, + "max_output_tokens": 131072, + "cost": { + "input": 0.6, + "output": 2.2, + "cache_read": 0.11 + }, + "source": "https://docs.bigmodel.cn/api-reference/模型-api/对话补全" + }, + { + "id": "glm-4.7-flash", + "name": "GLM-4.7 Flash", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 200000, + "max_output_tokens": 131072, + "cost": { + "input": 0, + "output": 0 + }, + "source": "https://docs.bigmodel.cn/api-reference/模型-api/对话补全" + }, + { + "id": "glm-4.6v", + "name": "GLM-4.6V", + "reasoning": true, + "input": [ + "text", + "image", + "video" + ], + "context_window": 128000, + "max_output_tokens": 32768, + "cost": { + "input": 0.3, + "output": 0.9 + }, + "source": "https://docs.bigmodel.cn/api-reference/模型-api/对话补全" + }, + { + "id": "glm-4.6", + "name": "GLM-4.6", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 204800, + "max_output_tokens": 131072, + "cost": { + "input": 0.6, + "output": 2.2, + "cache_read": 0.11 + }, + "source": "https://docs.bigmodel.cn/api-reference/模型-api/对话补全" + }, + { + "id": "glm-4.5-air", + "name": "GLM-4.5 Air", + "reasoning": true, + "input": [ + "text" + ], + "context_window": 131072, + "max_output_tokens": 98304, + "cost": { + "input": 0.2, + "output": 1.1, + "cache_read": 0.03 + }, + "source": "https://docs.bigmodel.cn/api-reference/模型-api/对话补全" + }, + { + "id": "embedding-3", + "name": "Embedding-3", + "type": "Embedding", + "dimension": 2048, + "source": "https://docs.bigmodel.cn/api-reference/模型-api/文本嵌入" + }, + { + "id": "embedding-2", + "name": "Embedding-2", + "type": "Embedding", + "dimension": 1024, + "source": "https://docs.bigmodel.cn/api-reference/模型-api/文本嵌入" + }, + { + "id": "rerank", + "name": "Rerank", + "type": "Rerank", + "source": "https://docs.bigmodel.cn/api-reference/模型-api/文本重排序" + }, + { + "id": "glm-asr-2512", + "name": "GLM-ASR-2512 (at most 30 s per file)", + "type": "ASR", + "source": "https://docs.bigmodel.cn/api-reference/模型-api/语音转文本" + } + ] + } +} diff --git a/internal/models/catalog/loader.go b/internal/models/catalog/loader.go new file mode 100644 index 00000000..3a038282 --- /dev/null +++ b/internal/models/catalog/loader.go @@ -0,0 +1,49 @@ +package catalog + +import ( + "bytes" + _ "embed" + "encoding/json" + "fmt" + "sync" + + "github.com/Tencent/WeKnora/internal/models" + "github.com/Tencent/WeKnora/internal/models/internal/configcopy" +) + +//go:embed data/models.generated.json +var builtinData []byte + +var ( + builtinOnce sync.Once + builtinEntries map[string][]models.ModelSpec +) + +// BuiltinModels returns an independent copy of a provider's generated catalog. +// Provider definitions never own or embed a second model list. +func BuiltinModels(provider string) []models.ModelSpec { + builtinOnce.Do(func() { + var data struct { + Version int `json:"version"` + Providers map[string][]models.ModelSpec `json:"providers"` + } + dec := json.NewDecoder(bytes.NewReader(builtinData)) + dec.DisallowUnknownFields() + if err := dec.Decode(&data); err != nil { + panic(fmt.Sprintf("invalid generated model catalog: %v", err)) + } + if data.Version != 1 { + panic("unsupported generated model catalog version") + } + builtinEntries = data.Providers + }) + entries, ok := builtinEntries[provider] + if !ok { + panic("missing generated model catalog for " + provider) + } + out := make([]models.ModelSpec, len(entries)) + for i, model := range entries { + out[i] = configcopy.Clone(model) + } + return out +} diff --git a/internal/models/catalog/registry.go b/internal/models/catalog/registry.go deleted file mode 100644 index fc132a49..00000000 --- a/internal/models/catalog/registry.go +++ /dev/null @@ -1,286 +0,0 @@ -package catalog - -import ( - "bytes" - "fmt" - "sort" - "strings" - "sync" - - "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/types" -) - -// GenericID is the catch-all vendor for any OpenAI-compatible endpoint. -const GenericID = "generic" - -var ( - mu sync.RWMutex - vendors = map[string]*Vendor{} -) - -// Register adds a built-in vendor. Registering the same id twice replaces -// the earlier definition (the deployment overlay relies on this). -func Register(v *Vendor) { - if v == nil || v.ID == "" { - panic("catalog: vendor without id") - } - if v.API == "" { - v.API = api.APIOpenAICompletions - } - if v.Auth == "" { - v.Auth = AuthBearer - } - if v.RerankAPI == "" && v.SupportsType(types.ModelTypeRerank) { - v.RerankAPI = api.RerankCohere - } - if v.TranscriptionAPI == "" && v.SupportsType(types.ModelTypeASR) { - v.TranscriptionAPI = api.TranscriptionOpenAI - } - if v.EmbeddingAPI == "" && v.SupportsType(types.ModelTypeEmbedding) { - v.EmbeddingAPI = api.EmbeddingOpenAI - } - for i := range v.Models { - if v.Models[i].Type == "" { - v.Models[i].Type = types.ModelTypeKnowledgeQA - } - if v.Models[i].API == "" && v.Models[i].Type == types.ModelTypeKnowledgeQA { - v.Models[i].API = v.API - } - } - mu.Lock() - defer mu.Unlock() - vendors[v.ID] = v -} - -// Get returns a vendor by id. -func Get(id string) (*Vendor, bool) { - mu.RLock() - defer mu.RUnlock() - v, ok := vendors[strings.ToLower(strings.TrimSpace(id))] - return v, ok -} - -// GetOrGeneric returns the vendor or the generic catch-all. When no vendor -// package is linked into the binary (unit tests of leaf packages), a -// built-in generic definition keeps resolution working. -func GetOrGeneric(id string) *Vendor { - if v, ok := Get(id); ok { - return v - } - if v, ok := Get(GenericID); ok { - return v - } - return fallbackGeneric -} - -// fallbackGeneric mirrors internal/models/vendors/generic so behaviour does -// not depend on whether that package was imported. -var fallbackGeneric = &Vendor{ - ID: GenericID, - Name: "Custom (OpenAI-compatible)", - API: api.APIOpenAICompletions, - DefaultBaseURLs: map[types.ModelType]string{}, - ModelTypes: []types.ModelType{ - types.ModelTypeKnowledgeQA, types.ModelTypeEmbedding, types.ModelTypeRerank, - types.ModelTypeVLLM, types.ModelTypeASR, - }, - Auth: AuthBearer, - Compat: VendorCompat{OpenAICompletions: OpenAICompletionsCompat{ - MaxTokensField: Ptr("max_tokens"), - ThinkingFormat: Ptr(ThinkingFormatChatTemplateKwargs), - }}, -} - -// List returns every vendor ordered by Order then id. -func List() []*Vendor { - mu.RLock() - defer mu.RUnlock() - out := make([]*Vendor, 0, len(vendors)) - for _, v := range vendors { - out = append(out, v) - } - sort.SliceStable(out, func(i, j int) bool { - if out[i].Order != out[j].Order { - return out[i].Order < out[j].Order - } - return out[i].ID < out[j].ID - }) - return out -} - -// ListByType returns vendors that support a model type. -func ListByType(modelType types.ModelType) []*Vendor { - all := List() - out := make([]*Vendor, 0, len(all)) - for _, v := range all { - if v.SupportsType(modelType) { - out = append(out, v) - } - } - return out -} - -// DetectByURL finds the vendor whose URLPatterns match a base URL. Used only -// when a stored model row carries no provider id. Longer patterns win so -// "api.lkeap.cloud.tencent.com" beats "tencent". -func DetectByURL(baseURL string) string { - if baseURL == "" { - return GenericID - } - lower := strings.ToLower(baseURL) - bestID, bestLen := GenericID, 0 - for _, v := range List() { - for _, p := range v.URLPatterns { - if p != "" && strings.Contains(lower, strings.ToLower(p)) && len(p) > bestLen { - bestID, bestLen = v.ID, len(p) - } - } - } - return bestID -} - -// ModelsByType returns the vendor's catalog entries for a model type, -// hiding deprecated and pattern-only entries. -func (v *Vendor) ModelsByType(modelType types.ModelType) []ModelSpec { - out := make([]ModelSpec, 0) - for _, m := range v.Models { - if m.Deprecated || m.ID == "" { - continue - } - mt := m.Type - if mt == "" { - mt = types.ModelTypeKnowledgeQA - } - switch modelType { - case types.ModelTypeVLLM: - // VLM pickers list chat models that accept images. - if mt == types.ModelTypeKnowledgeQA && m.AcceptsImages() { - out = append(out, m) - } - default: - if mt == modelType { - out = append(out, m) - } - } - } - return out -} - -// FindModel looks a model name up among the vendor's entries of one model -// type: exact id, then aliases, then glob patterns (longest literal prefix -// wins). Matching is case-insensitive. -// -// The type is part of the key because families share prefixes across types. -// Aliyun's qwen3* chat glob also matches qwen3.8-text-embedding, and gpt-5* -// matches gpt-5-embed; an untyped lookup would hand an embedding row the chat -// family's compat, which the embedding overlay rejects, and the row could not -// be built at all. A VLM row is a chat model that accepts images, so it looks -// among the chat entries. -func (v *Vendor) FindModel(name string, modelType types.ModelType) (ModelSpec, bool) { - needle := strings.ToLower(strings.TrimSpace(name)) - if needle == "" { - return ModelSpec{}, false - } - want := entryType(modelType) - var candidates []ModelSpec - for _, m := range v.Models { - if entryType(m.Type) == want { - candidates = append(candidates, m) - } - } - for _, m := range candidates { - if strings.ToLower(m.ID) == needle { - return m, true - } - } - for _, m := range candidates { - for _, alias := range m.Aliases { - if strings.ToLower(alias) == needle { - return m, true - } - } - } - var best ModelSpec - bestScore := -1 - for _, m := range candidates { - if m.Match == "" { - continue - } - if globMatch(strings.ToLower(m.Match), needle) { - score := len(strings.TrimRight(strings.SplitN(m.Match, "*", 2)[0], "*")) - if score > bestScore { - best, bestScore = m, score - } - } - } - if bestScore >= 0 { - return best, true - } - return ModelSpec{}, false -} - -// entryType folds a model type onto the catalog entries that describe it: -// chat entries leave Type empty, and VLM rows use them too. -func entryType(t types.ModelType) types.ModelType { - if t == "" || t == types.ModelTypeVLLM { - return types.ModelTypeKnowledgeQA - } - return t -} - -// globMatch supports '*' wildcards only. -func globMatch(pattern, s string) bool { - parts := strings.Split(pattern, "*") - if len(parts) == 1 { - return pattern == s - } - if !strings.HasPrefix(s, parts[0]) { - return false - } - s = s[len(parts[0]):] - for i := 1; i < len(parts)-1; i++ { - idx := strings.Index(s, parts[i]) - if idx < 0 { - return false - } - s = s[idx+len(parts[i]):] - } - return strings.HasSuffix(s, parts[len(parts)-1]) -} - -func defaultValidate(v *Vendor, cfg *Config) error { - if cfg == nil { - return fmt.Errorf("config is nil") - } - if v.RequiresAuth && v.Auth != AuthSigned && strings.TrimSpace(cfg.APIKey) == "" { - return fmt.Errorf("API key is required for %s", v.Name) - } - if v.ID == GenericID && strings.TrimSpace(cfg.BaseURL) == "" { - return fmt.Errorf("base URL is required for generic provider") - } - if strings.TrimSpace(cfg.ModelName) == "" { - return fmt.Errorf("model name is required") - } - return nil -} - -func bytesReader(b []byte) *bytes.Reader { return bytes.NewReader(b) } - -// reset clears the registry and returns a function that puts the previous -// contents back (tests only). The registry is process-global, so a test that -// merely cleared it would leave every later test in the same binary — the -// external catalog_test package included — resolving against an empty -// catalog, which silently turns assertions about real vendors into -// assertions about the generic fallback. -func reset() func() { - mu.Lock() - defer mu.Unlock() - previous := vendors - vendors = map[string]*Vendor{} - return func() { - mu.Lock() - defer mu.Unlock() - vendors = previous - } -} diff --git a/internal/models/chat/chat.go b/internal/models/chat/chat.go index 386db11f..33bbe2da 100644 --- a/internal/models/chat/chat.go +++ b/internal/models/chat/chat.go @@ -15,11 +15,8 @@ import ( "github.com/Tencent/WeKnora/internal/models/api/googlegenai" "github.com/Tencent/WeKnora/internal/models/api/openaicompletions" "github.com/Tencent/WeKnora/internal/models/api/openairesponses" - "github.com/Tencent/WeKnora/internal/models/catalog" + modelruntime "github.com/Tencent/WeKnora/internal/models/runtime" "github.com/Tencent/WeKnora/internal/models/utils/ollama" - // Built-in vendors register with the catalog through package init; the - // chat factory is the one place that must never see an empty catalog. - _ "github.com/Tencent/WeKnora/internal/models/vendors" "github.com/Tencent/WeKnora/internal/types" secutils "github.com/Tencent/WeKnora/internal/utils" ) @@ -141,11 +138,11 @@ func NewChat(config *ChatConfig, ollamaService *ollama.OllamaService) (Chat, err // Resolve looks the configuration up in the catalog. It is exposed so the // handler layer can report the effective protocol and capabilities. -func Resolve(config *ChatConfig) (*catalog.Resolved, error) { +func Resolve(config *ChatConfig) (*modelruntime.Resolved, error) { if config == nil { return nil, fmt.Errorf("chat config is nil") } - return catalog.Resolve(catalog.Ref{ + return modelruntime.Resolve(modelruntime.Ref{ Provider: config.Provider, Model: config.ModelName, BaseURL: config.BaseURL, @@ -182,47 +179,14 @@ func NewRemoteChat(config *ChatConfig) (Chat, error) { } } - creds := catalog.Credentials{APIKey: config.APIKey, AppID: config.AppID, AppSecret: config.AppSecret} - if creds.APIKey == "" { - creds.APIKey = vendor.DefaultAPIKey - } - if vendor.Auth == catalog.AuthSigned { - if creds.AppID == "" { - return nil, fmt.Errorf("%s provider: AppID is required", vendor.Name) - } - if creds.AppSecret == "" { - return nil, fmt.Errorf("%s provider: AppSecret is required", vendor.Name) - } - } else if vendor.RequiresAuth && resolved.API == api.APIAnthropicMessages && strings.TrimSpace(creds.APIKey) == "" { - return nil, fmt.Errorf("%s provider: API key is required", vendor.Name) - } - - headers := make(map[string]string, len(vendor.Headers)+len(config.CustomHeaders)) - for k, v := range vendor.Headers { - headers[k] = v - } - for k, v := range config.CustomHeaders { - headers[k] = v - } - endpoint := api.Endpoint{ - BaseURL: resolved.BaseURL, - Model: resolved.RemoteModel, - ModelID: config.ModelID, - Auth: vendor.AuthFunc(resolved.API, creds), - Headers: headers, - } - if vendor.Endpoint != nil { - url, query := vendor.Endpoint(catalog.EndpointRequest{ - BaseURL: resolved.BaseURL, - Model: resolved.RemoteModel, - ModelType: types.ModelTypeKnowledgeQA, - API: resolved.API, - Extra: config.ExtraConfig, - }) - if url != "" { - endpoint.URL = url - endpoint.Query = query - } + endpoint, err := resolved.Endpoint(types.ModelTypeKnowledgeQA, modelruntime.Connection{ + ModelID: config.ModelID, + Credentials: api.Credentials{APIKey: config.APIKey, AppID: config.AppID, AppSecret: config.AppSecret}, + Headers: config.CustomHeaders, + Extra: config.ExtraConfig, + }) + if err != nil { + return nil, err } switch resolved.API { diff --git a/internal/models/chat/llm_debug.go b/internal/models/chat/llm_debug.go index 1badc632..ccf6137c 100644 --- a/internal/models/chat/llm_debug.go +++ b/internal/models/chat/llm_debug.go @@ -6,9 +6,8 @@ import ( "strings" "time" - "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/logger" + "github.com/Tencent/WeKnora/internal/models/api" "github.com/Tencent/WeKnora/internal/types" ) diff --git a/internal/models/chat/ollama.go b/internal/models/chat/ollama.go index 9067aa37..7597863e 100644 --- a/internal/models/chat/ollama.go +++ b/internal/models/chat/ollama.go @@ -9,9 +9,8 @@ import ( "strings" "time" - "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/logger" + "github.com/Tencent/WeKnora/internal/models/api" "github.com/Tencent/WeKnora/internal/models/utils/ollama" "github.com/Tencent/WeKnora/internal/types" secutils "github.com/Tencent/WeKnora/internal/utils" diff --git a/internal/models/embedding/catalog_matrix_test.go b/internal/models/embedding/catalog_matrix_test.go new file mode 100644 index 00000000..cf5d907c --- /dev/null +++ b/internal/models/embedding/catalog_matrix_test.go @@ -0,0 +1,105 @@ +package embedding + +import ( + "context" + "net/url" + "strings" + "testing" + + modelruntime "github.com/Tencent/WeKnora/internal/models/runtime" + "github.com/Tencent/WeKnora/internal/types" + "github.com/stretchr/testify/require" +) + +// Exercise the production factory and HTTP transport for every embedding rule, +// including aliases, pattern entries and both query/document task modes. +func TestEveryCatalogEmbeddingTransport(t *testing.T) { + for _, v := range modelruntime.List() { + for _, m := range v.Models() { + if m.Type != types.ModelTypeEmbedding { + continue + } + names := append([]string{m.ID}, m.Aliases...) + if m.ID == "" { + names[0] = strings.ReplaceAll(m.Match, "*", "snapshot") + } + for _, name := range names { + t.Run(v.ID+"/"+name, func(t *testing.T) { + u := newUpstream(t) + base, err := url.Parse( + strings.ReplaceAll( + v.GetDefaultURL( + types.ModelTypeEmbedding, + ), + "{resource}", + "test-resource", + ), + ) + require.NoError(t, err) + cfg := Config{ + Source: types.ModelSourceRemote, + Provider: v.ID, + ModelName: name, + ModelID: "row-id", + BaseURL: u.url + base.Path, + APIKey: "row-key", + AppID: "app", + AppSecret: "secret", + Dimensions: 256, + SupportsDimensionOverride: true, + } + client, err := newRemoteEmbedder(cfg, nil) + require.NoError(t, err) + for _, ctx := range []context.Context{ + context.Background(), + types.WithEmbedQuery( + context.Background(), + ), + } { + vectors, err := client.BatchEmbed(ctx, []string{"a", "中文"}) + require.NoError(t, err) + require.Equal(t, [][]float32{{1}, {2}}, vectors) + } + require.NotEmpty(t, u.requests) + require.Equal(t, "row-id", client.GetModelID()) + }) + } + } + } +} + +func TestStoredEmbeddingSpecReachesWire(t *testing.T) { + u := newUpstream(t) + row := &types.Model{ + ID: "stable-id", + Name: "custom", + Source: types.ModelSourceRemote, + Parameters: types.ModelParameters{ + Provider: "generic", + BaseURL: u.url, + APIKey: "model-key", + Spec: &types.ModelSpecOverride{ + Compat: map[string]any{ + "path": "/custom-embeddings", + "max_batch_size": 1, + "extra_body": map[string]any{ + "custom_flag": true, + }, + }, + }, + }, + } + client, err := newRemoteEmbedder(ConfigFromModel(row, "", ""), nil) + require.NoError(t, err) + _, err = client.BatchEmbed(context.Background(), []string{"a", "b"}) + require.NoError(t, err) + require.Len(t, u.requests, 2) + for _, req := range u.requests { + require.Equal(t, "/custom-embeddings", req.path) + require.Equal(t, true, req.body["custom_flag"]) + require.Equal(t, "Bearer model-key", req.header.Get("Authorization")) + } + row.Parameters.Spec.Compat = map[string]any{"misspelled_option": true} + _, err = newRemoteEmbedder(ConfigFromModel(row, "", ""), nil) + require.ErrorContains(t, err, "unknown field") +} diff --git a/internal/models/embedding/embedder.go b/internal/models/embedding/embedder.go index 4e2502cb..4d008c4b 100644 --- a/internal/models/embedding/embedder.go +++ b/internal/models/embedding/embedder.go @@ -7,11 +7,6 @@ import ( "github.com/Tencent/WeKnora/internal/logger" "github.com/Tencent/WeKnora/internal/models/utils/ollama" - // catalog.Resolve answers from the vendor catalog, which is empty until - // the vendor packages have run their init. Without this import every row - // resolves to the generic vendor — silently, and only in builds that do - // not already link the container (leaf tests, future tools). - _ "github.com/Tencent/WeKnora/internal/models/vendors" "github.com/Tencent/WeKnora/internal/tracing/langfuse" "github.com/Tencent/WeKnora/internal/types" ) @@ -56,8 +51,9 @@ type Config struct { Provider string `json:"provider"` // MaxConcurrency caps concurrent background calls to this model; 0 falls // back to the process-wide default (see limiter.GateN). - MaxConcurrency int `json:"max_concurrency"` - ExtraConfig map[string]string `json:"extra_config"` + MaxConcurrency int `json:"max_concurrency"` + Spec *types.ModelSpecOverride `json:"spec,omitempty"` + ExtraConfig map[string]string `json:"extra_config"` // CustomHeaders 允许在调用远程 API 时附加自定义 HTTP 请求头(类似 OpenAI Python SDK 的 extra_headers)。 CustomHeaders map[string]string `json:"custom_headers"` AppID string @@ -82,6 +78,7 @@ func ConfigFromModel(m *types.Model, appID, appSecret string) Config { TruncatePromptTokens: m.Parameters.EmbeddingParameters.TruncatePromptTokens, Provider: m.Parameters.Provider, MaxConcurrency: m.Parameters.MaxConcurrency, + Spec: m.Parameters.Spec, ExtraConfig: m.Parameters.ExtraConfig, CustomHeaders: m.Parameters.CustomHeaders, AppID: appID, diff --git a/internal/models/embedding/protocol.go b/internal/models/embedding/protocol.go index 764e88f7..3398049b 100644 --- a/internal/models/embedding/protocol.go +++ b/internal/models/embedding/protocol.go @@ -11,7 +11,7 @@ import ( "github.com/Tencent/WeKnora/internal/models/api/dashscopeembeddings" "github.com/Tencent/WeKnora/internal/models/api/googleembeddings" "github.com/Tencent/WeKnora/internal/models/api/openaiembeddings" - "github.com/Tencent/WeKnora/internal/models/catalog" + modelruntime "github.com/Tencent/WeKnora/internal/models/runtime" "github.com/Tencent/WeKnora/internal/types" ) @@ -26,12 +26,13 @@ func newRemoteEmbedder(config Config, pooler EmbedderPooler) (Embedder, error) { if strings.TrimSpace(config.ModelName) == "" { return nil, fmt.Errorf("model name is required") } - resolved, err := catalog.Resolve(catalog.Ref{ + resolved, err := modelruntime.Resolve(modelruntime.Ref{ Provider: config.Provider, Model: config.ModelName, BaseURL: config.BaseURL, ModelType: types.ModelTypeEmbedding, Extra: config.ExtraConfig, + Override: config.Spec, TruncatePromptTokens: config.TruncatePromptTokens, }) if err != nil { @@ -42,53 +43,22 @@ func newRemoteEmbedder(config Config, pooler EmbedderPooler) (Embedder, error) { } vendor := resolved.Vendor - creds := catalog.Credentials{APIKey: config.APIKey, AppID: config.AppID, AppSecret: config.AppSecret} - if creds.APIKey == "" { - creds.APIKey = vendor.DefaultAPIKey + endpoint, err := resolved.Endpoint(types.ModelTypeEmbedding, modelruntime.Connection{ + ModelID: config.ModelID, + Credentials: api.Credentials{APIKey: config.APIKey, AppID: config.AppID, AppSecret: config.AppSecret}, + Headers: config.CustomHeaders, + Extra: config.ExtraConfig, + Client: newEmbeddingHTTPClient(time.Duration(resolved.Embeddings.RequestTimeout) * time.Second), + }) + if err != nil { + return nil, err } - // A signing vendor with no identity pair would otherwise send unsigned - // requests and fail at the far end, which is a worse error than this one. - if vendor.Auth == catalog.AuthSigned { - if creds.AppID == "" { - return nil, fmt.Errorf("%s embedding: AppID is required", vendor.Name) + if endpoint.URL != "" { + if err := validateEmbeddingBaseURL(endpoint.URL); err != nil { + return nil, err } - if creds.AppSecret == "" { - return nil, fmt.Errorf("%s embedding: AppSecret is required", vendor.Name) - } - } - // Vendor headers first so a user header cannot silently replace a vendor - // beta flag, matching chat.NewRemoteChat. - headers := make(map[string]string, len(vendor.Headers)+len(config.CustomHeaders)) - for k, v := range vendor.Headers { - headers[k] = v - } - for k, v := range config.CustomHeaders { - headers[k] = v } settings := resolved.Embeddings - endpoint := api.Endpoint{ - BaseURL: resolved.BaseURL, - Model: resolved.RemoteModel, - ModelID: config.ModelID, - Auth: vendor.AuthFunc(vendor.API, creds), - Headers: headers, - Client: newEmbeddingHTTPClient(time.Duration(settings.RequestTimeout) * time.Second), - } - if vendor.Endpoint != nil { - if url, query := vendor.Endpoint(catalog.EndpointRequest{ - BaseURL: resolved.BaseURL, - Model: resolved.RemoteModel, - ModelType: types.ModelTypeEmbedding, - API: vendor.API, - EmbeddingAPI: resolved.EmbeddingAPI, - Extra: config.ExtraConfig, - }); url != "" { - if err := validateEmbeddingBaseURL(url); err != nil { - return nil, err - } - endpoint.URL, endpoint.Query = url, query - } - } // The width is the vendor's field but the operator's decision: a row // that did not opt in keeps the model's native width even where the @@ -137,7 +107,7 @@ func newRemoteEmbedder(config Config, pooler EmbedderPooler) (Embedder, error) { // and telling the vendor which side of a search a text is on. type protocolEmbedder struct { inner api.Embedder - settings catalog.EmbeddingsSettings + settings api.EmbeddingsSettings modelName string modelID string dimensions int diff --git a/internal/models/internal/configcopy/copy.go b/internal/models/internal/configcopy/copy.go new file mode 100644 index 00000000..c16fb1d9 --- /dev/null +++ b/internal/models/internal/configcopy/copy.go @@ -0,0 +1,62 @@ +// Package configcopy copies exported configuration data and immutable function values. +package configcopy + +import "reflect" + +// Clone copies exported configuration fields while retaining immutable functions. +func Clone[T any](value T) T { + var out T + reflect.ValueOf(&out).Elem().Set(cloneValue(reflect.ValueOf(&value).Elem())) + return out +} + +// Value preserves the static type of reflected optional configuration fields. +func Value(value reflect.Value) reflect.Value { return cloneValue(value) } + +// Definitions contain only exported data fields and immutable function values. +// Copy every pointer, map and slice, including nested compatibility settings. +func cloneValue(v reflect.Value) reflect.Value { + switch v.Kind() { + case reflect.Interface: + if v.IsNil() { + return reflect.Zero(v.Type()) + } + out := reflect.New(v.Type()).Elem() + out.Set(cloneValue(v.Elem())) + return out + case reflect.Pointer: + if v.IsNil() { + return reflect.Zero(v.Type()) + } + out := reflect.New(v.Type().Elem()) + out.Elem().Set(cloneValue(v.Elem())) + return out + case reflect.Map: + if v.IsNil() { + return reflect.Zero(v.Type()) + } + out := reflect.MakeMapWithSize(v.Type(), v.Len()) + iter := v.MapRange() + for iter.Next() { + out.SetMapIndex(iter.Key(), cloneValue(iter.Value())) + } + return out + case reflect.Slice: + if v.IsNil() { + return reflect.Zero(v.Type()) + } + out := reflect.MakeSlice(v.Type(), v.Len(), v.Len()) + for i := 0; i < v.Len(); i++ { + out.Index(i).Set(cloneValue(v.Index(i))) + } + return out + case reflect.Struct: + out := reflect.New(v.Type()).Elem() + for i := 0; i < v.NumField(); i++ { + out.Field(i).Set(cloneValue(v.Field(i))) + } + return out + default: + return v + } +} diff --git a/internal/models/legacy_keys.go b/internal/models/legacy_keys.go new file mode 100644 index 00000000..96b37168 --- /dev/null +++ b/internal/models/legacy_keys.go @@ -0,0 +1,28 @@ +package models + +// Extra-config keys honoured by Resolve. They predate the catalog and stay +// supported so existing model rows keep working unchanged. +const ( + // ExtraAPI forces a protocol ("openai-responses", "anthropic-messages", ...). + ExtraAPI = "api" + // ExtraRemoteModelName sends a different model id on the wire. + ExtraRemoteModelName = "remote_model_name" + // ExtraAPIVersion is the Azure api-version query parameter. + ExtraAPIVersion = "api_version" + // ExtraThinkingControl is the legacy thinking encoding selector written + // by older UIs: none | enable_thinking | thinking_type | chat_template_kwargs. + ExtraThinkingControl = "thinking_control" + // ExtraTruncatePromptTokens is the vLLM-only server-side truncation + // budget for rerank, opt-in per row. It is never sent unless the operator + // set it: vendors that do not implement it reject the unknown field. + ExtraTruncatePromptTokens = "truncate_prompt_tokens" + // LegacyTruncatePromptTokens is the embedding truncation budget the + // pre-catalog OpenAI-compatible client sent whenever a row left it at 0. + LegacyTruncatePromptTokens = 511 + // ExtraScoreScale overrides the vendor rerank score scale for one row. + // A self-hosted gateway serves whatever reranker was deployed behind it + // and the two families disagree: BGE-class models answer a 0..1 + // probability, Qwen3-Reranker-class models an unbounded score. A vendor + // can only state what its own documentation shows. + ExtraScoreScale = "score_scale" +) diff --git a/internal/models/model.go b/internal/models/model.go new file mode 100644 index 00000000..b68a3a70 --- /dev/null +++ b/internal/models/model.go @@ -0,0 +1,76 @@ +// Package models defines shared, credential-free model metadata. +package models + +import ( + "encoding/json" + + "github.com/Tencent/WeKnora/internal/models/api" + "github.com/Tencent/WeKnora/internal/types" +) + +// ModelCost is priced per million tokens, in USD unless Currency says otherwise. +type ModelCost struct { + Input float64 `json:"input"` + Output float64 `json:"output"` + CacheRead float64 `json:"cache_read,omitempty"` + CacheWrite float64 `json:"cache_write,omitempty"` + Currency string `json:"currency,omitempty"` +} + +// ModelSpec is one entry of the generated model catalog. +// +// Only ID is required. API defaults to the vendor's API; Type defaults to +// KnowledgeQA. Compat is interpreted according to API (see compat.go). +type ModelSpec struct { + ID string `json:"id"` + Name string `json:"name,omitempty"` + // Type is the WeKnora model type this entry describes. Chat models with + // image input are still KnowledgeQA; the UI derives VLM eligibility from + // Input. Embedding / Rerank / ASR entries exist for the model picker. + Type types.ModelType `json:"type,omitempty"` + API api.API `json:"api,omitempty"` + // Aliases are additional ids that resolve to this entry (dated + // snapshots, vendor-prefixed names on gateways). + Aliases []string `json:"aliases,omitempty"` + // Match is a case-insensitive glob ("gpt-5*", "*deepseek-r1*") that lets + // one entry describe a family. Exact ids and aliases win over patterns; + // among patterns the longest literal prefix wins. + Match string `json:"match,omitempty"` + // Reasoning reports whether the model can emit thinking at all. + Reasoning bool `json:"reasoning"` + // Input lists accepted modalities: text, image, audio, video. + Input []string `json:"input,omitempty"` + ContextWindow int `json:"context_window,omitempty"` + MaxOutputTokens int `json:"max_output_tokens,omitempty"` + Cost *ModelCost `json:"cost,omitempty"` + // ThinkingLevels maps protocol-neutral levels to vendor values; missing + // keys inherit the vendor map. See api.ThinkingLevelMap. + ThinkingLevels api.ThinkingLevelMap `json:"thinking_levels,omitempty"` + // Compat is the protocol-specific overlay for this model (flat object, + // fields depend on API). Decoded lazily by Resolve. + Compat json.RawMessage `json:"compat,omitempty"` + // Dimension is the embedding vector width (embedding entries only). + Dimension int `json:"dimension,omitempty"` + // Deprecated hides the entry from pickers but keeps resolution working. + Deprecated bool `json:"deprecated,omitempty"` + // Source is the documentation URL the facts were taken from. + Source string `json:"source,omitempty"` +} + +// DisplayName returns Name or the id. +func (m ModelSpec) DisplayName() string { + if m.Name != "" { + return m.Name + } + return m.ID +} + +// AcceptsImages reports whether Input lists image. +func (m ModelSpec) AcceptsImages() bool { + for _, in := range m.Input { + if in == "image" { + return true + } + } + return false +} diff --git a/internal/models/model_type.go b/internal/models/model_type.go new file mode 100644 index 00000000..12bdfe93 --- /dev/null +++ b/internal/models/model_type.go @@ -0,0 +1,30 @@ +package models + +import ( + "strings" + + "github.com/Tencent/WeKnora/internal/types" +) + +var frontendTypes = map[string]types.ModelType{ + "chat": types.ModelTypeKnowledgeQA, + "embedding": types.ModelTypeEmbedding, + "rerank": types.ModelTypeRerank, + "vlm": types.ModelTypeVLLM, + "vllm": types.ModelTypeVLLM, + "asr": types.ModelTypeASR, +} + +// ParseModelType accepts both frontend ("chat") and backend ("KnowledgeQA") +// spellings. +func ParseModelType(s string) (types.ModelType, bool) { + if t, ok := frontendTypes[strings.ToLower(strings.TrimSpace(s))]; ok { + return t, true + } + switch types.ModelType(s) { + case types.ModelTypeKnowledgeQA, types.ModelTypeEmbedding, types.ModelTypeRerank, + types.ModelTypeVLLM, types.ModelTypeASR: + return types.ModelType(s), true + } + return "", false +} diff --git a/internal/models/parity/catalog_baseline_test.go b/internal/models/parity/catalog_baseline_test.go new file mode 100644 index 00000000..f365ac55 --- /dev/null +++ b/internal/models/parity/catalog_baseline_test.go @@ -0,0 +1,113 @@ +package parity + +import ( + "crypto/sha256" + "encoding/json" + "fmt" + "os" + "strings" + "testing" + + "github.com/Tencent/WeKnora/internal/models/api" + "github.com/Tencent/WeKnora/internal/models/chat" + "github.com/Tencent/WeKnora/internal/models/providers" + modelruntime "github.com/Tencent/WeKnora/internal/models/runtime" + "github.com/Tencent/WeKnora/internal/types" + "github.com/stretchr/testify/require" +) + +// This fixture was captured before the provider/runtime refactor. It pins every +// catalog entry, alias and family rule, including full resolved protocol options, +// endpoints and request bodies at every reasoning level. Updating it is an +// explicit compatibility decision, never part of normal model generation. +func TestCatalogMigrationBaseline(t *testing.T) { + actual := map[string]string{} + for _, vendor := range modelruntime.List() { + for _, entry := range vendor.Models() { + names := append([]string{entry.ID}, entry.Aliases...) + if entry.Match != "" { + names = append(names, strings.ReplaceAll(entry.Match, "*", "snapshot")) + } + for _, name := range names { + if name == "" { + continue + } + key := fmt.Sprintf("%s/%s/%s", vendor.ID, entry.Type, name) + r, err := modelruntime.Resolve( + modelruntime.Ref{ + Provider: vendor.ID, + Model: name, + ModelType: entry.Type, + }, + ) + if err != nil { + actual[key] = "error: " + err.Error() + continue + } + state := map[string]any{"resolved": r, "auth": vendor.AuthStyleFor(r.API)} + if vendor.Endpoint != nil { + u, q := vendor.Endpoint( + providers.EndpointRequest{ + BaseURL: r.BaseURL, + Model: name, + ModelType: entry.Type, + API: r.API, + EmbeddingAPI: r.EmbeddingAPI, + }, + ) + state["endpoint"], state["query"] = u, q + } + r.Vendor = nil // functions are not serializable; their output is captured above + if entry.Type == "" || entry.Type == types.ModelTypeKnowledgeQA { + bodies := map[string]any{} + for _, level := range api.ReasoningLadder { + for _, stream := range []bool{false, true} { + bodies[fmt.Sprintf("%s/%t", level, stream)] = buildBody(t, + &chat.ChatConfig{ + Provider: vendor.ID, + ModelName: name, + AppID: "app", + AppSecret: "secret", + BaseURL: reachableBaseURL( + vendor.GetDefaultURL( + types.ModelTypeKnowledgeQA, + ), + ), + }, + &api.Options{ + MaxTokens: 256, + Temperature: 0.5, + ReasoningEffort: level, + Thinking: ptrBool( + level != api.ReasoningOff, + ), + }, stream) + } + } + state["bodies"] = bodies + } + data, err := json.Marshal(state) + require.NoError(t, err, key) + actual[key] = fmt.Sprintf("%x", sha256.Sum256(data)) + } + } + } + const path = "testdata/catalog-baseline.json" + if os.Getenv("WEKNORA_UPDATE_MODEL_BASELINE") == "1" { + data, err := json.MarshalIndent(actual, "", " ") + require.NoError(t, err) + require.NoError(t, os.MkdirAll("testdata", 0o755)) + require.NoError(t, os.WriteFile(path, append(data, '\n'), 0o644)) + } + data, err := os.ReadFile(path) + require.NoError(t, err) + var expected map[string]string + require.NoError(t, json.Unmarshal(data, &expected)) + require.Equal( + t, + expected, + actual, + "catalog or wire contract changed; inspect each difference before updating the baseline", + ) + t.Logf("verified %d catalog entries, aliases and family matches", len(actual)) +} diff --git a/internal/models/parity/parity_test.go b/internal/models/parity/parity_test.go index 9b10629e..9c0de964 100644 --- a/internal/models/parity/parity_test.go +++ b/internal/models/parity/parity_test.go @@ -25,10 +25,11 @@ import ( "strings" "testing" + "github.com/Tencent/WeKnora/internal/models" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" "github.com/Tencent/WeKnora/internal/models/chat" - _ "github.com/Tencent/WeKnora/internal/models/vendors" + "github.com/Tencent/WeKnora/internal/models/providers" + modelruntime "github.com/Tencent/WeKnora/internal/models/runtime" "github.com/Tencent/WeKnora/internal/types" secutils "github.com/Tencent/WeKnora/internal/utils" "github.com/stretchr/testify/assert" @@ -68,7 +69,7 @@ func ptrBool(b bool) *bool { return &b } var userTurn = []api.Message{{Role: "user", Content: "hi"}} -// buildBody runs the production path: ChatConfig -> catalog.Resolve -> +// buildBody runs the production path: ChatConfig -> modelruntime.Resolve -> // protocol client -> request body, then round-trips through JSON so the // assertions see the real wire types. func buildBody(t *testing.T, cfg *chat.ChatConfig, opts *api.Options, stream bool) map[string]any { @@ -93,9 +94,9 @@ func buildBody(t *testing.T, cfg *chat.ChatConfig, opts *api.Options, stream boo return out } -func resolve(t *testing.T, provider, model string) *catalog.Resolved { +func resolve(t *testing.T, provider, model string) *modelruntime.Resolved { t.Helper() - r, err := catalog.Resolve(catalog.Ref{Provider: provider, Model: model}) + r, err := modelruntime.Resolve(modelruntime.Ref{Provider: provider, Model: model}) require.NoError(t, err) return r } @@ -253,7 +254,7 @@ func TestLegacyWireParity(t *testing.T) { { name: "openai reasoning model keeps max_completion_tokens and drops sampling", provider: "openai", model: "gpt-5.5", - extra: map[string]string{catalog.ExtraAPI: "openai-completions"}, + extra: map[string]string{models.ExtraAPI: "openai-completions"}, opts: &api.Options{MaxTokens: 100, Temperature: 0.7, TopP: 0.9}, want: map[string]any{ "max_completion_tokens": float64(100), "max_tokens": nil, @@ -325,7 +326,7 @@ func TestLegacyWireParity(t *testing.T) { // precedence rule: an explicit legacy override outranks that gate. name: "legacy extra_config.thinking_control still overrides the vendor default", provider: "deepseek", model: "deepseek-chat", - extra: map[string]string{catalog.ExtraThinkingControl: "chat_template_kwargs"}, + extra: map[string]string{models.ExtraThinkingControl: "chat_template_kwargs"}, opts: &api.Options{Thinking: ptrBool(true)}, want: map[string]any{ "chat_template_kwargs": map[string]any{"enable_thinking": true}, "thinking": nil, @@ -334,14 +335,14 @@ func TestLegacyWireParity(t *testing.T) { { name: "legacy extra_config.thinking_control=none silences thinking", provider: "volcengine", model: "doubao-seed-1-6-251015", - extra: map[string]string{catalog.ExtraThinkingControl: "none"}, + extra: map[string]string{models.ExtraThinkingControl: "none"}, opts: &api.Options{Thinking: ptrBool(true)}, want: map[string]any{"thinking": nil, "reasoning_effort": nil}, }, { name: "remote_model_name still overrides the wire model id", provider: "deepseek", model: "deepseek-chat", - extra: map[string]string{catalog.ExtraRemoteModelName: "deepseek-v4-pro-internal"}, + extra: map[string]string{models.ExtraRemoteModelName: "deepseek-v4-pro-internal"}, opts: &api.Options{}, want: map[string]any{"model": "deepseek-v4-pro-internal"}, }, @@ -441,7 +442,7 @@ func TestLegacyProviderDetection(t *testing.T) { "": "generic", } for url, want := range cases { - assert.Equal(t, want, catalog.DetectByURL(url), "DetectByURL(%q)", url) + assert.Equal(t, want, modelruntime.DetectByURL(url), "DetectByURL(%q)", url) } } @@ -449,7 +450,7 @@ func TestLegacyProviderDetection(t *testing.T) { // net that catches a newly added vendor or model entry that is malformed, // contradictory, or unresolvable — without anyone updating this test. func TestCatalogInvariants(t *testing.T) { - vendors := catalog.List() + vendors := modelruntime.List() require.NotEmpty(t, vendors, "no vendors registered") seenID := map[string]bool{} @@ -467,7 +468,7 @@ func TestCatalogInvariants(t *testing.T) { if v.RequiresAuth { assert.NotEmpty(t, v.Auth, "RequiresAuth without an auth style") } - if v.Auth == catalog.AuthSigned { + if v.Auth == providers.AuthSigned { assert.NotNil(t, v.Signer, "signed auth without a Signer hook") } @@ -489,7 +490,7 @@ func TestCatalogInvariants(t *testing.T) { } ids := map[string]bool{} - for _, m := range v.Models { + for _, m := range v.Models() { label := m.ID if label == "" { label = "match:" + m.Match @@ -523,7 +524,7 @@ func TestCatalogInvariants(t *testing.T) { if m.ID != "" { // Resolve validates the compat object against the model's // protocol: an unknown or misspelled key fails here. - _, err := catalog.Resolve(catalog.Ref{Provider: v.ID, Model: m.ID, ModelType: m.Type}) + _, err := modelruntime.Resolve(modelruntime.Ref{Provider: v.ID, Model: m.ID, ModelType: m.Type}) if bytes.Contains(m.Compat, []byte("unsupported_reason")) { // An entry that declares itself unserveable must say so // by refusing, not by resolving into a request shaped @@ -542,7 +543,7 @@ func TestCatalogInvariants(t *testing.T) { // model, with thinking on and off, and asserts the invariants that hold for // every vendor. A new model whose compat contradicts itself fails here. func TestEveryChatModelRequestShape(t *testing.T) { - for _, v := range catalog.List() { + for _, v := range modelruntime.List() { if !v.SupportsType(types.ModelTypeKnowledgeQA) { continue } @@ -580,7 +581,7 @@ func TestEveryChatModelRequestShape(t *testing.T) { assert.NotContains(t, body, "temperature", "thinking=%v: model rejects sampling parameters", thinking) } - if settings.ThinkingFormat == catalog.ThinkingFormatNone { + if settings.ThinkingFormat == api.ThinkingFormatNone { for _, field := range []string{"thinking", "enable_thinking", "reasoning_effort", "reasoning"} { assert.NotContains(t, body, field, "thinking=%v: %s must not be sent when the vendor has no thinking format", @@ -611,10 +612,10 @@ func TestEveryChatModelRequestShape(t *testing.T) { // other vendor does: a signed request to a non-standard path, and plain-text // content because the endpoint rejects multi-part messages. func TestWeKnoraCloudTransport(t *testing.T) { - v, ok := catalog.Get("weknoracloud") + v, ok := modelruntime.Get("weknoracloud") require.True(t, ok) require.NotNil(t, v.Endpoint, "WeKnora Cloud needs a custom endpoint") - url, _ := v.Endpoint(catalog.EndpointRequest{ + url, _ := v.Endpoint(providers.EndpointRequest{ BaseURL: "https://weknora.weixin.qq.com", ModelType: types.ModelTypeKnowledgeQA, }) assert.Equal(t, "https://weknora.weixin.qq.com/api/v1/chat/completions", url) @@ -634,7 +635,7 @@ func TestWeKnoraCloudTransport(t *testing.T) { // base URL, and those must keep speaking that protocol after the switch to // native generateContent as the default. func TestGeminiLegacyBaseURLKeepsOpenAIProtocol(t *testing.T) { - r, err := catalog.Resolve(catalog.Ref{ + r, err := modelruntime.Resolve(modelruntime.Ref{ Provider: "gemini", Model: "gemini-2.5-pro", BaseURL: "https://generativelanguage.googleapis.com/v1beta/openai", }) @@ -699,7 +700,7 @@ func TestGeminiCredentialFollowsTheProtocol(t *testing.T) { // registry map and the per-vendor slices are shared, so a resolver that // mutated them would corrupt another request. Run with -race. func TestConcurrentResolve(t *testing.T) { - vendors := catalog.List() + vendors := modelruntime.List() require.NotEmpty(t, vendors) const goroutines = 32 @@ -713,7 +714,7 @@ func TestConcurrentResolve(t *testing.T) { if len(models) > 0 { name = models[i%len(models)].ID } - r, err := catalog.Resolve(catalog.Ref{Provider: v.ID, Model: name}) + r, err := modelruntime.Resolve(modelruntime.Ref{Provider: v.ID, Model: name}) if err != nil { t.Errorf("resolve %s/%s: %v", v.ID, name, err) return @@ -721,7 +722,7 @@ func TestConcurrentResolve(t *testing.T) { // Touch the derived views the handlers use. _ = r.Capabilities() _ = r.ThinkingLevels.SupportedLevels() - _ = catalog.DetectByURL(r.BaseURL) + _ = modelruntime.DetectByURL(r.BaseURL) } }(i) } @@ -737,11 +738,11 @@ func TestConcurrentResolve(t *testing.T) { // page they came from is recorded next to them, and the model editor links an // operator straight to that page from the picker. models.json may state the // URL once at file level for the entries a single page covers, so this also -// covers MustParseModels pushing it down — before that it was parsed and +// covers the generator preserving per-entry sources — previously it was parsed and // dropped, and most entries had nothing to link to. func TestEveryCatalogModelDocumentsItsSource(t *testing.T) { - for _, vendor := range catalog.List() { - for _, model := range vendor.Models { + for _, vendor := range modelruntime.List() { + for _, model := range vendor.Models() { name := model.ID if name == "" { name = model.Match diff --git a/internal/models/parity/rerank_test.go b/internal/models/parity/rerank_test.go index 113061e6..90618bcf 100644 --- a/internal/models/parity/rerank_test.go +++ b/internal/models/parity/rerank_test.go @@ -8,9 +8,11 @@ import ( "strings" "testing" + "github.com/Tencent/WeKnora/internal/models" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" + "github.com/Tencent/WeKnora/internal/models/providers" "github.com/Tencent/WeKnora/internal/models/rerank" + modelruntime "github.com/Tencent/WeKnora/internal/models/runtime" "github.com/Tencent/WeKnora/internal/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -19,7 +21,7 @@ import ( // TestEveryRerankVendorResolvesToAKnownProtocol walks the catalog, so a newly // added vendor is covered without touching this file. func TestEveryRerankVendorResolvesToAKnownProtocol(t *testing.T) { - vendors := catalog.ListByType(types.ModelTypeRerank) + vendors := modelruntime.ListByType(types.ModelTypeRerank) require.NotEmpty(t, vendors, "no vendor serves rerank") for _, v := range vendors { @@ -28,7 +30,7 @@ func TestEveryRerankVendorResolvesToAKnownProtocol(t *testing.T) { if catalogued := v.ModelsByType(types.ModelTypeRerank); len(catalogued) > 0 { model = catalogued[0].ID } - resolved, err := catalog.Resolve(catalog.Ref{ + resolved, err := modelruntime.Resolve(modelruntime.Ref{ Provider: v.ID, Model: model, ModelType: types.ModelTypeRerank, }) require.NoError(t, err) @@ -36,7 +38,7 @@ func TestEveryRerankVendorResolvesToAKnownProtocol(t *testing.T) { "unknown rerank protocol %q", resolved.RerankAPI) // The catch-all vendor has no endpoint of its own: the operator // supplies one, and Validate requires it. - if v.ID != catalog.GenericID { + if v.ID != providers.GenericID { assert.NotEmpty(t, resolved.BaseURL, "rerank vendors need a default endpoint") } @@ -73,7 +75,7 @@ func TestRerankProtocolAssignment(t *testing.T) { "litellm": api.RerankCohere, } { t.Run(id, func(t *testing.T) { - resolved, err := catalog.Resolve(catalog.Ref{ + resolved, err := modelruntime.Resolve(modelruntime.Ref{ Provider: id, Model: "m", ModelType: types.ModelTypeRerank, }) require.NoError(t, err) @@ -216,11 +218,11 @@ func TestSignedRerankVendorRequiresItsIdentityPair(t *testing.T) { // managed vendor documents the field, and sending it to one is how an // undocumented parameter ends up on every request. func TestTruncatePromptTokensOnlyReachesVLLMClassVendors(t *testing.T) { - optIn := map[string]string{catalog.ExtraTruncatePromptTokens: "512"} + optIn := map[string]string{models.ExtraTruncatePromptTokens: "512"} for _, id := range []string{"generic", "gpustack"} { t.Run(id+" accepts it", func(t *testing.T) { - resolved, err := catalog.Resolve(catalog.Ref{ + resolved, err := modelruntime.Resolve(modelruntime.Ref{ Provider: id, Model: "m", ModelType: types.ModelTypeRerank, BaseURL: "http://127.0.0.1:9/v1", Extra: optIn, }) @@ -231,7 +233,7 @@ func TestTruncatePromptTokensOnlyReachesVLLMClassVendors(t *testing.T) { for _, id := range []string{"jina", "zhipu", "siliconflow", "qianfan", "weknoracloud", "aliyun", "nvidia"} { t.Run(id+" rejects it", func(t *testing.T) { - _, err := catalog.Resolve(catalog.Ref{ + _, err := modelruntime.Resolve(modelruntime.Ref{ Provider: id, Model: "m", ModelType: types.ModelTypeRerank, Extra: optIn, }) require.Error(t, err, "a managed vendor must not silently accept a vLLM extension") @@ -242,10 +244,10 @@ func TestTruncatePromptTokensOnlyReachesVLLMClassVendors(t *testing.T) { func TestTruncatePromptTokensRejectsAnInvalidValue(t *testing.T) { for _, raw := range []string{"0", "-1", "abc"} { - _, err := catalog.Resolve(catalog.Ref{ + _, err := modelruntime.Resolve(modelruntime.Ref{ Provider: "generic", Model: "m", ModelType: types.ModelTypeRerank, BaseURL: "http://127.0.0.1:9/v1", - Extra: map[string]string{catalog.ExtraTruncatePromptTokens: raw}, + Extra: map[string]string{models.ExtraTruncatePromptTokens: raw}, }) require.Error(t, err, "value %q", raw) } @@ -256,7 +258,7 @@ func TestTruncatePromptTokensRejectsAnInvalidValue(t *testing.T) { // test watched them; now they are declarations, so they need their own guard — // TestEveryRerankVendorResolvesToAKnownProtocol only checks they are sane. func TestRerankCeilingsAreTheDocumentedOnes(t *testing.T) { - for id, want := range map[string]catalog.RerankSettings{ + for id, want := range map[string]api.RerankSettings{ // docs.bigmodel.cn: 最多 128 条,query 与单条文档各 4096 字符 "zhipu": {MaxDocuments: 128, MaxQueryChars: 4096, MaxDocumentChars: 4096}, // cloud.tencent.com/document/product/1772: RunRerank 60 docs, @@ -274,7 +276,7 @@ func TestRerankCeilingsAreTheDocumentedOnes(t *testing.T) { "aliyun": {MaxDocuments: 500}, } { t.Run(id, func(t *testing.T) { - resolved, err := catalog.Resolve(catalog.Ref{ + resolved, err := modelruntime.Resolve(modelruntime.Ref{ Provider: id, Model: "m", ModelType: types.ModelTypeRerank, }) require.NoError(t, err) @@ -292,7 +294,7 @@ func TestRerankCeilingsAreTheDocumentedOnes(t *testing.T) { // ever had a client-level timeout. Without it a hung endpoint holds the // retrieval stage open for as long as the caller's context allows. func TestWeKnoraCloudRerankKeepsItsDeadline(t *testing.T) { - resolved, err := catalog.Resolve(catalog.Ref{ + resolved, err := modelruntime.Resolve(modelruntime.Ref{ Provider: "weknoracloud", Model: "rerank", ModelType: types.ModelTypeRerank, }) require.NoError(t, err) @@ -300,7 +302,7 @@ func TestWeKnoraCloudRerankKeepsItsDeadline(t *testing.T) { // Everyone else has always run without one and relies on the caller. for _, id := range []string{"zhipu", "jina", "siliconflow", "aliyun", "nvidia", "generic"} { - other, err := catalog.Resolve(catalog.Ref{ + other, err := modelruntime.Resolve(modelruntime.Ref{ Provider: id, Model: "m", ModelType: types.ModelTypeRerank, }) require.NoError(t, err) @@ -316,14 +318,14 @@ func TestWeKnoraCloudRerankKeepsItsDeadline(t *testing.T) { // all it takes — and it must be declared exactly where the extension is // accepted, or the form offers a switch the vendor will reject. func TestTruncatePromptTokensIsReachableFromTheEditor(t *testing.T) { - for _, v := range catalog.ListByType(types.ModelTypeRerank) { - var field *catalog.ExtraField + for _, v := range modelruntime.ListByType(types.ModelTypeRerank) { + var field *providers.ExtraField for i := range v.ExtraFields { - if v.ExtraFields[i].Key == catalog.ExtraTruncatePromptTokens { + if v.ExtraFields[i].Key == models.ExtraTruncatePromptTokens { field = &v.ExtraFields[i] } } - resolved, err := catalog.Resolve(catalog.Ref{ + resolved, err := modelruntime.Resolve(modelruntime.Ref{ Provider: v.ID, Model: "m", ModelType: types.ModelTypeRerank, }) require.NoError(t, err) @@ -350,8 +352,8 @@ func TestRerankScoreScalesMatchTheVendorDocs(t *testing.T) { // GPUStack: relevance_score, e.g. 1.951 / -3.734 / -6.157 logitScaled := map[string]bool{"nvidia": true, "gpustack": true} - for _, v := range catalog.ListByType(types.ModelTypeRerank) { - resolved, err := catalog.Resolve(catalog.Ref{ + for _, v := range modelruntime.ListByType(types.ModelTypeRerank) { + resolved, err := modelruntime.Resolve(modelruntime.Ref{ Provider: v.ID, Model: "m", ModelType: types.ModelTypeRerank, }) require.NoError(t, err) @@ -369,7 +371,7 @@ func TestRerankScoreScalesMatchTheVendorDocs(t *testing.T) { // construction with the reason beats sending a request shaped for the wrong // protocol and reporting whatever the decoder makes of the reply. func TestUnimplementedRerankDialectsAreRefused(t *testing.T) { - v, ok := catalog.Get("aliyun") + v, ok := modelruntime.Get("aliyun") require.True(t, ok) offered := make([]string, 0) @@ -379,7 +381,7 @@ func TestUnimplementedRerankDialectsAreRefused(t *testing.T) { assert.NotContains(t, offered, "qwen3-rerank", "the picker must not offer an unimplemented dialect") assert.Contains(t, offered, "gte-rerank-v2") - _, err := catalog.Resolve(catalog.Ref{ + _, err := modelruntime.Resolve(modelruntime.Ref{ Provider: "aliyun", Model: "qwen3-rerank", ModelType: types.ModelTypeRerank, }) require.Error(t, err) @@ -387,7 +389,7 @@ func TestUnimplementedRerankDialectsAreRefused(t *testing.T) { "the error should name the protocol the model actually speaks") // The vendor's other rerank model is unaffected. - _, err = catalog.Resolve(catalog.Ref{ + _, err = modelruntime.Resolve(modelruntime.Ref{ Provider: "aliyun", Model: "gte-rerank-v2", ModelType: types.ModelTypeRerank, }) require.NoError(t, err) @@ -411,7 +413,7 @@ func TestGatewayRerankEndpoints(t *testing.T) { {provider: "litellm", wantURL: "http://your_litellm_proxy/rerank"}, } { t.Run(tc.provider, func(t *testing.T) { - resolved, err := catalog.Resolve(catalog.Ref{ + resolved, err := modelruntime.Resolve(modelruntime.Ref{ Provider: tc.provider, Model: "m", ModelType: types.ModelTypeRerank, }) require.NoError(t, err) @@ -438,19 +440,19 @@ func TestScoreScaleIsOverridablePerRow(t *testing.T) { for _, id := range []string{"gpustack", "generic"} { t.Run(id, func(t *testing.T) { base := "http://127.0.0.1:9/v1" - overridden, err := catalog.Resolve(catalog.Ref{ + overridden, err := modelruntime.Resolve(modelruntime.Ref{ Provider: id, Model: "bge-reranker-v2-m3", ModelType: types.ModelTypeRerank, - BaseURL: base, Extra: map[string]string{catalog.ExtraScoreScale: "probability"}, + BaseURL: base, Extra: map[string]string{models.ExtraScoreScale: "probability"}, }) require.NoError(t, err) assert.Equal(t, api.ScoreProbability, overridden.Rerank.ScoreScale) // And the input to set it is rendered by the editor. - v, ok := catalog.Get(id) + v, ok := modelruntime.Get(id) require.True(t, ok) - var field *catalog.ExtraField + var field *providers.ExtraField for i := range v.ExtraFields { - if v.ExtraFields[i].Key == catalog.ExtraScoreScale { + if v.ExtraFields[i].Key == models.ExtraScoreScale { field = &v.ExtraFields[i] } } @@ -460,10 +462,10 @@ func TestScoreScaleIsOverridablePerRow(t *testing.T) { }) } - _, err := catalog.Resolve(catalog.Ref{ + _, err := modelruntime.Resolve(modelruntime.Ref{ Provider: "gpustack", Model: "m", ModelType: types.ModelTypeRerank, BaseURL: "http://127.0.0.1:9/v1", - Extra: map[string]string{catalog.ExtraScoreScale: "sigmoid"}, + Extra: map[string]string{models.ExtraScoreScale: "sigmoid"}, }) require.Error(t, err, "an unknown scale must not be treated as a probability") } @@ -476,10 +478,10 @@ func TestScoreScaleIsOverridablePerRow(t *testing.T) { func TestGatewayVendorsOfferTheScoreScaleOverride(t *testing.T) { gateways := map[string]bool{"generic": true, "gpustack": true, "litellm": true} - for _, v := range catalog.ListByType(types.ModelTypeRerank) { - var field *catalog.ExtraField + for _, v := range modelruntime.ListByType(types.ModelTypeRerank) { + var field *providers.ExtraField for i := range v.ExtraFields { - if v.ExtraFields[i].Key == catalog.ExtraScoreScale { + if v.ExtraFields[i].Key == models.ExtraScoreScale { field = &v.ExtraFields[i] } } @@ -502,7 +504,7 @@ func TestGatewayVendorsOfferTheScoreScaleOverride(t *testing.T) { // Every operator-facing string a vendor declares has to exist in both // languages, or half the product reads English prose in a Chinese form. func TestEveryExtraFieldProseIsLocalized(t *testing.T) { - for _, v := range catalog.List() { + for _, v := range modelruntime.List() { for _, field := range v.ExtraFields { if field.Placeholder != "" && strings.Contains(field.Placeholder, " ") { assert.NotEqual(t, field.Placeholder, field.LocalizedPlaceholder("zh-CN"), diff --git a/internal/models/parity/testdata/catalog-baseline.json b/internal/models/parity/testdata/catalog-baseline.json new file mode 100644 index 00000000..9f74f4c1 --- /dev/null +++ b/internal/models/parity/testdata/catalog-baseline.json @@ -0,0 +1,353 @@ +{ + "aliyun/ASR/qwen3-asr-flash": "bb6104c02ce1013fd954de79c4998fd5b9e96e8b91cbbe083c9bc02a23660d7a", + "aliyun/ASR/snapshot": "error: catalog: aliyun does not serve \"\" through a protocol this build implements: Alibaba's other recognition models take a public file URL or run as asynchronous tasks; only qwen3-asr-flash accepts the audio in the request", + "aliyun/Embedding/multimodal-embeddingsnapshot": "841622b61917a7ec092feffad27e86d4a9125deecdc27d46117c439d44c85806", + "aliyun/Embedding/qwen2.5-vl-embeddingsnapshot": "b975e014ce58f39766a416bd75098b7d17124a63a71861b5e53316ef2eb22b1b", + "aliyun/Embedding/qwen3-vl-embeddingsnapshot": "6360c00080aace602f2f430b8fbdd61a03db3307fe8d760b4fd72c516361b57e", + "aliyun/Embedding/qwen3.7-text-embedding": "1747d31bcb369f32605000f3f2cc59406a4f7ddc5be6123c80e4e06f5d7fc2e7", + "aliyun/Embedding/qwen3.7-text-embedding-flash": "14ce61f8e4aea6394b43f6383bd2ec3d1398abd0a8d666374c4300fb86845cd5", + "aliyun/Embedding/text-embedding-v1": "1e7d78c2635542f53008f0aa30d69544fd4fae3a48d36745b027875005cfb2d6", + "aliyun/Embedding/text-embedding-v2": "b3eb2440097a26c93dea795bdf9b9d1ea4d4a11f1e20a034e2bb146d7226883f", + "aliyun/Embedding/text-embedding-v3": "ef7acfe7150c048a9c46d5e8e2bc14d890df0721f877d76c41e6a2ed275bb7cc", + "aliyun/Embedding/text-embedding-v4": "acd6a3536ee4f98330fb02e39c9f1952dbb1eb578d70a82c64278355ca44bc36", + "aliyun/Embedding/tongyi-embedding-vision-flash": "4e471e8267f1a58f999fea0c7c8d7280f96977d08f5381845195d98d141103c4", + "aliyun/Embedding/tongyi-embedding-vision-plus": "0962b5ddbc901c0428bcab0ab362059ecd1628b6e1c8b41907122d6e8a037068", + "aliyun/Embedding/tongyi-embedding-visionsnapshot": "f6dc43b2e5f638957bb1fedb361d4bd5f68a86d656ca1bd662be21695d18c9f9", + "aliyun/KnowledgeQA/deepseek-r1": "735322a596dda4a914b7e53041643eab61bd90b51e18e0cffd36dcc807b6fd16", + "aliyun/KnowledgeQA/deepseek-v3snapshot": "b3e72a6d322e5d53b18cf1204434be5f75de77262e67bab838492376c7c287b3", + "aliyun/KnowledgeQA/deepseek-v4-flash": "ac9d4d9224054609f98ba4ab3fc32c47b99f6af8c4153793a2fd00f5495212e9", + "aliyun/KnowledgeQA/deepseek-v4-pro": "721e53ca9a8ce694089bcd40191192bc977da23b4a1d4bd0dedf4fdc49211d22", + "aliyun/KnowledgeQA/deepseek-v4snapshot": "0d8da530ae0a30876180c66297759e2432c7f1d75a3d619a8d16e62a68855947", + "aliyun/KnowledgeQA/glm-5.3": "4dd3f7f0fa9a150dc5f5a04ac2e966d4ba72175469899595e2be1e25b3ced1cc", + "aliyun/KnowledgeQA/glm-5snapshot": "1ac48a35980b980f74bba9ec66d544f4002d0cae9a56df6e56af048a4638d773", + "aliyun/KnowledgeQA/kimi-k2.6": "c3abc2f5dca8649975aeba02b65d00b5e9d52a42d1ed78738e4ab52f21519cc6", + "aliyun/KnowledgeQA/kimi-k2snapshot": "fe5309c7a15bd6d1a1f0a7a6ff6781114bca8df784d51426d10435f3b6bfe801", + "aliyun/KnowledgeQA/kimi-k3": "bc5876d0856c08564e99bf64fe7d3d146ac198dbe2162aed5da5dc31e4414e76", + "aliyun/KnowledgeQA/qwen-flash": "0dd76b78c1ec61684c3652e2071669dd7cf3bfebf5f2ac5455256ab7a3fea943", + "aliyun/KnowledgeQA/qwen-flashsnapshot": "c87b62a72825e100762a35f59a9de188e5c32b9af200a88f52f53b31e242919c", + "aliyun/KnowledgeQA/qwen-max": "6cbf111674fb87b581e0a00ba5bc374f755350df9f0f1b04cb1c57f2fbcf93bd", + "aliyun/KnowledgeQA/qwen-maxsnapshot": "a82d0a42e7fda949b518405d13d1ffb00c2e638b9057eaa023d97133e47202a7", + "aliyun/KnowledgeQA/qwen-plus": "9cddc4357709d690a0d6fc7c4f5e489f2be896079a5c2c0865ee8d584cb0710b", + "aliyun/KnowledgeQA/qwen-plussnapshot": "71d8ee8a8211fd8185fa6d55ceb54d3bc211bab28de145eed903909ea56f99b9", + "aliyun/KnowledgeQA/qwen-turbo": "2509ff8973a28864388f0f78bc9cf5ff39c41badcbb0b68c006fbd737d8b733f", + "aliyun/KnowledgeQA/qwen-turbosnapshot": "763ccbe6edf8591c503e0fa583ccb57f2f3b1d3301d8755f281b93973c86ffdd", + "aliyun/KnowledgeQA/qwen-vl-max": "363afe785842c67a130d5b52276898907ab6ec68fa94f7daeb92f620d9461241", + "aliyun/KnowledgeQA/qwen-vl-plus": "93ceef7e0934e75ba46c29808100d06beb5b17e166d42b1a8f9b67827445bb20", + "aliyun/KnowledgeQA/qwen3-max": "26c68d4418a2ac820f38298cc02c819759ad07ad73f1cdfb0717c2f3fb3b4777", + "aliyun/KnowledgeQA/qwen3-vl-plus": "a9c17b4adc677e16c45c46f7c3d349050cf74f8bc45f4b00801d27bcef7afb0f", + "aliyun/KnowledgeQA/qwen3.5-flash": "031aff057e413a6fbca8e23ad0c49c87c21966ee6a9433e62974da629c0e601b", + "aliyun/KnowledgeQA/qwen3.5-plus": "0996fbdbd529902600e90b5479fd33433a1a42dbfc5bd048261f8e731fec1199", + "aliyun/KnowledgeQA/qwen3.5snapshot": "aaeb6e1305ae6ed1e17f1f7d6f63998a6be1f643266510bd0b22de04cf1ec269", + "aliyun/KnowledgeQA/qwen3.6-flash": "b0d78ba90bc8389faf889ddb233433c9064be614c223f9e642d56a76343631a6", + "aliyun/KnowledgeQA/qwen3.6-plus": "ae8db4ffac0edb2acdc88415b4b86d7684b0c240adb5dc14d4396b83b249c287", + "aliyun/KnowledgeQA/qwen3.6snapshot": "99d81f0501afe9bc35d73bde4994bf9694c3eac8df3db5555bda7ebe9a4d8c2d", + "aliyun/KnowledgeQA/qwen3.7-flash": "bb843bbbcb15592b40b0440eefd62ccf33071296fafe2f62ad91b568d79a2278", + "aliyun/KnowledgeQA/qwen3.7-max": "2d928e94ee5a8f4c7929b7864811809f24c9111c07c29ef5636a4f9100b5d24c", + "aliyun/KnowledgeQA/qwen3.7-plus": "a9c62431dbc611c0fbe8143abbbf6684fe693b80ab0df6ef51f3420c434c234d", + "aliyun/KnowledgeQA/qwen3.7snapshot": "c4f7868c2d989871b19f56ded1c2618681c42c9df3e21387b79592e684bce552", + "aliyun/KnowledgeQA/qwen3.8-flash": "cfc1b3931753e0c95289e593b1b090492ab406cd5ba61e7b2517d9a0ca3202b7", + "aliyun/KnowledgeQA/qwen3.8-max": "59599abf4bf64d2f9c7a3facb860fcbcddcdf833533202d6abf04f67b86bc4ec", + "aliyun/KnowledgeQA/qwen3.8snapshot": "c7ca540b17a3b0c74abaf31bff8e3c5f6cf41011c36380931086c13f9adf947e", + "aliyun/KnowledgeQA/qwen3snapshot": "aa634e380fcef6efc6ce9c096acb8d7ad75f8d80e3c078829ab47a08164d4cc8", + "aliyun/KnowledgeQA/qwq-32b": "b05df754c2d09e0fe937e85c6bda28b71ef3e694c0e06c17dccdbd9217fecb28", + "aliyun/KnowledgeQA/qwq-plus": "7139911fda2d14b002889abbd06c185e550bec0984cea85116510b17ba4063ea", + "aliyun/Rerank/gte-rerank-v2": "27219a2ffc212a35e9eeacf87da136410342e1915dd1141dc3357d7b40f9595b", + "aliyun/Rerank/qwen3-rerank": "error: catalog: aliyun does not serve \"qwen3-rerank\" through a protocol this build implements: qwen3-rerank speaks a different protocol (/compatible-api/v1/reranks, flat request, results at the top level) that no protocol package implements yet", + "anthropic/KnowledgeQA/claude-fable-5": "8cb0c332960f271acac66df25e0b8a1259c863994b6d4ef3c9be3df47f85b5bc", + "anthropic/KnowledgeQA/claude-fable-5-1": "fe4ee19f613745815e5caa1f258e67f9f9a901f5fc45c1d4cce030bfa6287b72", + "anthropic/KnowledgeQA/claude-haiku-4-5": "5eb4abef41f957d98c0a15c83de48c0e6b46be48d59f761ba6006c29010487f9", + "anthropic/KnowledgeQA/claude-haiku-4-5-20251001": "50878a87d7d212c8f295f191343f77200d71e71337b934a07a949ce04ef976f1", + "anthropic/KnowledgeQA/claude-opus-4-5": "3536e5a1bb14f6e980eeda66cca9d7fc8bfea8c6b26937765069d93f713a673d", + "anthropic/KnowledgeQA/claude-opus-4-5-20251101": "78bfa567c9c17acb9488ea0a7aaccb5b0e73e840db8c4955731debf1382ff8cf", + "anthropic/KnowledgeQA/claude-opus-4-6": "96f08927c9e9df5c113102d498d38c1aab3a7280f350f14cfe8fad4dfcffe039", + "anthropic/KnowledgeQA/claude-opus-4-7": "7b85755f5c9166ecd8e2e25d1ac60e580aa982ec8ab735c52fdec20dd8fa0db0", + "anthropic/KnowledgeQA/claude-opus-4-8": "aedacfa002c376af796c1eae5063d9fb17a1b980e0528207621f47d723b702dd", + "anthropic/KnowledgeQA/claude-opus-5": "6657decfbaaf44e3fc4aec8ac14fccd7e569e8614ce7127049a092de821132d3", + "anthropic/KnowledgeQA/claude-sonnet-4-5": "176ba6989053acf35be0a6acdd421c1c94c20f183358544eb0343c6e74897220", + "anthropic/KnowledgeQA/claude-sonnet-4-5-20250929": "6757d77ed1d25cf80d04d2d35217a7f5d94e37f1b7c3545bf1613ac0494ec388", + "anthropic/KnowledgeQA/claude-sonnet-4-6": "c00c494964632af431731f6fdf2ba4d697d42b8e58600e8a28e6a880ad6f0cda", + "anthropic/KnowledgeQA/claude-sonnet-5": "bcb9eaafd30ca276f91fddf6bd62cdbdce38129300abd069e202245568273f41", + "azure_openai/Embedding/text-embedding-3snapshot": "0c2f547ad2206affe719f6f0775ee73574a4dda8a7993a699ee9c4e7d4983cab", + "azure_openai/KnowledgeQA/gpt-4.1snapshot": "6b6e303e1e4ed32f972e8224ab090f835e63570543036912809fc6e2551f923c", + "azure_openai/KnowledgeQA/gpt-4osnapshot": "69fab35e2db1fab9640c72ab3b0c7acae322a1d0758c61ade28bc39fb9f9f750", + "azure_openai/KnowledgeQA/gpt-5": "db0a775a9c41d10b19d7707826820455e4b8f07cd5fbf9340f1329d97531d564", + "azure_openai/KnowledgeQA/gpt-5-mini": "4b0569c209354289d80d9e897e199a0deb1e759b685e1f1f13d87b5a54aee4d6", + "azure_openai/KnowledgeQA/gpt-5-nano": "362639f61878bf5dbe5c1f61172a7f617984014ef23e2d2183d0debebf17ba3d", + "azure_openai/KnowledgeQA/gpt-5snapshot": "0212af206f4f3be585e5be378ae78d2a72e127dfd017b2ea3f0e31680377a15f", + "azure_openai/KnowledgeQA/gpt-6snapshot": "32f322083e4d338bad9d46878e193be7914754a38771204a2ea110050b8fa655", + "azure_openai/KnowledgeQA/o1snapshot": "932a1de3ec30ca2f61c26391d01e8053c167417818a347f1fff3968351992868", + "azure_openai/KnowledgeQA/o3snapshot": "06838afe2bf35d03ad99cdceb6b088f272fa83aa4cc25d461d3b0ad034573066", + "azure_openai/KnowledgeQA/o4snapshot": "5a234aaf785bf4b2835f8dbcc49b0f6ce886743ef6d429c68180ca247c9b5a3e", + "deepseek/KnowledgeQA/deepseek-chat": "07512b23255f3d8ca9b19123617f7fecdf0da538b6d4c3ea7773ccc73a08be00", + "deepseek/KnowledgeQA/deepseek-flash": "77d77b5c366570d4ba6e9b088c2690e8970e0284af7f5a6b4c114ff2024afdd3", + "deepseek/KnowledgeQA/deepseek-reasoner": "0765764d483664d8df1d1fe2c708671a74eb355764cec3e7a3e1cfe0a1b6e89a", + "deepseek/KnowledgeQA/deepseek-v4-flash": "a1d11bc227bae61b53cd3642d32c59affa715b2cdb73fc53995c6a0ad9977438", + "deepseek/KnowledgeQA/deepseek-v4-pro": "5b245660012e5b1e4160861575244ecd1d0feb9b24a366d10cc58b4ae8257786", + "gemini/Embedding/gemini-embedding-001": "2126e8863f9ba5d4cef4e0154c5b8ce8579dddd7d8aeb674bb74632b6294a7dd", + "gemini/Embedding/gemini-embedding-2": "e99a5211364c62e875aa93c65911197d150f8e5581654705da6433ca129c34e7", + "gemini/Embedding/gemini-embedding-2-preview": "a9d78acffaeabbae5c554d346a2c5893b7b68882f239cc5fc1e108126d4c8260", + "gemini/KnowledgeQA/gemini-2.5-flash": "8fd1fd7205b512d2e7c506f171d4cf09f77e7c1f08d327942e42a63dd6a10560", + "gemini/KnowledgeQA/gemini-2.5-flash-lite": "04688ec4b28a2ffc5afd5fa501b6ea144c3ee519badcbb36d82b61d44a25dd17", + "gemini/KnowledgeQA/gemini-2.5-pro": "6929d8015b51e7326d9de5f333408b7abe91c23f87623af4f4434a78a6cbbaa2", + "gemini/KnowledgeQA/gemini-3-flash-preview": "b2f619cdd5fbcd2202198be74c9215b1998e3e428cd46f7c38a38dceeee36542", + "gemini/KnowledgeQA/gemini-3.1-flash-lite": "c8a1e2b17e829616366e2ad52cfb2e331c6e62e6c9682150da6ec5a0ebb94604", + "gemini/KnowledgeQA/gemini-3.1-pro-preview": "53ce7edd9dc46112991f6ea1746dc419abcfad267c694db8d461fdd9a4275177", + "gemini/KnowledgeQA/gemini-3.5-flash": "2abcc9d6223b140d31e73c4ea63f9f25b9728c6bea9dcfd4bc1e7ec96d985a96", + "gemini/KnowledgeQA/gemini-3.5-flash-lite": "9c9815ef99aab3ab91926ecd8e0586598dde2737fe533d43d70c839bddd62521", + "gemini/KnowledgeQA/gemini-3.6-flash": "8be4820a9da0c156cad0684936bb3c6f1ae0833065cb45952f8d0027a5eb1fee", + "gemini/KnowledgeQA/gemini-3.7-flash": "570b30391590c3fa380e98e8323bf2187635d18db427eae3d75f9e63def26c8d", + "gemini/KnowledgeQA/gemini-3.8-flash": "6d40802ed8d3b310e1e91c186f769a4f8a298138538853cf623ad43e59c29140", + "gemini/KnowledgeQA/gemini-3snapshot": "c5931f2304774b718637f47540e78b66cbf855b4a4189c9fc0cea2040a12951d", + "generic/KnowledgeQA/gpt-5snapshot": "3e3712264316db008c1465a2d7c395072d85942d0352196e456342cef0b14eb0", + "generic/KnowledgeQA/o1snapshot": "52340886b4160a0cb9342ae33a7c81304c9dad5d22c2d1c1ce073f89860a30b1", + "generic/KnowledgeQA/o3snapshot": "782e836769e56c43d9c954ab2d563df7d2f476ae4fb4d588bb8bf3c88ae42ce6", + "generic/KnowledgeQA/o4snapshot": "dc652fe264d2c9bde369307bc48e8136ba92a5d31a54676374560ba878f2190a", + "hunyuan/Embedding/hunyuan-embedding": "8f8dff4309455e2bb4566768b6d335b34359a7d6aa5253eb11f3b59d16517c5a", + "hunyuan/KnowledgeQA/hunyuan-2.0-instruct-20251111": "1a634287a65c3317056937c9e9e35e28ae79e326f1910ee0f331618fc076acb9", + "hunyuan/KnowledgeQA/hunyuan-2.0-thinking-20251109": "1e982bc103cfc5830b0634a9b1a44a1a33bece3647606c712016c89ea17af467", + "hunyuan/KnowledgeQA/hunyuan-a13b": "615fcf75935e1b842cbfaf188d212546dd3a5450f1a850c7c7c269f3b3263dab", + "hunyuan/KnowledgeQA/hunyuan-lite": "c2a18cc8c2fecd9f807dc0a746c287c3a111bc0fe68453806fcd511c388f48e9", + "hunyuan/KnowledgeQA/hunyuan-t1-latest": "6b5be11d928cb578f87ad8fb151dabc2b41f9882e0eec5c2bbbdc63c8a9d4aac", + "hunyuan/KnowledgeQA/hunyuan-t1-vision-20250916": "edfac3f8a8a9b5f32852f4669b9cc13f3c8d326a3ab5f01008135b474853e5dc", + "hunyuan/KnowledgeQA/hunyuan-t1snapshot": "6d8d26d354fc6540e269a51d5a2e1108520e0c08133ca38f78d459ba0691770a", + "hunyuan/KnowledgeQA/hunyuan-turbos-latest": "e0c9996172983b9d47994f073438aea931bdd995b7794c84eae745502afb3466", + "hunyuan/KnowledgeQA/hunyuan-turbos-vision": "de1994d9055a856578b34082829c6de1728633d1e7e664b02b993131797f1291", + "hunyuan/KnowledgeQA/hunyuan-turbos-vision-video": "07d35ec30279d336e39257ff80f558dd69ffa1c3e865a34a1585f2a261aad640", + "hunyuan/KnowledgeQA/hunyuan-vision-1.5-instruct": "eb831ff45f66229ed468214ad2c40cd89e07d60021ee79685ff58d8cc68421e9", + "jina/Embedding/jina-code-embeddings-0.5b": "b0d7bb78d59e7ab07673bdff461f516c5b50a48903d0eaeeeb01bfd0f53fa730", + "jina/Embedding/jina-code-embeddings-1.5b": "06932f7c3e756ebfaedbcc60ff918cd7b544e3b4fdfaaca3bf49ef3746073e04", + "jina/Embedding/jina-embeddings-v3": "34fede5426a6aa78e1e2c575a7fef52afd3af53331155f15e82d6ae566beff69", + "jina/Embedding/jina-embeddings-v4": "f8b2c8a0328f5ba3b2e3eacb72dbbab13558d3961cf9c51eb76535b6a9d8db0b", + "jina/Embedding/jina-embeddings-v5-omni-nano": "90d9ca7bd2bccbe643d984d5eff478f09f5190436d5baefbc498e700bd7131c6", + "jina/Embedding/jina-embeddings-v5-omni-small": "fe239e4fc9e4ef3e61f6a43ea9eab9b23a249d85e8d2fbc38d2d5368fe0d6811", + "jina/Embedding/jina-embeddings-v5-text-nano": "c9efe64eee9dc11b2583155ce522af3332188b5bbedaaa8bc07caaab54910f74", + "jina/Embedding/jina-embeddings-v5-text-small": "16bdb3d6cba14b0fd16786cb6e9c16dfa411488661ff134629a330b0cbc9cba4", + "jina/Rerank/jina-reranker-m0": "056816679d30640e0c9c0583d42cb1db42bce784206d85397dff780ff6762552", + "jina/Rerank/jina-reranker-v2-base-multilingual": "40e4c4971b8fca257fd877fe92d59f8f4042552c07f8c0d3d282eddee491686a", + "jina/Rerank/jina-reranker-v3": "686a1e72192f3d0d4ca422135c08612131a96017eea0dae371ec390c81497ea7", + "jina/Rerank/jina-reranker-v3.5": "04141df650d26082775e4dda0e41c1fe0aaa712edcb6d70b2db71c2788835dcf", + "lkeap/KnowledgeQA/deepseek-r1": "910b88dd40f5445e1cb93d4f1f75d0a918b6c2cbbfb2f6dd626486cfc30a01af", + "lkeap/KnowledgeQA/deepseek-r1-0528": "e29f4d275bd351a9cba4dd109a13c70326403c50eedc630ef8c3d6be4c6b380d", + "lkeap/KnowledgeQA/deepseek-v3": "1d95b0fcec9e157382300ff255b002fb81073020f1d857b47ddff7c8c0cc6899", + "lkeap/KnowledgeQA/deepseek-v3-0324": "5d66cc4e847187520a51e6976edc2dceb11f1ef1ceb3bbc35b1c5f337e2a1f58", + "lkeap/KnowledgeQA/deepseek-v3.1": "b51473160f3d344f85d5e0ae45ac6f1db7343781aea471c4a9c7ddd72dbc1e5d", + "lkeap/KnowledgeQA/deepseek-v3.1-terminus": "6cd662bc9e0fd9b7e51f63dd97552f991897339a1e28301c099ee67c3a13fbc7", + "lkeap/KnowledgeQA/deepseek-v3.2": "3ac1f719fd185a24d899de8b0ab8bce08c55fdfaeaf4370e8084d80eb7841456", + "lkeap/KnowledgeQA/snapshotdeepseek-r1snapshot": "5fe12a729af1576b4446cf21e2df7d06147d1213da0b15bec1058ff4236fdf66", + "lkeap/KnowledgeQA/snapshotdeepseek-v3snapshot": "b488b275212bd6fb7543b43798aa30d5008a231d7cae749e06a2be3b469f5965", + "lkeap/Rerank/lke-reranker-base": "6e8dcdc74c37d9cf8abd2c513dcd8e79d43d6fc52ddc3bb44a95b25a6a191f52", + "longcat/KnowledgeQA/LongCat-2.0": "84748558b2d2dbdad28bfb9937d2cb8fd867cf6d6240f561eb4278b93f186b4a", + "longcat/KnowledgeQA/LongCat-Flash-Chat": "7f27f6c3e463fe45a39144ca5e0ca934e1157c7251e695a9f470d66bb63c4afb", + "longcat/KnowledgeQA/LongCat-Flash-Thinking": "30269a2c7037a4b928b0ea4164f9934f4dca117b03574de470e2d8053a8d661a", + "mimo/ASR/mimo-v2.5-asr": "cfd5e7af20f9bea915399d1de654049880144fd3b16b46d38563b328545f7d53", + "mimo/KnowledgeQA/mimo-v2-flash": "a1111e2792de419143f71c33230097b3d7e0e5b525c6e217713940f0a9e34246", + "mimo/KnowledgeQA/mimo-v2.5": "a53a5bf889aa110e4460fed294a3230758ddaa49a6db60e8b0408fe183a60ed9", + "mimo/KnowledgeQA/mimo-v2.5-pro": "3c38342327d6286db15a7548f651c2780d8b0998b2671d05f187781eb6a23262", + "mimo/KnowledgeQA/mimo-v2.5-pro-ultraspeed": "a47aba2614020595d63accdc1c3c6058cfebdb3198df58936fb95e28c9046092", + "minimax/ASR/asr-1.0": "3466d2d1953d8165ba7677de85f36fa933118f5dc902bf39fdfa9158b0ec0eab", + "minimax/KnowledgeQA/MiniMax-M2": "145995deb36b85b3f0933c4aed6273b97cbacf92891cae224949dae906d251cd", + "minimax/KnowledgeQA/MiniMax-M2.1": "b745d75ad3095e2fdc25d22d7f723c30078b9bbb155c4d0f7d1bc64c5dbfbb59", + "minimax/KnowledgeQA/MiniMax-M2.1-highspeed": "6f3d05e123ef452d9ed0b40456ccbe08c552ca2408f225dce40115add1b23fd5", + "minimax/KnowledgeQA/MiniMax-M2.5": "163e53955eb8a46362e4581513644be9c86c39ff744819f777ae4f2bd81bf81d", + "minimax/KnowledgeQA/MiniMax-M2.5-highspeed": "c1731e761db65503eaa72acdba28c95a1eaae15882d813534f7831b3256022cb", + "minimax/KnowledgeQA/MiniMax-M2.7": "2efbb13fcb0efd7c36987ad5d12d1d6c1d80f2e0b5518abeaac8dc603ff44050", + "minimax/KnowledgeQA/MiniMax-M2.7-highspeed": "7f7518fa498dc12eeec38d8d73daae4f1a43a207d07b9d2369948aaca347c5e8", + "minimax/KnowledgeQA/MiniMax-M3": "e0ab669e2f427ed88ad4d5defec501fa835fa6e32922f8942be5216d5076b92b", + "modelscope/Embedding/Qwen/Qwen3-Embedding-0.6B": "a4515af27268a360fe7ee62eb4c4785bc5e3079f65e0264acc99ba974b9a777b", + "modelscope/Embedding/Qwen/Qwen3-Embedding-8B": "a76960f74528a100af92aad4def93306da5eb819ba8fc916693197d779f0ebd2", + "modelscope/KnowledgeQA/Qwen/Qwen3-235B-A22B-Instruct-2507": "cbd8290913b5b1a584aaa9cd20ccb6478b67c62a73d9aa3f9f9c5aee0baf7d80", + "modelscope/KnowledgeQA/Qwen/Qwen3-235B-A22B-Thinking-2507": "35599fb7d339e43401eed51973c8f67f2440c40e96c4dfdcdb6f0393d39163be", + "modelscope/KnowledgeQA/Qwen/Qwen3-30B-A3B-Instruct-2507": "de63c30b559ee1b70d214465c67091c8892ed30e1213b1df7bbe06d22c4a31d5", + "modelscope/KnowledgeQA/Qwen/Qwen3-30B-A3B-Thinking-2507": "e2e2b90ca7a7178d660a86796a671d9ca05311b13b5c3d10a914a33249de0e77", + "modelscope/KnowledgeQA/Qwen/Qwen3-8B": "d9650153601f0e158e9799a2da4059925251959366d6bd511878c8c02ac49de2", + "modelscope/KnowledgeQA/Qwen/Qwen3-Coder-30B-A3B-Instruct": "54874cdaf43b7b91c520b7db9e33bf45cf7ae64aa2fece00c9d0d4c14e8c8bbe", + "modelscope/KnowledgeQA/Qwen/Qwen3-VL-235B-A22B-Instruct": "3fae347f784339e772be3d18d13182822ef2d16581ee4e2a588f5dc573945146", + "modelscope/KnowledgeQA/ZhipuAI/GLM-4.5": "4c3824594e8801642e459a728ef3d786fddf5ae9b7cad658f3ca868834d98d8f", + "modelscope/KnowledgeQA/ZhipuAI/GLM-4.6": "3c7c2713d06b22fef0cb7c4ca002c9d14049abf37be9750716d403e64caca607", + "moonshot/KnowledgeQA/kimi-k2-thinking": "78e9accc9b580b7b4ddfe804b6d234912d906e5b84098db9378743a933d653fa", + "moonshot/KnowledgeQA/kimi-k2-turbo-preview": "eef0bbc6a30c62c3125ea3bec013c99ce23c135e00be532ebf69f10946e2d197", + "moonshot/KnowledgeQA/kimi-k2.5": "dd37529bc898f32b26c1261396b9bd5461ddc36da08b43743185a9af4551555f", + "moonshot/KnowledgeQA/kimi-k2.6": "6a6e887f73fc5abcbe313c9ce5f15206f605b2f2f713c11acce3d720f8ba4c50", + "moonshot/KnowledgeQA/kimi-k2.7-code": "e010d8cac56af5fdd145466dd229bbc3b21ce7120dd2840df7a79599dd51126b", + "moonshot/KnowledgeQA/kimi-k2.7-code-highspeed": "2f6a58da0d422895eb49a1e2a85ef3ad1c25569c83ab6e08425a03ce39c08fff", + "moonshot/KnowledgeQA/kimi-k3": "d762c5e5af93b109df5ea421866ccb260f819a12768cb19e88f708ed39bc6e06", + "moonshot/KnowledgeQA/moonshot-v1-128k": "a083f7226a9ef76bd048db7852bfe263c8f080b5725b1dc0b99257ae3841ffb8", + "moonshot/KnowledgeQA/moonshot-v1-32k": "ba0dcd86e11bbcec03725d605d6a50ce308d5f6682fd9522b101a7ef81f2f709", + "moonshot/KnowledgeQA/moonshot-v1-8k": "118b5c3533abac97b6f364a3341d599856c5724842ccd809de6a27e7d78a9a5b", + "moonshot/KnowledgeQA/moonshot-v1-8k-vision-preview": "dfce889dafa16367941825e7e496b2ba542c0f950d796d30e60bc611ee20ea55", + "moonshot/KnowledgeQA/moonshot-v1snapshot": "ad805e8b2951004069afc16305e6dd5d24570bce9454fff41da4c89b0b552e8a", + "novita/Embedding/baai/bge-m3": "ead230cee65e288b3f8f1befb4cfb39dddf581528bb617a46feaa76e0454faab", + "novita/Embedding/qwen/qwen3-embedding-0.6b": "fd7fe2850e9f193d11bb27f1130bb325b95d95156c879f770c6e303599298e2e", + "novita/Embedding/qwen/qwen3-embedding-8b": "870036141aea257889436fc43fef077f91ca92451c5c78cd14fcb10697bbe7be", + "novita/KnowledgeQA/deepseek/deepseek-v4-flash": "46882c5a6f42c8c50189bd311fcd34e0f19e073006d94c403f7f7a0d130fb981", + "novita/KnowledgeQA/deepseek/deepseek-v4-pro": "202e557b0ae3ec4cc2647b9c362ff0b8cb36d381d296ba5cf74bc1a3df8c7095", + "novita/KnowledgeQA/google/gemma-4-31b-it": "3302698feace987ec23fad14ade2b771eef6cc60830baab3c93f0341994a475a", + "novita/KnowledgeQA/minimax/minimax-m2.7": "d46d5b8360a5d7d6a7c81750234fcde3bbff8a308368b85d098d7a5afec27795", + "novita/KnowledgeQA/moonshotai/kimi-k2.6": "1db1fe6b65cfb73ad60ee112020f7a44bf1d74b0bc5177ad49b1af5d19526811", + "novita/KnowledgeQA/moonshotai/kimi-k2.7-code": "4c84bb9463ccec60043eb6a1682f85b2de44e3257aeb6bae036b3de4bc3f6ee9", + "novita/KnowledgeQA/moonshotai/kimi-k3": "a4a9490695fab439e2ff3bbc428b3632cd6e1a2661c7664c76d86b0455c5ac30", + "novita/KnowledgeQA/qwen/qwen3.5-397b-a17b": "7d73f0dfcf6597fa8d885a7b23cfbc3dee5cf2999e8787c490da7d3e2d27ae07", + "novita/KnowledgeQA/qwen/qwen3.7-max": "e9ba323773ced5ebf841c3f58d68836a9123faa00ef6c307886f66d03c727ded", + "novita/KnowledgeQA/xiaomimimo/mimo-v2.5-pro": "c5af6bb090696d50afb7564d863e05e62d889f285eb385e676e2d3bf5064ae79", + "novita/KnowledgeQA/zai-org/glm-5.1": "f5e07a2348ba716a0c6fca88f9233bb591e38ba893290085a57098e94d0a90e2", + "novita/KnowledgeQA/zai-org/glm-5.2": "5801f0529d010aa9d60e4fbbb00be0ab90103fb241361daf03f9b81fc4975af5", + "nvidia/Embedding/nvidia/nemotron-3-embed-1b": "d5117e8e9b70279b2bd66152840f6c6421e79cdc953b76f8227573e9763f8216", + "nvidia/KnowledgeQA/deepseek-ai/deepseek-v4-flash-0731": "f2c975c6dc38d31fc297c847c0d4c82173dac24252886b4c91ae8ea3bad87bae", + "nvidia/KnowledgeQA/deepseek-ai/deepseek-v4-pro-0813": "ab2c7147362fba415f417037e4cc9a55c851613cb5febe1adc6867c9d8d68814", + "nvidia/KnowledgeQA/google/gemma-4-31b-it": "2d9d31c3f69fedbf720aac946e6ef7226280ee2d9cd11e2f41cb1f8a8ab05f3d", + "nvidia/KnowledgeQA/moonshotai/kimi-k2.6": "a62ebedfac75c0cd21a02ea11dfe6a3f7c021c0a055338268122174385cdf63d", + "nvidia/KnowledgeQA/moonshotai/kimi-k3": "26588e04850c35ef81c921daa4577ad50680cdd94570a795c2b0a26558c797b7", + "nvidia/KnowledgeQA/nvidia/nemotron-3-super-120b-a12b": "c0b0e182881bb1cae1d5e09edf0b18008ff84e766e71bf7f21540f77d3083aa6", + "nvidia/KnowledgeQA/nvidia/nemotron-3-ultra-550b-a55b": "16a998db79f88f0014802d020cc38cb7819e4c961964c1cb358cf698e3ca43c0", + "nvidia/KnowledgeQA/nvidia/nemotron-3.5-lightning-30b-a3b": "0b58b353733a2aa6c6254a31dd4b75e36eeaeb50fd87c79f89719db826c91766", + "nvidia/KnowledgeQA/z-ai/glm-5.3": "5b2cc061f54a17df95cdf53e359faab697869a6ddfb24c945aa7823577795c3f", + "nvidia/Rerank/nvidia/llama-nemotron-rerank-vl-1b-v2": "16ac1bfe044ead2a6d46ee3a8c9b8ab6f2b8256ae2cb050121331d515fa466cc", + "nvidia/Rerank/nvidia/nv-rerankqa-mistral-4b-v3": "7fb22c5cb8dfb51d09e8fd4ad0d174f4734cf174e1d270ec190a56460d4fa939", + "openai/ASR/gpt-4o-mini-transcribe": "ce0044f799b08a1524971126a2881e0a0f830d26cc44f141f93f944ac55eee8b", + "openai/ASR/gpt-4o-transcribe": "3e533c7d02be1039d0316d2c4968ce73052240248baa096c1df5cabf713692e9", + "openai/ASR/gpt-transcribe": "540a1ae5b477a4f73d9c2269bb3ec2b7f95459995140517987ae5f76e68b6899", + "openai/ASR/whisper-1": "0636eb35239490f9e8e6a1d3fee44b9826a391e021e85aed7072c33fdcf2218c", + "openai/Embedding/text-embedding-3-large": "3c14fc11141e7f473040fefb14ba5595e1dcb193e970b4480554935d1c118435", + "openai/Embedding/text-embedding-3-small": "96dba6192448cf2a6e6b1aff646bd5be063e49fdea64b277555f4b5297b4560b", + "openai/Embedding/text-embedding-ada-002": "410188713299a54711ca75e6d82c950d45e506602a71ec1dfbea298460a78d94", + "openai/KnowledgeQA/gpt-4.1": "2c2025b04be58eb7dbb846ff5aa3098db2d4e0e556f5ae04a0727ed5ee122ed7", + "openai/KnowledgeQA/gpt-4.1-mini": "6cd397454d5b4ff738b14c93c58bab88a447904da3332d8fa35aa9e137e1eec1", + "openai/KnowledgeQA/gpt-4o": "49267acbe5769cff75edff28caa8880e23d7465d3381c13f6464fcf41cd11ceb", + "openai/KnowledgeQA/gpt-4o-2024-08-06": "d2b5c47db996452cc672c75388b25da1462a60f302389d95029d50555e2bc95d", + "openai/KnowledgeQA/gpt-4o-2024-11-20": "78c808e3cc9659ab1d27efd829e12313a8f7bf8e587ed856a2d85ae182d68921", + "openai/KnowledgeQA/gpt-4o-mini": "39176c7bf6c81072957a5955c1804a75ffcfbb3cda03cbfb40ee15389927218b", + "openai/KnowledgeQA/gpt-5": "1b8a325e646c0251225a1d83099eb67544dfd637e6fbe4489ea0399e59174ddb", + "openai/KnowledgeQA/gpt-5-mini": "687e595b4d87b87a62230103fe10895e131795eef2c83e5a69daddfaea36dd02", + "openai/KnowledgeQA/gpt-5-nano": "c0802166ccd659d2078118320182b73c6d6f3137f68838a15271e905e3e28ee5", + "openai/KnowledgeQA/gpt-5.1": "a655f01773da62bb4dff4c26e6880465e83816e976a17052c26940068fdd5cee", + "openai/KnowledgeQA/gpt-5.2": "37ed13fbd98481774ed42a462ee36f07d46776ff762e79cc63d37f80d6c8d31a", + "openai/KnowledgeQA/gpt-5.4": "a4e18227d5b5bb6ba2ed085f36fdbd2d870abf6f2d43a253cb893eb34675661b", + "openai/KnowledgeQA/gpt-5.4-mini": "2b491f50798d8ad85dadb59e9d9afb731ded5fee2b7479060e34e2749e5f3f63", + "openai/KnowledgeQA/gpt-5.4-nano": "435903825985472fe57ad84d74233eb0f8cde613134e0da1c7c1d3e91072bdea", + "openai/KnowledgeQA/gpt-5.5": "2ec73f0f32e00993d395a02f62b53873f010991423400a59c1388d9759cabc29", + "openai/KnowledgeQA/gpt-5.6": "f3ae64cf2bb8b366c5355b96f3417a0f1b5c033aec57489bc9ea091b0a3906d0", + "openai/KnowledgeQA/gpt-5.6-luna": "315609c50a9598f6a9ae0411ed2aba39946fe6be868b06cb7177516cad28706b", + "openai/KnowledgeQA/gpt-5.6-sol": "6646d9a8463b8dcc13d84a53cd16deb84613c132c480378e3f243b83df01ef19", + "openai/KnowledgeQA/gpt-5.6-terra": "ee33f16f0630b8c7f23a64c724267fcb5d794dfc523a6ab38e20a48d4447b515", + "openai/KnowledgeQA/gpt-5snapshot": "fc10abaa4f5b71bf2c4c46624109ed99d5c0ddc196517803d0cdf68ef92a9448", + "openai/KnowledgeQA/gpt-6-astra": "1a4d4e1be37f472307da3af52dd6db448da7bed568fedf3086e548303fb460cf", + "openai/KnowledgeQA/gpt-6snapshot": "75e800414ec7df086c55eaf36509de26a5f6ed000f0e38d2520191a4176c3ad7", + "openai/KnowledgeQA/o1snapshot": "dcc4cb93570f7fcd128679b692a27e2cc6e6ea38f37f2e7ad9ce6e28ac6749e8", + "openai/KnowledgeQA/o3": "39cf8e5211e93dae65a14f9c6c5a76172844266690c4f448e5eb401bcd766572", + "openai/KnowledgeQA/o3snapshot": "d875433d0f7897c01785b510381144f43dbc835249963e5f9b16ee3130068c68", + "openai/KnowledgeQA/o4snapshot": "82910c522ac0b0d023f995a3672647c73e533b1992f79d4e597c11a8d53189a6", + "openrouter/ASR/openai/whisper-large-v3": "18d077ef76d17cb51b3dadc18b570b40f2da916572c0196f7435d2728c3027f7", + "openrouter/Embedding/openai/text-embedding-3-large": "18f651405d3a854813dd5938ce8c8ffefbc8f3e68ac64057335c1d6d1a382b62", + "openrouter/Embedding/openai/text-embedding-3-small": "f16558abafbe7e1980542efd23ccd8bc215802e5a35444422ba948a02c59538d", + "openrouter/KnowledgeQA/anthropic/claude-opus-5": "b410f7a28577fb2b8ec7845fbb9157dc44d2a51b287a825fade2722929c6fb7d", + "openrouter/KnowledgeQA/anthropic/claude-sonnet-4.6": "d7d4e8a93c533bad68fa85c2accef5b10f08cabb382765ddea7799b06e8b5739", + "openrouter/KnowledgeQA/anthropic/claude-sonnet-5": "7ebf34dfd7d017ac1fe6983b2191345fe96a1727619951a3426363a366b45f45", + "openrouter/KnowledgeQA/anthropic/snapshot": "74ea9636e921fe17977b2915ba6397823abc6b23a43825b41e0b99612df38358", + "openrouter/KnowledgeQA/deepseek/deepseek-v4-flash": "c25c357b6078af533e7a7fdd01ffed9d5ab83c6e589486d48bba184291a0e6b2", + "openrouter/KnowledgeQA/deepseek/deepseek-v4-pro": "3f350e296e22a05eddca8737d11f637cfeb4c0ad245246fa510cdf2cd19a1980", + "openrouter/KnowledgeQA/google/gemini-3.1-pro-preview": "1bba0aa89a00cd5fe8af7e76e93891ca4dd77281cd48414923afc95c9b4f0818", + "openrouter/KnowledgeQA/google/gemini-3.8-flash": "e1f59cee98e945423b040c0bd2aa8ecf26780c0e70cd6a037b0b0aa0108ea475", + "openrouter/KnowledgeQA/minimax/minimax-m3": "7fac4b6ec8518284aed9c74d66e0e243bec860a8a538d45cc03f5f7481b99cdb", + "openrouter/KnowledgeQA/moonshotai/kimi-k3": "bf7e74b42760aa71c4423665f323d054d932ad5b1a59401857de1e2092fe6e36", + "openrouter/KnowledgeQA/openai/gpt-5.4": "8a22de2014afc2a58312d2e5f965116ed19cbe0652246f8964d94993616c8e1c", + "openrouter/KnowledgeQA/openai/gpt-5.5": "a9007fd1530e4f597ed152a3bf13a2921433557405c048952b07c17c6fbfba9a", + "openrouter/KnowledgeQA/qwen/qwen3.7-max": "b875905a43449272a94f2339766bac4c4f9b5414c603b9c434b0e6a31b925fd3", + "openrouter/KnowledgeQA/x-ai/grok-4.6": "b43bad43581cfc02bb2f7c8e56fbfea372edf6e4e6b1a34d15442efab0a0b0f4", + "openrouter/KnowledgeQA/z-ai/glm-5.3": "d629d890b3e68a3e95a37d320390c60fe44019ff3bd80f9bb4bd897edcfa425c", + "openrouter/Rerank/cohere/rerank-v3.5": "35f701fdcf196b6de1e71dc677dd3cdecf1a2a9b4fd71f08f2fb5cbc78601fc5", + "qianfan/Embedding/bge-large-zh": "121f5c8566989713874cba0044039f9e02cf53fe23db739709e122459b9a3fda", + "qianfan/Embedding/embedding-v1": "cc6b2807cbedb3422ba1982e04cae952c7ddffbba2685e4b53f90774d56aeab0", + "qianfan/Embedding/tao-8k": "af316a1f4b9f96f93088f52a3e7e4292b6e30b5aa6f49243830890f4f4043058", + "qianfan/KnowledgeQA/deepseek-v3.2": "32ebceea751c46e99ec750d5301e17e3b50a29a9002eb61e3065c4a4dd14ea5b", + "qianfan/KnowledgeQA/ernie-4.5-turbo-128k": "2fa61399541418ed8d8fbe5fd8ead2655baf8bc92ef20f6ff2d9d4884de2f396", + "qianfan/KnowledgeQA/ernie-4.5-turbo-vl-32k": "134b57565beec32415b79eb070c74dbd5bd819f90488fd005a4b44e671189d56", + "qianfan/KnowledgeQA/ernie-5.0-thinking-preview": "638accf53511978b7a01a6d5bc2f06407a1a60906540a44ce1fe1ea57d0a73e3", + "qianfan/KnowledgeQA/ernie-x1-turbo-32k": "fcb41841b028c5e6199f277b2d3e1036260d3913a923f7eb8f5650467d8d49ef", + "qianfan/Rerank/bce-reranker-base": "485e2639fccc993514e87c0dcf434cb24dd37284777302b78f88e9b45bb412a0", + "qiniu/KnowledgeQA/deepseek-r1": "95d9f18f66374713e5f7265b7d571a70590369048ad5b58c5499cae2090dcc88", + "qiniu/KnowledgeQA/deepseek-v3": "921365f0f3370f7870edbfd7720cd948f51e5aae95e3956f3f8d4f130176b964", + "qiniu/KnowledgeQA/deepseek/deepseek-v3.2-251201": "f505852c2ef532a79b58577d489b152a80a8960565d86472bcc73c7ab9ddc58c", + "qiniu/KnowledgeQA/doubao-seed-2.0-pro": "b25cada50048f5a77ca8f54b55696d2c5d38a2bbb795a6200704ac093691ae45", + "qiniu/KnowledgeQA/minimax/minimax-m2.5": "6d3df233d5dfaa21a13e124795d57cca22a69f3dff91bbd83fed3b4a03fc4493", + "qiniu/KnowledgeQA/moonshotai/kimi-k2.5": "108c5be046d8592d756e1ff40592b36af6dd0798fd5d1967b747e5e44427b426", + "qiniu/KnowledgeQA/qwen3.5-397b-a17b": "187b4cef7195768aeae7bf5d949dd438ce9a4bc9d0e07da993f9548ba0584a19", + "qiniu/KnowledgeQA/xiaomi/mimo-v2-flash": "845a64410036654c2e66e2665461ce2cb4aef29e4aecdb94cd42df072f63f5e7", + "qiniu/KnowledgeQA/z-ai/glm-4.7": "50f155530873601913d3501ae5fdd8e02cd53e779d164d5e3e5983f9f72aa6d2", + "qiniu/KnowledgeQA/z-ai/glm-5": "d9ea33c0add65f8a817e4fd688141c1082d6e42f26e2a4cf85761f081feec093", + "requesty/ASR/openai/gpt-4o-mini-transcribe": "c0349aa7c2203860f357fd0e46450f27489e3d1ca6600635268cc847b1866bab", + "requesty/ASR/openai/gpt-4o-transcribe": "4316875346e4271458d0e62e5037d53454da07386768de13f370ce6b4fc65e45", + "requesty/ASR/openai/whisper-1": "778b91371b71032df8453c650f91bbc964f6560522577a4846b9f25c8945f48a", + "requesty/KnowledgeQA/anthropic/claude-opus-5": "8356a41a7bd95135d2ddf12b4b2415b82b8dbbcce718d1e60d8de3db1c950687", + "requesty/KnowledgeQA/anthropic/claude-sonnet-5": "a75f2e814e2a97a56258c93d0039a7d89496abc72bb52f1955ad660dd13858ac", + "requesty/KnowledgeQA/deepseek/deepseek-v4-pro-0813": "fa7d14e1c3a15d18e25b86b4276a83f9299ca7a7e6b08ebe396c61c88dcf9f46", + "requesty/KnowledgeQA/google/gemini-3.1-pro-preview": "5ae18bea9729e634d48bbd42f720f8b3ccd2f61a1d6fd2351d66ae0ec7e72c68", + "requesty/KnowledgeQA/google/gemini-3.6-flash": "4a87ddc564934a9852b530f1e26049a5a621425f190d2e4b1d43d1b1b65a51d4", + "requesty/KnowledgeQA/moonshot/kimi-k3": "96f37af49c144a446d9c4c7c65211e65689826a25d8c33e5db31f508cae637c0", + "requesty/KnowledgeQA/openai/gpt-5.4": "6ca93580eedb4008adf37034d96f41230e7b4222c96dbcb22a857a2da9e9b0b3", + "requesty/KnowledgeQA/openai/gpt-5.5": "253f766ef2d39c19ba8e0bb5cdffd2839a4be3de4cf5ae16e319d515a18697f1", + "requesty/KnowledgeQA/openai/gpt-6-astra": "6f4c1566c3840c8b0ce6d96a98dd1c07fd79b1e2b9293d1a53873ce5a1b5a427", + "requesty/KnowledgeQA/vertex/gemini-3.8-flash": "8fb9c557105405e4a8b20bf9fd857da65edd424d02c9fbc084fb7411c5fa9d3b", + "requesty/KnowledgeQA/zai/glm-5.2": "055e7a4a4470f79a61e327423a0212b24f6ad79be04afbde3abc26eb65347bb6", + "siliconflow/ASR/FunAudioLLM/SenseVoiceSmall": "88839578e8f7b051a3d7143f8d302709fe69ab9271b8e854d5b5d12efa172c8b", + "siliconflow/ASR/TeleAI/TeleSpeechASR": "a4dca0f67155be24e0a868455c53651ef38ff2553a5d8c5dd35087731b1a66cd", + "siliconflow/Embedding/BAAI/bge-m3": "9d87b5170939e61d952b96f7dcffc56ea414b1ff59c0592a3e42dc826fda441c", + "siliconflow/Embedding/Qwen/Qwen3-Embedding-0.6B": "b55351b9b00e746f4b383ae0c065c8e3c2a906273297f081d7e35a5a7e04f0ba", + "siliconflow/Embedding/Qwen/Qwen3-Embedding-4B": "8aa441fee0aade229c25c57db8b0c93303f2d53d1102d57b939131c3c0a983a0", + "siliconflow/Embedding/Qwen/Qwen3-Embedding-8B": "f3a6805f2883d3a193d13148ab9ca0aa182de4ec11f3007a4fd78702aa0b21bf", + "siliconflow/KnowledgeQA/Pro/MiniMaxAI/MiniMax-M2.5": "700781182ca8df30b8cfdad4180fd36e2bfaae0da63ade30a1d10b5488fe2db9", + "siliconflow/KnowledgeQA/Pro/deepseek-ai/DeepSeek-V4snapshot": "292817da83beca2f7fa60e9eeae633269f6d8e018032c02d7166b80b9120f5d6", + "siliconflow/KnowledgeQA/Pro/moonshotai/Kimi-K2.5": "34d25f8f2758edefe777c7a89cd912afe8dcc6ec9d291847efda649f56656cd1", + "siliconflow/KnowledgeQA/Pro/moonshotai/Kimi-K2.6": "1d65e2cb0cd8817f30ea1841b17f7c1688de2fb596cf886736e424128620889e", + "siliconflow/KnowledgeQA/Pro/zai-org/GLM-5": "4549beb67deab651429c8385e206e7a256594a526c22d672a29c4c869d4b5755", + "siliconflow/KnowledgeQA/Pro/zai-org/GLM-5.1": "9db6bed5330d09ee15dbc828a57e646da9abcdb3760004c51b5b7fbaa761ce59", + "siliconflow/KnowledgeQA/Pro/zai-org/GLM-5.2": "ab9c0076ec579b6fe0b51f706128021b32f0b754b1fc62d913d7caeae7ed05fe", + "siliconflow/KnowledgeQA/Qwen/Qwen3-VL-32B-Instruct": "35beda50dc06f2714574ee5a85b5e99ea0398e7eecd89ce663b510d1b101c242", + "siliconflow/KnowledgeQA/Qwen/Qwen3.5-122B-A10B": "07db7c23527b82c43d9c85e6a341638dc856896417652fb5d15fd97e4c18d64a", + "siliconflow/KnowledgeQA/Qwen/Qwen3.5-35B-A3B": "9a35f5c89b6ffeb6f1c2f2f524f393075f03e30eca264a99f03825007704499d", + "siliconflow/KnowledgeQA/Qwen/Qwen3.5-397B-A17B": "852f2b573c9a7710fcba19662fca908de01b8a9e197eed500075e25feae18d4c", + "siliconflow/KnowledgeQA/Qwen/Qwen3.6-35B-A3B": "46e2a4b78ef2f4ad61ae4cc4cf464434ca589333e6c03440819b2d93c7f0e834", + "siliconflow/KnowledgeQA/deepseek-ai/DeepSeek-V3.2": "a8717568360641fc17238d588c9e5457e8be46c26377b6b3825b34c1002b4bbe", + "siliconflow/KnowledgeQA/deepseek-ai/DeepSeek-V4-Flash": "0359b123c902a072e6b7f00ce62500745f9b7e68be0fdb4c96cb7ff1746dca46", + "siliconflow/KnowledgeQA/deepseek-ai/DeepSeek-V4-Pro": "727f889e46c372bad78b32249a7adc3a32ed83191252c27477849785b4968cf0", + "siliconflow/KnowledgeQA/deepseek-ai/DeepSeek-V4snapshot": "724ec881791b35536279abfc42f4ff466401032433d160c3ba3205bb2b921178", + "siliconflow/KnowledgeQA/zai-org/GLM-5.2": "acce2ad2d6d1987c4702c00418bac6e441d0194fd7e8c12c9abee0141ac0f743", + "siliconflow/Rerank/BAAI/bge-reranker-v2-m3": "471d9660cd6219c98941f7aec09ef68a17a5191a2350bea872d235098e4a1c1e", + "siliconflow/Rerank/Qwen/Qwen3-Reranker-8B": "712284e5eef89f522e30c96bba18d019d0c48703adb2dc0fc1239aa55d582d49", + "volcengine/Embedding/doubao-embedding-large-textsnapshot": "44d79d19f14506e75d7b9144907ffe70c3eb3110e07470362264022866ce104e", + "volcengine/Embedding/doubao-embedding-textsnapshot": "e522020c10b4d3962869cd0bdfa42f845ca60cf2d1862f06ecb725d67386f32a", + "volcengine/Embedding/doubao-embedding-vision-250615": "3d1035120259b61b2b7c6fc26d21948c6b2ef7420365f51f518573be2e4767d3", + "volcengine/Embedding/doubao-embedding-vision-251215": "4c353f33993f52212365357f33f4547a49e127391c5f5424f52136b6924027fd", + "volcengine/KnowledgeQA/deepseek-v4-1-flash-260910": "da798ebd4b75f0cac486e0c13b7b944db5e72119d70cb95749ea9a7546c8694b", + "volcengine/KnowledgeQA/deepseek-v4-flash-ga-260731": "a5150f406c1a4889c3488cc113f14a55e55fbc67ad254e00f3e7919b3d6ea04d", + "volcengine/KnowledgeQA/deepseek-v4-pro-ga-260813": "0bfe115ffe3d5837228188d4c94c34d58f374b4dd9c9c70106f0717ad335b456", + "volcengine/KnowledgeQA/doubao-seed-1-6-251015": "41c2fe8ba6b42ec7961fdd2e1f6a4f27258d6d21e1f1fdf1d94c00201f347b8d", + "volcengine/KnowledgeQA/doubao-seed-1-6-flash-250828": "e4b5567cd833190f9b87f8832d2a55554f0ae642acef6e8cd6f29f15cd875e0b", + "volcengine/KnowledgeQA/doubao-seed-1-6-vision-250815": "9637b628a6c8ebd56d2fa5cf867bcbf70f16016961167ec269074e257b6d648d", + "volcengine/KnowledgeQA/doubao-seed-1-8-251228": "342c5c259199ba362e65940a93a11a518c9c360fa3866f1ebe75549a996e46f6", + "volcengine/KnowledgeQA/doubao-seed-2-0-code-preview-260215": "2e708cad82ed46e174bb0e21a72f131746f1d1bdbda3ffe62f6e7a00da18429f", + "volcengine/KnowledgeQA/doubao-seed-2-0-lite-260428": "0730f665ae74ede933c04820e4616618b50eca760b87ccaccfeffe19e56ef07f", + "volcengine/KnowledgeQA/doubao-seed-2-0-mini-260428": "b9a472f9abeaec9df800bad8b464527797e0c3b60203ca2565fd18e7e94c10ad", + "volcengine/KnowledgeQA/doubao-seed-2-0-pro-260215": "bd0e1f3043f453477d4aeb1d74ee101f5fa7d9c14563404380ac30d42a0104fb", + "volcengine/KnowledgeQA/doubao-seed-2-1-pro-260628": "c401fe36c486bb0bde15dbadda5f66d1095e83a4954afc3dc3567534fceae58c", + "volcengine/KnowledgeQA/doubao-seed-2-1-pro-260915": "abea45c2694f8eb2e36dc4ed7e53643b89e09dde68e7fc89fe6149e2d9d8d56b", + "volcengine/KnowledgeQA/doubao-seed-2-1-turbo-260628": "7a15c04ee6d70612fbfbf80cfff77507bd101ff3b9f22df1ee286fa734dd0476", + "volcengine/KnowledgeQA/glm-5-2-260617": "e5207931dafd7edbc947999ff780a34d20867caa28772b6b10715ace4312f22a", + "volcengine/KnowledgeQA/glm-5-3-flash-260828": "ca9bd13d9c86d2463efeb07ad414515a1f0cd7ab8dbe2173e5cc939f034e8577", + "volcengine/Rerank/base-multilingual-rerank": "fa578e2a39ad622b50452c4d04ae9612ad5279c9abfe1df86143aacbae70820a", + "volcengine/Rerank/doubao-seed-rerank": "2d26d34faf9c3d7a69302cfdd28c7e7162fe1ceb8060a507582724a5368f493f", + "zhipu/ASR/glm-asr-2512": "58e487f13624e4ef38d8258e01664bd609e65d8b1d68c80855d314d8bc541342", + "zhipu/Embedding/embedding-2": "524e2d23e61229245c2befdd4edd46c7ecd1814368d1afd7acb1ce98125601f4", + "zhipu/Embedding/embedding-3": "e84ca0362294219a7dc044537d2dacf897d75c531e49699eac85c2c9f9cc4d3c", + "zhipu/KnowledgeQA/glm-4.5-air": "3911dfaa4e69e0342c2c7757f78846e1509c7300db2e92ee256bb293db9b1b99", + "zhipu/KnowledgeQA/glm-4.6": "2aa273031863e5b4a3dd1a66dfe951285837cd1161034748c798189639864ad7", + "zhipu/KnowledgeQA/glm-4.6v": "b82aad09279b58d1bc98239fb6292c7571aa1160c6f8b763d984ecbbfa6080f1", + "zhipu/KnowledgeQA/glm-4.7": "6614695fc13cfbf22f03be7304df3ed8335edff9a67d8dd1a3ec10d0d56055d5", + "zhipu/KnowledgeQA/glm-4.7-flash": "fce7d598de8b287455711de716af3259470aaaeb04cc8af2ba32618b19cf10c4", + "zhipu/KnowledgeQA/glm-5": "2bf18dfd80557bbca52ed26321b904a6289aa671d0307977e4115176ce4faec2", + "zhipu/KnowledgeQA/glm-5.1": "dfcc36d6d2ded9ab8bfc5bbfc6af7a530d918710d9bfd301252a6c9ab17d8767", + "zhipu/KnowledgeQA/glm-5.2": "3dad7d6d1be8fb9a43bd5e0b0d38eb28d988cb70029a5062e2d71b8ca046cd76", + "zhipu/KnowledgeQA/glm-5.3": "2e114d129d282680ba853add9fad838921adef5ef20b5182b29ce21d9c705821", + "zhipu/KnowledgeQA/glm-5.3-flash": "859f96e6699a7f6923f1fe224adcf6e0e6be012740970a9109f0b35a27862224", + "zhipu/KnowledgeQA/glm-5v-turbo": "39c2299304ce46d636b564cab7b3061b74491b32f31d7ea8b4a2a1c22304704e", + "zhipu/Rerank/rerank": "566896288736efe9f8ef8a44c6e9b9d2f2ad9cdc944bfb05b794c4c3ecb20a66" +} diff --git a/internal/models/parity/volcengine_budget_test.go b/internal/models/parity/volcengine_budget_test.go new file mode 100644 index 00000000..c48c63cd --- /dev/null +++ b/internal/models/parity/volcengine_budget_test.go @@ -0,0 +1,38 @@ +package parity + +import ( + "testing" + + "github.com/Tencent/WeKnora/internal/models/api" + "github.com/Tencent/WeKnora/internal/models/chat" + modelruntime "github.com/Tencent/WeKnora/internal/models/runtime" + "github.com/Tencent/WeKnora/internal/types" + "github.com/stretchr/testify/require" +) + +func TestVolcengineCompletionBudgetFieldsAreMutuallyExclusive(t *testing.T) { + vendor, ok := modelruntime.Get("volcengine") + require.True(t, ok) + for _, model := range vendor.ModelsByType(types.ModelTypeKnowledgeQA) { + t.Run(model.ID, func(t *testing.T) { + for _, stream := range []bool{false, true} { + for _, thinking := range []bool{false, true} { + for _, budget := range []int{0, 256} { + body := buildBody(t, &chat.ChatConfig{ + Provider: "volcengine", ModelName: model.ID, BaseURL: "http://127.0.0.1:9/v3", + Spec: &types.ModelSpecOverride{Compat: map[string]any{ + "extra_body": map[string]any{"max_tokens": 1024, "max_completion_tokens": 2048}, + }}, + }, &api.Options{MaxTokens: budget, Thinking: ptrBool(thinking)}, stream) + require.NotContains(t, body, "max_tokens") + want := 2048 + if budget > 0 { + want = budget + } + require.Equal(t, float64(want), body["max_completion_tokens"]) + } + } + } + }) + } +} diff --git a/internal/models/vendors/aliyun/vendor.go b/internal/models/providers/aliyun.go similarity index 80% rename from internal/models/vendors/aliyun/vendor.go rename to internal/models/providers/aliyun.go index 9c567258..3b85e488 100644 --- a/internal/models/vendors/aliyun/vendor.go +++ b/internal/models/providers/aliyun.go @@ -1,4 +1,4 @@ -// Package aliyun registers Alibaba Cloud Model Studio (Bailian / DashScope) +// Package providers registers Alibaba Cloud Model Studio (Bailian / DashScope) // through its OpenAI-compatible mode. // // Facts (https://help.aliyun.com/zh/model-studio/qwen-api-via-openai-chat-completions, @@ -78,58 +78,54 @@ // public docs render behind a console table we cannot quote; they are left as // they were. The same holds for kimi-k3 / kimi-k2.6 / glm-5.3 hosted here and // for qwq-32b's "off": null, which the 仅思考模式 list does not spell out. -package aliyun +package providers import ( _ "embed" "strings" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" "github.com/Tencent/WeKnora/internal/types" ) -//go:embed models.json -var modelsJSON []byte +//go:embed assets/aliyun.svg +var aliyunIcon []byte -//go:embed icon.svg -var icon []byte +// AliyunID is the provider identifier stored on model rows. +const AliyunID = "aliyun" -// ID is the provider identifier stored on model rows. -const ID = "aliyun" +// AliyunBaseURL is the OpenAI-compatible mode used for chat, embedding and VLM. +const AliyunBaseURL = "https://dashscope.aliyuncs.com/compatible-mode/v1" -// BaseURL is the OpenAI-compatible mode used for chat, embedding and VLM. -const BaseURL = "https://dashscope.aliyuncs.com/compatible-mode/v1" +// AliyunRerankBaseURL is the DashScope-native text rerank endpoint. +const AliyunRerankBaseURL = "https://dashscope.aliyuncs.com/api/v1/services/rerank/text-rerank/text-rerank" -// RerankBaseURL is the DashScope-native text rerank endpoint. -const RerankBaseURL = "https://dashscope.aliyuncs.com/api/v1/services/rerank/text-rerank/text-rerank" - -// AnthropicBaseURL is the documented Anthropic Messages facade. It is not the +// AliyunAnthropicBaseURL is the documented Anthropic Messages facade. It is not the // default for this vendor; operators who want it configure it explicitly. -const AnthropicBaseURL = "https://dashscope.aliyuncs.com/apps/anthropic" +const AliyunAnthropicBaseURL = "https://dashscope.aliyuncs.com/apps/anthropic" -// multimodalEmbeddingPath is the native multimodal embedding method +// AliyunMultimodalEmbeddingPath is the native multimodal embedding method // (https://help.aliyun.com/zh/model-studio/multimodal-embedding-api-reference). -const multimodalEmbeddingPath = "/api/v1/services/embeddings/multimodal-embedding/multimodal-embedding" +const AliyunMultimodalEmbeddingPath = "/api/v1/services/embeddings/multimodal-embedding/multimodal-embedding" -func init() { - catalog.Register(&catalog.Vendor{ - ID: ID, +func newAliyunProvider() *Definition { + return &Definition{ + ID: AliyunID, Name: "Alibaba Cloud DashScope", Names: map[string]string{"zh-CN": "阿里云 DashScope"}, Description: "qwen-plus, qwen3.8-max, deepseek-v4-pro, text-embedding-v4, gte-rerank-v2, etc.", Website: "https://bailian.console.aliyun.com", - Icon: icon, + Icon: aliyunIcon, API: api.APIOpenAICompletions, Order: 10, RequiresAuth: true, - Auth: catalog.AuthBearer, + Auth: AuthBearer, URLPatterns: []string{"dashscope.aliyuncs.com"}, DefaultBaseURLs: map[types.ModelType]string{ - types.ModelTypeKnowledgeQA: BaseURL, - types.ModelTypeEmbedding: BaseURL, - types.ModelTypeRerank: RerankBaseURL, - types.ModelTypeVLLM: BaseURL, + types.ModelTypeKnowledgeQA: AliyunBaseURL, + types.ModelTypeEmbedding: AliyunBaseURL, + types.ModelTypeRerank: AliyunRerankBaseURL, + types.ModelTypeVLLM: AliyunBaseURL, }, ModelTypes: []types.ModelType{ types.ModelTypeKnowledgeQA, @@ -145,7 +141,7 @@ func init() { // URL without either root is taken as the host itself, which keeps a // workspace or international domain instead of replacing it with the // Beijing default as the pre-catalog client did. - Endpoint: func(r catalog.EndpointRequest) (string, map[string]string) { + Endpoint: func(r EndpointRequest) (string, map[string]string) { if r.ModelType != types.ModelTypeEmbedding { return "", nil } @@ -156,11 +152,11 @@ func init() { } } if r.EmbeddingAPI == api.EmbeddingDashScope { - return root + multimodalEmbeddingPath, nil + return root + AliyunMultimodalEmbeddingPath, nil } return root + "/compatible-mode/v1/embeddings", nil }, - Compat: catalog.VendorCompat{ + Compat: VendorCompat{ // ASR: qwen3-asr-flash is the one recognition model callable with // the audio in the request, on the compatible chat endpoint as a // base64 data URI; its catalog entry declares that. Every other @@ -175,34 +171,33 @@ func init() { // in models.json. The native APIs' text_type / instruct are not // declared: both change the document vectors // (Tencent/WeKnora#1401). - Embeddings: catalog.EmbeddingsCompat{ - SendEncodingFormat: catalog.Ptr(true), - DimensionsField: catalog.Ptr("dimensions"), + Embeddings: api.EmbeddingsCompat{ + SendEncodingFormat: api.Ptr(true), + DimensionsField: api.Ptr("dimensions"), }, - Rerank: catalog.RerankCompat{ - SendReturnDocs: catalog.Ptr(true), + Rerank: api.RerankCompat{ + SendReturnDocs: api.Ptr(true), // 500 documents per request for the native text-rerank models. // The query (4,000 tokens) and per-document limits are stated in // tokens, which a rune count cannot express, so they are not // declared. - MaxDocuments: catalog.Ptr(500), + MaxDocuments: api.Ptr(500), }, - OpenAICompletions: catalog.OpenAICompletionsCompat{ + OpenAICompletions: api.OpenAICompletionsCompat{ // Explicit although it matches the protocol default, because // this vendor's own parameter table deprecates the other // field and the choice should be visible here. - MaxTokensField: catalog.Ptr("max_completion_tokens"), - ThinkingFormat: catalog.Ptr(catalog.ThinkingFormatEnableThinking), - ThinkingBudgetField: catalog.Ptr("thinking_budget"), - CacheControlFormat: catalog.Ptr("anthropic"), + MaxTokensField: api.Ptr("max_completion_tokens"), + ThinkingFormat: api.Ptr(api.ThinkingFormatEnableThinking), + ThinkingBudgetField: api.Ptr("thinking_budget"), + CacheControlFormat: api.Ptr("anthropic"), // usage carries prompt_tokens_details.cached_tokens and // cache_creation.ephemeral_5m_input_tokens. - PromptCacheAccounting: catalog.Ptr(true), + PromptCacheAccounting: api.Ptr(true), // reasoning_effort exists but only on the families that enable // it per entry (qwen3.8, DeepSeek-V4, glm-5.3). - SupportsReasoningEffort: catalog.Ptr(false), + SupportsReasoningEffort: api.Ptr(false), }, }, - Models: catalog.MustParseModels(modelsJSON), - }) + } } diff --git a/internal/models/vendors/anthropic/vendor.go b/internal/models/providers/anthropic.go similarity index 83% rename from internal/models/vendors/anthropic/vendor.go rename to internal/models/providers/anthropic.go index 2c6c8f97..15158664 100644 --- a/internal/models/vendors/anthropic/vendor.go +++ b/internal/models/providers/anthropic.go @@ -1,4 +1,4 @@ -// Package anthropic registers Anthropic's native Messages API. +// Package providers registers Anthropic's native Messages API. // // Facts (https://platform.claude.com/docs/en/api/messages — docs.anthropic.com // now redirects there): @@ -36,55 +36,50 @@ // // Unverified: Claude Mythos 5.1 / Mythos 5 / Mythos Preview are documented // but limited-availability, so they are left out of the catalog. -package anthropic +package providers import ( _ "embed" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" "github.com/Tencent/WeKnora/internal/types" ) -//go:embed models.json -var modelsJSON []byte +//go:embed assets/anthropic.svg +var anthropicIcon []byte -//go:embed icon.svg -var icon []byte +// AnthropicID is the provider identifier stored on model rows. +const AnthropicID = "anthropic" -// ID is the provider identifier stored on model rows. -const ID = "anthropic" +// AnthropicBaseURL is the documented first-party endpoint. +const AnthropicBaseURL = "https://api.anthropic.com/v1" -// BaseURL is the documented first-party endpoint. -const BaseURL = "https://api.anthropic.com/v1" - -func init() { - catalog.Register(&catalog.Vendor{ - ID: ID, +func newAnthropicProvider() *Definition { + return &Definition{ + ID: AnthropicID, Name: "Anthropic", Names: map[string]string{"zh-CN": "Anthropic"}, Description: "Claude models via the native Anthropic Messages API: " + "claude-opus-5, claude-sonnet-5, claude-haiku-4-5, etc.", Website: "https://console.anthropic.com", - Icon: icon, + Icon: anthropicIcon, API: api.APIAnthropicMessages, Order: 32, RequiresAuth: true, - Auth: catalog.AuthXAPIKey, + Auth: AuthXAPIKey, URLPatterns: []string{"api.anthropic.com"}, DefaultBaseURLs: map[types.ModelType]string{ - types.ModelTypeKnowledgeQA: BaseURL, + types.ModelTypeKnowledgeQA: AnthropicBaseURL, }, ModelTypes: []types.ModelType{ types.ModelTypeKnowledgeQA, }, // Protocol defaults (budget-mode thinking, 2023-06-01 version) apply // at vendor level; adaptive-effort models override per entry. - Compat: catalog.VendorCompat{}, + Compat: VendorCompat{}, // Anthropic's effort ladder has no "minimal" rung; fold it onto low // for every model so a caller asking for minimal never sends a value // the Messages API rejects. ThinkingLevels: api.ThinkingLevelMap{api.ReasoningMinimal: api.StringPtr("low")}, - Models: catalog.MustParseModels(modelsJSON), - }) + } } diff --git a/internal/models/vendors/aliyun/icon.svg b/internal/models/providers/assets/aliyun.svg similarity index 100% rename from internal/models/vendors/aliyun/icon.svg rename to internal/models/providers/assets/aliyun.svg diff --git a/internal/models/vendors/anthropic/icon.svg b/internal/models/providers/assets/anthropic.svg similarity index 100% rename from internal/models/vendors/anthropic/icon.svg rename to internal/models/providers/assets/anthropic.svg diff --git a/internal/models/vendors/azure_openai/icon.svg b/internal/models/providers/assets/azure_openai.svg similarity index 100% rename from internal/models/vendors/azure_openai/icon.svg rename to internal/models/providers/assets/azure_openai.svg diff --git a/internal/models/vendors/deepseek/icon.svg b/internal/models/providers/assets/deepseek.svg similarity index 100% rename from internal/models/vendors/deepseek/icon.svg rename to internal/models/providers/assets/deepseek.svg diff --git a/internal/models/vendors/gemini/icon.svg b/internal/models/providers/assets/gemini.svg similarity index 100% rename from internal/models/vendors/gemini/icon.svg rename to internal/models/providers/assets/gemini.svg diff --git a/internal/models/vendors/generic/icon.svg b/internal/models/providers/assets/generic.svg similarity index 100% rename from internal/models/vendors/generic/icon.svg rename to internal/models/providers/assets/generic.svg diff --git a/internal/models/vendors/gpustack/icon.svg b/internal/models/providers/assets/gpustack.svg similarity index 100% rename from internal/models/vendors/gpustack/icon.svg rename to internal/models/providers/assets/gpustack.svg diff --git a/internal/models/vendors/hunyuan/icon.svg b/internal/models/providers/assets/hunyuan.svg similarity index 100% rename from internal/models/vendors/hunyuan/icon.svg rename to internal/models/providers/assets/hunyuan.svg diff --git a/internal/models/vendors/jina/icon.svg b/internal/models/providers/assets/jina.svg similarity index 100% rename from internal/models/vendors/jina/icon.svg rename to internal/models/providers/assets/jina.svg diff --git a/internal/models/vendors/litellm/icon.svg b/internal/models/providers/assets/litellm.svg similarity index 100% rename from internal/models/vendors/litellm/icon.svg rename to internal/models/providers/assets/litellm.svg diff --git a/internal/models/vendors/lkeap/icon.svg b/internal/models/providers/assets/lkeap.svg similarity index 100% rename from internal/models/vendors/lkeap/icon.svg rename to internal/models/providers/assets/lkeap.svg diff --git a/internal/models/vendors/longcat/icon.svg b/internal/models/providers/assets/longcat.svg similarity index 100% rename from internal/models/vendors/longcat/icon.svg rename to internal/models/providers/assets/longcat.svg diff --git a/internal/models/vendors/mimo/icon.svg b/internal/models/providers/assets/mimo.svg similarity index 100% rename from internal/models/vendors/mimo/icon.svg rename to internal/models/providers/assets/mimo.svg diff --git a/internal/models/vendors/minimax/icon.svg b/internal/models/providers/assets/minimax.svg similarity index 100% rename from internal/models/vendors/minimax/icon.svg rename to internal/models/providers/assets/minimax.svg diff --git a/internal/models/vendors/modelscope/icon.svg b/internal/models/providers/assets/modelscope.svg similarity index 100% rename from internal/models/vendors/modelscope/icon.svg rename to internal/models/providers/assets/modelscope.svg diff --git a/internal/models/vendors/moonshot/icon.svg b/internal/models/providers/assets/moonshot.svg similarity index 100% rename from internal/models/vendors/moonshot/icon.svg rename to internal/models/providers/assets/moonshot.svg diff --git a/internal/models/vendors/novita/icon.svg b/internal/models/providers/assets/novita.svg similarity index 100% rename from internal/models/vendors/novita/icon.svg rename to internal/models/providers/assets/novita.svg diff --git a/internal/models/vendors/nvidia/icon.svg b/internal/models/providers/assets/nvidia.svg similarity index 100% rename from internal/models/vendors/nvidia/icon.svg rename to internal/models/providers/assets/nvidia.svg diff --git a/internal/models/vendors/openai/icon.svg b/internal/models/providers/assets/openai.svg similarity index 100% rename from internal/models/vendors/openai/icon.svg rename to internal/models/providers/assets/openai.svg diff --git a/internal/models/vendors/openrouter/icon.svg b/internal/models/providers/assets/openrouter.svg similarity index 100% rename from internal/models/vendors/openrouter/icon.svg rename to internal/models/providers/assets/openrouter.svg diff --git a/internal/models/vendors/qianfan/icon.svg b/internal/models/providers/assets/qianfan.svg similarity index 100% rename from internal/models/vendors/qianfan/icon.svg rename to internal/models/providers/assets/qianfan.svg diff --git a/internal/models/vendors/qiniu/icon.svg b/internal/models/providers/assets/qiniu.svg similarity index 100% rename from internal/models/vendors/qiniu/icon.svg rename to internal/models/providers/assets/qiniu.svg diff --git a/internal/models/vendors/requesty/icon.svg b/internal/models/providers/assets/requesty.svg similarity index 100% rename from internal/models/vendors/requesty/icon.svg rename to internal/models/providers/assets/requesty.svg diff --git a/internal/models/vendors/siliconflow/icon.svg b/internal/models/providers/assets/siliconflow.svg similarity index 100% rename from internal/models/vendors/siliconflow/icon.svg rename to internal/models/providers/assets/siliconflow.svg diff --git a/internal/models/vendors/volcengine/icon.svg b/internal/models/providers/assets/volcengine.svg similarity index 100% rename from internal/models/vendors/volcengine/icon.svg rename to internal/models/providers/assets/volcengine.svg diff --git a/internal/models/vendors/weknoracloud/icon.svg b/internal/models/providers/assets/weknoracloud.svg similarity index 100% rename from internal/models/vendors/weknoracloud/icon.svg rename to internal/models/providers/assets/weknoracloud.svg diff --git a/internal/models/vendors/zhipu/icon.svg b/internal/models/providers/assets/zhipu.svg similarity index 100% rename from internal/models/vendors/zhipu/icon.svg rename to internal/models/providers/assets/zhipu.svg diff --git a/internal/models/vendors/azure_openai/vendor.go b/internal/models/providers/azure_openai.go similarity index 83% rename from internal/models/vendors/azure_openai/vendor.go rename to internal/models/providers/azure_openai.go index 63e7909c..656988f5 100644 --- a/internal/models/vendors/azure_openai/vendor.go +++ b/internal/models/providers/azure_openai.go @@ -1,4 +1,4 @@ -// Package azureopenai registers Azure OpenAI (Azure AI Foundry). +// Package providers registers Azure OpenAI (Azure AI Foundry). // // Facts (https://learn.microsoft.com/azure/ai-foundry/openai/api-version-lifecycle // and https://learn.microsoft.com/azure/ai-foundry/openai/how-to/reasoning): @@ -15,7 +15,7 @@ // cannot work on it. The Endpoint hook therefore emits the v1 shape by // default and only falls back to the legacy shape when the operator // explicitly fills the api_version extra field; -// - authentication is the `api-key` header, not a bearer token (Entra ID +// - authentication is the `api-key` header, not a bearer token (Entra AzureOpenaiID // bearer tokens are the other documented option and are not modelled); // - the model name stored on the row is the deployment name, so the // catalog only carries family patterns (gpt-6*, gpt-5*, o1*, o3*, o4*, @@ -75,54 +75,51 @@ // website-docs/03-features/06-models.md; an operator whose gateway only // serves the dated path (an API Management front end, a sovereign cloud) // restores the exact previous shape by filling the api_version extra field. -package azureopenai +package providers import ( _ "embed" "net/url" "strings" + "github.com/Tencent/WeKnora/internal/models" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" "github.com/Tencent/WeKnora/internal/types" ) -//go:embed models.json -var modelsJSON []byte +//go:embed assets/azure_openai.svg +var azureOpenaiIcon []byte -//go:embed icon.svg -var icon []byte +// AzureOpenaiID is the provider identifier stored on model rows. +const AzureOpenaiID = "azure_openai" -// ID is the provider identifier stored on model rows. -const ID = "azure_openai" - -// BaseURL is the resource endpoint template; the operator replaces +// AzureOpenaiBaseURL is the resource endpoint template; the operator replaces // {resource} with their own resource name. -const BaseURL = "https://{resource}.openai.azure.com" +const AzureOpenaiBaseURL = "https://{resource}.openai.azure.com" -// LegacyAPIVersion is the newest GA api-version of the dated data-plane +// AzureOpenaiLegacyAPIVersion is the newest GA api-version of the dated data-plane // inference spec. It is only used when the operator explicitly asks for the // legacy deployments path; it predates reasoning_effort, so reasoning // deployments need a preview version such as 2025-04-01-preview instead. -const LegacyAPIVersion = "2024-10-21" +const AzureOpenaiLegacyAPIVersion = "2024-10-21" -func init() { - catalog.Register(&catalog.Vendor{ - ID: ID, +func newAzureOpenaiProvider() *Definition { + return &Definition{ + ID: AzureOpenaiID, Name: "Azure OpenAI", Names: map[string]string{"zh-CN": "Azure OpenAI"}, Description: "gpt-4o, gpt-5, o3, text-embedding-3-large deployments, etc.", Website: "https://ai.azure.com", - Icon: icon, + Icon: azureOpenaiIcon, API: api.APIOpenAICompletions, Order: 31, RequiresAuth: true, - Auth: catalog.AuthAPIKeyHeader, + Auth: AuthAPIKeyHeader, URLPatterns: []string{"openai.azure.com"}, DefaultBaseURLs: map[types.ModelType]string{ - types.ModelTypeKnowledgeQA: BaseURL, - types.ModelTypeEmbedding: BaseURL, - types.ModelTypeVLLM: BaseURL, + types.ModelTypeKnowledgeQA: AzureOpenaiBaseURL, + types.ModelTypeEmbedding: AzureOpenaiBaseURL, + types.ModelTypeVLLM: AzureOpenaiBaseURL, }, // ASR is deliberately absent. The ASR client now resolves through // this vendor (api-key header, Endpoint hook below), but the only @@ -139,9 +136,9 @@ func init() { types.ModelTypeEmbedding, types.ModelTypeVLLM, }, - ExtraFields: []catalog.ExtraField{ + ExtraFields: []ExtraField{ { - Key: catalog.ExtraAPIVersion, + Key: models.ExtraAPIVersion, Label: "API Version (legacy deployments path)", Labels: map[string]string{"zh-CN": "API 版本(旧版 deployments 路径)"}, Type: "string", @@ -155,23 +152,23 @@ func init() { }, }, }, - Compat: catalog.VendorCompat{ - Embeddings: catalog.EmbeddingsCompat{ + Compat: VendorCompat{ + Embeddings: api.EmbeddingsCompat{ // The same body as OpenAI's; the Endpoint hook below supplies the // v1 or deployments URL. - SendEncodingFormat: catalog.Ptr(true), - DimensionsField: catalog.Ptr("dimensions"), + SendEncodingFormat: api.Ptr(true), + DimensionsField: api.Ptr("dimensions"), }, - OpenAICompletions: catalog.OpenAICompletionsCompat{ - ThinkingFormat: catalog.Ptr(catalog.ThinkingFormatOpenAI), - SupportsReasoningEffort: catalog.Ptr(true), - SupportsDeveloperRole: catalog.Ptr(true), - SupportsStore: catalog.Ptr(true), - PromptCacheKey: catalog.Ptr(true), - PromptCacheAccounting: catalog.Ptr(true), + OpenAICompletions: api.OpenAICompletionsCompat{ + ThinkingFormat: api.Ptr(api.ThinkingFormatOpenAI), + SupportsReasoningEffort: api.Ptr(true), + SupportsDeveloperRole: api.Ptr(true), + SupportsStore: api.Ptr(true), + PromptCacheKey: api.Ptr(true), + PromptCacheAccounting: api.Ptr(true), }, }, - Endpoint: func(r catalog.EndpointRequest) (string, map[string]string) { + Endpoint: func(r EndpointRequest) (string, map[string]string) { var path string switch r.ModelType { case types.ModelTypeEmbedding: @@ -189,7 +186,7 @@ func init() { // An explicit api-version selects the legacy deployments path; // otherwise use the v1 GA data plane, which carries the // deployment name in the body instead of the URL. - if version := strings.TrimSpace(r.Extra[catalog.ExtraAPIVersion]); version != "" { + if version := strings.TrimSpace(r.Extra[models.ExtraAPIVersion]); version != "" { legacy := root + "/openai/deployments/" + url.PathEscape(r.Model) + path return legacy, map[string]string{"api-version": version} } @@ -198,6 +195,5 @@ func init() { } return root + "/openai/v1" + path, nil }, - Models: catalog.MustParseModels(modelsJSON), - }) + } } diff --git a/internal/models/providers/builtin.go b/internal/models/providers/builtin.go new file mode 100644 index 00000000..8a59435d --- /dev/null +++ b/internal/models/providers/builtin.go @@ -0,0 +1,36 @@ +package providers + +import "github.com/Tencent/WeKnora/internal/models/internal/configcopy" + +// Builtins returns independent provider definitions without registering global state. +func Builtins() []*Definition { + return configcopy.Clone([]*Definition{ + newAliyunProvider(), + newAnthropicProvider(), + newAzureOpenaiProvider(), + newDeepseekProvider(), + newGeminiProvider(), + newGenericProvider(), + newGpustackProvider(), + newHunyuanProvider(), + newJinaProvider(), + newLitellmProvider(), + newLkeapProvider(), + newLongcatProvider(), + newMimoProvider(), + newMinimaxProvider(), + newModelscopeProvider(), + newMoonshotProvider(), + newNovitaProvider(), + newNvidiaProvider(), + newOpenaiProvider(), + newOpenrouterProvider(), + newQianfanProvider(), + newQiniuProvider(), + newRequestyProvider(), + newSiliconflowProvider(), + newVolcengineProvider(), + newWeKnoraCloudProvider(), + newZhipuProvider(), + }) +} diff --git a/internal/models/providers/compat.go b/internal/models/providers/compat.go new file mode 100644 index 00000000..50be2a6f --- /dev/null +++ b/internal/models/providers/compat.go @@ -0,0 +1,18 @@ +package providers + +import "github.com/Tencent/WeKnora/internal/models/api" + +// VendorCompat carries a vendor's defaults for every protocol it may speak. +type VendorCompat struct { + OpenAICompletions api.OpenAICompletionsCompat `json:"openai_completions,omitempty"` + OpenAIResponses api.OpenAIResponsesCompat `json:"openai_responses,omitempty"` + AnthropicMessages api.AnthropicMessagesCompat `json:"anthropic_messages,omitempty"` + GoogleGenerativeAI api.GoogleGenerativeAICompat `json:"google_generative_ai,omitempty"` + // Rerank is the rerank protocol overlay. It has no per-protocol variants: + // a vendor serves exactly one rerank dialect. + Rerank api.RerankCompat `json:"rerank,omitempty"` + // Embeddings is the embedding protocol overlay, likewise one per vendor. + Embeddings api.EmbeddingsCompat `json:"embeddings,omitempty"` + // Transcriptions is the speech-to-text overlay, likewise one per vendor. + Transcriptions api.TranscriptionsCompat `json:"transcriptions,omitempty"` +} diff --git a/internal/models/vendors/deepseek/vendor.go b/internal/models/providers/deepseek.go similarity index 81% rename from internal/models/vendors/deepseek/vendor.go rename to internal/models/providers/deepseek.go index 0f175637..4db3f986 100644 --- a/internal/models/vendors/deepseek/vendor.go +++ b/internal/models/providers/deepseek.go @@ -1,4 +1,4 @@ -// Package deepseek registers DeepSeek's first-party API. +// Package providers registers DeepSeek's first-party API. // // Facts (https://api-docs.deepseek.com/api/create-chat-completion and // https://api-docs.deepseek.com/guides/thinking_mode): @@ -48,52 +48,48 @@ // minimal / low to `high`. The reference enumerates low / high / max for the // API as a whole without restricting them per model, so the override is kept // but nothing documents it. -package deepseek +package providers import ( _ "embed" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" "github.com/Tencent/WeKnora/internal/types" ) -//go:embed models.json -var modelsJSON []byte +//go:embed assets/deepseek.svg +var deepseekIcon []byte -//go:embed icon.svg -var icon []byte +// DeepseekID is the provider identifier stored on model rows. +const DeepseekID = "deepseek" -// ID is the provider identifier stored on model rows. -const ID = "deepseek" +// DeepseekBaseURL is the documented first-party endpoint. +const DeepseekBaseURL = "https://api.deepseek.com/v1" -// BaseURL is the documented first-party endpoint. -const BaseURL = "https://api.deepseek.com/v1" - -func init() { - catalog.Register(&catalog.Vendor{ - ID: ID, +func newDeepseekProvider() *Definition { + return &Definition{ + ID: DeepseekID, Name: "DeepSeek", Names: map[string]string{"zh-CN": "DeepSeek 深度求索"}, Description: "deepseek-flash, deepseek-v4-pro", Website: "https://platform.deepseek.com", - Icon: icon, + Icon: deepseekIcon, API: api.APIOpenAICompletions, Order: 30, RequiresAuth: true, - Auth: catalog.AuthBearer, + Auth: AuthBearer, URLPatterns: []string{"api.deepseek.com"}, DefaultBaseURLs: map[types.ModelType]string{ - types.ModelTypeKnowledgeQA: BaseURL, + types.ModelTypeKnowledgeQA: DeepseekBaseURL, }, ModelTypes: []types.ModelType{types.ModelTypeKnowledgeQA}, - Compat: catalog.VendorCompat{ - OpenAICompletions: catalog.OpenAICompletionsCompat{ - MaxTokensField: catalog.Ptr("max_tokens"), - ThinkingFormat: catalog.Ptr(catalog.ThinkingFormatThinkingType), - SupportsReasoningEffort: catalog.Ptr(true), - PromptCacheAccounting: catalog.Ptr(true), - SupportsStore: catalog.Ptr(false), + Compat: VendorCompat{ + OpenAICompletions: api.OpenAICompletionsCompat{ + MaxTokensField: api.Ptr("max_tokens"), + ThinkingFormat: api.Ptr(api.ThinkingFormatThinkingType), + SupportsReasoningEffort: api.Ptr(true), + PromptCacheAccounting: api.Ptr(true), + SupportsStore: api.Ptr(false), // `required` and named functions 400 while thinking is on, // which is the default on every current model. ToolChoiceModes: []string{"none", "auto"}, @@ -110,6 +106,5 @@ func init() { api.ReasoningXHigh: api.StringPtr("max"), api.ReasoningMax: api.StringPtr("max"), }, - Models: catalog.MustParseModels(modelsJSON), - }) + } } diff --git a/internal/models/catalog/types.go b/internal/models/providers/definition.go similarity index 68% rename from internal/models/catalog/types.go rename to internal/models/providers/definition.go index bc2985be..dc9923ff 100644 --- a/internal/models/catalog/types.go +++ b/internal/models/providers/definition.go @@ -1,22 +1,11 @@ -// Package catalog is the model/vendor directory. It answers one question for -// the rest of the system: "given a provider id, a model name and whatever the -// operator configured, how exactly do we talk to this model?" -// -// Facts come from three layers, lowest precedence first: -// 1. built-in vendor packages under internal/models/vendors (vendor.go + -// models.json + icon.svg), registered through Register; -// 2. the deployment overlay config/models.json (same schema as pi's -// ~/.pi/agent/models.json): new vendors, base URL / key overrides, -// per-model overrides; -// 3. per-model overrides stored on the models table. -// -// Resolve merges those layers into a Resolved value that the protocol -// packages consume verbatim. No protocol or vendor package is imported here. -package catalog +// Package providers defines vendor defaults and routing rules independently of the model catalog. +package providers import ( - "encoding/json" + "fmt" + "strings" + "github.com/Tencent/WeKnora/internal/models" "github.com/Tencent/WeKnora/internal/models/api" "github.com/Tencent/WeKnora/internal/types" ) @@ -111,7 +100,7 @@ func (f ExtraField) LocalizedPlaceholder(locale string) string { // CredentialLabelFor returns the credential naming for a model type, or nil // when the vendor uses the generic API-key wording. -func (v *Vendor) CredentialLabelFor(modelType types.ModelType) *CredentialLabel { +func (v *Definition) CredentialLabelFor(modelType types.ModelType) *CredentialLabel { for i := range v.CredentialLabels { c := &v.CredentialLabels[i] if len(c.ModelTypes) == 0 { @@ -141,80 +130,6 @@ func (o ExtraFieldOption) LocalizedLabel(locale string) string { return localizedOr(o.Labels, locale, o.Label) } -// ModelCost is priced per million tokens, in USD unless Currency says otherwise. -type ModelCost struct { - Input float64 `json:"input"` - Output float64 `json:"output"` - CacheRead float64 `json:"cache_read,omitempty"` - CacheWrite float64 `json:"cache_write,omitempty"` - Currency string `json:"currency,omitempty"` -} - -// ModelSpec is one entry of a vendor's models.json. -// -// Only ID is required. API defaults to the vendor's API; Type defaults to -// KnowledgeQA. Compat is interpreted according to API (see compat.go). -type ModelSpec struct { - ID string `json:"id"` - Name string `json:"name,omitempty"` - // Type is the WeKnora model type this entry describes. Chat models with - // image input are still KnowledgeQA; the UI derives VLM eligibility from - // Input. Embedding / Rerank / ASR entries exist for the model picker. - Type types.ModelType `json:"type,omitempty"` - API api.API `json:"api,omitempty"` - // Aliases are additional ids that resolve to this entry (dated - // snapshots, vendor-prefixed names on gateways). - Aliases []string `json:"aliases,omitempty"` - // Match is a case-insensitive glob ("gpt-5*", "*deepseek-r1*") that lets - // one entry describe a family. Exact ids and aliases win over patterns; - // among patterns the longest literal prefix wins. - Match string `json:"match,omitempty"` - // Reasoning reports whether the model can emit thinking at all. - Reasoning bool `json:"reasoning"` - // Input lists accepted modalities: text, image, audio, video. - Input []string `json:"input,omitempty"` - ContextWindow int `json:"context_window,omitempty"` - MaxOutputTokens int `json:"max_output_tokens,omitempty"` - Cost *ModelCost `json:"cost,omitempty"` - // ThinkingLevels maps protocol-neutral levels to vendor values; missing - // keys inherit the vendor map. See api.ThinkingLevelMap. - ThinkingLevels api.ThinkingLevelMap `json:"thinking_levels,omitempty"` - // Compat is the protocol-specific overlay for this model (flat object, - // fields depend on API). Decoded lazily by Resolve. - Compat json.RawMessage `json:"compat,omitempty"` - // Dimension is the embedding vector width (embedding entries only). - Dimension int `json:"dimension,omitempty"` - // Deprecated hides the entry from pickers but keeps resolution working. - Deprecated bool `json:"deprecated,omitempty"` - // Source is the documentation URL the facts were taken from. - Source string `json:"source,omitempty"` -} - -// DisplayName returns Name or the id. -func (m ModelSpec) DisplayName() string { - if m.Name != "" { - return m.Name - } - return m.ID -} - -// AcceptsImages reports whether Input lists image. -func (m ModelSpec) AcceptsImages() bool { - for _, in := range m.Input { - if in == "image" { - return true - } - } - return false -} - -// Credentials is what the operator stored for one model row. -type Credentials struct { - APIKey string - AppID string - AppSecret string -} - // EndpointRequest is the input to a vendor's Endpoint hook. type EndpointRequest struct { BaseURL string @@ -229,8 +144,8 @@ type EndpointRequest struct { Extra map[string]string } -// Vendor is one model vendor / gateway / self-hosted runtime. -type Vendor struct { +// Definition is one model vendor / gateway / self-hosted runtime. +type Definition struct { // ID is the stable identifier stored in models.parameters.provider. ID string // Name is the brand name; Names carries localized variants keyed by @@ -275,8 +190,6 @@ type Vendor struct { Compat VendorCompat // ThinkingLevels is the vendor-level level map. ThinkingLevels api.ThinkingLevelMap - // Models is the built-in catalog (from models.json). - Models []ModelSpec // Order sorts the vendor list in the UI (lower first). Order int @@ -286,10 +199,10 @@ type Vendor struct { // PreferAPI, when set, may switch the protocol for a base URL / model // pair after URL inference ran (OpenAI uses Responses on its own host // and Chat Completions on relays). Returning "" keeps the current choice. - PreferAPI func(baseURL string, spec ModelSpec) api.API + PreferAPI func(baseURL string, spec models.ModelSpec) api.API // Signer, when set (AuthSigned), builds the request signer from the // stored credentials. - Signer func(creds Credentials) api.AuthFunc + Signer func(creds api.Credentials) api.AuthFunc // Validate checks a configuration before it is saved or used. Nil means // the default check (key required when RequiresAuth; model name required). Validate func(cfg *Config) error @@ -313,7 +226,7 @@ type Config struct { // GetDefaultURL returns the default base URL for a model type, falling back // to the chat URL. -func (v *Vendor) GetDefaultURL(modelType types.ModelType) string { +func (v *Definition) GetDefaultURL(modelType types.ModelType) string { if v == nil { return "" } @@ -327,7 +240,7 @@ func (v *Vendor) GetDefaultURL(modelType types.ModelType) string { } // SupportsType reports whether the vendor lists the model type. -func (v *Vendor) SupportsType(modelType types.ModelType) bool { +func (v *Definition) SupportsType(modelType types.ModelType) bool { for _, t := range v.ModelTypes { if t == modelType { return true @@ -337,7 +250,7 @@ func (v *Vendor) SupportsType(modelType types.ModelType) bool { } // LocalizedName returns the name for a locale, falling back to Name. -func (v *Vendor) LocalizedName(locale string) string { +func (v *Definition) LocalizedName(locale string) string { if n, ok := v.Names[locale]; ok && n != "" { return n } @@ -345,7 +258,7 @@ func (v *Vendor) LocalizedName(locale string) string { } // LocalizedDescription returns the description for a locale. -func (v *Vendor) LocalizedDescription(locale string) string { +func (v *Definition) LocalizedDescription(locale string) string { if d, ok := v.Descriptions[locale]; ok && d != "" { return d } @@ -354,7 +267,7 @@ func (v *Vendor) LocalizedDescription(locale string) string { // AuthStyleFor returns the auth style this vendor uses for one protocol, // falling back to the vendor-wide Auth. -func (v *Vendor) AuthStyleFor(protocol api.API) AuthStyle { +func (v *Definition) AuthStyleFor(protocol api.API) AuthStyle { if style, ok := v.AuthByAPI[protocol]; ok && style != "" { return style } @@ -363,8 +276,8 @@ func (v *Vendor) AuthStyleFor(protocol api.API) AuthStyle { // AuthFunc builds the request authenticator for the stored credentials. The // protocol matters because a vendor that serves a second protocol on a -// sub-path may authenticate it differently (see Vendor.AuthByAPI). -func (v *Vendor) AuthFunc(protocol api.API, creds Credentials) api.AuthFunc { +// sub-path may authenticate it differently (see Definition.AuthByAPI). +func (v *Definition) AuthFunc(protocol api.API, creds api.Credentials) api.AuthFunc { switch v.AuthStyleFor(protocol) { case AuthAPIKeyHeader: return api.HeaderAuth("api-key", creds.APIKey) @@ -385,7 +298,7 @@ func (v *Vendor) AuthFunc(protocol api.API, creds Credentials) api.AuthFunc { } // ValidateConfig runs the vendor's validation. -func (v *Vendor) ValidateConfig(cfg *Config) error { +func (v *Definition) ValidateConfig(cfg *Config) error { if v.Validate != nil { return v.Validate(cfg) } @@ -395,5 +308,21 @@ func (v *Vendor) ValidateConfig(cfg *Config) error { // IconContentType is the media type of vendor icons served inline. const IconContentType = "image/svg+xml" -// Ptr returns a pointer to v; vendor packages use it to fill overlay structs. -func Ptr[T any](v T) *T { return &v } +// GenericID is the catch-all OpenAI-compatible provider. +const GenericID = "generic" + +func defaultValidate(v *Definition, cfg *Config) error { + if cfg == nil { + return fmt.Errorf("config is nil") + } + if v.RequiresAuth && v.Auth != AuthSigned && strings.TrimSpace(cfg.APIKey) == "" { + return fmt.Errorf("API key is required for %s", v.Name) + } + if v.ID == GenericID && strings.TrimSpace(cfg.BaseURL) == "" { + return fmt.Errorf("base URL is required for generic provider") + } + if strings.TrimSpace(cfg.ModelName) == "" { + return fmt.Errorf("model name is required") + } + return nil +} diff --git a/internal/models/vendors/gemini/vendor.go b/internal/models/providers/gemini.go similarity index 77% rename from internal/models/vendors/gemini/vendor.go rename to internal/models/providers/gemini.go index 7694f026..b5f7dd63 100644 --- a/internal/models/vendors/gemini/vendor.go +++ b/internal/models/providers/gemini.go @@ -1,4 +1,4 @@ -// Package gemini registers Google's Gemini API. +// Package providers registers Google's Gemini API. // // Facts (https://ai.google.dev/gemini-api/docs/thinking): // - the native protocol is generateContent under @@ -44,67 +44,63 @@ // - gemini-3.1-flash-lite is on the models page but absent from the // thinking guide's level table, so its minimal rung is an assumption // carried over from the other Flash Lite tiers. -package gemini +package providers import ( _ "embed" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" "github.com/Tencent/WeKnora/internal/types" ) -//go:embed models.json -var modelsJSON []byte +//go:embed assets/gemini.svg +var geminiIcon []byte -//go:embed icon.svg -var icon []byte +// GeminiID is the provider identifier stored on model rows. +const GeminiID = "gemini" -// ID is the provider identifier stored on model rows. -const ID = "gemini" +// GeminiBaseURL is the native Gemini API endpoint. +const GeminiBaseURL = "https://generativelanguage.googleapis.com/v1beta" -// BaseURL is the native Gemini API endpoint. -const BaseURL = "https://generativelanguage.googleapis.com/v1beta" +// GeminiOpenAICompatBaseURL keeps the OpenAI Chat Completions protocol. +const GeminiOpenAICompatBaseURL = GeminiBaseURL + "/openai" -// OpenAICompatBaseURL keeps the OpenAI Chat Completions protocol. -const OpenAICompatBaseURL = BaseURL + "/openai" - -func init() { - catalog.Register(&catalog.Vendor{ - ID: ID, +func newGeminiProvider() *Definition { + return &Definition{ + ID: GeminiID, Name: "Google Gemini", Names: map[string]string{"zh-CN": "Google Gemini"}, Description: "gemini-3.8-flash, gemini-3.1-pro-preview, gemini-2.5-pro, gemini-embedding-2, etc. " + - "Native generateContent by default; set base_url to " + OpenAICompatBaseURL + + "Native generateContent by default; set base_url to " + GeminiOpenAICompatBaseURL + " to keep the OpenAI-compatible protocol.", Descriptions: map[string]string{ "zh-CN": "gemini-3.8-flash, gemini-3.1-pro-preview, gemini-2.5-pro, gemini-embedding-2 等。" + - "默认走原生 generateContent 协议;将 base_url 指向 " + OpenAICompatBaseURL + " 可继续使用 OpenAI 兼容协议。", + "默认走原生 generateContent 协议;将 base_url 指向 " + GeminiOpenAICompatBaseURL + " 可继续使用 OpenAI 兼容协议。", }, Website: "https://aistudio.google.com", - Icon: icon, + Icon: geminiIcon, API: api.APIGoogleGenerativeAI, EmbeddingAPI: api.EmbeddingGoogle, Order: 33, RequiresAuth: true, - Auth: catalog.AuthGoogleAPIKey, + Auth: AuthGoogleAPIKey, // The OpenAI-compatible facade documents only Authorization: Bearer. // Sending x-goog-api-key there would change the credential of every // row stored before the native protocol became the default — they all // carry the .../v1beta/openai base URL. - AuthByAPI: map[api.API]catalog.AuthStyle{ - api.APIOpenAICompletions: catalog.AuthBearer, + AuthByAPI: map[api.API]AuthStyle{ + api.APIOpenAICompletions: AuthBearer, }, URLPatterns: []string{"generativelanguage.googleapis.com"}, DefaultBaseURLs: map[types.ModelType]string{ - types.ModelTypeKnowledgeQA: BaseURL, - types.ModelTypeEmbedding: BaseURL, + types.ModelTypeKnowledgeQA: GeminiBaseURL, + types.ModelTypeEmbedding: GeminiBaseURL, }, ModelTypes: []types.ModelType{ types.ModelTypeKnowledgeQA, types.ModelTypeEmbedding, }, - Compat: catalog.VendorCompat{ + Compat: VendorCompat{ // https://ai.google.dev/api/embeddings: per request model, content // and embedContentConfig {taskType, title, outputDimensionality, // autoTruncate, …}; the same option names at the top level of the @@ -114,19 +110,18 @@ func init() { // gemini-embedding-001 only and is deliberately not declared: it // changes the document vectors, so turning it on would split every // existing index across two spaces (Tencent/WeKnora#1401). - Embeddings: catalog.EmbeddingsCompat{ - DimensionsField: catalog.Ptr("outputDimensionality"), + Embeddings: api.EmbeddingsCompat{ + DimensionsField: api.Ptr("outputDimensionality"), }, // Used when the operator points base_url at the /openai facade. - OpenAICompletions: catalog.OpenAICompletionsCompat{ + OpenAICompletions: api.OpenAICompletionsCompat{ ToolCallExtraFields: []string{"extra_content"}, - ThinkingFormat: catalog.Ptr(catalog.ThinkingFormatOpenAI), - SupportsReasoningEffort: catalog.Ptr(true), - PromptCacheAccounting: catalog.Ptr(true), + ThinkingFormat: api.Ptr(api.ThinkingFormatOpenAI), + SupportsReasoningEffort: api.Ptr(true), + PromptCacheAccounting: api.Ptr(true), }, // Native protocol keeps the generativelanguage defaults. - GoogleGenerativeAI: catalog.GoogleGenerativeAICompat{}, + GoogleGenerativeAI: api.GoogleGenerativeAICompat{}, }, - Models: catalog.MustParseModels(modelsJSON), - }) + } } diff --git a/internal/models/vendors/generic/vendor.go b/internal/models/providers/generic.go similarity index 79% rename from internal/models/vendors/generic/vendor.go rename to internal/models/providers/generic.go index 145530fd..39f4e125 100644 --- a/internal/models/vendors/generic/vendor.go +++ b/internal/models/providers/generic.go @@ -1,4 +1,4 @@ -// Package generic registers the catch-all vendor for any OpenAI-compatible +// Package providers registers the catch-all vendor for any OpenAI-compatible // endpoint (vLLM, SGLang, Xinference, Ollama's OpenAI facade, ...). // // Facts (no single upstream; the settings follow the vLLM / SGLang @@ -29,40 +29,33 @@ // DeepSeek-V3, so a non-Qwen template will ignore the switch this vendor // sends rather than reject it. Per-model chat-template keys are not // expressible in the compat model. -package generic +package providers import ( _ "embed" "fmt" "strings" + "github.com/Tencent/WeKnora/internal/models" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" "github.com/Tencent/WeKnora/internal/types" ) -//go:embed models.json -var modelsJSON []byte +//go:embed assets/generic.svg +var genericIcon []byte -//go:embed icon.svg -var icon []byte - -// ID is the provider identifier stored on model rows. It must equal -// catalog.GenericID because Resolve degrades unknown vendors to it. -const ID = catalog.GenericID - -func init() { - catalog.Register(&catalog.Vendor{ - ID: ID, +func newGenericProvider() *Definition { + return &Definition{ + ID: GenericID, Name: "Custom (OpenAI-compatible)", Names: map[string]string{"zh-CN": "自定义 (OpenAI兼容接口)"}, Description: "Any OpenAI-compatible endpoint (vLLM, SGLang, Xinference, Ollama, ...)", Descriptions: map[string]string{"zh-CN": "任意 OpenAI 兼容接口(vLLM、SGLang、Xinference、Ollama 等)"}, - Icon: icon, + Icon: genericIcon, API: api.APIOpenAICompletions, Order: 0, RequiresAuth: false, - Auth: catalog.AuthBearer, + Auth: AuthBearer, DefaultBaseURLs: map[types.ModelType]string{}, ModelTypes: []types.ModelType{ types.ModelTypeKnowledgeQA, @@ -71,12 +64,12 @@ func init() { types.ModelTypeVLLM, types.ModelTypeASR, }, - ExtraFields: []catalog.ExtraField{{ - Key: catalog.ExtraScoreScale, + ExtraFields: []ExtraField{{ + Key: models.ExtraScoreScale, Label: "Rerank score scale", Labels: map[string]string{"zh-CN": "Rerank 分数标度"}, Type: "select", - Options: []catalog.ExtraFieldOption{ + Options: []ExtraFieldOption{ { Label: "Unbounded score (Qwen3-Reranker class)", Labels: map[string]string{"zh-CN": "无界分数(Qwen3-Reranker 一类)"}, @@ -96,7 +89,7 @@ func init() { Required: false, ModelTypes: []types.ModelType{types.ModelTypeRerank}, }, { - Key: catalog.ExtraTruncatePromptTokens, + Key: models.ExtraTruncatePromptTokens, Label: "Rerank prompt truncation (vLLM)", Labels: map[string]string{"zh-CN": "Rerank 提示词截断长度(vLLM)"}, Type: "number", @@ -107,7 +100,7 @@ func init() { Placeholders: map[string]string{"zh-CN": "留空,除非后端因文档过长而报错"}, ModelTypes: []types.ModelType{types.ModelTypeRerank}, }}, - Compat: catalog.VendorCompat{ + Compat: VendorCompat{ // Transcriptions keeps the baseline, json by default. The // pre-catalog client always asked for verbose_json, which not every // model or server can produce: OpenAI's gpt-4o transcribers accept @@ -116,30 +109,30 @@ func init() { // {"response_format": "verbose_json"} in its compat. The language // hint goes as OpenAI's language form field, which a server that // does not implement it ignores. - Transcriptions: catalog.TranscriptionsCompat{ - LanguageParam: catalog.Ptr(catalog.LanguageForm), + Transcriptions: api.TranscriptionsCompat{ + LanguageParam: api.Ptr(api.LanguageForm), }, - Embeddings: catalog.EmbeddingsCompat{ + Embeddings: api.EmbeddingsCompat{ // Whatever the operator runs. Everything the pre-catalog client // sent stays: vLLM, SGLang, TEI and Ollama's OpenAI route all // accept it, and dimensions still goes out only when the row // asks for a width. - SendEncodingFormat: catalog.Ptr(true), - DimensionsField: catalog.Ptr("dimensions"), - AcceptsTruncatePromptTokens: catalog.Ptr(true), + SendEncodingFormat: api.Ptr(true), + DimensionsField: api.Ptr("dimensions"), + AcceptsTruncatePromptTokens: api.Ptr(true), }, - Rerank: catalog.RerankCompat{ + Rerank: api.RerankCompat{ // Any OpenAI-compatible endpoint an operator points here is most // often a vLLM or SGLang server, which is where // truncate_prompt_tokens comes from. - AcceptsTruncatePromptTokens: catalog.Ptr(true), + AcceptsTruncatePromptTokens: api.Ptr(true), }, - OpenAICompletions: catalog.OpenAICompletionsCompat{ - MaxTokensField: catalog.Ptr("max_tokens"), - ThinkingFormat: catalog.Ptr(catalog.ThinkingFormatChatTemplateKwargs), + OpenAICompletions: api.OpenAICompletionsCompat{ + MaxTokensField: api.Ptr("max_tokens"), + ThinkingFormat: api.Ptr(api.ThinkingFormatChatTemplateKwargs), }, }, - Validate: func(cfg *catalog.Config) error { + Validate: func(cfg *Config) error { if cfg == nil { return fmt.Errorf("config is nil") } @@ -151,6 +144,5 @@ func init() { } return nil }, - Models: catalog.MustParseModels(modelsJSON), - }) + } } diff --git a/internal/models/vendors/gpustack/vendor.go b/internal/models/providers/gpustack.go similarity index 77% rename from internal/models/vendors/gpustack/vendor.go rename to internal/models/providers/gpustack.go index f42f3ff1..0062b6ec 100644 --- a/internal/models/vendors/gpustack/vendor.go +++ b/internal/models/providers/gpustack.go @@ -1,4 +1,4 @@ -// Package gpustack registers a self-hosted GPUStack cluster +// Package providers registers a self-hosted GPUStack cluster // (https://github.com/gpustack/gpustack). // // Facts (https://docs.gpustack.ai/latest/integrations/inference-apis/): @@ -27,52 +27,49 @@ // The 2.x docs neither document it nor announce its removal, which is why // the default moved to /v1 rather than keeping a path only one line // documents. -package gpustack +package providers import ( _ "embed" "fmt" "strings" + "github.com/Tencent/WeKnora/internal/models" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" "github.com/Tencent/WeKnora/internal/types" ) -//go:embed models.json -var modelsJSON []byte +//go:embed assets/gpustack.svg +var gpustackIcon []byte -//go:embed icon.svg -var icon []byte +// GpustackID is the provider identifier stored on model rows. +const GpustackID = "gpustack" -// ID is the provider identifier stored on model rows. -const ID = "gpustack" - -// BaseURL is the OpenAI-compatible placeholder. Since GPUStack 2.x every +// GpustackBaseURL is the OpenAI-compatible placeholder. Since GPUStack 2.x every // surface — chat, embeddings, transcriptions and the Jina-style rerank — // hangs off /v1. -const BaseURL = "http://your_gpustack_server_url/v1" +const GpustackBaseURL = "http://your_gpustack_server_url/v1" -func init() { - catalog.Register(&catalog.Vendor{ - ID: ID, +func newGpustackProvider() *Definition { + return &Definition{ + ID: GpustackID, Name: "GPUStack", Names: map[string]string{"zh-CN": "GPUStack"}, Description: "Choose your deployed model on GPUStack", Descriptions: map[string]string{"zh-CN": "选择你在 GPUStack 上部署的模型"}, Website: "https://gpustack.ai", - Icon: icon, + Icon: gpustackIcon, API: api.APIOpenAICompletions, Order: 60, RequiresAuth: true, - Auth: catalog.AuthBearer, + Auth: AuthBearer, URLPatterns: []string{"gpustack"}, DefaultBaseURLs: map[types.ModelType]string{ - types.ModelTypeKnowledgeQA: BaseURL, - types.ModelTypeEmbedding: BaseURL, - types.ModelTypeRerank: BaseURL, - types.ModelTypeVLLM: BaseURL, - types.ModelTypeASR: BaseURL, + types.ModelTypeKnowledgeQA: GpustackBaseURL, + types.ModelTypeEmbedding: GpustackBaseURL, + types.ModelTypeRerank: GpustackBaseURL, + types.ModelTypeVLLM: GpustackBaseURL, + types.ModelTypeASR: GpustackBaseURL, }, ModelTypes: []types.ModelType{ types.ModelTypeKnowledgeQA, @@ -81,12 +78,12 @@ func init() { types.ModelTypeVLLM, types.ModelTypeASR, }, - ExtraFields: []catalog.ExtraField{{ - Key: catalog.ExtraScoreScale, + ExtraFields: []ExtraField{{ + Key: models.ExtraScoreScale, Label: "Rerank score scale", Labels: map[string]string{"zh-CN": "Rerank 分数标度"}, Type: "select", - Options: []catalog.ExtraFieldOption{ + Options: []ExtraFieldOption{ { Label: "Unbounded score (Qwen3-Reranker class)", Labels: map[string]string{"zh-CN": "无界分数(Qwen3-Reranker 一类)"}, @@ -106,7 +103,7 @@ func init() { Required: false, ModelTypes: []types.ModelType{types.ModelTypeRerank}, }, { - Key: catalog.ExtraTruncatePromptTokens, + Key: models.ExtraTruncatePromptTokens, Label: "Rerank prompt truncation (vLLM)", Labels: map[string]string{"zh-CN": "Rerank 提示词截断长度(vLLM)"}, Type: "number", @@ -117,7 +114,7 @@ func init() { Placeholders: map[string]string{"zh-CN": "留空,除非后端因文档过长而报错"}, ModelTypes: []types.ModelType{types.ModelTypeRerank}, }}, - Compat: catalog.VendorCompat{ + Compat: VendorCompat{ // Transcriptions keeps the baseline, json by default. GPUStack // serves audio through vox-box (https://github.com/gpustack/vox-box), // whose route wraps a json answer as {"text": ...} but returns @@ -126,34 +123,34 @@ func init() { // format. The pre-catalog client's verbose_json therefore arrived // as a JSON string that could not be decoded. The route reads a // language form field. - Transcriptions: catalog.TranscriptionsCompat{ - LanguageParam: catalog.Ptr(catalog.LanguageForm), + Transcriptions: api.TranscriptionsCompat{ + LanguageParam: api.Ptr(api.LanguageForm), }, - Embeddings: catalog.EmbeddingsCompat{ + Embeddings: api.EmbeddingsCompat{ // vLLM's embedding server: dimensions for Matryoshka models, the // row's truncation budget, and encoding_format. - SendEncodingFormat: catalog.Ptr(true), - DimensionsField: catalog.Ptr("dimensions"), - AcceptsTruncatePromptTokens: catalog.Ptr(true), + SendEncodingFormat: api.Ptr(true), + DimensionsField: api.Ptr("dimensions"), + AcceptsTruncatePromptTokens: api.Ptr(true), }, - Rerank: catalog.RerankCompat{ + Rerank: api.RerankCompat{ // GPUStack's built-in backends are vLLM, SGLang, Ascend MindIE and // VoxBox, so the vLLM rerank extension reaches the model. - AcceptsTruncatePromptTokens: catalog.Ptr(true), + AcceptsTruncatePromptTokens: api.Ptr(true), // The field is spelled relevance_score like the Cohere shape, but // it is not a probability: the rerank API page's own example // returns 1.951932668685913, -3.7347371578216553 and // -6.157620906829834. Read as a probability, every negative score // falls below a relevance threshold tuned for 0..1. // https://docs.gpustack.ai/2.0/user-guide/rerank-api/ - ScoreScale: catalog.Ptr(api.ScoreLogit), + ScoreScale: api.Ptr(api.ScoreLogit), }, - OpenAICompletions: catalog.OpenAICompletionsCompat{ - MaxTokensField: catalog.Ptr("max_tokens"), - ThinkingFormat: catalog.Ptr(catalog.ThinkingFormatChatTemplateKwargs), + OpenAICompletions: api.OpenAICompletionsCompat{ + MaxTokensField: api.Ptr("max_tokens"), + ThinkingFormat: api.Ptr(api.ThinkingFormatChatTemplateKwargs), }, }, - Validate: func(cfg *catalog.Config) error { + Validate: func(cfg *Config) error { if cfg == nil { return fmt.Errorf("config is nil") } @@ -168,6 +165,5 @@ func init() { } return nil }, - Models: catalog.MustParseModels(modelsJSON), - }) + } } diff --git a/internal/models/vendors/hunyuan/vendor.go b/internal/models/providers/hunyuan.go similarity index 83% rename from internal/models/vendors/hunyuan/vendor.go rename to internal/models/providers/hunyuan.go index 8dfc8573..3218de8b 100644 --- a/internal/models/vendors/hunyuan/vendor.go +++ b/internal/models/providers/hunyuan.go @@ -1,4 +1,4 @@ -// Package hunyuan registers Tencent Hunyuan through its OpenAI-compatible +// Package providers registers Tencent Hunyuan through its OpenAI-compatible // endpoint. // // Facts (https://cloud.tencent.com/document/product/1729/111007): @@ -52,61 +52,56 @@ // unverified: the hunyuan-2.0-* ids are documented only on the Anthropic // facade, so their availability on this OpenAI-compatible host, their // context windows and their output caps are unconfirmed. -package hunyuan +package providers import ( _ "embed" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" "github.com/Tencent/WeKnora/internal/types" ) -//go:embed models.json -var modelsJSON []byte +//go:embed assets/hunyuan.svg +var hunyuanIcon []byte -//go:embed icon.svg -var icon []byte +// HunyuanID is the provider identifier stored on model rows. +const HunyuanID = "hunyuan" -// ID is the provider identifier stored on model rows. -const ID = "hunyuan" +// HunyuanBaseURL is the OpenAI-compatible endpoint (chat and embedding). +const HunyuanBaseURL = "https://api.hunyuan.cloud.tencent.com/v1" -// BaseURL is the OpenAI-compatible endpoint (chat and embedding). -const BaseURL = "https://api.hunyuan.cloud.tencent.com/v1" - -func init() { - catalog.Register(&catalog.Vendor{ - ID: ID, +func newHunyuanProvider() *Definition { + return &Definition{ + ID: HunyuanID, Name: "Tencent Hunyuan", Names: map[string]string{"zh-CN": "腾讯混元 Hunyuan"}, Description: "hunyuan-t1-latest, hunyuan-turbos-latest, hunyuan-a13b, hunyuan-embedding, etc.", Website: "https://cloud.tencent.com/product/hunyuan", - Icon: icon, + Icon: hunyuanIcon, API: api.APIOpenAICompletions, Order: 13, RequiresAuth: true, - Auth: catalog.AuthBearer, + Auth: AuthBearer, URLPatterns: []string{"hunyuan.cloud.tencent.com"}, DefaultBaseURLs: map[types.ModelType]string{ - types.ModelTypeKnowledgeQA: BaseURL, - types.ModelTypeEmbedding: BaseURL, + types.ModelTypeKnowledgeQA: HunyuanBaseURL, + types.ModelTypeEmbedding: HunyuanBaseURL, }, ModelTypes: []types.ModelType{ types.ModelTypeKnowledgeQA, types.ModelTypeEmbedding, }, - Compat: catalog.VendorCompat{ + Compat: VendorCompat{ // Embeddings keeps the bare baseline on purpose: "Embedding 接口目前仅 // 支持 input 和 model 参数 … dimensions 固定为 1024" // (https://cloud.tencent.com/document/product/1729/111007). - OpenAICompletions: catalog.OpenAICompletionsCompat{ - MaxTokensField: catalog.Ptr("max_tokens"), - ThinkingFormat: catalog.Ptr(catalog.ThinkingFormatEnableThinking), + OpenAICompletions: api.OpenAICompletionsCompat{ + MaxTokensField: api.Ptr("max_tokens"), + ThinkingFormat: api.Ptr(api.ThinkingFormatEnableThinking), // 可选值包括 none、auto、custom: neither "required" nor OpenAI's // named-function object is documented. ToolChoiceModes: []string{"none", "auto"}, }, }, - Models: catalog.MustParseModels(modelsJSON), - }) + } } diff --git a/internal/models/vendors/jina/vendor.go b/internal/models/providers/jina.go similarity index 74% rename from internal/models/vendors/jina/vendor.go rename to internal/models/providers/jina.go index 0d1b4191..5a21153e 100644 --- a/internal/models/vendors/jina/vendor.go +++ b/internal/models/providers/jina.go @@ -1,4 +1,4 @@ -// Package jina registers Jina AI's embedding and rerank APIs. +// Package providers registers Jina AI's embedding and rerank APIs. // // Facts (https://jina.ai/embeddings and https://jina.ai/reranker): // - both endpoints live under https://api.jina.ai/v1 and authenticate with @@ -20,51 +20,47 @@ // Unverified: api.jina.ai does not serve a fetchable OpenAPI document, so // the OpenAI-schema compatibility claim rests on the wording of the // embeddings FAQ rather than a spec. -package jina +package providers import ( _ "embed" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" "github.com/Tencent/WeKnora/internal/types" ) -//go:embed models.json -var modelsJSON []byte +//go:embed assets/jina.svg +var jinaIcon []byte -//go:embed icon.svg -var icon []byte +// JinaID is the provider identifier stored on model rows. +const JinaID = "jina" -// ID is the provider identifier stored on model rows. -const ID = "jina" +// JinaBaseURL serves embeddings and rerank. +const JinaBaseURL = "https://api.jina.ai/v1" -// BaseURL serves embeddings and rerank. -const BaseURL = "https://api.jina.ai/v1" - -func init() { - catalog.Register(&catalog.Vendor{ - ID: ID, +func newJinaProvider() *Definition { + return &Definition{ + ID: JinaID, Name: "Jina AI", Names: map[string]string{"zh-CN": "Jina"}, Description: "jina-embeddings-v5-text-small, jina-embeddings-v4, jina-reranker-v3.5, jina-reranker-m0, etc.", Website: "https://jina.ai", - Icon: icon, + Icon: jinaIcon, API: api.APIOpenAICompletions, Order: 50, RequiresAuth: true, - Auth: catalog.AuthBearer, + Auth: AuthBearer, URLPatterns: []string{"api.jina.ai"}, DefaultBaseURLs: map[types.ModelType]string{ - types.ModelTypeEmbedding: BaseURL, - types.ModelTypeRerank: BaseURL, + types.ModelTypeEmbedding: JinaBaseURL, + types.ModelTypeRerank: JinaBaseURL, }, ModelTypes: []types.ModelType{ types.ModelTypeEmbedding, types.ModelTypeRerank, }, - Compat: catalog.VendorCompat{ - Embeddings: catalog.EmbeddingsCompat{ + Compat: VendorCompat{ + Embeddings: api.EmbeddingsCompat{ // https://jina.ai/embeddings/: model, input, an optional task, // dimensions, embedding_type, normalized, late_chunking and a // boolean truncate that defaults to false (an over-long input is @@ -73,17 +69,16 @@ func init() { // changes the document vectors, so turning it on would leave every // existing index half in one space and half in another // (Tencent/WeKnora#1401). - DimensionsField: catalog.Ptr("dimensions"), - TruncateField: catalog.Ptr("truncate"), - TruncateValue: catalog.Ptr("true"), + DimensionsField: api.Ptr("dimensions"), + TruncateField: api.Ptr("truncate"), + TruncateValue: api.Ptr("true"), }, - Rerank: catalog.RerankCompat{ + Rerank: api.RerankCompat{ // return_documents echoes the text back. Results are matched // by index, so this is not needed to map them; it is kept // because it is what this vendor has always been sent. - SendReturnDocs: catalog.Ptr(true), + SendReturnDocs: api.Ptr(true), }, }, - Models: catalog.MustParseModels(modelsJSON), - }) + } } diff --git a/internal/models/vendors/litellm/vendor.go b/internal/models/providers/litellm.go similarity index 75% rename from internal/models/vendors/litellm/vendor.go rename to internal/models/providers/litellm.go index 23c24f2a..4d30d963 100644 --- a/internal/models/vendors/litellm/vendor.go +++ b/internal/models/providers/litellm.go @@ -1,4 +1,4 @@ -// Package litellm registers a self-hosted LiteLLM proxy +// Package providers registers a self-hosted LiteLLM proxy // (https://github.com/BerriAI/litellm). // // Facts (https://docs.litellm.ai/docs/reasoning_content): @@ -26,51 +26,48 @@ // the provider in the request body", but a proxy configured with // allowed_openai_params may drop it, so operators fronting open-weight // models may need thinking_control=chat_template_kwargs plus that allowlist. -package litellm +package providers import ( _ "embed" + "github.com/Tencent/WeKnora/internal/models" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" "github.com/Tencent/WeKnora/internal/types" ) -//go:embed models.json -var modelsJSON []byte +//go:embed assets/litellm.svg +var litellmIcon []byte -//go:embed icon.svg -var icon []byte +// LitellmID is the provider identifier stored on model rows. +const LitellmID = "litellm" -// ID is the provider identifier stored on model rows. -const ID = "litellm" +// LitellmBaseURL is a placeholder the operator replaces with a reachable proxy. +const LitellmBaseURL = "http://your_litellm_proxy/v1" -// BaseURL is a placeholder the operator replaces with a reachable proxy. -const BaseURL = "http://your_litellm_proxy/v1" - -// RerankBaseURL is the proxy root. LiteLLM documents rerank at /rerank +// LitellmRerankBaseURL is the proxy root. LiteLLM documents rerank at /rerank // rather than /v1/rerank, so it does not hang off the chat base URL. -const RerankBaseURL = "http://your_litellm_proxy" +const LitellmRerankBaseURL = "http://your_litellm_proxy" -func init() { - catalog.Register(&catalog.Vendor{ - ID: ID, +func newLitellmProvider() *Definition { + return &Definition{ + ID: LitellmID, Name: "LiteLLM", Names: map[string]string{"zh-CN": "LiteLLM"}, - Description: "Self-hosted LiteLLM proxy: one OpenAI-compatible endpoint to 100+ providers.", + Description: "Self-hosted LiteLLM proxy: one OpenAI-compatible endpoint to 100+ ", Descriptions: map[string]string{"zh-CN": "自建 LiteLLM 代理:一个 OpenAI 兼容入口对接 100+ 模型服务。"}, Website: "https://docs.litellm.ai", - Icon: icon, + Icon: litellmIcon, API: api.APIOpenAICompletions, Order: 41, RequiresAuth: true, - Auth: catalog.AuthBearer, + Auth: AuthBearer, URLPatterns: []string{"litellm"}, DefaultBaseURLs: map[types.ModelType]string{ - types.ModelTypeKnowledgeQA: BaseURL, - types.ModelTypeEmbedding: BaseURL, - types.ModelTypeRerank: RerankBaseURL, - types.ModelTypeVLLM: BaseURL, + types.ModelTypeKnowledgeQA: LitellmBaseURL, + types.ModelTypeEmbedding: LitellmBaseURL, + types.ModelTypeRerank: LitellmRerankBaseURL, + types.ModelTypeVLLM: LitellmBaseURL, }, ModelTypes: []types.ModelType{ types.ModelTypeKnowledgeQA, @@ -79,12 +76,12 @@ func init() { types.ModelTypeVLLM, types.ModelTypeASR, }, - ExtraFields: []catalog.ExtraField{{ - Key: catalog.ExtraScoreScale, + ExtraFields: []ExtraField{{ + Key: models.ExtraScoreScale, Label: "Rerank score scale", Labels: map[string]string{"zh-CN": "Rerank 分数标度"}, Type: "select", - Options: []catalog.ExtraFieldOption{ + Options: []ExtraFieldOption{ { Label: "Unbounded score (Qwen3-Reranker class)", Labels: map[string]string{"zh-CN": "无界分数(Qwen3-Reranker 一类)"}, @@ -104,20 +101,20 @@ func init() { Required: false, ModelTypes: []types.ModelType{types.ModelTypeRerank}, }}, - Compat: catalog.VendorCompat{ + Compat: VendorCompat{ // Transcriptions keeps the baseline: the proxy serves the OpenAI // /audio/transcriptions route for whichever upstream it is // configured with (https://docs.litellm.ai/docs/audio_transcription). - Embeddings: catalog.EmbeddingsCompat{ + Embeddings: api.EmbeddingsCompat{ // https://docs.litellm.ai/docs/embedding/supported_embedding: // model, input, user, dimensions, encoding_format; anything else // is forwarded to the upstream as a provider-specific kwarg. - SendEncodingFormat: catalog.Ptr(true), - DimensionsField: catalog.Ptr("dimensions"), + SendEncodingFormat: api.Ptr(true), + DimensionsField: api.Ptr("dimensions"), }, - OpenAICompletions: catalog.OpenAICompletionsCompat{ - ThinkingFormat: catalog.Ptr(catalog.ThinkingFormatOpenAI), - SupportsReasoningEffort: catalog.Ptr(true), + OpenAICompletions: api.OpenAICompletionsCompat{ + ThinkingFormat: api.Ptr(api.ThinkingFormatOpenAI), + SupportsReasoningEffort: api.Ptr(true), }, }, // LiteLLM documents the whole ladder plus "none" as the off switch. @@ -126,6 +123,5 @@ func init() { api.ReasoningXHigh: api.StringPtr("xhigh"), api.ReasoningMax: api.StringPtr("max"), }, - Models: catalog.MustParseModels(modelsJSON), - }) + } } diff --git a/internal/models/vendors/lkeap/vendor.go b/internal/models/providers/lkeap.go similarity index 80% rename from internal/models/vendors/lkeap/vendor.go rename to internal/models/providers/lkeap.go index 4bce1323..9f44aa7c 100644 --- a/internal/models/vendors/lkeap/vendor.go +++ b/internal/models/providers/lkeap.go @@ -1,4 +1,4 @@ -// Package lkeap registers Tencent Cloud LKEAP (Knowledge Engine Atomic +// Package providers registers Tencent Cloud LKEAP (Knowledge Engine Atomic // Power) through its OpenAI-compatible endpoint. // // Chat facts (https://cloud.tencent.com/document/product/1772/115969 and @@ -39,35 +39,31 @@ // unverified: LKEAP documents neither tool_choice modes, // stream_options.include_usage nor any prompt-cache accounting, so the // protocol defaults are kept. -package lkeap +package providers import ( _ "embed" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" "github.com/Tencent/WeKnora/internal/types" ) -//go:embed models.json -var modelsJSON []byte +//go:embed assets/lkeap.svg +var lkeapIcon []byte -//go:embed icon.svg -var icon []byte +// LkeapID is the provider identifier stored on model rows. +const LkeapID = "lkeap" -// ID is the provider identifier stored on model rows. -const ID = "lkeap" +// LkeapBaseURL is the OpenAI-compatible chat endpoint. +const LkeapBaseURL = "https://api.lkeap.cloud.tencent.com/v1" -// BaseURL is the OpenAI-compatible chat endpoint. -const BaseURL = "https://api.lkeap.cloud.tencent.com/v1" +// LkeapRerankBaseURL is the TC3-signed cloud API host used for rerank. +const LkeapRerankBaseURL = "https://lkeap.tencentcloudapi.com" -// RerankBaseURL is the TC3-signed cloud API host used for rerank. -const RerankBaseURL = "https://lkeap.tencentcloudapi.com" - -func init() { +func newLkeapProvider() *Definition { rerankOnly := []types.ModelType{types.ModelTypeRerank} - catalog.Register(&catalog.Vendor{ - ID: ID, + return &Definition{ + ID: LkeapID, Name: "Tencent Cloud LKEAP", Names: map[string]string{"zh-CN": "腾讯云 LKEAP"}, Description: "deepseek-v3.2, deepseek-v3.1-terminus, deepseek-r1-0528, lke-reranker-base", @@ -75,15 +71,15 @@ func init() { "zh-CN": "DeepSeek-V3.2、DeepSeek-V3.1-Terminus、DeepSeek-R1-0528、lke-reranker-base", }, Website: "https://cloud.tencent.com/product/lkeap", - Icon: icon, + Icon: lkeapIcon, API: api.APIOpenAICompletions, Order: 23, RequiresAuth: true, - Auth: catalog.AuthBearer, + Auth: AuthBearer, URLPatterns: []string{"lkeap.cloud.tencent.com", "api.lkeap", "lkeap.tencentcloudapi.com"}, DefaultBaseURLs: map[types.ModelType]string{ - types.ModelTypeKnowledgeQA: BaseURL, - types.ModelTypeRerank: RerankBaseURL, + types.ModelTypeKnowledgeQA: LkeapBaseURL, + types.ModelTypeRerank: LkeapRerankBaseURL, }, ModelTypes: []types.ModelType{ types.ModelTypeKnowledgeQA, @@ -93,7 +89,7 @@ func init() { // first credential is a SecretId, not a bearer token. Left as the // generic "API Key" an operator pastes an `sk-` key that can never // sign a request. - CredentialLabels: []catalog.CredentialLabel{{ + CredentialLabels: []CredentialLabel{{ Label: "SecretId", Labels: map[string]string{"zh-CN": "SecretId(TC3 签名)"}, Placeholder: "Tencent Cloud SecretId (AKID...)", @@ -103,7 +99,7 @@ func init() { ModelTypes: rerankOnly, Required: true, }}, - ExtraFields: []catalog.ExtraField{ + ExtraFields: []ExtraField{ { Key: "secret_key", Label: "Secret Key", @@ -125,7 +121,7 @@ func init() { Type: "select", Default: "ap-guangzhou", Placeholder: "ap-guangzhou", - Options: []catalog.ExtraFieldOption{ + Options: []ExtraFieldOption{ {Label: "ap-guangzhou", Value: "ap-guangzhou"}, {Label: "ap-beijing", Value: "ap-beijing"}, }, @@ -133,23 +129,22 @@ func init() { }, }, RerankAPI: api.RerankTencentLKEAP, - Compat: catalog.VendorCompat{ - Rerank: catalog.RerankCompat{ + Compat: VendorCompat{ + Rerank: api.RerankCompat{ // RunRerank takes at most 60 documents, and Query plus Docs // together at most 2000 characters. - MaxDocuments: catalog.Ptr(60), - MaxRequestChars: catalog.Ptr(2000), + MaxDocuments: api.Ptr(60), + MaxRequestChars: api.Ptr(2000), // Batches went out one at a time before the shared batching // layer existed. A 2000-character budget splits a large // candidate set into many requests, so the default fan-out of // four would be a new burst against RunRerank. - MaxConcurrency: catalog.Ptr(1), + MaxConcurrency: api.Ptr(1), }, - OpenAICompletions: catalog.OpenAICompletionsCompat{ - MaxTokensField: catalog.Ptr("max_tokens"), - ThinkingFormat: catalog.Ptr(catalog.ThinkingFormatThinkingType), + OpenAICompletions: api.OpenAICompletionsCompat{ + MaxTokensField: api.Ptr("max_tokens"), + ThinkingFormat: api.Ptr(api.ThinkingFormatThinkingType), }, }, - Models: catalog.MustParseModels(modelsJSON), - }) + } } diff --git a/internal/models/vendors/longcat/vendor.go b/internal/models/providers/longcat.go similarity index 75% rename from internal/models/vendors/longcat/vendor.go rename to internal/models/providers/longcat.go index 603a5727..801f3e72 100644 --- a/internal/models/vendors/longcat/vendor.go +++ b/internal/models/providers/longcat.go @@ -1,4 +1,4 @@ -// Package longcat registers Meituan LongCat's OpenAI-compatible endpoint. +// Package providers registers Meituan LongCat's OpenAI-compatible endpoint. // // Facts (chat reference https://longcat.chat/platform/docs/zh/api/chat.html, // overview https://longcat.chat/platform/docs/zh/APIDocs.html): @@ -42,56 +42,51 @@ // unverified: the published usage object carries no cache counters even // though the price list bills cached input, so prompt_cache_accounting // stays off; neither prompt_cache_key nor cache_control is documented. -package longcat +package providers import ( _ "embed" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" "github.com/Tencent/WeKnora/internal/types" ) -//go:embed models.json -var modelsJSON []byte +//go:embed assets/longcat.svg +var longcatIcon []byte -//go:embed icon.svg -var icon []byte +// LongcatID is the provider identifier stored on model rows. +const LongcatID = "longcat" -// ID is the provider identifier stored on model rows. -const ID = "longcat" +// LongcatBaseURL is the OpenAI-compatible chat endpoint. +const LongcatBaseURL = "https://api.longcat.chat/openai/v1" -// BaseURL is the OpenAI-compatible chat endpoint. -const BaseURL = "https://api.longcat.chat/openai/v1" +// LongcatAnthropicBaseURL is the Anthropic Messages surface of the same platform. +const LongcatAnthropicBaseURL = "https://api.longcat.chat/anthropic/v1" -// AnthropicBaseURL is the Anthropic Messages surface of the same platform. -const AnthropicBaseURL = "https://api.longcat.chat/anthropic/v1" - -func init() { - catalog.Register(&catalog.Vendor{ - ID: ID, +func newLongcatProvider() *Definition { + return &Definition{ + ID: LongcatID, Name: "LongCat AI", Names: map[string]string{"zh-CN": "美团 LongCat"}, Description: "LongCat-2.0", Website: "https://longcat.chat/platform", - Icon: icon, + Icon: longcatIcon, API: api.APIOpenAICompletions, Order: 22, RequiresAuth: true, - Auth: catalog.AuthBearer, + Auth: AuthBearer, URLPatterns: []string{"longcat.chat"}, DefaultBaseURLs: map[types.ModelType]string{ - types.ModelTypeKnowledgeQA: BaseURL, + types.ModelTypeKnowledgeQA: LongcatBaseURL, }, ModelTypes: []types.ModelType{ types.ModelTypeKnowledgeQA, }, - Compat: catalog.VendorCompat{ - OpenAICompletions: catalog.OpenAICompletionsCompat{ - MaxTokensField: catalog.Ptr("max_tokens"), - ThinkingFormat: catalog.Ptr(catalog.ThinkingFormatThinkingType), + Compat: VendorCompat{ + OpenAICompletions: api.OpenAICompletionsCompat{ + MaxTokensField: api.Ptr("max_tokens"), + ThinkingFormat: api.Ptr(api.ThinkingFormatThinkingType), }, }, - Models: catalog.MustParseModels(modelsJSON), - }) + } } diff --git a/internal/models/vendors/mimo/vendor.go b/internal/models/providers/mimo.go similarity index 77% rename from internal/models/vendors/mimo/vendor.go rename to internal/models/providers/mimo.go index 48ece1f1..4f298563 100644 --- a/internal/models/vendors/mimo/vendor.go +++ b/internal/models/providers/mimo.go @@ -1,4 +1,4 @@ -// Package mimo registers Xiaomi MiMo's OpenAI-compatible endpoint. +// Package providers registers Xiaomi MiMo's OpenAI-compatible endpoint. // // Facts (https://mimo.mi.com/static/docs/api/chat/openai-api.md, // https://mimo.mi.com/static/docs/quick-start/summary/model.md, @@ -33,67 +33,62 @@ // limits and prices are unconfirmed; the ASR (mimo-v2.5-asr) and TTS models // are documented but not registered here, since this vendor only declares the // chat model type. -package mimo +package providers import ( _ "embed" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" "github.com/Tencent/WeKnora/internal/types" ) -//go:embed models.json -var modelsJSON []byte +//go:embed assets/mimo.svg +var mimoIcon []byte -//go:embed icon.svg -var icon []byte +// MimoID is the provider identifier stored on model rows. +const MimoID = "mimo" -// ID is the provider identifier stored on model rows. -const ID = "mimo" +// MimoBaseURL is the OpenAI-compatible chat endpoint. +const MimoBaseURL = "https://api.xiaomimimo.com/v1" -// BaseURL is the OpenAI-compatible chat endpoint. -const BaseURL = "https://api.xiaomimimo.com/v1" - -func init() { - catalog.Register(&catalog.Vendor{ - ID: ID, +func newMimoProvider() *Definition { + return &Definition{ + ID: MimoID, Name: "Xiaomi MiMo", Names: map[string]string{"zh-CN": "小米 MiMo"}, Description: "mimo-v2.5-pro, mimo-v2.5", Website: "https://platform.xiaomimimo.com", - Icon: icon, + Icon: mimoIcon, API: api.APIOpenAICompletions, Order: 18, RequiresAuth: true, - Auth: catalog.AuthBearer, + Auth: AuthBearer, URLPatterns: []string{"xiaomimimo.com"}, DefaultBaseURLs: map[types.ModelType]string{ - types.ModelTypeKnowledgeQA: BaseURL, + types.ModelTypeKnowledgeQA: MimoBaseURL, }, TranscriptionAPI: api.TranscriptionChatAudio, ModelTypes: []types.ModelType{ types.ModelTypeKnowledgeQA, types.ModelTypeASR, }, - Compat: catalog.VendorCompat{ + Compat: VendorCompat{ // ASR: mimo-v2.5-asr on the chat endpoint, WAV or MP3 as a base64 // data URI whose "encoded string size must not exceed 10 MB" // (https://mimo.mi.com/docs/en-US/quick-start/usage-guide/audio/Speech-Recognition). - Transcriptions: catalog.TranscriptionsCompat{ + Transcriptions: api.TranscriptionsCompat{ // The ceiling counts the whole data URI as sent. - MaxEncodedBytes: catalog.Ptr(10 << 20), + MaxEncodedBytes: api.Ptr(10 << 20), Formats: []string{"wav", "mp3"}, // asr_options.language: "auto|zh|en". - LanguageParam: catalog.Ptr(catalog.LanguageASROptions), + LanguageParam: api.Ptr(api.LanguageASROptions), }, - OpenAICompletions: catalog.OpenAICompletionsCompat{ - ThinkingFormat: catalog.Ptr(catalog.ThinkingFormatThinkingType), - PromptCacheAccounting: catalog.Ptr(true), + OpenAICompletions: api.OpenAICompletionsCompat{ + ThinkingFormat: api.Ptr(api.ThinkingFormatThinkingType), + PromptCacheAccounting: api.Ptr(true), // Only `auto` is honoured; everything else is stripped. ToolChoiceModes: []string{"auto"}, }, }, - Models: catalog.MustParseModels(modelsJSON), - }) + } } diff --git a/internal/models/vendors/minimax/vendor.go b/internal/models/providers/minimax.go similarity index 71% rename from internal/models/vendors/minimax/vendor.go rename to internal/models/providers/minimax.go index d5a6f156..15192c32 100644 --- a/internal/models/vendors/minimax/vendor.go +++ b/internal/models/providers/minimax.go @@ -1,4 +1,4 @@ -// Package minimax registers MiniMax's OpenAI-compatible chat endpoint. +// Package providers registers MiniMax's OpenAI-compatible chat endpoint. // // Facts (https://platform.minimax.io/docs/api-reference/text-openai-api): // - both `max_tokens` (legacy) and `max_completion_tokens` are accepted, @@ -20,7 +20,7 @@ // minimaxi.com, global keys to minimax.io). // // Second protocol: an Anthropic Messages facade lives at -// https://api.minimax.io/anthropic (mainland form in AnthropicBaseURL), and +// https://api.minimax.io/anthropic (mainland form in MinimaxAnthropicBaseURL), and // the vendor presents it first for thinking and tool workflows, documented at // https://platform.minimax.io/docs/api-reference/text-anthropic-api. // Resolve switches protocol when the base URL ends with /anthropic; this @@ -42,82 +42,77 @@ // carried over unconfirmed; // unverified: only the global https://api.minimax.io/anthropic form of the // Anthropic facade is spelled out in the docs; the mainland -// https://api.minimaxi.com/anthropic that AnthropicBaseURL holds is inferred +// https://api.minimaxi.com/anthropic that MinimaxAnthropicBaseURL holds is inferred // from the region split of the /v1 hosts. -package minimax +package providers import ( _ "embed" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" "github.com/Tencent/WeKnora/internal/types" ) -//go:embed models.json -var modelsJSON []byte +//go:embed assets/minimax.svg +var minimaxIcon []byte -//go:embed icon.svg -var icon []byte +// MinimaxID is the provider identifier stored on model rows. +const MinimaxID = "minimax" -// ID is the provider identifier stored on model rows. -const ID = "minimax" +// MinimaxBaseURL is the mainland-China OpenAI-compatible endpoint. +const MinimaxBaseURL = "https://api.minimaxi.com/v1" -// BaseURL is the mainland-China OpenAI-compatible endpoint. -const BaseURL = "https://api.minimaxi.com/v1" +// MinimaxGlobalBaseURL is the international endpoint. +const MinimaxGlobalBaseURL = "https://api.minimax.io/v1" -// GlobalBaseURL is the international endpoint. -const GlobalBaseURL = "https://api.minimax.io/v1" +// MinimaxAnthropicBaseURL is the Anthropic Messages compatibility facade. +const MinimaxAnthropicBaseURL = "https://api.minimaxi.com/anthropic" -// AnthropicBaseURL is the Anthropic Messages compatibility facade. -const AnthropicBaseURL = "https://api.minimaxi.com/anthropic" - -func init() { - catalog.Register(&catalog.Vendor{ - ID: ID, +func newMinimaxProvider() *Definition { + return &Definition{ + ID: MinimaxID, Name: "MiniMax", Names: map[string]string{"zh-CN": "MiniMax"}, Description: "MiniMax-M3, MiniMax-M2.7, MiniMax-M2.7-highspeed, etc. Global endpoint " + - GlobalBaseURL + "; Anthropic-compatible facade " + AnthropicBaseURL, + MinimaxGlobalBaseURL + "; Anthropic-compatible facade " + MinimaxAnthropicBaseURL, Descriptions: map[string]string{ "zh-CN": "MiniMax-M3, MiniMax-M2.7, MiniMax-M2.7-highspeed 等。国际版 " + - GlobalBaseURL + ";Anthropic 兼容接口 " + AnthropicBaseURL, + MinimaxGlobalBaseURL + ";Anthropic 兼容接口 " + MinimaxAnthropicBaseURL, }, Website: "https://platform.minimaxi.com", - Icon: icon, + Icon: minimaxIcon, API: api.APIOpenAICompletions, Order: 16, RequiresAuth: true, - Auth: catalog.AuthBearer, + Auth: AuthBearer, URLPatterns: []string{"minimax.io", "minimaxi.com"}, DefaultBaseURLs: map[types.ModelType]string{ - types.ModelTypeKnowledgeQA: BaseURL, + types.ModelTypeKnowledgeQA: MinimaxBaseURL, }, ModelTypes: []types.ModelType{ types.ModelTypeKnowledgeQA, types.ModelTypeASR, }, - Compat: catalog.VendorCompat{ - Transcriptions: catalog.TranscriptionsCompat{ + Compat: VendorCompat{ + Transcriptions: api.TranscriptionsCompat{ // https://platform.minimax.io/docs/api-reference/speech-to-text // (and the same page on platform.minimax.cn): multipart model // (asr-1.0) + file on /v1/speech_to_text rather than the OpenAI // path, answering {text, duration, trace_id} for the default // json. At most 50 MB and 500 seconds; "超出会返回 400 而不会被截断". - Path: catalog.Ptr("/speech_to_text"), - MaxFileBytes: catalog.Ptr(50 << 20), + Path: api.Ptr("/speech_to_text"), + MaxFileBytes: api.Ptr(50 << 20), // "wav / aiff / flac / alac(m4a) / mp3 / aac / opus / ogg"; // "不支持无容器的裸 PCM 数据". The language hint is a request // header, a BCP-47 tag, not a form field. Formats: []string{"wav", "aiff", "flac", "m4a", "mp3", "aac", "opus", "ogg"}, - LanguageParam: catalog.Ptr(catalog.LanguageHeader), + LanguageParam: api.Ptr(api.LanguageHeader), }, - OpenAICompletions: catalog.OpenAICompletionsCompat{ - ThinkingFormat: catalog.Ptr(catalog.ThinkingFormatThinkingType), - ThinkingEnabledValue: catalog.Ptr("adaptive"), - PromptCacheAccounting: catalog.Ptr(true), + OpenAICompletions: api.OpenAICompletionsCompat{ + ThinkingFormat: api.Ptr(api.ThinkingFormatThinkingType), + ThinkingEnabledValue: api.Ptr("adaptive"), + PromptCacheAccounting: api.Ptr(true), }, }, - Models: catalog.MustParseModels(modelsJSON), - }) + } } diff --git a/internal/models/vendors/modelscope/vendor.go b/internal/models/providers/modelscope.go similarity index 76% rename from internal/models/vendors/modelscope/vendor.go rename to internal/models/providers/modelscope.go index 2c863057..bd4aa52d 100644 --- a/internal/models/vendors/modelscope/vendor.go +++ b/internal/models/providers/modelscope.go @@ -1,4 +1,4 @@ -// Package modelscope registers ModelScope's API-Inference service. +// Package providers registers ModelScope's API-Inference service. // // Facts (https://modelscope.cn/docs/model-service/API-Inference/intro, // https://modelscope.cn/docs/model-service/API-Inference/limits): @@ -32,59 +32,54 @@ // served, such as Qwen/Qwen3.5-35B-A3B or ZhipuAI/GLM-5.2, do) — they are kept // because no official page states their retirement, but the list needs a // refresh against the model pages. -package modelscope +package providers import ( _ "embed" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" "github.com/Tencent/WeKnora/internal/types" ) -//go:embed models.json -var modelsJSON []byte +//go:embed assets/modelscope.svg +var modelscopeIcon []byte -//go:embed icon.svg -var icon []byte +// ModelscopeID is the provider identifier stored on model rows. +const ModelscopeID = "modelscope" -// ID is the provider identifier stored on model rows. -const ID = "modelscope" +// ModelscopeBaseURL is the OpenAI-compatible inference endpoint. +const ModelscopeBaseURL = "https://api-inference.modelscope.cn/v1" -// BaseURL is the OpenAI-compatible inference endpoint. -const BaseURL = "https://api-inference.modelscope.cn/v1" - -func init() { - catalog.Register(&catalog.Vendor{ - ID: ID, +func newModelscopeProvider() *Definition { + return &Definition{ + ID: ModelscopeID, Name: "ModelScope", Names: map[string]string{"zh-CN": "魔搭 ModelScope"}, Description: "Qwen/Qwen3-235B-A22B-Instruct-2507, ZhipuAI/GLM-4.6, Qwen/Qwen3-Embedding-8B, etc.", Website: "https://modelscope.cn", - Icon: icon, + Icon: modelscopeIcon, API: api.APIOpenAICompletions, Order: 19, RequiresAuth: true, - Auth: catalog.AuthBearer, + Auth: AuthBearer, URLPatterns: []string{"modelscope.cn"}, DefaultBaseURLs: map[types.ModelType]string{ - types.ModelTypeKnowledgeQA: BaseURL, - types.ModelTypeEmbedding: BaseURL, - types.ModelTypeVLLM: BaseURL, + types.ModelTypeKnowledgeQA: ModelscopeBaseURL, + types.ModelTypeEmbedding: ModelscopeBaseURL, + types.ModelTypeVLLM: ModelscopeBaseURL, }, ModelTypes: []types.ModelType{ types.ModelTypeKnowledgeQA, types.ModelTypeEmbedding, types.ModelTypeVLLM, }, - Compat: catalog.VendorCompat{ + Compat: VendorCompat{ // Embeddings keeps the bare baseline: /v1/embeddings answers, but no // ModelScope page documents a single parameter of it. - OpenAICompletions: catalog.OpenAICompletionsCompat{ - MaxTokensField: catalog.Ptr("max_tokens"), - ThinkingFormat: catalog.Ptr(catalog.ThinkingFormatEnableThinking), + OpenAICompletions: api.OpenAICompletionsCompat{ + MaxTokensField: api.Ptr("max_tokens"), + ThinkingFormat: api.Ptr(api.ThinkingFormatEnableThinking), }, }, - Models: catalog.MustParseModels(modelsJSON), - }) + } } diff --git a/internal/models/vendors/moonshot/vendor.go b/internal/models/providers/moonshot.go similarity index 80% rename from internal/models/vendors/moonshot/vendor.go rename to internal/models/providers/moonshot.go index 0a6539d5..936d72c8 100644 --- a/internal/models/vendors/moonshot/vendor.go +++ b/internal/models/providers/moonshot.go @@ -1,4 +1,4 @@ -// Package moonshot registers Moonshot AI (Kimi). +// Package providers registers Moonshot AI (Kimi). // // Facts (https://platform.kimi.com/docs/api/overview, // https://platform.kimi.com/docs/api/chat, @@ -41,58 +41,53 @@ // the protocol defaults are kept; the 262144 max output tokens of the K2.x // entries is not a documented cap (the docs only give a 32768 default); the // per-token costs are USD conversions of the CNY price list. -package moonshot +package providers import ( _ "embed" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" "github.com/Tencent/WeKnora/internal/types" ) -//go:embed models.json -var modelsJSON []byte +//go:embed assets/moonshot.svg +var moonshotIcon []byte -//go:embed icon.svg -var icon []byte +// MoonshotID is the provider identifier stored on model rows. +const MoonshotID = "moonshot" -// ID is the provider identifier stored on model rows. -const ID = "moonshot" +// MoonshotBaseURL is the global OpenAI-compatible endpoint. +const MoonshotBaseURL = "https://api.moonshot.ai/v1" -// BaseURL is the global OpenAI-compatible endpoint. -const BaseURL = "https://api.moonshot.ai/v1" - -func init() { - catalog.Register(&catalog.Vendor{ - ID: ID, +func newMoonshotProvider() *Definition { + return &Definition{ + ID: MoonshotID, Name: "Moonshot AI", Names: map[string]string{"zh-CN": "月之暗面 Moonshot"}, Description: "kimi-k3, kimi-k2.7-code, kimi-k2.7-code-highspeed, kimi-k2.6", Website: "https://platform.kimi.com", - Icon: icon, + Icon: moonshotIcon, API: api.APIOpenAICompletions, Order: 17, RequiresAuth: true, - Auth: catalog.AuthBearer, + Auth: AuthBearer, URLPatterns: []string{"moonshot.ai", "moonshot.cn"}, DefaultBaseURLs: map[types.ModelType]string{ - types.ModelTypeKnowledgeQA: BaseURL, - types.ModelTypeVLLM: BaseURL, + types.ModelTypeKnowledgeQA: MoonshotBaseURL, + types.ModelTypeVLLM: MoonshotBaseURL, }, ModelTypes: []types.ModelType{ types.ModelTypeKnowledgeQA, types.ModelTypeVLLM, }, - Compat: catalog.VendorCompat{ - OpenAICompletions: catalog.OpenAICompletionsCompat{ - ThinkingFormat: catalog.Ptr(catalog.ThinkingFormatThinkingType), - PromptCacheAccounting: catalog.Ptr(true), + Compat: VendorCompat{ + OpenAICompletions: api.OpenAICompletionsCompat{ + ThinkingFormat: api.Ptr(api.ThinkingFormatThinkingType), + PromptCacheAccounting: api.Ptr(true), // `required` is kimi-k3 only and a named function 400s while // thinking is on, which is the default on every model. ToolChoiceModes: []string{"none", "auto"}, }, }, - Models: catalog.MustParseModels(modelsJSON), - }) + } } diff --git a/internal/models/vendors/novita/vendor.go b/internal/models/providers/novita.go similarity index 72% rename from internal/models/vendors/novita/vendor.go rename to internal/models/providers/novita.go index 05f38477..119b34d9 100644 --- a/internal/models/vendors/novita/vendor.go +++ b/internal/models/providers/novita.go @@ -1,4 +1,4 @@ -// Package novita registers the Novita AI gateway. +// Package providers registers the Novita AI gateway. // // Facts (https://docs.novita.ai — novita.ai/docs/* redirects there): // - chat, embedding, VLM and rerank share https://api.novita.ai/openai/v1; @@ -27,46 +27,42 @@ // - the three embedding entries are served by the API but the embeddings // reference restricts `model` to a single enum value (baai/bge-m3), and // they are absent from the default /v1/models listing. -package novita +package providers import ( _ "embed" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" "github.com/Tencent/WeKnora/internal/types" ) -//go:embed models.json -var modelsJSON []byte +//go:embed assets/novita.svg +var novitaIcon []byte -//go:embed icon.svg -var icon []byte +// NovitaID is the provider identifier stored on model rows. +const NovitaID = "novita" -// ID is the provider identifier stored on model rows. -const ID = "novita" +// NovitaBaseURL is the OpenAI-compatible gateway endpoint. +const NovitaBaseURL = "https://api.novita.ai/openai/v1" -// BaseURL is the OpenAI-compatible gateway endpoint. -const BaseURL = "https://api.novita.ai/openai/v1" - -func init() { - catalog.Register(&catalog.Vendor{ - ID: ID, +func newNovitaProvider() *Definition { + return &Definition{ + ID: NovitaID, Name: "Novita AI", Names: map[string]string{"zh-CN": "Novita AI"}, Description: "moonshotai/kimi-k3, zai-org/glm-5.2, deepseek/deepseek-v4-pro, qwen/qwen3-embedding-0.6b, etc.", Website: "https://novita.ai", - Icon: icon, + Icon: novitaIcon, API: api.APIOpenAICompletions, Order: 52, RequiresAuth: true, - Auth: catalog.AuthBearer, + Auth: AuthBearer, URLPatterns: []string{"api.novita.ai", "novita.ai"}, DefaultBaseURLs: map[types.ModelType]string{ - types.ModelTypeKnowledgeQA: BaseURL, - types.ModelTypeEmbedding: BaseURL, - types.ModelTypeRerank: BaseURL, - types.ModelTypeVLLM: BaseURL, + types.ModelTypeKnowledgeQA: NovitaBaseURL, + types.ModelTypeEmbedding: NovitaBaseURL, + types.ModelTypeRerank: NovitaBaseURL, + types.ModelTypeVLLM: NovitaBaseURL, }, ModelTypes: []types.ModelType{ types.ModelTypeKnowledgeQA, @@ -74,17 +70,16 @@ func init() { types.ModelTypeRerank, types.ModelTypeVLLM, }, - Compat: catalog.VendorCompat{ - Embeddings: catalog.EmbeddingsCompat{ + Compat: VendorCompat{ + Embeddings: api.EmbeddingsCompat{ // https://novita.ai/docs/api-reference/model-apis-llm-create-embeddings: // input, model, encoding_format. Nothing else. - SendEncodingFormat: catalog.Ptr(true), + SendEncodingFormat: api.Ptr(true), }, - OpenAICompletions: catalog.OpenAICompletionsCompat{ - MaxTokensField: catalog.Ptr("max_tokens"), - ThinkingFormat: catalog.Ptr(catalog.ThinkingFormatEnableThinking), + OpenAICompletions: api.OpenAICompletionsCompat{ + MaxTokensField: api.Ptr("max_tokens"), + ThinkingFormat: api.Ptr(api.ThinkingFormatEnableThinking), }, }, - Models: catalog.MustParseModels(modelsJSON), - }) + } } diff --git a/internal/models/vendors/nvidia/vendor.go b/internal/models/providers/nvidia.go similarity index 78% rename from internal/models/vendors/nvidia/vendor.go rename to internal/models/providers/nvidia.go index e602adc8..c4bebe6f 100644 --- a/internal/models/vendors/nvidia/vendor.go +++ b/internal/models/providers/nvidia.go @@ -1,4 +1,4 @@ -// Package nvidia registers NVIDIA NIM's hosted API (build.nvidia.com). +// Package providers registers NVIDIA NIM's hosted API (build.nvidia.com). // // Facts (https://docs.api.nvidia.com/nim/ and the per-model cards on // https://build.nvidia.com): @@ -50,50 +50,46 @@ // "configurable low, high, or max reasoning effort", but none of its // samples show the parameter. The entry assumes the top-level // `reasoning_effort` its first-party API documents. -package nvidia +package providers import ( _ "embed" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" "github.com/Tencent/WeKnora/internal/types" ) -//go:embed models.json -var modelsJSON []byte +//go:embed assets/nvidia.svg +var nvidiaIcon []byte -//go:embed icon.svg -var icon []byte +// NvidiaID is the provider identifier stored on model rows. +const NvidiaID = "nvidia" -// ID is the provider identifier stored on model rows. -const ID = "nvidia" +// NvidiaBaseURL serves chat, embedding and VLM. +const NvidiaBaseURL = "https://integrate.api.nvidia.com/v1" -// BaseURL serves chat, embedding and VLM. -const BaseURL = "https://integrate.api.nvidia.com/v1" +// NvidiaRerankBaseURL is the retrieval reranking NIM. +const NvidiaRerankBaseURL = "https://ai.api.nvidia.com/v1/retrieval/nvidia/reranking" -// RerankBaseURL is the retrieval reranking NIM. -const RerankBaseURL = "https://ai.api.nvidia.com/v1/retrieval/nvidia/reranking" - -func init() { - catalog.Register(&catalog.Vendor{ - ID: ID, +func newNvidiaProvider() *Definition { + return &Definition{ + ID: NvidiaID, Name: "NVIDIA", Names: map[string]string{"zh-CN": "NVIDIA"}, Description: "nvidia/nemotron-3-ultra-550b-a55b, deepseek-ai/deepseek-v4-pro-0813, " + "nvidia/nemotron-3-embed-1b, nvidia/nv-rerankqa-mistral-4b-v3, etc.", Website: "https://build.nvidia.com", - Icon: icon, + Icon: nvidiaIcon, API: api.APIOpenAICompletions, Order: 51, RequiresAuth: true, - Auth: catalog.AuthBearer, + Auth: AuthBearer, URLPatterns: []string{"nvidia.com"}, DefaultBaseURLs: map[types.ModelType]string{ - types.ModelTypeKnowledgeQA: BaseURL, - types.ModelTypeEmbedding: BaseURL, - types.ModelTypeRerank: RerankBaseURL, - types.ModelTypeVLLM: BaseURL, + types.ModelTypeKnowledgeQA: NvidiaBaseURL, + types.ModelTypeEmbedding: NvidiaBaseURL, + types.ModelTypeRerank: NvidiaRerankBaseURL, + types.ModelTypeVLLM: NvidiaBaseURL, }, ModelTypes: []types.ModelType{ types.ModelTypeKnowledgeQA, @@ -102,8 +98,8 @@ func init() { types.ModelTypeVLLM, }, RerankAPI: api.RerankNIM, - Compat: catalog.VendorCompat{ - Embeddings: catalog.EmbeddingsCompat{ + Compat: VendorCompat{ + Embeddings: api.EmbeddingsCompat{ // https://docs.api.nvidia.com/nim/reference/nvidia-nemotron-3-embed-1b-infer: // input, model, input_type (passage | query), encoding_format, // truncate (NONE | START | END, default NONE), user. There is no @@ -113,28 +109,27 @@ func init() { // insists they must. This is the hosted API: a self-hosted NIM // (https://docs.nvidia.com/nim/nemo-retriever/embedding/latest/reference.html) // does take dimensions, and belongs on a generic row pointed at it. - SendEncodingFormat: catalog.Ptr(true), - InputTypeField: catalog.Ptr("input_type"), + SendEncodingFormat: api.Ptr(true), + InputTypeField: api.Ptr("input_type"), InputTypeValues: map[string]string{"document": "passage", "query": "query"}, // NONE fails the request on an over-long input instead of // cutting it. - TruncateField: catalog.Ptr("truncate"), - TruncateValue: catalog.Ptr("END"), + TruncateField: api.Ptr("truncate"), + TruncateValue: api.Ptr("END"), }, - Rerank: catalog.RerankCompat{ + Rerank: api.RerankCompat{ // rankings[].logit is unbounded and routinely negative, so the // caller must be told this is not a 0..1 relevance score. - ScoreScale: catalog.Ptr(api.ScoreLogit), + ScoreScale: api.Ptr(api.ScoreLogit), // truncate defaults to NONE upstream, which fails the request on // an over-long passage instead of cutting it. - Truncate: catalog.Ptr("END"), - MaxDocuments: catalog.Ptr(512), + Truncate: api.Ptr("END"), + MaxDocuments: api.Ptr(512), }, - OpenAICompletions: catalog.OpenAICompletionsCompat{ - MaxTokensField: catalog.Ptr("max_tokens"), - ThinkingFormat: catalog.Ptr(catalog.ThinkingFormatChatTemplateKwargs), + OpenAICompletions: api.OpenAICompletionsCompat{ + MaxTokensField: api.Ptr("max_tokens"), + ThinkingFormat: api.Ptr(api.ThinkingFormatChatTemplateKwargs), }, }, - Models: catalog.MustParseModels(modelsJSON), - }) + } } diff --git a/internal/models/vendors/openai/vendor.go b/internal/models/providers/openai.go similarity index 76% rename from internal/models/vendors/openai/vendor.go rename to internal/models/providers/openai.go index f9191b9b..8474bcc0 100644 --- a/internal/models/vendors/openai/vendor.go +++ b/internal/models/providers/openai.go @@ -1,4 +1,4 @@ -// Package openai registers OpenAI's first-party platform. +// Package providers registers OpenAI's first-party platform. // // Facts (https://developers.openai.com/api/docs — platform.openai.com/docs // now redirects there): @@ -45,48 +45,45 @@ // against the entry's own API, and these entries are Chat Completions // entries. GPT-5.6 and later replaced `prompt_cache_retention` with // `prompt_cache_options.ttl`, which the protocol layer does not send yet. -package openai +package providers import ( _ "embed" "net/url" "strings" + "github.com/Tencent/WeKnora/internal/models" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" "github.com/Tencent/WeKnora/internal/types" ) -//go:embed models.json -var modelsJSON []byte +//go:embed assets/openai.svg +var openaiIcon []byte -//go:embed icon.svg -var icon []byte +// OpenaiID is the provider identifier stored on model rows. +const OpenaiID = "openai" -// ID is the provider identifier stored on model rows. -const ID = "openai" +// OpenaiBaseURL is the documented first-party endpoint. +const OpenaiBaseURL = "https://api.openai.com/v1" -// BaseURL is the documented first-party endpoint. -const BaseURL = "https://api.openai.com/v1" - -func init() { - catalog.Register(&catalog.Vendor{ - ID: ID, +func newOpenaiProvider() *Definition { + return &Definition{ + ID: OpenaiID, Name: "OpenAI", Names: map[string]string{"zh-CN": "OpenAI"}, Description: "gpt-6-astra, gpt-5.6-sol, gpt-5.5, gpt-4.1, text-embedding-3-large, etc.", Website: "https://developers.openai.com", - Icon: icon, + Icon: openaiIcon, API: api.APIOpenAICompletions, Order: 30, RequiresAuth: true, - Auth: catalog.AuthBearer, + Auth: AuthBearer, URLPatterns: []string{"api.openai.com"}, DefaultBaseURLs: map[types.ModelType]string{ - types.ModelTypeKnowledgeQA: BaseURL, - types.ModelTypeEmbedding: BaseURL, - types.ModelTypeVLLM: BaseURL, - types.ModelTypeASR: BaseURL, + types.ModelTypeKnowledgeQA: OpenaiBaseURL, + types.ModelTypeEmbedding: OpenaiBaseURL, + types.ModelTypeVLLM: OpenaiBaseURL, + types.ModelTypeASR: OpenaiBaseURL, }, // No rerank: OpenAI's API has no rerank endpoint — the reference // index (https://developers.openai.com/api/llms.txt) does not mention @@ -98,47 +95,47 @@ func init() { types.ModelTypeVLLM, types.ModelTypeASR, }, - Compat: catalog.VendorCompat{ - Transcriptions: catalog.TranscriptionsCompat{ + Compat: VendorCompat{ + Transcriptions: api.TranscriptionsCompat{ // The transcription reference (URL in openaitranscriptions): // response_format differs per model — "For gpt-4o-transcribe // and gpt-4o-mini-transcribe, the only supported format is // json", the default — so it is declared per entry, not here. // "Files can be up to 25 MB" // (https://developers.openai.com/api/docs/guides/speech-to-text). - MaxFileBytes: catalog.Ptr(25 << 20), + MaxFileBytes: api.Ptr(25 << 20), // "flac, mp3, mp4, mpeg, mpga, m4a, ogg, wav, or webm", and a // language field in ISO-639-1. Formats: []string{"flac", "mp3", "mp4", "mpeg", "mpga", "m4a", "ogg", "wav", "webm"}, - LanguageParam: catalog.Ptr(catalog.LanguageForm), + LanguageParam: api.Ptr(api.LanguageForm), }, - Embeddings: catalog.EmbeddingsCompat{ + Embeddings: api.EmbeddingsCompat{ // https://developers.openai.com/api/reference/resources/embeddings/methods/create: // model, input, dimensions (text-embedding-3 and later; the ada-002 // entry turns it off), encoding_format, user. An input array // "must be 2048 dimensions or less" — elements, despite the word. - SendEncodingFormat: catalog.Ptr(true), - DimensionsField: catalog.Ptr("dimensions"), - MaxBatchSize: catalog.Ptr(2048), + SendEncodingFormat: api.Ptr(true), + DimensionsField: api.Ptr("dimensions"), + MaxBatchSize: api.Ptr(2048), }, - OpenAICompletions: catalog.OpenAICompletionsCompat{ - ThinkingFormat: catalog.Ptr(catalog.ThinkingFormatOpenAI), - SupportsReasoningEffort: catalog.Ptr(true), - SupportsDeveloperRole: catalog.Ptr(true), - SupportsStore: catalog.Ptr(true), - PromptCacheKey: catalog.Ptr(true), - PromptCacheAccounting: catalog.Ptr(true), + OpenAICompletions: api.OpenAICompletionsCompat{ + ThinkingFormat: api.Ptr(api.ThinkingFormatOpenAI), + SupportsReasoningEffort: api.Ptr(true), + SupportsDeveloperRole: api.Ptr(true), + SupportsStore: api.Ptr(true), + PromptCacheKey: api.Ptr(true), + PromptCacheAccounting: api.Ptr(true), }, }, - Models: catalog.MustParseModels(modelsJSON), - PreferAPI: preferResponsesOnFirstParty, - }) + + PreferAPI: OpenaiPreferResponsesOnFirstParty, + } } -// preferResponsesOnFirstParty switches chat traffic aimed at api.openai.com +// OpenaiPreferResponsesOnFirstParty switches chat traffic aimed at api.openai.com // to the Responses protocol. Anything else (Azure-style relays, LiteLLM, // enterprise gateways) keeps Chat Completions, the protocol they document. -func preferResponsesOnFirstParty(baseURL string, spec catalog.ModelSpec) api.API { +func OpenaiPreferResponsesOnFirstParty(baseURL string, spec models.ModelSpec) api.API { if spec.Type != "" && spec.Type != types.ModelTypeKnowledgeQA { return "" } diff --git a/internal/models/vendors/openrouter/vendor.go b/internal/models/providers/openrouter.go similarity index 73% rename from internal/models/vendors/openrouter/vendor.go rename to internal/models/providers/openrouter.go index 38d62c26..a3addf3f 100644 --- a/internal/models/vendors/openrouter/vendor.go +++ b/internal/models/providers/openrouter.go @@ -1,4 +1,4 @@ -// Package openrouter registers the OpenRouter gateway. +// Package providers registers the OpenRouter gateway. // // Facts (https://openrouter.ai/docs/guides/best-practices/reasoning-tokens — // the old /docs/use-cases/ path now redirects there): @@ -28,47 +28,43 @@ // Unverified: GET /api/v1/models lists chat models only — embedding models // live behind /api/v1/embeddings/models — so any future auto-sync of this // catalog has to read both listings or it will silently lose embeddings. -package openrouter +package providers import ( _ "embed" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" "github.com/Tencent/WeKnora/internal/types" ) -//go:embed models.json -var modelsJSON []byte +//go:embed assets/openrouter.svg +var openrouterIcon []byte -//go:embed icon.svg -var icon []byte +// OpenrouterID is the provider identifier stored on model rows. +const OpenrouterID = "openrouter" -// ID is the provider identifier stored on model rows. -const ID = "openrouter" +// OpenrouterBaseURL is the OpenAI-compatible gateway endpoint. +const OpenrouterBaseURL = "https://openrouter.ai/api/v1" -// BaseURL is the OpenAI-compatible gateway endpoint. -const BaseURL = "https://openrouter.ai/api/v1" - -func init() { - catalog.Register(&catalog.Vendor{ - ID: ID, +func newOpenrouterProvider() *Definition { + return &Definition{ + ID: OpenrouterID, Name: "OpenRouter", Names: map[string]string{"zh-CN": "OpenRouter"}, Description: "openai/gpt-5.5, anthropic/claude-opus-5, google/gemini-3.8-flash, " + "deepseek/deepseek-v4-pro, etc.", Website: "https://openrouter.ai", - Icon: icon, + Icon: openrouterIcon, API: api.APIOpenAICompletions, Order: 40, RequiresAuth: true, - Auth: catalog.AuthBearer, + Auth: AuthBearer, URLPatterns: []string{"openrouter.ai"}, DefaultBaseURLs: map[types.ModelType]string{ - types.ModelTypeKnowledgeQA: BaseURL, - types.ModelTypeEmbedding: BaseURL, - types.ModelTypeRerank: BaseURL, - types.ModelTypeVLLM: BaseURL, + types.ModelTypeKnowledgeQA: OpenrouterBaseURL, + types.ModelTypeEmbedding: OpenrouterBaseURL, + types.ModelTypeRerank: OpenrouterBaseURL, + types.ModelTypeVLLM: OpenrouterBaseURL, }, ModelTypes: []types.ModelType{ types.ModelTypeKnowledgeQA, @@ -77,17 +73,17 @@ func init() { types.ModelTypeVLLM, types.ModelTypeASR, }, - Compat: catalog.VendorCompat{ - Transcriptions: catalog.TranscriptionsCompat{ + Compat: VendorCompat{ + Transcriptions: api.TranscriptionsCompat{ // https://openrouter.ai/docs/api/api-reference/stt/create-transcription: // OpenAI-style multipart file + model, json by default. "Max 25 // MB; send larger files as base64 JSON via input_audio." - MaxFileBytes: catalog.Ptr(25 << 20), + MaxFileBytes: api.Ptr(25 << 20), // language is an ISO-639-1 form field. The format "is derived // from the filename extension", with no closed list. - LanguageParam: catalog.Ptr(catalog.LanguageForm), + LanguageParam: api.Ptr(api.LanguageForm), }, - Embeddings: catalog.EmbeddingsCompat{ + Embeddings: api.EmbeddingsCompat{ // https://openrouter.ai/docs/api/api-reference/embeddings/create-embeddings: // model, input, dimensions, encoding_format, input_type, provider, // user. input_type is a free-form string handed to whichever @@ -96,14 +92,14 @@ func init() { // an asymmetric model it changes the document vectors. Not // declared, for the reason Jina's task is not // (Tencent/WeKnora#1401). - SendEncodingFormat: catalog.Ptr(true), - DimensionsField: catalog.Ptr("dimensions"), + SendEncodingFormat: api.Ptr(true), + DimensionsField: api.Ptr("dimensions"), }, - OpenAICompletions: catalog.OpenAICompletionsCompat{ - ThinkingFormat: catalog.Ptr(catalog.ThinkingFormatOpenRouter), - SupportsReasoningEffort: catalog.Ptr(true), - PromptCacheKey: catalog.Ptr(true), - PromptCacheAccounting: catalog.Ptr(true), + OpenAICompletions: api.OpenAICompletionsCompat{ + ThinkingFormat: api.Ptr(api.ThinkingFormatOpenRouter), + SupportsReasoningEffort: api.Ptr(true), + PromptCacheKey: api.Ptr(true), + PromptCacheAccounting: api.Ptr(true), }, }, // The reasoning.effort enum covers the whole ladder; per-model @@ -112,6 +108,5 @@ func init() { api.ReasoningXHigh: api.StringPtr("xhigh"), api.ReasoningMax: api.StringPtr("max"), }, - Models: catalog.MustParseModels(modelsJSON), - }) + } } diff --git a/internal/models/vendors/vendors_test.go b/internal/models/providers/providers_test.go similarity index 87% rename from internal/models/vendors/vendors_test.go rename to internal/models/providers/providers_test.go index f3ebb50f..465c1c56 100644 --- a/internal/models/vendors/vendors_test.go +++ b/internal/models/providers/providers_test.go @@ -1,12 +1,14 @@ -package vendors +package providers_test import ( "bytes" "strings" "testing" + "github.com/Tencent/WeKnora/internal/models" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" + "github.com/Tencent/WeKnora/internal/models/providers" + modelruntime "github.com/Tencent/WeKnora/internal/models/runtime" "github.com/Tencent/WeKnora/internal/types" ) @@ -25,7 +27,7 @@ func TestAllVendorsRegistered(t *testing.T) { t.Fatalf("expected 27 vendor ids in the spec, got %d", len(expectedIDs)) } for _, id := range expectedIDs { - v, ok := catalog.Get(id) + v, ok := modelruntime.Get(id) if !ok { t.Errorf("vendor %q is not registered", id) continue @@ -45,7 +47,7 @@ func TestAllVendorsRegistered(t *testing.T) { if v.RequiresAuth && v.Auth == "" { t.Errorf("vendor %q: RequiresAuth without Auth style", id) } - if v.Auth == catalog.AuthSigned && v.Signer == nil { + if v.Auth == providers.AuthSigned && v.Signer == nil { t.Errorf("vendor %q: AuthSigned without Signer", id) } if !v.API.Known() { @@ -55,7 +57,7 @@ func TestAllVendorsRegistered(t *testing.T) { t.Errorf("vendor %q: no ModelTypes", id) } } - for _, v := range catalog.List() { + for _, v := range modelruntime.List() { found := false for _, id := range expectedIDs { if id == v.ID { @@ -71,11 +73,11 @@ func TestAllVendorsRegistered(t *testing.T) { func TestEveryCatalogEntryResolves(t *testing.T) { for _, id := range expectedIDs { - v, ok := catalog.Get(id) + v, ok := modelruntime.Get(id) if !ok { t.Fatalf("vendor %q missing", id) } - for _, m := range v.Models { + for _, m := range v.Models() { if m.ID == "" && m.Match == "" { t.Errorf("%s: model entry %q has neither id nor match", id, m.Name) continue @@ -89,7 +91,7 @@ func TestEveryCatalogEntryResolves(t *testing.T) { if modelType == "" { modelType = types.ModelTypeKnowledgeQA } - r, err := catalog.Resolve(catalog.Ref{Provider: v.ID, Model: name, ModelType: modelType}) + r, err := modelruntime.Resolve(modelruntime.Ref{Provider: v.ID, Model: name, ModelType: modelType}) // An entry may declare that this build cannot serve it — a vendor // whose second rerank dialect has no protocol package. Refusing is // the point: the alternative is a request shaped for the wrong @@ -139,7 +141,7 @@ func TestNamesInsideChatGlobsResolveForOtherTypes(t *testing.T) { } for _, n := range names { for _, modelType := range []types.ModelType{types.ModelTypeEmbedding, types.ModelTypeRerank} { - r, err := catalog.Resolve(catalog.Ref{Provider: n.provider, Model: n.model, ModelType: modelType}) + r, err := modelruntime.Resolve(modelruntime.Ref{Provider: n.provider, Model: n.model, ModelType: modelType}) if err != nil { t.Errorf("%s/%s as %s: %v", n.provider, n.model, modelType, err) continue @@ -154,7 +156,7 @@ func TestNamesInsideChatGlobsResolveForOtherTypes(t *testing.T) { func TestDetectByURLRoundTrip(t *testing.T) { for _, id := range expectedIDs { - v, _ := catalog.Get(id) + v, _ := modelruntime.Get(id) if len(v.URLPatterns) == 0 { continue } @@ -162,19 +164,19 @@ func TestDetectByURLRoundTrip(t *testing.T) { if !strings.HasPrefix(u, "https://") || strings.Contains(u, "{") { continue // placeholder or http-only self-hosted default } - if got := catalog.DetectByURL(u); got != v.ID { + if got := modelruntime.DetectByURL(u); got != v.ID { t.Errorf("DetectByURL(%q) = %q, want %q", u, got, v.ID) } } - if got := catalog.DetectByURL("http://your_litellm_proxy/v1"); got != "litellm" { + if got := modelruntime.DetectByURL("http://your_litellm_proxy/v1"); got != "litellm" { t.Errorf("litellm placeholder detected as %q", got) } // GPUStack 2.x serves the OpenAI-compatible surface at /v1; the 0.x // /v1-openai path must keep resolving for rows saved before the move. - if got := catalog.DetectByURL("http://your_gpustack_server_url/v1-openai"); got != "gpustack" { + if got := modelruntime.DetectByURL("http://your_gpustack_server_url/v1-openai"); got != "gpustack" { t.Errorf("gpustack placeholder detected as %q", got) } - if got := catalog.DetectByURL("https://api.moonshot.cn/v1"); got != "moonshot" { + if got := modelruntime.DetectByURL("https://api.moonshot.cn/v1"); got != "moonshot" { t.Errorf("moonshot.cn detected as %q", got) } } @@ -194,7 +196,7 @@ func TestOpenAIProtocolSelection(t *testing.T) { {"https://api.openai.com/v1", map[string]string{"api": "openai-completions"}, api.APIOpenAICompletions}, } for _, tc := range cases { - r, err := catalog.Resolve(catalog.Ref{ + r, err := modelruntime.Resolve(modelruntime.Ref{ Provider: "openai", Model: "gpt-5.5", BaseURL: tc.baseURL, Extra: tc.extra, }) if err != nil { @@ -206,9 +208,9 @@ func TestOpenAIProtocolSelection(t *testing.T) { } } -func resolve(t *testing.T, provider, model string) *catalog.Resolved { +func resolve(t *testing.T, provider, model string) *modelruntime.Resolved { t.Helper() - r, err := catalog.Resolve(catalog.Ref{Provider: provider, Model: model}) + r, err := modelruntime.Resolve(modelruntime.Ref{Provider: provider, Model: model}) if err != nil { t.Fatalf("resolve %s/%s: %v", provider, model, err) } @@ -278,15 +280,15 @@ func TestFamilyExpectations(t *testing.T) { if r := resolve(t, "gemini", "gemini-2.5-flash"); r.API != api.APIGoogleGenerativeAI { t.Errorf("gemini/gemini-2.5-flash API = %q", r.API) } - if r := resolve(t, "gemini", "gemini-3.8-flash"); r.GoogleGenerativeAI.ThinkingMode != catalog.GoogleThinkingLevel { + if r := resolve(t, "gemini", "gemini-3.8-flash"); r.GoogleGenerativeAI.ThinkingMode != api.GoogleThinkingLevel { t.Errorf("gemini/gemini-3.8-flash thinking mode = %q", r.GoogleGenerativeAI.ThinkingMode) } if r := resolve(t, "anthropic", "claude-opus-5"); r.AnthropicMessages.ThinkingMode != - catalog.AnthropicThinkingAdaptive || !r.AnthropicMessages.SupportsEffort { + api.AnthropicThinkingAdaptive || !r.AnthropicMessages.SupportsEffort { t.Error("anthropic/claude-opus-5 should use adaptive thinking with effort") } if r := resolve(t, "anthropic", "claude-sonnet-4-5"); r.AnthropicMessages.ThinkingMode != - catalog.AnthropicThinkingBudget { + api.AnthropicThinkingBudget { t.Error("anthropic/claude-sonnet-4-5 should keep budget thinking") } if r := resolve(t, "anthropic", "claude-sonnet-4-5-20250929"); !r.Cataloged { @@ -329,13 +331,13 @@ func TestFamilyExpectations(t *testing.T) { // default (chat_template_kwargs) would silently drop the level. for _, model := range []string{"z-ai/glm-5.3", "moonshotai/kimi-k3"} { r := resolve(t, "nvidia", model) - if r.OpenAICompletions.ThinkingFormat != catalog.ThinkingFormatOpenAI || + if r.OpenAICompletions.ThinkingFormat != api.ThinkingFormatOpenAI || !r.OpenAICompletions.SupportsReasoningEffort { t.Errorf("nvidia/%s should grade with a top-level reasoning_effort", model) } } if r := resolve(t, "nvidia", "nvidia/nemotron-3-ultra-550b-a55b"); r.OpenAICompletions.ThinkingFormat != - catalog.ThinkingFormatChatTemplateKwargs { + api.ThinkingFormatChatTemplateKwargs { t.Error("nvidia nemotron should keep the chat-template switch") } // DashScope errors when qwen3.8-max gets both fields. @@ -350,12 +352,12 @@ func TestFamilyExpectations(t *testing.T) { } func TestHooks(t *testing.T) { - azure, _ := catalog.Get("azure_openai") - u, q := azure.Endpoint(catalog.EndpointRequest{ + azure, _ := modelruntime.Get("azure_openai") + u, q := azure.Endpoint(providers.EndpointRequest{ BaseURL: "https://my-res.openai.azure.com/", Model: "gpt-4o deploy", ModelType: types.ModelTypeKnowledgeQA, - Extra: map[string]string{catalog.ExtraAPIVersion: "2025-01-01-preview"}, + Extra: map[string]string{models.ExtraAPIVersion: "2025-01-01-preview"}, }) if u != "https://my-res.openai.azure.com/openai/deployments/gpt-4o%20deploy/chat/completions" { t.Errorf("azure endpoint = %q", u) @@ -366,20 +368,20 @@ func TestHooks(t *testing.T) { // Without an explicit api_version the hook emits the v1 GA data plane, // which carries the deployment name in the body and takes no // api-version at all. - u, q = azure.Endpoint(catalog.EndpointRequest{BaseURL: "https://x.openai.azure.com", Model: "d"}) + u, q = azure.Endpoint(providers.EndpointRequest{BaseURL: "https://x.openai.azure.com", Model: "d"}) if u != "https://x.openai.azure.com/openai/v1/chat/completions" { t.Errorf("azure v1 endpoint = %q", u) } if len(q) != 0 { t.Errorf("azure v1 query = %v, want none", q) } - if azure.Auth != catalog.AuthAPIKeyHeader { + if azure.Auth != providers.AuthAPIKeyHeader { t.Errorf("azure auth = %q", azure.Auth) } // Embedding obeys the same rule as chat for the same stored row, so one // Azure resource never ends up serving chat on v1 and embedding on the // dated deployments path. internal/models/embedding calls this hook. - u, q = azure.Endpoint(catalog.EndpointRequest{ + u, q = azure.Endpoint(providers.EndpointRequest{ BaseURL: "https://x.openai.azure.com", Model: "embed-deploy", ModelType: types.ModelTypeEmbedding, }) @@ -389,10 +391,10 @@ func TestHooks(t *testing.T) { if len(q) != 0 { t.Errorf("azure v1 embedding query = %v, want none", q) } - u, q = azure.Endpoint(catalog.EndpointRequest{ + u, q = azure.Endpoint(providers.EndpointRequest{ BaseURL: "https://x.openai.azure.com", Model: "embed-deploy", ModelType: types.ModelTypeEmbedding, - Extra: map[string]string{catalog.ExtraAPIVersion: "2024-10-21"}, + Extra: map[string]string{models.ExtraAPIVersion: "2024-10-21"}, }) if u != "https://x.openai.azure.com/openai/deployments/embed-deploy/embeddings" { t.Errorf("azure legacy embedding endpoint = %q", u) @@ -401,34 +403,34 @@ func TestHooks(t *testing.T) { t.Errorf("azure legacy embedding api-version = %q", q["api-version"]) } - wk, _ := catalog.Get("weknoracloud") - u, _ = wk.Endpoint(catalog.EndpointRequest{ + wk, _ := modelruntime.Get("weknoracloud") + u, _ = wk.Endpoint(providers.EndpointRequest{ BaseURL: "https://weknora.weixin.qq.com/", ModelType: types.ModelTypeKnowledgeQA, }) if u != "https://weknora.weixin.qq.com/api/v1/chat/completions" { t.Errorf("weknoracloud endpoint = %q", u) } - if wk.Auth != catalog.AuthSigned || wk.Signer == nil { + if wk.Auth != providers.AuthSigned || wk.Signer == nil { t.Error("weknoracloud should use a signer") } - if err := wk.ValidateConfig(&catalog.Config{}); err != nil { + if err := wk.ValidateConfig(&providers.Config{}); err != nil { t.Errorf("weknoracloud validate should pass without key: %v", err) } - generic, _ := catalog.Get("generic") - if err := generic.ValidateConfig(&catalog.Config{ModelName: "m"}); err == nil { + generic, _ := modelruntime.Get("generic") + if err := generic.ValidateConfig(&providers.Config{ModelName: "m"}); err == nil { t.Error("generic validate should require a base URL") } - if err := generic.ValidateConfig(&catalog.Config{BaseURL: "http://x/v1", ModelName: "m"}); err != nil { + if err := generic.ValidateConfig(&providers.Config{BaseURL: "http://x/v1", ModelName: "m"}); err != nil { t.Errorf("generic validate: %v", err) } - gpustack, _ := catalog.Get("gpustack") - if err := gpustack.ValidateConfig(&catalog.Config{APIKey: "k", ModelName: "m"}); err == nil { + gpustack, _ := modelruntime.Get("gpustack") + if err := gpustack.ValidateConfig(&providers.Config{APIKey: "k", ModelName: "m"}); err == nil { t.Error("gpustack validate should require a base URL") } for _, id := range []string{"volcengine", "lkeap"} { - v, _ := catalog.Get(id) + v, _ := modelruntime.Get(id) found := false for _, f := range v.ExtraFields { if f.Key == "secret_key" { @@ -454,7 +456,7 @@ func TestSignedRerankCredentialLabels(t *testing.T) { {"volcengine", "Access Key ID"}, } { t.Run(tc.vendor, func(t *testing.T) { - v, ok := catalog.Get(tc.vendor) + v, ok := modelruntime.Get(tc.vendor) if !ok { t.Fatalf("vendor %s is not registered", tc.vendor) } diff --git a/internal/models/vendors/qianfan/vendor.go b/internal/models/providers/qianfan.go similarity index 76% rename from internal/models/vendors/qianfan/vendor.go rename to internal/models/providers/qianfan.go index 0e0aad57..1d1a5237 100644 --- a/internal/models/vendors/qianfan/vendor.go +++ b/internal/models/providers/qianfan.go @@ -1,4 +1,4 @@ -// Package qianfan registers Baidu AI Cloud Qianfan through its +// Package providers registers Baidu AI Cloud Qianfan through its // OpenAI-compatible v2 endpoint. // // Facts (v2 text generation reference @@ -53,46 +53,42 @@ // - Qianfan also exposes a Responses API // (https://cloud.baidu.com/doc/qianfan-docs/s/4mi400l1m); this vendor // stays on Chat Completions, which is what the model pages document. -package qianfan +package providers import ( _ "embed" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" "github.com/Tencent/WeKnora/internal/types" ) -//go:embed models.json -var modelsJSON []byte +//go:embed assets/qianfan.svg +var qianfanIcon []byte -//go:embed icon.svg -var icon []byte +// QianfanID is the provider identifier stored on model rows. +const QianfanID = "qianfan" -// ID is the provider identifier stored on model rows. -const ID = "qianfan" +// QianfanBaseURL is the OpenAI-compatible v2 endpoint for every model type. +const QianfanBaseURL = "https://qianfan.baidubce.com/v2" -// BaseURL is the OpenAI-compatible v2 endpoint for every model type. -const BaseURL = "https://qianfan.baidubce.com/v2" - -func init() { - catalog.Register(&catalog.Vendor{ - ID: ID, +func newQianfanProvider() *Definition { + return &Definition{ + ID: QianfanID, Name: "Baidu Qianfan", Names: map[string]string{"zh-CN": "百度千帆 Baidu Cloud"}, Description: "ernie-5.0-thinking-preview, ernie-4.5-turbo-128k, embedding-v1, bce-reranker-base, etc.", Website: "https://console.bce.baidu.com/qianfan", - Icon: icon, + Icon: qianfanIcon, API: api.APIOpenAICompletions, Order: 20, RequiresAuth: true, - Auth: catalog.AuthBearer, + Auth: AuthBearer, URLPatterns: []string{"qianfan.baidubce.com", "baidubce.com"}, DefaultBaseURLs: map[types.ModelType]string{ - types.ModelTypeKnowledgeQA: BaseURL, - types.ModelTypeEmbedding: BaseURL, - types.ModelTypeRerank: BaseURL, - types.ModelTypeVLLM: BaseURL, + types.ModelTypeKnowledgeQA: QianfanBaseURL, + types.ModelTypeEmbedding: QianfanBaseURL, + types.ModelTypeRerank: QianfanBaseURL, + types.ModelTypeVLLM: QianfanBaseURL, }, ModelTypes: []types.ModelType{ types.ModelTypeKnowledgeQA, @@ -100,31 +96,30 @@ func init() { types.ModelTypeRerank, types.ModelTypeVLLM, }, - Compat: catalog.VendorCompat{ - Embeddings: catalog.EmbeddingsCompat{ + Compat: VendorCompat{ + Embeddings: api.EmbeddingsCompat{ // https://cloud.baidu.com/doc/qianfan-api/s/Fm7u3ropn: model, // input, user, encoding_format ("当前只支持float"). The model list // (https://cloud.baidu.com/doc/qianfan/s/rmh4stp0j) caps a request // at 16 texts; tao-8k takes one. - SendEncodingFormat: catalog.Ptr(true), - MaxBatchSize: catalog.Ptr(16), + SendEncodingFormat: api.Ptr(true), + MaxBatchSize: api.Ptr(16), }, - Rerank: catalog.RerankCompat{ + Rerank: api.RerankCompat{ // "文本数量不超过64"; query "长度不超过1600个字符"; each document // "长度不超过4096个字符". - MaxDocuments: catalog.Ptr(64), - MaxQueryChars: catalog.Ptr(1600), - MaxDocumentChars: catalog.Ptr(4096), + MaxDocuments: api.Ptr(64), + MaxQueryChars: api.Ptr(1600), + MaxDocumentChars: api.Ptr(4096), }, - OpenAICompletions: catalog.OpenAICompletionsCompat{ + OpenAICompletions: api.OpenAICompletionsCompat{ // Both spellings are accepted; max_completion_tokens is the // one that also covers the thinking chain. - MaxTokensField: catalog.Ptr("max_completion_tokens"), - ThinkingFormat: catalog.Ptr(catalog.ThinkingFormatEnableThinking), - ThinkingBudgetField: catalog.Ptr("thinking_budget"), - PromptCacheAccounting: catalog.Ptr(true), + MaxTokensField: api.Ptr("max_completion_tokens"), + ThinkingFormat: api.Ptr(api.ThinkingFormatEnableThinking), + ThinkingBudgetField: api.Ptr("thinking_budget"), + PromptCacheAccounting: api.Ptr(true), }, }, - Models: catalog.MustParseModels(modelsJSON), - }) + } } diff --git a/internal/models/vendors/qiniu/vendor.go b/internal/models/providers/qiniu.go similarity index 80% rename from internal/models/vendors/qiniu/vendor.go rename to internal/models/providers/qiniu.go index 98fd5dbe..4674736c 100644 --- a/internal/models/vendors/qiniu/vendor.go +++ b/internal/models/providers/qiniu.go @@ -1,4 +1,4 @@ -// Package qiniu registers Qiniu Cloud's AI token gateway. +// Package providers registers Qiniu Cloud's AI token gateway. // // Facts (parameter reference // https://developer.qiniu.com/aitokenapi/13390/chat-completions, endpoint @@ -49,55 +49,50 @@ // returned only a subset of the ids below. No retirement notice was found // for any of them, so every entry is kept; models.dev lists no prices for // this gateway, so cost is omitted. -package qiniu +package providers import ( _ "embed" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" "github.com/Tencent/WeKnora/internal/types" ) -//go:embed models.json -var modelsJSON []byte +//go:embed assets/qiniu.svg +var qiniuIcon []byte -//go:embed icon.svg -var icon []byte +// QiniuID is the provider identifier stored on model rows. +const QiniuID = "qiniu" -// ID is the provider identifier stored on model rows. -const ID = "qiniu" +// QiniuBaseURL is the OpenAI-compatible chat endpoint. +const QiniuBaseURL = "https://api.qnaigc.com/v1" -// BaseURL is the OpenAI-compatible chat endpoint. -const BaseURL = "https://api.qnaigc.com/v1" - -func init() { - catalog.Register(&catalog.Vendor{ - ID: ID, +func newQiniuProvider() *Definition { + return &Definition{ + ID: QiniuID, Name: "Qiniu Cloud", Names: map[string]string{"zh-CN": "七牛云 Qiniu"}, Description: "deepseek/deepseek-v3.2-251201, z-ai/glm-4.7, qwen3.5-397b-a17b, etc.", Website: "https://portal.qiniu.com/ai-inference", - Icon: icon, + Icon: qiniuIcon, API: api.APIOpenAICompletions, Order: 21, RequiresAuth: true, - Auth: catalog.AuthBearer, + Auth: AuthBearer, // api.modelink.ai is the gateway's documented international host. URLPatterns: []string{"qiniuapi.com", "qiniu", "qnaigc.com", "modelink.ai"}, DefaultBaseURLs: map[types.ModelType]string{ - types.ModelTypeKnowledgeQA: BaseURL, + types.ModelTypeKnowledgeQA: QiniuBaseURL, }, ModelTypes: []types.ModelType{ types.ModelTypeKnowledgeQA, }, - Compat: catalog.VendorCompat{ - OpenAICompletions: catalog.OpenAICompletionsCompat{ - MaxTokensField: catalog.Ptr("max_tokens"), - ThinkingFormat: catalog.Ptr(catalog.ThinkingFormatThinkingType), - SupportsReasoningEffort: catalog.Ptr(true), + Compat: VendorCompat{ + OpenAICompletions: api.OpenAICompletionsCompat{ + MaxTokensField: api.Ptr("max_tokens"), + ThinkingFormat: api.Ptr(api.ThinkingFormatThinkingType), + SupportsReasoningEffort: api.Ptr(true), }, }, - Models: catalog.MustParseModels(modelsJSON), - }) + } } diff --git a/internal/models/vendors/requesty/vendor.go b/internal/models/providers/requesty.go similarity index 74% rename from internal/models/vendors/requesty/vendor.go rename to internal/models/providers/requesty.go index 74be132d..36a8f067 100644 --- a/internal/models/vendors/requesty/vendor.go +++ b/internal/models/providers/requesty.go @@ -1,4 +1,4 @@ -// Package requesty registers the Requesty router. +// Package providers registers the Requesty router. // // Facts (https://docs.requesty.ai/features/reasoning and // https://docs.requesty.ai/frameworks/openai): @@ -33,45 +33,41 @@ // 3.6; // - GET /v1/models is chat-only; embedding models live at // /v1/models/embedding, which the docs do not mention. -package requesty +package providers import ( _ "embed" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" "github.com/Tencent/WeKnora/internal/types" ) -//go:embed models.json -var modelsJSON []byte +//go:embed assets/requesty.svg +var requestyIcon []byte -//go:embed icon.svg -var icon []byte +// RequestyID is the provider identifier stored on model rows. +const RequestyID = "requesty" -// ID is the provider identifier stored on model rows. -const ID = "requesty" +// RequestyBaseURL is the OpenAI-compatible router endpoint. +const RequestyBaseURL = "https://router.requesty.ai/v1" -// BaseURL is the OpenAI-compatible router endpoint. -const BaseURL = "https://router.requesty.ai/v1" - -func init() { - catalog.Register(&catalog.Vendor{ - ID: ID, +func newRequestyProvider() *Definition { + return &Definition{ + ID: RequestyID, Name: "Requesty", Names: map[string]string{"zh-CN": "Requesty"}, Description: "openai/gpt-5.5, anthropic/claude-opus-5, google/gemini-3.1-pro-preview, zai/glm-5.2, etc.", Website: "https://requesty.ai", - Icon: icon, + Icon: requestyIcon, API: api.APIOpenAICompletions, Order: 42, RequiresAuth: true, - Auth: catalog.AuthBearer, + Auth: AuthBearer, URLPatterns: []string{"router.requesty.ai", "requesty.ai"}, DefaultBaseURLs: map[types.ModelType]string{ - types.ModelTypeKnowledgeQA: BaseURL, - types.ModelTypeEmbedding: BaseURL, - types.ModelTypeVLLM: BaseURL, + types.ModelTypeKnowledgeQA: RequestyBaseURL, + types.ModelTypeEmbedding: RequestyBaseURL, + types.ModelTypeVLLM: RequestyBaseURL, }, ModelTypes: []types.ModelType{ types.ModelTypeKnowledgeQA, @@ -79,27 +75,27 @@ func init() { types.ModelTypeVLLM, types.ModelTypeASR, }, - Compat: catalog.VendorCompat{ - Transcriptions: catalog.TranscriptionsCompat{ + Compat: VendorCompat{ + Transcriptions: api.TranscriptionsCompat{ // https://docs.requesty.ai/api-reference/endpoint/audio-transcriptions-create: // OpenAI-compatible multipart, json by default, verbose_json // available. "The maximum upload size per request is 32 MB." - MaxFileBytes: catalog.Ptr(32 << 20), + MaxFileBytes: api.Ptr(32 << 20), // "flac, mp3, mp4, mpeg, mpga, m4a, ogg, wav, webm"; language // is an ISO 639-1 form field. Formats: []string{"flac", "mp3", "mp4", "mpeg", "mpga", "m4a", "ogg", "wav", "webm"}, - LanguageParam: catalog.Ptr(catalog.LanguageForm), + LanguageParam: api.Ptr(api.LanguageForm), }, - Embeddings: catalog.EmbeddingsCompat{ + Embeddings: api.EmbeddingsCompat{ // https://docs.requesty.ai/api-reference/endpoint/embeddings-create: // model, input, encoding_format, dimensions. - SendEncodingFormat: catalog.Ptr(true), - DimensionsField: catalog.Ptr("dimensions"), + SendEncodingFormat: api.Ptr(true), + DimensionsField: api.Ptr("dimensions"), }, - OpenAICompletions: catalog.OpenAICompletionsCompat{ - MaxTokensField: catalog.Ptr("max_tokens"), - ThinkingFormat: catalog.Ptr(catalog.ThinkingFormatOpenAI), - SupportsReasoningEffort: catalog.Ptr(true), + OpenAICompletions: api.OpenAICompletionsCompat{ + MaxTokensField: api.Ptr("max_tokens"), + ThinkingFormat: api.Ptr(api.ThinkingFormatOpenAI), + SupportsReasoningEffort: api.Ptr(true), }, }, // Requesty spells the weakest rung "min" and accepts the whole @@ -110,6 +106,5 @@ func init() { api.ReasoningXHigh: api.StringPtr("xhigh"), api.ReasoningMax: api.StringPtr("max"), }, - Models: catalog.MustParseModels(modelsJSON), - }) + } } diff --git a/internal/models/vendors/siliconflow/vendor.go b/internal/models/providers/siliconflow.go similarity index 67% rename from internal/models/vendors/siliconflow/vendor.go rename to internal/models/providers/siliconflow.go index 1421d5d7..4d036f5d 100644 --- a/internal/models/vendors/siliconflow/vendor.go +++ b/internal/models/providers/siliconflow.go @@ -1,4 +1,4 @@ -// Package siliconflow registers SiliconFlow (SiliconCloud), an +// Package providers registers SiliconFlow (SiliconCloud), an // OpenAI-compatible gateway to open-weight models. // // Facts (https://docs.siliconflow.cn/cn/api-reference/chat-completions/chat-completions): @@ -27,47 +27,43 @@ // from the SiliconCloud model pages, and the per-model context windows, // output caps and prices in models.json are not restated in the API // reference. -package siliconflow +package providers import ( _ "embed" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" "github.com/Tencent/WeKnora/internal/types" ) -//go:embed models.json -var modelsJSON []byte +//go:embed assets/siliconflow.svg +var siliconflowIcon []byte -//go:embed icon.svg -var icon []byte +// SiliconflowID is the provider identifier stored on model rows. +const SiliconflowID = "siliconflow" -// ID is the provider identifier stored on model rows. -const ID = "siliconflow" +// SiliconflowBaseURL serves every model type. +const SiliconflowBaseURL = "https://api.siliconflow.cn/v1" -// BaseURL serves every model type. -const BaseURL = "https://api.siliconflow.cn/v1" - -func init() { - catalog.Register(&catalog.Vendor{ - ID: ID, +func newSiliconflowProvider() *Definition { + return &Definition{ + ID: SiliconflowID, Name: "SiliconFlow", Names: map[string]string{"zh-CN": "硅基流动 SiliconFlow"}, Description: "deepseek-ai/DeepSeek-V4-Pro, zai-org/GLM-5.2, Qwen/Qwen3.5-397B-A17B, BAAI/bge-m3, etc.", Website: "https://cloud.siliconflow.cn", - Icon: icon, + Icon: siliconflowIcon, API: api.APIOpenAICompletions, Order: 14, RequiresAuth: true, - Auth: catalog.AuthBearer, + Auth: AuthBearer, URLPatterns: []string{"siliconflow.cn"}, DefaultBaseURLs: map[types.ModelType]string{ - types.ModelTypeKnowledgeQA: BaseURL, - types.ModelTypeEmbedding: BaseURL, - types.ModelTypeRerank: BaseURL, - types.ModelTypeVLLM: BaseURL, - types.ModelTypeASR: BaseURL, + types.ModelTypeKnowledgeQA: SiliconflowBaseURL, + types.ModelTypeEmbedding: SiliconflowBaseURL, + types.ModelTypeRerank: SiliconflowBaseURL, + types.ModelTypeVLLM: SiliconflowBaseURL, + types.ModelTypeASR: SiliconflowBaseURL, }, ModelTypes: []types.ModelType{ types.ModelTypeKnowledgeQA, @@ -76,30 +72,29 @@ func init() { types.ModelTypeVLLM, types.ModelTypeASR, }, - Compat: catalog.VendorCompat{ - Transcriptions: catalog.TranscriptionsCompat{ + Compat: VendorCompat{ + Transcriptions: api.TranscriptionsCompat{ // https://api-docs.siliconflow.cn/docs/api/audio-transcriptions-post: // file and model only — no response_format — and a file of // "时长不超过 1 小时,文件大小不超过 50MB". - MaxFileBytes: catalog.Ptr(50 << 20), + MaxFileBytes: api.Ptr(50 << 20), }, - Embeddings: catalog.EmbeddingsCompat{ + Embeddings: api.EmbeddingsCompat{ // https://api-docs.siliconflow.cn/docs/api/embeddings-post: model, // input, encoding_format, and dimensions "仅 Qwen/Qwen3 系列支持" // — the bge-m3 entry turns it off. The input array schema says // "当前最大数组大小为 32" (maxItems 32). - SendEncodingFormat: catalog.Ptr(true), - DimensionsField: catalog.Ptr("dimensions"), - MaxBatchSize: catalog.Ptr(32), + SendEncodingFormat: api.Ptr(true), + DimensionsField: api.Ptr("dimensions"), + MaxBatchSize: api.Ptr(32), }, - OpenAICompletions: catalog.OpenAICompletionsCompat{ - MaxTokensField: catalog.Ptr("max_tokens"), - ThinkingFormat: catalog.Ptr(catalog.ThinkingFormatEnableThinking), - ThinkingBudgetField: catalog.Ptr("thinking_budget"), - SupportsReasoningEffort: catalog.Ptr(true), - PromptCacheAccounting: catalog.Ptr(true), + OpenAICompletions: api.OpenAICompletionsCompat{ + MaxTokensField: api.Ptr("max_tokens"), + ThinkingFormat: api.Ptr(api.ThinkingFormatEnableThinking), + ThinkingBudgetField: api.Ptr("thinking_budget"), + SupportsReasoningEffort: api.Ptr(true), + PromptCacheAccounting: api.Ptr(true), }, }, - Models: catalog.MustParseModels(modelsJSON), - }) + } } diff --git a/internal/models/vendors/volcengine/vendor.go b/internal/models/providers/volcengine.go similarity index 81% rename from internal/models/vendors/volcengine/vendor.go rename to internal/models/providers/volcengine.go index 783f928b..ccbe18af 100644 --- a/internal/models/vendors/volcengine/vendor.go +++ b/internal/models/providers/volcengine.go @@ -1,4 +1,4 @@ -// Package volcengine registers Volcengine Ark (Doubao) through its +// Package providers registers Volcengine Ark (Doubao) through its // OpenAI-compatible chat endpoint. // // Facts (https://www.volcengine.com/docs/82379/1494384 = Chat API reference, @@ -72,64 +72,60 @@ // // unverified: prices in models.json come from the Ark pricing console, which // the public docs do not render. -package volcengine +package providers import ( _ "embed" "strings" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" "github.com/Tencent/WeKnora/internal/types" ) -//go:embed models.json -var modelsJSON []byte +//go:embed assets/volcengine.svg +var volcengineIcon []byte -//go:embed icon.svg -var icon []byte +// VolcengineID is the provider identifier stored on model rows. +const VolcengineID = "volcengine" -// ID is the provider identifier stored on model rows. -const ID = "volcengine" +// VolcengineBaseURL is the OpenAI-compatible Ark chat endpoint. +const VolcengineBaseURL = "https://ark.cn-beijing.volces.com/api/v3" -// BaseURL is the OpenAI-compatible Ark chat endpoint. -const BaseURL = "https://ark.cn-beijing.volces.com/api/v3" - -// EmbeddingBaseURL is the Ark multimodal embedding endpoint. -const EmbeddingBaseURL = "https://ark.cn-beijing.volces.com/api/v3/embeddings/multimodal" +// VolcengineEmbeddingBaseURL is the Ark multimodal embedding endpoint. +const VolcengineEmbeddingBaseURL = "https://ark.cn-beijing.volces.com/api/v3/embeddings/multimodal" const ( - multimodalEmbeddingPath = "/api/v3/embeddings/multimodal" - textEmbeddingPath = "/api/v3/embeddings" + volcengineMultimodalEmbeddingPath = "/api/v3/embeddings/multimodal" + volcengineTextEmbeddingPath = "/api/v3/embeddings" ) -// RerankBaseURL is the Knowledge Base managed rerank endpoint. -const RerankBaseURL = "https://api-knowledgebase.mlp.cn-beijing.volces.com" +// VolcengineRerankBaseURL is the Knowledge Base managed rerank endpoint. +const VolcengineRerankBaseURL = "https://api-knowledgebase.mlp.cn-beijing.volces.com" -// AnthropicBaseURL is the documented Anthropic Messages surface. It is not +// VolcengineAnthropicBaseURL is the documented Anthropic Messages surface. It is not // the default for this vendor; operators who want it configure it explicitly. -const AnthropicBaseURL = "https://ark.cn-beijing.volces.com/api/compatible/v1" +const VolcengineAnthropicBaseURL = "https://ark.cn-beijing.volces.com/api/compatible/v1" -func init() { +func newVolcengineProvider() *Definition { rerankOnly := []types.ModelType{types.ModelTypeRerank} - catalog.Register(&catalog.Vendor{ - ID: ID, + return &Definition{ + ID: VolcengineID, Name: "Volcengine Ark", Names: map[string]string{"zh-CN": "火山引擎 Volcengine"}, Description: "doubao-seed-2-1-pro-260628, deepseek-v4-pro-ga-260813, " + "doubao-embedding-vision-250615, doubao-seed-rerank, etc.", Website: "https://console.volcengine.com/ark", - Icon: icon, + Icon: volcengineIcon, API: api.APIOpenAICompletions, Order: 12, RequiresAuth: true, - Auth: catalog.AuthBearer, + Auth: AuthBearer, URLPatterns: []string{"volces.com", "volcengine"}, DefaultBaseURLs: map[types.ModelType]string{ - types.ModelTypeKnowledgeQA: BaseURL, - types.ModelTypeEmbedding: EmbeddingBaseURL, - types.ModelTypeRerank: RerankBaseURL, - types.ModelTypeVLLM: BaseURL, + types.ModelTypeKnowledgeQA: VolcengineBaseURL, + types.ModelTypeEmbedding: VolcengineEmbeddingBaseURL, + types.ModelTypeRerank: VolcengineRerankBaseURL, + types.ModelTypeVLLM: VolcengineBaseURL, }, ModelTypes: []types.ModelType{ types.ModelTypeKnowledgeQA, @@ -139,7 +135,7 @@ func init() { }, // Rerank is signed with an IAM access-key pair, so the first // credential is an Access Key ID rather than an Ark bearer token. - CredentialLabels: []catalog.CredentialLabel{{ + CredentialLabels: []CredentialLabel{{ Label: "Access Key ID", Labels: map[string]string{"zh-CN": "Access Key ID(AK/SK 签名)"}, Placeholder: "Volcengine IAM access key id (AKLT...)", @@ -149,7 +145,7 @@ func init() { ModelTypes: rerankOnly, Required: true, }}, - ExtraFields: []catalog.ExtraField{ + ExtraFields: []ExtraField{ { Key: "secret_key", Label: "Secret Key", @@ -191,7 +187,7 @@ func init() { // multimodal URL that was the default, .../api/v3 like chat, and the // bare host. All of them name the same service, so the request is // placed from the host. - Endpoint: func(r catalog.EndpointRequest) (string, map[string]string) { + Endpoint: func(r EndpointRequest) (string, map[string]string) { if r.ModelType != types.ModelTypeEmbedding { return "", nil } @@ -202,11 +198,11 @@ func init() { if r.EmbeddingAPI == api.EmbeddingOpenAI { // The retired doubao-embedding text models, whose archived // reference still names this endpoint. - return root + textEmbeddingPath, nil + return root + volcengineTextEmbeddingPath, nil } - return root + multimodalEmbeddingPath, nil + return root + volcengineMultimodalEmbeddingPath, nil }, - Compat: catalog.VendorCompat{ + Compat: VendorCompat{ // https://docs.volcengine.com/docs/ark/multimodal-vectorization-api: // the only embedding API Ark still lists. It fuses everything in // one request into a single vector, so a request carries one text. @@ -215,23 +211,23 @@ func init() { // curl sends it. `instructions` is documented too and deliberately // not declared: like Jina's task it changes the document vectors // (Tencent/WeKnora#1401). - Embeddings: catalog.EmbeddingsCompat{ - SendEncodingFormat: catalog.Ptr(true), - DimensionsField: catalog.Ptr("dimensions"), - MaxBatchSize: catalog.Ptr(1), + Embeddings: api.EmbeddingsCompat{ + SendEncodingFormat: api.Ptr(true), + DimensionsField: api.Ptr("dimensions"), + MaxBatchSize: api.Ptr(1), }, - Rerank: catalog.RerankCompat{ + Rerank: api.RerankCompat{ // datas "数组长度不超过 200" // (https://docs.volcengine.com/docs/vector_database_vikingdb/Rerank). // The pre-catalog client split at 50, a constant of its own // rather than a documented ceiling. - MaxDocuments: catalog.Ptr(200), - MaxConcurrency: catalog.Ptr(4), + MaxDocuments: api.Ptr(200), + MaxConcurrency: api.Ptr(4), }, - OpenAICompletions: catalog.OpenAICompletionsCompat{ - ThinkingFormat: catalog.Ptr(catalog.ThinkingFormatThinkingType), - SupportsReasoningEffort: catalog.Ptr(true), - PromptCacheAccounting: catalog.Ptr(true), + OpenAICompletions: api.OpenAICompletionsCompat{ + ThinkingFormat: api.Ptr(api.ThinkingFormatThinkingType), + SupportsReasoningEffort: api.Ptr(true), + PromptCacheAccounting: api.Ptr(true), }, }, // Ark accepts all seven effort rungs on every model that supports the @@ -245,6 +241,5 @@ func init() { api.ReasoningXHigh: api.StringPtr("xhigh"), api.ReasoningMax: api.StringPtr("max"), }, - Models: catalog.MustParseModels(modelsJSON), - }) + } } diff --git a/internal/models/vendors/weknoracloud/vendor.go b/internal/models/providers/weknoracloud.go similarity index 73% rename from internal/models/vendors/weknoracloud/vendor.go rename to internal/models/providers/weknoracloud.go index 9488ea3f..46c64eae 100644 --- a/internal/models/vendors/weknoracloud/vendor.go +++ b/internal/models/providers/weknoracloud.go @@ -1,4 +1,4 @@ -// Package weknoracloud registers the WeKnora managed model service. +// Package providers registers the WeKnora managed model service. // // unverified: this is a first-party endpoint with no published API // reference — https://weknora.weixin.qq.com/docs documents the WeKnora @@ -35,53 +35,48 @@ // // unverified: PromptCacheAccounting is kept false; the gateway is not // documented to report prompt-cache counters, and none have been observed. -package weknoracloud +package providers import ( _ "embed" "net/http" "strings" - "github.com/google/uuid" - "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" modelutils "github.com/Tencent/WeKnora/internal/models/utils" "github.com/Tencent/WeKnora/internal/types" + "github.com/google/uuid" ) -//go:embed models.json -var modelsJSON []byte +//go:embed assets/weknoracloud.svg +var weKnoraCloudIcon []byte -//go:embed icon.svg -var icon []byte +// WeKnoraCloudID is the provider identifier stored on model rows. +const WeKnoraCloudID = "weknoracloud" -// ID is the provider identifier stored on model rows. -const ID = "weknoracloud" - -// BaseURL is the single service entry point; per-capability paths are +// WeKnoraCloudBaseURL is the single service entry point; per-capability paths are // appended by the Endpoint hook and the embedding / rerank clients. -const BaseURL = "https://weknora.weixin.qq.com" +const WeKnoraCloudBaseURL = "https://weknora.weixin.qq.com" -func init() { - catalog.Register(&catalog.Vendor{ - ID: ID, +func newWeKnoraCloudProvider() *Definition { + return &Definition{ + ID: WeKnoraCloudID, Name: "WeKnora Cloud", Names: map[string]string{"zh-CN": "WeKnora 云服务"}, Description: "WeKnora managed models: chat, embedding, rerank, vlm", Descriptions: map[string]string{"zh-CN": "WeKnora云服务,模型:chat, embedding, rerank, vlm"}, - Website: BaseURL, - Icon: icon, + Website: WeKnoraCloudBaseURL, + Icon: weKnoraCloudIcon, API: api.APIOpenAICompletions, Order: 1, RequiresAuth: true, - Auth: catalog.AuthSigned, + Auth: AuthSigned, URLPatterns: []string{"weknora.weixin.qq.com"}, DefaultBaseURLs: map[types.ModelType]string{ - types.ModelTypeKnowledgeQA: BaseURL, - types.ModelTypeEmbedding: BaseURL, - types.ModelTypeRerank: BaseURL, - types.ModelTypeVLLM: BaseURL, + types.ModelTypeKnowledgeQA: WeKnoraCloudBaseURL, + types.ModelTypeEmbedding: WeKnoraCloudBaseURL, + types.ModelTypeRerank: WeKnoraCloudBaseURL, + types.ModelTypeVLLM: WeKnoraCloudBaseURL, }, ModelTypes: []types.ModelType{ types.ModelTypeKnowledgeQA, @@ -89,27 +84,27 @@ func init() { types.ModelTypeRerank, types.ModelTypeVLLM, }, - Compat: catalog.VendorCompat{ - Embeddings: catalog.EmbeddingsCompat{ + Compat: VendorCompat{ + Embeddings: api.EmbeddingsCompat{ // The OpenAI body on the service's own path, signed like the // rest of it. - Path: catalog.Ptr("/api/v1/embeddings"), - DimensionsField: catalog.Ptr("dimensions"), - RequestTimeout: catalog.Ptr(60), + Path: api.Ptr("/api/v1/embeddings"), + DimensionsField: api.Ptr("dimensions"), + RequestTimeout: api.Ptr(60), }, - Rerank: catalog.RerankCompat{ - Path: catalog.Ptr("/api/v1/rerank"), + Rerank: api.RerankCompat{ + Path: api.Ptr("/api/v1/rerank"), // The only rerank vendor that has ever had a client deadline // here. Without it a hung endpoint holds the retrieval stage // for as long as the caller's context allows. - RequestTimeout: catalog.Ptr(60), + RequestTimeout: api.Ptr(60), }, - OpenAICompletions: catalog.OpenAICompletionsCompat{ - SupportsMultiContent: catalog.Ptr(false), - PromptCacheAccounting: catalog.Ptr(false), + OpenAICompletions: api.OpenAICompletionsCompat{ + SupportsMultiContent: api.Ptr(false), + PromptCacheAccounting: api.Ptr(false), }, }, - Signer: func(creds catalog.Credentials) api.AuthFunc { + Signer: func(creds api.Credentials) api.AuthFunc { return func(req *http.Request, body []byte) { headers := modelutils.Sign(creds.AppID, creds.AppSecret, uuid.NewString(), string(body)) for k, v := range headers { @@ -117,7 +112,7 @@ func init() { } } }, - Endpoint: func(r catalog.EndpointRequest) (string, map[string]string) { + Endpoint: func(r EndpointRequest) (string, map[string]string) { switch r.ModelType { case types.ModelTypeEmbedding, types.ModelTypeRerank, types.ModelTypeASR: // Those clients build their own paths; fall back. @@ -127,7 +122,6 @@ func init() { }, // AppID / AppSecret are written by the dedicated initialization // endpoint; only structural checks happen there. - Validate: func(_ *catalog.Config) error { return nil }, - Models: catalog.MustParseModels(modelsJSON), - }) + Validate: func(_ *Config) error { return nil }, + } } diff --git a/internal/models/vendors/zhipu/vendor.go b/internal/models/providers/zhipu.go similarity index 75% rename from internal/models/vendors/zhipu/vendor.go rename to internal/models/providers/zhipu.go index 3b4e5d69..01cd84e1 100644 --- a/internal/models/vendors/zhipu/vendor.go +++ b/internal/models/providers/zhipu.go @@ -1,4 +1,4 @@ -// Package zhipu registers Zhipu AI's BigModel open platform. +// Package providers registers Zhipu AI's BigModel open platform. // // Facts (https://docs.bigmodel.cn/api-reference/模型-api/对话补全): // - chat completions live at POST /paas/v4/chat/completions under @@ -51,56 +51,52 @@ // unverified: context windows, max output tokens and prices of individual // entries beyond the GLM-5 / 5.2 / 5.3 / 4.7 model pages, and the // glm-4.7-flash zero price. -package zhipu +package providers import ( _ "embed" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" "github.com/Tencent/WeKnora/internal/types" ) -//go:embed models.json -var modelsJSON []byte +//go:embed assets/zhipu.svg +var zhipuIcon []byte -//go:embed icon.svg -var icon []byte +// ZhipuID is the provider identifier stored on model rows. +const ZhipuID = "zhipu" -// ID is the provider identifier stored on model rows. -const ID = "zhipu" +// ZhipuBaseURL is the OpenAI-compatible chat / embedding endpoint. +const ZhipuBaseURL = "https://open.bigmodel.cn/api/paas/v4" -// BaseURL is the OpenAI-compatible chat / embedding endpoint. -const BaseURL = "https://open.bigmodel.cn/api/paas/v4" +// ZhipuRerankBaseURL is the rerank endpoint. +const ZhipuRerankBaseURL = "https://open.bigmodel.cn/api/paas/v4/rerank" -// RerankBaseURL is the rerank endpoint. -const RerankBaseURL = "https://open.bigmodel.cn/api/paas/v4/rerank" +// ZhipuAnthropicBaseURL is the Anthropic Messages compatibility facade. +const ZhipuAnthropicBaseURL = "https://open.bigmodel.cn/api/anthropic" -// AnthropicBaseURL is the Anthropic Messages compatibility facade. -const AnthropicBaseURL = "https://open.bigmodel.cn/api/anthropic" - -func init() { - catalog.Register(&catalog.Vendor{ - ID: ID, +func newZhipuProvider() *Definition { + return &Definition{ + ID: ZhipuID, Name: "Zhipu BigModel", Names: map[string]string{"zh-CN": "智谱 BigModel"}, Description: "glm-5.3, glm-5.2, glm-4.7, embedding-3, rerank; " + - "Anthropic-compatible facade at " + AnthropicBaseURL, + "Anthropic-compatible facade at " + ZhipuAnthropicBaseURL, Descriptions: map[string]string{ - "zh-CN": "glm-5.3, glm-5.2, glm-4.7, embedding-3, rerank;Anthropic 兼容接口 " + AnthropicBaseURL, + "zh-CN": "glm-5.3, glm-5.2, glm-4.7, embedding-3, rerank;Anthropic 兼容接口 " + ZhipuAnthropicBaseURL, }, Website: "https://open.bigmodel.cn", - Icon: icon, + Icon: zhipuIcon, API: api.APIOpenAICompletions, Order: 11, RequiresAuth: true, - Auth: catalog.AuthBearer, + Auth: AuthBearer, URLPatterns: []string{"open.bigmodel.cn", "zhipu"}, DefaultBaseURLs: map[types.ModelType]string{ - types.ModelTypeKnowledgeQA: BaseURL, - types.ModelTypeEmbedding: BaseURL, - types.ModelTypeRerank: RerankBaseURL, - types.ModelTypeVLLM: BaseURL, + types.ModelTypeKnowledgeQA: ZhipuBaseURL, + types.ModelTypeEmbedding: ZhipuBaseURL, + types.ModelTypeRerank: ZhipuRerankBaseURL, + types.ModelTypeVLLM: ZhipuBaseURL, }, ModelTypes: []types.ModelType{ types.ModelTypeKnowledgeQA, @@ -109,37 +105,37 @@ func init() { types.ModelTypeVLLM, types.ModelTypeASR, }, - Compat: catalog.VendorCompat{ - Transcriptions: catalog.TranscriptionsCompat{ + Compat: VendorCompat{ + Transcriptions: api.TranscriptionsCompat{ // https://docs.bigmodel.cn/api-reference/模型-api/语音转文本: // POST {base}/audio/transcriptions, multipart file + model // (glm-asr-2512), answering {text}. The file is ".wav / .mp3", // at most 25 MB and 30 seconds — the duration cannot be checked // here without decoding, so a longer file is the vendor's error. - MaxFileBytes: catalog.Ptr(25 << 20), + MaxFileBytes: api.Ptr(25 << 20), // No language field; prompt and hotwords are its only hints. Formats: []string{"wav", "mp3"}, }, - Embeddings: catalog.EmbeddingsCompat{ + Embeddings: api.EmbeddingsCompat{ // https://docs.bigmodel.cn/api-reference/模型-api/文本嵌入: model, // input, dimensions — no encoding_format. embedding-2 is fixed at // 1024 and its entry turns dimensions off; embedding-3 takes at // most 64 inputs per request. - DimensionsField: catalog.Ptr("dimensions"), + DimensionsField: api.Ptr("dimensions"), }, - Rerank: catalog.RerankCompat{ + Rerank: api.RerankCompat{ // The reference gives 最大长度为 4096 字符 for the query and for each // document, and caps documents at 128 per request. - SendReturnDocs: catalog.Ptr(true), - MaxDocuments: catalog.Ptr(128), - MaxQueryChars: catalog.Ptr(4096), - MaxDocumentChars: catalog.Ptr(4096), + SendReturnDocs: api.Ptr(true), + MaxDocuments: api.Ptr(128), + MaxQueryChars: api.Ptr(4096), + MaxDocumentChars: api.Ptr(4096), }, - OpenAICompletions: catalog.OpenAICompletionsCompat{ - MaxTokensField: catalog.Ptr("max_tokens"), - ThinkingFormat: catalog.Ptr(catalog.ThinkingFormatThinkingType), - SupportsReasoningEffort: catalog.Ptr(true), - PromptCacheAccounting: catalog.Ptr(true), + OpenAICompletions: api.OpenAICompletionsCompat{ + MaxTokensField: api.Ptr("max_tokens"), + ThinkingFormat: api.Ptr(api.ThinkingFormatThinkingType), + SupportsReasoningEffort: api.Ptr(true), + PromptCacheAccounting: api.Ptr(true), // "默认 auto 且仅支持 auto": none / required / named function // are rejected. ToolChoiceModes: []string{"auto"}, @@ -154,6 +150,5 @@ func init() { api.ReasoningXHigh: api.StringPtr("xhigh"), api.ReasoningMax: api.StringPtr("max"), }, - Models: catalog.MustParseModels(modelsJSON), - }) + } } diff --git a/internal/models/rerank/catalog_matrix_test.go b/internal/models/rerank/catalog_matrix_test.go new file mode 100644 index 00000000..799d5903 --- /dev/null +++ b/internal/models/rerank/catalog_matrix_test.go @@ -0,0 +1,89 @@ +package rerank + +import ( + "context" + "net/url" + "strings" + "testing" + + modelruntime "github.com/Tencent/WeKnora/internal/models/runtime" + "github.com/Tencent/WeKnora/internal/types" + "github.com/stretchr/testify/require" +) + +func TestEveryCatalogRerankTransport(t *testing.T) { + for _, v := range modelruntime.List() { + for _, m := range v.Models() { + if m.Type != types.ModelTypeRerank { + continue + } + names := append([]string{m.ID}, m.Aliases...) + if m.ID == "" { + names[0] = strings.ReplaceAll(m.Match, "*", "snapshot") + } + for _, name := range names { + t.Run(v.ID+"/"+name, func(t *testing.T) { + u := newUpstream(t) + base, err := url.Parse(v.GetDefaultURL(types.ModelTypeRerank)) + require.NoError(t, err) + cfg := &RerankerConfig{ + Source: types.ModelSourceRemote, + Provider: v.ID, + ModelName: name, + ModelID: "row-id", + BaseURL: u.url + base.Path, + APIKey: "row-key", + AppID: "app", + AppSecret: "secret", + } + client, err := newReranker(cfg) + if strings.Contains(string(m.Compat), "unsupported_reason") { + require.ErrorContains(t, err, "does not serve") + require.Empty(t, u.requests) + return + } + require.NoError(t, err) + result, err := client.Rerank(context.Background(), "q", []string{"a", "中文"}) + require.NoError(t, err) + require.Len(t, result, 2) + require.NotEmpty(t, u.requests) + }) + } + } + } +} + +func TestStoredRerankSpecReachesWire(t *testing.T) { + u := newUpstream(t) + row := &types.Model{ + ID: "stable-id", + Name: "custom", + Source: types.ModelSourceRemote, + Parameters: types.ModelParameters{ + Provider: "generic", + BaseURL: u.url, + APIKey: "model-key", + Spec: &types.ModelSpecOverride{ + Compat: map[string]any{ + "path": "/custom-rerank", + "send_top_n": true, + "extra_body": map[string]any{ + "custom_flag": true, + }, + }, + }, + }, + } + client, err := newReranker(ConfigFromModel(row, "", "")) + require.NoError(t, err) + _, err = client.Rerank(context.Background(), "q", []string{"a", "bb"}) + require.NoError(t, err) + require.Len(t, u.requests, 1) + req := u.requests[0] + require.Equal(t, "/custom-rerank", req.path) + require.Equal(t, true, req.body["custom_flag"]) + require.Equal(t, float64(2), req.body["top_n"]) + row.Parameters.Spec.Compat = map[string]any{"misspelled_option": true} + _, err = newReranker(ConfigFromModel(row, "", "")) + require.ErrorContains(t, err, "unknown field") +} diff --git a/internal/models/rerank/lkeap_reranker.go b/internal/models/rerank/lkeap_reranker.go index e17adfb7..1b714717 100644 --- a/internal/models/rerank/lkeap_reranker.go +++ b/internal/models/rerank/lkeap_reranker.go @@ -1,107 +1,36 @@ package rerank import ( - "context" - "fmt" "strings" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" - "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common" - "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile" - lkeap "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/lkeap/v20240522" + "github.com/Tencent/WeKnora/internal/models/api/tencentlkeap" + modelruntime "github.com/Tencent/WeKnora/internal/models/runtime" ) +// Tencent action defaults retained for existing callers. const ( - // LKEAPRerankEndpoint 腾讯云知识引擎原子能力 Rerank API 域名 - LKEAPRerankEndpoint = "lkeap.tencentcloudapi.com" - // LKEAPDefaultRegion RunRerank 支持的地域,默认广州 - LKEAPDefaultRegion = "ap-guangzhou" - // LKEAPDefaultRerankModel 默认 rerank 模型名 - LKEAPDefaultRerankModel = "lke-reranker-base" + LKEAPRerankEndpoint = tencentlkeap.LKEAPRerankEndpoint + LKEAPDefaultRegion = tencentlkeap.LKEAPDefaultRegion + LKEAPDefaultRerankModel = tencentlkeap.LKEAPDefaultRerankModel ) -// lkeapEndpoint and lkeapScheme are where the SDK sends RunRerank: the public -// API host, as it has always been, whatever the row's base URL says. They are -// variables only so a test can point the SDK at a local server. -var ( - lkeapEndpoint = LKEAPRerankEndpoint - lkeapScheme = "HTTPS" -) +// Test composition may route the action SDK to a local stand-in. +var lkeapEndpoint, lkeapScheme = LKEAPRerankEndpoint, "HTTPS" -// lkeapClient calls Tencent Cloud's RunRerank action through the official -// SDK, which owns the TC3 signing this API requires. It implements -// api.Reranker and nothing else: the per-request ceilings (60 documents, -// 2000 characters for Query plus Docs together) are declared on the vendor -// and enforced by protocolReranker, like every other vendor's. -type lkeapClient struct { - modelName string - client *lkeap.Client -} - -func newLKEAPClient(config *RerankerConfig, resolved *catalog.Resolved) (api.Reranker, error) { - secretID := strings.TrimSpace(config.APIKey) - secretKey := strings.TrimSpace(config.AppSecret) - if secretKey == "" && config.ExtraConfig != nil { - secretKey = strings.TrimSpace(config.ExtraConfig["secret_key"]) - } - if secretID == "" || secretKey == "" { - return nil, fmt.Errorf("secret_id and secret_key are required for LKEAP rerank (set API Key and Secret Key)") - } - - region := LKEAPDefaultRegion - if config.ExtraConfig != nil { - if r := strings.TrimSpace(config.ExtraConfig["region"]); r != "" { - region = r - } - } - - credential := common.NewCredential(secretID, secretKey) - cpf := profile.NewClientProfile() - cpf.HttpProfile.Endpoint = lkeapEndpoint - cpf.HttpProfile.Scheme = lkeapScheme - - client, err := lkeap.NewClient(credential, region, cpf) - if err != nil { - return nil, fmt.Errorf("create LKEAP client: %w", err) - } - - modelName := strings.TrimSpace(resolved.RemoteModel) - if modelName == "" { - modelName = LKEAPDefaultRerankModel - } - return &lkeapClient{modelName: modelName, client: client}, nil -} - -// Rerank scores one batch. RunRerank answers a bare score list in input -// order rather than an indexed, sorted result set. -func (r *lkeapClient) Rerank( - ctx context.Context, query string, documents []string, -) ([]api.RerankResult, error) { - req := lkeap.NewRunRerankRequest() - req.Query = common.StringPtr(query) - req.Docs = common.StringPtrs(documents) - req.Model = common.StringPtr(r.modelName) - - resp, err := r.client.RunRerankWithContext(ctx, req) - if err != nil { - return nil, fmt.Errorf("LKEAP RunRerank: %w", err) - } - if resp == nil || resp.Response == nil || len(resp.Response.ScoreList) == 0 { - return nil, fmt.Errorf("LKEAP rerank API returned empty score list") - } - scores := resp.Response.ScoreList - if len(scores) != len(documents) { - return nil, fmt.Errorf("LKEAP rerank score count mismatch: got %d scores for %d documents", - len(scores), len(documents)) - } - - results := make([]api.RerankResult, len(documents)) - for i, score := range scores { - results[i] = api.RerankResult{Index: i, Text: documents[i]} - if score != nil { - results[i].Score = *score - } - } - return results, nil +func newLKEAPClient(config *RerankerConfig, resolved *modelruntime.Resolved) (api.Reranker, error) { + secret := strings.TrimSpace(config.AppSecret) + if secret == "" { + secret = config.ExtraConfig["secret_key"] + } + return tencentlkeap.New( + tencentlkeap.Config{ + SecretID: config.APIKey, + SecretKey: secret, + Region: config.ExtraConfig["region"], + Model: resolved.RemoteModel, + Endpoint: lkeapEndpoint, + Scheme: lkeapScheme, + }, + ) } diff --git a/internal/models/rerank/protocol.go b/internal/models/rerank/protocol.go index 63d580b5..2ed81da3 100644 --- a/internal/models/rerank/protocol.go +++ b/internal/models/rerank/protocol.go @@ -9,7 +9,6 @@ import ( "github.com/Tencent/WeKnora/internal/logger" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" "golang.org/x/sync/errgroup" ) @@ -19,7 +18,7 @@ import ( // ceilings, and putting the returned scores on one scale. type protocolReranker struct { inner api.Reranker - settings catalog.RerankSettings + settings api.RerankSettings endpoint string modelName string modelID string diff --git a/internal/models/rerank/protocol_test.go b/internal/models/rerank/protocol_test.go index 621256a9..b9c54516 100644 --- a/internal/models/rerank/protocol_test.go +++ b/internal/models/rerank/protocol_test.go @@ -9,7 +9,6 @@ import ( "testing" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -38,7 +37,7 @@ func (f *fakeProtocol) Rerank( return out, nil } -func newWrapped(inner api.Reranker, settings catalog.RerankSettings) *protocolReranker { +func newWrapped(inner api.Reranker, settings api.RerankSettings) *protocolReranker { return &protocolReranker{ inner: inner, settings: settings, endpoint: "https://example.invalid", modelName: "m", modelID: "id", @@ -50,7 +49,7 @@ func newWrapped(inner api.Reranker, settings catalog.RerankSettings) *protocolRe // original slice, not into the batch. func TestBatchingSplitsAndRestoresGlobalIndices(t *testing.T) { fake := &fakeProtocol{} - r := newWrapped(fake, catalog.RerankSettings{MaxDocuments: 2, MaxConcurrency: 1}) + r := newWrapped(fake, api.RerankSettings{MaxDocuments: 2, MaxConcurrency: 1}) docs := []string{"d0", "d1", "d2", "d3", "d4"} got, err := r.Rerank(context.Background(), "q", docs) @@ -67,7 +66,7 @@ func TestBatchingSplitsAndRestoresGlobalIndices(t *testing.T) { func TestBatchingIsSkippedWhenTheVendorDeclaresNoLimit(t *testing.T) { fake := &fakeProtocol{} - r := newWrapped(fake, catalog.RerankSettings{}) + r := newWrapped(fake, api.RerankSettings{}) _, err := r.Rerank(context.Background(), "q", []string{"a", "b", "c", "d"}) require.NoError(t, err) @@ -78,7 +77,7 @@ func TestBatchingIsSkippedWhenTheVendorDeclaresNoLimit(t *testing.T) { // so beats sending a prefix and returning a number for text nobody asked // about. func TestAnOversizedDocumentIsAnError(t *testing.T) { - r := newWrapped(&fakeProtocol{}, catalog.RerankSettings{MaxDocumentChars: 10}) + r := newWrapped(&fakeProtocol{}, api.RerankSettings{MaxDocumentChars: 10}) _, err := r.Rerank(context.Background(), "q", []string{"ok", strings.Repeat("x", 99)}) require.Error(t, err) @@ -86,7 +85,7 @@ func TestAnOversizedDocumentIsAnError(t *testing.T) { } func TestBatchErrorsPropagate(t *testing.T) { - r := newWrapped(&fakeProtocol{err: fmt.Errorf("upstream exploded")}, catalog.RerankSettings{}) + r := newWrapped(&fakeProtocol{err: fmt.Errorf("upstream exploded")}, api.RerankSettings{}) _, err := r.Rerank(context.Background(), "q", []string{"a"}) require.Error(t, err) @@ -95,7 +94,7 @@ func TestBatchErrorsPropagate(t *testing.T) { func TestEmptyInputMakesNoRequest(t *testing.T) { fake := &fakeProtocol{} - r := newWrapped(fake, catalog.RerankSettings{}) + r := newWrapped(fake, api.RerankSettings{}) got, err := r.Rerank(context.Background(), "q", nil) require.NoError(t, err) @@ -142,7 +141,7 @@ func TestProbabilityScoresPassThroughUntouched(t *testing.T) { // so the query is checked on its own before any request goes out. func TestAnOversizedQueryIsAnError(t *testing.T) { fake := &fakeProtocol{} - r := newWrapped(fake, catalog.RerankSettings{MaxQueryChars: 10}) + r := newWrapped(fake, api.RerankSettings{MaxQueryChars: 10}) _, err := r.Rerank(context.Background(), strings.Repeat("q", 11), []string{"d"}) require.Error(t, err) @@ -151,7 +150,7 @@ func TestAnOversizedQueryIsAnError(t *testing.T) { } func TestAQueryWithinTheLimitPasses(t *testing.T) { - r := newWrapped(&fakeProtocol{}, catalog.RerankSettings{MaxQueryChars: 10}) + r := newWrapped(&fakeProtocol{}, api.RerankSettings{MaxQueryChars: 10}) _, err := r.Rerank(context.Background(), strings.Repeat("中", 10), []string{"d"}) require.NoError(t, err, "runes, not bytes") } @@ -161,7 +160,7 @@ func TestAQueryWithinTheLimitPasses(t *testing.T) { // caller would see the best of the first batch only. func TestMergedBatchesAreRankedGlobally(t *testing.T) { // Scores are the position within the batch, so batch 2 holds the highest. - r := newWrapped(&fakeProtocol{}, catalog.RerankSettings{MaxDocuments: 2, MaxConcurrency: 1}) + r := newWrapped(&fakeProtocol{}, api.RerankSettings{MaxDocuments: 2, MaxConcurrency: 1}) got, err := r.Rerank(context.Background(), "q", []string{"d0", "d1", "d2", "d3", "d4"}) require.NoError(t, err) diff --git a/internal/models/rerank/provider_detection_test.go b/internal/models/rerank/provider_detection_test.go index 0353d89b..d223e880 100644 --- a/internal/models/rerank/provider_detection_test.go +++ b/internal/models/rerank/provider_detection_test.go @@ -3,13 +3,14 @@ package rerank import ( "testing" - "github.com/Tencent/WeKnora/internal/models/catalog" + "github.com/Tencent/WeKnora/internal/models/providers" + modelruntime "github.com/Tencent/WeKnora/internal/models/runtime" ) // TestDetectByURLSeesVendorCatalog guards the blank import of -// internal/models/vendors in reranker.go. +// runtime composition. // -// catalog.DetectByURL returns "generic" for every URL while the catalog is +// modelruntime.DetectByURL returns "generic" for every URL while the catalog is // empty. Without the vendor packages linked in, a stored rerank row that // carries no provider id resolves to the generic Cohere client: LKEAP and // Volcengine lose their signed SDK clients and Aliyun its native protocol. @@ -20,10 +21,10 @@ func TestDetectByURLSeesVendorCatalog(t *testing.T) { "https://api.jina.ai/v1": "jina", "https://open.bigmodel.cn/api/paas/v4": "zhipu", "https://dashscope.aliyuncs.com/compatible-mode/v1": "aliyun", - "https://some-self-hosted-gateway.example.internal/v1": catalog.GenericID, + "https://some-self-hosted-gateway.example.internal/v1": providers.GenericID, } for baseURL, want := range cases { - if got := catalog.DetectByURL(baseURL); got != want { + if got := modelruntime.DetectByURL(baseURL); got != want { t.Errorf("DetectByURL(%q) = %q, want %q", baseURL, got, want) } } diff --git a/internal/models/rerank/reranker.go b/internal/models/rerank/reranker.go index bc551dfb..1e4f6d60 100644 --- a/internal/models/rerank/reranker.go +++ b/internal/models/rerank/reranker.go @@ -1,3 +1,4 @@ +// Package rerank adapts rerank protocols to application batching and score semantics. package rerank import ( @@ -11,12 +12,12 @@ import ( "github.com/Tencent/WeKnora/internal/models/api/cohererank" "github.com/Tencent/WeKnora/internal/models/api/dashscoperank" "github.com/Tencent/WeKnora/internal/models/api/nimrerank" - "github.com/Tencent/WeKnora/internal/models/catalog" - // catalog.Resolve answers from the vendor catalog, which is empty until + modelruntime "github.com/Tencent/WeKnora/internal/models/runtime" + + // modelruntime.Resolve answers from the vendor catalog, which is empty until // the vendor packages have run their init. Without this import every row // resolves to the generic vendor: LKEAP and Volcengine would lose their // signed clients and Aliyun its native protocol. - _ "github.com/Tencent/WeKnora/internal/models/vendors" "github.com/Tencent/WeKnora/internal/types" ) @@ -94,7 +95,8 @@ type RerankerConfig struct { ModelName string Source types.ModelSource ModelID string - Provider string // Provider identifier: openai, aliyun, zhipu, siliconflow, jina, generic + Provider string // Provider identifier: openai, aliyun, zhipu, siliconflow, jina, generic + Spec *types.ModelSpecOverride `json:"spec,omitempty"` ExtraConfig map[string]string // CustomHeaders 允许在调用远程 API 时附加自定义 HTTP 请求头(类似 OpenAI Python SDK 的 extra_headers)。 CustomHeaders map[string]string @@ -116,6 +118,7 @@ func ConfigFromModel(m *types.Model, appID, appSecret string) *RerankerConfig { ModelName: m.Name, Source: m.Source, Provider: m.Parameters.Provider, + Spec: m.Parameters.Spec, ExtraConfig: m.Parameters.ExtraConfig, CustomHeaders: m.Parameters.CustomHeaders, AppID: appID, @@ -143,12 +146,13 @@ func newReranker(config *RerankerConfig) (Reranker, error) { if config == nil { return nil, fmt.Errorf("rerank config is nil") } - resolved, err := catalog.Resolve(catalog.Ref{ + resolved, err := modelruntime.Resolve(modelruntime.Ref{ Provider: config.Provider, Model: config.ModelName, BaseURL: config.BaseURL, ModelType: types.ModelTypeRerank, Extra: config.ExtraConfig, + Override: config.Spec, }) if err != nil { return nil, err @@ -158,50 +162,15 @@ func newReranker(config *RerankerConfig) (Reranker, error) { } vendor := resolved.Vendor - creds := catalog.Credentials{APIKey: config.APIKey, AppID: config.AppID, AppSecret: config.AppSecret} - if creds.APIKey == "" { - creds.APIKey = vendor.DefaultAPIKey - } - // A signing vendor with no identity pair would otherwise send unsigned - // requests and fail at the far end, which is a worse error than this one. - if vendor.Auth == catalog.AuthSigned { - if creds.AppID == "" { - return nil, fmt.Errorf("%s rerank: AppID is required", vendor.Name) - } - if creds.AppSecret == "" { - return nil, fmt.Errorf("%s rerank: AppSecret is required", vendor.Name) - } - } - // Vendor headers first so a user header cannot silently replace a vendor - // beta flag, matching chat.NewRemoteChat. - headers := make(map[string]string, len(vendor.Headers)+len(config.CustomHeaders)) - for k, v := range vendor.Headers { - headers[k] = v - } - for k, v := range config.CustomHeaders { - headers[k] = v - } - endpoint := api.Endpoint{ - BaseURL: resolved.BaseURL, - Model: resolved.RemoteModel, - ModelID: config.ModelID, - Auth: vendor.AuthFunc(vendor.API, creds), - Headers: headers, - // Most vendors have always run without a client deadline here and let - // the caller's context govern; the ones that declare a timeout get it. - Client: newRerankHTTPClient( - time.Duration(resolved.Rerank.RequestTimeout) * time.Second, - ), - } - if vendor.Endpoint != nil { - if url, query := vendor.Endpoint(catalog.EndpointRequest{ - BaseURL: resolved.BaseURL, - Model: resolved.RemoteModel, - ModelType: types.ModelTypeRerank, - Extra: config.ExtraConfig, - }); url != "" { - endpoint.URL, endpoint.Query = url, query - } + endpoint, err := resolved.Endpoint(types.ModelTypeRerank, modelruntime.Connection{ + ModelID: config.ModelID, + Credentials: api.Credentials{APIKey: config.APIKey, AppID: config.AppID, AppSecret: config.AppSecret}, + Headers: config.CustomHeaders, + Extra: config.ExtraConfig, + Client: newRerankHTTPClient(time.Duration(resolved.Rerank.RequestTimeout) * time.Second), + }) + if err != nil { + return nil, err } var client api.Reranker diff --git a/internal/models/rerank/sdk_clients_test.go b/internal/models/rerank/sdk_clients_test.go index b8d8c1b3..eb0bc8b4 100644 --- a/internal/models/rerank/sdk_clients_test.go +++ b/internal/models/rerank/sdk_clients_test.go @@ -5,10 +5,10 @@ import ( "encoding/json" "net/http" "net/http/httptest" - "strings" "testing" - "github.com/Tencent/WeKnora/internal/models/catalog" + modelruntime "github.com/Tencent/WeKnora/internal/models/runtime" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -45,7 +45,7 @@ func TestVolcengineClientOutboundShape(t *testing.T) { client, err := newVolcengineClient( &RerankerConfig{APIKey: "AKLT-test", AppSecret: "secret-test"}, - &catalog.Resolved{BaseURL: server.URL, RemoteModel: "doubao-seed-rerank"}, + &modelruntime.Resolved{BaseURL: server.URL, RemoteModel: "doubao-seed-rerank"}, ) require.NoError(t, err) @@ -80,7 +80,7 @@ func TestVolcengineClientSurfacesAnInBodyErrorCode(t *testing.T) { client, err := newVolcengineClient( &RerankerConfig{APIKey: "AKLT-test", AppSecret: "secret-test"}, - &catalog.Resolved{BaseURL: server.URL, RemoteModel: "doubao-seed-rerank"}, + &modelruntime.Resolved{BaseURL: server.URL, RemoteModel: "doubao-seed-rerank"}, ) require.NoError(t, err) @@ -100,7 +100,7 @@ func TestVolcengineClientRejectsAScoreCountMismatch(t *testing.T) { client, err := newVolcengineClient( &RerankerConfig{APIKey: "AKLT-test", AppSecret: "secret-test"}, - &catalog.Resolved{BaseURL: server.URL, RemoteModel: "doubao-seed-rerank"}, + &modelruntime.Resolved{BaseURL: server.URL, RemoteModel: "doubao-seed-rerank"}, ) require.NoError(t, err) @@ -114,7 +114,7 @@ func TestVolcengineClientRequiresAKAndSK(t *testing.T) { {AppSecret: "sk"}, {APIKey: "ak"}, } { - _, err := newVolcengineClient(cfg, &catalog.Resolved{BaseURL: "https://example.invalid"}) + _, err := newVolcengineClient(cfg, &modelruntime.Resolved{BaseURL: "https://example.invalid"}) require.Error(t, err) assert.Contains(t, err.Error(), "access key and secret key are required") } @@ -125,7 +125,7 @@ func TestLKEAPClientRequiresCredentials(t *testing.T) { {AppSecret: "sk"}, {APIKey: "id"}, } { - _, err := newLKEAPClient(cfg, &catalog.Resolved{}) + _, err := newLKEAPClient(cfg, &modelruntime.Resolved{}) require.Error(t, err) assert.Contains(t, err.Error(), "secret_id and secret_key are required") } @@ -136,20 +136,21 @@ func TestLKEAPClientRequiresCredentials(t *testing.T) { func TestLKEAPClientTakesTheSecretKeyFromExtraConfig(t *testing.T) { client, err := newLKEAPClient( &RerankerConfig{APIKey: "AKIDxxx", ExtraConfig: map[string]string{"secret_key": "sk"}}, - &catalog.Resolved{RemoteModel: "lke-reranker-base"}, + &modelruntime.Resolved{RemoteModel: "lke-reranker-base"}, ) require.NoError(t, err) require.NotNil(t, client) } func TestLKEAPClientFallsBackToTheDefaultModel(t *testing.T) { + upstream := newUpstream(t) client, err := newLKEAPClient( &RerankerConfig{APIKey: "AKIDxxx", AppSecret: "sk"}, - &catalog.Resolved{}, + &modelruntime.Resolved{}, ) require.NoError(t, err) - inner, ok := client.(*lkeapClient) - require.True(t, ok) - assert.Equal(t, LKEAPDefaultRerankModel, inner.modelName) - assert.False(t, strings.Contains(inner.modelName, " ")) + _, err = client.Rerank(context.Background(), "q", []string{"d"}) + require.NoError(t, err) + require.Len(t, upstream.requests, 1) + assert.Equal(t, LKEAPDefaultRerankModel, upstream.requests[0].body["Model"]) } diff --git a/internal/models/rerank/volcengine_reranker.go b/internal/models/rerank/volcengine_reranker.go index 2401b716..eb311ec3 100644 --- a/internal/models/rerank/volcengine_reranker.go +++ b/internal/models/rerank/volcengine_reranker.go @@ -1,114 +1,36 @@ package rerank import ( - "context" - "fmt" "strings" "time" "github.com/Tencent/WeKnora/internal/models/api" - "github.com/Tencent/WeKnora/internal/models/catalog" - "github.com/volcengine/vikingdb-go-sdk/knowledge" - knowledgemodel "github.com/volcengine/vikingdb-go-sdk/knowledge/model" + "github.com/Tencent/WeKnora/internal/models/api/volcengineknowledge" + modelruntime "github.com/Tencent/WeKnora/internal/models/runtime" ) const ( - volcengineRerankDefaultModel = "doubao-seed-rerank" - volcengineRerankDefaultRegion = "cn-beijing" - // The console's default instruction, verbatim: "如需对齐控制台效果,请使用 - // 相同指令" (https://docs.volcengine.com/docs/vector_database_vikingdb/Rerank). - volcengineRerankDefaultInstruction = "Whether the document answers the query " + - "or matches the content retrieval intent" + volcengineRerankDefaultModel = volcengineknowledge.DefaultModel + volcengineRerankDefaultRegion = volcengineknowledge.DefaultRegion + volcengineRerankDefaultInstruction = volcengineknowledge.DefaultInstruction ) -// volcengineClient calls the managed Knowledge Service rerank through the -// vikingdb SDK, which owns the AK/SK signing. It implements api.Reranker and -// nothing else: the 200-document ceiling and the batch concurrency are -// declared on the vendor and enforced by protocolReranker. -type volcengineClient struct { - modelName string - instruction string - client *knowledge.Client -} - -func newVolcengineClient(config *RerankerConfig, resolved *catalog.Resolved) (api.Reranker, error) { - accessKey := strings.TrimSpace(config.APIKey) - secretKey := strings.TrimSpace(config.AppSecret) - if secretKey == "" && config.ExtraConfig != nil { - secretKey = strings.TrimSpace(config.ExtraConfig["secret_key"]) +func newVolcengineClient(config *RerankerConfig, resolved *modelruntime.Resolved) (api.Reranker, error) { + secret := strings.TrimSpace(config.AppSecret) + if secret == "" { + secret = config.ExtraConfig["secret_key"] } - if accessKey == "" || secretKey == "" { - return nil, fmt.Errorf("access key and secret key are required for Volcengine rerank") - } - - // The catalog supplies the vendor's Knowledge Service host when the row - // names none. - baseURL := resolved.BaseURL - - modelName := strings.TrimSpace(resolved.RemoteModel) - if modelName == "" { - modelName = volcengineRerankDefaultModel - } - region := volcengineRerankDefaultRegion - instruction := volcengineRerankDefaultInstruction - if config.ExtraConfig != nil { - if value := strings.TrimSpace(config.ExtraConfig["region"]); value != "" { - region = value - } - if value := strings.TrimSpace(config.ExtraConfig["instruction"]); value != "" { - instruction = value - } - } - - client, err := knowledge.New( - knowledge.AuthIAM(accessKey, secretKey), - knowledge.WithEndpoint(baseURL), - knowledge.WithRegion(region), - knowledge.WithTimeout(30*time.Second), - knowledge.WithHTTPClient(newRerankHTTPClient(30*time.Second)), - knowledge.WithMaxRetries(1), + return volcengineknowledge.New( + volcengineknowledge.Config{ + AccessKey: config.APIKey, + SecretKey: secret, + BaseURL: resolved.BaseURL, + Model: resolved.RemoteModel, + Region: config.ExtraConfig["region"], + Instruction: config.ExtraConfig["instruction"], + Client: newRerankHTTPClient( + 30 * time.Second, + ), + }, ) - if err != nil { - return nil, fmt.Errorf("create Volcengine rerank client: %w", err) - } - return &volcengineClient{modelName: modelName, instruction: instruction, client: client}, nil -} - -// Rerank scores one batch. Every document is paired with the same query and -// instruction, and the reply is a score list in input order. -func (r *volcengineClient) Rerank( - ctx context.Context, query string, documents []string, -) ([]api.RerankResult, error) { - data := make([]knowledgemodel.RerankDataItem, len(documents)) - for i := range documents { - data[i] = knowledgemodel.RerankDataItem{Query: query, Content: &documents[i]} - } - request := knowledgemodel.RerankRequest{ - Datas: data, - RerankModel: &r.modelName, - RerankInstruction: &r.instruction, - } - - response, err := r.client.Rerank(ctx, request) - if err != nil { - return nil, fmt.Errorf("call Volcengine rerank: %w", err) - } - if response == nil || response.Data == nil { - return nil, fmt.Errorf("Volcengine rerank returned an empty response") - } - if response.Code != 0 { - return nil, fmt.Errorf("Volcengine rerank API error %d: %s", response.Code, response.Message) - } - if len(response.Data.Scores) != len(documents) { - return nil, fmt.Errorf( - "Volcengine rerank score count mismatch: got %d scores for %d documents", - len(response.Data.Scores), len(documents), - ) - } - - results := make([]api.RerankResult, len(documents)) - for i, score := range response.Data.Scores { - results[i] = api.RerankResult{Index: i, Score: score, Text: documents[i]} - } - return results, nil } diff --git a/internal/models/rerank/wire_test.go b/internal/models/rerank/wire_test.go index 600c9676..bb6b1ddd 100644 --- a/internal/models/rerank/wire_test.go +++ b/internal/models/rerank/wire_test.go @@ -13,7 +13,8 @@ import ( "testing" "unicode/utf8" - "github.com/Tencent/WeKnora/internal/models/catalog" + "github.com/Tencent/WeKnora/internal/models" + modelruntime "github.com/Tencent/WeKnora/internal/models/runtime" "github.com/Tencent/WeKnora/internal/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -210,7 +211,7 @@ func TestRerankWireFormatPerVendor(t *testing.T) { { name: "gpustack sends the row's truncation budget and answers logits", provider: "gpustack", model: "bge-reranker-v2-m3", base: "/v1", - extra: map[string]string{catalog.ExtraTruncatePromptTokens: "256"}, + extra: map[string]string{models.ExtraTruncatePromptTokens: "256"}, cohereLogs: true, wantPath: "/v1/rerank", wantAuth: [2]string{"Authorization", "Bearer k"}, wantBody: cohere("bge-reranker-v2-m3", three, map[string]any{"truncate_prompt_tokens": float64(256)}), @@ -351,7 +352,7 @@ func TestRerankWireFormatPerVendor(t *testing.T) { // OpenAI has no rerank API, so the vendor does not offer the type. func TestOpenAIDoesNotOfferRerank(t *testing.T) { - v, ok := catalog.Get("openai") + v, ok := modelruntime.Get("openai") require.True(t, ok) assert.False(t, v.SupportsType(types.ModelTypeRerank)) } diff --git a/internal/models/catalog/catalog_test.go b/internal/models/runtime/catalog_test.go similarity index 65% rename from internal/models/catalog/catalog_test.go rename to internal/models/runtime/catalog_test.go index bfc675e8..fcecaafa 100644 --- a/internal/models/catalog/catalog_test.go +++ b/internal/models/runtime/catalog_test.go @@ -1,10 +1,13 @@ -package catalog +package runtime_test import ( "encoding/json" "testing" + "github.com/Tencent/WeKnora/internal/models" "github.com/Tencent/WeKnora/internal/models/api" + "github.com/Tencent/WeKnora/internal/models/providers" + modelruntime "github.com/Tencent/WeKnora/internal/models/runtime" "github.com/Tencent/WeKnora/internal/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -12,16 +15,18 @@ import ( func registerTestVendors(t *testing.T) { t.Helper() - t.Cleanup(reset()) - Register(&Vendor{ - ID: GenericID, Name: "Custom", API: api.APIOpenAICompletions, + before := modelruntime.SnapshotCurrent() + t.Cleanup(func() { modelruntime.RestoreSnapshot(before) }) + modelruntime.Register(&providers.Definition{ + ID: providers.GenericID, Name: "Custom", API: api.APIOpenAICompletions, DefaultBaseURLs: map[types.ModelType]string{}, ModelTypes: []types.ModelType{types.ModelTypeKnowledgeQA}, - Compat: VendorCompat{OpenAICompletions: OpenAICompletionsCompat{ - MaxTokensField: Ptr("max_tokens"), ThinkingFormat: Ptr(ThinkingFormatChatTemplateKwargs), + Compat: providers.VendorCompat{OpenAICompletions: api.OpenAICompletionsCompat{ + MaxTokensField: api.Ptr("max_tokens"), + ThinkingFormat: api.Ptr(api.ThinkingFormatChatTemplateKwargs), }}, }) - Register(&Vendor{ + modelruntime.Register(&providers.Definition{ ID: "acme", Name: "Acme", Names: map[string]string{"zh-CN": "极目"}, API: api.APIOpenAICompletions, RequiresAuth: true, @@ -31,29 +36,28 @@ func registerTestVendors(t *testing.T) { types.ModelTypeRerank: "https://api.acme.ai/rerank", }, ModelTypes: []types.ModelType{types.ModelTypeKnowledgeQA, types.ModelTypeRerank}, - Compat: VendorCompat{OpenAICompletions: OpenAICompletionsCompat{ - ThinkingFormat: Ptr(ThinkingFormatThinkingType), - SupportsReasoningEffort: Ptr(true), - MaxTokensField: Ptr("max_tokens"), + Compat: providers.VendorCompat{OpenAICompletions: api.OpenAICompletionsCompat{ + ThinkingFormat: api.Ptr(api.ThinkingFormatThinkingType), + SupportsReasoningEffort: api.Ptr(true), + MaxTokensField: api.Ptr("max_tokens"), }}, ThinkingLevels: api.ThinkingLevelMap{api.ReasoningMax: api.StringPtr("max")}, - Models: []ModelSpec{ - { - ID: "acme-pro", Name: "Acme Pro", Reasoning: true, - Input: []string{"text", "image"}, ContextWindow: 200000, - Compat: json.RawMessage(`{"supports_temperature": false}`), - }, - {ID: "acme-r1", Reasoning: true, ThinkingLevels: api.ThinkingLevelMap{api.ReasoningOff: nil}}, - {Match: "acme-lite*", Reasoning: false, Compat: json.RawMessage(`{"thinking_format": "none"}`)}, - {Match: "acme-lite-vision*", Input: []string{"text", "image"}}, - {ID: "acme-embed", Type: types.ModelTypeEmbedding, Dimension: 1024}, - { - ID: "acme-claude", API: api.APIAnthropicMessages, Reasoning: true, - Compat: json.RawMessage(`{"thinking_mode": "adaptive", "supports_effort": true}`), - }, + }, []models.ModelSpec{ + { + ID: "acme-pro", Name: "Acme Pro", Reasoning: true, + Input: []string{"text", "image"}, ContextWindow: 200000, + Compat: json.RawMessage(`{"supports_temperature": false}`), }, - }) - Register(&Vendor{ + {ID: "acme-r1", Reasoning: true, ThinkingLevels: api.ThinkingLevelMap{api.ReasoningOff: nil}}, + {Match: "acme-lite*", Reasoning: false, Compat: json.RawMessage(`{"thinking_format": "none"}`)}, + {Match: "acme-lite-vision*", Input: []string{"text", "image"}}, + {ID: "acme-embed", Type: types.ModelTypeEmbedding, Dimension: 1024}, + { + ID: "acme-claude", API: api.APIAnthropicMessages, Reasoning: true, + Compat: json.RawMessage(`{"thinking_mode": "adaptive", "supports_effort": true}`), + }, + }...) + modelruntime.Register(&providers.Definition{ ID: "tencent-lkeap", Name: "LKEAP", API: api.APIOpenAICompletions, URLPatterns: []string{"api.lkeap.cloud.tencent.com", "tencent"}, DefaultBaseURLs: map[types.ModelType]string{ @@ -65,7 +69,7 @@ func registerTestVendors(t *testing.T) { func TestFindModel_ExactAliasAndGlob(t *testing.T) { registerTestVendors(t) - v, _ := Get("acme") + v, _ := modelruntime.Get("acme") chat := types.ModelTypeKnowledgeQA m, ok := v.FindModel("ACME-PRO", chat) @@ -88,7 +92,7 @@ func TestFindModel_ExactAliasAndGlob(t *testing.T) { // model that accepts images, so it sees the chat entries. func TestFindModel_IsTyped(t *testing.T) { registerTestVendors(t) - v, _ := Get("acme") + v, _ := modelruntime.Get("acme") _, ok := v.FindModel("acme-embed", types.ModelTypeKnowledgeQA) assert.False(t, ok, "a chat row must not pick up an embedding entry") @@ -108,7 +112,13 @@ func TestFindModel_IsTyped(t *testing.T) { func TestResolve_ModelNameInsideAChatGlobStillResolvesForOtherTypes(t *testing.T) { registerTestVendors(t) for _, modelType := range []types.ModelType{types.ModelTypeEmbedding, types.ModelTypeRerank} { - r, err := Resolve(Ref{Provider: "acme", Model: "acme-lite-embed", ModelType: modelType}) + r, err := modelruntime.Resolve( + modelruntime.Ref{ + Provider: "acme", + Model: "acme-lite-embed", + ModelType: modelType, + }, + ) require.NoError(t, err, modelType) assert.False(t, r.Cataloged, modelType) } @@ -116,22 +126,22 @@ func TestResolve_ModelNameInsideAChatGlobStillResolvesForOtherTypes(t *testing.T func TestDetectByURL_LongestPatternWins(t *testing.T) { registerTestVendors(t) - assert.Equal(t, "tencent-lkeap", DetectByURL("https://api.lkeap.cloud.tencent.com/v1")) - assert.Equal(t, "acme", DetectByURL("https://api.acme.ai/v1")) - assert.Equal(t, GenericID, DetectByURL("http://localhost:8000/v1")) - assert.Equal(t, GenericID, DetectByURL("")) + assert.Equal(t, "tencent-lkeap", modelruntime.DetectByURL("https://api.lkeap.cloud.tencent.com/v1")) + assert.Equal(t, "acme", modelruntime.DetectByURL("https://api.acme.ai/v1")) + assert.Equal(t, providers.GenericID, modelruntime.DetectByURL("http://localhost:8000/v1")) + assert.Equal(t, providers.GenericID, modelruntime.DetectByURL("")) } func TestResolve_MergesVendorModelAndOverrideLayers(t *testing.T) { registerTestVendors(t) - r, err := Resolve(Ref{Provider: "acme", Model: "acme-pro"}) + r, err := modelruntime.Resolve(modelruntime.Ref{Provider: "acme", Model: "acme-pro"}) require.NoError(t, err) assert.True(t, r.Cataloged) assert.Equal(t, api.APIOpenAICompletions, r.API) assert.Equal(t, "https://api.acme.ai/v1", r.BaseURL, "default base URL is filled in") assert.Equal(t, "max_tokens", r.OpenAICompletions.MaxTokensField) - assert.Equal(t, ThinkingFormatThinkingType, r.OpenAICompletions.ThinkingFormat) + assert.Equal(t, api.ThinkingFormatThinkingType, r.OpenAICompletions.ThinkingFormat) assert.True(t, r.OpenAICompletions.SupportsReasoningEffort) assert.False(t, r.OpenAICompletions.SupportsTemperature, "model compat overrides the protocol default") assert.True(t, r.OpenAICompletions.SupportsUsageInStreaming, "untouched defaults survive") @@ -147,7 +157,7 @@ func TestResolve_MergesVendorModelAndOverrideLayers(t *testing.T) { // Row-level override wins over everything. on := true - r, err = Resolve(Ref{ + r, err = modelruntime.Resolve(modelruntime.Ref{ Provider: "acme", Model: "acme-pro", BaseURL: "https://proxy.example.com/v1/", Override: &types.ModelSpecOverride{ ContextWindow: 1000, @@ -167,18 +177,23 @@ func TestResolve_MergesVendorModelAndOverrideLayers(t *testing.T) { func TestResolve_UnknownModelAndVendorDegradeToGeneric(t *testing.T) { registerTestVendors(t) - r, err := Resolve(Ref{Provider: "acme", Model: "brand-new"}) + r, err := modelruntime.Resolve(modelruntime.Ref{Provider: "acme", Model: "brand-new"}) require.NoError(t, err) assert.False(t, r.Cataloged) assert.Equal(t, "brand-new", r.Spec.ID) - assert.Equal(t, ThinkingFormatThinkingType, r.OpenAICompletions.ThinkingFormat, "vendor defaults still apply") + assert.Equal( + t, + api.ThinkingFormatThinkingType, + r.OpenAICompletions.ThinkingFormat, + "vendor defaults still apply", + ) - r, err = Resolve(Ref{Provider: "nope", Model: "x", BaseURL: "http://localhost:8000/v1"}) + r, err = modelruntime.Resolve(modelruntime.Ref{Provider: "nope", Model: "x", BaseURL: "http://localhost:8000/v1"}) require.NoError(t, err) - assert.Equal(t, GenericID, r.Vendor.ID) - assert.Equal(t, ThinkingFormatChatTemplateKwargs, r.OpenAICompletions.ThinkingFormat) + assert.Equal(t, providers.GenericID, r.Vendor.ID) + assert.Equal(t, api.ThinkingFormatChatTemplateKwargs, r.OpenAICompletions.ThinkingFormat) - r, err = Resolve(Ref{Model: "x", BaseURL: "https://api.acme.ai/v1"}) + r, err = modelruntime.Resolve(modelruntime.Ref{Model: "x", BaseURL: "https://api.acme.ai/v1"}) require.NoError(t, err) assert.Equal(t, "acme", r.Vendor.ID, "provider detected from URL when empty") } @@ -186,43 +201,73 @@ func TestResolve_UnknownModelAndVendorDegradeToGeneric(t *testing.T) { func TestResolve_ProtocolInference(t *testing.T) { registerTestVendors(t) - r, err := Resolve(Ref{Provider: "acme", Model: "acme-claude"}) + r, err := modelruntime.Resolve(modelruntime.Ref{Provider: "acme", Model: "acme-claude"}) require.NoError(t, err) assert.Equal(t, api.APIAnthropicMessages, r.API) - assert.Equal(t, AnthropicThinkingAdaptive, r.AnthropicMessages.ThinkingMode) + assert.Equal(t, api.AnthropicThinkingAdaptive, r.AnthropicMessages.ThinkingMode) assert.True(t, r.AnthropicMessages.SupportsEffort) assert.Equal(t, "thinking.adaptive", r.Capabilities().ThinkingFormat) - r, err = Resolve(Ref{Provider: "acme", Model: "acme-pro", BaseURL: "https://api.acme.ai/anthropic"}) + r, err = modelruntime.Resolve( + modelruntime.Ref{ + Provider: "acme", + Model: "acme-pro", + BaseURL: "https://api.acme.ai/anthropic", + }, + ) require.NoError(t, err) assert.Equal(t, api.APIAnthropicMessages, r.API, "/anthropic suffix switches protocol") - r, err = Resolve(Ref{Provider: "acme", Model: "acme-pro", Extra: map[string]string{ExtraAPI: "openai-responses"}}) + r, err = modelruntime.Resolve( + modelruntime.Ref{ + Provider: "acme", + Model: "acme-pro", + Extra: map[string]string{ + models.ExtraAPI: "openai-responses", + }, + }, + ) require.NoError(t, err) assert.Equal(t, api.APIOpenAIResponses, r.API, "extra_config.api forces the protocol") - _, err = Resolve(Ref{Provider: "acme", Model: "acme-pro", Extra: map[string]string{ExtraAPI: "bogus"}}) + _, err = modelruntime.Resolve( + modelruntime.Ref{ + Provider: "acme", + Model: "acme-pro", + Extra: map[string]string{ + models.ExtraAPI: "bogus", + }, + }, + ) require.Error(t, err) } func TestResolve_LegacyThinkingControlAndRemoteModelName(t *testing.T) { registerTestVendors(t) - r, err := Resolve(Ref{Provider: "acme", Model: "acme-pro", Extra: map[string]string{ - ExtraThinkingControl: "enable_thinking", - ExtraRemoteModelName: "acme-pro-2026", + r, err := modelruntime.Resolve(modelruntime.Ref{Provider: "acme", Model: "acme-pro", Extra: map[string]string{ + models.ExtraThinkingControl: "enable_thinking", + models.ExtraRemoteModelName: "acme-pro-2026", }}) require.NoError(t, err) - assert.Equal(t, ThinkingFormatEnableThinking, r.OpenAICompletions.ThinkingFormat) + assert.Equal(t, api.ThinkingFormatEnableThinking, r.OpenAICompletions.ThinkingFormat) assert.Equal(t, "acme-pro-2026", r.RemoteModel) - r, err = Resolve(Ref{Provider: "acme", Model: "acme-pro", Extra: map[string]string{ExtraThinkingControl: "none"}}) + r, err = modelruntime.Resolve( + modelruntime.Ref{ + Provider: "acme", + Model: "acme-pro", + Extra: map[string]string{ + models.ExtraThinkingControl: "none", + }, + }, + ) require.NoError(t, err) assert.Empty(t, r.Capabilities().ThinkingLevels, "none disables the selector") } func TestResolve_AlwaysOnModelCannotBeSwitchedOff(t *testing.T) { registerTestVendors(t) - r, err := Resolve(Ref{Provider: "acme", Model: "acme-r1"}) + r, err := modelruntime.Resolve(modelruntime.Ref{Provider: "acme", Model: "acme-r1"}) require.NoError(t, err) assert.False(t, r.ThinkingLevels.Supports(api.ReasoningOff)) assert.NotContains(t, r.Capabilities().ThinkingLevels, api.ReasoningOff) @@ -230,16 +275,22 @@ func TestResolve_AlwaysOnModelCannotBeSwitchedOff(t *testing.T) { func TestResolve_RejectsUnknownCompatKeys(t *testing.T) { registerTestVendors(t) - _, err := Resolve(Ref{Provider: "acme", Model: "acme-pro", Override: &types.ModelSpecOverride{ - Compat: map[string]any{"max_token_field": "max_tokens"}, - }}) + _, err := modelruntime.Resolve( + modelruntime.Ref{ + Provider: "acme", + Model: "acme-pro", + Override: &types.ModelSpecOverride{ + Compat: map[string]any{"max_token_field": "max_tokens"}, + }, + }, + ) require.Error(t, err) assert.Contains(t, err.Error(), "max_token_field") } func TestModelsByType(t *testing.T) { registerTestVendors(t) - v, _ := Get("acme") + v, _ := modelruntime.Get("acme") chat := v.ModelsByType(types.ModelTypeKnowledgeQA) ids := make([]string, 0, len(chat)) for _, m := range chat { @@ -277,9 +328,9 @@ func TestApplyOverlay(t *testing.T) { } } }` - require.NoError(t, ApplyOverlay([]byte(overlay), t.TempDir())) + require.NoError(t, modelruntime.ApplyOverlay([]byte(overlay), t.TempDir())) - acme, ok := Get("acme") + acme, ok := modelruntime.Get("acme") require.True(t, ok) assert.Equal(t, "https://acme.internal/v1", acme.GetDefaultURL(types.ModelTypeKnowledgeQA)) assert.Equal(t, "https://api.acme.ai/rerank", acme.GetDefaultURL(types.ModelTypeRerank), "other URLs untouched") @@ -288,30 +339,39 @@ func TestApplyOverlay(t *testing.T) { assert.Equal(t, "max", acme.ThinkingLevels.Value(api.ReasoningXHigh)) assert.Equal(t, "max", acme.ThinkingLevels.Value(api.ReasoningMax), "existing levels kept") - r, err := Resolve(Ref{Provider: "acme", Model: "acme-ultra"}) + r, err := modelruntime.Resolve(modelruntime.Ref{Provider: "acme", Model: "acme-ultra"}) require.NoError(t, err) assert.True(t, r.Cataloged) assert.Equal(t, 400000, r.Spec.ContextWindow) - r, err = Resolve(Ref{Provider: "acme", Model: "acme-pro"}) + r, err = modelruntime.Resolve(modelruntime.Ref{Provider: "acme", Model: "acme-pro"}) require.NoError(t, err) assert.Equal(t, 123, r.Spec.ContextWindow) assert.True(t, r.OpenAICompletions.SupportsTemperature, "model_overrides compat merges over the built-in compat") - lab, ok := Get("my-vllm") + lab, ok := modelruntime.Get("my-vllm") require.True(t, ok) assert.Equal(t, "实验室 vLLM", lab.LocalizedName("zh-CN")) assert.Equal(t, "Lab vLLM", lab.LocalizedName("en-US")) assert.False(t, lab.RequiresAuth) - r, err = Resolve(Ref{Provider: "my-vllm", Model: "Qwen/Qwen3-32B"}) + r, err = modelruntime.Resolve(modelruntime.Ref{Provider: "my-vllm", Model: "Qwen/Qwen3-32B"}) require.NoError(t, err) - assert.Equal(t, ThinkingFormatChatTemplateKwargs, r.OpenAICompletions.ThinkingFormat) + assert.Equal(t, api.ThinkingFormatChatTemplateKwargs, r.OpenAICompletions.ThinkingFormat) assert.Equal(t, "max_tokens", r.OpenAICompletions.MaxTokensField) assert.True(t, r.Spec.Reasoning) assert.Equal(t, "http://vllm.lab:8000/v1", r.BaseURL) - assert.Error(t, ApplyOverlay([]byte(`{"providers": {"x": {"bogus": 1}}}`), t.TempDir()), "unknown keys rejected") - assert.Error(t, ApplyOverlay([]byte(`{"providers": {"x": {"api": "nope"}}}`), t.TempDir())) + assert.Error( + t, + modelruntime.ApplyOverlay( + []byte( + `{"providers": {"x": {"bogus": 1}}}`, + ), + t.TempDir(), + ), + "unknown keys rejected", + ) + assert.Error(t, modelruntime.ApplyOverlay([]byte(`{"providers": {"x": {"api": "nope"}}}`), t.TempDir())) } func TestThinkingLevelMap(t *testing.T) { diff --git a/internal/models/runtime/compat.go b/internal/models/runtime/compat.go new file mode 100644 index 00000000..9ad559b9 --- /dev/null +++ b/internal/models/runtime/compat.go @@ -0,0 +1,73 @@ +package runtime + +import ( + "bytes" + "encoding/json" + "fmt" + "reflect" + + "github.com/Tencent/WeKnora/internal/models/internal/configcopy" +) + +// ApplyCompat writes the set fields of an overlay struct onto a settings struct +// with matching field names, dereferencing pointers. Slices and maps +// replace the default wholesale (no element merge) except map[string]any +// ExtraBody-style fields, which merge key by key. +func ApplyCompat(settings any, compat any) { + sv := reflect.ValueOf(settings).Elem() + cv := reflect.ValueOf(compat).Elem() + ct := cv.Type() + for i := 0; i < cv.NumField(); i++ { + field := ct.Field(i) + if !field.IsExported() { + continue + } + target := sv.FieldByName(field.Name) + if !target.IsValid() { + panic(fmt.Sprintf("catalog: overlay field %s.%s has no settings counterpart", ct.Name(), field.Name)) + } + f := cv.Field(i) + switch f.Kind() { + case reflect.Pointer: + if f.IsNil() { + continue + } + if target.Kind() == reflect.Pointer { + target.Set(configcopy.Value(f)) + } else { + target.Set(configcopy.Value(f.Elem())) + } + case reflect.Slice: + if f.Len() > 0 { + target.Set(configcopy.Value(f)) + } + case reflect.Map: + if f.Len() == 0 { + continue + } + if target.IsNil() { + target.Set(reflect.MakeMap(target.Type())) + } + iter := f.MapRange() + for iter.Next() { + target.SetMapIndex(iter.Key(), configcopy.Value(iter.Value())) + } + } + } +} + +// DecodeCompat unmarshals a flat compat object into the overlay type for an +// API. Unknown keys are rejected so typos in models.json surface early. +func DecodeCompat(raw json.RawMessage, into any) error { + if len(raw) == 0 { + return nil + } + dec := json.NewDecoder(bytesReader(raw)) + dec.DisallowUnknownFields() + if err := dec.Decode(into); err != nil { + return fmt.Errorf("decode compat: %w", err) + } + return nil +} + +func bytesReader(b []byte) *bytes.Reader { return bytes.NewReader(b) } diff --git a/internal/models/runtime/connection.go b/internal/models/runtime/connection.go new file mode 100644 index 00000000..c55e2da7 --- /dev/null +++ b/internal/models/runtime/connection.go @@ -0,0 +1,78 @@ +package runtime + +import ( + "fmt" + "net/http" + "strings" + + "github.com/Tencent/WeKnora/internal/models/api" + "github.com/Tencent/WeKnora/internal/models/providers" + "github.com/Tencent/WeKnora/internal/types" +) + +// Connection contains only one configured model's credentials and transport +// settings. It is never cached in the provider registry or model catalog. +type Connection struct { + ModelID string + Credentials api.Credentials + Headers map[string]string + Extra map[string]string + Client *http.Client +} + +// Endpoint assembles authentication, headers and vendor endpoint routing for +// every capability. Protocol clients receive the result without knowing vendors. +func (r *Resolved) Endpoint(kind types.ModelType, c Connection) (api.Endpoint, error) { + v := r.Vendor + creds := c.Credentials + if creds.APIKey == "" { + creds.APIKey = v.DefaultAPIKey + } + protocol := v.API + label := strings.ToLower(string(kind)) + if kind == types.ModelTypeKnowledgeQA || kind == types.ModelTypeVLLM { + protocol, label = r.API, "provider" + } + if v.AuthStyleFor(protocol) == providers.AuthSigned { + if creds.AppID == "" { + return api.Endpoint{}, fmt.Errorf("%s %s: AppID is required", v.Name, label) + } + if creds.AppSecret == "" { + return api.Endpoint{}, fmt.Errorf("%s %s: AppSecret is required", v.Name, label) + } + } else if v.RequiresAuth && protocol == api.APIAnthropicMessages && + (kind == types.ModelTypeKnowledgeQA || kind == types.ModelTypeVLLM) && strings.TrimSpace(creds.APIKey) == "" { + return api.Endpoint{}, fmt.Errorf("%s provider: API key is required", v.Name) + } + headers := make(map[string]string, len(v.Headers)+len(c.Headers)) + for k, val := range v.Headers { + headers[k] = val + } + for k, val := range c.Headers { + headers[k] = val + } + ep := api.Endpoint{ + BaseURL: r.BaseURL, Model: r.RemoteModel, ModelID: c.ModelID, + Auth: v.AuthFunc(protocol, creds), Headers: headers, Client: c.Client, + } + if v.Endpoint != nil { + req := providers.EndpointRequest{ + BaseURL: r.BaseURL, + Model: r.RemoteModel, + ModelType: kind, + API: protocol, + Extra: c.Extra, + } + if kind == types.ModelTypeEmbedding { + req.EmbeddingAPI = r.EmbeddingAPI + } + // Preserve historical rerank hook input; its routing uses ModelType. + if kind == types.ModelTypeRerank { + req.API = "" + } + if url, query := v.Endpoint(req); url != "" { + ep.URL, ep.Query = url, query + } + } + return ep, nil +} diff --git a/internal/models/runtime/icon_test.go b/internal/models/runtime/icon_test.go new file mode 100644 index 00000000..f1ee6974 --- /dev/null +++ b/internal/models/runtime/icon_test.go @@ -0,0 +1,26 @@ +package runtime + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestLooksLikeSVG(t *testing.T) { + for _, in := range []string{ + ``, + " \n", + "\ufeff\nx", + "y", + "", + } { + assert.True(t, looksLikeSVG([]byte(in)), "want SVG: %q", in) + } + for _, in := range []string{ + "", " ", "", "not markup at all", + "", "", "x", - "y", - "", - } { - assert.True(t, looksLikeSVG([]byte(in)), "want SVG: %q", in) - } - for _, in := range []string{ - "", " ", "", "not markup at all", - "", "", " CF["ConfigFromModel
(chat / embedding / rerank / vlm / asr)"] CF --> F{"工厂函数
NewChat / NewEmbedder / ..."} F -->|"source = local"| OL["OllamaService
(internal/models/utils/ollama)"] - F -->|"source = remote"| PD{"catalog.Resolve
(厂商 + 模型 + 叠加 + 行覆盖)"} + F -->|"source = remote"| PD{"runtime.Resolve
(厂商 + 模型 + 叠加 + 行覆盖)"} PD -->|"anthropic-messages"| AN["anthropicmessages.Client"] PD -->|"openai-responses"| RS["openairesponses.Client"] PD -->|"google-generative-ai"| GG["googlegenai.Client"] @@ -349,3 +349,6 @@ return wrapChatConcurrency(c, config.MaxConcurrency, err) 仓库根目录的 `rerank_server_demo.py` 是一个**自托管 Rerank 服务的最小参考实现**:FastAPI + HuggingFace `AutoModelForSequenceClassification`,暴露 `POST /rerank`,请求体 `{query, documents}`,返回 `{"results": [{index, document: {text}, score}]}`。 示例服务返回 `score` 字段,可用于验证客户端兼容性。`RankResult.UnmarshalJSON` 优先读取 `relevance_score`,缺失时读取 `score`;`DocumentInfo.UnmarshalJSON` 同时接受字符串和 `{text}` 对象。遵循此协议的私有重排服务可通过 `generic` provider 接入。 + + +重构后的配置边界:每个模型仍单独保存 URL、API Key、额外参数和 `spec`,不新增连接实体,不修改模型 ID 或历史引用。部署覆盖每次从内置定义重新构建;通过 `runtime.Initialize` / `runtime.Reload` 校验后整体发布,失败保留旧版本。暂不监听文件变更,修改部署文件后仍需重启服务。