Documentation
¶
Overview ¶
Package logstore provides a logs store for Bifrost.
Index ¶
- type Config
- type Log
- type LogStore
- type LogStoreType
- type PaginationOptions
- type SQLiteConfig
- type SQLiteLogStore
- func (s *SQLiteLogStore) CleanupLogs(since time.Time) error
- func (s *SQLiteLogStore) Create(entry *Log) error
- func (s *SQLiteLogStore) FindAll(query any, fields ...string) ([]*Log, error)
- func (s *SQLiteLogStore) FindFirst(query any, fields ...string) (*Log, error)
- func (s *SQLiteLogStore) SearchLogs(filters SearchFilters, pagination PaginationOptions) (*SearchResult, error)
- func (s *SQLiteLogStore) Update(id string, entry any) error
- type SearchFilters
- type SearchResult
- type SearchStats
- type SortBy
- type SortOrder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Enabled bool `json:"enabled"`
Type LogStoreType `json:"type"`
Config any `json:"config"`
}
Config represents the configuration for the logs store.
func (*Config) UnmarshalJSON ¶
UnmarshalJSON is the custom unmarshal logic for Config
type Log ¶
type Log struct {
ID string `gorm:"primaryKey;type:varchar(255)" json:"id"`
Timestamp time.Time `gorm:"index;not null" json:"timestamp"`
Object string `gorm:"type:varchar(255);index;not null;column:object_type" json:"object"` // text.completion, chat.completion, or embedding
Provider string `gorm:"type:varchar(255);index;not null" json:"provider"`
Model string `gorm:"type:varchar(255);index;not null" json:"model"`
InputHistory string `gorm:"type:text" json:"-"` // JSON serialized []schemas.BifrostMessage
OutputMessage string `gorm:"type:text" json:"-"` // JSON serialized *schemas.BifrostMessage
EmbeddingOutput string `gorm:"type:text" json:"-"` // JSON serialized *[][]float32
Params string `gorm:"type:text" json:"-"` // JSON serialized *schemas.ModelParameters
Tools string `gorm:"type:text" json:"-"` // JSON serialized *[]schemas.Tool
ToolCalls string `gorm:"type:text" json:"-"` // JSON serialized *[]schemas.ToolCall
SpeechInput string `gorm:"type:text" json:"-"` // JSON serialized *schemas.SpeechInput
TranscriptionInput string `gorm:"type:text" json:"-"` // JSON serialized *schemas.TranscriptionInput
SpeechOutput string `gorm:"type:text" json:"-"` // JSON serialized *schemas.BifrostSpeech
TranscriptionOutput string `gorm:"type:text" json:"-"` // JSON serialized *schemas.BifrostTranscribe
Latency *float64 `json:"latency,omitempty"`
TokenUsage string `gorm:"type:text" json:"-"` // JSON serialized *schemas.LLMUsage
Status string `gorm:"type:varchar(50);index;not null" json:"status"` // "processing", "success", or "error"
ErrorDetails string `gorm:"type:text" json:"-"` // JSON serialized *schemas.BifrostError
Stream bool `gorm:"default:false" json:"stream"` // true if this was a streaming response
ContentSummary string `gorm:"type:text" json:"-"` // For content search
// Denormalized token fields for easier querying
PromptTokens int `gorm:"default:0" json:"-"`
CompletionTokens int `gorm:"default:0" json:"-"`
TotalTokens int `gorm:"default:0" json:"-"`
CreatedAt time.Time `gorm:"index;not null" json:"created_at"`
// Virtual fields for JSON output - these will be populated when needed
InputHistoryParsed []schemas.BifrostMessage `gorm:"-" json:"input_history,omitempty"`
OutputMessageParsed *schemas.BifrostMessage `gorm:"-" json:"output_message,omitempty"`
EmbeddingOutputParsed *[]schemas.BifrostEmbedding `gorm:"-" json:"embedding_output,omitempty"`
ParamsParsed *schemas.ModelParameters `gorm:"-" json:"params,omitempty"`
ToolsParsed *[]schemas.Tool `gorm:"-" json:"tools,omitempty"`
ToolCallsParsed *[]schemas.ToolCall `gorm:"-" json:"tool_calls,omitempty"`
TokenUsageParsed *schemas.LLMUsage `gorm:"-" json:"token_usage,omitempty"`
ErrorDetailsParsed *schemas.BifrostError `gorm:"-" json:"error_details,omitempty"`
SpeechInputParsed *schemas.SpeechInput `gorm:"-" json:"speech_input,omitempty"`
TranscriptionInputParsed *schemas.TranscriptionInput `gorm:"-" json:"transcription_input,omitempty"`
SpeechOutputParsed *schemas.BifrostSpeech `gorm:"-" json:"speech_output,omitempty"`
TranscriptionOutputParsed *schemas.BifrostTranscribe `gorm:"-" json:"transcription_output,omitempty"`
}
Log represents a complete log entry for a request/response cycle This is the GORM model with appropriate tags
func (*Log) BeforeCreate ¶
BeforeCreate GORM hook to set created_at and serialize JSON fields
func (*Log) BeforeSave ¶
BeforeSave GORM hook to serialize JSON fields
func (*Log) BuildContentSummary ¶
BuildContentSummary creates a searchable text summary
func (*Log) DeserializeFields ¶
DeserializeFields converts JSON strings back to Go structs
func (*Log) SerializeFields ¶
SerializeFields converts Go structs to JSON strings for storage
type LogStore ¶
type LogStore interface {
Create(entry *Log) error
FindFirst(query any, fields ...string) (*Log, error)
FindAll(query any, fields ...string) ([]*Log, error)
SearchLogs(filters SearchFilters, pagination PaginationOptions) (*SearchResult, error)
Update(id string, entry any) error
CleanupLogs(since time.Time) error
}
LogStore is the interface for the log store.
type LogStoreType ¶
type LogStoreType string
LogStoreType represents the type of log store.
const (
LogStoreTypeSQLite LogStoreType = "sqlite"
)
LogStoreTypeSQLite is the type of log store for SQLite.
type PaginationOptions ¶
type PaginationOptions struct {
Limit int `json:"limit"`
Offset int `json:"offset"`
SortBy string `json:"sort_by"` // "timestamp", "latency", "tokens"
Order string `json:"order"` // "asc", "desc"
}
PaginationOptions represents pagination parameters
type SQLiteConfig ¶
type SQLiteConfig struct {
Path string `json:"path"`
}
SQLiteConfig represents the configuration for a SQLite database.
type SQLiteLogStore ¶
type SQLiteLogStore struct {
// contains filtered or unexported fields
}
SQLiteLogStore represents a logs store that uses a SQLite database.
func (*SQLiteLogStore) CleanupLogs ¶
func (s *SQLiteLogStore) CleanupLogs(since time.Time) error
CleanupLogs deletes old log entries from the database.
func (*SQLiteLogStore) Create ¶
func (s *SQLiteLogStore) Create(entry *Log) error
Create inserts a new log entry into the database.
func (*SQLiteLogStore) FindAll ¶
func (s *SQLiteLogStore) FindAll(query any, fields ...string) ([]*Log, error)
FindAll finds all log entries from the database.
func (*SQLiteLogStore) FindFirst ¶
func (s *SQLiteLogStore) FindFirst(query any, fields ...string) (*Log, error)
FindFirst gets a log entry from the database.
func (*SQLiteLogStore) SearchLogs ¶
func (s *SQLiteLogStore) SearchLogs(filters SearchFilters, pagination PaginationOptions) (*SearchResult, error)
SearchLogs searches for logs in the database.
type SearchFilters ¶
type SearchFilters struct {
Providers []string `json:"providers,omitempty"`
Models []string `json:"models,omitempty"`
Status []string `json:"status,omitempty"`
Objects []string `json:"objects,omitempty"` // For filtering by request type (chat.completion, text.completion, embedding)
StartTime *time.Time `json:"start_time,omitempty"`
EndTime *time.Time `json:"end_time,omitempty"`
MinLatency *float64 `json:"min_latency,omitempty"`
MaxLatency *float64 `json:"max_latency,omitempty"`
MinTokens *int `json:"min_tokens,omitempty"`
MaxTokens *int `json:"max_tokens,omitempty"`
ContentSearch string `json:"content_search,omitempty"`
}
SearchFilters represents the available filters for log searches
type SearchResult ¶
type SearchResult struct {
Logs []Log `json:"logs"`
Pagination PaginationOptions `json:"pagination"`
Stats SearchStats `json:"stats"`
}
SearchResult represents the result of a log search