chatbot

package
v0.0.0-...-8afbfe0 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2025 License: MIT Imports: 18 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()

type ChangeRoleTask

type ChangeRoleTask struct {
	Session *Session
	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
	BotName  string
	Session  *Session
	Message  string
	IsGroup  bool
	ReplyFn  func(reply string, imgUrls ...string) error
}

func (*ChatTask) Do

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

type ClearSessionTask

type ClearSessionTask struct {
	Session *Session
	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()

type SessionManager

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

func NewSessionManager

func NewSessionManager() *SessionManager

func (*SessionManager) ClearExpiredSessions

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

func (*SessionManager) GetSession

func (m *SessionManager) GetSession(id string, defaultRole 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