usage

package
v0.0.0-...-dc9418c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 7, 2026 License: BSD-3-Clause Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ImportOllamaCookiesFromLinuxBrowsers

func ImportOllamaCookiesFromLinuxBrowsers(home, outputPath string) (int, error)

func WriteOllamaCookieHeader

func WriteOllamaCookieHeader(path, header string) error

Types

type Budget

type Budget struct {
	ID              string
	Name            string
	BudgetType      string
	LimitAmount     float64
	LimitUnit       string
	ScopeType       string
	ScopeTarget     string
	AlertThresholds []int
	IsActive        bool
	WindowStart     *time.Time
	WindowEnd       *time.Time
	ResetsAt        *time.Time
}

type BudgetAlert

type BudgetAlert struct {
	ID               int64
	BudgetID         string
	AlertType        string
	ThresholdPercent int
	TokensAtAlert    int
	SentAt           time.Time
	Channel          string
}

type CompletionRecord

type CompletionRecord struct {
	SessionKey       string
	ProviderID       string
	ModelName        string
	RequestType      string
	PromptTokens     int
	CompletionTokens int
	TotalTokens      int
	DurationMS       int
	Status           string
	UsageSource      string
	RecordedAt       time.Time
}

type CookieLoader

type CookieLoader interface {
	Load() ([]*http.Cookie, error)
}

func NewCookieJarStore

func NewCookieJarStore(path string) CookieLoader

type HistoricalUsageSample

type HistoricalUsageSample struct {
	ID            int64
	ProviderID    string
	ModelName     string
	WindowType    string
	Source        string
	SampledAt     time.Time
	UsedPercent   float64
	ResetsAt      time.Time
	WindowMinutes int
	TotalTokens   int
}

type OllamaMeIdentity

type OllamaMeIdentity struct {
	IdentityState            QuotaIdentityState
	Source                   QuotaSource
	AccountName              string
	AccountEmail             string
	PlanName                 string
	NotifyUsageLimits        bool
	AccountMetadataPopulated bool
}

func ProbeOllamaMe

func ProbeOllamaMe(ctx context.Context, baseURL string, client *http.Client, signer OllamaMeSigner, now func() time.Time) (OllamaMeIdentity, error)

type OllamaMeSigner

type OllamaMeSigner interface {
	Sign(ctx context.Context, challenge []byte) (string, error)
}

func NewOllamaKeySigner

func NewOllamaKeySigner(keyPath string) OllamaMeSigner

type OllamaQuotaFetcher

type OllamaQuotaFetcher struct {
	BaseURL      string
	Client       *http.Client
	Clock        func() time.Time
	Signer       OllamaMeSigner
	CookieLoader CookieLoader
}

func (*OllamaQuotaFetcher) Fetch

type ProviderSummary

type ProviderSummary struct {
	ProviderID      string
	ModelName       string
	SessionKey      string
	SessionTokens   int
	TodayTokens     int
	WeeklyTokens    int
	SessionRequests int
	TodayRequests   int
	WeeklyRequests  int
	BudgetStatus    string
	WarningLevel    string
	Quota           *QuotaSummary
}

type QuotaIdentityState

type QuotaIdentityState string
const (
	QuotaIdentityStateUnknown            QuotaIdentityState = ""
	QuotaIdentityStateAuthenticated      QuotaIdentityState = "authenticated"
	QuotaIdentityStateAuthenticatedEmpty QuotaIdentityState = "authenticated_empty"
	QuotaIdentityStateUnauthenticated    QuotaIdentityState = "unauthenticated"
	QuotaIdentityStateError              QuotaIdentityState = "error"
)

type QuotaSource

type QuotaSource string
const (
	QuotaSourceUnknown            QuotaSource = ""
	QuotaSourceOllamaAPIMe        QuotaSource = "ollama_api_me"
	QuotaSourceOllamaSettingsHTML QuotaSource = "ollama_settings_html"
)

