feat: Enhance file upload functionality with progress tracking
- Updated the `uploadKnowledgeFile` function to accept an optional progress callback, enabling real-time upload progress tracking. - Refactored the document upload handling in the menu component to support multiple file uploads with individual progress events. - Removed deprecated document processing state management from the KnowledgeBase view, streamlining the upload process. - Improved user feedback during file uploads by dispatching events for upload start, progress, and completion.
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
package types
|
||||
|
||||
const (
|
||||
TypeChunkExtract = "chunk:extract"
|
||||
TypeChunkExtract = "chunk:extract"
|
||||
TypeDocumentProcess = "document:process" // 文档处理任务
|
||||
TypeFAQImport = "faq:import" // FAQ导入任务
|
||||
)
|
||||
|
||||
type ExtractChunkPayload struct {
|
||||
@@ -10,6 +12,32 @@ type ExtractChunkPayload struct {
|
||||
ModelID string `json:"model_id"`
|
||||
}
|
||||
|
||||
// DocumentProcessPayload 文档处理任务payload
|
||||
type DocumentProcessPayload struct {
|
||||
RequestId string `json:"request_id"`
|
||||
TenantID uint `json:"tenant_id"`
|
||||
KnowledgeID string `json:"knowledge_id"`
|
||||
KnowledgeBaseID string `json:"knowledge_base_id"`
|
||||
FilePath string `json:"file_path,omitempty"` // 文件路径(文件导入时使用)
|
||||
FileName string `json:"file_name,omitempty"` // 文件名(文件导入时使用)
|
||||
FileType string `json:"file_type,omitempty"` // 文件类型(文件导入时使用)
|
||||
URL string `json:"url,omitempty"` // URL(URL导入时使用)
|
||||
Passages []string `json:"passages,omitempty"` // 文本段落(文本导入时使用)
|
||||
EnableMultimodel bool `json:"enable_multimodel"`
|
||||
}
|
||||
|
||||
// FAQImportPayload FAQ导入任务payload
|
||||
type FAQImportPayload struct {
|
||||
TenantID uint `json:"tenant_id"`
|
||||
TaskID string `json:"task_id"`
|
||||
KBID string `json:"kb_id"`
|
||||
KnowledgeID string `json:"knowledge_id"`
|
||||
Entries []FAQEntryPayload `json:"entries"`
|
||||
Mode string `json:"mode"`
|
||||
StartChunkIndex int `json:"start_chunk_index"`
|
||||
EndChunkIndex int `json:"end_chunk_index"`
|
||||
}
|
||||
|
||||
type PromptTemplateStructured struct {
|
||||
Description string `json:"description"`
|
||||
Tags []string `json:"tags"`
|
||||
|
||||
@@ -114,10 +114,10 @@ type FAQSearchRequest struct {
|
||||
type FAQImportTaskStatus string
|
||||
|
||||
const (
|
||||
FAQImportStatusPending FAQImportTaskStatus = "pending"
|
||||
FAQImportStatusRunning FAQImportTaskStatus = "running"
|
||||
FAQImportStatusSuccess FAQImportTaskStatus = "success"
|
||||
FAQImportStatusFailed FAQImportTaskStatus = "failed"
|
||||
FAQImportStatusPending FAQImportTaskStatus = "pending"
|
||||
FAQImportStatusProcessing FAQImportTaskStatus = "processing"
|
||||
FAQImportStatusCompleted FAQImportTaskStatus = "completed"
|
||||
FAQImportStatusFailed FAQImportTaskStatus = "failed"
|
||||
)
|
||||
|
||||
// FAQImportMetadata 存储在Knowledge.Metadata中的FAQ导入任务信息
|
||||
@@ -125,6 +125,7 @@ type FAQImportMetadata struct {
|
||||
ImportProgress int `json:"import_progress"` // 0-100
|
||||
ImportTotal int `json:"import_total"`
|
||||
ImportProcessed int `json:"import_processed"`
|
||||
NextChunkIndex int `json:"next_chunk_index,omitempty"` // 下一个要分配的ChunkIndex(自增计数器)
|
||||
}
|
||||
|
||||
// ToJSON converts the metadata to JSON type.
|
||||
|
||||
@@ -41,6 +41,7 @@ type ChunkRepository interface {
|
||||
DeleteByKnowledgeList(ctx context.Context, tenantID uint, knowledgeIDs []string) error
|
||||
// CountChunksByKnowledgeBaseID counts the number of chunks in a knowledge base.
|
||||
CountChunksByKnowledgeBaseID(ctx context.Context, tenantID uint, kbID string) (int64, error)
|
||||
DeleteChunksByChunkIndexRange(ctx context.Context, tenantID uint, knowledgeID string, startChunkIndex int, endChunkIndex int) ([]*types.Chunk, error)
|
||||
}
|
||||
|
||||
// ChunkService defines the interface for chunk service operations
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"mime/multipart"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
"github.com/hibiken/asynq"
|
||||
)
|
||||
|
||||
// KnowledgeService defines the interface for knowledge services.
|
||||
@@ -73,6 +74,10 @@ type KnowledgeService interface {
|
||||
UpdateFAQEntryTagBatch(ctx context.Context, kbID string, updates map[string]*string) error
|
||||
// GetRepository gets the knowledge repository
|
||||
GetRepository() KnowledgeRepository
|
||||
// ProcessDocument handles Asynq document processing tasks
|
||||
ProcessDocument(ctx context.Context, t *asynq.Task) error
|
||||
// ProcessFAQImport handles Asynq FAQ import tasks
|
||||
ProcessFAQImport(ctx context.Context, t *asynq.Task) error
|
||||
}
|
||||
|
||||
// KnowledgeRepository defines the interface for knowledge repositories.
|
||||
|
||||
Reference in New Issue
Block a user