feat: 增强VLM配置兼容性,支持新旧版本配置判断逻辑
This commit is contained in:
@@ -279,7 +279,7 @@ func (s *knowledgeService) CreateKnowledgeFromFile(ctx context.Context,
|
||||
if enableMultimodel != nil {
|
||||
enableMultimodelValue = *enableMultimodel
|
||||
} else {
|
||||
enableMultimodelValue = kb.VLMConfig.Enabled
|
||||
enableMultimodelValue = kb.VLMConfig.IsEnabled()
|
||||
}
|
||||
|
||||
// Check question generation config
|
||||
@@ -413,7 +413,7 @@ func (s *knowledgeService) CreateKnowledgeFromURL(ctx context.Context,
|
||||
if enableMultimodel != nil {
|
||||
enableMultimodelValue = *enableMultimodel
|
||||
} else {
|
||||
enableMultimodelValue = kb.VLMConfig.Enabled
|
||||
enableMultimodelValue = kb.VLMConfig.IsEnabled()
|
||||
}
|
||||
|
||||
// Check question generation config
|
||||
@@ -4155,7 +4155,7 @@ func (s *knowledgeService) triggerManualProcessing(ctx context.Context,
|
||||
fileType := "md"
|
||||
|
||||
// 检查是否需要启用多模态(对于手动内容通常不需要,但保持一致性)
|
||||
enableMultimodel := kb.VLMConfig.Enabled && kb.StorageConfig.Provider != ""
|
||||
enableMultimodel := kb.VLMConfig.IsEnabled() && kb.StorageConfig.Provider != ""
|
||||
|
||||
var vlmConfig *proto.VLMConfig
|
||||
if enableMultimodel {
|
||||
@@ -4285,7 +4285,21 @@ func (s *knowledgeService) cleanupKnowledgeResources(ctx context.Context, knowle
|
||||
}
|
||||
|
||||
func (s *knowledgeService) getVLMProtoConfig(ctx context.Context, kb *types.KnowledgeBase) (*proto.VLMConfig, error) {
|
||||
if kb == nil || !kb.VLMConfig.Enabled || kb.VLMConfig.ModelID == "" {
|
||||
if kb == nil {
|
||||
return nil, nil
|
||||
}
|
||||
// 兼容老版本:直接使用 ModelName 和 BaseURL
|
||||
if kb.VLMConfig.ModelName != "" && kb.VLMConfig.BaseURL != "" {
|
||||
return &proto.VLMConfig{
|
||||
ModelName: kb.VLMConfig.ModelName,
|
||||
BaseUrl: kb.VLMConfig.BaseURL,
|
||||
ApiKey: kb.VLMConfig.APIKey,
|
||||
InterfaceType: kb.VLMConfig.InterfaceType,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// 新版本:未启用或无模型ID时返回nil
|
||||
if !kb.VLMConfig.Enabled || kb.VLMConfig.ModelID == "" {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -1251,7 +1251,7 @@ func (h *InitializationHandler) buildConfigResponse(ctx context.Context, models
|
||||
}
|
||||
|
||||
// 判断多模态是否启用:有VLM模型ID或有存储配置
|
||||
hasMultimodal := ((kb.VLMConfig.Enabled && kb.VLMConfig.ModelID != "") ||
|
||||
hasMultimodal := (kb.VLMConfig.IsEnabled() ||
|
||||
kb.StorageConfig.SecretID != "" || kb.StorageConfig.BucketName != "")
|
||||
if config["multimodal"] == nil {
|
||||
config["multimodal"] = map[string]interface{}{
|
||||
|
||||
@@ -180,6 +180,31 @@ func (c *ImageProcessingConfig) Scan(value interface{}) error {
|
||||
type VLMConfig struct {
|
||||
Enabled bool `yaml:"enabled" json:"enabled"`
|
||||
ModelID string `yaml:"model_id" json:"model_id"`
|
||||
|
||||
// 兼容老版本
|
||||
// Model Name
|
||||
ModelName string `yaml:"model_name" json:"model_name"`
|
||||
// Base URL
|
||||
BaseURL string `yaml:"base_url" json:"base_url"`
|
||||
// API Key
|
||||
APIKey string `yaml:"api_key" json:"api_key"`
|
||||
// Interface Type: "ollama" or "openai"
|
||||
InterfaceType string `yaml:"interface_type" json:"interface_type"`
|
||||
}
|
||||
|
||||
// IsEnabled 判断多模态是否启用(兼容新老版本)
|
||||
// 新版本:Enabled && ModelID != ""
|
||||
// 老版本:ModelName != "" && BaseURL != ""
|
||||
func (c VLMConfig) IsEnabled() bool {
|
||||
// 新版本配置
|
||||
if c.Enabled && c.ModelID != "" {
|
||||
return true
|
||||
}
|
||||
// 兼容老版本配置
|
||||
if c.ModelName != "" && c.BaseURL != "" {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// QuestionGenerationConfig represents the question generation configuration for document knowledge bases
|
||||
|
||||
Reference in New Issue
Block a user