callbacks

package
v0.7.17 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 30, 2025 License: Apache-2.0 Imports: 12 Imported by: 23

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EmbeddingCallbackHandler

type EmbeddingCallbackHandler struct {
	OnStart func(ctx context.Context, runInfo *callbacks.RunInfo, input *embedding.CallbackInput) context.Context
	OnEnd   func(ctx context.Context, runInfo *callbacks.RunInfo, output *embedding.CallbackOutput) context.Context
	OnError func(ctx context.Context, runInfo *callbacks.RunInfo, err error) context.Context
}

EmbeddingCallbackHandler is the handler for the embedding callback.

func (*EmbeddingCallbackHandler) Needed

Needed checks if the callback handler is needed for the given timing.

type HandlerHelper

type HandlerHelper struct {
	// contains filtered or unexported fields
}

HandlerHelper is a builder for creating a callbacks.Handler with specific handlers for different component types. create a handler with callbacks.NewHandlerHelper(). eg.

helper := template.NewHandlerHelper().
	ChatModel(&model.IndexerCallbackHandler{}).
	Prompt(&prompt.IndexerCallbackHandler{}).
	Handler()

then use the handler with runnable.Invoke(ctx, input, compose.WithCallbacks(handler))

func NewHandlerHelper

func NewHandlerHelper() *HandlerHelper

NewHandlerHelper creates a new component template handler builder. This builder can be used to configure and build a component template handler, which can handle callback events for different components with its own struct definition, and fallbackTemplate can be used to handle scenarios where none of the cases are hit as a fallback.

func (*HandlerHelper) Chain

func (c *HandlerHelper) Chain(handler callbacks.Handler) *HandlerHelper

Chain sets the chain handler for the handler helper, which will be called when the chain is executed.

func (*HandlerHelper) ChatModel

func (c *HandlerHelper) ChatModel(handler *ModelCallbackHandler) *HandlerHelper

ChatModel sets the chat model handler for the handler helper, which will be called when the chat model component is executed.

func (*HandlerHelper) Embedding

func (c *HandlerHelper) Embedding(handler *EmbeddingCallbackHandler) *HandlerHelper

Embedding sets the embedding handler for the handler helper, which will be called when the embedding component is executed.

func (*HandlerHelper) Graph

func (c *HandlerHelper) Graph(handler callbacks.Handler) *HandlerHelper

Graph sets the graph handler for the handler helper, which will be called when the graph is executed.

func (*HandlerHelper) Handler

func (c *HandlerHelper) Handler() callbacks.Handler

Handler returns the callbacks.Handler created by HandlerHelper.

func (*HandlerHelper) Indexer

func (c *HandlerHelper) Indexer(handler *IndexerCallbackHandler) *HandlerHelper

Indexer sets the indexer handler for the handler helper, which will be called when the indexer component is executed.

func (*HandlerHelper) Lambda

func (c *HandlerHelper) Lambda(handler callbacks.Handler) *HandlerHelper

Lambda sets the lambda handler for the handler helper, which will be called when the lambda is executed.

func (*HandlerHelper) Loader

func (c *HandlerHelper) Loader(handler *LoaderCallbackHandler) *HandlerHelper

Loader sets the loader handler for the handler helper, which will be called when the loader component is executed.

func (*HandlerHelper) Prompt

func (c *HandlerHelper) Prompt(handler *PromptCallbackHandler) *HandlerHelper

Prompt sets the prompt handler for the handler helper, which will be called when the prompt component is executed.

func (*HandlerHelper) Retriever

func (c *HandlerHelper) Retriever(handler *RetrieverCallbackHandler) *HandlerHelper

Retriever sets the retriever handler for the handler helper, which will be called when the retriever component is executed.

func (*HandlerHelper) Tool

func (c *HandlerHelper) Tool(handler *ToolCallbackHandler) *HandlerHelper

Tool sets the tool handler for the handler helper, which will be called when the tool component is executed.

func (*HandlerHelper) ToolsNode

func (c *HandlerHelper) ToolsNode(handler *ToolsNodeCallbackHandlers) *HandlerHelper

ToolsNode sets the tools node handler for the handler helper, which will be called when the tools node is executed.

func (*HandlerHelper) Transformer

func (c *HandlerHelper) Transformer(handler *TransformerCallbackHandler) *HandlerHelper

Transformer sets the transformer handler for the handler helper, which will be called when the transformer component is executed.

type IndexerCallbackHandler

type IndexerCallbackHandler struct {
	OnStart func(ctx context.Context, runInfo *callbacks.RunInfo, input *indexer.CallbackInput) context.Context
	OnEnd   func(ctx context.Context, runInfo *callbacks.RunInfo, output *indexer.CallbackOutput) context.Context
	OnError func(ctx context.Context, runInfo *callbacks.RunInfo, err error) context.Context
}

IndexerCallbackHandler is the handler for the indexer callback.

