Documentation
¶
Index ¶
- type AsyncRecorder
- func (a *AsyncRecorder) RecordInterception(ctx context.Context, req *InterceptionRecord) error
- func (a *AsyncRecorder) RecordInterceptionEnded(ctx context.Context, req *InterceptionRecordEnded) error
- func (a *AsyncRecorder) RecordPromptUsage(ctx context.Context, req *PromptUsageRecord) error
- func (a *AsyncRecorder) RecordTokenUsage(ctx context.Context, req *TokenUsageRecord) error
- func (a *AsyncRecorder) RecordToolUsage(ctx context.Context, req *ToolUsageRecord) error
- func (a *AsyncRecorder) Wait()
- func (a *AsyncRecorder) WithInitiatorID(initiatorID string)
- func (a *AsyncRecorder) WithMetrics(m any)
- func (a *AsyncRecorder) WithModel(model string)
- func (a *AsyncRecorder) WithProvider(provider string)
- type InterceptionRecord
- type InterceptionRecordEnded
- type Metadata
- type PromptUsageRecord
- type Recorder
- type RecorderWrapper
- func (r *RecorderWrapper) RecordInterception(ctx context.Context, req *InterceptionRecord) (outErr error)
- func (r *RecorderWrapper) RecordInterceptionEnded(ctx context.Context, req *InterceptionRecordEnded) (outErr error)
- func (r *RecorderWrapper) RecordPromptUsage(ctx context.Context, req *PromptUsageRecord) (outErr error)
- func (r *RecorderWrapper) RecordTokenUsage(ctx context.Context, req *TokenUsageRecord) (outErr error)
- func (r *RecorderWrapper) RecordToolUsage(ctx context.Context, req *ToolUsageRecord) (outErr error)
- type TokenUsageRecord
- type ToolArgs
- type ToolUsageRecord
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AsyncRecorder ¶
type AsyncRecorder struct {
// contains filtered or unexported fields
}
AsyncRecorder calls Recorder methods asynchronously and logs any errors which may occur.
func NewAsyncRecorder ¶
func (*AsyncRecorder) RecordInterception ¶
func (a *AsyncRecorder) RecordInterception(ctx context.Context, req *InterceptionRecord) error
RecordInterception must NOT be called asynchronously. If an interception cannot be recorded, the whole request should fail.
func (*AsyncRecorder) RecordInterceptionEnded ¶
func (a *AsyncRecorder) RecordInterceptionEnded(ctx context.Context, req *InterceptionRecordEnded) error
func (*AsyncRecorder) RecordPromptUsage ¶
func (a *AsyncRecorder) RecordPromptUsage(ctx context.Context, req *PromptUsageRecord) error
func (*AsyncRecorder) RecordTokenUsage ¶
func (a *AsyncRecorder) RecordTokenUsage(ctx context.Context, req *TokenUsageRecord) error
func (*AsyncRecorder) RecordToolUsage ¶
func (a *AsyncRecorder) RecordToolUsage(ctx context.Context, req *ToolUsageRecord) error
func (*AsyncRecorder) Wait ¶
func (a *AsyncRecorder) Wait()
func (*AsyncRecorder) WithInitiatorID ¶
func (a *AsyncRecorder) WithInitiatorID(initiatorID string)
func (*AsyncRecorder) WithMetrics ¶
func (a *AsyncRecorder) WithMetrics(m any)
func (*AsyncRecorder) WithModel ¶
func (a *AsyncRecorder) WithModel(model string)
func (*AsyncRecorder) WithProvider ¶
func (a *AsyncRecorder) WithProvider(provider string)
type InterceptionRecord ¶
type InterceptionRecordEnded ¶
type PromptUsageRecord ¶
type Recorder ¶
type Recorder interface {
// RecordInterception records metadata about an interception with an upstream AI provider.
RecordInterception(ctx context.Context, req *InterceptionRecord) error
// RecordInterceptionEnded records that given interception has completed.
RecordInterceptionEnded(ctx context.Context, req *InterceptionRecordEnded) error
// RecordTokenUsage records the tokens used in an interception with an upstream AI provider.
RecordTokenUsage(ctx context.Context, req *TokenUsageRecord) error
// RecordPromptUsage records the prompts used in an interception with an upstream AI provider.
RecordPromptUsage(ctx context.Context, req *PromptUsageRecord) error
// RecordToolUsage records the tools used in an interception with an upstream AI provider.
RecordToolUsage(ctx context.Context, req *ToolUsageRecord) error
}
Recorder describes all the possible usage information we need to capture during interactions with AI providers. Additionally, it introduces the concept of an "Interception", which includes information about which provider/model was used and by whom. All usage records should reference this Interception by ID.
type RecorderWrapper ¶
type RecorderWrapper struct {
// contains filtered or unexported fields
}
RecorderWrapper is a convenience struct which implements RecorderClient and resolves a client before calling each method. It also sets the start/creation time of each record.
func NewRecorder ¶
func (*RecorderWrapper) RecordInterception ¶
func (r *RecorderWrapper) RecordInterception(ctx context.Context, req *InterceptionRecord) (outErr error)
func (*RecorderWrapper) RecordInterceptionEnded ¶
func (r *RecorderWrapper) RecordInterceptionEnded(ctx context.Context, req *InterceptionRecordEnded) (outErr error)
func (*RecorderWrapper) RecordPromptUsage ¶
func (r *RecorderWrapper) RecordPromptUsage(ctx context.Context, req *PromptUsageRecord) (outErr error)
func (*RecorderWrapper) RecordTokenUsage ¶
func (r *RecorderWrapper) RecordTokenUsage(ctx context.Context, req *TokenUsageRecord) (outErr error)
func (*RecorderWrapper) RecordToolUsage ¶
func (r *RecorderWrapper) RecordToolUsage(ctx context.Context, req *ToolUsageRecord) (outErr error)
type TokenUsageRecord ¶
type TokenUsageRecord struct {
InterceptionID string
MsgID string
Input, Output int64
// ExtraTokenTypes holds token types which *may* exist over and above input/output.
// These should ultimately get merged into [Metadata], but it's useful to keep these
// with their actual type (int64) since [Metadata] is a map[string]any.
ExtraTokenTypes map[string]int64
Metadata Metadata
CreatedAt time.Time
}