Documentation ¶
Overview ¶
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.
Index ¶
- Variables
- type AgentFinalStreamHandler
- type CombiningHandler
- func (l CombiningHandler) HandleAgentAction(ctx context.Context, action schema.AgentAction)
- func (l CombiningHandler) HandleAgentFinish(ctx context.Context, finish schema.AgentFinish)
- func (l CombiningHandler) HandleChainEnd(ctx context.Context, outputs map[string]any)
- func (l CombiningHandler) HandleChainError(ctx context.Context, err error)
- func (l CombiningHandler) HandleChainStart(ctx context.Context, inputs map[string]any)
- func (l CombiningHandler) HandleLLMError(ctx context.Context, err error)
- func (l CombiningHandler) HandleLLMGenerateContentEnd(ctx context.Context, res *llms.ContentResponse)
- func (l CombiningHandler) HandleLLMGenerateContentStart(ctx context.Context, ms []llms.MessageContent)
- func (l CombiningHandler) HandleLLMStart(ctx context.Context, prompts []string)
- func (l CombiningHandler) HandleRetrieverEnd(ctx context.Context, query string, documents []schema.Document)
- func (l CombiningHandler) HandleRetrieverStart(ctx context.Context, query string)
- func (l CombiningHandler) HandleStreamingFunc(ctx context.Context, chunk []byte)
- func (l CombiningHandler) HandleText(ctx context.Context, text string)
- func (l CombiningHandler) HandleToolEnd(ctx context.Context, output string)
- func (l CombiningHandler) HandleToolError(ctx context.Context, err error)
- func (l CombiningHandler) HandleToolStart(ctx context.Context, input string)
- type Handler
- type HandlerHaver
- type LogHandler
- func (l LogHandler) HandleAgentAction(_ context.Context, action schema.AgentAction)
- func (l LogHandler) HandleAgentFinish(_ context.Context, finish schema.AgentFinish)
- func (l LogHandler) HandleChainEnd(_ context.Context, outputs map[string]any)
- func (l LogHandler) HandleChainError(_ context.Context, err error)
- func (l LogHandler) HandleChainStart(_ context.Context, inputs map[string]any)
- func (l LogHandler) HandleLLMError(_ context.Context, err error)
- func (l LogHandler) HandleLLMGenerateContentEnd(_ context.Context, res *llms.ContentResponse)
- func (l LogHandler) HandleLLMGenerateContentStart(_ context.Context, ms []llms.MessageContent)
- func (l LogHandler) HandleLLMStart(_ context.Context, prompts []string)
- func (l LogHandler) HandleRetrieverEnd(_ context.Context, query string, documents []schema.Document)
- func (l LogHandler) HandleRetrieverStart(_ context.Context, query string)
- func (l LogHandler) HandleStreamingFunc(_ context.Context, chunk []byte)
- func (l LogHandler) HandleText(_ context.Context, text string)
- func (l LogHandler) HandleToolEnd(_ context.Context, output string)
- func (l LogHandler) HandleToolError(_ context.Context, err error)
- func (l LogHandler) HandleToolStart(_ context.Context, input string)
- type SimpleHandler
- func (SimpleHandler) HandleAgentAction(context.Context, schema.AgentAction)
- func (SimpleHandler) HandleAgentFinish(context.Context, schema.AgentFinish)
- func (SimpleHandler) HandleChainEnd(context.Context, map[string]any)
- func (SimpleHandler) HandleChainError(context.Context, error)
- func (SimpleHandler) HandleChainStart(context.Context, map[string]any)
- func (SimpleHandler) HandleLLMError(context.Context, error)
- func (SimpleHandler) HandleLLMGenerateContentEnd(context.Context, *llms.ContentResponse)
- func (SimpleHandler) HandleLLMGenerateContentStart(context.Context, []llms.MessageContent)
- func (SimpleHandler) HandleLLMStart(context.Context, []string)
- func (SimpleHandler) HandleRetrieverEnd(context.Context, string, []schema.Document)
- func (SimpleHandler) HandleRetrieverStart(context.Context, string)
- func (SimpleHandler) HandleStreamingFunc(context.Context, []byte)
- func (SimpleHandler) HandleText(context.Context, string)
- func (SimpleHandler) HandleToolEnd(context.Context, string)
- func (SimpleHandler) HandleToolError(context.Context, error)
- func (SimpleHandler) HandleToolStart(context.Context, string)
- type StreamLogHandler
Constants ¶
This section is empty.
Variables ¶
var DefaultKeywords = []string{"Final Answer:", "Final:", "AI:"}
DefaultKeywords is map of the agents final out prefix keywords.
Functions ¶
This section is empty.
Types ¶
type AgentFinalStreamHandler ¶
type AgentFinalStreamHandler struct { SimpleHandler Keywords []string LastTokens string KeywordDetected bool PrintOutput bool // contains filtered or unexported fields }
func NewFinalStreamHandler ¶
func NewFinalStreamHandler(keywords ...string) *AgentFinalStreamHandler
NewFinalStreamHandler creates a new instance of the AgentFinalStreamHandler struct.
It accepts a variadic number of strings as keywords. If any keywords are provided, the DefaultKeywords variable is updated with the provided keywords.
DefaultKeywords is map of the agents final out prefix keywords.
The function returns a pointer to the created AgentFinalStreamHandler struct.
func (*AgentFinalStreamHandler) GetEgress ¶
func (handler *AgentFinalStreamHandler) GetEgress() chan []byte
GetEgress returns the egress channel of the AgentFinalStreamHandler.
It does not take any parameters. It returns a channel of type []byte.
func (*AgentFinalStreamHandler) HandleStreamingFunc ¶
func (handler *AgentFinalStreamHandler) HandleStreamingFunc(_ context.Context, chunk []byte)
HandleStreamingFunc implements the callback interface that handles the streaming of data in the AgentFinalStreamHandler. The handler reads the incoming data and checks for the agents final output keywords, ie, `Final Answer:`, `Final:`, `AI:`. Upon detection of the keyword, it starst to stream the agents final output to the egress channel.
It takes in the context and a chunk of bytes as parameters. There is no return type for this function.
func (*AgentFinalStreamHandler) ReadFromEgress ¶
func (handler *AgentFinalStreamHandler) ReadFromEgress( ctx context.Context, callback func(ctx context.Context, chunk []byte), )
ReadFromEgress reads data from the egress channel and invokes the provided callback function with each chunk of data.
The callback function receives two parameters: - ctx: the context.Context object for the egress operation. - chunk: a byte slice representing a chunk of data from the egress channel.
type CombiningHandler ¶ added in v0.1.13
type CombiningHandler struct {
Callbacks []Handler
}
CombiningHandler is a callback handler that combine multi callbacks.
func (CombiningHandler) HandleAgentAction ¶ added in v0.1.13
func (l CombiningHandler) HandleAgentAction(ctx context.Context, action schema.AgentAction)
func (CombiningHandler) HandleAgentFinish ¶ added in v0.1.13
func (l CombiningHandler) HandleAgentFinish(ctx context.Context, finish schema.AgentFinish)
func (CombiningHandler) HandleChainEnd ¶ added in v0.1.13
func (l CombiningHandler) HandleChainEnd(ctx context.Context, outputs map[string]any)
func (CombiningHandler) HandleChainError ¶ added in v0.1.13
func (l CombiningHandler) HandleChainError(ctx context.Context, err error)
func (CombiningHandler) HandleChainStart ¶ added in v0.1.13
func (l CombiningHandler) HandleChainStart(ctx context.Context, inputs map[string]any)
func (CombiningHandler) HandleLLMError ¶ added in v0.1.13
func (l CombiningHandler) HandleLLMError(ctx context.Context, err error)
func (CombiningHandler) HandleLLMGenerateContentEnd ¶ added in v0.1.13
func (l CombiningHandler) HandleLLMGenerateContentEnd(ctx context.Context, res *llms.ContentResponse)
func (CombiningHandler) HandleLLMGenerateContentStart ¶ added in v0.1.13
func (l CombiningHandler) HandleLLMGenerateContentStart(ctx context.Context, ms []llms.MessageContent)
func (CombiningHandler) HandleLLMStart ¶ added in v0.1.13
func (l CombiningHandler) HandleLLMStart(ctx context.Context, prompts []string)
func (CombiningHandler) HandleRetrieverEnd ¶ added in v0.1.13
func (CombiningHandler) HandleRetrieverStart ¶ added in v0.1.13
func (l CombiningHandler) HandleRetrieverStart(ctx context.Context, query string)
func (CombiningHandler) HandleStreamingFunc ¶ added in v0.1.13
func (l CombiningHandler) HandleStreamingFunc(ctx context.Context, chunk []byte)
func (CombiningHandler) HandleText ¶ added in v0.1.13
func (l CombiningHandler) HandleText(ctx context.Context, text string)
func (CombiningHandler) HandleToolEnd ¶ added in v0.1.13
func (l CombiningHandler) HandleToolEnd(ctx context.Context, output string)
func (CombiningHandler) HandleToolError ¶ added in v0.1.13
func (l CombiningHandler) HandleToolError(ctx context.Context, err error)
func (CombiningHandler) HandleToolStart ¶ added in v0.1.13
func (l CombiningHandler) HandleToolStart(ctx context.Context, input string)
type Handler ¶
type Handler interface { HandleText(ctx context.Context, text string) HandleLLMStart(ctx context.Context, prompts []string) HandleLLMGenerateContentStart(ctx context.Context, ms []llms.MessageContent) HandleLLMGenerateContentEnd(ctx context.Context, res *llms.ContentResponse) HandleLLMError(ctx context.Context, err error) HandleChainStart(ctx context.Context, inputs map[string]any) HandleChainEnd(ctx context.Context, outputs map[string]any) HandleChainError(ctx context.Context, err error) HandleToolStart(ctx context.Context, input string) HandleToolEnd(ctx context.Context, output string) HandleToolError(ctx context.Context, err error) HandleAgentAction(ctx context.Context, action schema.AgentAction) HandleAgentFinish(ctx context.Context, finish schema.AgentFinish) HandleRetrieverStart(ctx context.Context, query string) HandleRetrieverEnd(ctx context.Context, query string, documents []schema.Document) HandleStreamingFunc(ctx context.Context, chunk []byte) }
Handler is the interface that allows for hooking into specific parts of an LLM application.
type HandlerHaver ¶
type HandlerHaver interface {
GetCallbackHandler() Handler
}
HandlerHaver is an interface used to get callbacks handler.
type LogHandler ¶
type LogHandler struct{}
LogHandler is a callback handler that prints to the standard output.
func (LogHandler) HandleAgentAction ¶
func (l LogHandler) HandleAgentAction(_ context.Context, action schema.AgentAction)
func (LogHandler) HandleAgentFinish ¶ added in v0.1.13
func (l LogHandler) HandleAgentFinish(_ context.Context, finish schema.AgentFinish)
func (LogHandler) HandleChainEnd ¶
func (l LogHandler) HandleChainEnd(_ context.Context, outputs map[string]any)
func (LogHandler) HandleChainError ¶ added in v0.1.13
func (l LogHandler) HandleChainError(_ context.Context, err error)
func (LogHandler) HandleChainStart ¶
func (l LogHandler) HandleChainStart(_ context.Context, inputs map[string]any)
func (LogHandler) HandleLLMError ¶ added in v0.1.13
func (l LogHandler) HandleLLMError(_ context.Context, err error)
func (LogHandler) HandleLLMGenerateContentEnd ¶ added in v0.1.10
func (l LogHandler) HandleLLMGenerateContentEnd(_ context.Context, res *llms.ContentResponse)
func (LogHandler) HandleLLMGenerateContentStart ¶ added in v0.1.10
func (l LogHandler) HandleLLMGenerateContentStart(_ context.Context, ms []llms.MessageContent)
func (LogHandler) HandleLLMStart ¶
func (l LogHandler) HandleLLMStart(_ context.Context, prompts []string)
func (LogHandler) HandleRetrieverEnd ¶
func (LogHandler) HandleRetrieverStart ¶
func (l LogHandler) HandleRetrieverStart(_ context.Context, query string)
func (LogHandler) HandleStreamingFunc ¶ added in v0.1.13
func (l LogHandler) HandleStreamingFunc(_ context.Context, chunk []byte)
func (LogHandler) HandleText ¶
func (l LogHandler) HandleText(_ context.Context, text string)
func (LogHandler) HandleToolEnd ¶
func (l LogHandler) HandleToolEnd(_ context.Context, output string)
func (LogHandler) HandleToolError ¶ added in v0.1.13
func (l LogHandler) HandleToolError(_ context.Context, err error)
func (LogHandler) HandleToolStart ¶
func (l LogHandler) HandleToolStart(_ context.Context, input string)
type SimpleHandler ¶
type SimpleHandler struct{}
func (SimpleHandler) HandleAgentAction ¶
func (SimpleHandler) HandleAgentAction(context.Context, schema.AgentAction)
func (SimpleHandler) HandleAgentFinish ¶ added in v0.1.13
func (SimpleHandler) HandleAgentFinish(context.Context, schema.AgentFinish)
func (SimpleHandler) HandleChainEnd ¶
func (SimpleHandler) HandleChainEnd(context.Context, map[string]any)
func (SimpleHandler) HandleChainError ¶ added in v0.1.13
func (SimpleHandler) HandleChainError(context.Context, error)
func (SimpleHandler) HandleChainStart ¶
func (SimpleHandler) HandleChainStart(context.Context, map[string]any)
func (SimpleHandler) HandleLLMError ¶ added in v0.1.13
func (SimpleHandler) HandleLLMError(context.Context, error)
func (SimpleHandler) HandleLLMGenerateContentEnd ¶ added in v0.1.10
func (SimpleHandler) HandleLLMGenerateContentEnd(context.Context, *llms.ContentResponse)
func (SimpleHandler) HandleLLMGenerateContentStart ¶ added in v0.1.10
func (SimpleHandler) HandleLLMGenerateContentStart(context.Context, []llms.MessageContent)
func (SimpleHandler) HandleLLMStart ¶
func (SimpleHandler) HandleLLMStart(context.Context, []string)
func (SimpleHandler) HandleRetrieverEnd ¶
func (SimpleHandler) HandleRetrieverStart ¶
func (SimpleHandler) HandleRetrieverStart(context.Context, string)
func (SimpleHandler) HandleStreamingFunc ¶
func (SimpleHandler) HandleStreamingFunc(context.Context, []byte)
func (SimpleHandler) HandleText ¶
func (SimpleHandler) HandleText(context.Context, string)
func (SimpleHandler) HandleToolEnd ¶
func (SimpleHandler) HandleToolEnd(context.Context, string)
func (SimpleHandler) HandleToolError ¶ added in v0.1.13
func (SimpleHandler) HandleToolError(context.Context, error)
func (SimpleHandler) HandleToolStart ¶
func (SimpleHandler) HandleToolStart(context.Context, string)
type StreamLogHandler ¶ added in v0.1.13
type StreamLogHandler struct {
SimpleHandler
}
StreamLogHandler is a callback handler that prints to the standard output streaming.
func (StreamLogHandler) HandleStreamingFunc ¶ added in v0.1.13
func (StreamLogHandler) HandleStreamingFunc(_ context.Context, chunk []byte)