mirror of
https://github.com/Crosstalk-Solutions/project-nomad.git
synced 2026-04-04 07:46:16 +02:00
feat(KnowledgeBase): support up to 5 files upload of 100mb each per req
This commit is contained in:
parent
1bd1811498
commit
a14dd688fa
|
|
@ -47,7 +47,7 @@ const bodyParserConfig = defineConfig({
|
||||||
* Maximum limit of data to parse including all files
|
* Maximum limit of data to parse including all files
|
||||||
* and fields
|
* and fields
|
||||||
*/
|
*/
|
||||||
limit: '20mb',
|
limit: '110mb', // Set to 110MB to allow for some overhead beyond the 100MB file size limit
|
||||||
types: ['multipart/form-data'],
|
types: ['multipart/form-data'],
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ function sourceToDisplayName(source: string): string {
|
||||||
export default function KnowledgeBaseModal({ aiAssistantName = "AI Assistant", onClose }: KnowledgeBaseModalProps) {
|
export default function KnowledgeBaseModal({ aiAssistantName = "AI Assistant", onClose }: KnowledgeBaseModalProps) {
|
||||||
const { addNotification } = useNotifications()
|
const { addNotification } = useNotifications()
|
||||||
const [files, setFiles] = useState<File[]>([])
|
const [files, setFiles] = useState<File[]>([])
|
||||||
|
const [isUploading, setIsUploading] = useState(false)
|
||||||
const [confirmDeleteSource, setConfirmDeleteSource] = useState<string | null>(null)
|
const [confirmDeleteSource, setConfirmDeleteSource] = useState<string | null>(null)
|
||||||
const fileUploaderRef = useRef<React.ComponentRef<typeof FileUploader>>(null)
|
const fileUploaderRef = useRef<React.ComponentRef<typeof FileUploader>>(null)
|
||||||
const { openModal, closeModal } = useModals()
|
const { openModal, closeModal } = useModals()
|
||||||
|
|
@ -37,23 +38,6 @@ export default function KnowledgeBaseModal({ aiAssistantName = "AI Assistant", o
|
||||||
|
|
||||||
const uploadMutation = useMutation({
|
const uploadMutation = useMutation({
|
||||||
mutationFn: (file: File) => api.uploadDocument(file),
|
mutationFn: (file: File) => api.uploadDocument(file),
|
||||||
onSuccess: (data) => {
|
|
||||||
addNotification({
|
|
||||||
type: 'success',
|
|
||||||
message: data?.message || 'Document uploaded and queued for processing',
|
|
||||||
})
|
|
||||||
setFiles([])
|
|
||||||
if (fileUploaderRef.current) {
|
|
||||||
fileUploaderRef.current.clear()
|
|
||||||
}
|
|
||||||
queryClient.invalidateQueries({ queryKey: ['embed-jobs'] })
|
|
||||||
},
|
|
||||||
onError: (error: any) => {
|
|
||||||
addNotification({
|
|
||||||
type: 'error',
|
|
||||||
message: error?.message || 'Failed to upload document',
|
|
||||||
})
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const deleteMutation = useMutation({
|
const deleteMutation = useMutation({
|
||||||
|
|
@ -96,9 +80,34 @@ export default function KnowledgeBaseModal({ aiAssistantName = "AI Assistant", o
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
const handleUpload = () => {
|
const handleUpload = async () => {
|
||||||
if (files.length > 0) {
|
if (files.length === 0) return
|
||||||
uploadMutation.mutate(files[0])
|
setIsUploading(true)
|
||||||
|
let successCount = 0
|
||||||
|
const failedNames: string[] = []
|
||||||
|
|
||||||
|
for (const file of files) {
|
||||||
|
try {
|
||||||
|
await uploadMutation.mutateAsync(file)
|
||||||
|
successCount++
|
||||||
|
} catch (error: any) {
|
||||||
|
failedNames.push(file.name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setIsUploading(false)
|
||||||
|
setFiles([])
|
||||||
|
fileUploaderRef.current?.clear()
|
||||||
|
queryClient.invalidateQueries({ queryKey: ['embed-jobs'] })
|
||||||
|
|
||||||
|
if (successCount > 0) {
|
||||||
|
addNotification({
|
||||||
|
type: 'success',
|
||||||
|
message: `${successCount} file${successCount > 1 ? 's' : ''} queued for processing.`,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
for (const name of failedNames) {
|
||||||
|
addNotification({ type: 'error', message: `Failed to upload: ${name}` })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -145,7 +154,7 @@ export default function KnowledgeBaseModal({ aiAssistantName = "AI Assistant", o
|
||||||
<FileUploader
|
<FileUploader
|
||||||
ref={fileUploaderRef}
|
ref={fileUploaderRef}
|
||||||
minFiles={1}
|
minFiles={1}
|
||||||
maxFiles={1}
|
maxFiles={5}
|
||||||
onUpload={(uploadedFiles) => {
|
onUpload={(uploadedFiles) => {
|
||||||
setFiles(Array.from(uploadedFiles))
|
setFiles(Array.from(uploadedFiles))
|
||||||
}}
|
}}
|
||||||
|
|
@ -156,8 +165,8 @@ export default function KnowledgeBaseModal({ aiAssistantName = "AI Assistant", o
|
||||||
size="lg"
|
size="lg"
|
||||||
icon="IconUpload"
|
icon="IconUpload"
|
||||||
onClick={handleUpload}
|
onClick={handleUpload}
|
||||||
disabled={files.length === 0 || uploadMutation.isPending}
|
disabled={files.length === 0 || isUploading}
|
||||||
loading={uploadMutation.isPending}
|
loading={isUploading}
|
||||||
>
|
>
|
||||||
Upload
|
Upload
|
||||||
</StyledButton>
|
</StyledButton>
|
||||||
|
|
@ -243,8 +252,8 @@ export default function KnowledgeBaseModal({ aiAssistantName = "AI Assistant", o
|
||||||
size="md"
|
size="md"
|
||||||
icon='IconRefresh'
|
icon='IconRefresh'
|
||||||
onClick={handleConfirmSync}
|
onClick={handleConfirmSync}
|
||||||
disabled={syncMutation.isPending || uploadMutation.isPending}
|
disabled={syncMutation.isPending || isUploading}
|
||||||
loading={syncMutation.isPending || uploadMutation.isPending}
|
loading={syncMutation.isPending || isUploading}
|
||||||
>
|
>
|
||||||
Sync Storage
|
Sync Storage
|
||||||
</StyledButton>
|
</StyledButton>
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ const FileUploader = forwardRef<FileUploaderRef, FileUploaderProps>((props, ref)
|
||||||
const {
|
const {
|
||||||
minFiles = 0,
|
minFiles = 0,
|
||||||
maxFiles = 1,
|
maxFiles = 1,
|
||||||
maxFileSize = 10485760, // default to 10MB
|
maxFileSize = 104857600, // default to 100MB
|
||||||
fileTypes,
|
fileTypes,
|
||||||
disabled = false,
|
disabled = false,
|
||||||
onUpload,
|
onUpload,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user