Documentation
¶
Index ¶
- type Buffer
- func (m *Buffer) Clear(ctx context.Context) error
- func (m *Buffer) LoadVariables(ctx context.Context, _ map[string]any) (map[string]any, error)
- func (m *Buffer) MemoryKey(context.Context) string
- func (m *Buffer) SaveContext(ctx context.Context, in map[string]any, out map[string]any) error
- func (m *Buffer) Variables(context.Context) []string
- type Option
- func WithAIPrefix(aiPrefix string) Option
- func WithChatHistory(chatHistory llm.ChatMessageHistory) Option
- func WithHumanPrefix(humanPrefix string) Option
- func WithInputKey(inputKey string) Option
- func WithMemoryKey(key string) Option
- func WithOutputKey(outputKey string) Option
- func WithReturnMessages(returnMessages bool) Option
- type WindowBuffer
- func (wb *WindowBuffer) Clear(ctx context.Context) error
- func (wb *WindowBuffer) LoadVariables(ctx context.Context, _ map[string]any) (map[string]any, error)
- func (wb *WindowBuffer) SaveContext(ctx context.Context, inputValues map[string]any, outputValues map[string]any) error
- func (wb *WindowBuffer) Variables(ctx context.Context) []string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer is a simple form of memory that remembers previous conversational back and forth directly.
func (*Buffer) LoadVariables ¶
LoadVariables 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 llms.ChatMessage. Otherwise, the output is a buffer string of the chat messages.
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 Option ¶
type Option func(b *Buffer)
Option is a function for creating new buffer with other than the default values.
func WithAIPrefix ¶
WithAIPrefix is an option for specifying the AI prefix.
func WithChatHistory ¶
func WithChatHistory(chatHistory llm.ChatMessageHistory) Option
WithChatHistory is an option for providing the chat history store.
func WithHumanPrefix ¶
WithHumanPrefix is an option for specifying the human prefix.
func WithInputKey ¶
WithInputKey is an option for specifying the input key.
func WithMemoryKey ¶
WithMemoryKey is an option for specifying the memory key.
func WithOutputKey ¶
WithOutputKey is an option for specifying the output key.
func WithReturnMessages ¶
WithReturnMessages is an option for specifying should it return messages.
type WindowBuffer ¶
type WindowBuffer struct { Buffer // contains filtered or unexported fields }
WindowBuffer for storing conversation memory.
func NewWindowBuffer ¶
func NewWindowBuffer(windowSize int, options ...Option) *WindowBuffer
NewWindowBuffer is a function for crating a new window buffer memory.
func (*WindowBuffer) Clear ¶
func (wb *WindowBuffer) Clear(ctx context.Context) error
Clear uses ConversationBuffer method for clearing buffer memory.
func (*WindowBuffer) LoadVariables ¶
func (wb *WindowBuffer) LoadVariables(ctx context.Context, _ map[string]any) (map[string]any, error)
LoadVariables uses ConversationBuffer method for loading memory variables.
func (*WindowBuffer) SaveContext ¶
func (wb *WindowBuffer) SaveContext(ctx context.Context, inputValues map[string]any, outputValues map[string]any) error
SaveContext uses ConversationBuffer method for saving context and prunes memory buffer if needed.