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
main
lyingbug 2026-09-23 14:20:08 +08:00 committed by GitHub
parent 653307b5c7
commit e179f44445
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
203 changed files with 16811 additions and 3380 deletions

View File

@ -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

View File

@ -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

View File

@ -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<InitializationConfig
// customHeaders / extraConfig / interfaceType 对应后端 ModelTestRequest 里的同名字段,
// 会被透传给真正的模型装配流程,保证测试连接与生产调用走完全相同的路径。
interface BaseModelTestPayload {
spec?: ModelSpecOverride;
customHeaders?: Record<string, string>;
extraConfig?: Record<string, string>;
interfaceType?: string;
@ -690,6 +691,7 @@ export function listModelProviders(modelType?: string): Promise<ModelProviderOpt
}
export interface ResolveModelCatalogParams {
spec?: ModelSpecOverride;
provider: string;
model?: string;
base_url?: string;
@ -700,7 +702,7 @@ export interface ResolveModelCatalogParams {
// Vendor-declared non-secret extra fields (Azure api_version, ...) are
// forwarded by key so the preview resolves the same request the runtime
// will make. The backend only accepts keys the vendor declares.
[extraField: string]: string | undefined;
[extraField: string]: string | ModelSpecOverride | undefined;
}
// 目录解析结果。Mirrors handler.ResolveModelCatalog response data.
@ -722,14 +724,8 @@ export interface ResolvedModelCatalog {
// 解析模型的有效接入配置(协议、思考等级、上下文窗口等),供编辑器实时展示。
export function resolveModelCatalog(params: ResolveModelCatalogParams): Promise<ResolvedModelCatalog> {
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);

View File

@ -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() } : {}),
}

View File

@ -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);

View File

@ -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() }
})

View File

@ -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/)
})

View File

@ -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);

View File

@ -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"])

View File

@ -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 != "" {

View File

@ -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)

View File

@ -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)
}

View File

@ -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 {

View File

@ -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"},
},

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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 <img src>.
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,

View File

@ -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.

View File

@ -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},

View File

@ -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)
}
}

View File

@ -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},
},
})

View File

@ -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")}
})

View File

@ -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)
}

View File

@ -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
}

View File

@ -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,

View File

@ -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.

View File

@ -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"})

View File

@ -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
}

View File

@ -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 }

View File

@ -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
}

View File

@ -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,
})
}

View File

@ -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.

View File

@ -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,

View File

@ -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 ""
}

View File

@ -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
}

View File

@ -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")

View File

@ -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"),

View File

@ -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

View File

@ -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.

View File

@ -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")

View File

@ -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

View File

@ -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"])
}

View File

@ -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)

View File

@ -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 != "" {

View File

@ -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

View File

@ -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")

View File

@ -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",
})

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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,
}
}

View File

@ -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
}

View File

@ -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

View File

@ -5,7 +5,7 @@
// tool-call assembly, prompt-cache bookkeeping and usage logging.
//
// Protocol packages live under api/<protocol>; 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

View File

@ -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
}

View File

@ -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,
}

View File

@ -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")
}

View File

@ -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

View File

@ -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",
})

View File

@ -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"`
}

View File

@ -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])
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -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
}

View File

@ -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
}
}

View File

@ -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 {

View File

@ -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"
)

View File

@ -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"

View File

@ -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")
}

View File

@ -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,

View File

@ -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

View File

@ -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
}
}

View File

@ -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"
)

View File

@ -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
}

View File

@ -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
}

View File

@ -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))
}

View File

@ -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

View File

@ -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"),

View File

@ -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"
}

View File

@ -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"])
}
}
}
})
}
}

View File

@ -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),
})
}
}

View File

@ -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),
})
}
}

View File

Before

Width:  |  Height:  |  Size: 656 B

After

Width:  |  Height:  |  Size: 656 B

View File

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

View File

Before

Width:  |  Height:  |  Size: 283 B

After

Width:  |  Height:  |  Size: 283 B

View File

Before

Width:  |  Height:  |  Size: 265 B

After

Width:  |  Height:  |  Size: 265 B

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

Before

Width:  |  Height:  |  Size: 404 B

After

Width:  |  Height:  |  Size: 404 B

View File

Before

Width:  |  Height:  |  Size: 265 B

After

Width:  |  Height:  |  Size: 265 B

View File

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

Before

Width:  |  Height:  |  Size: 819 B

After

Width:  |  Height:  |  Size: 819 B

View File

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 632 B

After

Width:  |  Height:  |  Size: 632 B

View File

Before

Width:  |  Height:  |  Size: 776 B

After

Width:  |  Height:  |  Size: 776 B

View File

Before

Width:  |  Height:  |  Size: 286 B

After

Width:  |  Height:  |  Size: 286 B

Some files were not shown because too many files have changed in this diff Show More