Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support callback handler to llm chain #461

Merged
merged 2 commits into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion agents/conversational.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ func NewConversationalAgent(llm llms.LanguageModel, tools []tools.Tool, opts ...
}

return &ConversationalAgent{
Chain: chains.NewLLMChain(llm, options.getConversationalPrompt(tools)),
Chain: chains.NewLLMChain(
llm,
options.getConversationalPrompt(tools),
chains.WithCallback(options.callbacksHandler),
),
Tools: tools,
OutputKey: options.outputKey,
CallbacksHandler: options.callbacksHandler,
Expand Down
6 changes: 5 additions & 1 deletion agents/mrkl.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ func NewOneShotAgent(llm llms.LanguageModel, tools []tools.Tool, opts ...Creatio
}

return &OneShotZeroAgent{
Chain: chains.NewLLMChain(llm, options.getMrklPrompt(tools)),
Chain: chains.NewLLMChain(
llm,
options.getMrklPrompt(tools),
chains.WithCallback(options.callbacksHandler),
),
Tools: tools,
OutputKey: options.outputKey,
CallbacksHandler: options.callbacksHandler,
Expand Down
18 changes: 11 additions & 7 deletions chains/llm.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,18 @@ var (
)

// NewLLMChain creates a new LLMChain with an LLM and a prompt.
func NewLLMChain(llm llms.LanguageModel, prompt prompts.FormatPrompter) *LLMChain {
func NewLLMChain(llm llms.LanguageModel, prompt prompts.FormatPrompter, opts ...ChainCallOption) *LLMChain {
opt := &chainCallOption{}
for _, o := range opts {
o(opt)
}
chain := &LLMChain{
Prompt: prompt,
LLM: llm,
OutputParser: outputparser.NewSimple(),
Memory: memory.NewSimple(),

OutputKey: _llmChainDefaultOutputKey,
Prompt: prompt,
LLM: llm,
OutputParser: outputparser.NewSimple(),
Memory: memory.NewSimple(),
OutputKey: _llmChainDefaultOutputKey,
CallbacksHandler: opt.CallbackHandler,
}

return chain
Expand Down
Loading