fix: add model display name

This commit is contained in:
wolfkill
2026-05-28 18:36:38 +08:00
committed by lyingbug
parent 4e58dd42cc
commit 43565c5d1b
21 changed files with 187 additions and 46 deletions
+15 -13
View File
@@ -15,18 +15,19 @@ import (
// stripped along with every other field that could leak how a particular
// tenant configured the upstream provider.
type ModelResponse struct {
ID string `json:"id"`
TenantID uint64 `json:"tenant_id"`
Name string `json:"name"`
Type types.ModelType `json:"type"`
Source types.ModelSource `json:"source"`
Description string `json:"description"`
Parameters ModelParametersDTO `json:"parameters"`
IsDefault bool `json:"is_default"`
IsBuiltin bool `json:"is_builtin"`
Status types.ModelStatus `json:"status"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
ID string `json:"id"`
TenantID uint64 `json:"tenant_id"`
Name string `json:"name"`
DisplayName string `json:"display_name"`
Type types.ModelType `json:"type"`
Source types.ModelSource `json:"source"`
Description string `json:"description"`
Parameters ModelParametersDTO `json:"parameters"`
IsDefault bool `json:"is_default"`
IsBuiltin bool `json:"is_builtin"`
Status types.ModelStatus `json:"status"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
// Per-field "configured?" map. Omitted for builtin models (no
// per-tenant credentials). See MCPServiceResponse.Credentials.
Credentials map[string]CredentialFieldMetadata `json:"credentials,omitempty"`
@@ -44,7 +45,7 @@ type ModelParametersDTO struct {
Provider string `json:"provider"`
ExtraConfig map[string]string `json:"extra_config,omitempty"`
CustomHeaders map[string]string `json:"custom_headers,omitempty"`
SupportsVision bool `json:"supports_vision"`
SupportsVision bool `json:"supports_vision"`
AppID string `json:"app_id,omitempty"`
}
@@ -88,6 +89,7 @@ func NewModelResponse(m *types.Model) *ModelResponse {
ID: m.ID,
TenantID: m.TenantID,
Name: m.Name,
DisplayName: m.DisplayName,
Type: m.Type,
Source: m.Source,
Description: m.Description,
+4 -2
View File
@@ -11,8 +11,9 @@ import (
func TestModelResponse_OmitsSecrets(t *testing.T) {
m := &types.Model{
ID: "m-1",
Name: "gpt-x",
ID: "m-1",
Name: "gpt-x",
DisplayName: "Support QA",
Parameters: types.ModelParameters{
APIKey: "sk-real-api-key-do-not-leak",
AppSecret: "app-real-secret-do-not-leak",
@@ -39,6 +40,7 @@ func TestModelResponse_OmitsSecrets(t *testing.T) {
// Non-secret fields pass through.
assert.Contains(t, s, "appid-public-ok-to-show")
assert.Contains(t, s, "api.example.com")
assert.Contains(t, s, `"display_name":"Support QA"`)
}
func TestModelResponse_BuiltinStripsTenantConfig(t *testing.T) {
+6
View File
@@ -38,6 +38,7 @@ func NewModelHandler(service interfaces.ModelService) *ModelHandler {
// Contains all fields required to create a new model in the system
type CreateModelRequest struct {
Name string `json:"name" binding:"required"`
DisplayName string `json:"display_name"`
Type types.ModelType `json:"type" binding:"required"`
Source types.ModelSource `json:"source" binding:"required"`
Description string `json:"description"`
@@ -89,6 +90,7 @@ func (h *ModelHandler) CreateModel(c *gin.Context) {
model := &types.Model{
TenantID: tenantID,
Name: secutils.SanitizeForLog(req.Name),
DisplayName: secutils.SanitizeForLog(req.DisplayName),
Type: types.ModelType(secutils.SanitizeForLog(string(req.Type))),
Source: req.Source,
Description: secutils.SanitizeForLog(req.Description),
@@ -201,6 +203,7 @@ func (h *ModelHandler) ListModels(c *gin.Context) {
// Contains fields that can be updated for an existing model
type UpdateModelRequest struct {
Name string `json:"name"`
DisplayName *string `json:"display_name"`
Description string `json:"description"`
Parameters types.ModelParameters `json:"parameters"`
Source types.ModelSource `json:"source"`
@@ -256,6 +259,9 @@ func (h *ModelHandler) UpdateModel(c *gin.Context) {
if req.Name != "" {
model.Name = req.Name
}
if req.DisplayName != nil {
model.DisplayName = secutils.SanitizeForLog(*req.DisplayName)
}
model.Description = req.Description
// SSRF validation for updated model BaseURL
+20
View File
@@ -0,0 +1,20 @@
package handler
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestModelUpdateRequestDisplayNamePresence(t *testing.T) {
var omitted UpdateModelRequest
require.NoError(t, json.Unmarshal([]byte(`{"name":"gpt-4o"}`), &omitted))
assert.Nil(t, omitted.DisplayName)
var cleared UpdateModelRequest
require.NoError(t, json.Unmarshal([]byte(`{"display_name":""}`), &cleared))
require.NotNil(t, cleared.DisplayName)
assert.Equal(t, "", *cleared.DisplayName)
}
+21 -19
View File
@@ -35,22 +35,22 @@ const (
type ModelSource string
const (
ModelSourceLocal ModelSource = "local" // Local model
ModelSourceRemote ModelSource = "remote" // Remote model
ModelSourceAliyun ModelSource = "aliyun" // Aliyun DashScope model
ModelSourceZhipu ModelSource = "zhipu" // Zhipu model
ModelSourceVolcengine ModelSource = "volcengine" // Volcengine model
ModelSourceDeepseek ModelSource = "deepseek" // Deepseek model
ModelSourceHunyuan ModelSource = "hunyuan" // Hunyuan model
ModelSourceMinimax ModelSource = "minimax" // Minimax mode
ModelSourceOpenAI ModelSource = "openai" // OpenAI model
ModelSourceGemini ModelSource = "gemini" // Gemini model
ModelSourceMimo ModelSource = "mimo" // Mimo model
ModelSourceSiliconFlow ModelSource = "siliconflow" // SiliconFlow model
ModelSourceJina ModelSource = "jina" // Jina AI model
ModelSourceOpenRouter ModelSource = "openrouter" // OpenRouter model
ModelSourceNvidia ModelSource = "nvidia" // NVIDIA model
ModelSourceNovita ModelSource = "novita" // Novita AI model
ModelSourceLocal ModelSource = "local" // Local model
ModelSourceRemote ModelSource = "remote" // Remote model
ModelSourceAliyun ModelSource = "aliyun" // Aliyun DashScope model
ModelSourceZhipu ModelSource = "zhipu" // Zhipu model
ModelSourceVolcengine ModelSource = "volcengine" // Volcengine model
ModelSourceDeepseek ModelSource = "deepseek" // Deepseek model
ModelSourceHunyuan ModelSource = "hunyuan" // Hunyuan model
ModelSourceMinimax ModelSource = "minimax" // Minimax mode
ModelSourceOpenAI ModelSource = "openai" // OpenAI model
ModelSourceGemini ModelSource = "gemini" // Gemini model
ModelSourceMimo ModelSource = "mimo" // Mimo model
ModelSourceSiliconFlow ModelSource = "siliconflow" // SiliconFlow model
ModelSourceJina ModelSource = "jina" // Jina AI model
ModelSourceOpenRouter ModelSource = "openrouter" // OpenRouter model
ModelSourceNvidia ModelSource = "nvidia" // NVIDIA model
ModelSourceNovita ModelSource = "novita" // Novita AI model
ModelSourceAzureOpenAI ModelSource = "azure_openai" // Azure OpenAI model
)
@@ -65,9 +65,9 @@ type ModelParameters struct {
APIKey string `yaml:"api_key" json:"api_key"`
InterfaceType string `yaml:"interface_type" json:"interface_type"`
EmbeddingParameters EmbeddingParameters `yaml:"embedding_parameters" json:"embedding_parameters"`
ParameterSize string `yaml:"parameter_size" json:"parameter_size"` // Ollama model parameter size (e.g., "7B", "13B", "70B")
Provider string `yaml:"provider" json:"provider"` // Provider identifier: openai, aliyun, zhipu, generic
ExtraConfig map[string]string `yaml:"extra_config" json:"extra_config"` // Provider-specific configuration
ParameterSize string `yaml:"parameter_size" json:"parameter_size"` // Ollama model parameter size (e.g., "7B", "13B", "70B")
Provider string `yaml:"provider" json:"provider"` // Provider identifier: openai, aliyun, zhipu, generic
ExtraConfig map[string]string `yaml:"extra_config" json:"extra_config"` // Provider-specific configuration
// CustomHeaders 允许在调用远程模型 API 时附加自定义 HTTP 请求头,
// 用途类似 Python OpenAI SDK 的 extra_headers 参数,
// 常见场景包括透传企业网关鉴权信息、追踪 ID、路由标识等。
@@ -111,6 +111,8 @@ type Model struct {
TenantID uint64 `yaml:"tenant_id" json:"tenant_id"`
// Name of the model
Name string `yaml:"name" json:"name"`
// Optional user-facing display name. Runtime calls still use Name.
DisplayName string `yaml:"display_name" json:"display_name" gorm:"type:varchar(255);default:''"`
// Type of the model
Type ModelType `yaml:"type" json:"type"`
// Source of the model