refactor: 合并 FAQ 导入和验证逻辑

This commit is contained in:
wizardchen
2026-01-06 15:17:08 +08:00
parent 100484f13d
commit a63a2a8daf
8 changed files with 240 additions and 463 deletions
+30 -65
View File
@@ -344,19 +344,37 @@ func (c *Client) ExportFAQEntries(ctx context.Context, knowledgeBaseID string) (
return data, nil
}
// FAQFailedEntry represents a failed entry during FAQ import/validation.
type FAQFailedEntry struct {
Index int `json:"index"`
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"`
}
// FAQImportProgress represents the progress of an async FAQ import task.
type FAQImportProgress struct {
TaskID string `json:"task_id"`
KBID string `json:"kb_id"`
KnowledgeID string `json:"knowledge_id"`
Status string `json:"status"`
Progress int `json:"progress"`
Total int `json:"total"`
Processed int `json:"processed"`
Message string `json:"message"`
Error string `json:"error,omitempty"`
CreatedAt int64 `json:"created_at"`
UpdatedAt int64 `json:"updated_at"`
TaskID string `json:"task_id"`
KBID string `json:"kb_id"`
KnowledgeID string `json:"knowledge_id"`
Status string `json:"status"`
Progress int `json:"progress"`
Total int `json:"total"`
Processed int `json:"processed"`
SuccessCount int `json:"success_count"`
FailedCount int `json:"failed_count"`
FailedEntries []FAQFailedEntry `json:"failed_entries,omitempty"`
FailedEntriesURL string `json:"failed_entries_url,omitempty"` // CSV download URL when too many failures
Message string `json:"message"`
Error string `json:"error,omitempty"`
CreatedAt int64 `json:"created_at"`
UpdatedAt int64 `json:"updated_at"`
DryRun bool `json:"dry_run,omitempty"` // Whether this is a dry run validation
}
// FAQImportProgressResponse wraps the FAQ import progress response.
@@ -368,6 +386,7 @@ type FAQImportProgressResponse struct {
}
// GetFAQImportProgress retrieves the progress of an async FAQ import task.
// This works for both regular imports and dry run validations.
func (c *Client) GetFAQImportProgress(ctx context.Context, taskID string) (*FAQImportProgress, error) {
path := fmt.Sprintf("/api/v1/faq/import/progress/%s", taskID)
resp, err := c.doRequest(ctx, http.MethodGet, path, nil, nil)
@@ -381,57 +400,3 @@ func (c *Client) GetFAQImportProgress(ctx context.Context, taskID string) (*FAQI
}
return response.Data, nil
}
// FAQDryRunFailedEntry represents a failed entry in dry run validation.
type FAQDryRunFailedEntry struct {
Index int `json:"index"`
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"`
}
// FAQDryRunProgress represents the progress of an async FAQ dry run validation task.
type FAQDryRunProgress struct {
TaskID string `json:"task_id"`
KBID string `json:"kb_id"`
Status string `json:"status"`
Progress int `json:"progress"`
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 download URL when too many failures
Message string `json:"message"`
Error string `json:"error,omitempty"`
CreatedAt int64 `json:"created_at"`
UpdatedAt int64 `json:"updated_at"`
}
// FAQDryRunProgressResponse wraps the FAQ dry run progress response.
type FAQDryRunProgressResponse struct {
Success bool `json:"success"`
Data *FAQDryRunProgress `json:"data"`
Message string `json:"message,omitempty"`
Code string `json:"code,omitempty"`
}
// GetFAQDryRunProgress retrieves the progress of an async FAQ dry run validation task.
func (c *Client) GetFAQDryRunProgress(ctx context.Context, taskID string) (*FAQDryRunProgress, error) {
path := fmt.Sprintf("/api/v1/faq/dryrun/progress/%s", taskID)
resp, err := c.doRequest(ctx, http.MethodGet, path, nil, nil)
if err != nil {
return nil, err
}
var response FAQDryRunProgressResponse
if err := parseResponse(resp, &response); err != nil {
return nil, err
}
return response.Data, nil
}