db

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2024 License: Apache-2.0 Imports: 11 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var D *sql.DB

Functions

func GetDittoTokensPerDollar

func GetDittoTokensPerDollar(ctx context.Context) (int64, error)

func SearchExamples

func SearchExamples(ctx context.Context, em llm.Embedding, opts ...SearchOption) ([]llm.Example, error)

func Setup

func Setup(ctx context.Context, shutdown *sync.WaitGroup) (err error)

Types

type Purchase

type Purchase struct {
	ID        int64
	PaymentID string
	UserID    int64
	Cents     int64
	Tokens    int64
	CreatedAt time.Time
}

func (*Purchase) Insert

func (p *Purchase) Insert(uid string) error

type Receipt

type Receipt struct {
	ID     int64
	UserID int64
	// ServiceName is the name of the service used for this receipt.
	// It is not in this DB table, but is used for internal logic.
	ServiceName         llm.ServiceName
	ServiceID           int64
	Timestamp           time.Time
	InputTokens         int64
	OutputTokens        int64
	TotalTokens         int64
	CallDurationSeconds float64
	DataProcessedBytes  int64
	DataStoredBytes     int64
	NumImages           int64
	NumSearches         int64
	NumAPICalls         int64
	DittoTokenCost      int64
	Metadata            json.RawMessage
}

func (*Receipt) Insert

func (r *Receipt) Insert(ctx context.Context) error

Insert inserts a new receipt into the database. It updates the Receipt's ID with the ID from the database.

type SearchOption

type SearchOption func(*opt)

func WithK

func WithK(k int) SearchOption

type Service

type Service struct {
	ID                             int64
	Name                           string
	Description                    string
	Version                        string
	ServiceType                    string
	Provider                       string
	BaseCostPerCall                float64
	BaseCostPerMillionTokens       float64
	BaseCostPerMillionInputTokens  float64
	BaseCostPerMillionOutputTokens float64
	BaseCostPerImage               float64
	BaseCostPerSearch              float64
	MaxInputTokens                 int64
	MaxOutputTokens                int64
	MaxTotalTokens                 int64
	BaseCostPerSecond              float64
	BaseCostPerGBProcessed         float64
	BaseCostPerGBStored            float64
	SupportsBatching               bool
	BatchSizeLimit                 int64
	BaseCostPerBatch               float64
	RateLimitPerMinute             int64
	RateLimitPerDay                int64
	ProfitMarginPercentage         float64
	MinimumProfitAmount            float64
	PeakHoursMultiplier            float64
	VolumeDiscountThreshold        int64
	VolumeDiscountPercentage       float64
	Currency                       string
	IsActive                       bool
}

func (*Service) GetByName

func (s *Service) GetByName(ctx context.Context) error

GetServiceByName retrieves a service from the database by its name.

type User

type User struct {
	ID                 int64
	UID                string
	Balance            int64
	LastAirdropAt      time.Time
	TotalTokensAirdrop int64
}

func (*User) Get

func (u *User) Get(ctx context.Context) error

Get gets a user by their UID. If the user does not exist, it creates a new user.

func (*User) InitBalance

func (u *User) InitBalance(ctx context.Context) error

Init sets the user's balance to the given value. If the user does not exist, it creates a new user.

func (*User) Insert

func (u *User) Insert(ctx context.Context) error

Insert inserts a new user into the database. It updates the User's ID with the ID from the database.

Jump to

Keyboard shortcuts

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