refactor: 重构多模态配置检查逻辑,统一使用IsMultimodalEnabled方法并优化错误处理
This commit is contained in:
@@ -279,7 +279,7 @@ func (s *knowledgeService) CreateKnowledgeFromFile(ctx context.Context,
|
|||||||
if enableMultimodel != nil {
|
if enableMultimodel != nil {
|
||||||
enableMultimodelValue = *enableMultimodel
|
enableMultimodelValue = *enableMultimodel
|
||||||
} else {
|
} else {
|
||||||
enableMultimodelValue = kb.VLMConfig.IsEnabled()
|
enableMultimodelValue = kb.IsMultimodalEnabled()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check question generation config
|
// Check question generation config
|
||||||
@@ -413,7 +413,7 @@ func (s *knowledgeService) CreateKnowledgeFromURL(ctx context.Context,
|
|||||||
if enableMultimodel != nil {
|
if enableMultimodel != nil {
|
||||||
enableMultimodelValue = *enableMultimodel
|
enableMultimodelValue = *enableMultimodel
|
||||||
} else {
|
} else {
|
||||||
enableMultimodelValue = kb.VLMConfig.IsEnabled()
|
enableMultimodelValue = kb.IsMultimodalEnabled()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check question generation config
|
// Check question generation config
|
||||||
@@ -4155,7 +4155,7 @@ func (s *knowledgeService) triggerManualProcessing(ctx context.Context,
|
|||||||
fileType := "md"
|
fileType := "md"
|
||||||
|
|
||||||
// 检查是否需要启用多模态(对于手动内容通常不需要,但保持一致性)
|
// 检查是否需要启用多模态(对于手动内容通常不需要,但保持一致性)
|
||||||
enableMultimodel := kb.VLMConfig.IsEnabled() && kb.StorageConfig.Provider != ""
|
enableMultimodel := kb.IsMultimodalEnabled() && kb.StorageConfig.Provider != ""
|
||||||
|
|
||||||
var vlmConfig *proto.VLMConfig
|
var vlmConfig *proto.VLMConfig
|
||||||
if enableMultimodel {
|
if enableMultimodel {
|
||||||
@@ -4411,20 +4411,10 @@ func (s *knowledgeService) ProcessDocument(ctx context.Context, t *asynq.Task) e
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
logger.GetLogger(ctx).WithField("knowledge_id", knowledge.ID).
|
logger.GetLogger(ctx).WithField("knowledge_id", knowledge.ID).
|
||||||
WithField("error", err).Errorf("processDocument build VLM config failed")
|
WithField("error", err).Errorf("processDocument build VLM config failed")
|
||||||
knowledge.ParseStatus = "failed"
|
|
||||||
knowledge.ErrorMessage = err.Error()
|
|
||||||
knowledge.UpdatedAt = time.Now()
|
|
||||||
s.repo.UpdateKnowledge(ctx, knowledge)
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
if vlmConfig == nil {
|
if vlmConfig == nil {
|
||||||
logger.GetLogger(ctx).WithField("knowledge_id", knowledge.ID).
|
logger.GetLogger(ctx).WithField("knowledge_id", knowledge.ID).
|
||||||
Error("processDocument enable multimodal but VLM config missing")
|
Warn("processDocument enable multimodal but VLM config missing")
|
||||||
knowledge.ParseStatus = "failed"
|
|
||||||
knowledge.ErrorMessage = "VLM 配置缺失"
|
|
||||||
knowledge.UpdatedAt = time.Now()
|
|
||||||
s.repo.UpdateKnowledge(ctx, knowledge)
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -101,6 +101,8 @@ type ChunkingConfig struct {
|
|||||||
ChunkOverlap int `yaml:"chunk_overlap" json:"chunk_overlap"`
|
ChunkOverlap int `yaml:"chunk_overlap" json:"chunk_overlap"`
|
||||||
// Separators
|
// Separators
|
||||||
Separators []string `yaml:"separators" json:"separators"`
|
Separators []string `yaml:"separators" json:"separators"`
|
||||||
|
// EnableMultimodal (deprecated, kept for backward compatibility with old data)
|
||||||
|
EnableMultimodal bool `yaml:"enable_multimodal,omitempty" json:"enable_multimodal,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// COSConfig represents the COS configuration
|
// COSConfig represents the COS configuration
|
||||||
@@ -325,3 +327,21 @@ func (kb *KnowledgeBase) EnsureDefaults() {
|
|||||||
kb.FAQConfig.QuestionIndexMode = FAQQuestionIndexModeCombined
|
kb.FAQConfig.QuestionIndexMode = FAQQuestionIndexModeCombined
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsMultimodalEnabled 判断多模态是否启用(兼容新老版本配置)
|
||||||
|
// 新版本:VLMConfig.IsEnabled()
|
||||||
|
// 老版本:ChunkingConfig.EnableMultimodal
|
||||||
|
func (kb *KnowledgeBase) IsMultimodalEnabled() bool {
|
||||||
|
if kb == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
// 新版本配置优先
|
||||||
|
if kb.VLMConfig.IsEnabled() {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
// 兼容老版本:chunking_config 中的 enable_multimodal 字段
|
||||||
|
if kb.ChunkingConfig.EnableMultimodal {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user