topfans/backend/services/aiChatService/model/ai_chat_models.go
2026-05-28 12:00:19 +08:00

102 lines
3.4 KiB
Go
Raw 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 model
import (
"time"
"github.com/google/uuid"
)
// Persona 人设结构
type Persona struct {
ID uuid.UUID `json:"id" gorm:"type:uuid;primary_key;default:gen_random_uuid()"`
UserID int64 `json:"user_id" gorm:"index;not null"`
Name string `json:"name" gorm:"type:varchar(64);not null"`
Description string `json:"description" gorm:"type:text"`
AvatarURL string `json:"avatar_url" gorm:"type:varchar(512)"`
TalkStyle string `json:"talk_style" gorm:"type:varchar(256)"`
SystemPrompt string `json:"system_prompt" gorm:"type:text;not null"`
IsDefault bool `json:"is_default" gorm:"default:false"`
CreatedAt int64 `json:"created_at" gorm:"autoCreateTime:milli"`
UpdatedAt int64 `json:"updated_at" gorm:"autoUpdateTime:milli"`
}
// TableName 指定表名
func (Persona) TableName() string {
return "ai_personas"
}
// UserMemory 用户长期记忆
type UserMemory struct {
ID uint `json:"id" gorm:"primaryKey;autoIncrement"`
UserID int64 `json:"user_id" gorm:"index;not null"`
Content string `json:"content" gorm:"type:text;not null"`
Keywords []string `json:"keywords" gorm:"type:text[]"`
Weight int `json:"weight" gorm:"default:50"`
IsCore bool `json:"is_core" gorm:"default:false"`
CreatedAt int64 `json:"created_at" gorm:"autoCreateTime:milli"`
UpdatedAt int64 `json:"updated_at" gorm:"autoUpdateTime:milli"`
}
// TableName 指定表名
func (UserMemory) TableName() string {
return "ai_user_memories"
}
// Config 配置结构
type Config struct {
ID uint `json:"id" gorm:"primaryKey;autoIncrement"`
ConfigKey string `json:"config_key" gorm:"type:varchar(128);uniqueIndex;not null"`
ConfigValue string `json:"config_value" gorm:"type:text;not null"`
ConfigType string `json:"config_type" gorm:"type:varchar(32);default:string"`
Category string `json:"category" gorm:"type:varchar(64);index"`
Description string `json:"description" gorm:"type:varchar(256)"`
IsEncrypted bool `json:"is_encrypted" gorm:"default:false"`
UpdatedAt int64 `json:"updated_at" gorm:"autoUpdateTime:milli"`
CreatedAt int64 `json:"created_at" gorm:"autoCreateTime:milli"`
}
// TableName 指定表名
func (Config) TableName() string {
return "ai_chat_configs"
}
// Message 对话消息
type Message struct {
Role string `json:"role"`
Content string `json:"content"`
}
// ChatContext 短期上下文Redis 存储)
type ChatContext struct {
SessionID string `json:"session_id"`
Messages []Message `json:"messages"`
PersonaID string `json:"persona_id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// PersonaInfo 人设信息API 返回)
type PersonaInfo struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
AvatarURL string `json:"avatar_url"`
TalkStyle string `json:"talk_style"`
IsDefault bool `json:"is_default"`
CreatedAt int64 `json:"created_at"`
UpdatedAt int64 `json:"updated_at"`
}
// ToPersonaInfo converts Persona to PersonaInfo
func (p *Persona) ToPersonaInfo() PersonaInfo {
return PersonaInfo{
ID: p.ID.String(),
Name: p.Name,
Description: p.Description,
AvatarURL: p.AvatarURL,
TalkStyle: p.TalkStyle,
IsDefault: p.IsDefault,
CreatedAt: p.CreatedAt,
UpdatedAt: p.UpdatedAt,
}
}