Skip to content

Commit

Permalink
feature-adding-max-token-size-memory | logic update
Browse files Browse the repository at this point in the history
  • Loading branch information
zivkovicn committed Jul 24, 2023
1 parent bf100ce commit c948011
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
13 changes: 4 additions & 9 deletions memory/token_buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,10 @@ func (tb *TokenBuffer) Clear() error {
}

func (tb *TokenBuffer) getNumTokensFromMessages() (int, error) {
sum := 0
for _, message := range tb.ChatHistory.Messages() {
bufferString, err := schema.GetBufferString([]schema.ChatMessage{message}, tb.Buffer.HumanPrefix, tb.Buffer.AIPrefix)
if err != nil {
return 0, err
}

sum += tb.LLM.GetNumTokens(bufferString)
bufferString, err := schema.GetBufferString(tb.ChatHistory.Messages(), tb.Buffer.HumanPrefix, tb.Buffer.AIPrefix)
if err != nil {
return 0, err
}

return sum, nil
return tb.LLM.GetNumTokens(bufferString), nil
}
15 changes: 11 additions & 4 deletions outputparser/simple.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package outputparser

import "github.com/tmc/langchaingo/schema"
import (
"strings"

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

// Simple is an output parser that does nothing.
type Simple struct{}
Expand All @@ -9,9 +13,12 @@ func NewSimple() Simple { return Simple{} }

var _ schema.OutputParser[any] = Simple{}

func (p Simple) GetFormatInstructions() string { return "" }
func (p Simple) Parse(text string) (any, error) { return text, nil }
func (p Simple) GetFormatInstructions() string { return "" }
func (p Simple) Parse(text string) (any, error) {
return strings.TrimSpace(text), nil
}

func (p Simple) ParseWithPrompt(text string, _ schema.PromptValue) (any, error) {
return text, nil
return strings.TrimSpace(text), nil
}
func (p Simple) Type() string { return "simple_parser" }

0 comments on commit c948011

Please sign in to comment.