56
server/model/app/conversation.go
Normal file
56
server/model/app/conversation.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/datatypes"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// Conversation 对话会话模型
|
||||
type Conversation struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
||||
|
||||
UserID uint `gorm:"index;not null" json:"userId"` // 所属用户ID
|
||||
CharacterID uint `gorm:"index;not null" json:"characterId"` // 角色卡ID
|
||||
Title string `gorm:"type:varchar(200)" json:"title"` // 对话标题
|
||||
|
||||
// 对话配置
|
||||
PresetID *uint `gorm:"index" json:"presetId"` // 使用的预设ID
|
||||
AIProvider string `gorm:"type:varchar(50)" json:"aiProvider"` // AI提供商 (openai/anthropic)
|
||||
Model string `gorm:"type:varchar(100)" json:"model"` // 使用的模型
|
||||
Settings datatypes.JSON `gorm:"type:jsonb" json:"settings"` // 对话设置 (temperature等)
|
||||
|
||||
// 统计信息
|
||||
MessageCount int `gorm:"default:0" json:"messageCount"` // 消息数量
|
||||
TokenCount int `gorm:"default:0" json:"tokenCount"` // Token使用量
|
||||
}
|
||||
|
||||
// TableName 指定表名
|
||||
func (Conversation) TableName() string {
|
||||
return "conversations"
|
||||
}
|
||||
|
||||
// Message 消息模型
|
||||
type Message struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
||||
|
||||
ConversationID uint `gorm:"index;not null" json:"conversationId"` // 所属对话ID
|
||||
Role string `gorm:"type:varchar(20);not null" json:"role"` // 角色 (user/assistant/system)
|
||||
Content string `gorm:"type:text;not null" json:"content"` // 消息内容
|
||||
|
||||
// 元数据
|
||||
TokenCount int `gorm:"default:0" json:"tokenCount"` // Token数量
|
||||
Metadata datatypes.JSON `gorm:"type:jsonb" json:"metadata"` // 额外元数据
|
||||
}
|
||||
|
||||
// TableName 指定表名
|
||||
func (Message) TableName() string {
|
||||
return "messages"
|
||||
}
|
||||
Reference in New Issue
Block a user