Documentation
¶
Index ¶
- Constants
- func AcSearch(findText string, dict []string, stopImmediately bool) (bool, []string)
- func AppendChannelAffinityAdminInfo(c *gin.Context, adminInfo map[string]interface{})
- func CacheGetRandomSatisfiedChannel(param *RetryParam) (*model.Channel, string, error)
- func CalcOpenRouterCacheCreateTokens(usage dto.Usage, priceData types.PriceData) int
- func ChargeViolationFeeIfNeeded(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, apiErr *types.NewAPIError) bool
- func ChatCompletionsRequestToResponsesRequest(req *dto.GeneralOpenAIRequest) (*dto.OpenAIResponsesRequest, error)
- func CheckNotificationLimit(userId int, notifyType string) (bool, error)
- func CheckSensitiveMessages(messages []dto.Message) ([]string, error)
- func CheckSensitiveText(text string) (bool, []string)
- func ClaudeErrorWrapper(err error, code string, statusCode int) *dto.ClaudeErrorWithStatusCode
- func ClaudeErrorWrapperLocal(err error, code string, statusCode int) *dto.ClaudeErrorWithStatusCode
- func ClaudeToOpenAIRequest(claudeRequest dto.ClaudeRequest, info *relaycommon.RelayInfo) (*dto.GeneralOpenAIRequest, error)
- func CleanupFileSources(c *gin.Context)
- func ClearChannelAffinityCacheAll() int
- func ClearChannelAffinityCacheByRuleName(ruleName string) (int, error)
- func CloseResponseBodyGracefully(httpResponse *http.Response)
- func ConvertSimpleChangeParams(content string) *dto.MidjourneyRequest
- func CountAudioTokenInput(audioBase64 string, audioFormat string) (int, error)
- func CountAudioTokenOutput(audioBase64 string, audioFormat string) (int, error)
- func CountTextToken(text string, model string) int
- func CountTokenInput(input any, model string) int
- func CountTokenRealtime(info *relaycommon.RelayInfo, request dto.RealtimeEvent, model string) (int, int, error)
- func CoverActionToModelName(mjAction string) string
- func CoverPlusActionToNormalAction(midjRequest *dto.MidjourneyRequest) *dto.MidjourneyResponse
- func CoverTaskActionToModelName(platform constant.TaskPlatform, action string) string
- func DecodeBase64AudioData(audioBase64 string) (string, error)
- func DecodeBase64FileData(base64String string) (string, string, error)
- func DecodeBase64ImageData(base64String string) (image.Config, string, string, error)
- func DecodeUrlImageData(imageUrl string) (image.Config, string, error)
- func DetectFileType(mimeType string) types.FileType
- func DisableChannel(channelError types.ChannelError, reason string)
- func DoDownloadRequest(originUrl string, reason ...string) (resp *http.Response, err error)
- func DoMidjourneyHttpRequest(c *gin.Context, timeout time.Duration, fullRequestURL string) (*dto.MidjourneyResponseWithStatusCode, []byte, error)
- func DoWorkerRequest(req *WorkerRequest) (*http.Response, error)
- func EnableChannel(channelId int, usingKey string, channelName string)
- func EstimateRequestToken(c *gin.Context, meta *types.TokenCountMeta, info *relaycommon.RelayInfo) (int, error)
- func EstimateToken(provider Provider, text string) int
- func EstimateTokenByModel(model, text string) int
- func ExtractCodexAccountIDFromJWT(token string) (string, bool)
- func ExtractEmailFromJWT(token string) (string, bool)
- func ExtractOutputTextFromResponses(resp *dto.OpenAIResponsesResponse) string
- func FetchCodexWhamUsage(ctx context.Context, client *http.Client, baseURL string, accessToken string, ...) (statusCode int, body []byte, err error)
- func GeminiToOpenAIRequest(geminiRequest *dto.GeminiChatRequest, info *relaycommon.RelayInfo) (*dto.GeneralOpenAIRequest, error)
- func GenerateAudioOtherInfo(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, usage *dto.Usage, ...) map[string]interface{}
- func GenerateClaudeOtherInfo(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, ...) map[string]interface{}
- func GenerateMjOtherInfo(relayInfo *relaycommon.RelayInfo, priceData types.PerCallPriceData) map[string]interface{}
- func GenerateTextOtherInfo(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, ...) map[string]interface{}
- func GenerateWssOtherInfo(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, usage *dto.RealtimeUsage, ...) map[string]interface{}
- func GetBase64Data(c *gin.Context, source *types.FileSource, reason ...string) (string, string, error)
- func GetCallbackAddress() string
- func GetFileBase64FromUrl(c *gin.Context, url string, reason ...string) (*types.LocalFileData, error)
- func GetFileTypeFromUrl(c *gin.Context, url string, reason ...string) (string, error)
- func GetHttpClient() *http.Client
- func GetHttpClientWithProxy(proxyURL string) (*http.Client, error)
- func GetImageConfig(c *gin.Context, source *types.FileSource) (image.Config, string, error)
- func GetImageFromUrl(url string) (mimeType string, data string, err error)
- func GetMimeType(c *gin.Context, source *types.FileSource) (string, error)
- func GetMimeTypeByExtension(ext string) string
- func GetMjRequestModel(relayMode int, midjRequest *dto.MidjourneyRequest) (string, *dto.MidjourneyResponse, bool)
- func GetPreferredChannelByAffinity(c *gin.Context, modelName string, usingGroup string) (int, bool)
- func GetUserAutoGroup(userGroup string) []string
- func GetUserGroupRatio(userGroup, group string) float64
- func GetUserUsableGroups(userGroup string) map[string]string
- func GroupInUserUsableGroups(userGroup, groupName string) bool
- func HasCSAMViolationMarker(err *types.NewAPIError) bool
- func IOCopyBytesGracefully(c *gin.Context, src *http.Response, data []byte)
- func InitAc(dict []string) *goahocorasick.Machine
- func InitHttpClient()
- func InitTokenEncoders()
- func IsViolationFeeCode(code types.ErrorCode) bool
- func LoadFileSource(c *gin.Context, source *types.FileSource, reason ...string) (*types.CachedFileData, error)
- func MarkChannelAffinityUsed(c *gin.Context, selectedGroup string, channelID int)
- func MidjourneyErrorWithStatusCodeWrapper(code int, desc string, statusCode int) *dto.MidjourneyResponseWithStatusCode
- func MidjourneyErrorWrapper(code int, desc string) *dto.MidjourneyResponse
- func NewProxyHttpClient(proxyURL string) (*http.Client, error)
- func NormalizeViolationFeeError(err *types.NewAPIError) *types.NewAPIError
- func NotifyRootUser(t string, subject string, content string)
- func NotifyUser(userId int, userEmail string, userSetting dto.UserSetting, data dto.Notify) error
- func ObserveChannelAffinityUsageCacheFromContext(c *gin.Context, usage *dto.Usage)
- func PostAudioConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, usage *dto.Usage, ...)
- func PostClaudeConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, usage *dto.Usage)
- func PostConsumeQuota(relayInfo *relaycommon.RelayInfo, quota int, preConsumedQuota int, ...) (err error)
- func PostWssConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, modelName string, ...)
- func PreConsumeBilling(c *gin.Context, preConsumedQuota int, relayInfo *relaycommon.RelayInfo) *types.NewAPIError
- func PreConsumeTokenQuota(relayInfo *relaycommon.RelayInfo, quota int) error
- func PreWssConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, usage *dto.RealtimeUsage) error
- func RecordChannelAffinity(c *gin.Context, channelID int)
- func RelayErrorHandler(ctx context.Context, resp *http.Response, showBodyWhenFail bool) (newApiErr *types.NewAPIError)
- func RemoveDuplicate(s []string) []string
- func ResetProxyClientCache()
- func ResetStatusCode(newApiErr *types.NewAPIError, statusCodeMappingStr string)
- func ResponseOpenAI2Claude(openAIResponse *dto.OpenAITextResponse, info *relaycommon.RelayInfo) *dto.ClaudeResponse
- func ResponseOpenAI2Gemini(openAIResponse *dto.OpenAITextResponse, info *relaycommon.RelayInfo) *dto.GeminiChatResponse
- func ResponseText2Usage(c *gin.Context, responseText string, modeName string, promptTokens int) *dto.Usage
- func ResponsesResponseToChatCompletionsResponse(resp *dto.OpenAIResponsesResponse, id string) (*dto.OpenAITextResponse, *dto.Usage, error)
- func SendWebhookNotify(webhookURL string, secret string, data dto.Notify) error
- func SensitiveWordContains(text string) (bool, []string)
- func SensitiveWordReplace(text string, returnImmediately bool) (bool, []string, string)
- func SettleBilling(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, actualQuota int) error
- func ShouldChatCompletionsUseResponsesGlobal(channelID int, channelType int, model string) bool
- func ShouldChatCompletionsUseResponsesPolicy(policy model_setting.ChatCompletionsToResponsesPolicy, channelID int, ...) bool
- func ShouldDisableChannel(channelType int, err *types.NewAPIError) bool
- func ShouldEnableChannel(newAPIError *types.NewAPIError, status int) bool
- func ShouldSkipRetryAfterChannelAffinityFailure(c *gin.Context) bool
- func StartCodexCredentialAutoRefreshTask()
- func StartSubscriptionQuotaResetTask()
- func StreamResponseOpenAI2Claude(openAIResponse *dto.ChatCompletionsStreamResponse, info *relaycommon.RelayInfo) []*dto.ClaudeResponse
- func StreamResponseOpenAI2Gemini(openAIResponse *dto.ChatCompletionsStreamResponse, info *relaycommon.RelayInfo) *dto.GeminiChatResponse
- func SundaySearch(text string, pattern string) bool
- func TaskErrorWrapper(err error, code string, statusCode int) *dto.TaskError
- func TaskErrorWrapperLocal(err error, code string, statusCode int) *dto.TaskError
- func ValidUsage(usage *dto.Usage) bool
- func WrapAsViolationFeeGrokCSAM(err *types.NewAPIError) *types.NewAPIError
- type BillingSession
- type ChannelAffinityCacheStats
- type ChannelAffinityStatsContext
- type ChannelAffinityUsageCacheCounters
- type ChannelAffinityUsageCacheStats
- type CodexCredentialRefreshOptions
- type CodexOAuthAuthorizationFlow
- type CodexOAuthKey
- type CodexOAuthTokenResult
- type FundingSource
- type Provider
- type QuotaInfo
- type RetryParam
- type SubscriptionFunding
- type TokenDetails
- type WalletFunding
- type WebhookPayload
- type WorkerRequest
Constants ¶
const ( BillingSourceWallet = "wallet" BillingSourceSubscription = "subscription" )
const ( ViolationFeeCodePrefix = "violation_fee." CSAMViolationMarker = "Failed check: SAFETY_CHECK_TYPE_CSAM" )
Variables ¶
This section is empty.
Functions ¶
func CacheGetRandomSatisfiedChannel ¶
func CacheGetRandomSatisfiedChannel(param *RetryParam) (*model.Channel, string, error)
CacheGetRandomSatisfiedChannel tries to get a random channel that satisfies the requirements. 尝试获取一个满足要求的随机渠道。
For "auto" tokenGroup with cross-group Retry enabled: 对于启用了跨分组重试的 "auto" tokenGroup:
Each group will exhaust all its priorities before moving to the next group. 每个分组会用完所有优先级后才会切换到下一个分组。
Uses ContextKeyAutoGroupIndex to track current group index. 使用 ContextKeyAutoGroupIndex 跟踪当前分组索引。
Uses ContextKeyAutoGroupRetryIndex to track the global Retry count when current group started. 使用 ContextKeyAutoGroupRetryIndex 跟踪当前分组开始时的全局重试次数。
priorityRetry = Retry - startRetryIndex, represents the priority level within current group. priorityRetry = Retry - startRetryIndex,表示当前分组内的优先级级别。
When GetRandomSatisfiedChannel returns nil (priorities exhausted), moves to next group. 当 GetRandomSatisfiedChannel 返回 nil(优先级用完)时,切换到下一个分组。
Example flow (2 groups, each with 2 priorities, RetryTimes=3): 示例流程(2个分组,每个有2个优先级,RetryTimes=3):
Retry=0: GroupA, priority0 (startRetryIndex=0, priorityRetry=0)
分组A, 优先级0
Retry=1: GroupA, priority1 (startRetryIndex=0, priorityRetry=1)
分组A, 优先级1
Retry=2: GroupA exhausted → GroupB, priority0 (startRetryIndex=2, priorityRetry=0)
分组A用完 → 分组B, 优先级0
Retry=3: GroupB, priority1 (startRetryIndex=2, priorityRetry=1)
分组B, 优先级1
func ChargeViolationFeeIfNeeded ¶
func ChargeViolationFeeIfNeeded(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, apiErr *types.NewAPIError) bool
ChargeViolationFeeIfNeeded charges an additional fee after the normal flow finishes (including refund). It uses Grok fee settings as the fee policy.
func ChatCompletionsRequestToResponsesRequest ¶
func ChatCompletionsRequestToResponsesRequest(req *dto.GeneralOpenAIRequest) (*dto.OpenAIResponsesRequest, error)
func CheckNotificationLimit ¶
CheckNotificationLimit checks if the user has exceeded their notification limit Returns true if the user can send notification, false if limit exceeded
func CheckSensitiveText ¶
func ClaudeErrorWrapper ¶
func ClaudeErrorWrapper(err error, code string, statusCode int) *dto.ClaudeErrorWithStatusCode
func ClaudeErrorWrapperLocal ¶
func ClaudeErrorWrapperLocal(err error, code string, statusCode int) *dto.ClaudeErrorWithStatusCode
func ClaudeToOpenAIRequest ¶
func ClaudeToOpenAIRequest(claudeRequest dto.ClaudeRequest, info *relaycommon.RelayInfo) (*dto.GeneralOpenAIRequest, error)
func CleanupFileSources ¶ added in v0.10.8
CleanupFileSources 清理请求中所有注册的 FileSource 应在请求结束时调用(通常由中间件自动调用)
func ClearChannelAffinityCacheAll ¶
func ClearChannelAffinityCacheAll() int
func ConvertSimpleChangeParams ¶
func ConvertSimpleChangeParams(content string) *dto.MidjourneyRequest
func CountAudioTokenInput ¶
func CountAudioTokenOutput ¶
func CountTextToken ¶
CountTextToken 统计文本的token数量,仅OpenAI模型使用tokenizer,其余模型使用估算
func CountTokenInput ¶
func CountTokenRealtime ¶
func CountTokenRealtime(info *relaycommon.RelayInfo, request dto.RealtimeEvent, model string) (int, int, error)
func CoverActionToModelName ¶
func CoverPlusActionToNormalAction ¶
func CoverPlusActionToNormalAction(midjRequest *dto.MidjourneyRequest) *dto.MidjourneyResponse
func CoverTaskActionToModelName ¶
func CoverTaskActionToModelName(platform constant.TaskPlatform, action string) string
func DecodeBase64AudioData ¶
func DecodeBase64ImageData ¶
return image.Config, format, clean base64 string, error
func DetectFileType ¶ added in v0.10.8
DetectFileType 检测文件类型
func DisableChannel ¶
func DisableChannel(channelError types.ChannelError, reason string)
disable & notify
func DoDownloadRequest ¶
func DoMidjourneyHttpRequest ¶
func DoWorkerRequest ¶
func DoWorkerRequest(req *WorkerRequest) (*http.Response, error)
DoWorkerRequest 通过Worker发送请求
func EnableChannel ¶
func EstimateRequestToken ¶
func EstimateRequestToken(c *gin.Context, meta *types.TokenCountMeta, info *relaycommon.RelayInfo) (int, error)
func EstimateToken ¶
EstimateToken 计算 Token 数量
func EstimateTokenByModel ¶
func ExtractEmailFromJWT ¶
func ExtractOutputTextFromResponses ¶
func ExtractOutputTextFromResponses(resp *dto.OpenAIResponsesResponse) string
func FetchCodexWhamUsage ¶
func GeminiToOpenAIRequest ¶
func GeminiToOpenAIRequest(geminiRequest *dto.GeminiChatRequest, info *relaycommon.RelayInfo) (*dto.GeneralOpenAIRequest, error)
func GenerateAudioOtherInfo ¶
func GenerateClaudeOtherInfo ¶
func GenerateClaudeOtherInfo(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, modelRatio, groupRatio, completionRatio float64, cacheTokens int, cacheRatio float64, cacheCreationTokens int, cacheCreationRatio float64, cacheCreationTokens5m int, cacheCreationRatio5m float64, cacheCreationTokens1h int, cacheCreationRatio1h float64, modelPrice float64, userGroupRatio float64) map[string]interface{}
func GenerateMjOtherInfo ¶
func GenerateMjOtherInfo(relayInfo *relaycommon.RelayInfo, priceData types.PerCallPriceData) map[string]interface{}
func GenerateTextOtherInfo ¶
func GenerateWssOtherInfo ¶
func GenerateWssOtherInfo(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, usage *dto.RealtimeUsage, modelRatio, groupRatio, completionRatio, audioRatio, audioCompletionRatio, modelPrice, userGroupRatio float64) map[string]interface{}
func GetBase64Data ¶ added in v0.10.8
func GetBase64Data(c *gin.Context, source *types.FileSource, reason ...string) (string, string, error)
GetBase64Data 获取 base64 编码的数据
func GetCallbackAddress ¶
func GetCallbackAddress() string
func GetFileBase64FromUrl ¶
func GetFileBase64FromUrl(c *gin.Context, url string, reason ...string) (*types.LocalFileData, error)
GetFileBase64FromUrl 从 URL 获取文件的 base64 编码数据 Deprecated: 请使用 GetBase64Data 配合 types.NewURLFileSource 替代 此函数保留用于向后兼容,内部已重构为调用统一的文件服务
func GetFileTypeFromUrl ¶
GetFileTypeFromUrl 获取文件类型,返回 mime type, 例如 image/jpeg, image/png, image/gif, image/bmp, image/tiff, application/pdf 如果获取失败,返回 application/octet-stream
func GetHttpClient ¶
func GetHttpClientWithProxy ¶
GetHttpClientWithProxy returns the default client or a proxy-enabled one when proxyURL is provided.
func GetImageConfig ¶ added in v0.10.8
GetImageConfig 获取图片配置
func GetImageFromUrl ¶
GetImageFromUrl 获取图片的类型和base64编码的数据
func GetMimeType ¶ added in v0.10.8
GetMimeType 获取文件的 MIME 类型
func GetMimeTypeByExtension ¶
func GetMjRequestModel ¶
func GetMjRequestModel(relayMode int, midjRequest *dto.MidjourneyRequest) (string, *dto.MidjourneyResponse, bool)
func GetUserAutoGroup ¶
GetUserAutoGroup 根据用户分组获取自动分组设置
func GetUserGroupRatio ¶
GetUserGroupRatio 获取用户使用某个分组的倍率 userGroup 用户分组 group 需要获取倍率的分组
func GetUserUsableGroups ¶
func GroupInUserUsableGroups ¶
func HasCSAMViolationMarker ¶
func HasCSAMViolationMarker(err *types.NewAPIError) bool
func IOCopyBytesGracefully ¶
func InitAc ¶
func InitAc(dict []string) *goahocorasick.Machine
func InitHttpClient ¶
func InitHttpClient()
func InitTokenEncoders ¶
func InitTokenEncoders()
func IsViolationFeeCode ¶
func LoadFileSource ¶ added in v0.10.8
func LoadFileSource(c *gin.Context, source *types.FileSource, reason ...string) (*types.CachedFileData, error)
LoadFileSource 加载文件源数据 这是统一的入口,会自动处理缓存和不同的来源类型
func MarkChannelAffinityUsed ¶
func MidjourneyErrorWithStatusCodeWrapper ¶
func MidjourneyErrorWithStatusCodeWrapper(code int, desc string, statusCode int) *dto.MidjourneyResponseWithStatusCode
func MidjourneyErrorWrapper ¶
func MidjourneyErrorWrapper(code int, desc string) *dto.MidjourneyResponse
func NewProxyHttpClient ¶
NewProxyHttpClient 创建支持代理的 HTTP 客户端
func NormalizeViolationFeeError ¶
func NormalizeViolationFeeError(err *types.NewAPIError) *types.NewAPIError
NormalizeViolationFeeError ensures: - if the CSAM marker is present, error.code is set to a stable violation-fee code and skip-retry is enabled. - if error.code already has the violation-fee prefix, skip-retry is enabled.
It must be called before retry decision logic.
func NotifyRootUser ¶
func NotifyUser ¶
func PostAudioConsumeQuota ¶
func PostClaudeConsumeQuota ¶
func PostConsumeQuota ¶
func PostWssConsumeQuota ¶
func PostWssConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, modelName string, usage *dto.RealtimeUsage, extraContent string)
func PreConsumeBilling ¶ added in v0.10.8
func PreConsumeBilling(c *gin.Context, preConsumedQuota int, relayInfo *relaycommon.RelayInfo) *types.NewAPIError
PreConsumeBilling 根据用户计费偏好创建 BillingSession 并执行预扣费。 会话存储在 relayInfo.Billing 上,供后续 Settle / Refund 使用。
func PreConsumeTokenQuota ¶
func PreConsumeTokenQuota(relayInfo *relaycommon.RelayInfo, quota int) error
func PreWssConsumeQuota ¶
func PreWssConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, usage *dto.RealtimeUsage) error
func RecordChannelAffinity ¶
func RelayErrorHandler ¶
func RemoveDuplicate ¶
func ResetProxyClientCache ¶
func ResetProxyClientCache()
ResetProxyClientCache 清空代理客户端缓存,确保下次使用时重新初始化
func ResetStatusCode ¶
func ResetStatusCode(newApiErr *types.NewAPIError, statusCodeMappingStr string)
func ResponseOpenAI2Claude ¶
func ResponseOpenAI2Claude(openAIResponse *dto.OpenAITextResponse, info *relaycommon.RelayInfo) *dto.ClaudeResponse
func ResponseOpenAI2Gemini ¶
func ResponseOpenAI2Gemini(openAIResponse *dto.OpenAITextResponse, info *relaycommon.RelayInfo) *dto.GeminiChatResponse
ResponseOpenAI2Gemini 将 OpenAI 响应转换为 Gemini 格式
func ResponseText2Usage ¶
func ResponsesResponseToChatCompletionsResponse ¶
func ResponsesResponseToChatCompletionsResponse(resp *dto.OpenAIResponsesResponse, id string) (*dto.OpenAITextResponse, *dto.Usage, error)
func SendWebhookNotify ¶
SendWebhookNotify 发送 webhook 通知
func SensitiveWordContains ¶
SensitiveWordContains 是否包含敏感词,返回是否包含敏感词和敏感词列表
func SensitiveWordReplace ¶
SensitiveWordReplace 敏感词替换,返回是否包含敏感词和替换后的文本
func SettleBilling ¶ added in v0.10.8
SettleBilling 执行计费结算。如果 RelayInfo 上有 BillingSession 则通过 session 结算, 否则回退到旧的 PostConsumeQuota 路径(兼容按次计费等场景)。
func ShouldChatCompletionsUseResponsesPolicy ¶
func ShouldChatCompletionsUseResponsesPolicy(policy model_setting.ChatCompletionsToResponsesPolicy, channelID int, channelType int, model string) bool
func ShouldDisableChannel ¶
func ShouldDisableChannel(channelType int, err *types.NewAPIError) bool
func ShouldEnableChannel ¶
func ShouldEnableChannel(newAPIError *types.NewAPIError, status int) bool
func StartCodexCredentialAutoRefreshTask ¶
func StartCodexCredentialAutoRefreshTask()
func StartSubscriptionQuotaResetTask ¶ added in v0.10.8
func StartSubscriptionQuotaResetTask()
func StreamResponseOpenAI2Claude ¶
func StreamResponseOpenAI2Claude(openAIResponse *dto.ChatCompletionsStreamResponse, info *relaycommon.RelayInfo) []*dto.ClaudeResponse
func StreamResponseOpenAI2Gemini ¶
func StreamResponseOpenAI2Gemini(openAIResponse *dto.ChatCompletionsStreamResponse, info *relaycommon.RelayInfo) *dto.GeminiChatResponse
StreamResponseOpenAI2Gemini 将 OpenAI 流式响应转换为 Gemini 格式
func SundaySearch ¶
func TaskErrorWrapper ¶
func TaskErrorWrapperLocal ¶
func ValidUsage ¶
func WrapAsViolationFeeGrokCSAM ¶
func WrapAsViolationFeeGrokCSAM(err *types.NewAPIError) *types.NewAPIError
Types ¶
type BillingSession ¶ added in v0.10.8
type BillingSession struct {
// contains filtered or unexported fields
}
BillingSession 封装单次请求的预扣费/结算/退款生命周期。 实现 relaycommon.BillingSettler 接口。
func NewBillingSession ¶ added in v0.10.8
func NewBillingSession(c *gin.Context, relayInfo *relaycommon.RelayInfo, preConsumedQuota int) (*BillingSession, *types.NewAPIError)
NewBillingSession 根据用户计费偏好创建 BillingSession,处理 subscription_first / wallet_first 的回退。
func (*BillingSession) GetPreConsumedQuota ¶ added in v0.10.8
func (s *BillingSession) GetPreConsumedQuota() int
GetPreConsumedQuota 返回实际预扣的额度。
func (*BillingSession) NeedsRefund ¶ added in v0.10.8
func (s *BillingSession) NeedsRefund() bool
NeedsRefund 返回是否存在需要退还的预扣状态。
func (*BillingSession) Refund ¶ added in v0.10.8
func (s *BillingSession) Refund(c *gin.Context)
Refund 退还所有预扣费,幂等安全,异步执行。
func (*BillingSession) Settle ¶ added in v0.10.8
func (s *BillingSession) Settle(actualQuota int) error
Settle 根据实际消耗额度进行结算。 资金来源和令牌额度分两步提交:若资金来源已提交但令牌调整失败, 会标记 fundingSettled 防止 Refund 对已提交的资金来源执行退款。
type ChannelAffinityCacheStats ¶
type ChannelAffinityCacheStats struct {
Enabled bool `json:"enabled"`
Total int `json:"total"`
Unknown int `json:"unknown"`
ByRuleName map[string]int `json:"by_rule_name"`
CacheCapacity int `json:"cache_capacity"`
CacheAlgo string `json:"cache_algo"`
}
func GetChannelAffinityCacheStats ¶
func GetChannelAffinityCacheStats() ChannelAffinityCacheStats
type ChannelAffinityStatsContext ¶
type ChannelAffinityStatsContext struct {
RuleName string
UsingGroup string
KeyFingerprint string
TTLSeconds int64
}
func GetChannelAffinityStatsContext ¶
func GetChannelAffinityStatsContext(c *gin.Context) (ChannelAffinityStatsContext, bool)
type ChannelAffinityUsageCacheCounters ¶
type ChannelAffinityUsageCacheCounters struct {
Hit int64 `json:"hit"`
Total int64 `json:"total"`
WindowSeconds int64 `json:"window_seconds"`
PromptTokens int64 `json:"prompt_tokens"`
CompletionTokens int64 `json:"completion_tokens"`
TotalTokens int64 `json:"total_tokens"`
CachedTokens int64 `json:"cached_tokens"`
PromptCacheHitTokens int64 `json:"prompt_cache_hit_tokens"`
LastSeenAt int64 `json:"last_seen_at"`
}
type ChannelAffinityUsageCacheStats ¶
type ChannelAffinityUsageCacheStats struct {
RuleName string `json:"rule_name"`
UsingGroup string `json:"using_group"`
KeyFingerprint string `json:"key_fp"`
Hit int64 `json:"hit"`
Total int64 `json:"total"`
WindowSeconds int64 `json:"window_seconds"`
PromptTokens int64 `json:"prompt_tokens"`
CompletionTokens int64 `json:"completion_tokens"`
TotalTokens int64 `json:"total_tokens"`
CachedTokens int64 `json:"cached_tokens"`
PromptCacheHitTokens int64 `json:"prompt_cache_hit_tokens"`
LastSeenAt int64 `json:"last_seen_at"`
}
func GetChannelAffinityUsageCacheStats ¶
func GetChannelAffinityUsageCacheStats(ruleName, usingGroup, keyFp string) ChannelAffinityUsageCacheStats
type CodexCredentialRefreshOptions ¶
type CodexCredentialRefreshOptions struct {
ResetCaches bool
}
type CodexOAuthAuthorizationFlow ¶
type CodexOAuthAuthorizationFlow struct {
State string
Verifier string
Challenge string
AuthorizeURL string
}
func CreateCodexOAuthAuthorizationFlow ¶
func CreateCodexOAuthAuthorizationFlow() (*CodexOAuthAuthorizationFlow, error)
type CodexOAuthKey ¶
type CodexOAuthKey struct {
IDToken string `json:"id_token,omitempty"`
AccessToken string `json:"access_token,omitempty"`
RefreshToken string `json:"refresh_token,omitempty"`
AccountID string `json:"account_id,omitempty"`
LastRefresh string `json:"last_refresh,omitempty"`
Email string `json:"email,omitempty"`
Type string `json:"type,omitempty"`
Expired string `json:"expired,omitempty"`
}
func RefreshCodexChannelCredential ¶
func RefreshCodexChannelCredential(ctx context.Context, channelID int, opts CodexCredentialRefreshOptions) (*CodexOAuthKey, *model.Channel, error)
type CodexOAuthTokenResult ¶
func RefreshCodexOAuthToken ¶
func RefreshCodexOAuthToken(ctx context.Context, refreshToken string) (*CodexOAuthTokenResult, error)
type FundingSource ¶ added in v0.10.8
type FundingSource interface {
// Source 返回资金来源标识:"wallet" 或 "subscription"
Source() string
// PreConsume 从该资金来源预扣 amount 额度
PreConsume(amount int) error
// Settle 根据差额调整资金来源(正数补扣,负数退还)
Settle(delta int) error
// Refund 退还所有预扣费
Refund() error
}
FundingSource 抽象了预扣费的资金来源。
type QuotaInfo ¶
type QuotaInfo struct {
InputDetails TokenDetails
OutputDetails TokenDetails
ModelName string
UsePrice bool
ModelPrice float64
ModelRatio float64
GroupRatio float64
}
type RetryParam ¶
type RetryParam struct {
Ctx *gin.Context
TokenGroup string
ModelName string
Retry *int
// contains filtered or unexported fields
}
func (*RetryParam) GetRetry ¶
func (p *RetryParam) GetRetry() int
func (*RetryParam) IncreaseRetry ¶
func (p *RetryParam) IncreaseRetry()
func (*RetryParam) ResetRetryNextTry ¶
func (p *RetryParam) ResetRetryNextTry()
func (*RetryParam) SetRetry ¶
func (p *RetryParam) SetRetry(retry int)
type SubscriptionFunding ¶ added in v0.10.8
type SubscriptionFunding struct {
// 以下字段在 PreConsume 成功后填充,供 RelayInfo 同步使用
AmountTotal int64
AmountUsedAfter int64
PlanId int
PlanTitle string
// contains filtered or unexported fields
}
func (*SubscriptionFunding) PreConsume ¶ added in v0.10.8
func (s *SubscriptionFunding) PreConsume(_ int) error
func (*SubscriptionFunding) Refund ¶ added in v0.10.8
func (s *SubscriptionFunding) Refund() error
func (*SubscriptionFunding) Settle ¶ added in v0.10.8
func (s *SubscriptionFunding) Settle(delta int) error
func (*SubscriptionFunding) Source ¶ added in v0.10.8
func (s *SubscriptionFunding) Source() string
type TokenDetails ¶
type WalletFunding ¶ added in v0.10.8
type WalletFunding struct {
// contains filtered or unexported fields
}
func (*WalletFunding) PreConsume ¶ added in v0.10.8
func (w *WalletFunding) PreConsume(amount int) error
func (*WalletFunding) Refund ¶ added in v0.10.8
func (w *WalletFunding) Refund() error
func (*WalletFunding) Settle ¶ added in v0.10.8
func (w *WalletFunding) Settle(delta int) error
func (*WalletFunding) Source ¶ added in v0.10.8
func (w *WalletFunding) Source() string
type WebhookPayload ¶
type WebhookPayload struct {
Type string `json:"type"`
Title string `json:"title"`
Content string `json:"content"`
Values []interface{} `json:"values,omitempty"`
Timestamp int64 `json:"timestamp"`
}
WebhookPayload webhook 通知的负载数据
type WorkerRequest ¶
type WorkerRequest struct {
URL string `json:"url"`
Key string `json:"key"`
Method string `json:"method,omitempty"`
Headers map[string]string `json:"headers,omitempty"`
Body json.RawMessage `json:"body,omitempty"`
}
WorkerRequest Worker请求的数据结构
Source Files
¶
- audio.go
- billing.go
- billing_session.go
- channel.go
- channel_affinity.go
- channel_select.go
- codex_credential_refresh.go
- codex_credential_refresh_task.go
- codex_oauth.go
- codex_wham_usage.go
- convert.go
- download.go
- epay.go
- error.go
- file_decoder.go
- file_service.go
- funding_source.go
- group.go
- http.go
- http_client.go
- image.go
- log_info_generate.go
- midjourney.go
- notify-limit.go
- openai_chat_responses_compat.go
- openai_chat_responses_mode.go
- quota.go
- sensitive.go
- str.go
- subscription_reset_task.go
- task.go
- token_counter.go
- token_estimator.go
- tokenizer.go
- usage_helpr.go
- user_notify.go
- violation_fee.go
- webhook.go