fix(models): protect auto-tag model references
parent
350b2ab364
commit
fc2c12e8ec
|
|
@ -458,7 +458,7 @@ curl --location --request DELETE 'http://localhost:8080/api/v1/models/8fdc464d-8
|
|||
}
|
||||
```
|
||||
|
||||
`bindings` 是稳定的配置类型标识:知识库可能返回 `embedding_model`、`summary_model`、`image_processing_model`、`vlm_model`、`asr_model`、`wiki_synthesis_model`;智能体可能返回 `chat_model`、`rerank_model`、`vlm_model`、`asr_model`、`query_understand_model`、`follow_up_model`;长期记忆可能返回 `embedding_model`、`extract_model`。同一对象的多处引用会合并到一个 `bindings` 数组。`knowledge_bases` / `agents` 最多各返回 50 条;未截断的引用数在 `knowledge_base_total` / `agent_total`。404 表示模型不存在。
|
||||
`bindings` 是稳定的配置类型标识:知识库可能返回 `embedding_model`、`summary_model`、`image_processing_model`、`vlm_model`、`asr_model`、`wiki_synthesis_model`、`auto_tag_model`;智能体可能返回 `chat_model`、`rerank_model`、`vlm_model`、`asr_model`、`query_understand_model`、`follow_up_model`;长期记忆可能返回 `embedding_model`、`extract_model`。同一对象的多处引用会合并到一个 `bindings` 数组。`knowledge_bases` / `agents` 最多各返回 50 条;未截断的引用数在 `knowledge_base_total` / `agent_total`。404 表示模型不存在。
|
||||
|
||||
## 参数说明
|
||||
|
||||
|
|
|
|||
|
|
@ -118,6 +118,7 @@ test('maps knowledge-base bindings to the configuration section that owns them',
|
|||
assert.equal(modelUsageKnowledgeBaseSection(['embedding_model']), 'models')
|
||||
assert.equal(modelUsageKnowledgeBaseSection(['summary_model']), 'models')
|
||||
assert.equal(modelUsageKnowledgeBaseSection(['wiki_synthesis_model']), 'models')
|
||||
assert.equal(modelUsageKnowledgeBaseSection(['auto_tag_model']), 'models')
|
||||
assert.equal(modelUsageKnowledgeBaseSection(['image_processing_model']), 'multimodal')
|
||||
assert.equal(modelUsageKnowledgeBaseSection(['vlm_model']), 'multimodal')
|
||||
assert.equal(modelUsageKnowledgeBaseSection(['asr_model']), 'asr')
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ export const KNOWN_MODEL_USAGE_BINDINGS = [
|
|||
'vlm_model',
|
||||
'asr_model',
|
||||
'wiki_synthesis_model',
|
||||
'auto_tag_model',
|
||||
'chat_model',
|
||||
'rerank_model',
|
||||
'query_understand_model',
|
||||
|
|
@ -133,6 +134,7 @@ const knowledgeBaseUsageSections: Partial<Record<KnownModelUsageBinding, Knowled
|
|||
embedding_model: 'models',
|
||||
summary_model: 'models',
|
||||
wiki_synthesis_model: 'models',
|
||||
auto_tag_model: 'models',
|
||||
image_processing_model: 'multimodal',
|
||||
vlm_model: 'multimodal',
|
||||
asr_model: 'asr',
|
||||
|
|
|
|||
|
|
@ -4977,6 +4977,7 @@ export default {
|
|||
vlm_model: 'Vision model',
|
||||
asr_model: 'Speech recognition model',
|
||||
wiki_synthesis_model: 'Wiki synthesis model',
|
||||
auto_tag_model: 'Auto-tagging model',
|
||||
chat_model: 'Chat model',
|
||||
rerank_model: 'Re-ranking model',
|
||||
query_understand_model: 'Query understanding model',
|
||||
|
|
|
|||
|
|
@ -4977,6 +4977,7 @@ export default {
|
|||
vlm_model: '視覚モデル',
|
||||
asr_model: '音声認識モデル',
|
||||
wiki_synthesis_model: 'Wiki生成モデル',
|
||||
auto_tag_model: '自動タグ付けモデル',
|
||||
chat_model: 'チャットモデル',
|
||||
rerank_model: 'リランクモデル',
|
||||
query_understand_model: 'クエリ理解モデル',
|
||||
|
|
|
|||
|
|
@ -2207,6 +2207,7 @@ export default {
|
|||
vlm_model: '비전 모델',
|
||||
asr_model: '음성 인식 모델',
|
||||
wiki_synthesis_model: 'Wiki 종합 모델',
|
||||
auto_tag_model: '자동 태그 모델',
|
||||
chat_model: '대화 모델',
|
||||
rerank_model: '재정렬 모델',
|
||||
query_understand_model: '질의 이해 모델',
|
||||
|
|
|
|||
|
|
@ -2207,6 +2207,7 @@ export default {
|
|||
vlm_model: 'Модель компьютерного зрения',
|
||||
asr_model: 'Модель распознавания речи',
|
||||
wiki_synthesis_model: 'Модель синтеза Wiki',
|
||||
auto_tag_model: 'Модель автоматической разметки',
|
||||
chat_model: 'Диалоговая модель',
|
||||
rerank_model: 'Модель реранжирования',
|
||||
query_understand_model: 'Модель понимания запроса',
|
||||
|
|
|
|||
|
|
@ -2209,6 +2209,7 @@ export default {
|
|||
vlm_model: '视觉理解模型',
|
||||
asr_model: '语音识别模型',
|
||||
wiki_synthesis_model: 'Wiki 综合模型',
|
||||
auto_tag_model: '自动标签模型',
|
||||
chat_model: '对话模型',
|
||||
rerank_model: '重排序模型',
|
||||
query_understand_model: '问题理解模型',
|
||||
|
|
|
|||
|
|
@ -229,7 +229,7 @@ func (r *knowledgeBaseRepository) ListModelUsages(
|
|||
Model(&types.KnowledgeBase{}).
|
||||
Select(
|
||||
"id", "name", "embedding_model_id", "summary_model_id",
|
||||
"image_processing_config", "vlm_config", "asr_config", "wiki_config",
|
||||
"image_processing_config", "vlm_config", "asr_config", "wiki_config", "auto_tag_config",
|
||||
).
|
||||
Where("tenant_id = ?", tenantID)
|
||||
query = scopeKnowledgeBasesByModelID(query, modelID)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import (
|
|||
)
|
||||
|
||||
func knowledgeBaseModelUsageBindings(kb *types.KnowledgeBase, modelID string) []types.ModelUsageBinding {
|
||||
bindings := make([]types.ModelUsageBinding, 0, 6)
|
||||
bindings := make([]types.ModelUsageBinding, 0, 7)
|
||||
if kb.EmbeddingModelID == modelID {
|
||||
bindings = append(bindings, types.ModelUsageBindingEmbeddingModel)
|
||||
}
|
||||
|
|
@ -25,6 +25,9 @@ func knowledgeBaseModelUsageBindings(kb *types.KnowledgeBase, modelID string) []
|
|||
if kb.WikiConfig != nil && kb.WikiConfig.SynthesisModelID == modelID {
|
||||
bindings = append(bindings, types.ModelUsageBindingWikiSynthesisModel)
|
||||
}
|
||||
if kb.AutoTagConfig != nil && kb.AutoTagConfig.ModelID == modelID {
|
||||
bindings = append(bindings, types.ModelUsageBindingAutoTagModel)
|
||||
}
|
||||
return bindings
|
||||
}
|
||||
|
||||
|
|
@ -61,8 +64,9 @@ func scopeKnowledgeBasesByModelID(db *gorm.DB, modelID string) *gorm.DB {
|
|||
"image_processing_config->>'model_id' = ? OR "+
|
||||
"vlm_config->>'model_id' = ? OR "+
|
||||
"asr_config->>'model_id' = ? OR "+
|
||||
"wiki_config->>'synthesis_model_id' = ?",
|
||||
modelID, modelID, modelID, modelID, modelID, modelID,
|
||||
"wiki_config->>'synthesis_model_id' = ? OR "+
|
||||
"auto_tag_config->>'model_id' = ?",
|
||||
modelID, modelID, modelID, modelID, modelID, modelID, modelID,
|
||||
)
|
||||
}
|
||||
return db.Where(
|
||||
|
|
@ -70,8 +74,9 @@ func scopeKnowledgeBasesByModelID(db *gorm.DB, modelID string) *gorm.DB {
|
|||
"json_extract(image_processing_config, '$.model_id') = ? OR "+
|
||||
"json_extract(vlm_config, '$.model_id') = ? OR "+
|
||||
"json_extract(asr_config, '$.model_id') = ? OR "+
|
||||
"json_extract(wiki_config, '$.synthesis_model_id') = ?",
|
||||
modelID, modelID, modelID, modelID, modelID, modelID,
|
||||
"json_extract(wiki_config, '$.synthesis_model_id') = ? OR "+
|
||||
"json_extract(auto_tag_config, '$.model_id') = ?",
|
||||
modelID, modelID, modelID, modelID, modelID, modelID, modelID,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -83,6 +83,7 @@ func TestListModelUsages_KnowledgeBase(t *testing.T) {
|
|||
allBindings.VLMConfig = types.VLMConfig{Enabled: true, ModelID: modelID}
|
||||
allBindings.ASRConfig = types.ASRConfig{Enabled: true, ModelID: modelID}
|
||||
allBindings.WikiConfig = &types.WikiConfig{SynthesisModelID: modelID}
|
||||
allBindings.AutoTagConfig = &types.AutoTagConfig{Enabled: true, ModelID: modelID}
|
||||
require.NoError(t, db.Create(allBindings).Error)
|
||||
|
||||
vlmOnly := makeKB(nil)
|
||||
|
|
@ -115,9 +116,25 @@ func TestListModelUsages_KnowledgeBase(t *testing.T) {
|
|||
types.ModelUsageBindingVLMModel,
|
||||
types.ModelUsageBindingASRModel,
|
||||
types.ModelUsageBindingWikiSynthesisModel,
|
||||
types.ModelUsageBindingAutoTagModel,
|
||||
}, usages[1].Bindings)
|
||||
}
|
||||
|
||||
func TestCountByModelID_KnowledgeBaseAutoTag(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db := setupModelUsageTestDB(t)
|
||||
repo := NewKnowledgeBaseRepository(db)
|
||||
modelID := "auto-tag-model"
|
||||
|
||||
kb := makeKB(nil)
|
||||
kb.AutoTagConfig = &types.AutoTagConfig{Enabled: true, ModelID: modelID}
|
||||
require.NoError(t, db.Create(kb).Error)
|
||||
|
||||
count, err := repo.CountByModelID(ctx, 1, modelID)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, int64(1), count)
|
||||
}
|
||||
|
||||
func TestListModelUsages_KnowledgeBaseRespectsLimit(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db := setupModelUsageTestDB(t)
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ const (
|
|||
ModelUsageBindingVLMModel ModelUsageBinding = "vlm_model"
|
||||
ModelUsageBindingASRModel ModelUsageBinding = "asr_model"
|
||||
ModelUsageBindingWikiSynthesisModel ModelUsageBinding = "wiki_synthesis_model"
|
||||
ModelUsageBindingAutoTagModel ModelUsageBinding = "auto_tag_model"
|
||||
ModelUsageBindingChatModel ModelUsageBinding = "chat_model"
|
||||
ModelUsageBindingRerankModel ModelUsageBinding = "rerank_model"
|
||||
ModelUsageBindingQueryUnderstandModel ModelUsageBinding = "query_understand_model"
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ curl -X PUT $BASE/api/v1/models/m-1 -H "Authorization: Bearer $TOKEN" \
|
|||
}
|
||||
```
|
||||
|
||||
知识库绑定值:`embedding_model`、`summary_model`、`image_processing_model`、`vlm_model`、`asr_model`、`wiki_synthesis_model`;智能体绑定值:`chat_model`、`rerank_model`、`vlm_model`、`asr_model`、`query_understand_model`、`follow_up_model`;长期记忆绑定值:`embedding_model`、`extract_model`。详情包含对象 `id`、`name`、合并后的 `bindings`,以及 `knowledge_base_total` / `agent_total`。列表最多各 50 条,删除守卫以总数为准。
|
||||
知识库绑定值:`embedding_model`、`summary_model`、`image_processing_model`、`vlm_model`、`asr_model`、`wiki_synthesis_model`、`auto_tag_model`;智能体绑定值:`chat_model`、`rerank_model`、`vlm_model`、`asr_model`、`query_understand_model`、`follow_up_model`;长期记忆绑定值:`embedding_model`、`extract_model`。详情包含对象 `id`、`name`、合并后的 `bindings`,以及 `knowledge_base_total` / `agent_total`。列表最多各 50 条,删除守卫以总数为准。
|
||||
|
||||
```bash
|
||||
curl -X DELETE $BASE/api/v1/models/m-1 -H "Authorization: Bearer $TOKEN"
|
||||
|
|
|
|||
Loading…
Reference in New Issue