From 7df66bbc6180612a32af2245d517cd4678a7fc28 Mon Sep 17 00:00:00 2001 From: MangoFanFanw Date: Mon, 1 Jun 2026 20:42:16 +0800 Subject: [PATCH] =?UTF-8?q?feat(webui):=20WebUI=20=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=90=8E=E5=8F=B0=E6=96=B0=E5=A2=9E=20AII=20=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E6=A0=8F=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在 WebUI NyaHome 管理后台中实现 AII 管理栏目,用于在线修改模型设置。 同时在后端补全了两个路由端点。 --- webui/components.d.ts | 12 +- .../{chatroom => aii}/AiiModelAddModal.vue | 92 ++++---- .../src/components/aii/AiiModelEditModal.vue | 90 ++++++++ .../{chatroom => aii}/AiiProviderAddModal.vue | 46 ++-- .../components/aii/AiiProviderEditModal.vue | 46 ++++ .../components/chatroom/ChatControlPanel.vue | 111 +++++++--- webui/src/components/chatroom/ChatTable.vue | 9 +- .../chatroom/ChatroomCreatorModal.vue | 2 - webui/src/pages/Chatroom1Page.vue | 11 +- webui/src/pages/admin/AdminNyahome.vue | 11 +- webui/src/pages/nyahome/AdminAii.vue | 199 ++++++++++++++++++ webui/src/tools/avaliable-check.ts | 50 +++++ webui/src/types/aii.ts | 1 + 13 files changed, 571 insertions(+), 109 deletions(-) rename webui/src/components/{chatroom => aii}/AiiModelAddModal.vue (67%) create mode 100644 webui/src/components/aii/AiiModelEditModal.vue rename webui/src/components/{chatroom => aii}/AiiProviderAddModal.vue (53%) create mode 100644 webui/src/components/aii/AiiProviderEditModal.vue create mode 100644 webui/src/pages/nyahome/AdminAii.vue create mode 100644 webui/src/tools/avaliable-check.ts diff --git a/webui/components.d.ts b/webui/components.d.ts index a2dc5fd..ed9ead2 100644 --- a/webui/components.d.ts +++ b/webui/components.d.ts @@ -12,8 +12,10 @@ export {} /* prettier-ignore */ declare module 'vue' { export interface GlobalComponents { - AiiModelAddModal: typeof import('./src/components/chatroom/AiiModelAddModal.vue')['default'] - AiiProviderAddModal: typeof import('./src/components/chatroom/AiiProviderAddModal.vue')['default'] + AiiModelAddModal: typeof import('./src/components/aii/AiiModelAddModal.vue')['default'] + AiiModelEditModal: typeof import('./src/components/aii/AiiModelEditModal.vue')['default'] + AiiProviderAddModal: typeof import('./src/components/aii/AiiProviderAddModal.vue')['default'] + AiiProviderEditModal: typeof import('./src/components/aii/AiiProviderEditModal.vue')['default'] ChangeEmailModal: typeof import('./src/components/admin/ChangeEmailModal.vue')['default'] ChangePhoneModal: typeof import('./src/components/admin/ChangePhoneModal.vue')['default'] ChatControlPanel: typeof import('./src/components/chatroom/ChatControlPanel.vue')['default'] @@ -88,8 +90,10 @@ declare module 'vue' { // For TSX support declare global { - const AiiModelAddModal: typeof import('./src/components/chatroom/AiiModelAddModal.vue')['default'] - const AiiProviderAddModal: typeof import('./src/components/chatroom/AiiProviderAddModal.vue')['default'] + const AiiModelAddModal: typeof import('./src/components/aii/AiiModelAddModal.vue')['default'] + const AiiModelEditModal: typeof import('./src/components/aii/AiiModelEditModal.vue')['default'] + const AiiProviderAddModal: typeof import('./src/components/aii/AiiProviderAddModal.vue')['default'] + const AiiProviderEditModal: typeof import('./src/components/aii/AiiProviderEditModal.vue')['default'] const ChangeEmailModal: typeof import('./src/components/admin/ChangeEmailModal.vue')['default'] const ChangePhoneModal: typeof import('./src/components/admin/ChangePhoneModal.vue')['default'] const ChatControlPanel: typeof import('./src/components/chatroom/ChatControlPanel.vue')['default'] diff --git a/webui/src/components/chatroom/AiiModelAddModal.vue b/webui/src/components/aii/AiiModelAddModal.vue similarity index 67% rename from webui/src/components/chatroom/AiiModelAddModal.vue rename to webui/src/components/aii/AiiModelAddModal.vue index 467c38f..53c16db 100644 --- a/webui/src/components/chatroom/AiiModelAddModal.vue +++ b/webui/src/components/aii/AiiModelAddModal.vue @@ -2,15 +2,21 @@ import { type SelectOption, useMessage } from 'naive-ui' import { computed, onMounted, ref, watch } from 'vue' -import AiiProviderAddModal from '@/components/chatroom/AiiProviderAddModal.vue' +import AiiProviderAddModal from '@/components/aii/AiiProviderAddModal.vue' +import { aiiModelRules, check_remote_model } from '@/tools/avaliable-check.ts' import { api } from '@/tools/web.js' -import type { AiiProviderPublicWithoutKey } from '@/types/aii.js' +import type { AiiModelPublic, AiiProviderPublicWithoutKey } from '@/types/aii.js' import type { ReturnDto } from '@/types/response.js' const MESSAGE = useMessage() const showModal = defineModel('showModal', { required: true }) +const { reload } = defineProps<{ + noAddProvider?: boolean + reload?: () => void +}>() + const showAddProviderModal = ref(false) const selectProvider = ref(null) const providers = ref([]) @@ -20,6 +26,7 @@ const addModelForm = ref({ id: 0, model_name: '', max_context_length: 0, + reasonable: false, aii_provider_id: selectProvider.value, }) @@ -30,14 +37,7 @@ watch(selectProvider, (newValue) => { function loadProviders() { api .get('/aii/provider/') - .then((res) => res.data as ReturnDto) - .then((data) => { - if (data.success) { - return data.result as AiiProviderPublicWithoutKey[] - } else { - throw TypeError('因未知原因,后端业务失败。') - } - }) + .then((res) => res.data as AiiProviderPublicWithoutKey[]) .then((result) => { providers.value = result MESSAGE.success(`成功加载了 ${result.length} 个模型提供商。`) @@ -82,33 +82,26 @@ function onGetRemoteModels() { }) } -function onCheck() { - api - .get(`/aii/provider/${selectProvider.value}/remote/model/${addModelForm.value.model_name}/`) - .then((res) => res.data as ReturnDto) - .then((data) => { - if (data.success) { - MESSAGE.success(`检测成功,模型 ${addModelForm.value.model_name} 可用。`) - } else { - MESSAGE.warning(`检测完成,模型 ${addModelForm.value.model_name} 不可用。`) - } - }) - .catch((err) => { - MESSAGE.error(`检测过程出现问题:${err}`) - }) +async function onCheck() { + if (selectProvider.value) { + if (await check_remote_model(selectProvider.value, addModelForm.value.model_name)) { + MESSAGE.success(`提供商的模型 ${addModelForm.value.model_name} 可用。`) + } else { + MESSAGE.warning(`提供商的模型 ${addModelForm.value.model_name} 不可用。`) + } + } else { + MESSAGE.warning('请选择模型提供商。') + } } function onConfirm() { api .post('/aii/model/', JSON.stringify(addModelForm.value)) - .then((res) => res.data as ReturnDto) - .then((data) => { - if (data.success) { - MESSAGE.success(`模型 ${addModelForm.value.model_name} 成功添加。`) - showModal.value = false - } else { - throw TypeError('因未知原因,后端业务失败。') - } + .then((res) => res.data as AiiModelPublic) + .then(() => { + MESSAGE.success(`模型 ${addModelForm.value.model_name} 成功添加。`) + showModal.value = false + if (reload) reload() }) .catch((err) => { MESSAGE.error(`添加模型失败:${err}`) @@ -118,16 +111,36 @@ function onConfirm() {