Documentation
¶
Index ¶
- Constants
- Variables
- func APIRespondWithError(c *gin.Context, status int, err error)
- func AbortWithErr(c *gin.Context, statusCode int, err error)
- func AbortWithMessage(c *gin.Context, statusCode int, message string)
- func CountTokenImage(input interface{}) (int, error)
- func CountTokenInput(input any, model string) int
- func CountTokenInputMessages(input any, model string, preCostType int) int
- func CountTokenMessages(messages []types.ChatCompletionMessage, model string, preCostType int) int
- func CountTokenRerankMessages(messages types.RerankRequest, model string, preCostType int) int
- func CountTokenText(text string, model string) int
- func DecodeJson(reader io.Reader, v any) error
- func DeleteKey(key string, purpose string)
- func ErrorToOpenAIError(err error) *types.OpenAIError
- func ErrorWrapper(err error, code string, statusCode int) *types.OpenAIErrorWithStatusCode
- func ErrorWrapperLocal(err error, code string, statusCode int) *types.OpenAIErrorWithStatusCode
- func GenerateToken(tokenID, userID int) (string, error)
- func GenerateVerificationCode(length int) string
- func GetDefaultDisableChannelKeywords() string
- func GetJsonType(data json.RawMessage) string
- func GetRechargeDiscount(name string) float64
- func GetTokenEncoder(model string) *tiktoken.Tiktoken
- func GetTokenNum(tokenEncoder *tiktoken.Tiktoken, text string) int
- func InitTokenEncoders()
- func InitUserToken() error
- func LogQuota(quota int) string
- func Marshal(v any) ([]byte, error)
- func OpenAIErrorToRerankError(err *types.OpenAIErrorWithStatusCode) *types.RerankErrorWithStatusCode
- func Password2Hash(password string) (string, error)
- func RechargeDiscount2JSONString() string
- func RegisterVerificationCodeWithKey(key string, code string, purpose string)
- func SafeGoroutine(f func())
- func SafeKeyword2JSONString() string
- func SafeSend(ch chan bool, value bool) (closed bool)
- func StringErrorWrapper(err string, code string, statusCode int) *types.OpenAIErrorWithStatusCode
- func StringErrorWrapperLocal(err string, code string, statusCode int) *types.OpenAIErrorWithStatusCode
- func StringRerankErrorWrapper(err string, code string, statusCode int) *types.RerankErrorWithStatusCode
- func StringRerankErrorWrapperLocal(err string, code string, statusCode int) *types.RerankErrorWithStatusCode
- func Unmarshal(data []byte, v any) error
- func UnmarshalBodyReusable(c *gin.Context, v any) error
- func UnmarshalJsonStr(data string, v any) error
- func UpdateRechargeDiscountByJSONString(jsonStr string) error
- func UpdateSafeKeywordByJSONString(jsonStr string) error
- func ValidatePasswordAndHash(password string, hash string) bool
- func ValidateToken(token string) (tokenID, userID int, err error)
- func VerifyCodeWithKey(key string, code string, purpose string) bool
- type CountImageFun
- type DisableChannelKeyword
- type InMemoryRateLimiter
- type OpenAIImageCost
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 Validate *validator.Validate
View Source
var VerificationValidMinutes = 10
Functions ¶
func CountTokenImage ¶
func CountTokenInput ¶
func CountTokenInputMessages ¶
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 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 GetDefaultDisableChannelKeywords ¶
func GetDefaultDisableChannelKeywords() string
func GetJsonType ¶
func GetJsonType(data json.RawMessage) string
func GetRechargeDiscount ¶
func GetTokenEncoder ¶
func InitTokenEncoders ¶
func InitTokenEncoders()
func InitUserToken ¶
func InitUserToken() error
func OpenAIErrorToRerankError ¶
func OpenAIErrorToRerankError(err *types.OpenAIErrorWithStatusCode) *types.RerankErrorWithStatusCode
func Password2Hash ¶
func RechargeDiscount2JSONString ¶
func RechargeDiscount2JSONString() string
func SafeGoroutine ¶
func SafeGoroutine(f func())
func SafeKeyword2JSONString ¶
func SafeKeyword2JSONString() string
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 UnmarshalJsonStr ¶
func ValidatePasswordAndHash ¶
func ValidateToken ¶
Types ¶
type CountImageFun ¶
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)
type OpenAIImageCost ¶
Source Files
¶
Click to show internal directories.
Click to hide internal directories.