chatbot

package
v0.0.0-...-ef01d87 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2023 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetOpenAIErrCode

func GetOpenAIErrCode(err error) int

Types

type Bot

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

func NewBot

func NewBot(cfg *cfgs.Config) (*Bot, error)

func (*Bot) ClearExpiredSessionsPeriodically

func (bot *Bot) ClearExpiredSessionsPeriodically()

func (*Bot) DoTasks

func (bot *Bot) DoTasks()

func (*Bot) Serve

func (bot *Bot) Serve() error

func (*Bot) Stop

func (bot *Bot) Stop()

func (*Bot) UpdateApiServerAccessToken

func (bot *Bot) UpdateApiServerAccessToken() error

type ChangeRoleTask

type ChangeRoleTask struct {
	SessionID string
	Role      string
	ReplyFn   func(reply string, imgUrls ...string) error
}

func (*ChangeRoleTask) Do

func (task *ChangeRoleTask) Do(bot *Bot) error

type ChatTask

type ChatTask struct {
	UserName  string
	SessionID string
	Message   string
	ReplyFn   func(reply string, imgUrls ...string) error
}

func (*ChatTask) Do

func (task *ChatTask) Do(bot *Bot) error

type ClearExpiredSessionsTask

type ClearExpiredSessionsTask struct {
	PushMessageFn func(sessionID, msg string) error
}

func (*ClearExpiredSessionsTask) Do

func (task *ClearExpiredSessionsTask) Do(bot *Bot) error

type ClearSessionTask

type ClearSessionTask struct {
	SessionID string
	ReplyFn   func(reply string, imgUrls ...string) error
}

func (*ClearSessionTask) Do

func (task *ClearSessionTask) Do(bot *Bot) error

type Session

type Session struct {
	ID             string
	Role           string
	Messages       []openai.ChatCompletionMessage
	LastUpdateDate time.Time
}

func NewSession

func NewSession(id, role string) *Session

func (*Session) AddMessage

func (s *Session) AddMessage(msg *openai.ChatCompletionMessage)

func (*Session) ChangeRole

func (s *Session) ChangeRole(role string)

func (*Session) Clear

func (s *Session) Clear()

func (*Session) ShortID

func (s *Session) ShortID() string

type SessionManager

type SessionManager struct {
	DefaultRole string
	Sessions    map[string]*Session
}

func NewSessionManager

func NewSessionManager(defaultRole string) *SessionManager

func (*SessionManager) ClearExpiredSessions

func (m *SessionManager) ClearExpiredSessions(expiryPeriod time.Duration) []string

func (*SessionManager) GetSession

func (m *SessionManager) GetSession(id string) *Session

type Task

type Task interface {
	Do(bot *Bot) error
}

Jump to

Keyboard shortcuts

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