MCPcopy Create free account
hub / github.com/aiprodcoder/MIXAPI / SumUsedToken

Function SumUsedToken

model/log.go:391–410  ·  view source on GitHub ↗
(logType int, startTimestamp int64, endTimestamp int64, modelName string, username string, tokenName string)

Source from the content-addressed store, hash-verified

389}
390
391func SumUsedToken(logType int, startTimestamp int64, endTimestamp int64, modelName string, username string, tokenName string) (token int) {
392 tx := LOG_DB.Table("logs").Select("ifnull(sum(prompt_tokens),0) + ifnull(sum(completion_tokens),0)")
393 if username != "" {
394 tx = tx.Where("username = ?", username)
395 }
396 if tokenName != "" {
397 tx = tx.Where("token_name = ?", tokenName)
398 }
399 if startTimestamp != 0 {
400 tx = tx.Where("created_at >= ?", startTimestamp)
401 }
402 if endTimestamp != 0 {
403 tx = tx.Where("created_at <= ?", endTimestamp)
404 }
405 if modelName != "" {
406 tx = tx.Where("model_name = ?", modelName)
407 }
408 tx.Where("type = ?", LogTypeConsume).Scan(&token)
409 return token
410}
411
412func DeleteOldLog(ctx context.Context, targetTimestamp int64, limit int) (int64, error) {
413 var total int64 = 0

Callers

nothing calls this directly

Calls 1

ScanMethod · 0.45

Tested by

no test coverage detected