feat: Enhance Kol Generation Service with web search and knowledge group support

- Added `EnableWebSearch` and `KnowledgeGroupIDs` fields to `KolGenerationSubmitRequest`.
- Updated `Submit` method in `KolGenerationService` to handle new request fields.
- Integrated web search and knowledge group validation based on card configuration.
- Introduced caching mechanisms in `KolPackageService`, `KolPromptService`, and `KolSubscriptionAdminService` to improve performance.
- Implemented knowledge context resolution in `KolGenerationWorker` to enrich prompts with relevant knowledge snippets.
- Added utility functions for handling card configuration in both backend and frontend.
- Created tests for knowledge extraction and rendering to ensure accuracy and reliability.
This commit is contained in:
2026-04-18 13:47:32 +08:00
parent 3ef0807456
commit b2605abd6a
27 changed files with 2051 additions and 171 deletions
@@ -74,7 +74,7 @@ func (h *ArticleHandler) List(c *gin.Context) {
if v := c.Query("publish_status"); v != "" {
params.PublishStatus = &v
}
if v := c.Query("source_type"); v != "" {
if v := normalizeSourceTypeParam(c.Query("source_type")); v != "" {
params.SourceType = &v
}
if v := c.Query("generation_mode"); v != "" {
@@ -85,6 +85,11 @@ func (h *ArticleHandler) List(c *gin.Context) {
params.TemplateID = &id
}
}
if v := c.Query("kol_prompt_id"); v != "" {
if id, err := strconv.ParseInt(v, 10, 64); err == nil {
params.KolPromptID = &id
}
}
if v := c.Query("prompt_rule_id"); v != "" {
if id, err := strconv.ParseInt(v, 10, 64); err == nil {
params.PromptRuleID = &id
@@ -118,6 +123,29 @@ func (h *ArticleHandler) List(c *gin.Context) {
response.Success(c, data)
}
func normalizeSourceTypeParam(raw string) string {
if strings.TrimSpace(raw) == "" {
return ""
}
parts := strings.Split(raw, ",")
out := make([]string, 0, len(parts))
seen := make(map[string]struct{}, len(parts))
for _, part := range parts {
value := strings.TrimSpace(part)
if value == "" {
continue
}
if _, exists := seen[value]; exists {
continue
}
seen[value] = struct{}{}
out = append(out, value)
}
return strings.Join(out, ",")
}
func (h *ArticleHandler) GenerateFromRule(c *gin.Context) {
var req app.GenerateFromRuleRequest
if err := c.ShouldBindJSON(&req); err != nil {