feat: Implement FAQ functionality in Knowledge Base

- Added support for creating and managing FAQ knowledge bases, including new API endpoints for listing, upserting, updating, and deleting FAQ entries.
- Enhanced the frontend to allow users to create FAQ knowledge bases and manage FAQ entries with a dedicated interface.
- Introduced new types and configurations for FAQ handling in the backend, ensuring proper indexing and retrieval of FAQ entries.
- Updated localization files to include new strings related to FAQ management in multiple languages.
- Refactored existing components to accommodate the new FAQ features, improving user experience and functionality.
This commit is contained in:
wizardchen
2025-11-15 01:30:17 +08:00
parent 0ea5e6a2a2
commit 25fdaed8ca
37 changed files with 4778 additions and 198 deletions
+34
View File
@@ -49,6 +49,40 @@ func Deduplicate[T any, K comparable](keyFunc func(T) K, items ...T) []T {
return slices.Collect(maps.Values(seen))
}
// ScoreComparable is an interface for types that have a Score method returning float64
type ScoreComparable interface {
GetScore() float64
}
// DeduplicateWithScore removes duplicates from a slice based on a key function,
// keeping the item with the highest score for each key, then sorts by score descending
// T: the type of elements in the slice (must implement ScoreComparable)
// K: the type of key used for deduplication
func DeduplicateWithScore[T ScoreComparable, K comparable](keyFunc func(T) K, items ...T) []T {
seen := make(map[K]T)
for _, item := range items {
key := keyFunc(item)
if existing, exists := seen[key]; !exists {
seen[key] = item
} else if item.GetScore() > existing.GetScore() {
seen[key] = item
}
}
result := slices.Collect(maps.Values(seen))
// Sort by score descending
slices.SortFunc(result, func(a, b T) int {
scoreA := a.GetScore()
scoreB := b.GetScore()
if scoreA > scoreB {
return -1
} else if scoreA < scoreB {
return 1
}
return 0
})
return result
}
// ParseLLMJsonResponse parses a JSON response from LLM, handling cases where JSON is wrapped in code blocks.
// This is useful when LLMs return responses like:
// ```json