From 8d3e7a5a1fa28e4883a509fbe80a0f68fa93d4e5 Mon Sep 17 00:00:00 2001 From: Hu Gang <18768366022@163.com> Date: Wed, 30 Apr 2025 17:16:55 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=AE=BE=E7=BD=AE=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E3=80=81apikey=E7=9B=B8=E5=85=B3=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/apis/index.ts | 4 + src/apis/paths/apikey.ts | 11 +- src/apis/paths/model.ts | 92 +++++++ src/router/index.ts | 5 + .../dialogue/components/DialogueSession.vue | 2 +- src/views/dialogue/dialogueView.vue | 196 ++++++++------- src/views/settings/ApiKey.vue | 210 ++++++++++++++++ src/views/settings/Model.vue | 169 +++++++++++++ src/views/settings/components/AddModel.vue | 224 ++++++++++++++++++ src/views/settings/components/ModelCard.vue | 108 +++++++++ src/views/settings/index.vue | 80 +++++++ 11 files changed, 1006 insertions(+), 95 deletions(-) create mode 100644 src/apis/paths/model.ts create mode 100644 src/views/settings/ApiKey.vue create mode 100644 src/views/settings/Model.vue create mode 100644 src/views/settings/components/AddModel.vue create mode 100644 src/views/settings/components/ModelCard.vue create mode 100644 src/views/settings/index.vue diff --git a/src/apis/index.ts b/src/apis/index.ts index 530a741c..32242d55 100644 --- a/src/apis/index.ts +++ b/src/apis/index.ts @@ -15,6 +15,8 @@ import { knowledgeApi, appApi, apiApi, + modelApi, + mcpApi, } from './paths'; import { workFlowApi } from './workFlow'; import { appCenterApi } from './appCenter'; @@ -29,4 +31,6 @@ export const api = { ...workFlowApi, ...appApi, ...apiApi, + ...modelApi, + ...mcpApi, }; diff --git a/src/apis/paths/apikey.ts b/src/apis/paths/apikey.ts index 6ffdb0c6..0e7498cc 100644 --- a/src/apis/paths/apikey.ts +++ b/src/apis/paths/apikey.ts @@ -19,7 +19,7 @@ export const getApiKey = (): Promise< any, ( | FcResponse<{ - api_key: string; + api_key_exists: string; }> | undefined ), @@ -32,11 +32,10 @@ export const getApiKey = (): Promise< * USER登录 * @returns */ -export const changeApiKey = (params: { - action: string; - query?: string; -}): Promise<[any, FcResponse | undefined]> => { - return post('/api/auth/key', params, params); +export const changeApiKey = (params: { action: string; query?: string }) => { + return post<{ + api_key: string; + }>('/api/auth/key', params, params); }; export const apiKeyApi = { diff --git a/src/apis/paths/model.ts b/src/apis/paths/model.ts new file mode 100644 index 00000000..35f61f7f --- /dev/null +++ b/src/apis/paths/model.ts @@ -0,0 +1,92 @@ +import { get, post, del } from '../server'; + +enum Provider { + OLLAMA = 'Ollama', + VLLM = 'VLLM', + QWEN = 'Tongyi-Qianwen', + XUNFEI = 'XunFei Spark', + BAICHUAN = 'BaiChuan', + BAIDU = 'BaiduYiyan', + MODELSCOPE = 'ModelScope', +} + +/** + * 获取用户的模型列表 + * @returns + */ +const getUserModelList = () => { + return get<{ + models: { + modelId: string; + icon: string; + description: string; + name: string; + model: string; + url: string; + provider: string; + maxTokens: number; + apiKey: string; + }[]; + totalModels: number; + }>('/api/model'); +}; + +/** + * 获取模型提供商列表 + * @returns + */ +const getModelProviderList = () => { + return get<{ + providers: { + providerId: string; + icon: string; + url: string; + description: string; + name: string; + }[]; + totalProviders: number; + }>('/api/model/provider'); +}; + +const getAllModels = (searchKey: string) => { + return get<{ + models: { modelId: string; modelName: string }[]; + }>('/api/model/all', { + searchKey, + }); +}; + +/** + * 添加模型 + * @param params + * @returns + */ +const createModel = (params: { + modelId?: string; + name: string; + provider: string; + icon?: string; + apiKey: string; + maxTokens: string; + model: string; + url: string; +}) => { + return post('/api/model', params); +}; + +/** + * 删除模型 + * @param modelId + * @returns + */ +const deleteModel = (modelId: string) => { + return del(`/api/model/${modelId}`); +}; + +export const modelApi = { + getUserModelList, + getModelProviderList, + createModel, + getAllModels, + deleteModel, +}; diff --git a/src/router/index.ts b/src/router/index.ts index 5c5fb4a8..59be4cbd 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -49,6 +49,11 @@ const staticRoutes: Array = [ component: (): Promise => import('src/views/tools/index.vue'), }, + { + path: '/settings', + name: 'settings', + component: () => import('src/views/settings/index.vue'), + }, ], }, { diff --git a/src/views/dialogue/components/DialogueSession.vue b/src/views/dialogue/components/DialogueSession.vue index 205810db..99acf1df 100644 --- a/src/views/dialogue/components/DialogueSession.vue +++ b/src/views/dialogue/components/DialogueSession.vue @@ -987,7 +987,7 @@ button[disabled]:hover { top: 0; left: 0; opacity: 0.4; - background-image: linear-gradient(180deg, #e7f0fd 1%, #accbee 100%); + // background-image: linear-gradient(180deg, #e7f0fd 1%, #accbee 100%); z-index: -1; } diff --git a/src/views/dialogue/dialogueView.vue b/src/views/dialogue/dialogueView.vue index f7d65ca6..86a4137a 100644 --- a/src/views/dialogue/dialogueView.vue +++ b/src/views/dialogue/dialogueView.vue @@ -13,15 +13,17 @@ import { ElMessage } from 'element-plus'; import { watch } from 'vue'; import i18n from 'src/i18n'; import { reactive } from 'vue'; -import { useRouter } from 'vue-router'; +import { useRouter, useRoute } from 'vue-router'; import CopilotIcon from '@/assets/svgs/routerCopilot.svg'; import CopilotIconSelected from '@/assets/svgs/routerCopilotSelected.svg'; -import ApiIcon from '@/assets/svgs/routerApi.svg'; -import ApiIconSelected from '@/assets/svgs/routerApiSelected.svg'; +import PluginCenter from '@/assets/svgs/plugin_center.svg'; +import PluginCenterSelected from '@/assets/svgs/plugin_center_active.svg'; import AppIcon from '@/assets/svgs/routerApp.svg'; import AppIconSelected from '@/assets/svgs/routerAppSelected.svg'; import WitChainDIcon from '@/assets/svgs/witChainD.svg'; import WitChainDIconSelected from '@/assets/svgs/witChainDSelected.svg'; +import Setting from '@/assets/svgs/setting.svg'; +import SettingSelected from '@/assets/svgs/setting_active.svg'; import tools from '../tools/index.vue'; import TitleBar from './components/TitleBar.vue'; @@ -42,6 +44,7 @@ const revoke = ref(true); const isSubmitDisabled = ref(true); const ruleFormRef = ref(); const router = useRouter(); +const route = useRoute(); const type = import.meta.env.VITE_USER_TYPE; let routerList: ComputedRef< Array<{ @@ -63,10 +66,10 @@ let routerList: ComputedRef< anotherName: 'copilot', }, { - name: i18n.global.t('menu.semantic_center'), + name: i18n.global.t('menu.plugin_center'), path: '/api', - src: ApiIcon, - selectedSrc: ApiIconSelected, + src: PluginCenter, + selectedSrc: PluginCenterSelected, routerName: 'api', }, { @@ -166,8 +169,13 @@ const changeLanguagefun = (lang: 'CN' | 'EN') => { // 同步语言到iframe const iframe = document.querySelector('#my-iframe'); if (iframe?.contentWindow) { - const data = { lang: localStorage.getItem('localeLang') ?? 'CN' ,type: 'changeLanguage'}; - let target = window.location.origin.includes('localhost')?'http://localhost:3002/witchaind/' : `${window.location.origin}/witchaind/`; + const data = { + lang: localStorage.getItem('localeLang') ?? 'CN', + type: 'changeLanguage', + }; + let target = window.location.origin.includes('localhost') + ? 'http://localhost:3002/witchaind/' + : `${window.location.origin}/witchaind/`; iframe.contentWindow.postMessage(data, target); } }; @@ -177,10 +185,10 @@ const handleFormValidate = (prop: any, isValid: boolean, message: string) => { }; onMounted(() => { if (localStorage.getItem('theme')) { - document.body.setAttribute( - 'theme', - localStorage.getItem('theme') || 'light', - ); + // document.body.setAttribute( + // 'theme', + // localStorage.getItem('theme') || 'light', + // ); } if (localStorage.getItem('kb_id')) { ruleForm.kb_id = localStorage.getItem('kb_id'); @@ -256,37 +264,54 @@ watch(
- +
+ + + + + + + + {{ item.name }} + +
+ + - + - - {{ item.name }} + {{ i18n.global.t('menu.settings') }}
- +
diff --git a/src/views/settings/ApiKey.vue b/src/views/settings/ApiKey.vue new file mode 100644 index 00000000..496d3f19 --- /dev/null +++ b/src/views/settings/ApiKey.vue @@ -0,0 +1,210 @@ + + + + + + diff --git a/src/views/settings/Model.vue b/src/views/settings/Model.vue new file mode 100644 index 00000000..9e63951d --- /dev/null +++ b/src/views/settings/Model.vue @@ -0,0 +1,169 @@ + + + diff --git a/src/views/settings/components/AddModel.vue b/src/views/settings/components/AddModel.vue new file mode 100644 index 00000000..45eb882b --- /dev/null +++ b/src/views/settings/components/AddModel.vue @@ -0,0 +1,224 @@ + + + + diff --git a/src/views/settings/components/ModelCard.vue b/src/views/settings/components/ModelCard.vue new file mode 100644 index 00000000..b91a4a99 --- /dev/null +++ b/src/views/settings/components/ModelCard.vue @@ -0,0 +1,108 @@ + + + diff --git a/src/views/settings/index.vue b/src/views/settings/index.vue new file mode 100644 index 00000000..b4d51073 --- /dev/null +++ b/src/views/settings/index.vue @@ -0,0 +1,80 @@ + + + + + + -- Gitee