context

package
v0.2.22 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2023 License: MIT Imports: 8 Imported by: 1

Documentation

Index

Constants

View Source
const RoleAssistant = "assistant"
View Source
const RoleSystem = "system"
View Source
const RoleUser = "user"

Variables

This section is empty.

Functions

func ConvertMessagesToOpenAIMessages

func ConvertMessagesToOpenAIMessages(messages []*Message) ([]openai.ChatCompletionMessage, error)

Types

type Manager

type Manager struct {
	Messages     []*Message
	SystemPrompt string
}

func NewManager

func NewManager(options ...ManagerOption) *Manager

func (*Manager) AddMessages

func (c *Manager) AddMessages(messages ...*Message)

func (*Manager) GetMessages

func (c *Manager) GetMessages() []*Message

func (*Manager) GetMessagesWithSystemPrompt

func (c *Manager) GetMessagesWithSystemPrompt() []*Message

GetMessagesWithSystemPrompt returns all messages with the system prompt prepended

func (*Manager) GetSinglePrompt

func (c *Manager) GetSinglePrompt() string

GetSinglePrompt is a helper to use the context manager with a completion api. It just concatenates all the messages together with a prompt in front (if there are more than one message).

func (*Manager) GetSystemPrompt

func (c *Manager) GetSystemPrompt() string

func (*Manager) SetMessages

func (c *Manager) SetMessages(messages []*Message)

func (*Manager) SetSystemPrompt

func (c *Manager) SetSystemPrompt(systemPrompt string)

type ManagerOption

type ManagerOption func(*Manager)

func WithMessages

func WithMessages(messages []*Message) ManagerOption

func WithSystemPrompt

func WithSystemPrompt(systemPrompt string) ManagerOption

type Message

type Message struct {
	Text string    `json:"text" yaml:"text"`
	Time time.Time `json:"time" yaml:"time"`
	Role string    `json:"role" yaml:"role"`
}

func LoadFromFile

func LoadFromFile(filename string) ([]*Message, error)

LoadFromFile loads messages from a json file or yaml file

Jump to

Keyboard shortcuts

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