Skip to content

Commit

Permalink
chat-history-clear-method | adding context to match all other methods
Browse files Browse the repository at this point in the history
  • Loading branch information
zivkovicn committed Aug 18, 2023
1 parent fef0821 commit c1cd7f2
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 12 deletions.
3 changes: 1 addition & 2 deletions llms/openai/openaillm_option.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@ type options struct {
baseURL string
organization string
apiType APIType
httpClient openaiclient.Doer

// required when APIType is APITypeAzure or APITypeAzureAD
apiVersion string
embeddingModel string

httpClient openaiclient.Doer
}

type Option func(*options)
Expand Down
6 changes: 3 additions & 3 deletions memory/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (m *ConversationBuffer) MemoryVariables(context.Context) []string {

// 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
// "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 (m *ConversationBuffer) LoadMemoryVariables(
ctx context.Context, _ map[string]any,
Expand Down Expand Up @@ -98,8 +98,8 @@ func (m *ConversationBuffer) SaveContext(
}

// Clear sets the chat messages to a new and empty chat message history.
func (m *ConversationBuffer) Clear() error {
return m.ChatHistory.Clear()
func (m *ConversationBuffer) Clear(ctx context.Context) error {
return m.ChatHistory.Clear(ctx)
}

func (m *ConversationBuffer) GetMemoryKey(context.Context) string {
Expand Down
3 changes: 2 additions & 1 deletion memory/buffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/tmc/langchaingo/schema"
)

Expand Down Expand Up @@ -89,7 +90,7 @@ func (t testChatMessageHistory) AddMessage(context.Context, schema.ChatMessage)
return nil
}

func (t testChatMessageHistory) Clear() error {
func (t testChatMessageHistory) Clear(context.Context) error {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion memory/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (h *ChatMessageHistory) AddUserMessage(_ context.Context, text string) erro
return nil
}

func (h *ChatMessageHistory) Clear() error {
func (h *ChatMessageHistory) Clear(_ context.Context) error {
h.messages = make([]schema.ChatMessage, 0)
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion memory/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (m Simple) SaveContext(context.Context, map[string]any, map[string]any) err
return nil
}

func (m Simple) Clear() error {
func (m Simple) Clear(context.Context) error {
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions memory/token_buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ func (tb *ConversationTokenBuffer) SaveContext(
}

// Clear uses ConversationBuffer method for clearing buffer memory.
func (tb *ConversationTokenBuffer) Clear() error {
return tb.ConversationBuffer.Clear()
func (tb *ConversationTokenBuffer) Clear(ctx context.Context) error {
return tb.ConversationBuffer.Clear(ctx)
}

func (tb *ConversationTokenBuffer) getNumTokensFromMessages(ctx context.Context) (int, error) {
Expand Down
2 changes: 1 addition & 1 deletion schema/chat_message_history.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type ChatMessageHistory interface {
AddMessage(ctx context.Context, message ChatMessage) error

// Clear Remove all messages from the store.
Clear() error
Clear(ctx context.Context) error

// Messages get all messages from the store
Messages(ctx context.Context) ([]ChatMessage, error)
Expand Down
2 changes: 1 addition & 1 deletion schema/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ type Memory interface {
// SaveContext Save the context of this model run to memory.
SaveContext(ctx context.Context, inputs map[string]any, outputs map[string]any) error
// Clear memory contents.
Clear() error
Clear(ctx context.Context) error
}

0 comments on commit c1cd7f2

Please sign in to comment.