-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
40 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,39 @@ | ||
package nmemory | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/tmc/langchaingo/llms" | ||
"github.com/tmc/langchaingo/memory" | ||
) | ||
|
||
type ChatHistory struct { | ||
history *memory.ChatMessageHistory | ||
} | ||
|
||
// NewChatHistory creates a new ChatHistory instance | ||
func NewChatHistory() *ChatHistory { | ||
return &ChatHistory{ | ||
history: memory.NewChatMessageHistory(), | ||
} | ||
} | ||
|
||
// AddUserMessage adds a user message to the chat history | ||
func (ch *ChatHistory) AddUserMessage(ctx context.Context, content string) error { | ||
return ch.history.AddUserMessage(ctx, content) | ||
} | ||
|
||
// AddAIMessage adds an AI message to the chat history | ||
func (ch *ChatHistory) AddAIMessage(ctx context.Context, content string) error { | ||
return ch.history.AddAIMessage(ctx, content) | ||
} | ||
|
||
// GetMessages returns all messages in the chat history | ||
func (ch *ChatHistory) GetMessages(ctx context.Context) ([]llms.ChatMessage, error) { | ||
return ch.history.Messages(ctx) | ||
} | ||
|
||
// Clear clears all messages from the chat history | ||
func (ch *ChatHistory) Clear(ctx context.Context) error { | ||
return ch.history.Clear(ctx) | ||
} |