feat(go-api): support setting tenant default models by model_id (#16030)

### Description
Currently, when setting tenant default models (e.g., chat, embedding,
rerank), the API only accepts the composite name
(`model_name@model_instance@model_provider`). However, some integrations
and front-end features prefer using the database `model_id` (UUID)
directly.

This PR adds support for `model_id` in default model configuration:
1. **Request Binding**: Added `model_id` (optional field) to the request
body schema in the handler.
2. **Database Lookup**: If `model_id` is supplied, the service queries
the database to resolve the respective provider, instance, and model
names.
3. **Security Validation**: Verified that the provider associated with
the resolved `model_id` belongs to the requesting tenant.
4. **Unit Tests**: Added `TestSetTenantDefaultModels_WithModelID` to
verify DB ID resolution and tenant mapping.
This commit is contained in:
Hz_
2026-06-16 12:53:03 +08:00
committed by GitHub
parent 5a817762fa
commit 3d7b45bbd7
3 changed files with 174 additions and 5 deletions

View File

@@ -83,6 +83,7 @@ type SetModelRequest struct {
ModelProvider string `json:"model_provider"`
ModelInstance string `json:"model_instance"`
ModelName string `json:"model_name"`
ModelID string `json:"model_id"`
ModelType string `json:"model_type" binding:"required"`
}
@@ -112,7 +113,7 @@ func (h *TenantHandler) setDefaultModels(c *gin.Context, wrapModels bool) {
return
}
err := h.tenantService.SetTenantDefaultModels(user.ID, req.ModelProvider, req.ModelInstance, req.ModelName, req.ModelType)
err := h.tenantService.SetTenantDefaultModels(user.ID, req.ModelProvider, req.ModelInstance, req.ModelName, req.ModelType, req.ModelID)
if err != nil {
c.JSON(http.StatusOK, gin.H{
"code": common.CodeExceptionError,
@@ -462,9 +463,9 @@ func (h *TenantHandler) InsertChunksFromFile(c *gin.Context) {
// Parse JSON - format: {"index_name"/"table_name": ..., "knowledgebase_id": ..., "chunks": [...]}
var debugFormat struct {
IndexName string `json:"index_name"`
TableName string `json:"table_name"`
KnowledgebaseID string `json:"knowledgebase_id"`
IndexName string `json:"index_name"`
TableName string `json:"table_name"`
KnowledgebaseID string `json:"knowledgebase_id"`
Chunks []map[string]interface{} `json:"chunks"`
}