Files
st/server/model/app/ai_provider.go

46 lines
2.4 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package app
import (
"git.echol.cn/loser/st/server/global"
"gorm.io/datatypes"
)
// AIProvider AI 服务提供商配置
// 每个用户可以配置多个 AI 提供商(如 OpenAI、Claude、Gemini 等)
// UserID 为 NULL 表示系统预设的提供商配置
type AIProvider struct {
global.GVA_MODEL
UserID *uint `json:"userId" gorm:"index;comment:用户IDNULL表示系统配置"`
User *AppUser `json:"user,omitempty" gorm:"foreignKey:UserID"`
ProviderName string `json:"providerName" gorm:"type:varchar(100);not null;index;comment:提供商名称"`
ProviderType string `json:"providerType" gorm:"type:varchar(50);not null;default:openai;comment:提供商类型(openai/claude/gemini/custom)"`
BaseURL string `json:"baseUrl" gorm:"type:varchar(500);comment:API基础地址"`
APIKey string `json:"-" gorm:"type:varchar(500);comment:API密钥加密存储"`
APIConfig datatypes.JSON `json:"apiConfig" gorm:"type:jsonb;comment:额外API配置"`
Capabilities datatypes.JSON `json:"capabilities" gorm:"type:jsonb;comment:支持的能力(chat/image_gen等)"`
IsEnabled bool `json:"isEnabled" gorm:"default:true;comment:是否启用"`
IsDefault bool `json:"isDefault" gorm:"default:false;comment:是否为默认提供商"`
SortOrder int `json:"sortOrder" gorm:"default:0;comment:排序权重"`
}
func (AIProvider) TableName() string {
return "ai_providers"
}
// AIModel AI 模型配置
// 每个提供商下可以有多个模型(如 gpt-4o、gpt-4o-mini 等)
type AIModel struct {
global.GVA_MODEL
ProviderID uint `json:"providerId" gorm:"not null;index;comment:提供商ID"`
Provider *AIProvider `json:"provider,omitempty" gorm:"foreignKey:ProviderID"`
ModelName string `json:"modelName" gorm:"type:varchar(200);not null;comment:模型标识API调用用"`
DisplayName string `json:"displayName" gorm:"type:varchar(200);comment:模型显示名称"`
ModelType string `json:"modelType" gorm:"type:varchar(50);not null;default:chat;comment:模型类型(chat/image_gen)"`
Config datatypes.JSON `json:"config" gorm:"type:jsonb;comment:模型参数配置"`
IsEnabled bool `json:"isEnabled" gorm:"default:true;comment:是否启用"`
}
func (AIModel) TableName() string {
return "ai_models"
}