58 lines
1.9 KiB
Go
58 lines
1.9 KiB
Go
package models
|
|
|
|
import (
|
|
"kefu/types"
|
|
)
|
|
|
|
// LlmLog 模型对应于llm_log表
|
|
type LlmLog struct {
|
|
ID uint `gorm:"primary_key;auto_increment" json:"id"`
|
|
EntID string `gorm:"type:varchar(100);not null;default:'';comment:'企业ID'" json:"ent_id"`
|
|
KefuName string `gorm:"type:varchar(500);not null;default:'';comment:'客服账户'" json:"kefu_name"`
|
|
ModelName string `gorm:"type:varchar(500);not null;default:'';comment:'大模型名称'" json:"model_name"`
|
|
Question string `gorm:"type:text;default:null;comment:'提问'" json:"question"`
|
|
Answer string `gorm:"type:text;default:null;comment:'回复'" json:"answer"`
|
|
CreatedAt types.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP" json:"created_at"`
|
|
}
|
|
|
|
// CountLlmLogs 返回符合条件的 LlmLog 记录数量
|
|
func CountLlmLogs(query interface{}, args ...interface{}) int64 {
|
|
var count int64
|
|
db := DB.Model(&LlmLog{}).Where(query, args...)
|
|
db.Count(&count)
|
|
return count
|
|
}
|
|
|
|
// FindLlmLog 查询单个 LlmLog 记录
|
|
func FindLlmLog(query interface{}, args ...interface{}) LlmLog {
|
|
var log LlmLog
|
|
db := DB.Model(&LlmLog{}).Where(query, args...)
|
|
db.First(&log)
|
|
return log
|
|
}
|
|
|
|
// SaveLlmLog 更新 LlmLog 记录
|
|
func (l *LlmLog) SaveLlmLog(query interface{}, args ...interface{}) error {
|
|
db := DB.Model(&LlmLog{}).Where(query, args...).Updates(l)
|
|
return db.Error
|
|
}
|
|
|
|
// AddLlmLog 添加新的 LlmLog 记录
|
|
func (l *LlmLog) AddLlmLog() error {
|
|
return DB.Create(l).Error
|
|
}
|
|
|
|
// FindLlmLogs 分页查询 LlmLog 记录
|
|
func FindLlmLogs(page, pageSize int, query interface{}, args ...interface{}) []LlmLog {
|
|
var logs []LlmLog
|
|
limit := pageSize
|
|
offset := (page - 1) * pageSize
|
|
DB.Model(&LlmLog{}).Where(query, args...).Order("id desc").Limit(limit).Offset(offset).Find(&logs)
|
|
return logs
|
|
}
|
|
|
|
// DeleteLlmLog 删除 LlmLog 记录
|
|
func DeleteLlmLog(query interface{}, args ...interface{}) error {
|
|
return DB.Where(query, args...).Delete(&LlmLog{}).Error
|
|
}
|