Add instruction fields to knowledge base configuration
This commit is contained in:
@@ -111,9 +111,10 @@ type KBModelConfigRequest struct {
|
||||
// from "field present with empty/zero value" (clear / disable).
|
||||
// Without that distinction, users could set strategy="auto" once
|
||||
// but never reset it back to legacy / unset.
|
||||
Strategy *string `json:"strategy,omitempty"`
|
||||
TokenLimit *int `json:"tokenLimit,omitempty"`
|
||||
Languages *[]string `json:"languages,omitempty"`
|
||||
Strategy *string `json:"strategy,omitempty"`
|
||||
TokenLimit *int `json:"tokenLimit,omitempty"`
|
||||
Languages *[]string `json:"languages,omitempty"`
|
||||
TableMetadataInstructions *string `json:"tableMetadataInstructions,omitempty"`
|
||||
} `json:"documentSplitting"`
|
||||
|
||||
// 多模态配置(仅模型相关;存储引擎在 storageProvider 中配置)
|
||||
@@ -126,17 +127,19 @@ type KBModelConfigRequest struct {
|
||||
|
||||
// 知识图谱配置
|
||||
NodeExtract struct {
|
||||
Enabled bool `json:"enabled"`
|
||||
Text string `json:"text"`
|
||||
Tags []string `json:"tags"`
|
||||
Nodes []types.GraphNode `json:"nodes"`
|
||||
Relations []types.GraphRelation `json:"relations"`
|
||||
Enabled bool `json:"enabled"`
|
||||
Text string `json:"text"`
|
||||
Tags []string `json:"tags"`
|
||||
Nodes []types.GraphNode `json:"nodes"`
|
||||
Relations []types.GraphRelation `json:"relations"`
|
||||
CustomInstructions string `json:"customInstructions"`
|
||||
} `json:"nodeExtract"`
|
||||
|
||||
// 问题生成配置
|
||||
QuestionGeneration struct {
|
||||
Enabled bool `json:"enabled"`
|
||||
QuestionCount int `json:"questionCount"`
|
||||
Enabled bool `json:"enabled"`
|
||||
QuestionCount int `json:"questionCount"`
|
||||
CustomInstructions string `json:"customInstructions"`
|
||||
} `json:"questionGeneration"`
|
||||
}
|
||||
|
||||
@@ -344,6 +347,9 @@ func (h *InitializationHandler) UpdateKBConfig(c *gin.Context) {
|
||||
if req.DocumentSplitting.Languages != nil {
|
||||
kb.ChunkingConfig.Languages = *req.DocumentSplitting.Languages
|
||||
}
|
||||
if req.DocumentSplitting.TableMetadataInstructions != nil {
|
||||
kb.ChunkingConfig.TableMetadataInstructions = strings.TrimSpace(*req.DocumentSplitting.TableMetadataInstructions)
|
||||
}
|
||||
|
||||
// 更新多模态配置
|
||||
if req.Multimodal.Enabled {
|
||||
@@ -351,6 +357,10 @@ func (h *InitializationHandler) UpdateKBConfig(c *gin.Context) {
|
||||
} else {
|
||||
kb.VLMConfig.ModelID = ""
|
||||
}
|
||||
if req.VLMConfig != nil {
|
||||
kb.VLMConfig.DescriptionLanguage = strings.TrimSpace(req.VLMConfig.DescriptionLanguage)
|
||||
kb.VLMConfig.CustomInstructions = strings.TrimSpace(req.VLMConfig.CustomInstructions)
|
||||
}
|
||||
|
||||
// 存储引擎:仅写入 provider 到新字段,参数从租户全局 StorageEngineConfig 读取
|
||||
provider := strings.ToLower(strings.TrimSpace(req.StorageProvider))
|
||||
@@ -387,11 +397,12 @@ func (h *InitializationHandler) UpdateKBConfig(c *gin.Context) {
|
||||
}
|
||||
|
||||
kb.ExtractConfig = &types.ExtractConfig{
|
||||
Enabled: req.NodeExtract.Enabled,
|
||||
Text: req.NodeExtract.Text,
|
||||
Tags: req.NodeExtract.Tags,
|
||||
Nodes: nodes,
|
||||
Relations: relations,
|
||||
Enabled: req.NodeExtract.Enabled,
|
||||
Text: req.NodeExtract.Text,
|
||||
Tags: req.NodeExtract.Tags,
|
||||
Nodes: nodes,
|
||||
Relations: relations,
|
||||
CustomInstructions: strings.TrimSpace(req.NodeExtract.CustomInstructions),
|
||||
}
|
||||
} else {
|
||||
kb.ExtractConfig = &types.ExtractConfig{Enabled: false}
|
||||
@@ -412,11 +423,19 @@ func (h *InitializationHandler) UpdateKBConfig(c *gin.Context) {
|
||||
questionCount = 10
|
||||
}
|
||||
kb.QuestionGenerationConfig = &types.QuestionGenerationConfig{
|
||||
Enabled: true,
|
||||
QuestionCount: questionCount,
|
||||
Enabled: true,
|
||||
QuestionCount: questionCount,
|
||||
CustomInstructions: strings.TrimSpace(req.QuestionGeneration.CustomInstructions),
|
||||
}
|
||||
} else {
|
||||
kb.QuestionGenerationConfig = &types.QuestionGenerationConfig{Enabled: false}
|
||||
kb.QuestionGenerationConfig = &types.QuestionGenerationConfig{
|
||||
Enabled: false,
|
||||
CustomInstructions: strings.TrimSpace(req.QuestionGeneration.CustomInstructions),
|
||||
}
|
||||
}
|
||||
if err := validateKnowledgeBasePromptInstructions(kb); err != nil {
|
||||
c.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
// 保存更新后的知识库
|
||||
|
||||
Reference in New Issue
Block a user