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
403614e2
authored
Mar 18, 2024
by
CaIon
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/main'
parents
865816c8
fadde534
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
8 additions
and
0 deletions
+8
-0
middleware/distributor.go
+3
-0
relay/channel/openai/adaptor.go
+3
-0
relay/common/relay_info.go
+2
-0
No files found.
middleware/distributor.go
View file @
403614e2
...
@@ -155,6 +155,9 @@ func Distribute() func(c *gin.Context) {
...
@@ -155,6 +155,9 @@ func Distribute() func(c *gin.Context) {
if
channel
.
AutoBan
!=
nil
&&
*
channel
.
AutoBan
==
0
{
if
channel
.
AutoBan
!=
nil
&&
*
channel
.
AutoBan
==
0
{
ban
=
false
ban
=
false
}
}
if
nil
!=
channel
.
OpenAIOrganization
{
c
.
Set
(
"channel_organization"
,
*
channel
.
OpenAIOrganization
)
}
c
.
Set
(
"auto_ban"
,
ban
)
c
.
Set
(
"auto_ban"
,
ban
)
c
.
Set
(
"model_mapping"
,
channel
.
GetModelMapping
())
c
.
Set
(
"model_mapping"
,
channel
.
GetModelMapping
())
c
.
Request
.
Header
.
Set
(
"Authorization"
,
fmt
.
Sprintf
(
"Bearer %s"
,
channel
.
Key
))
c
.
Request
.
Header
.
Set
(
"Authorization"
,
fmt
.
Sprintf
(
"Bearer %s"
,
channel
.
Key
))
...
...
relay/channel/openai/adaptor.go
View file @
403614e2
...
@@ -49,6 +49,9 @@ func (a *Adaptor) SetupRequestHeader(c *gin.Context, req *http.Request, info *re
...
@@ -49,6 +49,9 @@ func (a *Adaptor) SetupRequestHeader(c *gin.Context, req *http.Request, info *re
req
.
Header
.
Set
(
"api-key"
,
info
.
ApiKey
)
req
.
Header
.
Set
(
"api-key"
,
info
.
ApiKey
)
return
nil
return
nil
}
}
if
info
.
ChannelType
==
common
.
ChannelTypeOpenAI
&&
""
!=
info
.
Organization
{
req
.
Header
.
Set
(
"OpenAI-Organization"
,
info
.
Organization
)
}
req
.
Header
.
Set
(
"Authorization"
,
"Bearer "
+
info
.
ApiKey
)
req
.
Header
.
Set
(
"Authorization"
,
"Bearer "
+
info
.
ApiKey
)
//if info.ChannelType == common.ChannelTypeOpenRouter {
//if info.ChannelType == common.ChannelTypeOpenRouter {
// req.Header.Set("HTTP-Referer", "https://github.com/songquanpeng/one-api")
// req.Header.Set("HTTP-Referer", "https://github.com/songquanpeng/one-api")
...
...
relay/common/relay_info.go
View file @
403614e2
...
@@ -24,6 +24,7 @@ type RelayInfo struct {
...
@@ -24,6 +24,7 @@ type RelayInfo struct {
ApiVersion
string
ApiVersion
string
PromptTokens
int
PromptTokens
int
ApiKey
string
ApiKey
string
Organization
string
BaseUrl
string
BaseUrl
string
}
}
...
@@ -52,6 +53,7 @@ func GenRelayInfo(c *gin.Context) *RelayInfo {
...
@@ -52,6 +53,7 @@ func GenRelayInfo(c *gin.Context) *RelayInfo {
ApiType
:
apiType
,
ApiType
:
apiType
,
ApiVersion
:
c
.
GetString
(
"api_version"
),
ApiVersion
:
c
.
GetString
(
"api_version"
),
ApiKey
:
strings
.
TrimPrefix
(
c
.
Request
.
Header
.
Get
(
"Authorization"
),
"Bearer "
),
ApiKey
:
strings
.
TrimPrefix
(
c
.
Request
.
Header
.
Get
(
"Authorization"
),
"Bearer "
),
Organization
:
c
.
GetString
(
"channel_organization"
),
}
}
if
info
.
BaseUrl
==
""
{
if
info
.
BaseUrl
==
""
{
info
.
BaseUrl
=
common
.
ChannelBaseURLs
[
channelType
]
info
.
BaseUrl
=
common
.
ChannelBaseURLs
[
channelType
]
...
...
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