forked from infiniflow/ragflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Supports chatting with files/images infiniflow#1880 (infiniflow…
…#1943) ### What problem does this PR solve? feat: Supports chatting with files/images infiniflow#1880 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
- Loading branch information
Showing
17 changed files
with
487 additions
and
37 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { useFetchKnowledgeGraph } from '@/hooks/chunk-hooks'; | ||
import { Modal } from 'antd'; | ||
import { useTranslation } from 'react-i18next'; | ||
import IndentedTree from './indented-tree'; | ||
|
||
import { IModalProps } from '@/interfaces/common'; | ||
|
||
const IndentedTreeModal = ({ | ||
documentId, | ||
visible, | ||
hideModal, | ||
}: IModalProps<any> & { documentId: string }) => { | ||
const { data } = useFetchKnowledgeGraph(documentId); | ||
const { t } = useTranslation(); | ||
|
||
return ( | ||
<Modal | ||
title={t('chunk.graph')} | ||
open={visible} | ||
onCancel={hideModal} | ||
width={'90vw'} | ||
footer={null} | ||
> | ||
<section> | ||
<IndentedTree data={data?.data?.mind_map} show></IndentedTree> | ||
</section> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export default IndentedTreeModal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
import { Authorization } from '@/constants/authorization'; | ||
import { useTranslate } from '@/hooks/common-hooks'; | ||
import { getAuthorization } from '@/utils/authorization-util'; | ||
import { PlusOutlined } from '@ant-design/icons'; | ||
import type { GetProp, UploadFile } from 'antd'; | ||
import { Button, Flex, Input, Upload, UploadProps } from 'antd'; | ||
import get from 'lodash/get'; | ||
import { ChangeEventHandler, useCallback, useState } from 'react'; | ||
|
||
type FileType = Parameters<GetProp<UploadProps, 'beforeUpload'>>[0]; | ||
|
||
interface IProps { | ||
disabled: boolean; | ||
value: string; | ||
sendDisabled: boolean; | ||
sendLoading: boolean; | ||
onPressEnter(documentIds: string[]): Promise<any>; | ||
onInputChange: ChangeEventHandler<HTMLInputElement>; | ||
conversationId: string; | ||
} | ||
|
||
const getBase64 = (file: FileType): Promise<string> => | ||
new Promise((resolve, reject) => { | ||
const reader = new FileReader(); | ||
reader.readAsDataURL(file as any); | ||
reader.onload = () => resolve(reader.result as string); | ||
reader.onerror = (error) => reject(error); | ||
}); | ||
|
||
const MessageInput = ({ | ||
disabled, | ||
value, | ||
onPressEnter, | ||
sendDisabled, | ||
sendLoading, | ||
onInputChange, | ||
conversationId, | ||
}: IProps) => { | ||
const { t } = useTranslate('chat'); | ||
|
||
const [fileList, setFileList] = useState<UploadFile[]>([ | ||
// { | ||
// uid: '-1', | ||
// name: 'image.png', | ||
// status: 'done', | ||
// url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png', | ||
// }, | ||
// { | ||
// uid: '-xxx', | ||
// percent: 50, | ||
// name: 'image.png', | ||
// status: 'uploading', | ||
// url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png', | ||
// }, | ||
// { | ||
// uid: '-5', | ||
// name: 'image.png', | ||
// status: 'error', | ||
// }, | ||
]); | ||
|
||
const handlePreview = async (file: UploadFile) => { | ||
if (!file.url && !file.preview) { | ||
file.preview = await getBase64(file.originFileObj as FileType); | ||
} | ||
|
||
// setPreviewImage(file.url || (file.preview as string)); | ||
// setPreviewOpen(true); | ||
}; | ||
|
||
const handleChange: UploadProps['onChange'] = ({ fileList: newFileList }) => { | ||
console.log('🚀 ~ newFileList:', newFileList); | ||
setFileList(newFileList); | ||
}; | ||
|
||
const handlePressEnter = useCallback(async () => { | ||
const ids = fileList.reduce((pre, cur) => { | ||
return pre.concat(get(cur, 'response.data', [])); | ||
}, []); | ||
|
||
await onPressEnter(ids); | ||
setFileList([]); | ||
}, [fileList, onPressEnter]); | ||
|
||
const uploadButton = ( | ||
<button style={{ border: 0, background: 'none' }} type="button"> | ||
<PlusOutlined /> | ||
<div style={{ marginTop: 8 }}>Upload</div> | ||
</button> | ||
); | ||
|
||
return ( | ||
<Flex gap={10} vertical> | ||
<Input | ||
size="large" | ||
placeholder={t('sendPlaceholder')} | ||
value={value} | ||
disabled={disabled} | ||
suffix={ | ||
<Button | ||
type="primary" | ||
onClick={handlePressEnter} | ||
loading={sendLoading} | ||
disabled={sendDisabled} | ||
> | ||
{t('send')} | ||
</Button> | ||
} | ||
onPressEnter={handlePressEnter} | ||
onChange={onInputChange} | ||
/> | ||
<Upload | ||
action="/v1/document/upload_and_parse" | ||
listType="picture-card" | ||
fileList={fileList} | ||
onPreview={handlePreview} | ||
onChange={handleChange} | ||
multiple | ||
headers={{ [Authorization]: getAuthorization() }} | ||
data={{ conversation_id: conversationId }} | ||
method="post" | ||
> | ||
{fileList.length >= 8 ? null : uploadButton} | ||
</Upload> | ||
</Flex> | ||
); | ||
}; | ||
|
||
export default MessageInput; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.