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() {