From 919a400cec453b5b384d0ae927ec9ecb6aa97456 Mon Sep 17 00:00:00 2001 From: fxjhello <2395112364@qq.com> Date: Mon, 22 May 2023 11:45:41 +0800 Subject: [PATCH] =?UTF-8?q?bingsearch=E5=89=8D=E5=90=8E=E7=AB=AF=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=EF=BC=8Chistory=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api.py | 4 ++-- views/src/api/chat.ts | 8 ++++---- views/src/views/chat/index.vue | 18 ++++++++---------- views/vite.config.ts | 2 +- 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/api.py b/api.py index af20303..7308311 100644 --- a/api.py +++ b/api.py @@ -249,7 +249,7 @@ async def local_doc_chat( async def bing_search_chat( question: str = Body(..., description="Question", example="工伤保险是什么?"), - history: List[List[str]] = Body( + history: Optional[List[List[str]]] = Body( [], description="History of previous questions and answers", example=[ @@ -265,7 +265,7 @@ async def bing_search_chat( ): pass source_documents = [ - f"""出处 [{inum + 1}] {doc.metadata["source"]} \n\n{doc.page_content}\n\n""" + f"""出处 [{inum + 1}]({doc.metadata["source"]}) \n\n{doc.page_content}\n\n""" for inum, doc in enumerate(resp["source_documents"]) ] diff --git a/views/src/api/chat.ts b/views/src/api/chat.ts index 5adbb3b..41f9f99 100644 --- a/views/src/api/chat.ts +++ b/views/src/api/chat.ts @@ -24,11 +24,11 @@ export const getfilelist = (knowledge_base_id: any) => { }) } -export const bing_search = (search_text: any) => { +export const bing_search = (params: any) => { return api({ - url: '/bing_search', - method: 'get', - params: { search_text }, + url: '/local_doc_qa/bing_search_chat', + method: 'post', + data: JSON.stringify(params), }) } diff --git a/views/src/views/chat/index.vue b/views/src/views/chat/index.vue index 2087357..c1418df 100644 --- a/views/src/views/chat/index.vue +++ b/views/src/views/chat/index.vue @@ -40,7 +40,7 @@ const conversationList = computed(() => dataSources.value.filter(item => (!item. const prompt = ref('') const loading = ref(false) const inputRef = ref(null) -const search = ref('对话') +const search = ref('对话') // 添加PromptStore const promptStore = usePromptStore() @@ -58,7 +58,7 @@ dataSources.value.forEach((item, index) => { }) async function handleSubmit() { - if (search.value == 'Bing搜索') { + if (search.value === 'Bing搜索') { loading.value = true const options: Chat.ConversationRequest = {} const lastText = '' @@ -76,9 +76,9 @@ async function handleSubmit() { }, ) scrollToBottom() - const res = await bing_search(prompt.value) + const res = await bing_search({ question: prompt.value }) - const result = active.value ? `${res.data.response}\n\n数据来源:\n\n>${res.data.source_documents.join('>')}` : res.data.response + const result = `${res.data.response}\n\n数据来源:\n\n${res.data.source_documents}` addChat( +uuid, { @@ -116,12 +116,10 @@ async function handleSubmit() { async function onConversation() { const message = prompt.value - history.value = [] + history.value = [] if (usingContext.value) { - for (let i = 0; i < dataSources.value.length; i = i + 2) { - if (!i) - history.value.push([dataSources.value[i].text, dataSources.value[i + 1].text.split('\n\n数据来源:\n\n>')[0]]) - } + for (let i = 0; i < dataSources.value.length; i = i + 2) + history.value.push([dataSources.value[i].text, dataSources.value[i + 1].text.split('\n\n数据来源:\n\n>')[0]]) } else { history.value.length = 0 } @@ -589,7 +587,7 @@ onUnmounted(() => { controller.abort() }) function searchfun() { - if (search.value == '知识库') + if (search.value === '知识库') active.value = true else diff --git a/views/vite.config.ts b/views/vite.config.ts index 796872f..af9e990 100644 --- a/views/vite.config.ts +++ b/views/vite.config.ts @@ -37,7 +37,7 @@ export default defineConfig((env) => { open: false, proxy: { '/api': { - target: 'http://127.0.0.1:7861', + target: 'http://146.56.190.29:7861', changeOrigin: true, // 允许跨域 rewrite: path => path.replace('/api/', ''), },