memory

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidInputValues = errors.New("invalid input values")

ErrInvalidInputValues is returned when input values given to a memory in save context are invalid.

Functions

This section is empty.

Types

type Buffer

type Buffer struct {
	ChatHistory *ChatMessageHistory

	ReturnMessages bool
	InputKey       string
	OutputKey      string
	HumanPrefix    string
	AIPrefix       string
	MemoryKey      string
	Depth          int
}

Buffer is a simple form of memory that remembers previous conversational back and forth directly.

func NewBuffer

func NewBuffer() *Buffer

NewBuffer is a function for crating a new buffer memory.

func (*Buffer) Clear

func (m *Buffer) Clear() error

Clear sets the chat messages to a new and empty chat message history.

func (*Buffer) LoadMemoryVariables

func (m *Buffer) LoadMemoryVariables(map[string]any) (map[string]any, error)

LoadMemoryVariables returns the previous chat messages stored in memory. Previous chat messages are returned in a map with the key specified in the MemoryKey field. This key defaults to "history". If ReturnMessages is set to true the output is a slice of schema.ChatMessage. Otherwise, the output is a buffer string of the chat messages.

func (*Buffer) MemoryVariables

func (m *Buffer) MemoryVariables() []string

MemoryVariables gets the input key the buffer memory class will load dynamically.

func (*Buffer) SaveContext

func (m *Buffer) SaveContext(inputValues, outputValues map[string]any) error

SaveContext uses the input values to the llm to save a user message, and the output values of the llm to save an AI message. If the input or output key is not set, the input values or output values must contain only one key such that the function can know what string to add as a user and AI message. On the other hand, if the output key or input key is set, the input key must be a key in the input values and the output key must be a key in the output values. The values in the input and output values used to save a user and AI message must be strings.

type ChatMessageHistory

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

ChatMessageHistory is a struct that stores chat messages

func NewChatMessageHistory

func NewChatMessageHistory(options ...NewChatMessageOption) *ChatMessageHistory

NewChatMessageHistory creates a new ChatMessageHistory using chat message options.

func (*ChatMessageHistory) AddAIMessage

func (h *ChatMessageHistory) AddAIMessage(text string)

AddAIMessage adds an AIMessage to the chat message history.

func (*ChatMessageHistory) AddUserMessage

func (h *ChatMessageHistory) AddUserMessage(text string)

AddUserMessage adds an user to the chat message history.

func (*ChatMessageHistory) Clear

func (h *ChatMessageHistory) Clear()

func (*ChatMessageHistory) Keep

func (h *ChatMessageHistory) Keep(depth int)

Keep keeps interactions in memory. an interaction is two slice length

func (*ChatMessageHistory) Messages

func (h *ChatMessageHistory) Messages() []schema.ChatMessage

Messages returns all messages stored.

type NewChatMessageOption

type NewChatMessageOption func(m *ChatMessageHistory)

NewChatMessageOption is a function for creating new chat message history with other than the default values.

func WithPreviousMessages

func WithPreviousMessages(previousMessages []schema.ChatMessage) NewChatMessageOption

WithPreviousMessages is an option for NewChatMessageHistory for adding previous messages to the history.

Jump to

Keyboard shortcuts

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