common

package
v0.5.6 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2026 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EmailVerificationPurpose = "v"
	PasswordResetPurpose     = "r"
)

Variables

View Source
var CountImageFunMap = map[string]CountImageFun{
	"gpt-":    countOpenaiImageTokens,
	"gemini-": countGeminiImageTokens,
	"claude-": countClaudeImageTokens,
	"glm-":    countGlmImageTokens,
}
View Source
var DalleGenerationImageAmounts = map[string][2]int{
	"dall-e-2": {1, 10},
	"dall-e-3": {1, 1},
}
View Source
var DalleSizeRatios = map[string]map[string]float64{
	"dall-e-2": {
		"256x256":   1,
		"512x512":   1.125,
		"1024x1024": 1.25,
	},
	"dall-e-3": {
		"1024x1024": 1,
		"1024x1792": 2,
		"1792x1024": 2,
	},
}
View Source
var OpenAIImageCostMap = map[string]*OpenAIImageCost{
	"general": {
		Low:        85,
		High:       170,
		Additional: 85,
	},
	"gpt-4o-mini": {
		Low:        2833,
		High:       5667,
		Additional: 2833,
	},
}
View Source
var RechargeDiscount = map[string]float64{}
View Source
var SafeKeyword = map[string]string{}
View Source
var UsingPostgreSQL = false
View Source
var UsingSQLite = false
View Source
var VerificationValidMinutes = 10

Functions

func APIRespondWithError

func APIRespondWithError(c *gin.Context, status int, err error)

func AbortWithErr

func AbortWithErr(c *gin.Context, statusCode int, err error)

func AbortWithMessage

func AbortWithMessage(c *gin.Context, statusCode int, message string)

func CountTokenImage

func CountTokenImage(input interface{}) (int, error)

func CountTokenInput

func CountTokenInput(input any, model string) int

func CountTokenInputMessages

func CountTokenInputMessages(input any, model string, preCostType int) int

func CountTokenMessages

func CountTokenMessages(messages []types.ChatCompletionMessage, model string, preCostType int) int

func CountTokenRerankMessages

func CountTokenRerankMessages(messages types.RerankRequest, model string, preCostType int) int

func CountTokenText

func CountTokenText(text string, model string) int

func DecodeJson

func DecodeJson(reader io.Reader, v any) error

func DeleteKey

func DeleteKey(key string, purpose string)

func ErrorToOpenAIError

func ErrorToOpenAIError(err error) *types.OpenAIError

func ErrorWrapper

func ErrorWrapper(err error, code string, statusCode int) *types.OpenAIErrorWithStatusCode

func ErrorWrapperLocal

func ErrorWrapperLocal(err error, code string, statusCode int) *types.OpenAIErrorWithStatusCode

func GenerateToken

func GenerateToken(tokenID, userID int) (string, error)

func GenerateVerificationCode

func GenerateVerificationCode(length int) string

func GetDefaultDisableChannelKeywords

func GetDefaultDisableChannelKeywords() string

func GetJsonType

func GetJsonType(data json.RawMessage) string

func GetRechargeDiscount

func GetRechargeDiscount(name string) float64

func GetTokenEncoder

func GetTokenEncoder(model string) *tiktoken.Tiktoken

func GetTokenNum

func GetTokenNum(tokenEncoder *tiktoken.Tiktoken, text string) int

func InitTokenEncoders

func InitTokenEncoders()

func InitUserToken

func InitUserToken() error

func LogQuota

func LogQuota(quota int) string

func Marshal

func Marshal(v any) ([]byte, error)

func Password2Hash

func Password2Hash(password string) (string, error)

func RechargeDiscount2JSONString

func RechargeDiscount2JSONString() string

func RegisterVerificationCodeWithKey

func RegisterVerificationCodeWithKey(key string, code string, purpose string)

func SafeGoroutine

func SafeGoroutine(f func())

func SafeKeyword2JSONString

func SafeKeyword2JSONString() string

func SafeSend

func SafeSend(ch chan bool, value bool) (closed bool)

func StringErrorWrapper

func StringErrorWrapper(err string, code string, statusCode int) *types.OpenAIErrorWithStatusCode

func StringErrorWrapperLocal

func StringErrorWrapperLocal(err string, code string, statusCode int) *types.OpenAIErrorWithStatusCode

func StringRerankErrorWrapper

func StringRerankErrorWrapper(err string, code string, statusCode int) *types.RerankErrorWithStatusCode

func StringRerankErrorWrapperLocal

func StringRerankErrorWrapperLocal(err string, code string, statusCode int) *types.RerankErrorWithStatusCode

func Unmarshal

func Unmarshal(data []byte, v any) error

func UnmarshalBodyReusable

func UnmarshalBodyReusable(c *gin.Context, v any) error

func UnmarshalJsonStr

func UnmarshalJsonStr(data string, v any) error

func UpdateRechargeDiscountByJSONString

func UpdateRechargeDiscountByJSONString(jsonStr string) error

func UpdateSafeKeywordByJSONString

func UpdateSafeKeywordByJSONString(jsonStr string) error

func ValidatePasswordAndHash

func ValidatePasswordAndHash(password string, hash string) bool

func ValidateToken

func ValidateToken(token string) (tokenID, userID int, err error)

func VerifyCodeWithKey

func VerifyCodeWithKey(key string, code string, purpose string) bool

Types

type CountImageFun

type CountImageFun func(url, detail, modelName string) (int, error)

type DisableChannelKeyword

type DisableChannelKeyword struct {
	AcMachines *goahocorasick.Machine
	// contains filtered or unexported fields
}
var DisableChannelKeywordsInstance *DisableChannelKeyword

func (*DisableChannelKeyword) GetKeywords

func (d *DisableChannelKeyword) GetKeywords() string

func (*DisableChannelKeyword) IsContains

func (d *DisableChannelKeyword) IsContains(message string) bool

func (*DisableChannelKeyword) Load

func (d *DisableChannelKeyword) Load(keywords string)

type InMemoryRateLimiter

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

func (*InMemoryRateLimiter) Init

func (l *InMemoryRateLimiter) Init(expirationDuration time.Duration)

func (*InMemoryRateLimiter) Request

func (l *InMemoryRateLimiter) Request(key string, maxRequestNum int, duration int64) bool

Request parameter duration's unit is seconds

type OpenAIImageCost

type OpenAIImageCost struct {
	Low        int
	High       int
	Additional int
}

Jump to

Keyboard shortcuts

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