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
1661d34f
authored
Sep 18, 2023
by
JustSong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: fix unable to set zero value for base url & model mapping
parent
977015ac
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
28 additions
and
17 deletions
+28
-17
controller/channel-billing.go
+6
-6
controller/channel-test.go
+3
-3
middleware/distributor.go
+2
-2
model/channel.go
+17
-3
web/src/pages/Channel/EditChannel.js
+0
-3
No files found.
controller/channel-billing.go
View file @
1661d34f
...
@@ -111,7 +111,7 @@ func GetResponseBody(method, url string, channel *model.Channel, headers http.He
...
@@ -111,7 +111,7 @@ func GetResponseBody(method, url string, channel *model.Channel, headers http.He
}
}
func
updateChannelCloseAIBalance
(
channel
*
model
.
Channel
)
(
float64
,
error
)
{
func
updateChannelCloseAIBalance
(
channel
*
model
.
Channel
)
(
float64
,
error
)
{
url
:=
fmt
.
Sprintf
(
"%s/dashboard/billing/credit_grants"
,
channel
.
BaseURL
)
url
:=
fmt
.
Sprintf
(
"%s/dashboard/billing/credit_grants"
,
channel
.
GetBaseURL
()
)
body
,
err
:=
GetResponseBody
(
"GET"
,
url
,
channel
,
GetAuthHeader
(
channel
.
Key
))
body
,
err
:=
GetResponseBody
(
"GET"
,
url
,
channel
,
GetAuthHeader
(
channel
.
Key
))
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -201,18 +201,18 @@ func updateChannelAIGC2DBalance(channel *model.Channel) (float64, error) {
...
@@ -201,18 +201,18 @@ func updateChannelAIGC2DBalance(channel *model.Channel) (float64, error) {
func
updateChannelBalance
(
channel
*
model
.
Channel
)
(
float64
,
error
)
{
func
updateChannelBalance
(
channel
*
model
.
Channel
)
(
float64
,
error
)
{
baseURL
:=
common
.
ChannelBaseURLs
[
channel
.
Type
]
baseURL
:=
common
.
ChannelBaseURLs
[
channel
.
Type
]
if
channel
.
BaseURL
==
""
{
if
channel
.
GetBaseURL
()
==
""
{
channel
.
BaseURL
=
baseURL
channel
.
BaseURL
=
&
baseURL
}
}
switch
channel
.
Type
{
switch
channel
.
Type
{
case
common
.
ChannelTypeOpenAI
:
case
common
.
ChannelTypeOpenAI
:
if
channel
.
BaseURL
!=
""
{
if
channel
.
GetBaseURL
()
!=
""
{
baseURL
=
channel
.
BaseURL
baseURL
=
channel
.
GetBaseURL
()
}
}
case
common
.
ChannelTypeAzure
:
case
common
.
ChannelTypeAzure
:
return
0
,
errors
.
New
(
"尚未实现"
)
return
0
,
errors
.
New
(
"尚未实现"
)
case
common
.
ChannelTypeCustom
:
case
common
.
ChannelTypeCustom
:
baseURL
=
channel
.
BaseURL
baseURL
=
channel
.
GetBaseURL
()
case
common
.
ChannelTypeCloseAI
:
case
common
.
ChannelTypeCloseAI
:
return
updateChannelCloseAIBalance
(
channel
)
return
updateChannelCloseAIBalance
(
channel
)
case
common
.
ChannelTypeOpenAISB
:
case
common
.
ChannelTypeOpenAISB
:
...
...
controller/channel-test.go
View file @
1661d34f
...
@@ -42,10 +42,10 @@ func testChannel(channel *model.Channel, request ChatRequest) (err error, openai
...
@@ -42,10 +42,10 @@ func testChannel(channel *model.Channel, request ChatRequest) (err error, openai
}
}
requestURL
:=
common
.
ChannelBaseURLs
[
channel
.
Type
]
requestURL
:=
common
.
ChannelBaseURLs
[
channel
.
Type
]
if
channel
.
Type
==
common
.
ChannelTypeAzure
{
if
channel
.
Type
==
common
.
ChannelTypeAzure
{
requestURL
=
fmt
.
Sprintf
(
"%s/openai/deployments/%s/chat/completions?api-version=2023-03-15-preview"
,
channel
.
BaseURL
,
request
.
Model
)
requestURL
=
fmt
.
Sprintf
(
"%s/openai/deployments/%s/chat/completions?api-version=2023-03-15-preview"
,
channel
.
GetBaseURL
()
,
request
.
Model
)
}
else
{
}
else
{
if
channel
.
BaseURL
!=
""
{
if
channel
.
GetBaseURL
()
!=
""
{
requestURL
=
channel
.
BaseURL
requestURL
=
channel
.
GetBaseURL
()
}
}
requestURL
+=
"/v1/chat/completions"
requestURL
+=
"/v1/chat/completions"
}
}
...
...
middleware/distributor.go
View file @
1661d34f
...
@@ -82,9 +82,9 @@ func Distribute() func(c *gin.Context) {
...
@@ -82,9 +82,9 @@ func Distribute() func(c *gin.Context) {
c
.
Set
(
"channel"
,
channel
.
Type
)
c
.
Set
(
"channel"
,
channel
.
Type
)
c
.
Set
(
"channel_id"
,
channel
.
Id
)
c
.
Set
(
"channel_id"
,
channel
.
Id
)
c
.
Set
(
"channel_name"
,
channel
.
Name
)
c
.
Set
(
"channel_name"
,
channel
.
Name
)
c
.
Set
(
"model_mapping"
,
channel
.
ModelMapping
)
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
))
c
.
Set
(
"base_url"
,
channel
.
BaseURL
)
c
.
Set
(
"base_url"
,
channel
.
GetBaseURL
()
)
switch
channel
.
Type
{
switch
channel
.
Type
{
case
common
.
ChannelTypeAzure
:
case
common
.
ChannelTypeAzure
:
c
.
Set
(
"api_version"
,
channel
.
Other
)
c
.
Set
(
"api_version"
,
channel
.
Other
)
...
...
model/channel.go
View file @
1661d34f
...
@@ -15,14 +15,14 @@ type Channel struct {
...
@@ -15,14 +15,14 @@ type Channel struct {
CreatedTime
int64
`json:"created_time" gorm:"bigint"`
CreatedTime
int64
`json:"created_time" gorm:"bigint"`
TestTime
int64
`json:"test_time" gorm:"bigint"`
TestTime
int64
`json:"test_time" gorm:"bigint"`
ResponseTime
int
`json:"response_time"`
// in milliseconds
ResponseTime
int
`json:"response_time"`
// in milliseconds
BaseURL
string
`json:"base_url" gorm:"column:base_url"`
BaseURL
*
string
`json:"base_url" gorm:"column:base_url"`
Other
string
`json:"other"`
Other
string
`json:"other"`
Balance
float64
`json:"balance"`
// in USD
Balance
float64
`json:"balance"`
// in USD
BalanceUpdatedTime
int64
`json:"balance_updated_time" gorm:"bigint"`
BalanceUpdatedTime
int64
`json:"balance_updated_time" gorm:"bigint"`
Models
string
`json:"models"`
Models
string
`json:"models"`
Group
string
`json:"group" gorm:"type:varchar(32);default:'default'"`
Group
string
`json:"group" gorm:"type:varchar(32);default:'default'"`
UsedQuota
int64
`json:"used_quota" gorm:"bigint;default:0"`
UsedQuota
int64
`json:"used_quota" gorm:"bigint;default:0"`
ModelMapping
string
`json:"model_mapping" gorm:"type:varchar(1024);default:''"`
ModelMapping
*
string
`json:"model_mapping" gorm:"type:varchar(1024);default:''"`
Priority
*
int64
`json:"priority" gorm:"bigint;default:0"`
Priority
*
int64
`json:"priority" gorm:"bigint;default:0"`
}
}
...
@@ -80,12 +80,26 @@ func BatchInsertChannels(channels []Channel) error {
...
@@ -80,12 +80,26 @@ func BatchInsertChannels(channels []Channel) error {
}
}
func
(
channel
*
Channel
)
GetPriority
()
int64
{
func
(
channel
*
Channel
)
GetPriority
()
int64
{
if
channel
==
nil
{
if
channel
.
Priority
==
nil
{
return
0
return
0
}
}
return
*
channel
.
Priority
return
*
channel
.
Priority
}
}
func
(
channel
*
Channel
)
GetBaseURL
()
string
{
if
channel
.
BaseURL
==
nil
{
return
""
}
return
*
channel
.
BaseURL
}
func
(
channel
*
Channel
)
GetModelMapping
()
string
{
if
channel
.
ModelMapping
==
nil
{
return
""
}
return
*
channel
.
ModelMapping
}
func
(
channel
*
Channel
)
Insert
()
error
{
func
(
channel
*
Channel
)
Insert
()
error
{
var
err
error
var
err
error
err
=
DB
.
Create
(
channel
)
.
Error
err
=
DB
.
Create
(
channel
)
.
Error
...
...
web/src/pages/Channel/EditChannel.js
View file @
1661d34f
...
@@ -183,9 +183,6 @@ const EditChannel = () => {
...
@@ -183,9 +183,6 @@ const EditChannel = () => {
if
(
localInputs
.
type
===
18
&&
localInputs
.
other
===
''
)
{
if
(
localInputs
.
type
===
18
&&
localInputs
.
other
===
''
)
{
localInputs
.
other
=
'v2.1'
;
localInputs
.
other
=
'v2.1'
;
}
}
if
(
localInputs
.
model_mapping
===
''
)
{
localInputs
.
model_mapping
=
'{}'
;
}
let
res
;
let
res
;
localInputs
.
models
=
localInputs
.
models
.
join
(
','
);
localInputs
.
models
=
localInputs
.
models
.
join
(
','
);
localInputs
.
group
=
localInputs
.
groups
.
join
(
','
);
localInputs
.
group
=
localInputs
.
groups
.
join
(
','
);
...
...
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