diff --git a/frontend/components.d.ts b/frontend/components.d.ts index b058116..4af0e99 100644 --- a/frontend/components.d.ts +++ b/frontend/components.d.ts @@ -63,17 +63,29 @@ declare module 'vue' { DownModelInfo: typeof import('./src/components/ai/DownModelInfo.vue')['default'] EditFileName: typeof import('./src/components/builtin/EditFileName.vue')['default'] EditType: typeof import('./src/components/builtin/EditType.vue')['default'] + ElAlert: typeof import('element-plus/es')['ElAlert'] + ElAside: typeof import('element-plus/es')['ElAside'] ElAvatar: typeof import('element-plus/es')['ElAvatar'] + ElBadge: typeof import('element-plus/es')['ElBadge'] ElButton: typeof import('element-plus/es')['ElButton'] ElCard: typeof import('element-plus/es')['ElCard'] ElCarousel: typeof import('element-plus/es')['ElCarousel'] ElCarouselItem: typeof import('element-plus/es')['ElCarouselItem'] + ElCol: typeof import('element-plus/es')['ElCol'] + ElCollapse: typeof import('element-plus/es')['ElCollapse'] + ElCollapseItem: typeof import('element-plus/es')['ElCollapseItem'] + ElContainer: typeof import('element-plus/es')['ElContainer'] ElDialog: typeof import('element-plus/es')['ElDialog'] + ElDrawer: typeof import('element-plus/es')['ElDrawer'] + ElEmpty: typeof import('element-plus/es')['ElEmpty'] ElForm: typeof import('element-plus/es')['ElForm'] ElFormItem: typeof import('element-plus/es')['ElFormItem'] + ElHeader: typeof import('element-plus/es')['ElHeader'] ElIcon: typeof import('element-plus/es')['ElIcon'] + ElImage: typeof import('element-plus/es')['ElImage'] ElInput: typeof import('element-plus/es')['ElInput'] ElOption: typeof import('element-plus/es')['ElOption'] + ElPageHeader: typeof import('element-plus/es')['ElPageHeader'] ElPagination: typeof import('element-plus/es')['ElPagination'] ElPopover: typeof import('element-plus/es')['ElPopover'] ElProgress: typeof import('element-plus/es')['ElProgress'] @@ -81,8 +93,12 @@ declare module 'vue' { ElScrollbar: typeof import('element-plus/es')['ElScrollbar'] ElSelect: typeof import('element-plus/es')['ElSelect'] ElSlider: typeof import('element-plus/es')['ElSlider'] + ElSpace: typeof import('element-plus/es')['ElSpace'] ElTabPane: typeof import('element-plus/es')['ElTabPane'] ElTabs: typeof import('element-plus/es')['ElTabs'] + ElTag: typeof import('element-plus/es')['ElTag'] + ElText: typeof import('element-plus/es')['ElText'] + ElTooltip: typeof import('element-plus/es')['ElTooltip'] Error: typeof import('./src/components/taskbar/Error.vue')['default'] FileIcon: typeof import('./src/components/builtin/FileIcon.vue')['default'] FileIconImg: typeof import('./src/components/builtin/FileIconImg.vue')['default'] diff --git a/frontend/src/components/ai/AiSettingApi.vue b/frontend/src/components/ai/AiSettingApi.vue index 5d9542c..df2f10e 100644 --- a/frontend/src/components/ai/AiSettingApi.vue +++ b/frontend/src/components/ai/AiSettingApi.vue @@ -5,55 +5,78 @@ import { getSystemConfig, setSystemConfig, } from "@/system/config"; -import { OpenDirDialog } from "@/util/goutil"; -const config: any = ref({}); +import { OpenDirDialog, checkUrl } from "@/util/goutil"; +const activeNames = ref([]) const hoverTxt = { dataDir: t('aisetting.tips_dataDir'), apiUrl: t('aisetting.tips_apiUrl'), }; +const formData: any = ref({ + dataDir: "", + aiUrl: "", + ollamaUrl: "", + ollamaDir: "", + openaiUrl: "", + openaiSecret: "", + giteeSecret: "", + cloudflareUserId: "", + cloudflareSecret: "", + deepseekSecret: "", + bigmodelSecret: "", + volcesSecret:"", + alibabaSecret: "", + groqSecret: "", + mistralSecret: "", + anthropicSecret: "", + llamafamilySecret: "", + siliconflowSecret: "" +}) onMounted(() => { - config.value = getSystemConfig(); + const config = getSystemConfig(); + for (const key in config) { + if (formData.value.hasOwnProperty(key)) { + formData.value[key] = config[key]; + } + } }); -async function changeDir() { +async function changeDir(name: any) { const path: any = await OpenDirDialog(); //console.log(path) - config.value.dataDir = path; + formData.value[name] = path; } const saveConfig = async () => { - try { - await fetch(config.value.apiUrl, { - method: "GET", - mode: "no-cors", - }); - } catch (error) { - notifyError(t('common.urlError')); - return; - } + const config = getSystemConfig(); + const saveData = toRaw(formData.value) let postData: any = [] - if (config.value.dataDir.trim() != "") { - postData.push({ - name: "aiDir", - value: config.value.dataDir.trim(), - }) + for (const key in saveData) { + saveData[key] = saveData[key].trim() + config[key] = saveData[key]; + if (saveData[key] != "") { + postData.push({ + name: key, + value: saveData[key], + }) + } } - if (config.value.ollamaUrl.trim() != "") { - postData.push({ - name: "ollamaUrl", - value: config.value.ollamaUrl.trim(), - }) + if (saveData.aiUrl != "") { + if (!await checkUrl(saveData.aiUrl)) { + notifyError("ai服务端地址有误"); + return; + } } - if (config.value.openaiUrl.trim() != "") { - postData.push({ - name: "openaiUrl", - value: config.value.openaiUrl.trim(), - }) + if (saveData.ollamaUrl != "") { + if (!await checkUrl(saveData.ollamaUrl)) { + notifyError("ai服务端地址有误"); + return; + } } + if (postData.length > 0) { const postDatas = { method: "POST", body: JSON.stringify(postData), }; - const res: any = await fetch(config.value.apiUrl + "/system/setting", postDatas); + const res: any = await fetch(config.apiUrl + "/system/setting", postDatas); //console.log(res) if (!res || !res.ok) { notifyError(t('common.saveError')); @@ -66,63 +89,182 @@ const saveConfig = async () => { } } - setSystemConfig(config.value); + setSystemConfig(config); notifySuccess(t('common.saveSuccess')); }; \ No newline at end of file diff --git a/frontend/src/components/ai/AiSettingDef.vue b/frontend/src/components/ai/AiSettingDef.vue index 2df156b..0ce67ba 100644 --- a/frontend/src/components/ai/AiSettingDef.vue +++ b/frontend/src/components/ai/AiSettingDef.vue @@ -6,7 +6,6 @@ const currentsModel: any = ref({}); onMounted(async () => { await modelStore.getModelList(); updateCurrentsModel(); - }); function updateCurrentsModel() { modelStore.cateList.forEach((item:any) => { diff --git a/frontend/src/components/ai/DownAddbox.vue b/frontend/src/components/ai/DownAddbox.vue index 73225ba..af2f4d6 100644 --- a/frontend/src/components/ai/DownAddbox.vue +++ b/frontend/src/components/ai/DownAddbox.vue @@ -20,8 +20,18 @@ const formInit = { quant: "q4_K_M", pb: "", }, - type: "", + type: "local", }; +const engineType = [ + { + name: "local", + label: "本地引擎", + }, + { + name: "net", + label: "网络引擎", + }, +] const formData = ref(formInit); const fromSource = computed(() => { if (formData.value.info.engine == "ollama") { @@ -59,6 +69,15 @@ function setFrom(val: string) { formData.value.info.from = "network" } } +function setType(val: string) { + if (val == "local") { + formData.value.info.from = "ollama" + formData.value.info.engine = "ollama" + } else { + formData.value.info.from = "network" + formData.value.info.engine = "openai" + } +} const emit = defineEmits(["closeFn", "saveFn"]); const localModels: any = ref([]); async function getLocalModel() { @@ -99,13 +118,11 @@ function setLocalInfo() { urls.push(url + item); }); //formData.value.info.url = urls; - modelData.info.url = urls; + modelData.info.url = urls.join("\n"); + modelData.info.engine = "ollama"; + modelData.info.from = "local"; + modelData.info.model = formData.value.info.model; formData.value.info = modelData.info; - //formData.value.file_name = modelData.file_name; - //formData.value.engine = modelData.engine; - // if (modelData.engine == "ollama") { - // formData.value.type = "local"; - // } } async function download() { const saveData: any = toRaw(formData.value); @@ -115,12 +132,17 @@ async function download() { notifyError(t('model.selectLabel')); return; } - + if(saveData.info.model == ""){ + notifyError(t('model.labelNameEmpty')); + return; + } + if(saveData.type == "net"){ + saveData.info.url = []; + saveData.info.context_length = 1024; + emit("saveFn", saveData); + return; + } if (saveData.info.from == "ollama") { - if (saveData.info.model == "") { - notifyError(t('model.labelNameEmpty')); - return; - } if (saveData.info.model.indexOf(":") === -1) { saveData.info.model = saveData.info.model + ":latest"; } @@ -204,12 +226,20 @@ async function download() { + + + + + - + + + + - + @@ -219,7 +249,7 @@ async function download() { :placeholder="t('model.enterModelName')"> -