Files
langchaingo/callbacks/callbacks.go
T
Dmitry Ng 6317685b67 feat: integrate streaming functionality across LLMs and callbacks
- Updated LLMs and callback interfaces to utilize a new streaming package for handling content chunks.
- Changed function signatures to accept streaming.Chunk instead of byte slices for better type safety and clarity.
- Enhanced examples and tests to demonstrate the new streaming capabilities, ensuring compatibility with existing functionality.
- Added reasoning and tool call handling in streaming responses for improved processing of LLM outputs.
2025-06-23 18:52:06 +03:00

38 lines
1.4 KiB
Go

package callbacks
import (
"context"
"github.com/vxcontrol/langchaingo/llms"
"github.com/vxcontrol/langchaingo/llms/streaming"
"github.com/vxcontrol/langchaingo/schema"
)
// Handler is the interface that allows for hooking into specific parts of an
// LLM application.
//
//nolint:all
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 streaming.Chunk)
}
// HandlerHaver is an interface used to get callbacks handler.
type HandlerHaver interface {
GetCallbackHandler() Handler
}