feat(chat): 尝试在对话中加入知识库
This commit is contained in:
@@ -2,10 +2,10 @@ import {ClearOutlined, FileOutlined, UserOutlined} from '@ant-design/icons'
|
||||
import {Bubble, Sender, useXAgent, useXChat, Welcome} from '@ant-design/x'
|
||||
import {fetchEventSource} from '@echofly/fetch-event-source'
|
||||
import {useMount} from 'ahooks'
|
||||
import {Button, Divider, Flex, Popover, Radio, Switch, Tooltip, Typography} from 'antd'
|
||||
import {Button, Collapse, Divider, Flex, Popover, Radio, Switch, Tooltip, Typography} from 'antd'
|
||||
import {isEqual, isStrBlank, trim} from 'licia'
|
||||
import markdownIt from 'markdown-it'
|
||||
import {useRef, useState} from 'react'
|
||||
import {useMemo, useRef, useState} from 'react'
|
||||
import styled from 'styled-components'
|
||||
import {commonInfo} from '../../util/amis.tsx'
|
||||
|
||||
@@ -31,8 +31,8 @@ const ConversationDiv = styled.div`
|
||||
think {
|
||||
color: gray;
|
||||
display: block;
|
||||
border-left: 3px solid;
|
||||
padding-left: 5px;
|
||||
border-left: 3px solid lightgray;
|
||||
padding-left: 10px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
}
|
||||
@@ -52,6 +52,13 @@ function Conversation() {
|
||||
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`, {
|
||||
@@ -63,10 +70,6 @@ function Conversation() {
|
||||
|
||||
const [agent] = useXAgent<ChatMessage>({
|
||||
request: async (info, callbacks) => {
|
||||
let requestUrl = `${commonInfo.baseAiChatUrl}/chat/async`
|
||||
if (!isEqual('0', knowledge)) {
|
||||
requestUrl = `${requestUrl}?knowledge=${knowledge}`
|
||||
}
|
||||
await fetchEventSource(requestUrl, {
|
||||
method: 'POST',
|
||||
headers: commonInfo.authorizationHeaders,
|
||||
@@ -124,17 +127,33 @@ function Conversation() {
|
||||
},
|
||||
},
|
||||
messageRender: item => {
|
||||
let content = ''
|
||||
let content = '', reason = ''
|
||||
if (!isStrBlank(item['reason'])) {
|
||||
content = `<think>${trim(md.render(item['reason']))}</think>${trim(md.render(item['content']))}`
|
||||
} else {
|
||||
content = trim(md.render(item['content']))
|
||||
reason = `${trim(md.render(item['reason']))}`
|
||||
}
|
||||
console.log(content)
|
||||
content = trim(md.render(item['content']))
|
||||
return (
|
||||
<Typography>
|
||||
<div dangerouslySetInnerHTML={{__html: content}}/>
|
||||
</Typography>
|
||||
<div>
|
||||
{isStrBlank(reason)
|
||||
? <span/>
|
||||
: <Collapse
|
||||
size="small"
|
||||
items={[
|
||||
{
|
||||
key: 0,
|
||||
label: '思考链',
|
||||
children: (
|
||||
<Typography>
|
||||
<div dangerouslySetInnerHTML={{__html: reason}}/>
|
||||
</Typography>
|
||||
),
|
||||
},
|
||||
]}
|
||||
/>}
|
||||
<Typography>
|
||||
<div dangerouslySetInnerHTML={{__html: content}}/>
|
||||
</Typography>
|
||||
</div>
|
||||
)
|
||||
},
|
||||
},
|
||||
|
||||
@@ -146,7 +146,7 @@ const DataDetail: React.FC = () => {
|
||||
level: 'link',
|
||||
size: 'sm',
|
||||
actionType: 'ajax',
|
||||
api: `${commonInfo.baseAiKnowledgeUrl}/group/delete?id=\${id}`,
|
||||
api: `get:${commonInfo.baseAiKnowledgeUrl}/group/delete?id=\${id}`,
|
||||
confirmText: '确认删除',
|
||||
confirmTitle: '删除',
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user