F1 告警静默规则 [done]: - 后端 alert_silence.go: CRUD + Toggle (onetime/daily/weekly 三模式) - 告警引擎 isSilenced 集成 (alert_engine.go) - 前端 SilenceRuleTab + SilenceDialog - 路由 /alerts/silences 已注册 F2 审计日志导出 [done]: - 重写 ExportAuditLogs: 真正的 CSV 导出 (encoding/csv + UTF-8 BOM) - 支持 module/action/username/startTime/endTime 筛选 - 导出限制 10000 条防溢出,自动记录审计日志 - JSON 格式向后兼容 (format=json) - 前端 exportLogs 传递查询参数 同时包含累积的前期工作: - 目录重构 internal/ -> controller/model/router (v0.55-v0.57) - 后端分层架构 dto/repository/service/utils - 审计模块全功能 (终端审计/操作审计/登录日志) - asciicast v2 录制格式 - SFTP 文件浏览器 - StatStrip 紧凑统计条 - 在线会话自动刷新 - LiveMonitor WebSocket 诊断修复 验证: go build ✅ | npm run build ✅ | Docker 部署 ✅ | 10 回归端点 ✅ | CSV 导出 ✅ | 静默 CRUD ✅
69 lines
3.4 KiB
Go
69 lines
3.4 KiB
Go
package model
|
||
|
||
import "time"
|
||
|
||
// LLMConfig 大语言模型配置(单行配置,类似 LDAPConfig) // Logan.Li
|
||
// 支持 OpenAI 兼容接口(OpenAI / DeepSeek / 通义千问 / Moonshot / Ollama / 自定义)
|
||
type LLMConfig struct {
|
||
ID uint `gorm:"primarykey" json:"id"`
|
||
Provider string `gorm:"size:50;not null;default:openai" json:"provider"` // openai/deepseek/qwen/moonshot/ollama/custom
|
||
Model string `gorm:"size:100;not null;default:gpt-4o-mini" json:"model"` // 模型名,如 gpt-4o-mini / deepseek-chat
|
||
APIKey string `gorm:"size:500" json:"api_key"` // API Key(GET 时会被脱敏)
|
||
Endpoint string `gorm:"size:500" json:"endpoint"` // 基础地址,如 https://api.openai.com/v1
|
||
Temperature float64 `gorm:"default:0.7" json:"temperature"` // 采样温度 0-2
|
||
MaxTokens int `gorm:"default:2000" json:"max_tokens"` // 最大输出 token
|
||
SystemPrompt string `gorm:"type:text" json:"system_prompt"` // 系统提示词(AIOps 运维助手角色)
|
||
Enabled bool `gorm:"default:false" json:"enabled"` // 是否启用
|
||
CreatedAt time.Time `json:"created_at"`
|
||
UpdatedAt time.Time `json:"updated_at"`
|
||
}
|
||
|
||
// TableName 表名 // Logan.Li
|
||
func (LLMConfig) TableName() string { return "ai_llm_configs" }
|
||
|
||
// SaveLLMConfigRequest 保存 LLM 配置请求 // Logan.Li
|
||
type SaveLLMConfigRequest struct {
|
||
Provider string `json:"provider"`
|
||
Model string `json:"model"`
|
||
APIKey string `json:"api_key"` // 若为脱敏值(含 ****)则后端保留原值
|
||
Endpoint string `json:"endpoint"`
|
||
Temperature float64 `json:"temperature"`
|
||
MaxTokens int `json:"max_tokens"`
|
||
SystemPrompt string `json:"system_prompt"`
|
||
Enabled bool `json:"enabled"`
|
||
}
|
||
|
||
// ChatMessage 对话消息 // Logan.Li
|
||
type ChatMessage struct {
|
||
Role string `json:"role"` // system / user / assistant
|
||
Content string `json:"content"`
|
||
}
|
||
|
||
// ChatRequest AI 对话请求 // Logan.Li
|
||
type ChatRequest struct {
|
||
Messages []ChatMessage `json:"messages" binding:"required,min=1,dive"`
|
||
SessionID string `json:"session_id"` // 前端生成,用于隔离多轮对话
|
||
}
|
||
|
||
// ChatResponse AI 对话响应 // Logan.Li
|
||
type ChatResponse struct {
|
||
Content string `json:"content"`
|
||
Model string `json:"model"`
|
||
TokensUsed int `json:"tokens_used"`
|
||
}
|
||
|
||
// ChatHistory 对话历史记录(按用户隔离,session_id 区分多轮对话) // Logan.Li
|
||
// 仅持久化成功完成的对话(用户消息 + 助手回复成对写入),错误气泡为瞬时 UI 不入库
|
||
type ChatHistory struct {
|
||
ID uint `gorm:"primarykey" json:"id"`
|
||
UserID uint `gorm:"index;not null" json:"user_id"` // 所属用户(JWT 中间件注入)
|
||
SessionID string `gorm:"size:64;index;not null;default:''" json:"session_id"` // 对话会话 ID(前端 UUID)
|
||
Role string `gorm:"size:16;not null" json:"role"` // user / assistant
|
||
Content string `gorm:"type:text;not null" json:"content"` // 消息内容
|
||
Model string `gorm:"size:100" json:"model"` // 生成回复所用模型(仅 assistant 行有意义)
|
||
CreatedAt time.Time `json:"created_at"`
|
||
}
|
||
|
||
// TableName 表名 // Logan.Li
|
||
func (ChatHistory) TableName() string { return "ai_chat_histories" }
|