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
e7d91d01
authored
Aug 08, 2025
by
Yincmewy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feats:replace GLM-4v authentication headers to support customize api key
parent
b3a1948a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
1 additions
and
61 deletions
+1
-61
relay/channel/zhipu_4v/adaptor.go
+1
-2
relay/channel/zhipu_4v/relay-zhipu_v4.go
+0
-59
No files found.
relay/channel/zhipu_4v/adaptor.go
View file @
e7d91d01
...
@@ -54,8 +54,7 @@ func (a *Adaptor) GetRequestURL(info *relaycommon.RelayInfo) (string, error) {
...
@@ -54,8 +54,7 @@ func (a *Adaptor) GetRequestURL(info *relaycommon.RelayInfo) (string, error) {
func
(
a
*
Adaptor
)
SetupRequestHeader
(
c
*
gin
.
Context
,
req
*
http
.
Header
,
info
*
relaycommon
.
RelayInfo
)
error
{
func
(
a
*
Adaptor
)
SetupRequestHeader
(
c
*
gin
.
Context
,
req
*
http
.
Header
,
info
*
relaycommon
.
RelayInfo
)
error
{
channel
.
SetupApiRequestHeader
(
info
,
c
,
req
)
channel
.
SetupApiRequestHeader
(
info
,
c
,
req
)
token
:=
getZhipuToken
(
info
.
ApiKey
)
req
.
Set
(
"Authorization"
,
"Bearer "
+
info
.
ApiKey
)
req
.
Set
(
"Authorization"
,
token
)
return
nil
return
nil
}
}
...
...
relay/channel/zhipu_4v/relay-zhipu_v4.go
View file @
e7d91d01
package
zhipu_4v
package
zhipu_4v
import
(
import
(
"github.com/golang-jwt/jwt"
"one-api/common"
"one-api/dto"
"one-api/dto"
"strings"
"strings"
"sync"
"time"
)
)
// https://open.bigmodel.cn/doc/api#chatglm_std
// chatglm_std, chatglm_lite
// https://open.bigmodel.cn/api/paas/v3/model-api/chatglm_std/invoke
// https://open.bigmodel.cn/api/paas/v3/model-api/chatglm_std/sse-invoke
var
zhipuTokens
sync
.
Map
var
expSeconds
int64
=
24
*
3600
func
getZhipuToken
(
apikey
string
)
string
{
data
,
ok
:=
zhipuTokens
.
Load
(
apikey
)
if
ok
{
tokenData
:=
data
.
(
tokenData
)
if
time
.
Now
()
.
Before
(
tokenData
.
ExpiryTime
)
{
return
tokenData
.
Token
}
}
split
:=
strings
.
Split
(
apikey
,
"."
)
if
len
(
split
)
!=
2
{
common
.
SysError
(
"invalid zhipu key: "
+
apikey
)
return
""
}
id
:=
split
[
0
]
secret
:=
split
[
1
]
expMillis
:=
time
.
Now
()
.
Add
(
time
.
Duration
(
expSeconds
)
*
time
.
Second
)
.
UnixNano
()
/
1e6
expiryTime
:=
time
.
Now
()
.
Add
(
time
.
Duration
(
expSeconds
)
*
time
.
Second
)
timestamp
:=
time
.
Now
()
.
UnixNano
()
/
1e6
payload
:=
jwt
.
MapClaims
{
"api_key"
:
id
,
"exp"
:
expMillis
,
"timestamp"
:
timestamp
,
}
token
:=
jwt
.
NewWithClaims
(
jwt
.
SigningMethodHS256
,
payload
)
token
.
Header
[
"alg"
]
=
"HS256"
token
.
Header
[
"sign_type"
]
=
"SIGN"
tokenString
,
err
:=
token
.
SignedString
([]
byte
(
secret
))
if
err
!=
nil
{
return
""
}
zhipuTokens
.
Store
(
apikey
,
tokenData
{
Token
:
tokenString
,
ExpiryTime
:
expiryTime
,
})
return
tokenString
}
func
requestOpenAI2Zhipu
(
request
dto
.
GeneralOpenAIRequest
)
*
dto
.
GeneralOpenAIRequest
{
func
requestOpenAI2Zhipu
(
request
dto
.
GeneralOpenAIRequest
)
*
dto
.
GeneralOpenAIRequest
{
messages
:=
make
([]
dto
.
Message
,
0
,
len
(
request
.
Messages
))
messages
:=
make
([]
dto
.
Message
,
0
,
len
(
request
.
Messages
))
for
_
,
message
:=
range
request
.
Messages
{
for
_
,
message
:=
range
request
.
Messages
{
...
...
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