Skip to content

Commit

Permalink
fix: unmarshal binary contents as string cause the agent impl sucks ass
Browse files Browse the repository at this point in the history
  • Loading branch information
ntauth committed Jul 1, 2024
1 parent 6b634c1 commit 98c2c99
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions chains/llm.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package chains

import (
"context"
"encoding/json"
"fmt"

"github.com/tmc/langchaingo/callbacks"
Expand Down Expand Up @@ -64,10 +65,15 @@ func (c LLMChain) Call(ctx context.Context, values map[string]any, options ...Ch
Text: promptValue.String(),
}},
})
if binaryContents_, hasBinaryContents := values[llms.BinaryContentsDummyKey]; hasBinaryContents {
binaryContents, ok := binaryContents_.([]llms.BinaryContent)
if binaryContentsStr_, hasBinaryContents := values[llms.BinaryContentsDummyKey]; hasBinaryContents {

Check warning on line 68 in chains/llm.go

View workflow job for this annotation

GitHub Actions / lint

var-naming: don't use underscores in Go names; var binaryContentsStr_ should be binaryContentsStr (revive)
binaryContentsStr, ok := binaryContentsStr_.(string)
if !ok {
return nil, fmt.Errorf("invalid binary contents, expected %T, got %T", []llms.BinaryContent{}, binaryContents_)
return nil, fmt.Errorf("invalid binary contents, expected %T, got %T", "", binaryContentsStr_)
}

var binaryContents []llms.BinaryContent
if err := json.Unmarshal([]byte(binaryContentsStr), &binaryContents); err != nil {
return nil, err
}

var contentParts []llms.ContentPart
Expand Down

0 comments on commit 98c2c99

Please sign in to comment.