config

package
v0.0.0-...-dcbe3c4 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package config implements config.

Index

Constants

View Source
const (
	// FreetierUserToken freetier user token
	FreetierUserToken = "DEFAULT_PROXY_TOKEN"
)

Variables

This section is empty.

Functions

func SetupConfig

func SetupConfig() (err error)

SetupConfig setup config

Types

type ImageTokenType

type ImageTokenType string

ImageTokenType image token type

const (
	// ImageTokenAzure azure image token
	ImageTokenAzure ImageTokenType = "azure"
	// ImageTokenOpenai openai image token
	ImageTokenOpenai ImageTokenType = "openai"
)

func (ImageTokenType) String

func (t ImageTokenType) String() string

type OpenAI

type OpenAI struct {
	// Gateway (optional) gateway url, default to https://chat.laisky.com
	Gateway string `json:"gateway" mapstructure:"gateway"`
	// API (optional) openai api base url, default is https://api.openai.com
	API string `json:"api" mapstructure:"api"`
	// Token (required) openai api request token
	Token string `json:"-" mapstructure:"token"`
	// DefaultOpenaiToken (optional) default openai token, default equals to token
	//
	// Dangerous: will escape paying wall, use it carefully
	// DefaultOpenaiToken string `json:"-" mapstructure:"default_openai_token"`
	// DefaultImageToken (optional) default image token, default equals to token
	DefaultImageToken string `json:"-" mapstructure:"default_image_token"`

	// DefaultImageUrl (optional) default image url
	//
	// default to https://{{API}}/v1/images/generations
	DefaultImageUrl string `json:"-" mapstructure:"default_image_url"`
	// RateLimitExpensiveModelsIntervalSeconds (optional) rate limit interval seconds for expensive models, default is 60
	RateLimitExpensiveModelsIntervalSeconds int `json:"rate_limit_expensive_models_interval_secs" mapstructure:"rate_limit_expensive_models_interval_secs"`
	// RateLimitImageModelsIntervalSeconds (optional) rate limit interval seconds for image models, default is 600
	RateLimitImageModelsIntervalSeconds int `json:"rate_limit_image_models_interval_secs" mapstructure:"rate_limit_image_models_interval_secs"`
	// Proxy (optional) proxy url to send request
	Proxy string `json:"-" mapstructure:"proxy"`
	// UserTokens (optional) paid user's tenant tokens
	UserTokens []*UserConfig `json:"user_tokens" mapstructure:"user_tokens"`
	// GoogleAnalytics (optional) google analytics id
	GoogleAnalytics string `json:"ga" mapstructure:"ga"`
	// StaticLibs (optional) replace default static libs' url
	StaticLibs map[string]string `json:"static_libs" mapstructure:"static_libs"`
	// QAChatModels (optional) qa chat models
	QAChatModels []qaChatModel `json:"qa_chat_models" mapstructure:"qa_chat_models"`
	// ExternalBillingAPI (optional) default billing api, default is https://oneapi.laisky.com
	ExternalBillingAPI string `json:"external_billing_api" mapstructure:"external_billing_api"`
	// ExternalBillingToken (optional) default billing token
	ExternalBillingToken string `json:"external_billing_token" mapstructure:"external_billing_token"`
	// RamjetURL (optional) ramjet url
	RamjetURL string `json:"ramjet_url" mapstructure:"ramjet_url"`
	// S3 (optional) s3 config
	S3 s3Config `json:"s3" mapstructure:"s3"`

	// PaymentStripeKey (optional) stripe key
	PaymentStripeKey string `json:"payment_stripe_key" mapstructure:"payment_stripe_key"`

	// LcmBasicAuthUsername (optional) lcm basic auth username
	LcmBasicAuthUsername string `json:"lcm_basic_auth_username" mapstructure:"lcm_basic_auth_username"`
	// LcmBasicAuthPassword (optional) lcm basic auth password
	LcmBasicAuthPassword string `json:"lcm_basic_auth_password" mapstructure:"lcm_basic_auth_password"`
	// LimitUploadFileBytes (optional) limit upload file bytes, default is 20MB
	LimitUploadFileBytes int `json:"limit_upload_file_bytes" mapstructure:"limit_upload_file_bytes"`
}

OpenAI openai config

nolint: lll

var (
	// Config global shared config instance
	Config *OpenAI
)

type UserConfig

type UserConfig struct {
	UserName string `json:"username" mapstructure:"username"`
	// Token (required) client's tenant token, not the openai token
	Token string `json:"-" mapstructure:"token"`
	// OpenaiToken (optional) openai token, default is global default token
	OpenaiToken string `json:"-" mapstructure:"openai_token"`
	// ImageToken (optional) token be used to generate image,
	// default is global default image token
	ImageToken string `json:"-" mapstructure:"image_token"`
	// ImageUrl (optional) image url, default is global default image url
	ImageUrl string `json:"-" mapstructure:"image_url"`

	// APIBase (optional) api base url, default is global default api base
	APIBase string `json:"api_base" mapstructure:"api_base"`
	// IsFree (optional) is free user, default is false
	IsFree bool `json:"is_free" mapstructure:"is_free"`
	// BYOK (optional) user's bring his own token, default is false
	BYOK bool `json:"byok" mapstructure:"byok"`
	// AllowedModels (required) allowed models
	AllowedModels []string `json:"allowed_models" mapstructure:"allowed_models"`
	// NoLimitExpensiveModels (optional) skip rate limiter for expensive models
	NoLimitExpensiveModels bool `json:"no_limit_expensive_models" mapstructure:"no_limit_expensive_models"`
	// NoLimitImageModels (optional) skip rate limiter for image models
	NoLimitImageModels bool `json:"no_limit_image_models" mapstructure:"no_limit_image_models"`
	// NoLimitOpenaiModels (optional) skip rate limiter for models that only supported by openai
	NoLimitOpenaiModels bool `json:"no_limit_openai_models" mapstructure:"no_limit_openai_models"`
	// LimitPromptTokenLength (optional) set limit for prompt token length, <=0 means no limit
	LimitPromptTokenLength int `json:"limit_prompt_token_length" mapstructure:"limit_prompt_token_length"`
	// EnableExternalImageBilling (optional) enable external image billing
	EnableExternalImageBilling bool `json:"enable_external_image_billing" mapstructure:"enable_external_image_billing"`
	// ExternalImageBillingUID (optional) external image billing uid
	ExternalImageBillingUID string `json:"external_image_billing_uid" mapstructure:"external_image_billing_uid"`
}

UserConfig user config

func (*UserConfig) IsModelAllowed

func (c *UserConfig) IsModelAllowed(ctx context.Context, model string, nPromptTokens int) error

IsModelAllowed check if model is allowed

Args

  • model: model name
  • nPromptTokens: the length of prompt tokens, 0 means no limit

func (*UserConfig) Valid

func (c *UserConfig) Valid() error

Valid valid and fill default values

Jump to

Keyboard shortcuts

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