Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
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 (*Buffer) LoadMemoryVariables ¶
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 ¶
MemoryVariables gets the input key the buffer memory class will load dynamically.
func (*Buffer) SaveContext ¶
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.