types

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2026 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

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

	RelayFormatTask    = "task"
	RelayFormatMjProxy = "mj_proxy"
)

Variables

View Source
var (
	FinishReasonStop          = "stop"
	FinishReasonToolCalls     = "tool_calls"
	FinishReasonLength        = "length"
	FinishReasonFunctionCall  = "function_call"
	FinishReasonContentFilter = "content_filter"
)

Finish reasons shared by the OpenAI-compatible response formats. Declared as vars (not consts) because converter code takes their address for *string finish-reason fields.

Functions

func IsChannelError

func IsChannelError(err *NewAPIError) bool

func IsRecordErrorLog

func IsRecordErrorLog(e *NewAPIError) bool

func IsSkipRetryError

func IsSkipRetryError(err *NewAPIError) bool

Types

type Base64Source

type Base64Source struct {
	Base64Data string
	MimeType   string
	// contains filtered or unexported fields
}

func NewBase64FileSource

func NewBase64FileSource(base64Data string, mimeType string) *Base64Source

func (*Base64Source) ClearCache

func (b *Base64Source) ClearCache()

func (*Base64Source) ClearRawData

func (b *Base64Source) ClearRawData()

func (*Base64Source) GetCache

func (b *Base64Source) GetCache() *CachedFileData

func (*Base64Source) GetIdentifier

func (b *Base64Source) GetIdentifier() string

func (*Base64Source) GetRawData

func (b *Base64Source) GetRawData() string

func (*Base64Source) HasCache

func (b *Base64Source) HasCache() bool

func (*Base64Source) IsRegistered

func (b *Base64Source) IsRegistered() bool

func (*Base64Source) IsURL

func (b *Base64Source) IsURL() bool

func (*Base64Source) Mu

func (b *Base64Source) Mu() *sync.Mutex

func (*Base64Source) SetCache

func (b *Base64Source) SetCache(data *CachedFileData)

func (*Base64Source) SetRegistered

func (b *Base64Source) SetRegistered(registered bool)

type CachedFileData

type CachedFileData struct {
	MimeType    string        // MIME 类型
	Size        int64         // 文件大小(字节)
	DiskSize    int64         // 磁盘缓存实际占用大小(字节,通常是 base64 长度)
	ImageConfig *image.Config // 图片配置(如果是图片)
	ImageFormat string        // 图片格式(如果是图片)

	OnClose func(size int64)
	// contains filtered or unexported fields
}

func NewDiskCachedData

func NewDiskCachedData(diskPath string, mimeType string, size int64) *CachedFileData

func NewMemoryCachedData

func NewMemoryCachedData(base64Data string, mimeType string, size int64) *CachedFileData

func (*CachedFileData) Close

func (c *CachedFileData) Close() error

func (*CachedFileData) GetBase64Data

func (c *CachedFileData) GetBase64Data() (string, error)

func (*CachedFileData) IsDisk

func (c *CachedFileData) IsDisk() bool

func (*CachedFileData) SetBase64Data

func (c *CachedFileData) SetBase64Data(data string)

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 EndpointType

type EndpointType string

EndpointType identifies a downstream API surface. Moved from constant so the conversion kit (dto/relayconvert) has no host imports; constant keeps aliases for host code.

const (
	EndpointTypeOpenAI                EndpointType = "openai"
	EndpointTypeOpenAIResponse        EndpointType = "openai-response"
	EndpointTypeOpenAIResponseCompact EndpointType = "openai-response-compact"
	EndpointTypeOpenAIAlphaSearch     EndpointType = "openai-alpha-search"
	EndpointTypeAnthropic             EndpointType = "anthropic"
	EndpointTypeGemini                EndpointType = "gemini"
	EndpointTypeJinaRerank            EndpointType = "jina-rerank"
	EndpointTypeImageGeneration       EndpointType = "image-generation"
	EndpointTypeEmbeddings            EndpointType = "embeddings"
	EndpointTypeOpenAIVideo           EndpointType = "openai-video"
)

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
	Source FileSource // 统一的文件来源(URL 或 base64)
	Detail string     // 图片细节级别(low/high/auto)
}

func NewFileMeta

func NewFileMeta(fileType FileType, source FileSource) *FileMeta

NewFileMeta 创建新的 FileMeta

func NewImageFileMeta

func NewImageFileMeta(source FileSource, detail string) *FileMeta

NewImageFileMeta 创建图片类型的 FileMeta

func (*FileMeta) GetIdentifier

func (f *FileMeta) GetIdentifier() string

GetIdentifier 获取文件标识符(用于日志)

func (*FileMeta) GetRawData

func (f *FileMeta) GetRawData() string

GetRawData 获取原始数据(兼容旧代码) Deprecated: 请使用 Source.GetRawData()

func (*FileMeta) IsURL

func (f *FileMeta) IsURL() bool

IsURL 判断是否是 URL 来源

type FileSource

type FileSource interface {
	IsURL() bool
	GetIdentifier() string
	GetRawData() string
	ClearRawData()

	SetCache(data *CachedFileData)
	GetCache() *CachedFileData
	HasCache() bool
	ClearCache()

	IsRegistered() bool
	SetRegistered(registered bool)
	Mu() *sync.Mutex
}

FileSource 统一的文件来源抽象接口 支持 URL 和 base64 两种来源,提供懒加载和缓存机制

func NewFileSourceFromData

func NewFileSourceFromData(data string, mimeType string) FileSource

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 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

func ErrOptionWithStatusCode

func ErrOptionWithStatusCode(statusCode int) 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 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 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
	BillingRatios   map[string]float64 `json:"billing_ratios,omitempty"` // Validated request multipliers used by pre-consume billing

}

type TokenType

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

type URLSource

type URLSource struct {
	URL string
	// contains filtered or unexported fields
}

func NewURLFileSource

func NewURLFileSource(url string) *URLSource

func (*URLSource) ClearCache

func (b *URLSource) ClearCache()

func (*URLSource) ClearRawData

func (u *URLSource) ClearRawData()

func (*URLSource) GetCache

func (b *URLSource) GetCache() *CachedFileData

func (*URLSource) GetIdentifier

func (u *URLSource) GetIdentifier() string

func (*URLSource) GetRawData

func (u *URLSource) GetRawData() string

func (*URLSource) HasCache

func (b *URLSource) HasCache() bool

func (*URLSource) IsRegistered

func (b *URLSource) IsRegistered() bool

func (*URLSource) IsURL

func (u *URLSource) IsURL() bool

func (*URLSource) Mu

func (b *URLSource) Mu() *sync.Mutex

func (*URLSource) SetCache

func (b *URLSource) SetCache(data *CachedFileData)

func (*URLSource) SetRegistered

func (b *URLSource) SetRegistered(registered bool)

Jump to

Keyboard shortcuts

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