69 lines
2.8 KiB
Go
69 lines
2.8 KiB
Go
package app
|
||
|
||
import (
|
||
"time"
|
||
|
||
"gorm.io/datatypes"
|
||
"gorm.io/gorm"
|
||
)
|
||
|
||
// Worldbook 世界书主表
|
||
type Worldbook 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"`
|
||
Name string `gorm:"type:varchar(100);not null" json:"name"`
|
||
Description string `gorm:"type:text" json:"description"`
|
||
IsPublic bool `gorm:"default:false" json:"isPublic"`
|
||
EntryCount int `gorm:"default:0" json:"entryCount"`
|
||
}
|
||
|
||
func (Worldbook) TableName() string {
|
||
return "worldbooks"
|
||
}
|
||
|
||
// WorldbookEntry 世界书条目表(完全兼容 SillyTavern 格式)
|
||
type WorldbookEntry struct {
|
||
ID uint `gorm:"primarykey" json:"id"`
|
||
CreatedAt time.Time `json:"createdAt"`
|
||
UpdatedAt time.Time `json:"updatedAt"`
|
||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
||
|
||
WorldbookID uint `gorm:"index;not null" json:"worldbookId"`
|
||
Comment string `gorm:"type:varchar(200)" json:"comment"` // 条目标题/备注
|
||
Content string `gorm:"type:text;not null" json:"content"` // 注入内容
|
||
|
||
// 关键词(存为 JSONB []string)
|
||
Keys datatypes.JSON `gorm:"type:jsonb" json:"keys"`
|
||
SecondaryKeys datatypes.JSON `gorm:"type:jsonb" json:"secondaryKeys"`
|
||
|
||
// 触发设置
|
||
Constant bool `gorm:"default:false" json:"constant"` // 常驻注入,无需关键词触发
|
||
Enabled bool `gorm:"default:true" json:"enabled"` // 是否启用
|
||
UseRegex bool `gorm:"default:false" json:"useRegex"` // 关键词用正则表达式
|
||
CaseSensitive bool `gorm:"default:false" json:"caseSensitive"` // 区分大小写
|
||
MatchWholeWords bool `gorm:"default:false" json:"matchWholeWords"` // 全词匹配
|
||
Selective bool `gorm:"default:false" json:"selective"` // 是否需要次要关键词
|
||
SelectiveLogic int `gorm:"default:0" json:"selectiveLogic"` // 0=AND, 1=NOT
|
||
|
||
// 注入位置与优先级
|
||
Position int `gorm:"default:1" json:"position"` // 0=系统提示词前, 1=系统提示词后, 4=指定深度
|
||
Depth int `gorm:"default:4" json:"depth"` // position=4 时生效
|
||
Order int `gorm:"default:100" json:"order"` // 同位置时的排序
|
||
|
||
// 概率与触发控制(SillyTavern 兼容字段)
|
||
Probability int `gorm:"default:100" json:"probability"` // 触发概率 0-100
|
||
ScanDepth int `gorm:"default:2" json:"scanDepth"` // 扫描最近 N 条消息(0=全部)
|
||
GroupID string `gorm:"type:varchar(100)" json:"groupId"` // 条目分组
|
||
|
||
// 扩展字段
|
||
Extensions datatypes.JSON `gorm:"type:jsonb" json:"extensions"`
|
||
}
|
||
|
||
func (WorldbookEntry) TableName() string {
|
||
return "worldbook_entries"
|
||
}
|