From 32513efcc4ecbccc760e09bde4fe871663ea101e Mon Sep 17 00:00:00 2001 From: Acbox Date: Tue, 10 Feb 2026 17:41:37 +0800 Subject: [PATCH] refactor(web): model & provider page --- .../web/src/components/create-model/index.vue | 172 ++++++++++-------- packages/web/src/composables/api/useModels.ts | 6 +- 2 files changed, 102 insertions(+), 76 deletions(-) diff --git a/packages/web/src/components/create-model/index.vue b/packages/web/src/components/create-model/index.vue index 506ebfbe..ad916ea3 100644 --- a/packages/web/src/components/create-model/index.vue +++ b/packages/web/src/components/create-model/index.vue @@ -9,8 +9,7 @@
- - + {{ title === 'edit' ? '编辑Model' : '添加Model' }} @@ -18,55 +17,7 @@
- - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -121,7 +133,7 @@ :disabled="!form.meta.value.valid" > - {{ $t("button.add", { msg: "Model" }) }} + {{ title === 'edit' ? '保存' : $t("button.add", { msg: "Model" }) }} @@ -154,40 +166,54 @@ import { Switch, Separator, Label, - Spinner + Spinner, } from '@memoh/ui' import { useForm } from 'vee-validate' -import { inject, watch, type Ref, ref } from 'vue' +import { inject, computed, watch, type Ref, ref } from 'vue' import { toTypedSchema } from '@vee-validate/zod' import z from 'zod' import { type ModelInfo } from '@memoh/shared' import { useCreateModel } from '@/composables/api/useModels' const formSchema = toTypedSchema(z.object({ - is_multimodal: z.coerce.boolean(), + type: z.string().min(1, '请选择模型类型'), model_id: z.string().min(1), - name: z.string().min(1), - type: z.string().min(1), - dimensions: z.coerce.number().min(1), + name: z.string().optional(), + dimensions: z.coerce.number().min(1).optional(), + is_multimodal: z.coerce.boolean().optional(), })) const form = useForm({ validationSchema: formSchema, - initialValues: { - dimensions: 1, - }, }) +const selectedType = computed(() => form.values.type) + const { id } = defineProps<{ id: string }>() const { mutate: createModel, isLoading } = useCreateModel() -const addModel = form.handleSubmit(async (modelInfo) => { +const addModel = form.handleSubmit(async (values) => { try { - await createModel({ - ...modelInfo, + const payload: Record = { + type: values.type, + model_id: values.model_id, llm_provider_id: id, - }) + } + + if (values.name) { + payload.name = values.name + } + + if (values.type === 'embedding' && values.dimensions) { + payload.dimensions = values.dimensions + } + + if (values.type === 'chat') { + payload.is_multimodal = values.is_multimodal ?? false + } + + await createModel(payload as any) open.value = false } catch { return @@ -196,7 +222,7 @@ const addModel = form.handleSubmit(async (modelInfo) => { const open = inject>('openModel', ref(false)) const title = inject>('openModelTitle', ref('title')) -const editInfo =inject>('openModelState',ref(null)) +const editInfo = inject>('openModelState', ref(null)) watch(open, () => { if (open.value && editInfo?.value) { @@ -207,9 +233,9 @@ watch(open, () => { if (!open.value) { title.value = 'title' - editInfo.value=null + editInfo.value = null } }, { - immediate: true + immediate: true, }) - \ No newline at end of file + diff --git a/packages/web/src/composables/api/useModels.ts b/packages/web/src/composables/api/useModels.ts index 18ebe616..b1f1714f 100644 --- a/packages/web/src/composables/api/useModels.ts +++ b/packages/web/src/composables/api/useModels.ts @@ -6,12 +6,12 @@ import type { Ref } from 'vue' // ---- Types ---- export interface CreateModelRequest { - name: string model_id: string type: string - dimensions: number - is_multimodal: boolean llm_provider_id: string + name?: string + dimensions?: number + is_multimodal?: boolean } // ---- Query: 获取 Provider 下的模型列表 ----