Files
X-Agents/server/internal/model/model_info.go
DESKTOP-72TV0V4\caoxiaozhu 25d3781f06 feat: 优化 Model 连接测试,支持阿里云 DashScope
- 添加阿里云 provider 支持
- 添加连接超时 (10s)
- 优化 URL 构建逻辑
- 默认状态改为 inactive
- 添加详细日志

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 16:21:29 +08:00

71 lines
2.5 KiB
Go

package model
import "time"
// ModelInfo 模型信息
type ModelInfo struct {
ID string `json:"id" gorm:"primaryKey;type:varchar(36)"`
Name string `json:"name" gorm:"type:varchar(255);not null"`
ModelType string `json:"model_type" gorm:"type:varchar(50);not null"` // chat/embedding/rerank/vlm
Provider string `json:"provider" gorm:"type:varchar(50);not null"` // OpenAI/Ollama
Model string `json:"model" gorm:"type:varchar(255);not null"` // 模型标识
APIKey string `json:"api_key" gorm:"type:text"` // API 密钥
BaseURL string `json:"base_url" gorm:"type:varchar(500)"` // 基础 URL
APIEndpoint string `json:"api_endpoint" gorm:"type:varchar(500)"` // API 端点路径
Status string `json:"status" gorm:"type:varchar(20);default:active"` // active/inactive
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
func (ModelInfo) TableName() string {
return "model_info"
}
// ModelListRequest 获取模型列表请求
type ModelListRequest struct {
}
// ModelListResponse 获取模型列表响应
type ModelListResponse struct {
List []ModelInfo `json:"list"`
}
// CreateModelRequest 创建模型请求
type CreateModelRequest struct {
Name string `json:"name" binding:"required"`
ModelType string `json:"model_type" binding:"required"`
Provider string `json:"provider" binding:"required"`
Model string `json:"model" binding:"required"`
APIKey string `json:"api_key" binding:"required"`
BaseURL string `json:"base_url" binding:"required"`
APIEndpoint string `json:"api_endpoint"`
Status string `json:"status"`
}
// UpdateModelRequest 更新模型请求
type UpdateModelRequest struct {
Name string `json:"name"`
ModelType string `json:"model_type"`
Provider string `json:"provider"`
Model string `json:"model"`
APIKey string `json:"api_key"`
BaseURL string `json:"base_url"`
APIEndpoint string `json:"api_endpoint"`
Status string `json:"status"`
}
// TestModelRequest 测试模型连接请求
type TestModelRequest struct {
Provider string `json:"provider" binding:"required"`
Model string `json:"model" binding:"required"`
APIKey string `json:"api_key" binding:"required"`
BaseURL string `json:"base_url" binding:"required"`
APIEndpoint string `json:"api_endpoint"`
}
// TestModelResponse 测试模型连接响应
type TestModelResponse struct {
Success bool `json:"success"`
Message string `json:"message"`
}