models

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 31, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultMessageUserRole = "Human"
	DefaultMessageBotRole  = "Assistant"
	DefaultBotContentType  = "text"
	// DefaultHistoryDepth is a complete user-bot log
	DefaultHistoryDepth = 2
)
View Source
const (
	AdminRoleSort   = 0
	DefaultRoleSort = 20
	DefaultRoleId   = 2
)
View Source
const (
	UserStatusNormal   uint = 1
	UserStatusDisabled uint = 0
)

Variables

This section is empty.

Functions

func FindList

func FindList[T DomainObject](db *gorm.DB, pageInfo *PageInfo, list []*T) ([]*T, error)

Types

type Conversation

type Conversation struct {
	UUIDModel
	Username string     `gorm:"comment:'user name'" json:"username"`
	Title    string     `gorm:"comment:'conversation title'" json:"title"`
	State    bool       `gorm:"comment:'state'" json:"state"`
	Messages []*Message `gorm:"foreignkey:ConversationId" json:"messages"`
}

Conversation saves user conversations

type DomainObject

type DomainObject interface {
	User | Role | Conversation | LLM
}

type History

type History struct {
	Role    string
	Content string
}

type LLM

type LLM struct {
	Model
	Name string `gorm:"comment:'ai models name'" json:"name"`
}

LLM Stores artificial intelligence LLM(large language models)

type Message

type Message struct {
	UUIDModel
	Role           string       `gorm:"comment:'informative role'" json:"role"`
	Content        string       `gorm:"type:text;" json:"content"`
	ContentType    string       `gorm:"comment:'content type'" json:"contentType"`
	Model          string       `gorm:"comment:'ai models name'" json:"models"`
	Feedback       uint         `gorm:"type:tinyint(1)" json:"feedback"`
	ParentMsgId    string       `gorm:"type:varchar(36)" json:"parentMsgId"`
	ConversationId string       `gorm:"type:varchar(36)" json:"conversationId"`
	Conversation   Conversation `gorm:"foreignkey:ConversationId" json:"conversation"`
}

Message Store conversation logs, Including user questions and chat bot responses

func (*Message) FindPreMessages

func (m *Message) FindPreMessages(rep repository.Repository, depth uint) ([]*History, error)

FindPreMessages Find previous message records by depth. The depth is an even number, which means a completed user-bot log

type Model

type Model struct {
	Id        uint           `gorm:"primaryKey" json:"id"`
	CreatedAt time.Time      `json:"createdAt"`
	UpdatedAt time.Time      `json:"updatedAt"`
	DeletedAt gorm.DeletedAt `gorm:"index:idx_deleted_at" json:"deletedAt"`
}

type PageInfo

type PageInfo struct {
	PageNum      uint  `json:"pageNum" form:"pageNum"`
	PageSize     uint  `json:"pageSize" form:"pageSize"`
	Total        int64 `json:"total" form:"total"`
	NoPagination bool  `json:"noPagination" form:"noPagination"` // Do not use pagination
}

PageInfo includes the Response result of query by page number

func (*PageInfo) GetLimit

func (p *PageInfo) GetLimit() (limit, offset int)

GetLimit Calculate limit/offset for gorm query

type Role

type Role struct {
	Model
	Name    string  `gorm:"comment:'role name'" json:"name"`
	Keyword string  `gorm:"comment:'role keyword';unique" json:"keyword"`
	Desc    string  `gorm:"comment:'role description'" json:"desc"`
	Sort    *uint   `gorm:"default:1;comment:'Role sorting (the larger the value, the smaller the authority)'" json:"sort"`
	Status  *uint   `gorm:"comment:'role status(enable/disable)';default:1;type:tinyint(1)" json:"status"`
	Creator string  `gorm:"comment:'creator'" json:"creator"`
	Users   []*User `gorm:"foreignkey:RoleId" json:"users"`
}

func (*Role) FindIdsBySort

func (r *Role) FindIdsBySort(rep repository.Repository, sort uint) ([]uint, error)

type UUIDModel

type UUIDModel struct {
	Id        string         `gorm:"type:char(36);primaryKey" json:"id"`
	CreatedAt time.Time      `json:"createdAt"`
	UpdatedAt time.Time      `json:"updatedAt"`
	DeletedAt gorm.DeletedAt `gorm:"index:idx_deleted_at" json:"deletedAt"`
}

func (*UUIDModel) BeforeCreate

func (u *UUIDModel) BeforeCreate(tx *gorm.DB) (err error)

type Url

type Url struct {
	Model
	Method   string `gorm:"comment:'request method'" json:"method"`
	Path     string `gorm:"comment:'url path'" json:"path"`
	Category string `gorm:"comment:'category'" json:"category"`
	Desc     string `gorm:"comment:'description'" json:"desc"`
	Creator  string `gorm:"comment:'creator'" json:"creator"`
}

Url stores all api paths of the current application

type User

type User struct {
	Model
	Username string `gorm:"comment:'user name';unique" json:"username"`
	ZhName   string `gorm:"comment:'user zh name'" json:"zhName"`
	Email    string `gorm:"comment:'user email'" json:"email"`
	Status   *uint  `gorm:"comment:'user status';default:1;type:tinyint(1)" json:"status"`
	Creator  string `gorm:"comment:'creator'" json:"creator"`
	RoleId   uint   `gorm:"comment:'role id'" json:"roleId"`
	Role     Role   `gorm:"foreignkey:RoleId" json:"role"`
}

func (*User) FindByName

func (u *User) FindByName(rep repository.Repository, name string) (*User, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL