types

package
v0.10.7 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RelayFormatOpenAI                    RelayFormat = "openai"
	RelayFormatClaude                                = "claude"
	RelayFormatGemini                                = "gemini"
	RelayFormatOpenAIResponses                       = "openai_responses"
	RelayFormatOpenAIResponsesCompaction             = "openai_responses_compaction"
	RelayFormatOpenAIAudio                           = "openai_audio"
	RelayFormatOpenAIImage                           = "openai_image"
	RelayFormatOpenAIRealtime                        = "openai_realtime"
	RelayFormatRerank                                = "rerank"
	RelayFormatEmbedding                             = "embedding"

	RelayFormatTask    = "task"
	RelayFormatMjProxy = "mj_proxy"
)

Variables

This section is empty.

Functions

func IsChannelError

func IsChannelError(err *NewAPIError) bool

func IsRecordErrorLog

func IsRecordErrorLog(e *NewAPIError) bool

func IsSkipRetryError

func IsSkipRetryError(err *NewAPIError) bool

func LoadFromJsonString

func LoadFromJsonString[K comparable, V any](m *RWMap[K, V], jsonStr string) error

Types

type ChannelError

type ChannelError struct {
	ChannelId   int    `json:"channel_id"`
	ChannelType int    `json:"channel_type"`
	ChannelName string `json:"channel_name"`
	IsMultiKey  bool   `json:"is_multi_key"`
	AutoBan     bool   `json:"auto_ban"`
	UsingKey    string `json:"using_key"`
}

func NewChannelError

func NewChannelError(channelId int, channelType int, channelName string, isMultiKey bool, usingKey string, autoBan bool) *ChannelError

type ClaudeError

type ClaudeError struct {
	Type    string `json:"type,omitempty"`
	Message string `json:"message,omitempty"`
}

type ErrorCode

type ErrorCode string
const (
	ErrorCodeInvalidRequest         ErrorCode = "invalid_request"
	ErrorCodeSensitiveWordsDetected ErrorCode = "sensitive_words_detected"
	ErrorCodeViolationFeeGrokCSAM   ErrorCode = "violation_fee.grok.csam"

	// new api error
	ErrorCodeCountTokenFailed   ErrorCode = "count_token_failed"
	ErrorCodeModelPriceError    ErrorCode = "model_price_error"
	ErrorCodeInvalidApiType     ErrorCode = "invalid_api_type"
	ErrorCodeJsonMarshalFailed  ErrorCode = "json_marshal_failed"
	ErrorCodeDoRequestFailed    ErrorCode = "do_request_failed"
	ErrorCodeGetChannelFailed   ErrorCode = "get_channel_failed"
	ErrorCodeGenRelayInfoFailed ErrorCode = "gen_relay_info_failed"

	// channel error
	ErrorCodeChannelNoAvailableKey        ErrorCode = "channel:no_available_key"
	ErrorCodeChannelParamOverrideInvalid  ErrorCode = "channel:param_override_invalid"
	ErrorCodeChannelHeaderOverrideInvalid ErrorCode = "channel:header_override_invalid"
	ErrorCodeChannelModelMappedError      ErrorCode = "channel:model_mapped_error"
	ErrorCodeChannelAwsClientError        ErrorCode = "channel:aws_client_error"
	ErrorCodeChannelInvalidKey            ErrorCode = "channel:invalid_key"
	ErrorCodeChannelResponseTimeExceeded  ErrorCode = "channel:response_time_exceeded"

	// client request error
	ErrorCodeReadRequestBodyFailed ErrorCode = "read_request_body_failed"
	ErrorCodeConvertRequestFailed  ErrorCode = "convert_request_failed"
	ErrorCodeAccessDenied          ErrorCode = "access_denied"

	// request error
	ErrorCodeBadRequestBody ErrorCode = "bad_request_body"

	// response error
	ErrorCodeReadResponseBodyFailed ErrorCode = "read_response_body_failed"
	ErrorCodeBadResponseStatusCode  ErrorCode = "bad_response_status_code"
	ErrorCodeBadResponse            ErrorCode = "bad_response"
	ErrorCodeBadResponseBody        ErrorCode = "bad_response_body"
	ErrorCodeEmptyResponse          ErrorCode = "empty_response"
	ErrorCodeAwsInvokeError         ErrorCode = "aws_invoke_error"
	ErrorCodeModelNotFound          ErrorCode = "model_not_found"
	ErrorCodePromptBlocked          ErrorCode = "prompt_blocked"

	// sql error
	ErrorCodeQueryDataError  ErrorCode = "query_data_error"
	ErrorCodeUpdateDataError ErrorCode = "update_data_error"

	// quota error
	ErrorCodeInsufficientUserQuota      ErrorCode = "insufficient_user_quota"
	ErrorCodePreConsumeTokenQuotaFailed ErrorCode = "pre_consume_token_quota_failed"
)

