This commit introduces a major architectural refactoring to improve quota management, centralize logging, and streamline the relay handling logic. Key changes: - **Pre-consume Quota:** Implements a new mechanism to check and reserve user quota *before* making the request to the upstream provider. This ensures more accurate quota deduction and prevents users from exceeding their limits due to concurrent requests. - **Unified Relay Handlers:** Refactors the relay logic to use generic handlers (e.g., `ChatHandler`, `ImageHandler`) instead of provider-specific implementations. This significantly reduces code duplication and simplifies adding new channels. - **Centralized Logger:** A new dedicated `logger` package is introduced, and all system logging calls are migrated to use it, moving this responsibility out of the `common` package. - **Code Reorganization:** DTOs are generalized (e.g., `dalle.go` -> `openai_image.go`) and utility code is moved to more appropriate packages (e.g., `common/http.go` -> `service/http.go`) for better code structure.
49 lines
2.2 KiB
Go
49 lines
2.2 KiB
Go
package constant
|
|
|
|
type ContextKey string
|
|
|
|
const (
|
|
ContextKeyPromptTokens ContextKey = "prompt_tokens"
|
|
|
|
ContextKeyOriginalModel ContextKey = "original_model"
|
|
ContextKeyRequestStartTime ContextKey = "request_start_time"
|
|
|
|
/* token related keys */
|
|
ContextKeyTokenUnlimited ContextKey = "token_unlimited_quota"
|
|
ContextKeyTokenKey ContextKey = "token_key"
|
|
ContextKeyTokenId ContextKey = "token_id"
|
|
ContextKeyTokenGroup ContextKey = "token_group"
|
|
ContextKeyTokenSpecificChannelId ContextKey = "specific_channel_id"
|
|
ContextKeyTokenModelLimitEnabled ContextKey = "token_model_limit_enabled"
|
|
ContextKeyTokenModelLimit ContextKey = "token_model_limit"
|
|
|
|
/* channel related keys */
|
|
ContextKeyChannelId ContextKey = "channel_id"
|
|
ContextKeyChannelName ContextKey = "channel_name"
|
|
ContextKeyChannelCreateTime ContextKey = "channel_create_time"
|
|
ContextKeyChannelBaseUrl ContextKey = "base_url"
|
|
ContextKeyChannelType ContextKey = "channel_type"
|
|
ContextKeyChannelSetting ContextKey = "channel_setting"
|
|
ContextKeyChannelOtherSetting ContextKey = "channel_other_setting"
|
|
ContextKeyChannelParamOverride ContextKey = "param_override"
|
|
ContextKeyChannelOrganization ContextKey = "channel_organization"
|
|
ContextKeyChannelAutoBan ContextKey = "auto_ban"
|
|
ContextKeyChannelModelMapping ContextKey = "model_mapping"
|
|
ContextKeyChannelStatusCodeMapping ContextKey = "status_code_mapping"
|
|
ContextKeyChannelIsMultiKey ContextKey = "channel_is_multi_key"
|
|
ContextKeyChannelMultiKeyIndex ContextKey = "channel_multi_key_index"
|
|
ContextKeyChannelKey ContextKey = "channel_key"
|
|
|
|
/* user related keys */
|
|
ContextKeyUserId ContextKey = "id"
|
|
ContextKeyUserSetting ContextKey = "user_setting"
|
|
ContextKeyUserQuota ContextKey = "user_quota"
|
|
ContextKeyUserStatus ContextKey = "user_status"
|
|
ContextKeyUserEmail ContextKey = "user_email"
|
|
ContextKeyUserGroup ContextKey = "user_group"
|
|
ContextKeyUsingGroup ContextKey = "group"
|
|
ContextKeyUserName ContextKey = "username"
|
|
|
|
ContextKeySystemPromptOverride ContextKey = "system_prompt_override"
|
|
)
|