langchaingo
langchaingo copied to clipboard
Anthropic does not handle null content elegantly (panics)
If attempts to anthropic fail or return no content, the generateMessagesContent function will die. This function should check result.Content to see if its nil, if it is an error should be returned an the request should be retried.
Crash:
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x8 pc=0x1034766c8]
goroutine 10 [running]:
github.com/tmc/langchaingo/llms/anthropic.generateMessagesContent({0x1039656f8, 0x103df40c0}, 0x1400031a9f0, {0x14000402d50?, 0x140003d5308?, 0x1032eacec?}, 0x1400040e1e0)
/Users/r/go/pkg/mod/github.com/tmc/[email protected]/llms/anthropic/anthropicllm.go:155 +0x248
github.com/tmc/langchaingo/llms/anthropic.(*LLM).GenerateContent(0x1400031a9f0, {0x1039656f8, 0x103df40c0}, {0x14000402d50, 0x1, 0x1}, {0x140002fe5a0, 0x2, 0x140002e3000?})
/Users/r/go/pkg/mod/github.com/tmc/[email protected]/llms/anthropic/anthropicllm.go:89 +0xe8
github.com/tmc/langchaingo/llms.GenerateFromSinglePrompt({0x1039656f8, 0x103df40c0}, {0x103962350, 0x1400031a9f0}, {0x1400046e000, 0x1554}, {0x140002fe5a0, 0x2, 0x2})
/Users/r/go/pkg/mod/github.com/tmc/[email protected]/llms/llms.go:41 +0x148
github.com/tmc/langchaingo/chains.LLMChain.Call({{0x103962300, 0x140000201e0}, {0x103962350, 0x1400031a9f0}, {0x1039665a0, 0x103df40c0}, {0x103969b78, 0x140002fe240}, {0x1039657a0, 0x103df40c0}, ...}, ...)
/Users/r/go/pkg/mod/github.com/tmc/[email protected]/chains/llm.go:59 +0xc8
github.com/tmc/langchaingo/chains.callChain({0x1039656f8, 0x103df40c0}, {0x103965768, 0x140001143c0}, 0x140004027b0, {0x140002fe3e0, 0x2, 0x2})
/Users/r/go/pkg/mod/github.com/tmc/[email protected]/chains/chains.go:79 +0x74
github.com/tmc/langchaingo/chains.Call({0x1039656f8, 0x103df40c0}, {0x103965768, 0x140001143c0}, 0x14000402780, {0x140002fe3e0, 0x2, 0x2})
/Users/r/go/pkg/mod/github.com/tmc/[email protected]/chains/chains.go:50 +0x268
github.com/tmc/langchaingo/chains.Predict({0x1039656f8?, 0x103df40c0?}, {0x103965768, 0x140001143c0}, 0x104113458?, {0x140002fe3e0?, 0x10?, 0x10?})
/Users/r/go/pkg/mod/github.com/tmc/[email protected]/chains/chains.go:136 +0x30
github.com/tmc/langchaingo/agents.(*ConversationalAgent).Plan(0x14000020230, {0x1039656f8, 0x103df40c0}, {0x103df40c0, 0x0, 0x1030fe508?}, 0x14000402720)
/Users/r/go/pkg/mod/github.com/tmc/[email protected]/agents/conversational.go:83 +0x320
github.com/tmc/langchaingo/agents.(*Executor).doIteration(0x14000020280, {0x1039656f8, 0x103df40c0}, {0x103df40c0, 0x0, 0x0}, 0x14000402750, 0x5?)
/Users/r/go/pkg/mod/github.com/tmc/[email protected]/agents/executor.go:83 +0x54
github.com/tmc/langchaingo/agents.(*Executor).Call(0x14000020280, {0x1039656f8, 0x103df40c0}, 0x103910a60?, {0x1038b4d01?, 0x140004026f0?, 0x140004026f0?})
/Users/r/go/pkg/mod/github.com/tmc/[email protected]/agents/executor.go:60 +0xd0
github.com/tmc/langchaingo/chains.callChain({0x1039656f8, 0x103df40c0}, {0x1039656c0, 0x14000020280}, 0x140004026c0, {0x0, 0x0, 0x0})
/Users/r/go/pkg/mod/github.com/tmc/[email protected]/chains/chains.go:79 +0x74
github.com/tmc/langchaingo/chains.Call({0x1039656f8, 0x103df40c0}, {0x1039656c0, 0x14000020280}, 0x14000402690, {0x0, 0x0, 0x0})
/Users/r/go/pkg/mod/github.com/tmc/[email protected]/chains/chains.go:50 +0x268
github.com/tmc/langchaingo/chains.Run({0x1039656f8, 0x103df40c0}, {0x1039656c0, 0x14000020280}, {0x103883be0, 0x140002fe370}, {0x0, 0x0, 0x0})
/Users/r/go/pkg/mod/github.com/tmc/[email protected]/chains/chains.go:121 +0x21c
#1012 has fixed this.