From 004c9bc52e329fb0d079f74f15017d1f4130584d Mon Sep 17 00:00:00 2001 From: FluffyKebab Date: Sat, 19 Aug 2023 21:57:03 +0200 Subject: [PATCH 01/11] add callbackHandler interface and log handler --- callbacks/callbacks.go | 19 ++++++++++++++ callbacks/log.go | 59 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 callbacks/callbacks.go create mode 100644 callbacks/log.go diff --git a/callbacks/callbacks.go b/callbacks/callbacks.go new file mode 100644 index 000000000..67879651e --- /dev/null +++ b/callbacks/callbacks.go @@ -0,0 +1,19 @@ +package callbacks + +import ( + "github.com/tmc/langchaingo/llms" + "github.com/tmc/langchaingo/schema" +) + +type CallbackHandler interface { + HandleText(text string) + HandleLLMStart(prompts []string) + HandleLLMEnd(output llms.LLMResult) + HandleChainStart(inputs map[string]any) + HandleChainEnd(outputs map[string]any) + HandleToolStart(input string) + HandleToolEnd(output string) + HandleAgentAction(action schema.AgentAction) + HandleRetrieverStart(query string) + HandleRetrieverEnd(documents []schema.Document) +} diff --git a/callbacks/log.go b/callbacks/log.go new file mode 100644 index 000000000..86946b351 --- /dev/null +++ b/callbacks/log.go @@ -0,0 +1,59 @@ +package callbacks + +import ( + "fmt" + + "github.com/tmc/langchaingo/llms" + "github.com/tmc/langchaingo/schema" +) + +// LogHandler is a callback handler that prints to the standard output. +type LogHandler struct{} + +var _ CallbackHandler = LogHandler{} + +func (l LogHandler) HandleText(text string) { + fmt.Println(text) +} + +func (l LogHandler) HandleLLMStart(prompts []string) { + fmt.Println("Entering LLM with prompts", prompts) +} + +func (l LogHandler) HandleLLMEnd(output llms.LLMResult) { + results := "" + for i := 0; i < len(output.Generations); i++ { + for j := 0; j < len(output.Generations[i]); j++ { + results += output.Generations[i][j].Text + "\n" + } + } + fmt.Println("Exiting LLM with results: \n", results) +} + +func (l LogHandler) HandleChainStart(inputs map[string]any) { + fmt.Println("Entering chain with inputs:", inputs) +} + +func (l LogHandler) HandleChainEnd(outputs map[string]any) { + fmt.Println("Exiting chain with outputs:", outputs) +} + +func (l LogHandler) HandleToolStart(input string) { + fmt.Println("Entering tool with input:", input) +} + +func (l LogHandler) HandleToolEnd(output string) { + fmt.Println("Exiting tool with output:", output) +} + +func (l LogHandler) HandleAgentAction(action schema.AgentAction) { + fmt.Println("Agent selected action:", action) +} + +func (l LogHandler) HandleRetrieverStart(query string) { + fmt.Println("Entering retriever with query:", query) +} + +func (l LogHandler) HandleRetrieverEnd(documents []schema.Document) { + fmt.Println("Exiting retirer with documents:", documents) +} From 442e5f1e7d17a02d30270b66a02d261e5436e610 Mon Sep 17 00:00:00 2001 From: FluffyKebab Date: Sat, 19 Aug 2023 22:36:45 +0200 Subject: [PATCH 02/11] add callbacks to llms --- callbacks/callbacks.go | 6 +++++- callbacks/log.go | 2 +- llms/anthropic/anthropicllm.go | 11 +++++++++- llms/cohere/coherellm.go | 12 ++++++++++- llms/huggingface/huggingfacellm.go | 18 ++++++++++++++--- llms/local/localllm.go | 32 +++++++++++++++++++++--------- llms/openai/openaillm.go | 12 ++++++++++- llms/openai/openaillm_chat.go | 21 +++++++++++++++++++- llms/vertexai/vertexai_palm_llm.go | 12 ++++++++++- 9 files changed, 107 insertions(+), 19 deletions(-) diff --git a/callbacks/callbacks.go b/callbacks/callbacks.go index 67879651e..5da9b6bab 100644 --- a/callbacks/callbacks.go +++ b/callbacks/callbacks.go @@ -5,7 +5,7 @@ import ( "github.com/tmc/langchaingo/schema" ) -type CallbackHandler interface { +type Handler interface { HandleText(text string) HandleLLMStart(prompts []string) HandleLLMEnd(output llms.LLMResult) @@ -17,3 +17,7 @@ type CallbackHandler interface { HandleRetrieverStart(query string) HandleRetrieverEnd(documents []schema.Document) } + +type HandlerHaver interface { + GetCallbackHandler() Handler +} diff --git a/callbacks/log.go b/callbacks/log.go index 86946b351..350353987 100644 --- a/callbacks/log.go +++ b/callbacks/log.go @@ -10,7 +10,7 @@ import ( // LogHandler is a callback handler that prints to the standard output. type LogHandler struct{} -var _ CallbackHandler = LogHandler{} +var _ Handler = LogHandler{} func (l LogHandler) HandleText(text string) { fmt.Println(text) diff --git a/llms/anthropic/anthropicllm.go b/llms/anthropic/anthropicllm.go index fe9bb5db2..674714357 100644 --- a/llms/anthropic/anthropicllm.go +++ b/llms/anthropic/anthropicllm.go @@ -5,6 +5,7 @@ import ( "errors" "os" + "github.com/tmc/langchaingo/callbacks" "github.com/tmc/langchaingo/llms" "github.com/tmc/langchaingo/llms/anthropic/internal/anthropicclient" "github.com/tmc/langchaingo/schema" @@ -18,7 +19,8 @@ var ( ) type LLM struct { - client *anthropicclient.Client + CallbacksHandler callbacks.Handler + client *anthropicclient.Client } var ( @@ -63,6 +65,10 @@ func (o *LLM) Call(ctx context.Context, prompt string, options ...llms.CallOptio } func (o *LLM) Generate(ctx context.Context, prompts []string, options ...llms.CallOption) ([]*llms.Generation, error) { + if o.CallbacksHandler != nil { + o.CallbacksHandler.HandleLLMStart(prompts) + } + opts := llms.CallOptions{} for _, opt := range options { opt(&opts) @@ -87,6 +93,9 @@ func (o *LLM) Generate(ctx context.Context, prompts []string, options ...llms.Ca }) } + if o.CallbacksHandler != nil { + o.CallbacksHandler.HandleLLMEnd(llms.LLMResult{Generations: [][]*llms.Generation{generations}}) + } return generations, nil } diff --git a/llms/cohere/coherellm.go b/llms/cohere/coherellm.go index 63bcf862c..3c28d0220 100644 --- a/llms/cohere/coherellm.go +++ b/llms/cohere/coherellm.go @@ -5,6 +5,7 @@ import ( "errors" "os" + "github.com/tmc/langchaingo/callbacks" "github.com/tmc/langchaingo/llms" "github.com/tmc/langchaingo/llms/cohere/internal/cohereclient" "github.com/tmc/langchaingo/schema" @@ -18,7 +19,8 @@ var ( ) type LLM struct { - client *cohereclient.Client + CallbacksHandler callbacks.Handler + client *cohereclient.Client } var ( @@ -38,6 +40,10 @@ func (o *LLM) Call(ctx context.Context, prompt string, options ...llms.CallOptio } func (o *LLM) Generate(ctx context.Context, prompts []string, options ...llms.CallOption) ([]*llms.Generation, error) { + if o.CallbacksHandler != nil { + o.CallbacksHandler.HandleLLMStart(prompts) + } + opts := llms.CallOptions{} for _, opt := range options { opt(&opts) @@ -58,6 +64,10 @@ func (o *LLM) Generate(ctx context.Context, prompts []string, options ...llms.Ca }) } + if o.CallbacksHandler != nil { + o.CallbacksHandler.HandleLLMEnd(llms.LLMResult{Generations: [][]*llms.Generation{generations}}) + } + return generations, nil } diff --git a/llms/huggingface/huggingfacellm.go b/llms/huggingface/huggingfacellm.go index f42c8b818..009968b24 100644 --- a/llms/huggingface/huggingfacellm.go +++ b/llms/huggingface/huggingfacellm.go @@ -5,6 +5,7 @@ import ( "errors" "os" + "github.com/tmc/langchaingo/callbacks" "github.com/tmc/langchaingo/llms" "github.com/tmc/langchaingo/llms/huggingface/internal/huggingfaceclient" "github.com/tmc/langchaingo/schema" @@ -17,7 +18,8 @@ var ( ) type LLM struct { - client *huggingfaceclient.Client + CallbacksHandler callbacks.Handler + client *huggingfaceclient.Client } var ( @@ -37,6 +39,10 @@ func (o *LLM) Call(ctx context.Context, prompt string, options ...llms.CallOptio } func (o *LLM) Generate(ctx context.Context, prompts []string, options ...llms.CallOption) ([]*llms.Generation, error) { + if o.CallbacksHandler != nil { + o.CallbacksHandler.HandleLLMStart(prompts) + } + opts := &llms.CallOptions{Model: defaultModel} for _, opt := range options { opt(opts) @@ -56,9 +62,15 @@ func (o *LLM) Generate(ctx context.Context, prompts []string, options ...llms.Ca if err != nil { return nil, err } - return []*llms.Generation{ + + generations := []*llms.Generation{ {Text: result.Text}, - }, nil + } + + if o.CallbacksHandler != nil { + o.CallbacksHandler.HandleLLMEnd(llms.LLMResult{Generations: [][]*llms.Generation{generations}}) + } + return generations, nil } func (o *LLM) GeneratePrompt(ctx context.Context, prompts []schema.PromptValue, options ...llms.CallOption) (llms.LLMResult, error) { //nolint:lll diff --git a/llms/local/localllm.go b/llms/local/localllm.go index 9cc9fb78b..cafcf7683 100644 --- a/llms/local/localllm.go +++ b/llms/local/localllm.go @@ -8,6 +8,7 @@ import ( "os/exec" "strings" + "github.com/tmc/langchaingo/callbacks" "github.com/tmc/langchaingo/llms" "github.com/tmc/langchaingo/llms/local/internal/localclient" "github.com/tmc/langchaingo/schema" @@ -22,7 +23,8 @@ var ( // LLM is a local LLM implementation. type LLM struct { - client *localclient.Client + CallbacksHandler callbacks.Handler + client *localclient.Client } // _ ensures that LLM implements the llms.LLM and language model interface. @@ -71,6 +73,10 @@ func (o *LLM) appendGlobalsToArgs(opts llms.CallOptions) []string { // Generate generates completions using the local LLM binary. func (o *LLM) Generate(ctx context.Context, prompts []string, options ...llms.CallOption) ([]*llms.Generation, error) { + if o.CallbacksHandler != nil { + o.CallbacksHandler.HandleLLMStart(prompts) + } + opts := &llms.CallOptions{} for _, opt := range options { opt(opts) @@ -82,15 +88,23 @@ func (o *LLM) Generate(ctx context.Context, prompts []string, options ...llms.Ca o.appendGlobalsToArgs(*opts) } - result, err := o.client.CreateCompletion(ctx, &localclient.CompletionRequest{ - Prompt: prompts[0], - }) - if err != nil { - return nil, err + generations := make([]*llms.Generation, len(prompts)) + for _, prompt := range prompts { + result, err := o.client.CreateCompletion(ctx, &localclient.CompletionRequest{ + Prompt: prompt, + }) + if err != nil { + return nil, err + } + + generations = append(generations, &llms.Generation{Text: result.Text}) } - return []*llms.Generation{ - {Text: result.Text}, - }, nil + + if o.CallbacksHandler != nil { + o.CallbacksHandler.HandleLLMEnd(llms.LLMResult{Generations: [][]*llms.Generation{generations}}) + } + + return generations, nil } func (o *LLM) GeneratePrompt( diff --git a/llms/openai/openaillm.go b/llms/openai/openaillm.go index 4316a2c7b..c522e9e6f 100644 --- a/llms/openai/openaillm.go +++ b/llms/openai/openaillm.go @@ -3,13 +3,15 @@ package openai import ( "context" + "github.com/tmc/langchaingo/callbacks" "github.com/tmc/langchaingo/llms" "github.com/tmc/langchaingo/llms/openai/internal/openaiclient" "github.com/tmc/langchaingo/schema" ) type LLM struct { - client *openaiclient.Client + CallbacksHandler callbacks.Handler + client *openaiclient.Client } var ( @@ -38,6 +40,10 @@ func (o *LLM) Call(ctx context.Context, prompt string, options ...llms.CallOptio } func (o *LLM) Generate(ctx context.Context, prompts []string, options ...llms.CallOption) ([]*llms.Generation, error) { + if o.CallbacksHandler != nil { + o.CallbacksHandler.HandleLLMStart(prompts) + } + opts := llms.CallOptions{} for _, opt := range options { opt(&opts) @@ -64,6 +70,10 @@ func (o *LLM) Generate(ctx context.Context, prompts []string, options ...llms.Ca }) } + if o.CallbacksHandler != nil { + o.CallbacksHandler.HandleLLMEnd(llms.LLMResult{Generations: [][]*llms.Generation{generations}}) + } + return generations, nil } diff --git a/llms/openai/openaillm_chat.go b/llms/openai/openaillm_chat.go index aa9529717..a498b9d0e 100644 --- a/llms/openai/openaillm_chat.go +++ b/llms/openai/openaillm_chat.go @@ -4,6 +4,7 @@ import ( "context" "reflect" + "github.com/tmc/langchaingo/callbacks" "github.com/tmc/langchaingo/llms" "github.com/tmc/langchaingo/llms/openai/internal/openaiclient" "github.com/tmc/langchaingo/schema" @@ -12,7 +13,8 @@ import ( type ChatMessage = openaiclient.ChatMessage type Chat struct { - client *openaiclient.Client + CallbacksHandler callbacks.Handler + client *openaiclient.Client } var ( @@ -42,6 +44,10 @@ func (o *Chat) Call(ctx context.Context, messages []schema.ChatMessage, options //nolint:funlen func (o *Chat) Generate(ctx context.Context, messageSets [][]schema.ChatMessage, options ...llms.CallOption) ([]*llms.Generation, error) { // nolint:lll,cyclop + if o.CallbacksHandler != nil { + o.CallbacksHandler.HandleLLMStart(getPromptsFromMessageSets(messageSets)) + } + opts := llms.CallOptions{} for _, opt := range options { opt(&opts) @@ -151,3 +157,16 @@ func (o *Chat) CreateEmbedding(ctx context.Context, inputTexts []string) ([][]fl } return embeddings, nil } + +func getPromptsFromMessageSets(messageSets [][]schema.ChatMessage) []string { + prompts := make([]string, 0, len(messageSets)) + for i := 0; i < len(messageSets); i++ { + curPrompt := "" + for j := 0; j < len(messageSets[i]); j++ { + curPrompt += messageSets[i][j].GetContent() + } + prompts = append(prompts, curPrompt) + } + + return prompts +} diff --git a/llms/vertexai/vertexai_palm_llm.go b/llms/vertexai/vertexai_palm_llm.go index e837398e2..e53700620 100644 --- a/llms/vertexai/vertexai_palm_llm.go +++ b/llms/vertexai/vertexai_palm_llm.go @@ -4,6 +4,7 @@ import ( "context" "errors" + "github.com/tmc/langchaingo/callbacks" "github.com/tmc/langchaingo/llms" "github.com/tmc/langchaingo/llms/vertexai/internal/vertexaiclient" "github.com/tmc/langchaingo/schema" @@ -17,7 +18,8 @@ var ( ) type LLM struct { - client *vertexaiclient.PaLMClient + CallbacksHandler callbacks.Handler + client *vertexaiclient.PaLMClient } var ( @@ -38,6 +40,10 @@ func (o *LLM) Call(ctx context.Context, prompt string, options ...llms.CallOptio } func (o *LLM) Generate(ctx context.Context, prompts []string, options ...llms.CallOption) ([]*llms.Generation, error) { + if o.CallbacksHandler != nil { + o.CallbacksHandler.HandleLLMStart(prompts) + } + opts := llms.CallOptions{} for _, opt := range options { opt(&opts) @@ -57,6 +63,10 @@ func (o *LLM) Generate(ctx context.Context, prompts []string, options ...llms.Ca Text: r.Text, }) } + + if o.CallbacksHandler != nil { + o.CallbacksHandler.HandleLLMEnd(llms.LLMResult{Generations: [][]*llms.Generation{generations}}) + } return generations, nil } From 5e3175bf25954d096301141eb35a27ab00fcc551 Mon Sep 17 00:00:00 2001 From: FluffyKebab Date: Sat, 19 Aug 2023 22:48:27 +0200 Subject: [PATCH 03/11] add option for callbacks when calling chain --- chains/chains.go | 17 +++++++++++++++++ chains/llm.go | 15 +++++++++++---- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/chains/chains.go b/chains/chains.go index 17dd3aff0..c2658d37f 100644 --- a/chains/chains.go +++ b/chains/chains.go @@ -5,6 +5,7 @@ import ( "fmt" "sync" + "github.com/tmc/langchaingo/callbacks" "github.com/tmc/langchaingo/schema" ) @@ -41,6 +42,11 @@ func Call(ctx context.Context, c Chain, inputValues map[string]any, options ...C fullValues[key] = value } + callbacksHandler := getChainCallbackHandler(c) + if callbacksHandler != nil { + callbacksHandler.HandleChainStart(inputValues) + } + if err := validateInputs(c, fullValues); err != nil { return nil, err } @@ -53,6 +59,10 @@ func Call(ctx context.Context, c Chain, inputValues map[string]any, options ...C return nil, err } + if callbacksHandler != nil { + callbacksHandler.HandleChainEnd(outputValues) + } + err = c.GetMemory().SaveContext(ctx, inputValues, outputValues) if err != nil { return nil, err @@ -225,3 +235,10 @@ func validateOutputs(c Chain, outputValues map[string]any) error { } return nil } + +func getChainCallbackHandler(c Chain) callbacks.Handler { + if handlerHaver, ok := c.(callbacks.HandlerHaver); ok { + return handlerHaver.GetCallbackHandler() + } + return nil +} diff --git a/chains/llm.go b/chains/llm.go index 74470e189..a82f76dd9 100644 --- a/chains/llm.go +++ b/chains/llm.go @@ -3,6 +3,7 @@ package chains import ( "context" + "github.com/tmc/langchaingo/callbacks" "github.com/tmc/langchaingo/llms" "github.com/tmc/langchaingo/memory" "github.com/tmc/langchaingo/outputparser" @@ -13,15 +14,17 @@ import ( const _llmChainDefaultOutputKey = "text" type LLMChain struct { - Prompt prompts.FormatPrompter - LLM llms.LanguageModel - Memory schema.Memory - OutputParser schema.OutputParser[any] + Prompt prompts.FormatPrompter + LLM llms.LanguageModel + Memory schema.Memory + CallbacksHandler callbacks.Handler + OutputParser schema.OutputParser[any] OutputKey string } var _ Chain = &LLMChain{} +var _ callbacks.HandlerHaver = &LLMChain{} // NewLLMChain creates a new LLMChain with an llm and a prompt. func NewLLMChain(llm llms.LanguageModel, prompt prompts.FormatPrompter) *LLMChain { @@ -69,6 +72,10 @@ func (c LLMChain) GetMemory() schema.Memory { //nolint:ireturn return c.Memory //nolint:ireturn } +func (c LLMChain) GetCallbackHandler() callbacks.Handler { //nolint:ireturn + return c.CallbacksHandler +} + // GetInputKeys returns the expected input keys. func (c LLMChain) GetInputKeys() []string { return append([]string{}, c.Prompt.GetInputVariables()...) From 03ad4b77996d43f3153634b77061bcbae0000bf6 Mon Sep 17 00:00:00 2001 From: FluffyKebab Date: Sun, 20 Aug 2023 09:40:00 +0200 Subject: [PATCH 04/11] add callbacks to tools, vectorsores and agents --- agents/executor.go | 18 +++++++++++++++--- agents/options.go | 8 ++++++++ llms/openai/openaillm_chat.go | 4 ++++ tools/calculator.go | 16 ++++++++++++++-- tools/duckduckgo/ddg.go | 12 +++++++++++- tools/serpapi/serpapi.go | 12 +++++++++++- tools/wikipedia/wikipedia.go | 10 ++++++++++ tools/zapier/zapier.go | 20 +++++++++++++++----- vectorstores/vectorstores.go | 23 +++++++++++++++++++---- 9 files changed, 107 insertions(+), 16 deletions(-) diff --git a/agents/executor.go b/agents/executor.go index f94ab5bf3..44f279fec 100644 --- a/agents/executor.go +++ b/agents/executor.go @@ -5,6 +5,7 @@ import ( "fmt" "strings" + "github.com/tmc/langchaingo/callbacks" "github.com/tmc/langchaingo/chains" "github.com/tmc/langchaingo/schema" "github.com/tmc/langchaingo/tools" @@ -14,15 +15,17 @@ const _intermediateStepsOutputKey = "intermediateSteps" // Executor is the chain responsible for running agents. type Executor struct { - Agent Agent - Tools []tools.Tool - Memory schema.Memory + Agent Agent + Tools []tools.Tool + Memory schema.Memory + CallbacksHandler callbacks.Handler MaxIterations int ReturnIntermediateSteps bool } var _ chains.Chain = Executor{} +var _ callbacks.HandlerHaver = Executor{} // NewExecutor creates a new agent executor with a agent and the tools the agent can use. func NewExecutor(agent Agent, tools []tools.Tool, opts ...CreationOption) Executor { @@ -37,6 +40,7 @@ func NewExecutor(agent Agent, tools []tools.Tool, opts ...CreationOption) Execut Memory: options.memory, MaxIterations: options.maxIterations, ReturnIntermediateSteps: options.returnIntermediateSteps, + CallbacksHandler: options.callbacksHandler, } } @@ -63,6 +67,10 @@ func (e Executor) Call(ctx context.Context, inputValues map[string]any, _ ...cha } for _, action := range actions { + if e.CallbacksHandler != nil { + e.CallbacksHandler.HandleAgentAction(action) + } + tool, ok := nameToTool[strings.ToUpper(action.Tool)] if !ok { steps = append(steps, schema.AgentStep{ @@ -110,6 +118,10 @@ func (e Executor) GetMemory() schema.Memory { //nolint:ireturn return e.Memory } +func (e Executor) GetCallbackHandler() callbacks.Handler { //nolint:ireturn + return e.CallbacksHandler +} + func inputsToString(inputValues map[string]any) (map[string]string, error) { inputs := make(map[string]string, len(inputValues)) for key, value := range inputValues { diff --git a/agents/options.go b/agents/options.go index 6ac83e4c5..12d273135 100644 --- a/agents/options.go +++ b/agents/options.go @@ -1,6 +1,7 @@ package agents import ( + "github.com/tmc/langchaingo/callbacks" "github.com/tmc/langchaingo/memory" "github.com/tmc/langchaingo/prompts" "github.com/tmc/langchaingo/schema" @@ -10,6 +11,7 @@ import ( type CreationOptions struct { prompt prompts.PromptTemplate memory schema.Memory + callbacksHandler callbacks.Handler maxIterations int returnIntermediateSteps bool outputKey string @@ -131,3 +133,9 @@ func WithMemory(m schema.Memory) CreationOption { co.memory = m } } + +func WithCallbacksHandler(handler callbacks.Handler) CreationOption { + return func(co *CreationOptions) { + co.callbacksHandler = handler + } +} diff --git a/llms/openai/openaillm_chat.go b/llms/openai/openaillm_chat.go index a498b9d0e..2858b0160 100644 --- a/llms/openai/openaillm_chat.go +++ b/llms/openai/openaillm_chat.go @@ -130,6 +130,10 @@ func (o *Chat) Generate(ctx context.Context, messageSets [][]schema.ChatMessage, }) } + if o.CallbacksHandler != nil { + o.CallbacksHandler.HandleLLMEnd(llms.LLMResult{Generations: [][]*llms.Generation{generations}}) + } + return generations, nil } diff --git a/tools/calculator.go b/tools/calculator.go index 173f13413..f3af09db9 100644 --- a/tools/calculator.go +++ b/tools/calculator.go @@ -4,12 +4,15 @@ import ( "context" "fmt" + "github.com/tmc/langchaingo/callbacks" "go.starlark.net/lib/math" "go.starlark.net/starlark" ) // Calculator is a tool that can do math. -type Calculator struct{} +type Calculator struct { + CallbacksHandler callbacks.Handler +} var _ Tool = Calculator{} @@ -28,10 +31,19 @@ func (c Calculator) Name() string { // string. If the evaluator errors the error is given in the result to give the // agent the ability to retry. func (c Calculator) Call(_ context.Context, input string) (string, error) { + if c.CallbacksHandler != nil { + c.CallbacksHandler.HandleToolStart(input) + } + v, err := starlark.Eval(&starlark.Thread{Name: "main"}, "input", input, math.Module.Members) if err != nil { return fmt.Sprintf("error from evaluator: %s", err.Error()), nil //nolint:nilerr } + result := v.String() + + if c.CallbacksHandler != nil { + c.CallbacksHandler.HandleToolEnd(result) + } - return v.String(), nil + return result, nil } diff --git a/tools/duckduckgo/ddg.go b/tools/duckduckgo/ddg.go index e8bc7b089..8d740141a 100644 --- a/tools/duckduckgo/ddg.go +++ b/tools/duckduckgo/ddg.go @@ -4,6 +4,7 @@ import ( "context" "errors" + "github.com/tmc/langchaingo/callbacks" "github.com/tmc/langchaingo/tools" "github.com/tmc/langchaingo/tools/duckduckgo/internal" ) @@ -13,7 +14,8 @@ const DefaultUserAgent = "github.com/tmc/langchaingo/tools/duckduckgo" // Tool defines a tool implementation for the DuckDuckGo Search. type Tool struct { - client *internal.Client + CallbacksHandler callbacks.Handler + client *internal.Client } var _ tools.Tool = Tool{} @@ -41,6 +43,10 @@ func (t Tool) Description() string { // Call performs the search and return the result. func (t Tool) Call(ctx context.Context, input string) (string, error) { + if t.CallbacksHandler != nil { + t.CallbacksHandler.HandleToolStart(input) + } + result, err := t.client.Search(ctx, input) if err != nil { if errors.Is(err, internal.ErrNoGoodResult) { @@ -49,5 +55,9 @@ func (t Tool) Call(ctx context.Context, input string) (string, error) { return "", err } + if t.CallbacksHandler != nil { + t.CallbacksHandler.HandleToolEnd(result) + } + return result, nil } diff --git a/tools/serpapi/serpapi.go b/tools/serpapi/serpapi.go index 160a477ad..65c24f963 100644 --- a/tools/serpapi/serpapi.go +++ b/tools/serpapi/serpapi.go @@ -6,6 +6,7 @@ import ( "os" "strings" + "github.com/tmc/langchaingo/callbacks" "github.com/tmc/langchaingo/tools" "github.com/tmc/langchaingo/tools/serpapi/internal" ) @@ -13,7 +14,8 @@ import ( var ErrMissingToken = errors.New("missing the serpapi API key, set it in the SERPAPI_API_KEY environment variable") type Tool struct { - client *internal.Client + CallbacksHandler callbacks.Handler + client *internal.Client } var _ tools.Tool = Tool{} @@ -43,6 +45,10 @@ func (t Tool) Description() string { } func (t Tool) Call(ctx context.Context, input string) (string, error) { + if t.CallbacksHandler != nil { + t.CallbacksHandler.HandleToolStart(input) + } + result, err := t.client.Search(ctx, input) if err != nil { if errors.Is(err, internal.ErrNoGoodResult) { @@ -52,5 +58,9 @@ func (t Tool) Call(ctx context.Context, input string) (string, error) { return "", err } + if t.CallbacksHandler != nil { + t.CallbacksHandler.HandleToolEnd(result) + } + return strings.Join(strings.Fields(result), " "), nil } diff --git a/tools/wikipedia/wikipedia.go b/tools/wikipedia/wikipedia.go index 4984438d9..0cebebe24 100644 --- a/tools/wikipedia/wikipedia.go +++ b/tools/wikipedia/wikipedia.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" + "github.com/tmc/langchaingo/callbacks" "github.com/tmc/langchaingo/tools" ) @@ -19,6 +20,7 @@ var ErrUnexpectedAPIResult = errors.New("unexpected result from wikipedia api") // Tool is an implementation of the tool interface that finds information using the wikipedia api. type Tool struct { + CallbacksHandler callbacks.Handler // The number of wikipedia pages to include in the result. TopK int // The number of characters to take from each page. @@ -57,6 +59,10 @@ func (t Tool) Description() string { // Call uses the wikipedia api to find the top search results for the input and returns // the first part of the documents combined. func (t Tool) Call(ctx context.Context, input string) (string, error) { + if t.CallbacksHandler != nil { + t.CallbacksHandler.HandleToolStart(input) + } + searchResult, err := search(ctx, t.TopK, input, t.LanguageCode, t.UserAgent) if err != nil { return "", err @@ -85,5 +91,9 @@ func (t Tool) Call(ctx context.Context, input string) (string, error) { result += page.Extract } + if t.CallbacksHandler != nil { + t.CallbacksHandler.HandleToolEnd(result) + } + return result, nil } diff --git a/tools/zapier/zapier.go b/tools/zapier/zapier.go index 88fcc4320..f2c06f6c7 100644 --- a/tools/zapier/zapier.go +++ b/tools/zapier/zapier.go @@ -5,6 +5,7 @@ import ( "context" "text/template" + "github.com/tmc/langchaingo/callbacks" "github.com/tmc/langchaingo/tools" "github.com/tmc/langchaingo/tools/zapier/internal" ) @@ -15,11 +16,12 @@ type description struct { } type Tool struct { - client *internal.Client - name string - description string - actionID string - params map[string]string + CallbacksHandler callbacks.Handler + client *internal.Client + name string + description string + actionID string + params map[string]string } var _ tools.Tool = Tool{} @@ -77,11 +79,19 @@ func (t Tool) Description() string { } func (t Tool) Call(ctx context.Context, input string) (string, error) { + if t.CallbacksHandler != nil { + t.CallbacksHandler.HandleToolStart(input) + } + result, err := t.client.ExecuteAsString(ctx, t.actionID, input, t.params) if err != nil { return "", err } + if t.CallbacksHandler != nil { + t.CallbacksHandler.HandleToolEnd(result) + } + return result, nil } diff --git a/vectorstores/vectorstores.go b/vectorstores/vectorstores.go index 492e4e38b..8927bbf08 100644 --- a/vectorstores/vectorstores.go +++ b/vectorstores/vectorstores.go @@ -3,6 +3,7 @@ package vectorstores import ( "context" + "github.com/tmc/langchaingo/callbacks" "github.com/tmc/langchaingo/schema" ) @@ -15,16 +16,30 @@ type VectorStore interface { // Retriever is a retriever for vector stores. type Retriever struct { - v VectorStore - numDocs int - options []Option + CallbacksHandler callbacks.Handler + v VectorStore + numDocs int + options []Option } var _ schema.Retriever = Retriever{} // GetRelevantDocuments returns documents using the vector store. func (r Retriever) GetRelevantDocuments(ctx context.Context, query string) ([]schema.Document, error) { - return r.v.SimilaritySearch(ctx, query, r.numDocs, r.options...) + if r.CallbacksHandler != nil { + r.CallbacksHandler.HandleRetrieverStart(query) + } + + docs, err := r.v.SimilaritySearch(ctx, query, r.numDocs, r.options...) + if err != nil { + return nil, err + } + + if r.CallbacksHandler != nil { + r.CallbacksHandler.HandleRetrieverEnd(docs) + } + + return docs, nil } // ToRetriever takes a vector store and returns a retriever using the From 199046e5b7adb3306bd113c5c28935320b27e068 Mon Sep 17 00:00:00 2001 From: FluffyKebab Date: Sun, 20 Aug 2023 10:32:30 +0200 Subject: [PATCH 05/11] callbacks: improve logging formating and docs --- chains/llm_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/chains/llm_test.go b/chains/llm_test.go index e73dc40f3..7edaeaa53 100644 --- a/chains/llm_test.go +++ b/chains/llm_test.go @@ -7,6 +7,7 @@ import ( "testing" "github.com/stretchr/testify/require" + "github.com/tmc/langchaingo/callbacks" "github.com/tmc/langchaingo/llms/openai" "github.com/tmc/langchaingo/prompts" ) @@ -18,6 +19,7 @@ func TestLLMChain(t *testing.T) { } model, err := openai.New() require.NoError(t, err) + model.CallbacksHandler = callbacks.LogHandler{} prompt := prompts.NewPromptTemplate( "What is the capital of {{.country}}", From b5659cf46d412b5705f88d5d15e52183fecb701e Mon Sep 17 00:00:00 2001 From: FluffyKebab Date: Sun, 20 Aug 2023 10:34:53 +0200 Subject: [PATCH 06/11] callbacks: improve logging formating and docs --- callbacks/callbacks.go | 2 ++ callbacks/doc.go | 4 ++++ callbacks/log.go | 52 ++++++++++++++++++++++++++++++------------ 3 files changed, 44 insertions(+), 14 deletions(-) create mode 100644 callbacks/doc.go diff --git a/callbacks/callbacks.go b/callbacks/callbacks.go index 5da9b6bab..bc75348c7 100644 --- a/callbacks/callbacks.go +++ b/callbacks/callbacks.go @@ -5,6 +5,7 @@ import ( "github.com/tmc/langchaingo/schema" ) +// Handler is the interface that allows for hooking type Handler interface { HandleText(text string) HandleLLMStart(prompts []string) @@ -18,6 +19,7 @@ type Handler interface { HandleRetrieverEnd(documents []schema.Document) } +// HandlerHaver is an interface used to get callbacks handler. type HandlerHaver interface { GetCallbackHandler() Handler } diff --git a/callbacks/doc.go b/callbacks/doc.go new file mode 100644 index 000000000..56caf4893 --- /dev/null +++ b/callbacks/doc.go @@ -0,0 +1,4 @@ +// Package callbacks includes a standard interface for hooking into various +// stages of your LLM application. The package contains an implementation of +// this interface that prints to the standard output. +package callbacks diff --git a/callbacks/log.go b/callbacks/log.go index 350353987..45d000660 100644 --- a/callbacks/log.go +++ b/callbacks/log.go @@ -2,6 +2,7 @@ package callbacks import ( "fmt" + "strings" "github.com/tmc/langchaingo/llms" "github.com/tmc/langchaingo/schema" @@ -17,43 +18,66 @@ func (l LogHandler) HandleText(text string) { } func (l LogHandler) HandleLLMStart(prompts []string) { - fmt.Println("Entering LLM with prompts", prompts) + fmt.Println("Entering LLM with prompts:", prompts) } func (l LogHandler) HandleLLMEnd(output llms.LLMResult) { - results := "" - for i := 0; i < len(output.Generations); i++ { - for j := 0; j < len(output.Generations[i]); j++ { - results += output.Generations[i][j].Text + "\n" - } - } - fmt.Println("Exiting LLM with results: \n", results) + fmt.Println("Exiting LLM with results:", formatLLMResult(output)) } func (l LogHandler) HandleChainStart(inputs map[string]any) { - fmt.Println("Entering chain with inputs:", inputs) + fmt.Println("Entering chain with inputs:", formatChainValues(inputs)) } func (l LogHandler) HandleChainEnd(outputs map[string]any) { - fmt.Println("Exiting chain with outputs:", outputs) + + fmt.Println("Exiting chain with outputs:", formatChainValues(outputs)) } func (l LogHandler) HandleToolStart(input string) { - fmt.Println("Entering tool with input:", input) + fmt.Println("Entering tool with input:", removeNewLines(input)) } func (l LogHandler) HandleToolEnd(output string) { - fmt.Println("Exiting tool with output:", output) + fmt.Println("Exiting tool with output:", removeNewLines(output)) } func (l LogHandler) HandleAgentAction(action schema.AgentAction) { - fmt.Println("Agent selected action:", action) + fmt.Println("Agent selected action:", formatAgentAction(action)) } func (l LogHandler) HandleRetrieverStart(query string) { - fmt.Println("Entering retriever with query:", query) + fmt.Println("Entering retriever with query:", removeNewLines(query)) } func (l LogHandler) HandleRetrieverEnd(documents []schema.Document) { fmt.Println("Exiting retirer with documents:", documents) } + +func formatChainValues(values map[string]any) string { + output := "" + for key, value := range values { + output += fmt.Sprintf("\"%s\" : \"%s\", ", removeNewLines(key), removeNewLines(value)) + } + + return output +} + +func formatLLMResult(output llms.LLMResult) string { + results := "[ " + for i := 0; i < len(output.Generations); i++ { + for j := 0; j < len(output.Generations[i]); j++ { + results += output.Generations[i][j].Text + } + } + + return results + " ]" +} + +func formatAgentAction(action schema.AgentAction) string { + return fmt.Sprintf("\"%s\" with input \"%s\"", removeNewLines(action.Tool), removeNewLines(action.ToolInput)) +} + +func removeNewLines(s any) string { + return strings.ReplaceAll(fmt.Sprint(s), "\n", " ") +} From f7e95446c03608522c6524843b8be1a21e0a8572 Mon Sep 17 00:00:00 2001 From: FluffyKebab Date: Sun, 20 Aug 2023 10:59:22 +0200 Subject: [PATCH 07/11] fix lint --- callbacks/callbacks.go | 3 ++- callbacks/log.go | 1 - llms/local/localllm.go | 2 +- llms/openai/openaillm_chat.go | 30 +++++++++++++++++++++++++++++- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/callbacks/callbacks.go b/callbacks/callbacks.go index bc75348c7..e925ad572 100644 --- a/callbacks/callbacks.go +++ b/callbacks/callbacks.go @@ -5,7 +5,8 @@ import ( "github.com/tmc/langchaingo/schema" ) -// Handler is the interface that allows for hooking +// Handler is the interface that allows for hooking into specific parts of an +// LLM application. type Handler interface { HandleText(text string) HandleLLMStart(prompts []string) diff --git a/callbacks/log.go b/callbacks/log.go index 45d000660..e4a2d40d4 100644 --- a/callbacks/log.go +++ b/callbacks/log.go @@ -30,7 +30,6 @@ func (l LogHandler) HandleChainStart(inputs map[string]any) { } func (l LogHandler) HandleChainEnd(outputs map[string]any) { - fmt.Println("Exiting chain with outputs:", formatChainValues(outputs)) } diff --git a/llms/local/localllm.go b/llms/local/localllm.go index cafcf7683..6ce63adc7 100644 --- a/llms/local/localllm.go +++ b/llms/local/localllm.go @@ -88,7 +88,7 @@ func (o *LLM) Generate(ctx context.Context, prompts []string, options ...llms.Ca o.appendGlobalsToArgs(*opts) } - generations := make([]*llms.Generation, len(prompts)) + generations := make([]*llms.Generation, 0, len(prompts)) for _, prompt := range prompts { result, err := o.client.CreateCompletion(ctx, &localclient.CompletionRequest{ Prompt: prompt, diff --git a/llms/openai/openaillm_chat.go b/llms/openai/openaillm_chat.go index 2858b0160..d6effdf51 100644 --- a/llms/openai/openaillm_chat.go +++ b/llms/openai/openaillm_chat.go @@ -86,7 +86,7 @@ func (o *Chat) Generate(ctx context.Context, messageSets [][]schema.ChatMessage, req := &openaiclient.ChatRequest{ Model: opts.Model, StopWords: opts.StopWords, - Messages: msgs, + Messages: messagesToClientMessages(messageSet), StreamingFunc: opts.StreamingFunc, Temperature: opts.Temperature, MaxTokens: opts.MaxTokens, @@ -174,3 +174,31 @@ func getPromptsFromMessageSets(messageSets [][]schema.ChatMessage) []string { return prompts } + +func messagesToClientMessages(messages []schema.ChatMessage) []*openaiclient.ChatMessage { + msgs := make([]*openaiclient.ChatMessage, len(messages)) + for i, m := range messages { + msg := &openaiclient.ChatMessage{ + Content: m.GetContent(), + } + typ := m.GetType() + switch typ { + case schema.ChatMessageTypeSystem: + msg.Role = "system" + case schema.ChatMessageTypeAI: + msg.Role = "assistant" + case schema.ChatMessageTypeHuman: + msg.Role = "user" + case schema.ChatMessageTypeGeneric: + msg.Role = "user" + case schema.ChatMessageTypeFunction: + msg.Role = "function" + } + if n, ok := m.(schema.Named); ok { + msg.Name = n.GetName() + } + msgs[i] = msg + } + + return msgs +} From 9863d13b4e7da068610c3ec9e40184add501dfa4 Mon Sep 17 00:00:00 2001 From: FluffyKebab Date: Sun, 20 Aug 2023 11:20:39 +0200 Subject: [PATCH 08/11] reduce cylop in executor --- agents/executor.go | 49 ++++++++++++++++++++++++++++------------------ callbacks/log.go | 2 ++ 2 files changed, 32 insertions(+), 19 deletions(-) diff --git a/agents/executor.go b/agents/executor.go index 44f279fec..db8eb18eb 100644 --- a/agents/executor.go +++ b/agents/executor.go @@ -67,34 +67,45 @@ func (e Executor) Call(ctx context.Context, inputValues map[string]any, _ ...cha } for _, action := range actions { - if e.CallbacksHandler != nil { - e.CallbacksHandler.HandleAgentAction(action) - } - - tool, ok := nameToTool[strings.ToUpper(action.Tool)] - if !ok { - steps = append(steps, schema.AgentStep{ - Action: action, - Observation: fmt.Sprintf("%s is not a valid tool, try another one", action.Tool), - }) - continue - } - - observation, err := tool.Call(ctx, action.ToolInput) + steps, err = e.doAction(ctx, steps, nameToTool, action) if err != nil { return nil, err } - - steps = append(steps, schema.AgentStep{ - Action: action, - Observation: observation, - }) } } return nil, ErrNotFinished } +func (e Executor) doAction( + ctx context.Context, + steps []schema.AgentStep, + nameToTool map[string]tools.Tool, + action schema.AgentAction, +) ([]schema.AgentStep, error) { + if e.CallbacksHandler != nil { + e.CallbacksHandler.HandleAgentAction(action) + } + + tool, ok := nameToTool[strings.ToUpper(action.Tool)] + if !ok { + return append(steps, schema.AgentStep{ + Action: action, + Observation: fmt.Sprintf("%s is not a valid tool, try another one", action.Tool), + }), nil + } + + observation, err := tool.Call(ctx, action.ToolInput) + if err != nil { + return nil, err + } + + return append(steps, schema.AgentStep{ + Action: action, + Observation: observation, + }), nil +} + func (e Executor) getReturn(finish *schema.AgentFinish, steps []schema.AgentStep) map[string]any { if e.ReturnIntermediateSteps { finish.ReturnValues[_intermediateStepsOutputKey] = steps diff --git a/callbacks/log.go b/callbacks/log.go index e4a2d40d4..53303cb18 100644 --- a/callbacks/log.go +++ b/callbacks/log.go @@ -1,5 +1,7 @@ package callbacks +//nolint:forbidigo + import ( "fmt" "strings" From b2dee18c4b13b5845b8d9889fa5f980b9e0ea2a9 Mon Sep 17 00:00:00 2001 From: FluffyKebab Date: Sun, 20 Aug 2023 11:32:04 +0200 Subject: [PATCH 09/11] callbacks: nolint forbidigo in logger --- agents/executor.go | 6 ++++-- callbacks/log.go | 3 +-- chains/llm.go | 6 ++++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/agents/executor.go b/agents/executor.go index db8eb18eb..dd9af4f93 100644 --- a/agents/executor.go +++ b/agents/executor.go @@ -24,8 +24,10 @@ type Executor struct { ReturnIntermediateSteps bool } -var _ chains.Chain = Executor{} -var _ callbacks.HandlerHaver = Executor{} +var ( + _ chains.Chain = Executor{} + _ callbacks.HandlerHaver = Executor{} +) // NewExecutor creates a new agent executor with a agent and the tools the agent can use. func NewExecutor(agent Agent, tools []tools.Tool, opts ...CreationOption) Executor { diff --git a/callbacks/log.go b/callbacks/log.go index 53303cb18..b576e4ddc 100644 --- a/callbacks/log.go +++ b/callbacks/log.go @@ -1,6 +1,5 @@ -package callbacks - //nolint:forbidigo +package callbacks import ( "fmt" diff --git a/chains/llm.go b/chains/llm.go index a82f76dd9..e7eb596dd 100644 --- a/chains/llm.go +++ b/chains/llm.go @@ -23,8 +23,10 @@ type LLMChain struct { OutputKey string } -var _ Chain = &LLMChain{} -var _ callbacks.HandlerHaver = &LLMChain{} +var ( + _ Chain = &LLMChain{} + _ callbacks.HandlerHaver = &LLMChain{} +) // NewLLMChain creates a new LLMChain with an llm and a prompt. func NewLLMChain(llm llms.LanguageModel, prompt prompts.FormatPrompter) *LLMChain { From c5b84faa544673edda61a24735f6e70fc9f1a0a1 Mon Sep 17 00:00:00 2001 From: Travis Cline Date: Fri, 25 Aug 2023 19:14:02 -0700 Subject: [PATCH 10/11] callbacks: Include context --- agents/executor.go | 2 +- callbacks/callbacks.go | 22 ++++++++++--------- callbacks/log.go | 21 +++++++++--------- chains/chains.go | 4 ++-- examples/anthropic-completion-example/go.mod | 2 +- examples/anthropic-completion-example/go.sum | 4 ++-- examples/cohere-llm-example/go.mod | 2 +- examples/cohere-llm-example/go.sum | 4 ++-- examples/document-qa-example/go.mod | 2 +- examples/document-qa-example/go.sum | 4 ++-- examples/huggingface-llm-example/go.mod | 2 +- examples/huggingface-llm-example/go.sum | 4 ++-- examples/llm-chain-example/go.mod | 2 +- examples/llm-chain-example/go.sum | 4 ++-- examples/llmmath-chain-example/go.mod | 2 +- examples/llmmath-chain-example/go.sum | 4 ++-- .../llmsummarization-chain-example/go.mod | 2 +- .../llmsummarization-chain-example/go.sum | 4 ++-- examples/local-llm-example/go.mod | 2 +- examples/local-llm-example/go.sum | 4 ++-- examples/mrkl-agent-example/go.mod | 2 +- examples/mrkl-agent-example/go.sum | 4 ++-- examples/openai-chat-example/go.mod | 2 +- examples/openai-chat-example/go.sum | 4 ++-- examples/openai-completion-example/go.mod | 2 +- examples/openai-completion-example/go.sum | 4 ++-- examples/openai-function-call-example/go.mod | 2 +- examples/openai-function-call-example/go.sum | 4 ++-- examples/pinecone-vectorstore-example/go.mod | 2 +- examples/pinecone-vectorstore-example/go.sum | 4 ++-- .../postgresql-database-chain-example/go.mod | 2 +- .../postgresql-database-chain-example/go.sum | 4 ++-- examples/prompts-with-partial-example/go.mod | 2 +- examples/prompts-with-partial-example/go.sum | 4 ++-- .../prompts-with-partial-func-example/go.mod | 2 +- .../prompts-with-partial-func-example/go.sum | 4 ++-- examples/sequential-chain-example/go.mod | 2 +- examples/sequential-chain-example/go.sum | 4 ++-- examples/sql-database-chain-example/go.mod | 2 +- examples/sql-database-chain-example/go.sum | 4 ++-- examples/vertexai-palm-chat-example/go.mod | 2 +- examples/vertexai-palm-chat-example/go.sum | 4 ++-- .../vertexai-palm-completion-example/go.mod | 2 +- .../vertexai-palm-completion-example/go.sum | 4 ++-- examples/zapier-llm-example/go.mod | 2 +- llms/anthropic/anthropicllm.go | 4 ++-- llms/cohere/coherellm.go | 4 ++-- llms/huggingface/huggingfacellm.go | 4 ++-- llms/local/localllm.go | 4 ++-- llms/openai/openaillm.go | 4 ++-- llms/openai/openaillm_chat.go | 4 ++-- llms/vertexai/vertexai_palm_llm.go | 4 ++-- tools/calculator.go | 6 ++--- tools/duckduckgo/ddg.go | 4 ++-- tools/serpapi/serpapi.go | 4 ++-- tools/wikipedia/wikipedia.go | 4 ++-- tools/zapier/zapier.go | 4 ++-- vectorstores/vectorstores.go | 4 ++-- 58 files changed, 114 insertions(+), 111 deletions(-) diff --git a/agents/executor.go b/agents/executor.go index dd9af4f93..df759b81c 100644 --- a/agents/executor.go +++ b/agents/executor.go @@ -86,7 +86,7 @@ func (e Executor) doAction( action schema.AgentAction, ) ([]schema.AgentStep, error) { if e.CallbacksHandler != nil { - e.CallbacksHandler.HandleAgentAction(action) + e.CallbacksHandler.HandleAgentAction(ctx, action) } tool, ok := nameToTool[strings.ToUpper(action.Tool)] diff --git a/callbacks/callbacks.go b/callbacks/callbacks.go index e925ad572..bcccb2120 100644 --- a/callbacks/callbacks.go +++ b/callbacks/callbacks.go @@ -1,6 +1,8 @@ package callbacks import ( + "context" + "github.com/tmc/langchaingo/llms" "github.com/tmc/langchaingo/schema" ) @@ -8,16 +10,16 @@ import ( // Handler is the interface that allows for hooking into specific parts of an // LLM application. type Handler interface { - HandleText(text string) - HandleLLMStart(prompts []string) - HandleLLMEnd(output llms.LLMResult) - HandleChainStart(inputs map[string]any) - HandleChainEnd(outputs map[string]any) - HandleToolStart(input string) - HandleToolEnd(output string) - HandleAgentAction(action schema.AgentAction) - HandleRetrieverStart(query string) - HandleRetrieverEnd(documents []schema.Document) + HandleText(ctx context.Context, text string) + HandleLLMStart(ctx context.Context, prompts []string) + HandleLLMEnd(ctx context.Context, output llms.LLMResult) + HandleChainStart(ctx context.Context, inputs map[string]any) + HandleChainEnd(ctx context.Context, outputs map[string]any) + HandleToolStart(ctx context.Context, input string) + HandleToolEnd(ctx context.Context, output string) + HandleAgentAction(ctx context.Context, action schema.AgentAction) + HandleRetrieverStart(ctx context.Context, query string) + HandleRetrieverEnd(ctx context.Context, documents []schema.Document) } // HandlerHaver is an interface used to get callbacks handler. diff --git a/callbacks/log.go b/callbacks/log.go index b576e4ddc..f309f4620 100644 --- a/callbacks/log.go +++ b/callbacks/log.go @@ -2,6 +2,7 @@ package callbacks import ( + "context" "fmt" "strings" @@ -14,43 +15,43 @@ type LogHandler struct{} var _ Handler = LogHandler{} -func (l LogHandler) HandleText(text string) { +func (l LogHandler) HandleText(ctx context.Context, text string) { fmt.Println(text) } -func (l LogHandler) HandleLLMStart(prompts []string) { +func (l LogHandler) HandleLLMStart(ctx context.Context, prompts []string) { fmt.Println("Entering LLM with prompts:", prompts) } -func (l LogHandler) HandleLLMEnd(output llms.LLMResult) { +func (l LogHandler) HandleLLMEnd(ctx context.Context, output llms.LLMResult) { fmt.Println("Exiting LLM with results:", formatLLMResult(output)) } -func (l LogHandler) HandleChainStart(inputs map[string]any) { +func (l LogHandler) HandleChainStart(ctx context.Context, inputs map[string]any) { fmt.Println("Entering chain with inputs:", formatChainValues(inputs)) } -func (l LogHandler) HandleChainEnd(outputs map[string]any) { +func (l LogHandler) HandleChainEnd(ctx context.Context, outputs map[string]any) { fmt.Println("Exiting chain with outputs:", formatChainValues(outputs)) } -func (l LogHandler) HandleToolStart(input string) { +func (l LogHandler) HandleToolStart(ctx context.Context, input string) { fmt.Println("Entering tool with input:", removeNewLines(input)) } -func (l LogHandler) HandleToolEnd(output string) { +func (l LogHandler) HandleToolEnd(ctx context.Context, output string) { fmt.Println("Exiting tool with output:", removeNewLines(output)) } -func (l LogHandler) HandleAgentAction(action schema.AgentAction) { +func (l LogHandler) HandleAgentAction(ctx context.Context, action schema.AgentAction) { fmt.Println("Agent selected action:", formatAgentAction(action)) } -func (l LogHandler) HandleRetrieverStart(query string) { +func (l LogHandler) HandleRetrieverStart(ctx context.Context, query string) { fmt.Println("Entering retriever with query:", removeNewLines(query)) } -func (l LogHandler) HandleRetrieverEnd(documents []schema.Document) { +func (l LogHandler) HandleRetrieverEnd(ctx context.Context, documents []schema.Document) { fmt.Println("Exiting retirer with documents:", documents) } diff --git a/chains/chains.go b/chains/chains.go index c2658d37f..0efe76e0c 100644 --- a/chains/chains.go +++ b/chains/chains.go @@ -44,7 +44,7 @@ func Call(ctx context.Context, c Chain, inputValues map[string]any, options ...C callbacksHandler := getChainCallbackHandler(c) if callbacksHandler != nil { - callbacksHandler.HandleChainStart(inputValues) + callbacksHandler.HandleChainStart(ctx, inputValues) } if err := validateInputs(c, fullValues); err != nil { @@ -60,7 +60,7 @@ func Call(ctx context.Context, c Chain, inputValues map[string]any, options ...C } if callbacksHandler != nil { - callbacksHandler.HandleChainEnd(outputValues) + callbacksHandler.HandleChainEnd(ctx, outputValues) } err = c.GetMemory().SaveContext(ctx, inputValues, outputValues) diff --git a/examples/anthropic-completion-example/go.mod b/examples/anthropic-completion-example/go.mod index 6e9f2ea1a..09c92a441 100644 --- a/examples/anthropic-completion-example/go.mod +++ b/examples/anthropic-completion-example/go.mod @@ -2,7 +2,7 @@ module anthropic-completion-example go 1.19 -require github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849 +require github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0 require ( github.com/dlclark/regexp2 v1.8.1 // indirect diff --git a/examples/anthropic-completion-example/go.sum b/examples/anthropic-completion-example/go.sum index 1cf20e0bd..964c267ed 100644 --- a/examples/anthropic-completion-example/go.sum +++ b/examples/anthropic-completion-example/go.sum @@ -7,6 +7,6 @@ github.com/pkoukk/tiktoken-go v0.1.2 h1:u7PCSBiWJ3nJYoTGShyM9iHXz4dNyYkurwwp+GHt 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/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= -github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849 h1:y4TnpS57FeE5QzBzV2wKysVxWvkuMsha12yGHPVVAFo= -github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849/go.mod h1:8T+nNIGBr3nYQEYFmF/YaT8t8YTKLvFYZBuVZOAYn5E= +github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0 h1:7pmW0coaYnLm4evqJ+QR10EgDU1ku+xGOpcHBMuvE7E= +github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0/go.mod h1:fd7jP67Fwvcr+i7J+oAZbrh2aiekUuBLVqW/vgDslnw= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/examples/cohere-llm-example/go.mod b/examples/cohere-llm-example/go.mod index d37589e92..d7d55da44 100644 --- a/examples/cohere-llm-example/go.mod +++ b/examples/cohere-llm-example/go.mod @@ -2,7 +2,7 @@ module basic-llm-example go 1.19 -require github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849 +require github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0 require ( github.com/cohere-ai/tokenizer v1.1.2 // indirect diff --git a/examples/cohere-llm-example/go.sum b/examples/cohere-llm-example/go.sum index 8cf012302..5f8887a1a 100644 --- a/examples/cohere-llm-example/go.sum +++ b/examples/cohere-llm-example/go.sum @@ -11,6 +11,6 @@ github.com/pkoukk/tiktoken-go v0.1.2 h1:u7PCSBiWJ3nJYoTGShyM9iHXz4dNyYkurwwp+GHt 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/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= -github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849 h1:y4TnpS57FeE5QzBzV2wKysVxWvkuMsha12yGHPVVAFo= -github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849/go.mod h1:8T+nNIGBr3nYQEYFmF/YaT8t8YTKLvFYZBuVZOAYn5E= +github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0 h1:7pmW0coaYnLm4evqJ+QR10EgDU1ku+xGOpcHBMuvE7E= +github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0/go.mod h1:fd7jP67Fwvcr+i7J+oAZbrh2aiekUuBLVqW/vgDslnw= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/examples/document-qa-example/go.mod b/examples/document-qa-example/go.mod index 9bae0bb74..c09be5c0b 100644 --- a/examples/document-qa-example/go.mod +++ b/examples/document-qa-example/go.mod @@ -2,7 +2,7 @@ module document-qa-example go 1.19 -require github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849 +require github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0 require ( github.com/Masterminds/goutils v1.1.1 // indirect diff --git a/examples/document-qa-example/go.sum b/examples/document-qa-example/go.sum index 64aef84a6..fac53fb64 100644 --- a/examples/document-qa-example/go.sum +++ b/examples/document-qa-example/go.sum @@ -66,8 +66,8 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= -github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849 h1:y4TnpS57FeE5QzBzV2wKysVxWvkuMsha12yGHPVVAFo= -github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849/go.mod h1:8T+nNIGBr3nYQEYFmF/YaT8t8YTKLvFYZBuVZOAYn5E= +github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0 h1:7pmW0coaYnLm4evqJ+QR10EgDU1ku+xGOpcHBMuvE7E= +github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0/go.mod h1:fd7jP67Fwvcr+i7J+oAZbrh2aiekUuBLVqW/vgDslnw= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= go.starlark.net v0.0.0-20230302034142-4b1e35fe2254 h1:Ss6D3hLXTM0KobyBYEAygXzFfGcjnmfEJOBgSbemCtg= go.starlark.net v0.0.0-20230302034142-4b1e35fe2254/go.mod h1:jxU+3+j+71eXOW14274+SmmuW82qJzl6iZSeqEtTGds= diff --git a/examples/huggingface-llm-example/go.mod b/examples/huggingface-llm-example/go.mod index e2b053fe6..1e9b325a4 100644 --- a/examples/huggingface-llm-example/go.mod +++ b/examples/huggingface-llm-example/go.mod @@ -2,7 +2,7 @@ module huggingface-llm-example go 1.19 -require github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849 +require github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0 require ( github.com/dlclark/regexp2 v1.8.1 // indirect diff --git a/examples/huggingface-llm-example/go.sum b/examples/huggingface-llm-example/go.sum index 1cf20e0bd..964c267ed 100644 --- a/examples/huggingface-llm-example/go.sum +++ b/examples/huggingface-llm-example/go.sum @@ -7,6 +7,6 @@ github.com/pkoukk/tiktoken-go v0.1.2 h1:u7PCSBiWJ3nJYoTGShyM9iHXz4dNyYkurwwp+GHt 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/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= -github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849 h1:y4TnpS57FeE5QzBzV2wKysVxWvkuMsha12yGHPVVAFo= -github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849/go.mod h1:8T+nNIGBr3nYQEYFmF/YaT8t8YTKLvFYZBuVZOAYn5E= +github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0 h1:7pmW0coaYnLm4evqJ+QR10EgDU1ku+xGOpcHBMuvE7E= +github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0/go.mod h1:fd7jP67Fwvcr+i7J+oAZbrh2aiekUuBLVqW/vgDslnw= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/examples/llm-chain-example/go.mod b/examples/llm-chain-example/go.mod index ec8d55e87..0c9422fa2 100644 --- a/examples/llm-chain-example/go.mod +++ b/examples/llm-chain-example/go.mod @@ -2,7 +2,7 @@ module llm-chain-example go 1.19 -require github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849 +require github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0 require ( github.com/Masterminds/goutils v1.1.1 // indirect diff --git a/examples/llm-chain-example/go.sum b/examples/llm-chain-example/go.sum index 64aef84a6..fac53fb64 100644 --- a/examples/llm-chain-example/go.sum +++ b/examples/llm-chain-example/go.sum @@ -66,8 +66,8 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= -github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849 h1:y4TnpS57FeE5QzBzV2wKysVxWvkuMsha12yGHPVVAFo= -github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849/go.mod h1:8T+nNIGBr3nYQEYFmF/YaT8t8YTKLvFYZBuVZOAYn5E= +github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0 h1:7pmW0coaYnLm4evqJ+QR10EgDU1ku+xGOpcHBMuvE7E= +github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0/go.mod h1:fd7jP67Fwvcr+i7J+oAZbrh2aiekUuBLVqW/vgDslnw= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= go.starlark.net v0.0.0-20230302034142-4b1e35fe2254 h1:Ss6D3hLXTM0KobyBYEAygXzFfGcjnmfEJOBgSbemCtg= go.starlark.net v0.0.0-20230302034142-4b1e35fe2254/go.mod h1:jxU+3+j+71eXOW14274+SmmuW82qJzl6iZSeqEtTGds= diff --git a/examples/llmmath-chain-example/go.mod b/examples/llmmath-chain-example/go.mod index ea1c8b097..53f043c59 100644 --- a/examples/llmmath-chain-example/go.mod +++ b/examples/llmmath-chain-example/go.mod @@ -2,7 +2,7 @@ module llmmath-chain-example go 1.19 -require github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849 +require github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0 require ( github.com/Masterminds/goutils v1.1.1 // indirect diff --git a/examples/llmmath-chain-example/go.sum b/examples/llmmath-chain-example/go.sum index 64aef84a6..fac53fb64 100644 --- a/examples/llmmath-chain-example/go.sum +++ b/examples/llmmath-chain-example/go.sum @@ -66,8 +66,8 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= -github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849 h1:y4TnpS57FeE5QzBzV2wKysVxWvkuMsha12yGHPVVAFo= -github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849/go.mod h1:8T+nNIGBr3nYQEYFmF/YaT8t8YTKLvFYZBuVZOAYn5E= +github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0 h1:7pmW0coaYnLm4evqJ+QR10EgDU1ku+xGOpcHBMuvE7E= +github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0/go.mod h1:fd7jP67Fwvcr+i7J+oAZbrh2aiekUuBLVqW/vgDslnw= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= go.starlark.net v0.0.0-20230302034142-4b1e35fe2254 h1:Ss6D3hLXTM0KobyBYEAygXzFfGcjnmfEJOBgSbemCtg= go.starlark.net v0.0.0-20230302034142-4b1e35fe2254/go.mod h1:jxU+3+j+71eXOW14274+SmmuW82qJzl6iZSeqEtTGds= diff --git a/examples/llmsummarization-chain-example/go.mod b/examples/llmsummarization-chain-example/go.mod index a52cc62af..e5cd38505 100644 --- a/examples/llmsummarization-chain-example/go.mod +++ b/examples/llmsummarization-chain-example/go.mod @@ -2,7 +2,7 @@ module llmsummarization-chain-example go 1.19 -require github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849 +require github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0 require ( cloud.google.com/go v0.110.0 // indirect diff --git a/examples/llmsummarization-chain-example/go.sum b/examples/llmsummarization-chain-example/go.sum index ece214c4f..5d1d7f59c 100644 --- a/examples/llmsummarization-chain-example/go.sum +++ b/examples/llmsummarization-chain-example/go.sum @@ -127,8 +127,8 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= -github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849 h1:y4TnpS57FeE5QzBzV2wKysVxWvkuMsha12yGHPVVAFo= -github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849/go.mod h1:8T+nNIGBr3nYQEYFmF/YaT8t8YTKLvFYZBuVZOAYn5E= +github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0 h1:7pmW0coaYnLm4evqJ+QR10EgDU1ku+xGOpcHBMuvE7E= +github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0/go.mod h1:fd7jP67Fwvcr+i7J+oAZbrh2aiekUuBLVqW/vgDslnw= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0= go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo= diff --git a/examples/local-llm-example/go.mod b/examples/local-llm-example/go.mod index e888e655e..50f08440a 100644 --- a/examples/local-llm-example/go.mod +++ b/examples/local-llm-example/go.mod @@ -2,7 +2,7 @@ module local-llm-example go 1.19 -require github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849 +require github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0 require ( github.com/dlclark/regexp2 v1.8.1 // indirect diff --git a/examples/local-llm-example/go.sum b/examples/local-llm-example/go.sum index 1cf20e0bd..964c267ed 100644 --- a/examples/local-llm-example/go.sum +++ b/examples/local-llm-example/go.sum @@ -7,6 +7,6 @@ github.com/pkoukk/tiktoken-go v0.1.2 h1:u7PCSBiWJ3nJYoTGShyM9iHXz4dNyYkurwwp+GHt 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/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= -github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849 h1:y4TnpS57FeE5QzBzV2wKysVxWvkuMsha12yGHPVVAFo= -github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849/go.mod h1:8T+nNIGBr3nYQEYFmF/YaT8t8YTKLvFYZBuVZOAYn5E= +github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0 h1:7pmW0coaYnLm4evqJ+QR10EgDU1ku+xGOpcHBMuvE7E= +github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0/go.mod h1:fd7jP67Fwvcr+i7J+oAZbrh2aiekUuBLVqW/vgDslnw= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/examples/mrkl-agent-example/go.mod b/examples/mrkl-agent-example/go.mod index 81a2431f1..1ce3dbda5 100644 --- a/examples/mrkl-agent-example/go.mod +++ b/examples/mrkl-agent-example/go.mod @@ -2,7 +2,7 @@ module mrkl-agent-example go 1.19 -require github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849 +require github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0 require ( github.com/Masterminds/goutils v1.1.1 // indirect diff --git a/examples/mrkl-agent-example/go.sum b/examples/mrkl-agent-example/go.sum index 64aef84a6..fac53fb64 100644 --- a/examples/mrkl-agent-example/go.sum +++ b/examples/mrkl-agent-example/go.sum @@ -66,8 +66,8 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= -github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849 h1:y4TnpS57FeE5QzBzV2wKysVxWvkuMsha12yGHPVVAFo= -github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849/go.mod h1:8T+nNIGBr3nYQEYFmF/YaT8t8YTKLvFYZBuVZOAYn5E= +github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0 h1:7pmW0coaYnLm4evqJ+QR10EgDU1ku+xGOpcHBMuvE7E= +github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0/go.mod h1:fd7jP67Fwvcr+i7J+oAZbrh2aiekUuBLVqW/vgDslnw= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= go.starlark.net v0.0.0-20230302034142-4b1e35fe2254 h1:Ss6D3hLXTM0KobyBYEAygXzFfGcjnmfEJOBgSbemCtg= go.starlark.net v0.0.0-20230302034142-4b1e35fe2254/go.mod h1:jxU+3+j+71eXOW14274+SmmuW82qJzl6iZSeqEtTGds= diff --git a/examples/openai-chat-example/go.mod b/examples/openai-chat-example/go.mod index 5de12713f..8f1486650 100644 --- a/examples/openai-chat-example/go.mod +++ b/examples/openai-chat-example/go.mod @@ -2,7 +2,7 @@ module openai-chat-example go 1.19 -require github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849 +require github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0 require ( github.com/dlclark/regexp2 v1.8.1 // indirect diff --git a/examples/openai-chat-example/go.sum b/examples/openai-chat-example/go.sum index 1cf20e0bd..964c267ed 100644 --- a/examples/openai-chat-example/go.sum +++ b/examples/openai-chat-example/go.sum @@ -7,6 +7,6 @@ github.com/pkoukk/tiktoken-go v0.1.2 h1:u7PCSBiWJ3nJYoTGShyM9iHXz4dNyYkurwwp+GHt 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/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= -github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849 h1:y4TnpS57FeE5QzBzV2wKysVxWvkuMsha12yGHPVVAFo= -github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849/go.mod h1:8T+nNIGBr3nYQEYFmF/YaT8t8YTKLvFYZBuVZOAYn5E= +github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0 h1:7pmW0coaYnLm4evqJ+QR10EgDU1ku+xGOpcHBMuvE7E= +github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0/go.mod h1:fd7jP67Fwvcr+i7J+oAZbrh2aiekUuBLVqW/vgDslnw= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/examples/openai-completion-example/go.mod b/examples/openai-completion-example/go.mod index da554eb0a..d08d48f74 100644 --- a/examples/openai-completion-example/go.mod +++ b/examples/openai-completion-example/go.mod @@ -2,7 +2,7 @@ module openai-completion-example go 1.19 -require github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849 +require github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0 require ( github.com/dlclark/regexp2 v1.8.1 // indirect diff --git a/examples/openai-completion-example/go.sum b/examples/openai-completion-example/go.sum index 1cf20e0bd..964c267ed 100644 --- a/examples/openai-completion-example/go.sum +++ b/examples/openai-completion-example/go.sum @@ -7,6 +7,6 @@ github.com/pkoukk/tiktoken-go v0.1.2 h1:u7PCSBiWJ3nJYoTGShyM9iHXz4dNyYkurwwp+GHt 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/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= -github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849 h1:y4TnpS57FeE5QzBzV2wKysVxWvkuMsha12yGHPVVAFo= -github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849/go.mod h1:8T+nNIGBr3nYQEYFmF/YaT8t8YTKLvFYZBuVZOAYn5E= +github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0 h1:7pmW0coaYnLm4evqJ+QR10EgDU1ku+xGOpcHBMuvE7E= +github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0/go.mod h1:fd7jP67Fwvcr+i7J+oAZbrh2aiekUuBLVqW/vgDslnw= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/examples/openai-function-call-example/go.mod b/examples/openai-function-call-example/go.mod index 880d2049c..7740a7534 100644 --- a/examples/openai-function-call-example/go.mod +++ b/examples/openai-function-call-example/go.mod @@ -2,7 +2,7 @@ module openai-function-call-example go 1.19 -require github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849 +require github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0 require ( github.com/dlclark/regexp2 v1.8.1 // indirect diff --git a/examples/openai-function-call-example/go.sum b/examples/openai-function-call-example/go.sum index 1cf20e0bd..964c267ed 100644 --- a/examples/openai-function-call-example/go.sum +++ b/examples/openai-function-call-example/go.sum @@ -7,6 +7,6 @@ github.com/pkoukk/tiktoken-go v0.1.2 h1:u7PCSBiWJ3nJYoTGShyM9iHXz4dNyYkurwwp+GHt 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/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= -github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849 h1:y4TnpS57FeE5QzBzV2wKysVxWvkuMsha12yGHPVVAFo= -github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849/go.mod h1:8T+nNIGBr3nYQEYFmF/YaT8t8YTKLvFYZBuVZOAYn5E= +github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0 h1:7pmW0coaYnLm4evqJ+QR10EgDU1ku+xGOpcHBMuvE7E= +github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0/go.mod h1:fd7jP67Fwvcr+i7J+oAZbrh2aiekUuBLVqW/vgDslnw= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/examples/pinecone-vectorstore-example/go.mod b/examples/pinecone-vectorstore-example/go.mod index ff20bb852..d150b0e9e 100644 --- a/examples/pinecone-vectorstore-example/go.mod +++ b/examples/pinecone-vectorstore-example/go.mod @@ -4,7 +4,7 @@ go 1.20 require ( github.com/google/uuid v1.3.0 - github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849 + github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0 ) require ( diff --git a/examples/pinecone-vectorstore-example/go.sum b/examples/pinecone-vectorstore-example/go.sum index ecc7845be..1005311d5 100644 --- a/examples/pinecone-vectorstore-example/go.sum +++ b/examples/pinecone-vectorstore-example/go.sum @@ -158,8 +158,8 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= -github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849 h1:y4TnpS57FeE5QzBzV2wKysVxWvkuMsha12yGHPVVAFo= -github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849/go.mod h1:8T+nNIGBr3nYQEYFmF/YaT8t8YTKLvFYZBuVZOAYn5E= +github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0 h1:7pmW0coaYnLm4evqJ+QR10EgDU1ku+xGOpcHBMuvE7E= +github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0/go.mod h1:fd7jP67Fwvcr+i7J+oAZbrh2aiekUuBLVqW/vgDslnw= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= diff --git a/examples/postgresql-database-chain-example/go.mod b/examples/postgresql-database-chain-example/go.mod index c1510218b..383844dba 100644 --- a/examples/postgresql-database-chain-example/go.mod +++ b/examples/postgresql-database-chain-example/go.mod @@ -2,7 +2,7 @@ module postgresql-database-chain-example go 1.20 -require github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849 +require github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0 require ( github.com/Masterminds/goutils v1.1.1 // indirect diff --git a/examples/postgresql-database-chain-example/go.sum b/examples/postgresql-database-chain-example/go.sum index 48f7bff89..2b9cd2f50 100644 --- a/examples/postgresql-database-chain-example/go.sum +++ b/examples/postgresql-database-chain-example/go.sum @@ -74,8 +74,8 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= -github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849 h1:y4TnpS57FeE5QzBzV2wKysVxWvkuMsha12yGHPVVAFo= -github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849/go.mod h1:8T+nNIGBr3nYQEYFmF/YaT8t8YTKLvFYZBuVZOAYn5E= +github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0 h1:7pmW0coaYnLm4evqJ+QR10EgDU1ku+xGOpcHBMuvE7E= +github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0/go.mod h1:fd7jP67Fwvcr+i7J+oAZbrh2aiekUuBLVqW/vgDslnw= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= go.starlark.net v0.0.0-20230302034142-4b1e35fe2254 h1:Ss6D3hLXTM0KobyBYEAygXzFfGcjnmfEJOBgSbemCtg= go.starlark.net v0.0.0-20230302034142-4b1e35fe2254/go.mod h1:jxU+3+j+71eXOW14274+SmmuW82qJzl6iZSeqEtTGds= diff --git a/examples/prompts-with-partial-example/go.mod b/examples/prompts-with-partial-example/go.mod index 32b049f76..168e90720 100644 --- a/examples/prompts-with-partial-example/go.mod +++ b/examples/prompts-with-partial-example/go.mod @@ -2,7 +2,7 @@ module prompts-with-partial-example go 1.20 -require github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849 +require github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0 require ( github.com/Masterminds/goutils v1.1.1 // indirect diff --git a/examples/prompts-with-partial-example/go.sum b/examples/prompts-with-partial-example/go.sum index 204d6b18f..4cd8a5571 100644 --- a/examples/prompts-with-partial-example/go.sum +++ b/examples/prompts-with-partial-example/go.sum @@ -29,8 +29,8 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= -github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849 h1:y4TnpS57FeE5QzBzV2wKysVxWvkuMsha12yGHPVVAFo= -github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849/go.mod h1:8T+nNIGBr3nYQEYFmF/YaT8t8YTKLvFYZBuVZOAYn5E= +github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0 h1:7pmW0coaYnLm4evqJ+QR10EgDU1ku+xGOpcHBMuvE7E= +github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0/go.mod h1:fd7jP67Fwvcr+i7J+oAZbrh2aiekUuBLVqW/vgDslnw= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= diff --git a/examples/prompts-with-partial-func-example/go.mod b/examples/prompts-with-partial-func-example/go.mod index 3e61903bd..1b29d9a27 100644 --- a/examples/prompts-with-partial-func-example/go.mod +++ b/examples/prompts-with-partial-func-example/go.mod @@ -2,7 +2,7 @@ module prompts-with-partial-func-example go 1.20 -require github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849 +require github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0 require ( github.com/Masterminds/goutils v1.1.1 // indirect diff --git a/examples/prompts-with-partial-func-example/go.sum b/examples/prompts-with-partial-func-example/go.sum index 204d6b18f..4cd8a5571 100644 --- a/examples/prompts-with-partial-func-example/go.sum +++ b/examples/prompts-with-partial-func-example/go.sum @@ -29,8 +29,8 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= -github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849 h1:y4TnpS57FeE5QzBzV2wKysVxWvkuMsha12yGHPVVAFo= -github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849/go.mod h1:8T+nNIGBr3nYQEYFmF/YaT8t8YTKLvFYZBuVZOAYn5E= +github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0 h1:7pmW0coaYnLm4evqJ+QR10EgDU1ku+xGOpcHBMuvE7E= +github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0/go.mod h1:fd7jP67Fwvcr+i7J+oAZbrh2aiekUuBLVqW/vgDslnw= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= diff --git a/examples/sequential-chain-example/go.mod b/examples/sequential-chain-example/go.mod index fc794a55d..2fa2ff3a1 100644 --- a/examples/sequential-chain-example/go.mod +++ b/examples/sequential-chain-example/go.mod @@ -2,7 +2,7 @@ module sequential-chain-example go 1.20 -require github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849 +require github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0 require ( github.com/Masterminds/goutils v1.1.1 // indirect diff --git a/examples/sequential-chain-example/go.sum b/examples/sequential-chain-example/go.sum index 64aef84a6..fac53fb64 100644 --- a/examples/sequential-chain-example/go.sum +++ b/examples/sequential-chain-example/go.sum @@ -66,8 +66,8 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= -github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849 h1:y4TnpS57FeE5QzBzV2wKysVxWvkuMsha12yGHPVVAFo= -github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849/go.mod h1:8T+nNIGBr3nYQEYFmF/YaT8t8YTKLvFYZBuVZOAYn5E= +github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0 h1:7pmW0coaYnLm4evqJ+QR10EgDU1ku+xGOpcHBMuvE7E= +github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0/go.mod h1:fd7jP67Fwvcr+i7J+oAZbrh2aiekUuBLVqW/vgDslnw= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= go.starlark.net v0.0.0-20230302034142-4b1e35fe2254 h1:Ss6D3hLXTM0KobyBYEAygXzFfGcjnmfEJOBgSbemCtg= go.starlark.net v0.0.0-20230302034142-4b1e35fe2254/go.mod h1:jxU+3+j+71eXOW14274+SmmuW82qJzl6iZSeqEtTGds= diff --git a/examples/sql-database-chain-example/go.mod b/examples/sql-database-chain-example/go.mod index 1b6ec1496..1e78afb2a 100644 --- a/examples/sql-database-chain-example/go.mod +++ b/examples/sql-database-chain-example/go.mod @@ -2,7 +2,7 @@ module sql-database-chain-example go 1.19 -require github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849 +require github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0 require ( github.com/Masterminds/goutils v1.1.1 // indirect diff --git a/examples/sql-database-chain-example/go.sum b/examples/sql-database-chain-example/go.sum index 36fc390dc..d9d1c8192 100644 --- a/examples/sql-database-chain-example/go.sum +++ b/examples/sql-database-chain-example/go.sum @@ -68,8 +68,8 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= -github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849 h1:y4TnpS57FeE5QzBzV2wKysVxWvkuMsha12yGHPVVAFo= -github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849/go.mod h1:8T+nNIGBr3nYQEYFmF/YaT8t8YTKLvFYZBuVZOAYn5E= +github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0 h1:7pmW0coaYnLm4evqJ+QR10EgDU1ku+xGOpcHBMuvE7E= +github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0/go.mod h1:fd7jP67Fwvcr+i7J+oAZbrh2aiekUuBLVqW/vgDslnw= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= go.starlark.net v0.0.0-20230302034142-4b1e35fe2254 h1:Ss6D3hLXTM0KobyBYEAygXzFfGcjnmfEJOBgSbemCtg= go.starlark.net v0.0.0-20230302034142-4b1e35fe2254/go.mod h1:jxU+3+j+71eXOW14274+SmmuW82qJzl6iZSeqEtTGds= diff --git a/examples/vertexai-palm-chat-example/go.mod b/examples/vertexai-palm-chat-example/go.mod index 6acf92bbd..33ee825aa 100644 --- a/examples/vertexai-palm-chat-example/go.mod +++ b/examples/vertexai-palm-chat-example/go.mod @@ -2,7 +2,7 @@ module vertexai-palm-chat-example go 1.19 -require github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849 +require github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0 require ( cloud.google.com/go v0.110.0 // indirect diff --git a/examples/vertexai-palm-chat-example/go.sum b/examples/vertexai-palm-chat-example/go.sum index 6b39af9f5..08399c51f 100644 --- a/examples/vertexai-palm-chat-example/go.sum +++ b/examples/vertexai-palm-chat-example/go.sum @@ -90,8 +90,8 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= -github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849 h1:y4TnpS57FeE5QzBzV2wKysVxWvkuMsha12yGHPVVAFo= -github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849/go.mod h1:8T+nNIGBr3nYQEYFmF/YaT8t8YTKLvFYZBuVZOAYn5E= +github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0 h1:7pmW0coaYnLm4evqJ+QR10EgDU1ku+xGOpcHBMuvE7E= +github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0/go.mod h1:fd7jP67Fwvcr+i7J+oAZbrh2aiekUuBLVqW/vgDslnw= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0= go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo= diff --git a/examples/vertexai-palm-completion-example/go.mod b/examples/vertexai-palm-completion-example/go.mod index 2890c9f0d..d29bba120 100644 --- a/examples/vertexai-palm-completion-example/go.mod +++ b/examples/vertexai-palm-completion-example/go.mod @@ -2,7 +2,7 @@ module vertexai-palm-completion-example go 1.19 -require github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849 +require github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0 require ( cloud.google.com/go v0.110.0 // indirect diff --git a/examples/vertexai-palm-completion-example/go.sum b/examples/vertexai-palm-completion-example/go.sum index 6b39af9f5..08399c51f 100644 --- a/examples/vertexai-palm-completion-example/go.sum +++ b/examples/vertexai-palm-completion-example/go.sum @@ -90,8 +90,8 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= -github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849 h1:y4TnpS57FeE5QzBzV2wKysVxWvkuMsha12yGHPVVAFo= -github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849/go.mod h1:8T+nNIGBr3nYQEYFmF/YaT8t8YTKLvFYZBuVZOAYn5E= +github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0 h1:7pmW0coaYnLm4evqJ+QR10EgDU1ku+xGOpcHBMuvE7E= +github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0/go.mod h1:fd7jP67Fwvcr+i7J+oAZbrh2aiekUuBLVqW/vgDslnw= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0= go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo= diff --git a/examples/zapier-llm-example/go.mod b/examples/zapier-llm-example/go.mod index e91b51679..1da77bc6e 100644 --- a/examples/zapier-llm-example/go.mod +++ b/examples/zapier-llm-example/go.mod @@ -2,7 +2,7 @@ module zapier-llm-example go 1.19 -require github.com/tmc/langchaingo v0.0.0-20230729231952-1f3948210849 +require github.com/tmc/langchaingo v0.0.0-20230826015154-aa97aec400c0 require ( github.com/Masterminds/goutils v1.1.1 // indirect diff --git a/llms/anthropic/anthropicllm.go b/llms/anthropic/anthropicllm.go index 674714357..82a8da04f 100644 --- a/llms/anthropic/anthropicllm.go +++ b/llms/anthropic/anthropicllm.go @@ -66,7 +66,7 @@ func (o *LLM) Call(ctx context.Context, prompt string, options ...llms.CallOptio func (o *LLM) Generate(ctx context.Context, prompts []string, options ...llms.CallOption) ([]*llms.Generation, error) { if o.CallbacksHandler != nil { - o.CallbacksHandler.HandleLLMStart(prompts) + o.CallbacksHandler.HandleLLMStart(ctx, prompts) } opts := llms.CallOptions{} @@ -94,7 +94,7 @@ func (o *LLM) Generate(ctx context.Context, prompts []string, options ...llms.Ca } if o.CallbacksHandler != nil { - o.CallbacksHandler.HandleLLMEnd(llms.LLMResult{Generations: [][]*llms.Generation{generations}}) + o.CallbacksHandler.HandleLLMEnd(ctx, llms.LLMResult{Generations: [][]*llms.Generation{generations}}) } return generations, nil } diff --git a/llms/cohere/coherellm.go b/llms/cohere/coherellm.go index 3c28d0220..b1b45fd5b 100644 --- a/llms/cohere/coherellm.go +++ b/llms/cohere/coherellm.go @@ -41,7 +41,7 @@ func (o *LLM) Call(ctx context.Context, prompt string, options ...llms.CallOptio func (o *LLM) Generate(ctx context.Context, prompts []string, options ...llms.CallOption) ([]*llms.Generation, error) { if o.CallbacksHandler != nil { - o.CallbacksHandler.HandleLLMStart(prompts) + o.CallbacksHandler.HandleLLMStart(ctx, prompts) } opts := llms.CallOptions{} @@ -65,7 +65,7 @@ func (o *LLM) Generate(ctx context.Context, prompts []string, options ...llms.Ca } if o.CallbacksHandler != nil { - o.CallbacksHandler.HandleLLMEnd(llms.LLMResult{Generations: [][]*llms.Generation{generations}}) + o.CallbacksHandler.HandleLLMEnd(ctx, llms.LLMResult{Generations: [][]*llms.Generation{generations}}) } return generations, nil diff --git a/llms/huggingface/huggingfacellm.go b/llms/huggingface/huggingfacellm.go index 009968b24..940ba596a 100644 --- a/llms/huggingface/huggingfacellm.go +++ b/llms/huggingface/huggingfacellm.go @@ -40,7 +40,7 @@ func (o *LLM) Call(ctx context.Context, prompt string, options ...llms.CallOptio func (o *LLM) Generate(ctx context.Context, prompts []string, options ...llms.CallOption) ([]*llms.Generation, error) { if o.CallbacksHandler != nil { - o.CallbacksHandler.HandleLLMStart(prompts) + o.CallbacksHandler.HandleLLMStart(ctx, prompts) } opts := &llms.CallOptions{Model: defaultModel} @@ -68,7 +68,7 @@ func (o *LLM) Generate(ctx context.Context, prompts []string, options ...llms.Ca } if o.CallbacksHandler != nil { - o.CallbacksHandler.HandleLLMEnd(llms.LLMResult{Generations: [][]*llms.Generation{generations}}) + o.CallbacksHandler.HandleLLMEnd(ctx, llms.LLMResult{Generations: [][]*llms.Generation{generations}}) } return generations, nil } diff --git a/llms/local/localllm.go b/llms/local/localllm.go index 6ce63adc7..3a70dff67 100644 --- a/llms/local/localllm.go +++ b/llms/local/localllm.go @@ -74,7 +74,7 @@ func (o *LLM) appendGlobalsToArgs(opts llms.CallOptions) []string { // Generate generates completions using the local LLM binary. func (o *LLM) Generate(ctx context.Context, prompts []string, options ...llms.CallOption) ([]*llms.Generation, error) { if o.CallbacksHandler != nil { - o.CallbacksHandler.HandleLLMStart(prompts) + o.CallbacksHandler.HandleLLMStart(ctx, prompts) } opts := &llms.CallOptions{} @@ -101,7 +101,7 @@ func (o *LLM) Generate(ctx context.Context, prompts []string, options ...llms.Ca } if o.CallbacksHandler != nil { - o.CallbacksHandler.HandleLLMEnd(llms.LLMResult{Generations: [][]*llms.Generation{generations}}) + o.CallbacksHandler.HandleLLMEnd(ctx, llms.LLMResult{Generations: [][]*llms.Generation{generations}}) } return generations, nil diff --git a/llms/openai/openaillm.go b/llms/openai/openaillm.go index c522e9e6f..681a0007a 100644 --- a/llms/openai/openaillm.go +++ b/llms/openai/openaillm.go @@ -41,7 +41,7 @@ func (o *LLM) Call(ctx context.Context, prompt string, options ...llms.CallOptio func (o *LLM) Generate(ctx context.Context, prompts []string, options ...llms.CallOption) ([]*llms.Generation, error) { if o.CallbacksHandler != nil { - o.CallbacksHandler.HandleLLMStart(prompts) + o.CallbacksHandler.HandleLLMStart(ctx, prompts) } opts := llms.CallOptions{} @@ -71,7 +71,7 @@ func (o *LLM) Generate(ctx context.Context, prompts []string, options ...llms.Ca } if o.CallbacksHandler != nil { - o.CallbacksHandler.HandleLLMEnd(llms.LLMResult{Generations: [][]*llms.Generation{generations}}) + o.CallbacksHandler.HandleLLMEnd(ctx, llms.LLMResult{Generations: [][]*llms.Generation{generations}}) } return generations, nil diff --git a/llms/openai/openaillm_chat.go b/llms/openai/openaillm_chat.go index d6effdf51..f536c67ef 100644 --- a/llms/openai/openaillm_chat.go +++ b/llms/openai/openaillm_chat.go @@ -45,7 +45,7 @@ func (o *Chat) Call(ctx context.Context, messages []schema.ChatMessage, options //nolint:funlen func (o *Chat) Generate(ctx context.Context, messageSets [][]schema.ChatMessage, options ...llms.CallOption) ([]*llms.Generation, error) { // nolint:lll,cyclop if o.CallbacksHandler != nil { - o.CallbacksHandler.HandleLLMStart(getPromptsFromMessageSets(messageSets)) + o.CallbacksHandler.HandleLLMStart(ctx, getPromptsFromMessageSets(messageSets)) } opts := llms.CallOptions{} @@ -131,7 +131,7 @@ func (o *Chat) Generate(ctx context.Context, messageSets [][]schema.ChatMessage, } if o.CallbacksHandler != nil { - o.CallbacksHandler.HandleLLMEnd(llms.LLMResult{Generations: [][]*llms.Generation{generations}}) + o.CallbacksHandler.HandleLLMEnd(ctx, llms.LLMResult{Generations: [][]*llms.Generation{generations}}) } return generations, nil diff --git a/llms/vertexai/vertexai_palm_llm.go b/llms/vertexai/vertexai_palm_llm.go index e53700620..34ca1e21b 100644 --- a/llms/vertexai/vertexai_palm_llm.go +++ b/llms/vertexai/vertexai_palm_llm.go @@ -41,7 +41,7 @@ func (o *LLM) Call(ctx context.Context, prompt string, options ...llms.CallOptio func (o *LLM) Generate(ctx context.Context, prompts []string, options ...llms.CallOption) ([]*llms.Generation, error) { if o.CallbacksHandler != nil { - o.CallbacksHandler.HandleLLMStart(prompts) + o.CallbacksHandler.HandleLLMStart(ctx, prompts) } opts := llms.CallOptions{} @@ -65,7 +65,7 @@ func (o *LLM) Generate(ctx context.Context, prompts []string, options ...llms.Ca } if o.CallbacksHandler != nil { - o.CallbacksHandler.HandleLLMEnd(llms.LLMResult{Generations: [][]*llms.Generation{generations}}) + o.CallbacksHandler.HandleLLMEnd(ctx, llms.LLMResult{Generations: [][]*llms.Generation{generations}}) } return generations, nil } diff --git a/tools/calculator.go b/tools/calculator.go index f3af09db9..4740d66cf 100644 --- a/tools/calculator.go +++ b/tools/calculator.go @@ -30,9 +30,9 @@ func (c Calculator) Name() string { // Call evaluates the input using a starlak evaluator and returns the result as a // string. If the evaluator errors the error is given in the result to give the // agent the ability to retry. -func (c Calculator) Call(_ context.Context, input string) (string, error) { +func (c Calculator) Call(ctx context.Context, input string) (string, error) { if c.CallbacksHandler != nil { - c.CallbacksHandler.HandleToolStart(input) + c.CallbacksHandler.HandleToolStart(ctx, input) } v, err := starlark.Eval(&starlark.Thread{Name: "main"}, "input", input, math.Module.Members) @@ -42,7 +42,7 @@ func (c Calculator) Call(_ context.Context, input string) (string, error) { result := v.String() if c.CallbacksHandler != nil { - c.CallbacksHandler.HandleToolEnd(result) + c.CallbacksHandler.HandleToolEnd(ctx, result) } return result, nil diff --git a/tools/duckduckgo/ddg.go b/tools/duckduckgo/ddg.go index 8d740141a..5be3ad55d 100644 --- a/tools/duckduckgo/ddg.go +++ b/tools/duckduckgo/ddg.go @@ -44,7 +44,7 @@ func (t Tool) Description() string { // Call performs the search and return the result. func (t Tool) Call(ctx context.Context, input string) (string, error) { if t.CallbacksHandler != nil { - t.CallbacksHandler.HandleToolStart(input) + t.CallbacksHandler.HandleToolStart(ctx, input) } result, err := t.client.Search(ctx, input) @@ -56,7 +56,7 @@ func (t Tool) Call(ctx context.Context, input string) (string, error) { } if t.CallbacksHandler != nil { - t.CallbacksHandler.HandleToolEnd(result) + t.CallbacksHandler.HandleToolEnd(ctx, result) } return result, nil diff --git a/tools/serpapi/serpapi.go b/tools/serpapi/serpapi.go index 65c24f963..2890c912f 100644 --- a/tools/serpapi/serpapi.go +++ b/tools/serpapi/serpapi.go @@ -46,7 +46,7 @@ func (t Tool) Description() string { func (t Tool) Call(ctx context.Context, input string) (string, error) { if t.CallbacksHandler != nil { - t.CallbacksHandler.HandleToolStart(input) + t.CallbacksHandler.HandleToolStart(ctx, input) } result, err := t.client.Search(ctx, input) @@ -59,7 +59,7 @@ func (t Tool) Call(ctx context.Context, input string) (string, error) { } if t.CallbacksHandler != nil { - t.CallbacksHandler.HandleToolEnd(result) + t.CallbacksHandler.HandleToolEnd(ctx, result) } return strings.Join(strings.Fields(result), " "), nil diff --git a/tools/wikipedia/wikipedia.go b/tools/wikipedia/wikipedia.go index 0cebebe24..b0ecf96f1 100644 --- a/tools/wikipedia/wikipedia.go +++ b/tools/wikipedia/wikipedia.go @@ -60,7 +60,7 @@ func (t Tool) Description() string { // the first part of the documents combined. func (t Tool) Call(ctx context.Context, input string) (string, error) { if t.CallbacksHandler != nil { - t.CallbacksHandler.HandleToolStart(input) + t.CallbacksHandler.HandleToolStart(ctx, input) } searchResult, err := search(ctx, t.TopK, input, t.LanguageCode, t.UserAgent) @@ -92,7 +92,7 @@ func (t Tool) Call(ctx context.Context, input string) (string, error) { } if t.CallbacksHandler != nil { - t.CallbacksHandler.HandleToolEnd(result) + t.CallbacksHandler.HandleToolEnd(ctx, result) } return result, nil diff --git a/tools/zapier/zapier.go b/tools/zapier/zapier.go index f2c06f6c7..24a23968f 100644 --- a/tools/zapier/zapier.go +++ b/tools/zapier/zapier.go @@ -80,7 +80,7 @@ func (t Tool) Description() string { func (t Tool) Call(ctx context.Context, input string) (string, error) { if t.CallbacksHandler != nil { - t.CallbacksHandler.HandleToolStart(input) + t.CallbacksHandler.HandleToolStart(ctx, input) } result, err := t.client.ExecuteAsString(ctx, t.actionID, input, t.params) @@ -89,7 +89,7 @@ func (t Tool) Call(ctx context.Context, input string) (string, error) { } if t.CallbacksHandler != nil { - t.CallbacksHandler.HandleToolEnd(result) + t.CallbacksHandler.HandleToolEnd(ctx, result) } return result, nil diff --git a/vectorstores/vectorstores.go b/vectorstores/vectorstores.go index 8927bbf08..69e1778c3 100644 --- a/vectorstores/vectorstores.go +++ b/vectorstores/vectorstores.go @@ -27,7 +27,7 @@ var _ schema.Retriever = Retriever{} // GetRelevantDocuments returns documents using the vector store. func (r Retriever) GetRelevantDocuments(ctx context.Context, query string) ([]schema.Document, error) { if r.CallbacksHandler != nil { - r.CallbacksHandler.HandleRetrieverStart(query) + r.CallbacksHandler.HandleRetrieverStart(ctx, query) } docs, err := r.v.SimilaritySearch(ctx, query, r.numDocs, r.options...) @@ -36,7 +36,7 @@ func (r Retriever) GetRelevantDocuments(ctx context.Context, query string) ([]sc } if r.CallbacksHandler != nil { - r.CallbacksHandler.HandleRetrieverEnd(docs) + r.CallbacksHandler.HandleRetrieverEnd(ctx, docs) } return docs, nil From c9460de7bf339ab8143d5544851aa3d2eeb9d341 Mon Sep 17 00:00:00 2001 From: Travis Cline Date: Fri, 25 Aug 2023 19:22:17 -0700 Subject: [PATCH 11/11] openai: Fix lint issues --- callbacks/log.go | 20 ++++++++++---------- llms/openai/openaillm_chat.go | 17 ++++++++++++----- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/callbacks/log.go b/callbacks/log.go index f309f4620..5a03c14ba 100644 --- a/callbacks/log.go +++ b/callbacks/log.go @@ -15,43 +15,43 @@ type LogHandler struct{} var _ Handler = LogHandler{} -func (l LogHandler) HandleText(ctx context.Context, text string) { +func (l LogHandler) HandleText(_ context.Context, text string) { fmt.Println(text) } -func (l LogHandler) HandleLLMStart(ctx context.Context, prompts []string) { +func (l LogHandler) HandleLLMStart(_ context.Context, prompts []string) { fmt.Println("Entering LLM with prompts:", prompts) } -func (l LogHandler) HandleLLMEnd(ctx context.Context, output llms.LLMResult) { +func (l LogHandler) HandleLLMEnd(_ context.Context, output llms.LLMResult) { fmt.Println("Exiting LLM with results:", formatLLMResult(output)) } -func (l LogHandler) HandleChainStart(ctx context.Context, inputs map[string]any) { +func (l LogHandler) HandleChainStart(_ context.Context, inputs map[string]any) { fmt.Println("Entering chain with inputs:", formatChainValues(inputs)) } -func (l LogHandler) HandleChainEnd(ctx context.Context, outputs map[string]any) { +func (l LogHandler) HandleChainEnd(_ context.Context, outputs map[string]any) { fmt.Println("Exiting chain with outputs:", formatChainValues(outputs)) } -func (l LogHandler) HandleToolStart(ctx context.Context, input string) { +func (l LogHandler) HandleToolStart(_ context.Context, input string) { fmt.Println("Entering tool with input:", removeNewLines(input)) } -func (l LogHandler) HandleToolEnd(ctx context.Context, output string) { +func (l LogHandler) HandleToolEnd(_ context.Context, output string) { fmt.Println("Exiting tool with output:", removeNewLines(output)) } -func (l LogHandler) HandleAgentAction(ctx context.Context, action schema.AgentAction) { +func (l LogHandler) HandleAgentAction(_ context.Context, action schema.AgentAction) { fmt.Println("Agent selected action:", formatAgentAction(action)) } -func (l LogHandler) HandleRetrieverStart(ctx context.Context, query string) { +func (l LogHandler) HandleRetrieverStart(_ context.Context, query string) { fmt.Println("Entering retriever with query:", removeNewLines(query)) } -func (l LogHandler) HandleRetrieverEnd(ctx context.Context, documents []schema.Document) { +func (l LogHandler) HandleRetrieverEnd(_ context.Context, documents []schema.Document) { fmt.Println("Exiting retirer with documents:", documents) } diff --git a/llms/openai/openaillm_chat.go b/llms/openai/openaillm_chat.go index f536c67ef..9507f559a 100644 --- a/llms/openai/openaillm_chat.go +++ b/llms/openai/openaillm_chat.go @@ -17,6 +17,13 @@ type Chat struct { client *openaiclient.Client } +const ( + RoleSystem = "system" + RoleAssistant = "assistant" + RoleUser = "user" + RoleFunction = "function" +) + var ( _ llms.ChatLLM = (*Chat)(nil) _ llms.LanguageModel = (*Chat)(nil) @@ -62,9 +69,9 @@ func (o *Chat) Generate(ctx context.Context, messageSets [][]schema.ChatMessage, typ := m.GetType() switch typ { case schema.ChatMessageTypeSystem: - msg.Role = "system" + msg.Role = RoleSystem case schema.ChatMessageTypeAI: - msg.Role = "assistant" + msg.Role = RoleAssistant if aiChatMsg, ok := m.(schema.AIChatMessage); ok && aiChatMsg.FunctionCall != nil { msg.FunctionCall = &openaiclient.FunctionCall{ Name: aiChatMsg.FunctionCall.Name, @@ -72,11 +79,11 @@ func (o *Chat) Generate(ctx context.Context, messageSets [][]schema.ChatMessage, } } case schema.ChatMessageTypeHuman: - msg.Role = "user" + msg.Role = RoleUser case schema.ChatMessageTypeGeneric: - msg.Role = "user" + msg.Role = RoleUser case schema.ChatMessageTypeFunction: - msg.Role = "function" + msg.Role = RoleFunction } if n, ok := m.(schema.Named); ok { msg.Name = n.GetName()