store

package
v0.0.0-...-088f13f Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DialogRetention = time.Hour
	SaltLength      = 32
)

Variables

This section is empty.

Functions

This section is empty.

Types

type InputState

type InputState string
const (
	InputStateEmpty                  InputState = ""
	InputStateWaitingForSystemPrompt InputState = "waiting_for_system_prompt"
)

type Message

type Message struct {
	Id        int64          `db:"id"`
	ChatId    int64          `db:"chat_id"`
	Role      string         `db:"role"`
	Message   string         `db:"message"`
	Version   MessageVersion `db:"version"`
	CreatedAt ytime.Time     `db:"created_at"`
}

type MessageVersion

type MessageVersion int
const (
	MessageVersionV0 MessageVersion = iota
	MessageVersionV1
	MessageVersionV2
)

type SqliteStore

type SqliteStore struct {
	// contains filtered or unexported fields
}

func NewSqlite

func NewSqlite(path string) (*SqliteStore, error)

func (*SqliteStore) ApproveUser

func (s *SqliteStore) ApproveUser(ctx context.Context, chatId int64) error

func (*SqliteStore) CheckInviteCode

func (s *SqliteStore) CheckInviteCode(ctx context.Context, user *User, code string) error

func (*SqliteStore) ClearMessages

func (s *SqliteStore) ClearMessages(ctx context.Context, chatId int64) error

func (*SqliteStore) Close

func (s *SqliteStore) Close()

func (*SqliteStore) EnsureDiglogID

func (s *SqliteStore) EnsureDiglogID(ctx context.Context, user *User) error

func (*SqliteStore) EnsureInviteCode

func (s *SqliteStore) EnsureInviteCode(ctx context.Context, user *User) error

EnsureInviteCode checks if the user has an invite code and generates a new one if not.

func (*SqliteStore) GetDialogMessages

func (s *SqliteStore) GetDialogMessages(ctx context.Context, chatId int64) ([]*Message, error)

func (*SqliteStore) GetUser

func (s *SqliteStore) GetUser(ctx context.Context, chatId int64) (*User, error)

func (*SqliteStore) PutMessages

func (s *SqliteStore) PutMessages(ctx context.Context, messages []*Message) error

func (*SqliteStore) PutUsage

func (s *SqliteStore) PutUsage(ctx context.Context, usage *Usage) error

func (*SqliteStore) PutUser

func (s *SqliteStore) PutUser(ctx context.Context, user *User) (*User, error)

func (*SqliteStore) ResetDiglogID

func (s *SqliteStore) ResetDiglogID(ctx context.Context, user *User) error

func (*SqliteStore) SetDefaultInviteCode

func (s *SqliteStore) SetDefaultInviteCode(code string)

func (*SqliteStore) SetInputState

func (s *SqliteStore) SetInputState(ctx context.Context, chatId int64, state InputState) error

func (*SqliteStore) SetSystemPrompt

func (s *SqliteStore) SetSystemPrompt(ctx context.Context, chatId int64, prompt string) error

SetSystemPrompt sets the system prompt for the user.

type Store

type Store interface {
	GetUser(ctx context.Context, chatId int64) (*User, error)
	PutUser(ctx context.Context, user *User) (*User, error)
	ApproveUser(ctx context.Context, chatId int64) error
	EnsureInviteCode(ctx context.Context, user *User) error
	EnsureDiglogID(ctx context.Context, user *User) error
	ResetDiglogID(ctx context.Context, user *User) error
	CheckInviteCode(ctx context.Context, user *User, inviteCode string) error
	SetSystemPrompt(ctx context.Context, chatId int64, prompt string) error
	SetInputState(ctx context.Context, chatId int64, state InputState) error

	GetDialogMessages(ctx context.Context, chatId int64) ([]*Message, error)
	PutMessages(ctx context.Context, message []*Message) error
	ClearMessages(ctx context.Context, chatId int64) error

	PutUsage(ctx context.Context, usage *Usage) error
}

type Usage

type Usage struct {
	Id               int        `db:"id"`
	ChatId           int64      `db:"chat_id"`
	UpdateId         int        `db:"update_id"`
	Model            string     `db:"model"`
	CompletionTokens int        `db:"completion_tokens"`
	PromptTokens     int        `db:"prompt_tokens"`
	TotalTokens      int        `db:"total_tokens"`
	CreatedAt        ytime.Time `db:"created_at"`
}

type User

type User struct {
	ChatId       int64      `db:"chat_id"`
	Approved     bool       `db:"approved"`
	Username     string     `db:"username"`
	FullName     string     `db:"full_name"`
	Salt         string     `db:"salt"`
	Model        string     `db:"model"`
	InviteCode   string     `db:"invite_code"`
	SystemPrompt string     `db:"system_prompt"`
	InputState   InputState `db:"input_state"`
	DialogID     string     `db:"dialog_id"`

	CreatedAt ytime.Time `db:"created_at"`
	UpdatedAt ytime.Time `db:"updated_at"`
}

Jump to

Keyboard shortcuts

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