type ErrorType

type ErrorType string
const (
	ErrorTypeNewAPIError     ErrorType = "new_api_error"
	ErrorTypeOpenAIError     ErrorType = "openai_error"
	ErrorTypeClaudeError     ErrorType = "claude_error"
	ErrorTypeMidjourneyError ErrorType = "midjourney_error"
	ErrorTypeGeminiError     ErrorType = "gemini_error"
	ErrorTypeRerankError     ErrorType = "rerank_error"
	ErrorTypeUpstreamError   ErrorType = "upstream_error"
)

type FileMeta

type FileMeta struct {
	FileType
	MimeType   string
	OriginData string // url or base64 data
	Detail     string
	ParsedData *LocalFileData
}

type FileType

type FileType string
const (
	FileTypeImage FileType = "image" // Image file type
	FileTypeAudio FileType = "audio" // Audio file type
	FileTypeVideo FileType = "video" // Video file type
	FileTypeFile  FileType = "file"  // Generic file type
)

type GroupRatioInfo

type GroupRatioInfo struct {
	GroupRatio        float64
	GroupSpecialRatio float64
	HasSpecialRatio   bool
}

type LocalFileData

type LocalFileData struct {
	MimeType   string
	Base64Data string
	Url        string
	Size       int64
}

type NewAPIError

type NewAPIError struct {
	Err        error
	RelayError any

	StatusCode int
	Metadata   json.RawMessage
	// contains filtered or unexported fields
}

func InitOpenAIError

func InitOpenAIError(errorCode ErrorCode, statusCode int, ops ...NewAPIErrorOptions) *NewAPIError

func NewError

func NewError(err error, errorCode ErrorCode, ops ...NewAPIErrorOptions) *NewAPIError

func NewErrorWithStatusCode

func NewErrorWithStatusCode(err error, errorCode ErrorCode, statusCode int, ops ...NewAPIErrorOptions) *NewAPIError

func NewOpenAIError

func NewOpenAIError(err error, errorCode ErrorCode, statusCode int, ops ...NewAPIErrorOptions) *NewAPIError

func WithClaudeError

func WithClaudeError(claudeError ClaudeError, statusCode int, ops ...NewAPIErrorOptions) *NewAPIError

func WithOpenAIError

func WithOpenAIError(openAIError OpenAIError, statusCode int, ops ...NewAPIErrorOptions) *NewAPIError

func (*NewAPIError) Error

func (e *NewAPIError) Error() string

func (*NewAPIError) ErrorWithStatusCode

func (e *NewAPIError) ErrorWithStatusCode() string

func (*NewAPIError) GetErrorCode

func (e *NewAPIError) GetErrorCode() ErrorCode

func (*NewAPIError) GetErrorType

func (e *NewAPIError) GetErrorType() ErrorType

func (*NewAPIError) MaskSensitiveError

func (e *NewAPIError) MaskSensitiveError() string

func (*NewAPIError) MaskSensitiveErrorWithStatusCode

func (e *NewAPIError) MaskSensitiveErrorWithStatusCode() string

func (*NewAPIError) SetMessage

func (e *NewAPIError) SetMessage(message string)

func (*NewAPIError) ToClaudeError

func (e *NewAPIError) ToClaudeError() ClaudeError

func (*NewAPIError) ToOpenAIError

func (e *NewAPIError) ToOpenAIError() OpenAIError

func (*NewAPIError) Unwrap

func (e *NewAPIError) Unwrap() error

Unwrap enables errors.Is / errors.As to work with NewAPIError by exposing the underlying error.

type NewAPIErrorOptions

type NewAPIErrorOptions func(*NewAPIError)

func ErrOptionWithHideErrMsg

func ErrOptionWithHideErrMsg(replaceStr string) NewAPIErrorOptions

func ErrOptionWithNoRecordErrorLog

func ErrOptionWithNoRecordErrorLog() NewAPIErrorOptions

func ErrOptionWithSkipRetry

func ErrOptionWithSkipRetry() NewAPIErrorOptions

type OpenAIError

