fix(web): 修复知识库id没有及时添加到http请求中
This commit is contained in:
@@ -5,7 +5,7 @@ import {useMount} from 'ahooks'
|
||||
import {Button, Collapse, Divider, Flex, Popover, Radio, Switch, Tooltip, Typography} from 'antd'
|
||||
import {isEqual, isStrBlank, trim} from 'licia'
|
||||
import markdownIt from 'markdown-it'
|
||||
import {useMemo, useRef, useState} from 'react'
|
||||
import {useRef, useState} from 'react'
|
||||
import styled from 'styled-components'
|
||||
import {commonInfo} from '../../util/amis.tsx'
|
||||
|
||||
@@ -49,16 +49,8 @@ type ChatMessage = { role: string, content?: string, reason?: string }
|
||||
function Conversation() {
|
||||
const abortController = useRef<AbortController | null>(null)
|
||||
const [input, setInput] = useState<string>('')
|
||||
const [think, setThink] = useState<boolean>(true)
|
||||
const [knowledge, setKnowledge] = useState<string>('0')
|
||||
const [knowledgeList, setKnowledgeList] = useState<{ id: string, name: string }[]>([])
|
||||
const requestUrl = useMemo(() => {
|
||||
let url = `${commonInfo.baseAiChatUrl}/chat/async`
|
||||
if (!isEqual('0', knowledge)) {
|
||||
url = `${url}?knowledge_id=${knowledge}`
|
||||
}
|
||||
return url
|
||||
}, [knowledge])
|
||||
|
||||
useMount(async () => {
|
||||
let response = await fetch(`${commonInfo.baseAiKnowledgeUrl}/knowledge/list`, {
|
||||
@@ -70,6 +62,10 @@ function Conversation() {
|
||||
|
||||
const [agent] = useXAgent<ChatMessage>({
|
||||
request: async (info, callbacks) => {
|
||||
let requestUrl = `${commonInfo.baseAiChatUrl}/chat/async`
|
||||
if (!isEqual('0', info.knowledge)) {
|
||||
requestUrl = `${requestUrl}?knowledge_id=${info.knowledge}`
|
||||
}
|
||||
await fetchEventSource(requestUrl, {
|
||||
method: 'POST',
|
||||
headers: commonInfo.authorizationHeaders,
|
||||
@@ -193,9 +189,10 @@ function Conversation() {
|
||||
onRequest({
|
||||
message: {
|
||||
role: 'user',
|
||||
content: (!think && messages.length === 0) ? `/no_think ${message}` : message,
|
||||
content: message,
|
||||
},
|
||||
stream: true,
|
||||
knowledge: knowledge,
|
||||
})
|
||||
setInput('')
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user