feat: add embedding and rerank support

This commit is contained in:
Kayphoon
2026-05-03 17:32:41 +08:00
parent 3e2eca4fd0
commit 5abe664d65
87 changed files with 5520 additions and 184 deletions
@@ -0,0 +1,75 @@
import { describe, expect, it } from 'vitest'
import {
buildProviderModelCreatePayload,
buildProviderModelUpdatePayload,
modelSupportsEmbedding,
} from '../provider-model-form-helpers'
const pricing = {
tiers: [{ up_to: null, input_price_per_1m: 0.02, output_price_per_1m: 0 }],
}
describe('provider model form embedding helpers', () => {
it.each([
{ supported_capabilities: ['embedding'], config: {} },
{ supported_capabilities: null, config: { embedding: true } },
{ supported_capabilities: null, config: { model_type: 'embedding' } },
{ supported_capabilities: null, config: { api_formats: ['doubao:embedding'] } },
{ supports_embedding: true, effective_supports_embedding: null, config: {} },
{ supports_embedding: null, effective_supports_embedding: true, config: {} },
])('detects embedding metadata from %o', (model) => {
expect(modelSupportsEmbedding(model)).toBe(true)
})
it('keeps provider create payload inherited from the selected embedding global model', () => {
const payload = buildProviderModelCreatePayload({
globalModelId: 'gm-embedding',
providerModelName: 'text-embedding-3-small',
finalTieredPricing: pricing,
tieredPricingModified: false,
pricePerRequest: undefined,
cleanConfig: {
embedding: true,
model_type: 'embedding',
api_formats: ['openai:embedding'],
},
configTouched: false,
supportsStreaming: false,
isActive: true,
})
expect(payload).toMatchObject({
global_model_id: 'gm-embedding',
provider_model_name: 'text-embedding-3-small',
tiered_pricing: undefined,
config: undefined,
supports_streaming: false,
})
expect('supports_embedding' in payload).toBe(false)
})
it('preserves edited provider embedding config without posting unsupported embedding controls', () => {
const payload = buildProviderModelUpdatePayload({
finalTieredPricing: pricing,
pricePerRequest: undefined,
cleanConfig: {
streaming: false,
embedding: true,
model_type: 'embedding',
api_formats: ['gemini:embedding'],
},
supportsStreaming: false,
isActive: true,
})
expect(payload.config).toEqual({
streaming: false,
embedding: true,
model_type: 'embedding',
api_formats: ['gemini:embedding'],
})
expect(payload.supports_streaming).toBe(false)
expect('supports_embedding' in payload).toBe(false)
})
})