From 98c2c99a77f033f5281f55c9052c75f196991792 Mon Sep 17 00:00:00 2001 From: ntauth Date: Mon, 1 Jul 2024 16:46:04 +0200 Subject: [PATCH] fix: unmarshal binary contents as string cause the agent impl sucks ass --- chains/llm.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/chains/llm.go b/chains/llm.go index 971cd0c02..5e456211a 100644 --- a/chains/llm.go +++ b/chains/llm.go @@ -2,6 +2,7 @@ package chains import ( "context" + "encoding/json" "fmt" "github.com/tmc/langchaingo/callbacks" @@ -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 { + 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