Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
chyroc committed Jan 4, 2024
2 parents b4dec9f + 1bea996 commit a0ce29d
Show file tree
Hide file tree
Showing 100 changed files with 1,732 additions and 254 deletions.
Empty file removed agents/executor
Empty file.
10 changes: 9 additions & 1 deletion agents/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,18 @@ func (e Executor) Call(ctx context.Context, inputValues map[string]any, _ ...cha
}
}

if e.CallbacksHandler != nil {
e.CallbacksHandler.HandleAgentFinish(ctx, schema.AgentFinish{
ReturnValues: map[string]any{"output": ErrNotFinished.Error()},
})
}
return e.getReturn(
&schema.AgentFinish{ReturnValues: make(map[string]any)},
steps,
), ErrNotFinished
}

func (e Executor) doIteration(
func (e Executor) doIteration( // nolint
ctx context.Context,
steps []schema.AgentStep,
nameToTool map[string]tools.Tool,
Expand All @@ -97,6 +102,9 @@ func (e Executor) doIteration(
}

if finish != nil {
if e.CallbacksHandler != nil {
e.CallbacksHandler.HandleAgentFinish(ctx, *finish)
}
return steps, e.getReturn(finish, steps), nil
}

Expand Down
1 change: 1 addition & 0 deletions callbacks/callbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type Handler interface {
HandleToolEnd(ctx context.Context, output string)
HandleToolError(ctx context.Context, err error)
HandleAgentAction(ctx context.Context, action schema.AgentAction)
HandleAgentFinish(ctx context.Context, finish schema.AgentFinish)
HandleRetrieverStart(ctx context.Context, query string)
HandleRetrieverEnd(ctx context.Context, query string, documents []schema.Document)
HandleStreamingFunc(ctx context.Context, chunk []byte)
Expand Down
6 changes: 6 additions & 0 deletions callbacks/combining.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ func (l CombiningHandler) HandleAgentAction(ctx context.Context, action schema.A
}
}

func (l CombiningHandler) HandleAgentFinish(ctx context.Context, finish schema.AgentFinish) {
for _, handle := range l.Callbacks {
handle.HandleAgentFinish(ctx, finish)
}
}

func (l CombiningHandler) HandleRetrieverStart(ctx context.Context, query string) {
for _, handle := range l.Callbacks {
handle.HandleRetrieverStart(ctx, query)
Expand Down
4 changes: 4 additions & 0 deletions callbacks/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ func (l LogHandler) HandleAgentAction(_ context.Context, action schema.AgentActi
fmt.Println("Agent selected action:", formatAgentAction(action))
}

func (l LogHandler) HandleAgentFinish(_ context.Context, finish schema.AgentFinish) {
fmt.Printf("Agent finish: %v \n", finish)
}

func (l LogHandler) HandleRetrieverStart(_ context.Context, query string) {
fmt.Println("Entering retriever with query:", removeNewLines(query))
}
Expand Down
1 change: 1 addition & 0 deletions callbacks/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func (SimpleHandler) HandleToolStart(context.Context, string)
func (SimpleHandler) HandleToolEnd(context.Context, string) {}
func (SimpleHandler) HandleToolError(context.Context, error) {}
func (SimpleHandler) HandleAgentAction(context.Context, schema.AgentAction) {}
func (SimpleHandler) HandleAgentFinish(context.Context, schema.AgentFinish) {}
func (SimpleHandler) HandleRetrieverStart(context.Context, string) {}
func (SimpleHandler) HandleRetrieverEnd(context.Context, string, []schema.Document) {}
func (SimpleHandler) HandleStreamingFunc(context.Context, []byte) {}
4 changes: 0 additions & 4 deletions chains/chains_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ func (spv stringPromptValue) Messages() []schema.ChatMessage {
return nil
}

func (l *testLanguageModel) GetNumTokens(_ string) int {
return -1
}

func (l *testLanguageModel) Call(_ context.Context, prompt string, _ ...llms.CallOption) (string, error) {
l.recordedPrompt = []schema.PromptValue{
stringPromptValue{s: prompt},
Expand Down
2 changes: 1 addition & 1 deletion examples/anthropic-completion-example/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.21

toolchain go1.21.4

require github.com/tmc/langchaingo v0.1.2
require github.com/tmc/langchaingo v0.1.3

require (
github.com/dlclark/regexp2 v1.8.1 // indirect
Expand Down
4 changes: 2 additions & 2 deletions examples/anthropic-completion-example/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/tmc/langchaingo v0.1.2 h1:iyk/BSiA7rQ3jUk0oINs3RqjSDyv0UkMs3YnUXaHBFM=
github.com/tmc/langchaingo v0.1.2/go.mod h1:6gFzplGo6st/1G5y/Yv/7kGMI8NmFsCFImU24hqZ5Tw=
github.com/tmc/langchaingo v0.1.3 h1:QIzyhr5N2ZkE1z/9QJUBD+t9JndMrnXwIFw2I7FYtA8=
github.com/tmc/langchaingo v0.1.3/go.mod h1:Rm4WfxQR0WQLtcz5+zMGutlfgMuNY5QKZt8k3Y42gz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
4 changes: 2 additions & 2 deletions examples/chroma-vectorstore-example/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ go 1.21
toolchain go1.21.4

require (
github.com/amikos-tech/chroma-go v0.0.0-20230901221218-d0087270239e
github.com/amikos-tech/chroma-go v0.0.0-20231228181736-e8f5e927093e
github.com/google/uuid v1.3.1
github.com/tmc/langchaingo v0.1.3-0.20231229003435-adeea7c73769
github.com/tmc/langchaingo v0.1.3
)

require (
Expand Down
30 changes: 24 additions & 6 deletions examples/chroma-vectorstore-example/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ github.com/Masterminds/semver/v3 v3.2.0 h1:3MEsd0SM6jqZojhjLWWeBY+Kcjy9i6MQAeY7Y
github.com/Masterminds/semver/v3 v3.2.0/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ=
github.com/Masterminds/sprig/v3 v3.2.3 h1:eL2fZNezLomi0uOLqjQoN6BfsDD+fyLtgbJMAj9n6YA=
github.com/Masterminds/sprig/v3 v3.2.3/go.mod h1:rXcFaZ2zZbLRJv/xSysmlgIM1u11eBaRMhvYXJNkGuM=
github.com/amikos-tech/chroma-go v0.0.0-20230901221218-d0087270239e h1:RYla80qSHCeP8WL9Hyjfuk9n/KkDcYwzfaYbfc4cqRQ=
github.com/amikos-tech/chroma-go v0.0.0-20230901221218-d0087270239e/go.mod h1:bPy9xmWK59Ix/nteEqIvPfAI0L07di+uZMb+RiYbles=
github.com/amikos-tech/chroma-go v0.0.0-20231228181736-e8f5e927093e h1:68YtjXFDWgquXICyGFa0gZ+nqZbs4OURutAyUjH1mYs=
github.com/amikos-tech/chroma-go v0.0.0-20231228181736-e8f5e927093e/go.mod h1:uJwgGN4rBUTMI88Rn68Xia+cTRogOo0/elcPvJYFtBU=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dlclark/regexp2 v1.8.1 h1:6Lcdwya6GjPUNsBct8Lg/yRPwMhABj269AAzdGSiR+0=
github.com/dlclark/regexp2 v1.8.1/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE=
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
Expand All @@ -36,30 +38,46 @@ github.com/googleapis/enterprise-certificate-proxy v0.2.3 h1:yk9/cqRKtT9wXZSsRH9
github.com/googleapis/enterprise-certificate-proxy v0.2.3/go.mod h1:AwSRAtLfXpU5Nm3pW+v7rGDHp09LsPtGY9MduiEsR9k=
github.com/googleapis/gax-go/v2 v2.11.0 h1:9V9PWXEsWnPpQhu/PeQIkS4eGzMlTLGgt80cUUI8Ki4=
github.com/googleapis/gax-go/v2 v2.11.0/go.mod h1:DxmR61SGKkGLa2xigwuZIQpkCI2S5iydzRfb3peWZJI=
github.com/goph/emperror v0.17.2 h1:yLapQcmEsO0ipe9p5TaN22djm3OFV/TfM/fcYP0/J18=
github.com/goph/emperror v0.17.2/go.mod h1:+ZbQ+fUNO/6FNiUo0ujtMjhgad9Xa6fQL9KhH4LNHic=
github.com/huandu/xstrings v1.3.3 h1:/Gcsuc1x8JVbJ9/rlye4xZnVAbEkGauT8lbebqcQws4=
github.com/huandu/xstrings v1.3.3/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/imdario/mergo v0.3.11 h1:3tnifQM4i+fbajXKBHXWEH+KvNHqojZ778UH75j3bGA=
github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/mitchellh/copystructure v1.0.0 h1:Laisrj+bAB6b/yJwB5Bt3ITZhGJdqmxquMKeZ+mmkFQ=
github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw=
github.com/mitchellh/reflectwalk v1.0.0 h1:9D+8oIskB4VJBN5SFlmc27fSlIBZaov1Wpk/IfikLNY=
github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/nikolalohinski/gonja v1.5.3 h1:GsA+EEaZDZPGJ8JtpeGN78jidhOlxeJROpqMT9fTj9c=
github.com/nikolalohinski/gonja v1.5.3/go.mod h1:RmjwxNiXAEqcq1HeK5SSMmqFJvKOfTfXhkJv6YBtPa4=
github.com/pelletier/go-toml/v2 v2.0.9 h1:uH2qQXheeefCCkuBBSLi7jCiSmj3VRh2+Goq2N7Xxu0=
github.com/pelletier/go-toml/v2 v2.0.9/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkoukk/tiktoken-go v0.1.2 h1:u7PCSBiWJ3nJYoTGShyM9iHXz4dNyYkurwwp+GHtyHY=
github.com/pkoukk/tiktoken-go v0.1.2/go.mod h1:boMWvk9pQCOTx11pgu0DrIdrAKgQzzJKUP6vLXaz7Rw=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ=
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng=
github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/tmc/langchaingo v0.1.2 h1:iyk/BSiA7rQ3jUk0oINs3RqjSDyv0UkMs3YnUXaHBFM=
github.com/tmc/langchaingo v0.1.2/go.mod h1:6gFzplGo6st/1G5y/Yv/7kGMI8NmFsCFImU24hqZ5Tw=
github.com/tmc/langchaingo v0.1.3-0.20231229003435-adeea7c73769 h1:6Ooy1tU0Zq+3rQawfUa8hVJcDIDvfSc5m0I+Uza4eoY=
github.com/tmc/langchaingo v0.1.3-0.20231229003435-adeea7c73769/go.mod h1:8UNdSywnJCliFHfIWGbAGCYQ6khvnwMM2sSNV3JOZ3I=
github.com/tmc/langchaingo v0.1.3 h1:QIzyhr5N2ZkE1z/9QJUBD+t9JndMrnXwIFw2I7FYtA8=
github.com/tmc/langchaingo v0.1.3/go.mod h1:Rm4WfxQR0WQLtcz5+zMGutlfgMuNY5QKZt8k3Y42gz0=
github.com/yargevad/filepathx v1.0.0 h1:SYcT+N3tYGi+NvazubCNlvgIPbzAk7i7y2dwg3I5FYc=
github.com/yargevad/filepathx v1.0.0/go.mod h1:BprfX/gpYNJHJfc35GjRRpVcwWXS89gGulUIU5tK3tA=
go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
go.starlark.net v0.0.0-20230302034142-4b1e35fe2254 h1:Ss6D3hLXTM0KobyBYEAygXzFfGcjnmfEJOBgSbemCtg=
Expand Down
5 changes: 3 additions & 2 deletions examples/cohere-llm-example/cohere_completion_example.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"log"

"github.com/tmc/langchaingo/llms"
"github.com/tmc/langchaingo/llms/cohere"
)

Expand All @@ -22,8 +23,8 @@ func main() {

fmt.Println(completion)

inputToken := llm.GetNumTokens(input)
outputToken := llm.GetNumTokens(completion)
inputToken := llms.CountTokens("", input)
outputToken := llms.CountTokens("", completion)

fmt.Printf("%v/%v\n", inputToken, outputToken)
}
2 changes: 1 addition & 1 deletion examples/cohere-llm-example/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.21

toolchain go1.21.4

require github.com/tmc/langchaingo v0.1.2
require github.com/tmc/langchaingo v0.1.3

require (
github.com/cohere-ai/tokenizer v1.1.2 // indirect
Expand Down
4 changes: 2 additions & 2 deletions examples/cohere-llm-example/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/tmc/langchaingo v0.1.2 h1:iyk/BSiA7rQ3jUk0oINs3RqjSDyv0UkMs3YnUXaHBFM=
github.com/tmc/langchaingo v0.1.2/go.mod h1:6gFzplGo6st/1G5y/Yv/7kGMI8NmFsCFImU24hqZ5Tw=
github.com/tmc/langchaingo v0.1.3 h1:QIzyhr5N2ZkE1z/9QJUBD+t9JndMrnXwIFw2I7FYtA8=
github.com/tmc/langchaingo v0.1.3/go.mod h1:Rm4WfxQR0WQLtcz5+zMGutlfgMuNY5QKZt8k3Y42gz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
13 changes: 12 additions & 1 deletion examples/document-qa-example/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,34 @@ go 1.21

toolchain go1.21.4

require github.com/tmc/langchaingo v0.1.2
require github.com/tmc/langchaingo v0.1.3

require (
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.2.0 // indirect
github.com/Masterminds/sprig/v3 v3.2.3 // indirect
github.com/dlclark/regexp2 v1.8.1 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/goph/emperror v0.17.2 // indirect
github.com/huandu/xstrings v1.3.3 // indirect
github.com/imdario/mergo v0.3.11 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mitchellh/copystructure v1.0.0 // indirect
github.com/mitchellh/reflectwalk v1.0.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/nikolalohinski/gonja v1.5.3 // indirect
github.com/pelletier/go-toml/v2 v2.0.9 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pkoukk/tiktoken-go v0.1.2 // indirect
github.com/shopspring/decimal v1.2.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/spf13/cast v1.3.1 // indirect
github.com/yargevad/filepathx v1.0.0 // indirect
go.starlark.net v0.0.0-20230302034142-4b1e35fe2254 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1 // indirect
golang.org/x/sys v0.15.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit a0ce29d

Please sign in to comment.