type QuotaState

type QuotaState string
const (
	QuotaStateLive        QuotaState = "live"
	QuotaStateStale       QuotaState = "stale"
	QuotaStateExpired     QuotaState = "expired"
	QuotaStateUnavailable QuotaState = "unavailable"
)

type QuotaSummary

type QuotaSummary struct {
	ProviderID           string
	AccountName          string
	AccountEmail         string
	PlanName             string
	SessionUsedPercent   float64
	SessionResetsAt      *time.Time
	WeeklyUsedPercent    float64
	WeeklyResetsAt       *time.Time
	NotifyUsageLimits    bool
	State                QuotaState
	Source               QuotaSource
	FetchedAt            time.Time
	ExpiresAt            time.Time
	IdentityState        QuotaIdentityState
	IdentitySource       QuotaSource
	IdentityAccountName  string
	IdentityAccountEmail string
}

func ParseOllamaSettingsUsageHTML

func ParseOllamaSettingsUsageHTML(data []byte, fetchedAt, expiresAt time.Time) (QuotaSummary, error)

type Recorder

type Recorder interface {
	RecordCompletion(ctx context.Context, record CompletionRecord) error
}

type Store

type Store struct {
	// contains filtered or unexported fields
}

func NewStore

func NewStore(dsn string) (*Store, error)

func (*Store) Close

func (s *Store) Close() error

func (*Store) CurrentProviderSummary

func (s *Store) CurrentProviderSummary(sessionKey, providerID, modelName string, now time.Time) (ProviderSummary, error)

func (*Store) DailySummary

func (s *Store) DailySummary(providerID string, day time.Time) (Summary, error)

func (*Store) DeleteBudget

func (s *Store) DeleteBudget(ctx context.Context, id string) error

func (*Store) GetBudget

func (s *Store) GetBudget(ctx context.Context, id string) (Budget, error)

func (*Store) LatestQuotaSummary

func (s *Store) LatestQuotaSummary(providerID string) (QuotaSummary, error)

func (*Store) ListBudgetAlerts

func (s *Store) ListBudgetAlerts(budgetID string) ([]BudgetAlert, error)

func (*Store) ListBudgets

func (s *Store) ListBudgets(ctx context.Context) ([]Budget, error)

func (*Store) ListHistoricalSamples

func (s *Store) ListHistoricalSamples(providerID string) ([]HistoricalUsageSample, error)

func (*Store) ListUsageRecords

func (s *Store) ListUsageRecords(sessionKey string) ([]UsageRecord, error)

func (*Store) PruneOlderThan

func (s *Store) PruneOlderThan(ctx context.Context, cutoff time.Time) error

func (*Store) RecordCompletion

func (s *Store) RecordCompletion(ctx context.Context, record CompletionRecord) error

func (*Store) RecordHistoricalSample

func (s *Store) RecordHistoricalSample(ctx context.Context, sample HistoricalUsageSample) error

func (*Store) SaveQuotaSummary

func (s *Store) SaveQuotaSummary(ctx context.Context, summary QuotaSummary) error

func (*Store) SessionSummary

func (s *Store) SessionSummary(sessionKey string) (Summary, error)

func (*Store) UpsertBudget

func (s *Store) UpsertBudget(ctx context.Context, budget Budget) error

func (*Store) WeeklySummary

func (s *Store) WeeklySummary(providerID string, now time.Time) (Summary, error)

type Summary

type Summary struct {
	TotalRequests         int
	TotalPromptTokens     int
	TotalCompletionTokens int
	TotalTokens           int
}

type UsageRecord

type UsageRecord struct {
	ID               int64
	SessionKey       string
	ProviderID       string
	ModelName        string
	RequestType      string
	PromptTokens     int
	CompletionTokens int
	TotalTokens      int
	DurationMS       int
	Status           string
	UsageSource      string
	CreatedAt        time.Time
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL