mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
Fix: Added the ability to download files in the agent message reply function. (#11281)
### What problem does this PR solve? Fix: Added the ability to download files in the agent message reply function. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
@ -18,8 +18,10 @@ import { cn } from '@/lib/utils';
|
|||||||
import { AgentChatContext } from '@/pages/agent/context';
|
import { AgentChatContext } from '@/pages/agent/context';
|
||||||
import { WorkFlowTimeline } from '@/pages/agent/log-sheet/workflow-timeline';
|
import { WorkFlowTimeline } from '@/pages/agent/log-sheet/workflow-timeline';
|
||||||
import { IMessage } from '@/pages/chat/interface';
|
import { IMessage } from '@/pages/chat/interface';
|
||||||
|
import { downloadFile } from '@/services/file-manager-service';
|
||||||
|
import { downloadFileFromBlob } from '@/utils/file-util';
|
||||||
import { isEmpty } from 'lodash';
|
import { isEmpty } from 'lodash';
|
||||||
import { Atom, ChevronDown, ChevronUp } from 'lucide-react';
|
import { Atom, ChevronDown, ChevronUp, Download } from 'lucide-react';
|
||||||
import MarkdownContent from '../next-markdown-content';
|
import MarkdownContent from '../next-markdown-content';
|
||||||
import { RAGFlowAvatar } from '../ragflow-avatar';
|
import { RAGFlowAvatar } from '../ragflow-avatar';
|
||||||
import { useTheme } from '../theme-provider';
|
import { useTheme } from '../theme-provider';
|
||||||
@ -245,6 +247,32 @@ function MessageItem({
|
|||||||
{isUser && (
|
{isUser && (
|
||||||
<UploadedMessageFiles files={item.files}></UploadedMessageFiles>
|
<UploadedMessageFiles files={item.files}></UploadedMessageFiles>
|
||||||
)}
|
)}
|
||||||
|
{isAssistant && item.attachment && item.attachment.doc_id && (
|
||||||
|
<div className="w-full flex items-center justify-end">
|
||||||
|
<Button
|
||||||
|
variant="link"
|
||||||
|
className="p-1 m-0 h-auto text-text-sub-title-invert"
|
||||||
|
onClick={async () => {
|
||||||
|
if (item.attachment?.doc_id) {
|
||||||
|
try {
|
||||||
|
const response = await downloadFile({
|
||||||
|
docId: item.attachment.doc_id,
|
||||||
|
ext: item.attachment.format,
|
||||||
|
});
|
||||||
|
const blob = new Blob([response.data], {
|
||||||
|
type: response.data.type,
|
||||||
|
});
|
||||||
|
downloadFileFromBlob(blob, item.attachment.file_name);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Download failed:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Download size={16} />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
@ -44,9 +44,14 @@ export interface IInputData {
|
|||||||
inputs: Record<string, BeginQuery>;
|
inputs: Record<string, BeginQuery>;
|
||||||
tips: string;
|
tips: string;
|
||||||
}
|
}
|
||||||
|
export interface IAttachment {
|
||||||
|
doc_id: string;
|
||||||
|
format: string;
|
||||||
|
file_name: string;
|
||||||
|
}
|
||||||
export interface IMessageData {
|
export interface IMessageData {
|
||||||
content: string;
|
content: string;
|
||||||
|
outputs: any;
|
||||||
start_to_think?: boolean;
|
start_to_think?: boolean;
|
||||||
end_to_think?: boolean;
|
end_to_think?: boolean;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import { MessageType } from '@/constants/chat';
|
import { MessageType } from '@/constants/chat';
|
||||||
|
import { IAttachment } from '@/hooks/use-send-message';
|
||||||
|
|
||||||
export interface PromptConfig {
|
export interface PromptConfig {
|
||||||
empty_response: string;
|
empty_response: string;
|
||||||
@ -97,6 +98,7 @@ export interface Message {
|
|||||||
data?: any;
|
data?: any;
|
||||||
files?: File[];
|
files?: File[];
|
||||||
chatBoxId?: string;
|
chatBoxId?: string;
|
||||||
|
attachment?: IAttachment;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IReferenceChunk {
|
export interface IReferenceChunk {
|
||||||
@ -126,6 +128,7 @@ export interface IReferenceObject {
|
|||||||
|
|
||||||
export interface IAnswer {
|
export interface IAnswer {
|
||||||
answer: string;
|
answer: string;
|
||||||
|
attachment?: IAttachment;
|
||||||
reference?: IReference;
|
reference?: IReference;
|
||||||
conversationId?: string;
|
conversationId?: string;
|
||||||
prompt?: string;
|
prompt?: string;
|
||||||
|
|||||||
@ -1009,6 +1009,8 @@ Example: general/v2/`,
|
|||||||
pleaseUploadAtLeastOneFile: 'Please upload at least one file',
|
pleaseUploadAtLeastOneFile: 'Please upload at least one file',
|
||||||
},
|
},
|
||||||
flow: {
|
flow: {
|
||||||
|
downloadFileTypeTip: 'The file type to download',
|
||||||
|
downloadFileType: 'Download file type',
|
||||||
formatTypeError: 'Format or type error',
|
formatTypeError: 'Format or type error',
|
||||||
variableNameMessage:
|
variableNameMessage:
|
||||||
'Variable name can only contain letters and underscores',
|
'Variable name can only contain letters and underscores',
|
||||||
|
|||||||
@ -956,6 +956,8 @@ General:实体和关系提取提示来自 GitHub - microsoft/graphrag:基于
|
|||||||
pleaseUploadAtLeastOneFile: '请上传至少一个文件',
|
pleaseUploadAtLeastOneFile: '请上传至少一个文件',
|
||||||
},
|
},
|
||||||
flow: {
|
flow: {
|
||||||
|
downloadFileTypeTip: '文件下载的类型',
|
||||||
|
downloadFileType: '文件类型',
|
||||||
formatTypeError: '格式或类型错误',
|
formatTypeError: '格式或类型错误',
|
||||||
variableNameMessage: '名称只能包含字母和下划线',
|
variableNameMessage: '名称只能包含字母和下划线',
|
||||||
variableDescription: '变量的描述',
|
variableDescription: '变量的描述',
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import {
|
|||||||
useSelectDerivedMessages,
|
useSelectDerivedMessages,
|
||||||
} from '@/hooks/logic-hooks';
|
} from '@/hooks/logic-hooks';
|
||||||
import {
|
import {
|
||||||
|
IAttachment,
|
||||||
IEventList,
|
IEventList,
|
||||||
IInputEvent,
|
IInputEvent,
|
||||||
IMessageEndData,
|
IMessageEndData,
|
||||||
@ -75,9 +76,13 @@ export function findMessageFromList(eventList: IEventList) {
|
|||||||
nextContent += '</think>';
|
nextContent += '</think>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const workflowFinished = eventList.find(
|
||||||
|
(x) => x.event === MessageEventType.WorkflowFinished,
|
||||||
|
) as IMessageEvent;
|
||||||
return {
|
return {
|
||||||
id: eventList[0]?.message_id,
|
id: eventList[0]?.message_id,
|
||||||
content: nextContent,
|
content: nextContent,
|
||||||
|
attachment: workflowFinished?.data?.outputs?.attachment || {},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -388,12 +393,13 @@ export const useSendAgentMessage = ({
|
|||||||
}, [sendMessageInTaskMode]);
|
}, [sendMessageInTaskMode]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const { content, id } = findMessageFromList(answerList);
|
const { content, id, attachment } = findMessageFromList(answerList);
|
||||||
const inputAnswer = findInputFromList(answerList);
|
const inputAnswer = findInputFromList(answerList);
|
||||||
const answer = content || getLatestError(answerList);
|
const answer = content || getLatestError(answerList);
|
||||||
if (answerList.length > 0) {
|
if (answerList.length > 0) {
|
||||||
addNewestOneAnswer({
|
addNewestOneAnswer({
|
||||||
answer: answer ?? '',
|
answer: answer ?? '',
|
||||||
|
attachment: attachment as IAttachment,
|
||||||
id: id,
|
id: id,
|
||||||
...inputAnswer,
|
...inputAnswer,
|
||||||
});
|
});
|
||||||
|
|||||||
@ -417,6 +417,7 @@ export const initialIterationValues = {
|
|||||||
items_ref: '',
|
items_ref: '',
|
||||||
outputs: {},
|
outputs: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const initialIterationStartValues = {
|
export const initialIterationStartValues = {
|
||||||
outputs: {
|
outputs: {
|
||||||
item: {
|
item: {
|
||||||
@ -845,3 +846,10 @@ export enum JsonSchemaDataType {
|
|||||||
Array = 'array',
|
Array = 'array',
|
||||||
Object = 'object',
|
Object = 'object',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum ExportFileType {
|
||||||
|
PDF = 'pdf',
|
||||||
|
HTML = 'html',
|
||||||
|
Markdown = 'md',
|
||||||
|
DOCX = 'docx',
|
||||||
|
}
|
||||||
|
|||||||
@ -8,12 +8,14 @@ import {
|
|||||||
FormLabel,
|
FormLabel,
|
||||||
FormMessage,
|
FormMessage,
|
||||||
} from '@/components/ui/form';
|
} from '@/components/ui/form';
|
||||||
|
import { RAGFlowSelect } from '@/components/ui/select';
|
||||||
import { zodResolver } from '@hookform/resolvers/zod';
|
import { zodResolver } from '@hookform/resolvers/zod';
|
||||||
import { X } from 'lucide-react';
|
import { X } from 'lucide-react';
|
||||||
import { memo } from 'react';
|
import { memo } from 'react';
|
||||||
import { useFieldArray, useForm } from 'react-hook-form';
|
import { useFieldArray, useForm } from 'react-hook-form';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
import { ExportFileType } from '../../constant';
|
||||||
import { INextOperatorForm } from '../../interface';
|
import { INextOperatorForm } from '../../interface';
|
||||||
import { FormWrapper } from '../components/form-wrapper';
|
import { FormWrapper } from '../components/form-wrapper';
|
||||||
import { PromptEditor } from '../components/prompt-editor';
|
import { PromptEditor } from '../components/prompt-editor';
|
||||||
@ -33,10 +35,14 @@ function MessageForm({ node }: INextOperatorForm) {
|
|||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.optional(),
|
.optional(),
|
||||||
|
output_format: z.string().optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const form = useForm({
|
const form = useForm({
|
||||||
defaultValues: values,
|
defaultValues: {
|
||||||
|
...values,
|
||||||
|
output_format: values.output_format,
|
||||||
|
},
|
||||||
resolver: zodResolver(FormSchema),
|
resolver: zodResolver(FormSchema),
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -50,6 +56,39 @@ function MessageForm({ node }: INextOperatorForm) {
|
|||||||
return (
|
return (
|
||||||
<Form {...form}>
|
<Form {...form}>
|
||||||
<FormWrapper>
|
<FormWrapper>
|
||||||
|
<FormContainer>
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel tooltip={t('flow.downloadFileTypeTip')}>
|
||||||
|
{t('flow.downloadFileType')}
|
||||||
|
</FormLabel>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name={`output_format`}
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem className="flex-1">
|
||||||
|
<FormControl>
|
||||||
|
<RAGFlowSelect
|
||||||
|
options={Object.keys(ExportFileType).map(
|
||||||
|
(key: string) => {
|
||||||
|
return {
|
||||||
|
value:
|
||||||
|
ExportFileType[
|
||||||
|
key as keyof typeof ExportFileType
|
||||||
|
],
|
||||||
|
label: key,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
)}
|
||||||
|
{...field}
|
||||||
|
onValueChange={field.onChange}
|
||||||
|
placeholder={t('flow.messagePlaceholder')}
|
||||||
|
></RAGFlowSelect>
|
||||||
|
</FormControl>
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</FormItem>
|
||||||
|
</FormContainer>
|
||||||
<FormContainer>
|
<FormContainer>
|
||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel tooltip={t('flow.msgTip')}>{t('flow.msg')}</FormLabel>
|
<FormLabel tooltip={t('flow.msgTip')}>{t('flow.msg')}</FormLabel>
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import { RAGFlowNodeType } from '@/interfaces/database/flow';
|
import { RAGFlowNodeType } from '@/interfaces/database/flow';
|
||||||
import { isEmpty } from 'lodash';
|
import { isEmpty } from 'lodash';
|
||||||
import { useMemo } from 'react';
|
import { useMemo } from 'react';
|
||||||
import { initialMessageValues } from '../../constant';
|
import { ExportFileType, initialMessageValues } from '../../constant';
|
||||||
import { convertToObjectArray } from '../../utils';
|
import { convertToObjectArray } from '../../utils';
|
||||||
|
|
||||||
export function useValues(node?: RAGFlowNodeType) {
|
export function useValues(node?: RAGFlowNodeType) {
|
||||||
@ -15,6 +15,7 @@ export function useValues(node?: RAGFlowNodeType) {
|
|||||||
return {
|
return {
|
||||||
...formData,
|
...formData,
|
||||||
content: convertToObjectArray(formData.content),
|
content: convertToObjectArray(formData.content),
|
||||||
|
output_format: formData.output_format || ExportFileType.PDF,
|
||||||
};
|
};
|
||||||
}, [node]);
|
}, [node]);
|
||||||
|
|
||||||
|
|||||||
@ -13,6 +13,7 @@ const {
|
|||||||
get_document_file,
|
get_document_file,
|
||||||
getFile,
|
getFile,
|
||||||
moveFile,
|
moveFile,
|
||||||
|
get_document_file_download,
|
||||||
} = api;
|
} = api;
|
||||||
|
|
||||||
const methods = {
|
const methods = {
|
||||||
@ -65,4 +66,10 @@ const fileManagerService = registerServer<keyof typeof methods>(
|
|||||||
request,
|
request,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const downloadFile = (data: { docId: string; ext: string }) => {
|
||||||
|
return request.get(get_document_file_download(data.docId), {
|
||||||
|
params: { ext: data.ext },
|
||||||
|
responseType: 'blob',
|
||||||
|
});
|
||||||
|
};
|
||||||
export default fileManagerService;
|
export default fileManagerService;
|
||||||
|
|||||||
@ -100,6 +100,8 @@ export default {
|
|||||||
document_change_parser: `${api_host}/document/change_parser`,
|
document_change_parser: `${api_host}/document/change_parser`,
|
||||||
document_thumbnails: `${api_host}/document/thumbnails`,
|
document_thumbnails: `${api_host}/document/thumbnails`,
|
||||||
get_document_file: `${api_host}/document/get`,
|
get_document_file: `${api_host}/document/get`,
|
||||||
|
get_document_file_download: (docId: string) =>
|
||||||
|
`${api_host}/document/download/${docId}`,
|
||||||
document_upload: `${api_host}/document/upload`,
|
document_upload: `${api_host}/document/upload`,
|
||||||
web_crawl: `${api_host}/document/web_crawl`,
|
web_crawl: `${api_host}/document/web_crawl`,
|
||||||
document_infos: `${api_host}/document/infos`,
|
document_infos: `${api_host}/document/infos`,
|
||||||
|
|||||||
Reference in New Issue
Block a user