conversation

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

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 NewBuffer

func NewBuffer(options ...Option) *Buffer

NewBuffer is a function for crating a new buffer memory.

func (*Buffer) Clear

func (m *Buffer) Clear(ctx context.Context) error

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

func (*Buffer) LoadVariables

func (m *Buffer) LoadVariables(ctx context.Context, _ map[string]any) (map[string]any, error)

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) MemoryKey

func (m *Buffer) MemoryKey(context.Context) string

func (*Buffer) SaveContext

func (m *Buffer) SaveContext(ctx context.Context, in map[string]any, out 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.

func (*Buffer) Variables

func (m *Buffer) Variables(context.Context) []string

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

type Option

type Option func(b *Buffer)

Option is a function for creating new buffer with other than the default values.

func WithAIPrefix

func WithAIPrefix(aiPrefix string) Option

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

func WithHumanPrefix(humanPrefix string) Option

WithHumanPrefix is an option for specifying the human prefix.

func WithInputKey

func WithInputKey(inputKey string) Option

WithInputKey is an option for specifying the input key.

func WithMemoryKey

func WithMemoryKey(key string) Option

WithMemoryKey is an option for specifying the memory key.

func WithOutputKey

func WithOutputKey(outputKey string) Option

WithOutputKey is an option for specifying the output key.

func WithReturnMessages

func WithReturnMessages(returnMessages bool) Option

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.

func (*WindowBuffer) Variables

func (wb *WindowBuffer) Variables(ctx context.Context) []string

Variables uses ConversationBuffer method for memory variables.

Jump to

Keyboard shortcuts

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