Commit 1f9134cd by CaIon

feat: add support for multi-key channels in RelayInfo and access token caching

parent d7491096
...@@ -36,7 +36,12 @@ var Cache = asynccache.NewAsyncCache(asynccache.Options{ ...@@ -36,7 +36,12 @@ var Cache = asynccache.NewAsyncCache(asynccache.Options{
}) })
func getAccessToken(a *Adaptor, info *relaycommon.RelayInfo) (string, error) { func getAccessToken(a *Adaptor, info *relaycommon.RelayInfo) (string, error) {
cacheKey := fmt.Sprintf("access-token-%d", info.ChannelId) var cacheKey string
if info.ChannelIsMultiKey {
cacheKey = fmt.Sprintf("access-token-%d-%d", info.ChannelId, info.ChannelMultiKeyIndex)
} else {
cacheKey = fmt.Sprintf("access-token-%d", info.ChannelId)
}
val, err := Cache.Get(cacheKey) val, err := Cache.Get(cacheKey)
if err == nil { if err == nil {
return val.(string), nil return val.(string), nil
......
...@@ -62,6 +62,8 @@ type ResponsesUsageInfo struct { ...@@ -62,6 +62,8 @@ type ResponsesUsageInfo struct {
type RelayInfo struct { type RelayInfo struct {
ChannelType int ChannelType int
ChannelId int ChannelId int
ChannelIsMultiKey bool // 是否多密钥
ChannelMultiKeyIndex int // 多密钥索引
TokenId int TokenId int
TokenKey string TokenKey string
UserId int UserId int
...@@ -260,6 +262,9 @@ func GenRelayInfo(c *gin.Context) *RelayInfo { ...@@ -260,6 +262,9 @@ func GenRelayInfo(c *gin.Context) *RelayInfo {
IsFirstThinkingContent: true, IsFirstThinkingContent: true,
SendLastThinkingContent: false, SendLastThinkingContent: false,
}, },
ChannelIsMultiKey: common.GetContextKeyBool(c, constant.ContextKeyChannelIsMultiKey),
ChannelMultiKeyIndex: common.GetContextKeyInt(c, constant.ContextKeyChannelMultiKeyIndex),
} }
if strings.HasPrefix(c.Request.URL.Path, "/pg") { if strings.HasPrefix(c.Request.URL.Path, "/pg") {
info.IsPlayground = true info.IsPlayground = true
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment