context

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2024 License: MIT Imports: 14 Imported by: 1

Documentation

Index

Constants

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

Variables

This section is empty.

Functions

func ConvertMessagesToOpenAIMessages

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

func RunIntoWriter added in v0.2.24

func RunIntoWriter(
	ctx context2.Context,
	c GeppettoRunnable,
	manager *Manager,
	w io.Writer,
) error

func RunToString added in v0.2.24

func RunToString(
	ctx context2.Context,
	c GeppettoRunnable,
	manager *Manager,
) (string, error)

Types

type GeppettoRunnable added in v0.2.24

type GeppettoRunnable interface {
	RunWithManager(ctx context2.Context, manager *Manager) (steps.StepResult[string], error)
}

type Manager

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

func CreateManager added in v0.2.24

func CreateManager(
	systemPrompt string,
	prompt string,
	messages []*Message,
	params interface{},
	options ...ManagerOption,
) (*Manager, error)

CreateManager creates a new Context Manager. It is used by the code generator to initialize a conversation by passing a custom glazed struct for params.

The systemPrompt and prompt templates are rendered using the params. Messages are also rendered using the params before being added to the manager.

ManagerOptions can be passed to further customize the manager on creation.

func NewManager

func NewManager(options ...ManagerOption) *Manager

func RunToContextManager added in v0.2.24

func RunToContextManager(
	ctx context2.Context,
	c GeppettoRunnable,
	manager *Manager,
) (*Manager, error)

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) PrependMessages added in v0.2.24

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

func (*Manager) SaveToFile added in v0.2.24

func (c *Manager) SaveToFile(s string) error

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 WithAddMessages added in v0.2.24

func WithAddMessages(messages ...*Message) ManagerOption

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"`

	// additional metadata for the message
	Metadata map[string]interface{} `json:"metadata,omitempty" yaml:"metadata,omitempty"`
}

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