feat(knowledge): enhance FAQ export functionality
- Updated the exportFAQEntries function to support exporting FAQ entries in both CSV and JSON formats. - Modified the frontend to include options for selecting the export format. - Enhanced localization files to reflect the new export options in English, Russian, and Chinese. - Implemented new tests to validate the export functionality for both formats. This commit improves the flexibility of FAQ exports, allowing users to choose their preferred format for better integration with other tools.
This commit is contained in:
@@ -675,23 +675,47 @@ func (s *knowledgeService) cloneFAQKnowledgeBase(
|
||||
}
|
||||
srcKnowledge := srcKnowledgeList[0]
|
||||
|
||||
// Get chunk-level differences based on content_hash
|
||||
chunksToAdd, chunksToDelete, err := s.chunkRepo.FAQChunkDiff(ctx, srcKB.TenantID, srcKB.ID, dstKB.TenantID, dstKB.ID)
|
||||
// Get chunk-level differences based on content_hash.
|
||||
diff, err := s.chunkRepo.FAQChunkDiff(ctx, srcKB.TenantID, srcKB.ID, dstKB.TenantID, dstKB.ID)
|
||||
if err != nil {
|
||||
logger.Errorf(ctx, "Failed to calculate FAQ chunk difference: %v", err)
|
||||
handleError(progress, err, "Failed to calculate FAQ chunk difference")
|
||||
return err
|
||||
}
|
||||
chunksToAdd := diff.ChunksToAdd
|
||||
chunksToDelete := diff.ChunksToDelete
|
||||
|
||||
totalOperations := len(chunksToAdd) + len(chunksToDelete)
|
||||
tagIDMapping := map[string]string{}
|
||||
resolveFAQTag := func(srcTagID string) string {
|
||||
if srcTagID == "" {
|
||||
return ""
|
||||
}
|
||||
if id, ok := tagIDMapping[srcTagID]; ok {
|
||||
return id
|
||||
}
|
||||
return s.getOrCreateTagInTarget(ctx, srcKB.TenantID, dstKB.TenantID, dstKB.ID, srcTagID, tagIDMapping)
|
||||
}
|
||||
|
||||
syncPlan, err := s.buildFAQStatusSyncPlan(ctx, srcKB.TenantID, dstKB.TenantID, diff.MatchedPairs, resolveFAQTag)
|
||||
if err != nil {
|
||||
logger.Errorf(ctx, "Failed to build FAQ status sync plan: %v", err)
|
||||
handleError(progress, err, "Failed to build FAQ status sync plan")
|
||||
return err
|
||||
}
|
||||
chunksToUpdate := syncPlan.Pairs
|
||||
|
||||
totalOperations := len(chunksToAdd) + len(chunksToDelete) + len(chunksToUpdate)
|
||||
progress.Total = totalOperations
|
||||
progress.Message = fmt.Sprintf("Found %d FAQ entries to add, %d to delete", len(chunksToAdd), len(chunksToDelete))
|
||||
progress.Message = fmt.Sprintf(
|
||||
"Found %d FAQ entries to add, %d to delete, %d to update status",
|
||||
len(chunksToAdd), len(chunksToDelete), len(chunksToUpdate),
|
||||
)
|
||||
progress.UpdatedAt = time.Now().Unix()
|
||||
_ = s.saveKBCloneProgress(ctx, progress)
|
||||
|
||||
logger.Infof(ctx, "FAQ chunks to add: %d, delete: %d", len(chunksToAdd), len(chunksToDelete))
|
||||
logger.Infof(ctx, "FAQ chunks to add: %d, delete: %d, update status: %d",
|
||||
len(chunksToAdd), len(chunksToDelete), len(chunksToUpdate))
|
||||
|
||||
// If nothing to do, mark as completed
|
||||
if totalOperations == 0 {
|
||||
progress.Status = types.KBCloneStatusCompleted
|
||||
progress.Progress = 100
|
||||
@@ -760,7 +784,6 @@ func (s *knowledgeService) cloneFAQKnowledgeBase(
|
||||
|
||||
// Clone FAQ chunks from source to destination
|
||||
batch := 50
|
||||
tagIDMapping := map[string]string{} // srcTagID -> dstTagID
|
||||
for i := 0; i < len(chunksToAdd); i += batch {
|
||||
end := i + batch
|
||||
if end > len(chunksToAdd) {
|
||||
@@ -782,19 +805,11 @@ func (s *knowledgeService) cloneFAQKnowledgeBase(
|
||||
// Map TagID to target knowledge base
|
||||
targetTagID := ""
|
||||
if srcChunk.TagID != "" {
|
||||
if mappedTagID, ok := tagIDMapping[srcChunk.TagID]; ok {
|
||||
targetTagID = mappedTagID
|
||||
} else {
|
||||
// Try to find or create the tag in target knowledge base
|
||||
targetTagID = s.getOrCreateTagInTarget(ctx, srcKB.TenantID, dstKB.TenantID, dstKB.ID, srcChunk.TagID, tagIDMapping)
|
||||
}
|
||||
targetTagID = resolveFAQTag(srcChunk.TagID)
|
||||
}
|
||||
|
||||
// Deep-copy extracted images into objects owned by the destination
|
||||
// FAQ knowledge so deleting the source never breaks this clone. A FAQ
|
||||
// chunk is self-contained (its own Content + image_info), so its
|
||||
//  references can be rewritten immediately using the mapping
|
||||
// just accumulated in imageURLCache.
|
||||
// FAQ knowledge so deleting the source never breaks this clone.
|
||||
newImageInfo, copied, copyErr := cloneChunkImageInfo(
|
||||
ctx, dstSvc, srcChunk.ImageInfo, dstKB.TenantID, dstKnowledge.ID, imageURLCache)
|
||||
if copyErr != nil {
|
||||
@@ -860,6 +875,27 @@ func (s *knowledgeService) cloneFAQKnowledgeBase(
|
||||
_ = s.saveKBCloneProgress(ctx, progress)
|
||||
}
|
||||
|
||||
for i := 0; i < len(chunksToUpdate); i += batch {
|
||||
end := i + batch
|
||||
if end > len(chunksToUpdate) {
|
||||
end = len(chunksToUpdate)
|
||||
}
|
||||
if err := s.syncFAQChunkStatusBatch(
|
||||
ctx, dstKB, chunksToUpdate[i:end], syncPlan.SrcByID, syncPlan.DstByID, resolveFAQTag); err != nil {
|
||||
logger.Errorf(ctx, "Failed to sync FAQ status fields: %v", err)
|
||||
handleError(progress, err, "Failed to sync FAQ status fields")
|
||||
return err
|
||||
}
|
||||
processedCount += end - i
|
||||
if totalOperations > 0 {
|
||||
progress.Progress = processedCount * 100 / totalOperations
|
||||
}
|
||||
progress.Processed = processedCount
|
||||
progress.Message = fmt.Sprintf("Updated %d/%d FAQ status fields", processedCount-len(chunksToDelete)-len(chunksToAdd), len(chunksToUpdate))
|
||||
progress.UpdatedAt = time.Now().Unix()
|
||||
_ = s.saveKBCloneProgress(ctx, progress)
|
||||
}
|
||||
|
||||
// Mark as completed
|
||||
progress.Status = types.KBCloneStatusCompleted
|
||||
progress.Progress = 100
|
||||
|
||||
Reference in New Issue
Block a user