type OpenAIError struct {
	Message  string          `json:"message"`
	Type     string          `json:"type"`
	Param    string          `json:"param"`
	Code     any             `json:"code"`
	Metadata json.RawMessage `json:"metadata,omitempty"`
}

type PerCallPriceData

type PerCallPriceData struct {
	ModelPrice     float64
	Quota          int
	GroupRatioInfo GroupRatioInfo
}

type PriceData

type PriceData struct {
	FreeModel            bool
	ModelPrice           float64
	ModelRatio           float64
	CompletionRatio      float64
	CacheRatio           float64
	CacheCreationRatio   float64
	CacheCreation5mRatio float64
	CacheCreation1hRatio float64
	ImageRatio           float64
	AudioRatio           float64
	AudioCompletionRatio float64
	OtherRatios          map[string]float64
	UsePrice             bool
	QuotaToPreConsume    int // 预消耗额度
	GroupRatioInfo       GroupRatioInfo
}

func (*PriceData) AddOtherRatio

func (p *PriceData) AddOtherRatio(key string, ratio float64)

func (*PriceData) ToSetting

func (p *PriceData) ToSetting() string

type RWMap

type RWMap[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func NewRWMap

func NewRWMap[K comparable, V any]() *RWMap[K, V]

func (*RWMap[K, V]) AddAll

func (m *RWMap[K, V]) AddAll(other map[K]V)

func (*RWMap[K, V]) Clear

func (m *RWMap[K, V]) Clear()

func (*RWMap[K, V]) Get

func (m *RWMap[K, V]) Get(key K) (V, bool)

func (*RWMap[K, V]) Len

func (m *RWMap[K, V]) Len() int

func (*RWMap[K, V]) MarshalJSON

func (m *RWMap[K, V]) MarshalJSON() ([]byte, error)

func (*RWMap[K, V]) ReadAll

func (m *RWMap[K, V]) ReadAll() map[K]V

ReadAll returns a copy of the entire map.

func (*RWMap[K, V]) Set

func (m *RWMap[K, V]) Set(key K, value V)

func (*RWMap[K, V]) UnmarshalJSON

func (m *RWMap[K, V]) UnmarshalJSON(b []byte) error

type RelayFormat

type RelayFormat string

type RequestMeta

type RequestMeta struct {
	OriginalModelName string `json:"original_model_name"`
	UserUsingGroup    string `json:"user_using_group"`
	PromptTokens      int    `json:"prompt_tokens"`
	PreConsumedQuota  int    `json:"pre_consumed_quota"`
}

type Set

type Set[T comparable] struct {
	// contains filtered or unexported fields
}

func NewSet

func NewSet[T comparable]() *Set[T]

NewSet 创建并返回一个新的 Set

func (*Set[T]) Add

func (s *Set[T]) Add(item T)

func (*Set[T]) Contains

func (s *Set[T]) Contains(item T) bool

Contains 检查 Set 是否包含某个元素

func (*Set[T]) Items

func (s *Set[T]) Items() []T

Items 返回 Set 中所有元素组成的切片 注意:由于 map 的无序性,返回的切片元素顺序是随机的

func (*Set[T]) Len

func (s *Set[T]) Len() int

Len 返回 Set 中元素的数量

func (*Set[T]) Remove

func (s *Set[T]) Remove(item T)

Remove 从 Set 中移除一个元素

type TokenCountMeta

type TokenCountMeta struct {
	TokenType     TokenType   `json:"token_type,omitempty"`     // Type of tokens used in the request
	CombineText   string      `json:"combine_text,omitempty"`   // Combined text from all messages
	ToolsCount    int         `json:"tools_count,omitempty"`    // Number of tools used
	NameCount     int         `json:"name_count,omitempty"`     // Number of names in the request
	MessagesCount int         `json:"messages_count,omitempty"` // Number of messages in the request
	Files         []*FileMeta `json:"files,omitempty"`          // List of files, each with type and content
	MaxTokens     int         `json:"max_tokens,omitempty"`     // Maximum tokens allowed in the request

	ImagePriceRatio float64 `json:"image_ratio,omitempty"` // Ratio for image size, if applicable

}

type TokenType

type TokenType string
const (
	TokenTypeTextNumber TokenType = "text_number" // Text or number tokens
	TokenTypeTokenizer  TokenType = "tokenizer"   // Tokenizer tokens
	TokenTypeImage      TokenType = "image"       // Image tokens
)

Jump to

Keyboard shortcuts

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