service

package
v0.0.0-...-d48bf00 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2024 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RoleUser      ROLES = "user"
	RoleSystem    ROLES = "system"
	RoleAssistant ROLES = "assistant"
	RoleApp       ROLES = "app"

	TypeFile TYPE = "file"
	TypeUser TYPE = "user"
)

Variables

View Source
var ErrAlreadyExist = errors.New("already exists")
View Source
var ErrNotFound = errors.New("not found")

Functions

func AskImage

func AskImage(prompt string, size string) ([]byte, error)

func CountTokens

func CountTokens(content string) (int, error)

func EditImage

func EditImage(filePath, prompt, size string) ([]byte, error)

Types

type ChatMessage

type ChatMessage struct {
	Id      snowflake.ID
	Role    ROLES
	Content string
	Tokens  int
	Type    TYPE

	Order uint

	AssociatedMessageId int64

	Date time.Time

	AudioFileId string `json:"-"`

	Meta Meta
}

func (*ChatMessage) AsTypeFile

func (c *ChatMessage) AsTypeFile() *ChatMessage

func (*ChatMessage) SetAudioFileId

func (c *ChatMessage) SetAudioFileId(id string) *ChatMessage

type ChatMessages

type ChatMessages struct {
	Id          string
	Description string
	Messages    []ChatMessage
	TotalTokens int
	// contains filtered or unexported fields
}

func NewChatMessages

func NewChatMessages(id string) *ChatMessages

func (*ChatMessages) AddMessage

func (c *ChatMessages) AddMessage(content string, role ROLES) (*ChatMessage, error)

func (*ChatMessages) AddMessageFromFile

func (c *ChatMessages) AddMessageFromFile(filename string) (*ChatMessage, error)

AddMessageFromFile reads the content of a file using os.ReadFile, then adds a new message with the file content and filename to the ChatMessages using the AddMessage method. If there's an error reading the file, it returns the error.

func (*ChatMessages) ClearMessages

func (c *ChatMessages) ClearMessages()

func (*ChatMessages) DeleteMessage

func (c *ChatMessages) DeleteMessage(id int64) error

func (*ChatMessages) FilterByOpenAIRoles

func (c *ChatMessages) FilterByOpenAIRoles() []ChatMessage

func (*ChatMessages) FilterMessages

func (c *ChatMessages) FilterMessages(role ROLES) (messages []ChatMessage, tokens int)

func (*ChatMessages) FindById

func (c *ChatMessages) FindById(id int64) *ChatMessage

func (*ChatMessages) FindByOrder

func (c *ChatMessages) FindByOrder(order uint) *ChatMessage

func (*ChatMessages) FindMessageByContent

func (c *ChatMessages) FindMessageByContent(content string) (*ChatMessage, error)

func (*ChatMessages) LastMessage

func (c *ChatMessages) LastMessage(role ROLES) *ChatMessage

func (*ChatMessages) LoadFromFile

func (c *ChatMessages) LoadFromFile(filename string) (err error)

func (*ChatMessages) RecountTokens

func (c *ChatMessages) RecountTokens() *ChatMessages

func (*ChatMessages) SaveChatInModelfileFormat

func (c *ChatMessages) SaveChatInModelfileFormat(filename string) error

func (*ChatMessages) SaveToFile

func (c *ChatMessages) SaveToFile(filename string) error

func (*ChatMessages) SetAssociatedId

func (c *ChatMessages) SetAssociatedId(idUser, idAssistant int64) error

func (*ChatMessages) SetDescription

func (c *ChatMessages) SetDescription(description string) *ChatMessages

func (*ChatMessages) SetId

func (c *ChatMessages) SetId(id string) *ChatMessages

func (*ChatMessages) SetMessagesOrder

func (c *ChatMessages) SetMessagesOrder() *ChatMessages

func (*ChatMessages) ToLangchainMessage

func (c *ChatMessages) ToLangchainMessage() []llms.MessageContent

func (*ChatMessages) UpdateMessage

func (c *ChatMessages) UpdateMessage(m ChatMessage) error

type ContextHolder

type ContextHolder struct {
	UserChatId snowflake.ID
	Ctx        context.Context
	CancelFn   func()
}

func (ContextHolder) String

func (c ContextHolder) String() string

type ContextService

type ContextService struct {
	Contexts []ContextHolder
}

func NewContextService

func NewContextService() *ContextService

func (*ContextService) AddContext

func (cs *ContextService) AddContext(ctx context.Context, cancelFn func())

func (*ContextService) AddContextWithId

func (cs *ContextService) AddContextWithId(ctx context.Context, cancelFn func(), id int64)

func (*ContextService) CloseContext

func (cs *ContextService) CloseContext(ctx context.Context) error

func (*ContextService) CloseContextById

func (cs *ContextService) CloseContextById(id int64) error

func (*ContextService) CloseLastContext

func (cs *ContextService) CloseLastContext() error

func (*ContextService) FindContextWithId

func (cs *ContextService) FindContextWithId(id int64) *ContextHolder

func (*ContextService) Length

func (cs *ContextService) Length() int

type FileMetadata

type FileMetadata struct {
	ID         string    `json:"id"`
	FileType   FileType  `json:"fileType"`
	FileName   string    `json:"fileName"`
	MsgID      int64     `json:"msgId"`
	MsgContent string    `json:"msgContent"`
	Timestamp  time.Time `json:"timestamp"`
}

type FileService

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

func NewFileService

func NewFileService() (*FileService, error)

func (*FileService) Append

func (s *FileService) Append(fileType FileType, msgContent, originalFileName string, msgId int64, data []byte) (*FileMetadata, error)

func (*FileService) Delete

func (s *FileService) Delete(id string) error

func (*FileService) Get

func (s *FileService) Get(id string) (vfs.File, *FileMetadata, error)

func (*FileService) GetByMsgId

func (s *FileService) GetByMsgId(id int64, fileType FileType) (vfs.File, *FileMetadata, error)

func (*FileService) List

func (s *FileService) List(fileType FileType) ([]FileMetadata, error)

func (*FileService) SaveToOS

func (s *FileService) SaveToOS(id string, destinationPath string) error

type FileType

type FileType string
const (
	Audio FileType = "audio"
	Image FileType = "image"
	Text  FileType = "text"
)

type IContextService

type IContextService interface {
	AddContext(ctx context.Context, cancelFn func())
	AddContextWithId(ctx context.Context, cancelFn func(), id int64)
	CloseContext(ctx context.Context) error
	FindContextWithId(id int64) *ContextHolder
	CloseContextById(id int64) error
	Length() int
}

type IFileService

type IFileService interface {
	Append(fileType FileType, msgContent string, originalFileName string, msgId int64, data []byte) (*FileMetadata, error)
	Delete(id string) error
	Get(id string) (vfs.File, *FileMetadata, error)
	GetByMsgId(id int64, fileType FileType) (vfs.File, *FileMetadata, error)
	List(fileType FileType) ([]FileMetadata, error)
	SaveToOS(id string, destinationPath string) error
}

type Meta

type Meta struct {
	ApiType, Model, Agent string
}

type PromptConfig

type PromptConfig struct {
	ChatMessages   *ChatMessages
	PreviousPrompt string
	UserPrompt     string
	UpdateChan     chan *ChatMessage
	Contexts       IContextService
	Files          IFileService
}

type ROLES

type ROLES string

type TYPE

type TYPE string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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