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
@@ -7,6 +7,7 @@ import (
"time"
"github.com/geo-platform/tenant-api/internal/shared/auth"
sharedcache "github.com/geo-platform/tenant-api/internal/shared/cache"
"github.com/geo-platform/tenant-api/internal/shared/response"
"github.com/geo-platform/tenant-api/internal/tenant/repository"
)
@@ -44,6 +45,7 @@ type KolPackageService struct {
profileSvc *KolProfileService
repo repository.KolPackageRepository
promptRepo repository.KolPromptRepository
cache sharedcache.Cache
}
func NewKolPackageService(
@@ -58,6 +60,11 @@ func NewKolPackageService(
}
}
func (s *KolPackageService) WithCache(c sharedcache.Cache) *KolPackageService {
s.cache = c
return s
}
func (s *KolPackageService) List(ctx context.Context, actor auth.Actor) ([]KolPackageResponse, error) {
profile, err := s.profileSvc.RequireActiveKol(ctx, actor)
if err != nil {
@@ -119,6 +126,7 @@ func (s *KolPackageService) Create(ctx context.Context, actor auth.Actor, input
return nil, response.ErrInternal(50063, "kol_package_create_failed", err.Error())
}
InvalidateKolPromptCaches(ctx, s.cache)
return s.buildPackageResponse(ctx, profile, pkg)
}
@@ -158,6 +166,7 @@ func (s *KolPackageService) Update(ctx context.Context, actor auth.Actor, id int
return nil, errKolPackageNotFound
}
InvalidateKolPromptCaches(ctx, s.cache)
return s.buildPackageResponse(ctx, profile, updated)
}
@@ -179,6 +188,7 @@ func (s *KolPackageService) Publish(ctx context.Context, actor auth.Actor, id in
return nil, errKolPackageNotFound
}
InvalidateKolPromptCaches(ctx, s.cache)
return s.buildPackageResponse(ctx, profile, updated)
}
@@ -200,6 +210,7 @@ func (s *KolPackageService) Archive(ctx context.Context, actor auth.Actor, id in
return nil, errKolPackageNotFound
}
InvalidateKolPromptCaches(ctx, s.cache)
return s.buildPackageResponse(ctx, profile, updated)
}
@@ -212,6 +223,7 @@ func (s *KolPackageService) Delete(ctx context.Context, actor auth.Actor, id int
return response.ErrInternal(50067, "kol_package_delete_failed", err.Error())
}
InvalidateKolPromptCaches(ctx, s.cache)
return nil
}