mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-02 01:10:23 +08:00
fix(providers): remove unreachable manual model add flow
This commit is contained in:
@@ -11,24 +11,13 @@
|
|||||||
class="space-y-4"
|
class="space-y-4"
|
||||||
@submit.prevent="handleSubmit"
|
@submit.prevent="handleSubmit"
|
||||||
>
|
>
|
||||||
<!-- 添加模式:选择或手动创建本地全局模型 -->
|
<!-- 添加模式:选择本地全局模型 -->
|
||||||
<div
|
<div
|
||||||
v-if="!isEditing"
|
v-if="!isEditing"
|
||||||
class="space-y-3"
|
class="space-y-3"
|
||||||
>
|
>
|
||||||
<div class="flex items-center justify-between gap-3">
|
<div class="space-y-1.5">
|
||||||
<Label for="global-model">选择已有模型或手动添加 *</Label>
|
<Label for="global-model">选择已有模型 *</Label>
|
||||||
<Button
|
|
||||||
type="button"
|
|
||||||
variant="ghost"
|
|
||||||
size="sm"
|
|
||||||
class="h-7 px-2 text-xs"
|
|
||||||
@click="manualGlobalModelMode = !manualGlobalModelMode"
|
|
||||||
>
|
|
||||||
{{ manualGlobalModelMode ? '选择已有模型' : '手动添加' }}
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
<div v-if="!manualGlobalModelMode" class="space-y-2">
|
|
||||||
<Select
|
<Select
|
||||||
:model-value="form.global_model_id"
|
:model-value="form.global_model_id"
|
||||||
:disabled="loadingGlobalModels"
|
:disabled="loadingGlobalModels"
|
||||||
@@ -48,35 +37,11 @@
|
|||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
</div>
|
</div>
|
||||||
<div v-else class="rounded-lg border border-border/60 bg-muted/20 p-3 space-y-3">
|
|
||||||
<div class="grid grid-cols-2 gap-3">
|
|
||||||
<div class="space-y-1.5">
|
|
||||||
<Label for="manual-global-model-name" class="text-xs">模型ID *</Label>
|
|
||||||
<Input
|
|
||||||
id="manual-global-model-name"
|
|
||||||
v-model="form.manual_global_model_name"
|
|
||||||
placeholder="如 gpt-4o-mini"
|
|
||||||
@update:model-value="syncManualProviderName"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div class="space-y-1.5">
|
|
||||||
<Label for="manual-global-model-display-name" class="text-xs">显示名称</Label>
|
|
||||||
<Input
|
|
||||||
id="manual-global-model-display-name"
|
|
||||||
v-model="form.manual_global_model_display_name"
|
|
||||||
placeholder="默认使用模型ID"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<p class="text-xs text-muted-foreground">
|
|
||||||
无法联网获取模型目录时,可直接填写模型ID。保存时会先创建本地全局模型,再添加到当前 Provider。
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<p
|
<p
|
||||||
v-if="availableGlobalModels.length === 0 && !loadingGlobalModels && !manualGlobalModelMode"
|
v-if="availableGlobalModels.length === 0 && !loadingGlobalModels"
|
||||||
class="text-xs text-muted-foreground"
|
class="text-xs text-muted-foreground"
|
||||||
>
|
>
|
||||||
没有可选择的本地全局模型。可以切换到“手动添加”继续保存。
|
没有可选择的本地全局模型。请先在模型管理中添加全局模型。
|
||||||
</p>
|
</p>
|
||||||
<div class="space-y-1.5">
|
<div class="space-y-1.5">
|
||||||
<Label for="provider-model-name" class="text-xs">Provider 模型名 *</Label>
|
<Label for="provider-model-name" class="text-xs">Provider 模型名 *</Label>
|
||||||
@@ -285,7 +250,7 @@ import {
|
|||||||
import { useToast } from '@/composables/useToast'
|
import { useToast } from '@/composables/useToast'
|
||||||
import { parseNumberInput, sortResolutionEntries } from '@/utils/form'
|
import { parseNumberInput, sortResolutionEntries } from '@/utils/form'
|
||||||
import { createModel, updateModel, getProviderModels } from '@/api/endpoints/models'
|
import { createModel, updateModel, getProviderModels } from '@/api/endpoints/models'
|
||||||
import { createGlobalModel, listGlobalModels, type GlobalModelResponse } from '@/api/global-models'
|
import { listGlobalModels, type GlobalModelResponse } from '@/api/global-models'
|
||||||
import TieredPricingEditor from '@/features/models/components/TieredPricingEditor.vue'
|
import TieredPricingEditor from '@/features/models/components/TieredPricingEditor.vue'
|
||||||
import type { Model, TieredPricingConfig } from '@/api/endpoints'
|
import type { Model, TieredPricingConfig } from '@/api/endpoints'
|
||||||
import {
|
import {
|
||||||
@@ -334,7 +299,6 @@ const showCache1h = true
|
|||||||
const submitting = ref(false)
|
const submitting = ref(false)
|
||||||
const loadingGlobalModels = ref(false)
|
const loadingGlobalModels = ref(false)
|
||||||
const availableGlobalModels = ref<GlobalModelResponse[]>([])
|
const availableGlobalModels = ref<GlobalModelResponse[]>([])
|
||||||
const manualGlobalModelMode = ref(false)
|
|
||||||
|
|
||||||
// 阶梯计费配置
|
// 阶梯计费配置
|
||||||
const tieredPricing = ref<TieredPricingConfig | null>(null)
|
const tieredPricing = ref<TieredPricingConfig | null>(null)
|
||||||
@@ -369,15 +333,9 @@ const VIDEO_RESOLUTION_PRICE_PRESETS: Record<
|
|||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
const DEFAULT_MANUAL_GLOBAL_MODEL_PRICING: TieredPricingConfig = {
|
|
||||||
tiers: [{ up_to: null, input_price_per_1m: 0, output_price_per_1m: 0 }],
|
|
||||||
}
|
|
||||||
|
|
||||||
const form = ref({
|
const form = ref({
|
||||||
global_model_id: '',
|
global_model_id: '',
|
||||||
provider_model_name: '',
|
provider_model_name: '',
|
||||||
manual_global_model_name: '',
|
|
||||||
manual_global_model_display_name: '',
|
|
||||||
price_per_request: undefined as number | undefined,
|
price_per_request: undefined as number | undefined,
|
||||||
config: {} as Record<string, unknown>,
|
config: {} as Record<string, unknown>,
|
||||||
// 能力配置
|
// 能力配置
|
||||||
@@ -392,7 +350,6 @@ const form = ref({
|
|||||||
const canSubmitCreate = computed(() => {
|
const canSubmitCreate = computed(() => {
|
||||||
if (isEditing.value) return true
|
if (isEditing.value) return true
|
||||||
if (!form.value.provider_model_name.trim()) return false
|
if (!form.value.provider_model_name.trim()) return false
|
||||||
if (manualGlobalModelMode.value) return !!form.value.manual_global_model_name.trim()
|
|
||||||
return !!form.value.global_model_id
|
return !!form.value.global_model_id
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -407,8 +364,6 @@ watch(() => props.open, async (newOpen) => {
|
|||||||
form.value = {
|
form.value = {
|
||||||
global_model_id: props.editingModel.global_model_id || '',
|
global_model_id: props.editingModel.global_model_id || '',
|
||||||
provider_model_name: props.editingModel.provider_model_name || '',
|
provider_model_name: props.editingModel.provider_model_name || '',
|
||||||
manual_global_model_name: '',
|
|
||||||
manual_global_model_display_name: '',
|
|
||||||
// 显示有效的按次计费价格(继承自全局模型)
|
// 显示有效的按次计费价格(继承自全局模型)
|
||||||
price_per_request: props.editingModel.effective_price_per_request ?? props.editingModel.price_per_request ?? undefined,
|
price_per_request: props.editingModel.effective_price_per_request ?? props.editingModel.price_per_request ?? undefined,
|
||||||
config: effectiveConfig ? JSON.parse(JSON.stringify(effectiveConfig)) : {},
|
config: effectiveConfig ? JSON.parse(JSON.stringify(effectiveConfig)) : {},
|
||||||
@@ -470,8 +425,6 @@ function resetForm() {
|
|||||||
form.value = {
|
form.value = {
|
||||||
global_model_id: '',
|
global_model_id: '',
|
||||||
provider_model_name: '',
|
provider_model_name: '',
|
||||||
manual_global_model_name: '',
|
|
||||||
manual_global_model_display_name: '',
|
|
||||||
price_per_request: undefined,
|
price_per_request: undefined,
|
||||||
config: {},
|
config: {},
|
||||||
supports_vision: undefined,
|
supports_vision: undefined,
|
||||||
@@ -487,7 +440,6 @@ function resetForm() {
|
|||||||
tieredPricingModified.value = false
|
tieredPricingModified.value = false
|
||||||
originalTieredPricing.value = ''
|
originalTieredPricing.value = ''
|
||||||
availableGlobalModels.value = []
|
availableGlobalModels.value = []
|
||||||
manualGlobalModelMode.value = false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleGlobalModelSelect(value: string) {
|
function handleGlobalModelSelect(value: string) {
|
||||||
@@ -496,16 +448,6 @@ function handleGlobalModelSelect(value: string) {
|
|||||||
form.value.provider_model_name = selectedModel?.name || form.value.provider_model_name
|
form.value.provider_model_name = selectedModel?.name || form.value.provider_model_name
|
||||||
}
|
}
|
||||||
|
|
||||||
function syncManualProviderName(value: string | number) {
|
|
||||||
const modelName = String(value || '').trim()
|
|
||||||
if (!form.value.provider_model_name.trim()) {
|
|
||||||
form.value.provider_model_name = modelName
|
|
||||||
}
|
|
||||||
if (!form.value.manual_global_model_display_name.trim()) {
|
|
||||||
form.value.manual_global_model_display_name = modelName
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function getNested(obj: Record<string, unknown>, path: string): unknown {
|
function getNested(obj: Record<string, unknown>, path: string): unknown {
|
||||||
if (!obj || typeof obj !== 'object') return undefined
|
if (!obj || typeof obj !== 'object') return undefined
|
||||||
const parts = path.split('.').filter(Boolean)
|
const parts = path.split('.').filter(Boolean)
|
||||||
@@ -642,28 +584,6 @@ function _copyVideoPricingFromSelectedGlobal() {
|
|||||||
configTouched.value = true
|
configTouched.value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createManualGlobalModel(finalTieredPricing: TieredPricingConfig | null, cleanConfig: Record<string, unknown> | undefined): Promise<GlobalModelResponse> {
|
|
||||||
const modelName = form.value.manual_global_model_name.trim()
|
|
||||||
const displayName = form.value.manual_global_model_display_name.trim() || modelName
|
|
||||||
const supportedCapabilities = [
|
|
||||||
form.value.supports_vision === true ? 'vision' : null,
|
|
||||||
form.value.supports_function_calling === true ? 'function_calling' : null,
|
|
||||||
form.value.supports_streaming === true ? 'streaming' : null,
|
|
||||||
form.value.supports_extended_thinking === true ? 'extended_thinking' : null,
|
|
||||||
form.value.supports_image_generation === true ? 'image_generation' : null,
|
|
||||||
].filter((capability): capability is string => capability !== null)
|
|
||||||
|
|
||||||
return createGlobalModel({
|
|
||||||
name: modelName,
|
|
||||||
display_name: displayName,
|
|
||||||
default_price_per_request: form.value.price_per_request,
|
|
||||||
default_tiered_pricing: finalTieredPricing || DEFAULT_MANUAL_GLOBAL_MODEL_PRICING,
|
|
||||||
supported_capabilities: supportedCapabilities.length ? supportedCapabilities : undefined,
|
|
||||||
config: cleanConfig,
|
|
||||||
is_active: true,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// 加载可用的全局模型(排除已添加的)
|
// 加载可用的全局模型(排除已添加的)
|
||||||
async function loadAvailableGlobalModels() {
|
async function loadAvailableGlobalModels() {
|
||||||
loadingGlobalModels.value = true
|
loadingGlobalModels.value = true
|
||||||
@@ -701,7 +621,7 @@ function handleClose(value: boolean) {
|
|||||||
async function handleSubmit() {
|
async function handleSubmit() {
|
||||||
if (submitting.value) return
|
if (submitting.value) return
|
||||||
if (!isEditing.value && !canSubmitCreate.value) {
|
if (!isEditing.value && !canSubmitCreate.value) {
|
||||||
showError(manualGlobalModelMode.value ? '请填写模型ID和 Provider 模型名' : '请选择模型并填写 Provider 模型名', '错误')
|
showError('请选择模型并填写 Provider 模型名', '错误')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -734,21 +654,19 @@ async function handleSubmit() {
|
|||||||
showSuccess('模型配置已更新')
|
showSuccess('模型配置已更新')
|
||||||
} else {
|
} else {
|
||||||
// 添加模式:只有用户修改了配置才提交 tiered_pricing,否则保持继承关系
|
// 添加模式:只有用户修改了配置才提交 tiered_pricing,否则保持继承关系
|
||||||
const selectedModel = manualGlobalModelMode.value
|
const selectedModel = availableGlobalModels.value.find(m => m.id === form.value.global_model_id)
|
||||||
? await createManualGlobalModel(finalTieredPricing, cleanConfig)
|
|
||||||
: availableGlobalModels.value.find(m => m.id === form.value.global_model_id)
|
|
||||||
if (!selectedModel) {
|
if (!selectedModel) {
|
||||||
showError('请选择模型,或切换到手动添加后填写模型ID', '错误')
|
showError('请选择模型', '错误')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
await createModel(props.providerId, buildProviderModelCreatePayload({
|
await createModel(props.providerId, buildProviderModelCreatePayload({
|
||||||
globalModelId: selectedModel.id,
|
globalModelId: selectedModel.id,
|
||||||
providerModelName: form.value.provider_model_name.trim(),
|
providerModelName: form.value.provider_model_name.trim(),
|
||||||
finalTieredPricing,
|
finalTieredPricing,
|
||||||
tieredPricingModified: manualGlobalModelMode.value ? false : tieredPricingModified.value,
|
tieredPricingModified: tieredPricingModified.value,
|
||||||
pricePerRequest: manualGlobalModelMode.value ? undefined : form.value.price_per_request,
|
pricePerRequest: form.value.price_per_request,
|
||||||
cleanConfig,
|
cleanConfig,
|
||||||
configTouched: manualGlobalModelMode.value ? false : configTouched.value,
|
configTouched: configTouched.value,
|
||||||
supportsVision: form.value.supports_vision,
|
supportsVision: form.value.supports_vision,
|
||||||
supportsFunctionCalling: form.value.supports_function_calling,
|
supportsFunctionCalling: form.value.supports_function_calling,
|
||||||
supportsStreaming: form.value.supports_streaming,
|
supportsStreaming: form.value.supports_streaming,
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ describe('provider model form embedding helpers', () => {
|
|||||||
expect('supports_embedding' in payload).toBe(false)
|
expect('supports_embedding' in payload).toBe(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('uses manually supplied provider model name in create payload', () => {
|
it('uses supplied provider model name in create payload', () => {
|
||||||
const payload = buildProviderModelCreatePayload({
|
const payload = buildProviderModelCreatePayload({
|
||||||
globalModelId: 'gm-local-manual',
|
globalModelId: 'gm-local-manual',
|
||||||
providerModelName: 'intranet-chat-model-v1',
|
providerModelName: 'intranet-chat-model-v1',
|
||||||
|
|||||||
Reference in New Issue
Block a user