bingsearch前后端修改,history完善

This commit is contained in:
fxjhello 2023-05-22 11:45:41 +08:00
parent b8272bfe14
commit 919a400cec
4 changed files with 15 additions and 17 deletions

4
api.py
View File

@ -249,7 +249,7 @@ async def local_doc_chat(
async def bing_search_chat( async def bing_search_chat(
question: str = Body(..., description="Question", example="工伤保险是什么?"), question: str = Body(..., description="Question", example="工伤保险是什么?"),
history: List[List[str]] = Body( history: Optional[List[List[str]]] = Body(
[], [],
description="History of previous questions and answers", description="History of previous questions and answers",
example=[ example=[
@ -265,7 +265,7 @@ async def bing_search_chat(
): ):
pass pass
source_documents = [ source_documents = [
f"""出处 [{inum + 1}] <a href="{doc.metadata["source"]}" target="_blank">{doc.metadata["source"]}</a> \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"]) for inum, doc in enumerate(resp["source_documents"])
] ]

View File

@ -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({ return api({
url: '/bing_search', url: '/local_doc_qa/bing_search_chat',
method: 'get', method: 'post',
params: { search_text }, data: JSON.stringify(params),
}) })
} }

View File

@ -40,7 +40,7 @@ const conversationList = computed(() => dataSources.value.filter(item => (!item.
const prompt = ref<string>('') const prompt = ref<string>('')
const loading = ref<boolean>(false) const loading = ref<boolean>(false)
const inputRef = ref<Ref | null>(null) const inputRef = ref<Ref | null>(null)
const search = ref<boolean>('对话') const search = ref<string>('对话')
// PromptStore // PromptStore
const promptStore = usePromptStore() const promptStore = usePromptStore()
@ -58,7 +58,7 @@ dataSources.value.forEach((item, index) => {
}) })
async function handleSubmit() { async function handleSubmit() {
if (search.value == 'Bing搜索') { if (search.value === 'Bing搜索') {
loading.value = true loading.value = true
const options: Chat.ConversationRequest = {} const options: Chat.ConversationRequest = {}
const lastText = '' const lastText = ''
@ -76,9 +76,9 @@ async function handleSubmit() {
}, },
) )
scrollToBottom() 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( addChat(
+uuid, +uuid,
{ {
@ -116,12 +116,10 @@ async function handleSubmit() {
async function onConversation() { async function onConversation() {
const message = prompt.value const message = prompt.value
history.value = [] history.value = []
if (usingContext.value) { if (usingContext.value) {
for (let i = 0; i < dataSources.value.length; i = i + 2) { 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]])
history.value.push([dataSources.value[i].text, dataSources.value[i + 1].text.split('\n\n数据来源\n\n>')[0]])
}
} }
else { history.value.length = 0 } else { history.value.length = 0 }
@ -589,7 +587,7 @@ onUnmounted(() => {
controller.abort() controller.abort()
}) })
function searchfun() { function searchfun() {
if (search.value == '知识库') if (search.value === '知识库')
active.value = true active.value = true
else else

View File

@ -37,7 +37,7 @@ export default defineConfig((env) => {
open: false, open: false,
proxy: { proxy: {
'/api': { '/api': {
target: 'http://127.0.0.1:7861', target: 'http://146.56.190.29:7861',
changeOrigin: true, // 允许跨域 changeOrigin: true, // 允许跨域
rewrite: path => path.replace('/api/', ''), rewrite: path => path.replace('/api/', ''),
}, },