From 7eb5350c7d5a99b41f03e6c246b97bc739a54256 Mon Sep 17 00:00:00 2001 From: godo Date: Fri, 10 Jan 2025 09:29:44 +0800 Subject: [PATCH] change chat --- README.md | 1 + frontend/components.d.ts | 13 ++++ frontend/src/components/builtin/FileList.vue | 61 +++++++++++++------ .../src/components/localchat/AiChatMain.vue | 47 +++++++++++++- .../src/components/localchat/LocalChat.vue | 6 +- frontend/src/stores/aichat.ts | 4 ++ frontend/src/system/core/FileSystem.ts | 1 + godo/files/os.go | 15 ++++- godo/vector/go.mod | 19 ------ godo/vector/go.sum | 20 ------ godo/vector/run.go | 54 ---------------- 11 files changed, 121 insertions(+), 120 deletions(-) delete mode 100644 godo/vector/go.mod delete mode 100644 godo/vector/go.sum delete mode 100644 godo/vector/run.go diff --git a/README.md b/README.md index 37fba1f..42224f2 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ - 新增配置本地代理和远程代理,本地代理可实现本机ip映射外部域名,远程代理内嵌frpc设置后可实现内网用户外网域名访问。 - 修改锁屏机制,确保外网访问安全。 - 支持本地聊天ai对话文件和联网搜索。 +- 支持知识库根据文件智能生成,一键生成知识库索引,一键搜索知识库。 ## 🏭 第三阶段目标(一月底发布) 1. **文档处理与Markdown智能升级**:(已完成) diff --git a/frontend/components.d.ts b/frontend/components.d.ts index 3ccca52..37699f1 100644 --- a/frontend/components.d.ts +++ b/frontend/components.d.ts @@ -64,24 +64,37 @@ 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'] + 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'] + 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'] ElRow: typeof import('element-plus/es')['ElRow'] + ElScrollbar: typeof import('element-plus/es')['ElScrollbar'] ElSelect: typeof import('element-plus/es')['ElSelect'] + ElSpace: typeof import('element-plus/es')['ElSpace'] ElSwitch: typeof import('element-plus/es')['ElSwitch'] 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/builtin/FileList.vue b/frontend/src/components/builtin/FileList.vue index f4ab658..c793ba3 100644 --- a/frontend/src/components/builtin/FileList.vue +++ b/frontend/src/components/builtin/FileList.vue @@ -344,26 +344,47 @@ function handleRightClick( }, }); } - menuArr.push({ - label: "加入知识库", - click: () => { - console.log(item) - addKnowledge(item.path).then((res:any) => { - console.log(res) - if(res.code != 0){ - new Notify({ - title: t("tips"), - content: res.message, - }); - }else{ - new Notify({ - title: t("tips"), - content: "添加成功", - }); - } - }) - }, - }); + if (!item.knowledgeId) { + menuArr.push({ + label: "加入知识库", + click: () => { + console.log(item) + addKnowledge(item.path).then((res: any) => { + console.log(res) + if (res.code != 0) { + new Notify({ + title: t("tips"), + content: res.message, + }); + } else { + new Notify({ + title: t("tips"), + content: "添加成功", + }); + } + }) + }, + }); + }else{ + menuArr.push({ + label: "对话知识库", + click: () => { + const win = new BrowserWindow({ + title: "对话知识库", + content: "AiChatMain", + config: { + path: item.path, + knowledgeId: item.knowledgeId, + }, + width: 700, + height: 600, + center: true, + }); + win.show(); + }, + }); + } + } if (choose.ifShow) { menuArr.push({ diff --git a/frontend/src/components/localchat/AiChatMain.vue b/frontend/src/components/localchat/AiChatMain.vue index 003564b..c87fad4 100644 --- a/frontend/src/components/localchat/AiChatMain.vue +++ b/frontend/src/components/localchat/AiChatMain.vue @@ -6,13 +6,14 @@ import { notifyError } from "@/util/msg.ts"; import { ElScrollbar } from "element-plus"; import { getSystemConfig } from "@/system/config"; import { Vue3Lottie } from "vue3-lottie"; -import { file } from "jszip"; +import { BrowserWindow } from "@/system"; import { isMobileDevice } from "@/util/device"; const chatStore = useAiChatStore(); const modelStore = useModelStore(); const isPadding = ref(false); //是否发送中 const webSearch = ref(false); const imageInput: any = ref(null); +const win: any = inject("browserWindow"); let imageData = ref(""); let fileContent = ref(""); let fileName = ref(""); @@ -32,6 +33,10 @@ const promptMessage = computed(() => { }, ]; }); +onMounted(async () => { + await chatStore.initChat() + //await aiStore.initChat() +}); const requestMessages = computed(() => { const contextLen = modelStore.chatConfig.chat.contextLength; //console.log(contextLen) @@ -45,9 +50,44 @@ const requestMessages = computed(() => { }); const sendMessage = async () => { if (chatStore.activeId < 1) { - notifyError(t("index.notFindChatModel")); + notifyError(t("aichat.selectModel")); return; } + const knowledgeId = win?.config?.knowledgeId || 0; + if (knowledgeId > 0) { + const askData: any = { + id: knowledgeId, + input: userMessage.value, + } + const config = getSystemConfig() + const postData: any = { + method: "POST", + body: JSON.stringify(askData), + }; + const completion = await fetch(config.apiUrl + '/ai/askknowledge', postData); + if (!completion.ok) { + const errorData = await completion.json(); + //console.log(errorData) + notifyError(errorData.message); + isPadding.value = false; + return; + } + const res = await completion.json(); + console.log(res) + let prompt = await chatStore.getPrompt("knowledge") + if (prompt == '') { + notifyError("知识库prompt为空") + return + } + if (res && res.data.length > 0) { + let context: string = ""; + res.data.forEach((item: any) => { + context += "- " + item.content + "\n"; + }) + prompt = prompt.replace("{content}", context) + chatStore.chatInfo.prompt = prompt + } + } if (userMessage.value) { // Add the message to the list if (isPadding.value === true) return; @@ -207,6 +247,9 @@ const uploadImage = async (event: any) => {