func (*IndexerCallbackHandler) Needed

Needed checks if the callback handler is needed for the given timing.

type LoaderCallbackHandler

type LoaderCallbackHandler struct {
	OnStart func(ctx context.Context, runInfo *callbacks.RunInfo, input *document.LoaderCallbackInput) context.Context
	OnEnd   func(ctx context.Context, runInfo *callbacks.RunInfo, output *document.LoaderCallbackOutput) context.Context
	OnError func(ctx context.Context, runInfo *callbacks.RunInfo, err error) context.Context
}

LoaderCallbackHandler is the handler for the loader callback.

func (*LoaderCallbackHandler) Needed

Needed checks if the callback handler is needed for the given timing.

type ModelCallbackHandler

type ModelCallbackHandler struct {
	OnStart               func(ctx context.Context, runInfo *callbacks.RunInfo, input *model.CallbackInput) context.Context
	OnEnd                 func(ctx context.Context, runInfo *callbacks.RunInfo, output *model.CallbackOutput) context.Context
	OnEndWithStreamOutput func(ctx context.Context, runInfo *callbacks.RunInfo, output *schema.StreamReader[*model.CallbackOutput]) context.Context
	OnError               func(ctx context.Context, runInfo *callbacks.RunInfo, err error) context.Context
}

ModelCallbackHandler is the handler for the model callback.

func (*ModelCallbackHandler) Needed

Needed checks if the callback handler is needed for the given timing.

type PromptCallbackHandler

type PromptCallbackHandler struct {
	// OnStart is the callback function for the start of the callback.
	OnStart func(ctx context.Context, runInfo *callbacks.RunInfo, input *prompt.CallbackInput) context.Context
	// OnEnd is the callback function for the end of the callback.
	OnEnd func(ctx context.Context, runInfo *callbacks.RunInfo, output *prompt.CallbackOutput) context.Context
	// OnError is the callback function for the error of the callback.
	OnError func(ctx context.Context, runInfo *callbacks.RunInfo, err error) context.Context
}

PromptCallbackHandler is the handler for the callback.

func (*PromptCallbackHandler) Needed

Needed checks if the callback handler is needed for the given timing.

type RetrieverCallbackHandler

type RetrieverCallbackHandler struct {
	// OnStart is the callback function for the start of the retriever.
	OnStart func(ctx context.Context, runInfo *callbacks.RunInfo, input *retriever.CallbackInput) context.Context
	// OnEnd is the callback function for the end of the retriever.
	OnEnd func(ctx context.Context, runInfo *callbacks.RunInfo, output *retriever.CallbackOutput) context.Context
	// OnError is the callback function for the error of the retriever.
	OnError func(ctx context.Context, runInfo *callbacks.RunInfo, err error) context.Context
}

RetrieverCallbackHandler is the handler for the retriever callback.

func (*RetrieverCallbackHandler) Needed

Needed checks if the callback handler is needed for the given timing.

type ToolCallbackHandler

type ToolCallbackHandler struct {
	OnStart               func(ctx context.Context, info *callbacks.RunInfo, input *tool.CallbackInput) context.Context
	OnEnd                 func(ctx context.Context, info *callbacks.RunInfo, output *tool.CallbackOutput) context.Context
	OnEndWithStreamOutput func(ctx context.Context, info *callbacks.RunInfo, output *schema.StreamReader[*tool.CallbackOutput]) context.Context
	OnError               func(ctx context.Context, info *callbacks.RunInfo, err error) context.Context
}

ToolCallbackHandler is the handler for the tool callback.

func (*ToolCallbackHandler) Needed

Needed checks if the callback handler is needed for the given timing.

type ToolsNodeCallbackHandlers added in v0.3.4

type ToolsNodeCallbackHandlers struct {
	OnStart               func(ctx context.Context, info *callbacks.RunInfo, input *schema.Message) context.Context
	OnEnd                 func(ctx context.Context, info *callbacks.RunInfo, input []*schema.Message) context.Context
	OnEndWithStreamOutput func(ctx context.Context, info *callbacks.RunInfo, output *schema.StreamReader[[]*schema.Message]) context.Context
	OnError               func(ctx context.Context, info *callbacks.RunInfo, err error) context.Context
}

func (*ToolsNodeCallbackHandlers) Needed added in v0.3.4

type TransformerCallbackHandler

type TransformerCallbackHandler struct {
	OnStart func(ctx context.Context, runInfo *callbacks.RunInfo, input *document.TransformerCallbackInput) context.Context
	OnEnd   func(ctx context.Context, runInfo *callbacks.RunInfo, output *document.TransformerCallbackOutput) context.Context
	OnError func(ctx context.Context, runInfo *callbacks.RunInfo, err error) context.Context
}

TransformerCallbackHandler is the handler for the transformer callback.

func (*TransformerCallbackHandler) Needed

Needed checks if the callback handler is needed for the given timing.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL