Documentation
¶
Overview ¶
Package requestdb 在本地 SQLite 中保存请求用量、小时与本地日汇总及可选的 gzip 压缩截断正文
Index ¶
- type AccountUsageEntry
- type AccountUsageSeed
- type Logger
- type Row
- type Store
- func (store *Store) AccountUsageSeed(ctx context.Context, quotaDayStart time.Time) (AccountUsageSeed, error)
- func (store *Store) BodyCapture() bool
- func (store *Store) Close() error
- func (store *Store) ExportRecords(ctx context.Context, query api.UsageRecordQuery, output io.Writer) error
- func (store *Store) Record(row Row)
- func (store *Store) Records(ctx context.Context, query api.UsageRecordQuery) (api.UsageRecordPage, error)
- func (store *Store) RequestBody(ctx context.Context, id string) (api.RequestBody, error)
- func (store *Store) SaveBody(body api.RequestBody)
- func (store *Store) SetBodyCapture(enabled bool)
- func (store *Store) Usage(ctx context.Context, query api.UsageQuery) (api.UsageReport, error)
- func (store *Store) UsagePairs(ctx context.Context, query api.UsageQuery) ([]api.UsagePair, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AccountUsageEntry ¶ added in v0.3.15
AccountUsageEntry 表示单个账户在指定模型与通道上的最近使用时刻
type AccountUsageSeed ¶ added in v0.3.15
type AccountUsageSeed struct {
Entries []AccountUsageEntry
QuotaDayStart time.Time
QuotaDayRequests map[string]int64
}
AccountUsageSeed 保存启动时从请求账本读回的账户最近使用记录与当前配额日请求数
type Row ¶
type Row struct {
ID string
Time time.Time
Protocol string
Path string
Model string
Account string
Channel string
APIKey string
Status int
State string
Duration time.Duration
FirstEvent time.Duration
Queue time.Duration
Proof api.ProofTiming
InputTokens int64
CachedTokens int64
ReasoningTokens int64
ReplyTokens int64
TotalTokens int64
ToolCalls int
ReplyTool bool
ReplyToolCalls int
ReplyToolContinuations int
Error string
Attempts []api.RequestAttempt
}
Row 是一次完成请求的用量记录
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store 串行批量写入请求账本与汇总,并提供聚合与明细查询
func (*Store) AccountUsageSeed ¶ added in v0.3.15
func (store *Store) AccountUsageSeed(ctx context.Context, quotaDayStart time.Time) (AccountUsageSeed, error)
AccountUsageSeed 返回各账户按模型与通道聚合的最近使用时刻,以及自 quotaDayStart 起至今的请求数
func (*Store) ExportRecords ¶
func (store *Store) ExportRecords(ctx context.Context, query api.UsageRecordQuery, output io.Writer) error
ExportRecords 以带 BOM 的 UTF-8 CSV 按完成时间倒序写出范围内全部符合条件的请求记录
func (*Store) Records ¶
func (store *Store) Records(ctx context.Context, query api.UsageRecordQuery) (api.UsageRecordPage, error)
Records 按完成时间倒序返回一页请求记录
func (*Store) RequestBody ¶
RequestBody 返回请求保存的截断正文
func (*Store) SaveBody ¶
func (store *Store) SaveBody(body api.RequestBody)
SaveBody 排队写入一条截断正文,不等待落盘
func (*Store) SetBodyCapture ¶
SetBodyCapture 设置是否保存请求与响应正文
func (*Store) Usage ¶
func (store *Store) Usage(ctx context.Context, query api.UsageQuery) (api.UsageReport, error)
Usage 返回时间范围内的汇总、上一周期、估算费用、逐桶趋势、堆叠序列、分项与筛选候选
func (*Store) UsagePairs ¶ added in v0.3.11
UsagePairs 返回时间范围内符合筛选的账户与模型组合汇总,按请求数降序、账户与模型升序排列