Documentation
¶
Overview ¶
Package maxim provides integration for Maxim's SDK as a Bifrost plugin. This file contains the main plugin implementation.
Index ¶
- Constants
- func Init(config *Config, logger schemas.Logger) (schemas.LLMPlugin, error)
- type Config
- type Plugin
- func (plugin *Plugin) Cleanup() error
- func (plugin *Plugin) GetName() string
- func (plugin *Plugin) HTTPTransportPostHook(ctx *schemas.BifrostContext, req *schemas.HTTPRequest, ...) error
- func (plugin *Plugin) HTTPTransportPreHook(ctx *schemas.BifrostContext, req *schemas.HTTPRequest) (*schemas.HTTPResponse, error)
- func (plugin *Plugin) HTTPTransportStreamChunkHook(ctx *schemas.BifrostContext, req *schemas.HTTPRequest, ...) (*schemas.BifrostStreamChunk, error)
- func (plugin *Plugin) PostLLMHook(ctx *schemas.BifrostContext, result *schemas.BifrostResponse, ...) (*schemas.BifrostResponse, *schemas.BifrostError, error)
- func (plugin *Plugin) PreLLMHook(ctx *schemas.BifrostContext, req *schemas.BifrostRequest) (*schemas.BifrostRequest, *schemas.LLMPluginShortCircuit, error)
Constants ¶
const ( PluginName string = "maxim" PluginLoggerPrefix string = "[Maxim Plugin]" )
PluginName is the canonical name for the maxim plugin.
const ( SessionIDKey schemas.BifrostContextKey = "session-id" TraceIDKey schemas.BifrostContextKey = "trace-id" TraceNameKey schemas.BifrostContextKey = "trace-name" GenerationIDKey schemas.BifrostContextKey = "generation-id" GenerationNameKey schemas.BifrostContextKey = "generation-name" TagsKey schemas.BifrostContextKey = "maxim-tags" LogRepoIDKey schemas.BifrostContextKey = "log-repo-id" )
TraceIDKey is the context key used to store and retrieve trace IDs. This constant provides a consistent key for tracking request traces throughout the request/response lifecycle.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶ added in v1.3.0
type Config struct {
LogRepoID string `json:"log_repo_id,omitempty"` // Optional - can be empty
APIKey string `json:"api_key"`
}
Config is the configuration for the maxim plugin.
- APIKey: API key for Maxim SDK authentication
- LogRepoID: Optional default ID for the Maxim logger instance
type Plugin ¶
type Plugin struct {
// contains filtered or unexported fields
}
Plugin implements the schemas.LLMPlugin interface for Maxim's logger. It provides request and response tracing functionality using Maxim logger, allowing detailed tracking of requests and responses across different log repositories.
Fields:
- mx: The Maxim SDK instance for creating new loggers
- defaultLogRepoId: Default log repository ID from config (optional)
- loggers: Map of log repo ID to logger instances
- loggerMutex: RW mutex for thread-safe access to loggers map
func (*Plugin) HTTPTransportPostHook ¶ added in v1.5.9
func (plugin *Plugin) HTTPTransportPostHook(ctx *schemas.BifrostContext, req *schemas.HTTPRequest, resp *schemas.HTTPResponse) error
HTTPTransportPostHook is not used for this plugin
func (*Plugin) HTTPTransportPreHook ¶ added in v1.5.9
func (plugin *Plugin) HTTPTransportPreHook(ctx *schemas.BifrostContext, req *schemas.HTTPRequest) (*schemas.HTTPResponse, error)
HTTPTransportPreHook is not used for this plugin
func (*Plugin) HTTPTransportStreamChunkHook ¶ added in v1.5.14
func (plugin *Plugin) HTTPTransportStreamChunkHook(ctx *schemas.BifrostContext, req *schemas.HTTPRequest, chunk *schemas.BifrostStreamChunk) (*schemas.BifrostStreamChunk, error)
HTTPTransportStreamChunkHook passes through streaming chunks unchanged
func (*Plugin) PostLLMHook ¶ added in v1.5.16
func (plugin *Plugin) PostLLMHook(ctx *schemas.BifrostContext, result *schemas.BifrostResponse, bifrostErr *schemas.BifrostError) (*schemas.BifrostResponse, *schemas.BifrostError, error)
PostLLMHook is called after a request has been processed by Bifrost. It completes the request trace by: - Adding response data to the generation if a generation ID exists - Logging error details if bifrostErr is provided - Ending the generation if it exists - Ending the trace if a trace ID exists - Flushing all pending log data
The function gracefully handles cases where trace or generation IDs may be missing, ensuring that partial logging is still performed when possible.
Parameters:
- ctx: Pointer to the schemas.BifrostContext containing trace/generation IDs
- result: The Bifrost response to be traced
- bifrostErr: The BifrostError returned by the request, if any
Returns:
- *schemas.BifrostResponse: The original response, unmodified
- *schemas.BifrostError: The original error, unmodified
- error: Never returns an error as it handles missing IDs gracefully
func (*Plugin) PreLLMHook ¶ added in v1.5.16
func (plugin *Plugin) PreLLMHook(ctx *schemas.BifrostContext, req *schemas.BifrostRequest) (*schemas.BifrostRequest, *schemas.LLMPluginShortCircuit, error)
PreLLMHook is called before a request is processed by Bifrost. It manages trace and generation tracking for incoming requests by either: - Creating a new trace if none exists - Reusing an existing trace ID from the context - Creating a new generation within an existing trace - Skipping trace/generation creation if they already exist
The function handles both chat completion and text completion requests, capturing relevant metadata such as: - Request type (chat/text completion) - Model information - Message content and role - Model parameters
Parameters:
- ctx: Pointer to the schemas.BifrostContext that may contain existing trace/generation IDs
- req: The incoming Bifrost request to be traced
Returns:
- *schemas.BifrostRequest: The original request, unmodified
- error: Any error that occurred during trace/generation creation