From fc9d9f3c257f066e1eb8314dc5768c71303e07e5 Mon Sep 17 00:00:00 2001 From: fxjhello <2395112364@qq.com> Date: Sat, 13 May 2023 20:29:27 +0800 Subject: [PATCH] =?UTF-8?q?vue=E9=A1=B5=E9=9D=A2=E5=AE=8C=E6=88=9090%?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- views/src/api/chat.ts | 5 ++--- views/src/store/modules/knowledgebaseid/id.ts | 11 +++++++++++ views/src/views/chat/index.vue | 19 ++++++++++++++----- .../layout/sider/knowledge-base/filelist.vue | 2 +- .../layout/sider/knowledge-base/index.vue | 11 +++++++++++ views/vite.config.ts | 3 +-- 6 files changed, 40 insertions(+), 11 deletions(-) create mode 100644 views/src/store/modules/knowledgebaseid/id.ts diff --git a/views/src/api/chat.ts b/views/src/api/chat.ts index 9d664e9..08d7957 100644 --- a/views/src/api/chat.ts +++ b/views/src/api/chat.ts @@ -1,4 +1,3 @@ -import qs from 'qs' import { api } from './api' export const chat = (params: any) => { @@ -11,9 +10,9 @@ export const chat = (params: any) => { export const chatfile = (params: any) => { return api({ - url: '/chatfile', + url: '/local_doc_qa/local_doc_chat', method: 'post', - data: qs.stringify(params), + data: JSON.stringify(params), }) } diff --git a/views/src/store/modules/knowledgebaseid/id.ts b/views/src/store/modules/knowledgebaseid/id.ts new file mode 100644 index 0000000..0f17215 --- /dev/null +++ b/views/src/store/modules/knowledgebaseid/id.ts @@ -0,0 +1,11 @@ +import { defineStore } from 'pinia' + +export const idStore = defineStore('idStore', { + state: () => { + return { + knowledgeid: 'samples', + + } + }, + +}) diff --git a/views/src/views/chat/index.vue b/views/src/views/chat/index.vue index be82813..3d85bb4 100644 --- a/views/src/views/chat/index.vue +++ b/views/src/views/chat/index.vue @@ -15,6 +15,7 @@ import { useBasicLayout } from '@/hooks/useBasicLayout' import { useChatStore, usePromptStore } from '@/store' import { t } from '@/locales' import { chat, chatfile } from '@/api/chat' +import { idStore } from '@/store/modules/knowledgebaseid/id' let controller = new AbortController() // const openLongReply = import.meta.env.VITE_GLOB_OPEN_LONG_REPLY === 'true' @@ -22,7 +23,7 @@ let controller = new AbortController() const route = useRoute() const dialog = useDialog() const ms = useMessage() - +const idstore = idStore() const chatStore = useChatStore() const history = ref([]) const { isMobile } = useBasicLayout() @@ -60,9 +61,12 @@ function handleSubmit() { async function onConversation() { const message = prompt.value - dataSources.value.forEach((item) => { - console.log(item) - }) + if (usingContext.value) { + for (let i = 0; i < dataSources.value.length; i = i + 2) + history.value.push([dataSources.value[i].text, dataSources.value[i + 1].text]) + } + else { history.value.length = 0 } + if (loading.value) return @@ -112,6 +116,7 @@ async function onConversation() { const fetchChatAPIOnce = async () => { const res = active.value ? await chatfile({ + knowledge_base_id: idstore.knowledgeid, question: message, history: history.value, }) @@ -266,7 +271,11 @@ async function onRegenerate(index: number) { const lastText = '' const fetchChatAPIOnce = async () => { const res = active.value - ? await chatfile({ message }) + ? await chatfile({ + knowledge_base_id: idstore.knowledgeid, + question: message, + history: history.value, + }) : await chat({ question: message, history: history.value, diff --git a/views/src/views/chat/layout/sider/knowledge-base/filelist.vue b/views/src/views/chat/layout/sider/knowledge-base/filelist.vue index f08b02c..55cbdc4 100644 --- a/views/src/views/chat/layout/sider/knowledge-base/filelist.vue +++ b/views/src/views/chat/layout/sider/knowledge-base/filelist.vue @@ -41,7 +41,7 @@ function handleEnter({ uuid }: Chat.History, isEdit: boolean, event: KeyboardEve ([]) +const choice = ref('') +const store = idStore() + onMounted(async () => { + choice.value = store.knowledgeid const res = await getfilelist({}) res.data.data.forEach((item: any) => { items.value.push({ @@ -28,6 +33,9 @@ const rules = { }, } const handleValidateClick = (item: any) => { + // console.log(item) + choice.value = item + store.knowledgeid = choice.value items.value.forEach((res: { value: any; show: boolean }) => { if (res.value === item) res.show = !res.show @@ -46,6 +54,9 @@ const handleClick = () => {