Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
1f9134cd
authored
Aug 02, 2025
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add support for multi-key channels in RelayInfo and access token caching
parent
d7491096
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
12 deletions
+22
-12
relay/channel/vertex/service_account.go
+6
-1
relay/common/relay_info.go
+16
-11
No files found.
relay/channel/vertex/service_account.go
View file @
1f9134cd
...
@@ -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
...
...
relay/common/relay_info.go
View file @
1f9134cd
...
@@ -60,17 +60,19 @@ type ResponsesUsageInfo struct {
...
@@ -60,17 +60,19 @@ type ResponsesUsageInfo struct {
}
}
type
RelayInfo
struct
{
type
RelayInfo
struct
{
ChannelType
int
ChannelType
int
ChannelId
int
ChannelId
int
TokenId
int
ChannelIsMultiKey
bool
// 是否多密钥
TokenKey
string
ChannelMultiKeyIndex
int
// 多密钥索引
UserId
int
TokenId
int
UsingGroup
string
// 使用的分组
TokenKey
string
UserGroup
string
// 用户所在分组
UserId
int
TokenUnlimited
bool
UsingGroup
string
// 使用的分组
StartTime
time
.
Time
UserGroup
string
// 用户所在分组
FirstResponseTime
time
.
Time
TokenUnlimited
bool
isFirstResponse
bool
StartTime
time
.
Time
FirstResponseTime
time
.
Time
isFirstResponse
bool
//SendLastReasoningResponse bool
//SendLastReasoningResponse bool
ApiType
int
ApiType
int
IsStream
bool
IsStream
bool
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment