feat: 新增FAQ批量导入dry run功能
This commit is contained in:
@@ -4,6 +4,7 @@ const (
|
||||
TypeChunkExtract = "chunk:extract"
|
||||
TypeDocumentProcess = "document:process" // 文档处理任务
|
||||
TypeFAQImport = "faq:import" // FAQ导入任务
|
||||
TypeFAQDryRun = "faq:dryrun" // FAQ导入预检任务
|
||||
TypeQuestionGeneration = "question:generation" // 问题生成任务
|
||||
TypeSummaryGeneration = "summary:generation" // 摘要生成任务
|
||||
TypeKBClone = "kb:clone" // 知识库复制任务
|
||||
@@ -45,6 +46,15 @@ type FAQImportPayload struct {
|
||||
Mode string `json:"mode"`
|
||||
}
|
||||
|
||||
// FAQDryRunPayload represents the FAQ dry run validation task payload
|
||||
type FAQDryRunPayload struct {
|
||||
TenantID uint64 `json:"tenant_id"`
|
||||
TaskID string `json:"task_id"`
|
||||
KBID string `json:"kb_id"`
|
||||
Entries []FAQEntryPayload `json:"entries"`
|
||||
Mode string `json:"mode"`
|
||||
}
|
||||
|
||||
// QuestionGenerationPayload represents the question generation task payload
|
||||
type QuestionGenerationPayload struct {
|
||||
TenantID uint64 `json:"tenant_id"`
|
||||
|
||||
@@ -219,6 +219,48 @@ type FAQBatchUpsertPayload struct {
|
||||
Entries []FAQEntryPayload `json:"entries" binding:"required"`
|
||||
Mode string `json:"mode" binding:"oneof=append replace"`
|
||||
KnowledgeID string `json:"knowledge_id"`
|
||||
TaskID string `json:"task_id"` // 可选,如果不传则自动生成UUID
|
||||
DryRun bool `json:"dry_run"` // 仅验证,不实际导入
|
||||
}
|
||||
|
||||
// FAQDryRunFailedEntry 表示 dry_run 模式下验证失败的条目
|
||||
type FAQDryRunFailedEntry struct {
|
||||
Index int `json:"index"` // 条目在批次中的索引(从0开始)
|
||||
Reason string `json:"reason"` // 失败原因
|
||||
TagName string `json:"tag_name,omitempty"` // 分类
|
||||
StandardQuestion string `json:"standard_question"` // 标准问题
|
||||
SimilarQuestions []string `json:"similar_questions,omitempty"` // 相似问题
|
||||
NegativeQuestions []string `json:"negative_questions,omitempty"` // 反例问题
|
||||
Answers []string `json:"answers,omitempty"` // 答案
|
||||
AnswerAll bool `json:"answer_all,omitempty"` // 是否全部回复
|
||||
IsDisabled bool `json:"is_disabled,omitempty"` // 是否停用
|
||||
}
|
||||
|
||||
// FAQDryRunResult 表示 dry_run 模式的验证结果
|
||||
type FAQDryRunResult struct {
|
||||
TaskID string `json:"task_id,omitempty"` // 异步任务ID(异步模式时返回)
|
||||
Total int `json:"total"` // 总条目数
|
||||
SuccessCount int `json:"success_count"` // 验证通过的条目数
|
||||
FailedCount int `json:"failed_count"` // 验证失败的条目数
|
||||
FailedEntries []FAQDryRunFailedEntry `json:"failed_entries"` // 失败条目详情
|
||||
}
|
||||
|
||||
// FAQDryRunProgress 表示 dry_run 异步任务的进度(存储在 Redis)
|
||||
type FAQDryRunProgress struct {
|
||||
TaskID string `json:"task_id"`
|
||||
KBID string `json:"kb_id"`
|
||||
Status FAQImportTaskStatus `json:"status"` // pending, processing, completed, failed
|
||||
Progress int `json:"progress"` // 0-100 percentage
|
||||
Total int `json:"total"` // 总条目数
|
||||
Processed int `json:"processed"` // 已处理条目数
|
||||
SuccessCount int `json:"success_count"` // 验证通过的条目数
|
||||
FailedCount int `json:"failed_count"` // 验证失败的条目数
|
||||
FailedEntries []FAQDryRunFailedEntry `json:"failed_entries,omitempty"` // 失败条目详情(少量时直接返回)
|
||||
FailedEntriesURL string `json:"failed_entries_url,omitempty"` // 失败条目CSV下载URL(大量时返回URL)
|
||||
Message string `json:"message"` // 状态消息
|
||||
Error string `json:"error,omitempty"` // 错误信息
|
||||
CreatedAt int64 `json:"created_at"`
|
||||
UpdatedAt int64 `json:"updated_at"`
|
||||
}
|
||||
|
||||
// FAQSearchRequest FAQ检索请求参数
|
||||
|
||||
@@ -11,8 +11,13 @@ import (
|
||||
type FileService interface {
|
||||
// SaveFile saves a file.
|
||||
SaveFile(ctx context.Context, file *multipart.FileHeader, tenantID uint64, knowledgeID string) (string, error)
|
||||
// SaveBytes saves bytes data to a file and returns the file path.
|
||||
// If temp is true, the file will be saved to a temporary storage that may auto-expire.
|
||||
SaveBytes(ctx context.Context, data []byte, tenantID uint64, fileName string, temp bool) (string, error)
|
||||
// GetFile retrieves a file.
|
||||
GetFile(ctx context.Context, filePath string) (io.ReadCloser, error)
|
||||
// GetFileURL returns a download URL for the file (if supported by the storage backend).
|
||||
GetFileURL(ctx context.Context, filePath string) (string, error)
|
||||
// DeleteFile deletes a file.
|
||||
DeleteFile(ctx context.Context, filePath string) error
|
||||
}
|
||||
|
||||
@@ -88,6 +88,13 @@ type KnowledgeService interface {
|
||||
// UpsertFAQEntries imports or appends FAQ entries asynchronously.
|
||||
// Returns task ID (Knowledge ID) for tracking import progress.
|
||||
UpsertFAQEntries(ctx context.Context, kbID string, payload *types.FAQBatchUpsertPayload) (string, error)
|
||||
// ValidateFAQEntriesDryRun validates FAQ entries asynchronously without actually importing them.
|
||||
// Returns task ID for tracking validation progress.
|
||||
ValidateFAQEntriesDryRun(ctx context.Context, kbID string, payload *types.FAQBatchUpsertPayload) (string, error)
|
||||
// GetFAQDryRunProgress retrieves the progress of an FAQ dry run validation task.
|
||||
GetFAQDryRunProgress(ctx context.Context, taskID string) (*types.FAQDryRunProgress, error)
|
||||
// ProcessFAQDryRun handles Asynq FAQ dry run validation tasks.
|
||||
ProcessFAQDryRun(ctx context.Context, t *asynq.Task) error
|
||||
// CreateFAQEntry creates a single FAQ entry synchronously.
|
||||
CreateFAQEntry(ctx context.Context, kbID string, payload *types.FAQEntryPayload) (*types.FAQEntry, error)
|
||||
// GetFAQEntry retrieves a single FAQ entry by ID.
|
||||
|
||||
Reference in New Issue
Block a user