Add instruction fields to knowledge base configuration
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
stderrors "errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -361,6 +362,10 @@ func (h *KnowledgeBaseHandler) CreateKnowledgeBase(c *gin.Context) {
|
||||
c.Error(err)
|
||||
return
|
||||
}
|
||||
if err := validateKnowledgeBasePromptInstructions(&req); err != nil {
|
||||
c.Error(err)
|
||||
return
|
||||
}
|
||||
provider := strings.ToLower(strings.TrimSpace(req.GetStorageProvider()))
|
||||
if provider != "" && !isStorageProviderAllowed(provider) {
|
||||
c.Error(apperrors.NewBadRequestError("Storage provider is not allowed by STORAGE_ALLOW_LIST"))
|
||||
@@ -853,6 +858,17 @@ func (h *KnowledgeBaseHandler) UpdateKnowledgeBase(c *gin.Context) {
|
||||
c.Error(apperrors.NewBadRequestError("Invalid request parameters").WithDetails(err.Error()))
|
||||
return
|
||||
}
|
||||
if req.Config != nil {
|
||||
probe := &types.KnowledgeBase{
|
||||
ChunkingConfig: req.Config.ChunkingConfig,
|
||||
ImageProcessingConfig: req.Config.ImageProcessingConfig,
|
||||
WikiConfig: req.Config.WikiConfig,
|
||||
}
|
||||
if err := validateKnowledgeBasePromptInstructions(probe); err != nil {
|
||||
c.Error(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
logger.Infof(ctx, "Updating knowledge base, ID: %s, name: %s",
|
||||
secutils.SanitizeForLog(id), secutils.SanitizeForLog(req.Name))
|
||||
@@ -1293,6 +1309,32 @@ func validateExtractConfig(config *types.ExtractConfig) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateKnowledgeBasePromptInstructions(kb *types.KnowledgeBase) error {
|
||||
if kb == nil {
|
||||
return nil
|
||||
}
|
||||
fields := map[string]string{
|
||||
"table metadata instructions": kb.ChunkingConfig.TableMetadataInstructions,
|
||||
"image instructions": kb.VLMConfig.CustomInstructions,
|
||||
}
|
||||
if kb.WikiConfig != nil {
|
||||
fields["wiki content instructions"] = kb.WikiConfig.ContentInstructions
|
||||
fields["wiki extraction instructions"] = kb.WikiConfig.ExtractionInstructions
|
||||
}
|
||||
if kb.QuestionGenerationConfig != nil {
|
||||
fields["question generation instructions"] = kb.QuestionGenerationConfig.CustomInstructions
|
||||
}
|
||||
if kb.ExtractConfig != nil {
|
||||
fields["graph extraction instructions"] = kb.ExtractConfig.CustomInstructions
|
||||
}
|
||||
for name, value := range fields {
|
||||
if len([]rune(value)) > types.MaxCustomPromptInstructionsLength {
|
||||
return apperrors.NewBadRequestError(fmt.Sprintf("%s exceeds %d characters", name, types.MaxCustomPromptInstructionsLength))
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ListMoveTargets returns knowledge bases eligible as move targets for the given source KB.
|
||||
// Filters: same Type, same EmbeddingModelID, different ID, not temporary.
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user