feat(web): 增加知识库选择

This commit is contained in:
v-zhangjc9
2025-05-30 17:35:24 +08:00
parent dc5998cf72
commit 3901a47da0

View File

@@ -1,10 +1,11 @@
import {ClearOutlined, UserOutlined} from '@ant-design/icons'
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 {Button, Divider, Flex, Switch, Tooltip, Typography} from 'antd'
import {Button, Divider, Flex, Popover, Radio, Switch, Tooltip, Typography} from 'antd'
import markdownIt from 'markdown-it'
import {useRef, useState} from 'react'
import styled from 'styled-components'
import {commonInfo} from '../../util/amis.tsx'
const md = markdownIt({html: true, breaks: true})
const ConversationDiv = styled.div`
@@ -49,7 +50,7 @@ function Conversation() {
const [agent] = useXAgent<{ role: string, content: string }>({
request: async (info, callbacks) => {
await fetchEventSource('http://127.0.0.1:8080/chat/async', {
await fetchEventSource(`${commonInfo.baseAiChatUrl}/chat/async`, {
method: 'POST',
headers: {
'Authorization': 'Basic QXhoRWJzY3dzSkRiWU1IMjpjWXhnM2I0UHRXb1ZENVNqRmF5V3h0blNWc2p6UnNnNA==',
@@ -105,13 +106,9 @@ function Conversation() {
},
},
messageRender: content => {
let split = content.split('</think>')
if (split.length > 1) {
content = `${split[0]}</think>${md.render(split[1])}`
}
return (
<Typography>
<div dangerouslySetInnerHTML={{__html: content}}/>
<div dangerouslySetInnerHTML={{__html: md.render(content)}}/>
</Typography>
)
},
@@ -164,6 +161,28 @@ function Conversation() {
disabled={messages.length > 0}
/>
<Divider type="vertical"/>
<Popover
title="选择知识库"
trigger="hover"
content={<Radio.Group
style={{
display: 'flex',
flexDirection: 'column',
gap: 10,
}}
options={[
{value: 1, label: '测试'},
{value: 2, label: 'Hudi'},
{value: 3, label: 'Apache Hudi'},
]}
/>}
>
<Button
icon={<FileOutlined/>}
type="text"
size="small"
/>
</Popover>
<Tooltip title="清空对话">
<Button
icon={<ClearOutlined/>}
@@ -172,6 +191,7 @@ function Conversation() {
onClick={() => setMessages([])}
/>
</Tooltip>
<Divider type="vertical"/>
</Flex>
<Flex align="center">
{agent.isRequesting() ? (