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
8a0f707d
authored
Jul 15, 2023
by
JustSong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: retry on failed (close #112)
parent
efdc6c75
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
1 deletions
+30
-1
common/constants.go
+1
-0
controller/relay.go
+10
-0
model/option.go
+3
-0
web/src/components/OperationSetting.js
+16
-1
No files found.
common/constants.go
View file @
8a0f707d
...
@@ -68,6 +68,7 @@ var AutomaticDisableChannelEnabled = false
...
@@ -68,6 +68,7 @@ var AutomaticDisableChannelEnabled = false
var
QuotaRemindThreshold
=
1000
var
QuotaRemindThreshold
=
1000
var
PreConsumedQuota
=
500
var
PreConsumedQuota
=
500
var
ApproximateTokenEnabled
=
false
var
ApproximateTokenEnabled
=
false
var
RetryTimes
=
0
var
RootUserEmail
=
""
var
RootUserEmail
=
""
...
...
controller/relay.go
View file @
8a0f707d
...
@@ -4,6 +4,7 @@ import (
...
@@ -4,6 +4,7 @@ import (
"fmt"
"fmt"
"net/http"
"net/http"
"one-api/common"
"one-api/common"
"strconv"
"strings"
"strings"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin"
...
@@ -132,12 +133,21 @@ func Relay(c *gin.Context) {
...
@@ -132,12 +133,21 @@ func Relay(c *gin.Context) {
err
=
relayTextHelper
(
c
,
relayMode
)
err
=
relayTextHelper
(
c
,
relayMode
)
}
}
if
err
!=
nil
{
if
err
!=
nil
{
retryTimesStr
:=
c
.
Query
(
"retry"
)
retryTimes
,
_
:=
strconv
.
Atoi
(
retryTimesStr
)
if
retryTimesStr
==
""
{
retryTimes
=
common
.
RetryTimes
}
if
retryTimes
>
0
{
c
.
Redirect
(
http
.
StatusTemporaryRedirect
,
fmt
.
Sprintf
(
"%s?retry=%d"
,
c
.
Request
.
URL
.
Path
,
retryTimes
-
1
))
}
else
{
if
err
.
StatusCode
==
http
.
StatusTooManyRequests
{
if
err
.
StatusCode
==
http
.
StatusTooManyRequests
{
err
.
OpenAIError
.
Message
=
"当前分组负载已饱和,请稍后再试,或升级账户以提升服务质量。"
err
.
OpenAIError
.
Message
=
"当前分组负载已饱和,请稍后再试,或升级账户以提升服务质量。"
}
}
c
.
JSON
(
err
.
StatusCode
,
gin
.
H
{
c
.
JSON
(
err
.
StatusCode
,
gin
.
H
{
"error"
:
err
.
OpenAIError
,
"error"
:
err
.
OpenAIError
,
})
})
}
channelId
:=
c
.
GetInt
(
"channel_id"
)
channelId
:=
c
.
GetInt
(
"channel_id"
)
common
.
SysError
(
fmt
.
Sprintf
(
"relay error (channel #%d): %s"
,
channelId
,
err
.
Message
))
common
.
SysError
(
fmt
.
Sprintf
(
"relay error (channel #%d): %s"
,
channelId
,
err
.
Message
))
// https://platform.openai.com/docs/guides/error-codes/api-errors
// https://platform.openai.com/docs/guides/error-codes/api-errors
...
...
model/option.go
View file @
8a0f707d
...
@@ -68,6 +68,7 @@ func InitOptionMap() {
...
@@ -68,6 +68,7 @@ func InitOptionMap() {
common
.
OptionMap
[
"TopUpLink"
]
=
common
.
TopUpLink
common
.
OptionMap
[
"TopUpLink"
]
=
common
.
TopUpLink
common
.
OptionMap
[
"ChatLink"
]
=
common
.
ChatLink
common
.
OptionMap
[
"ChatLink"
]
=
common
.
ChatLink
common
.
OptionMap
[
"QuotaPerUnit"
]
=
strconv
.
FormatFloat
(
common
.
QuotaPerUnit
,
'f'
,
-
1
,
64
)
common
.
OptionMap
[
"QuotaPerUnit"
]
=
strconv
.
FormatFloat
(
common
.
QuotaPerUnit
,
'f'
,
-
1
,
64
)
common
.
OptionMap
[
"RetryTimes"
]
=
strconv
.
Itoa
(
common
.
RetryTimes
)
common
.
OptionMapRWMutex
.
Unlock
()
common
.
OptionMapRWMutex
.
Unlock
()
loadOptionsFromDatabase
()
loadOptionsFromDatabase
()
}
}
...
@@ -196,6 +197,8 @@ func updateOptionMap(key string, value string) (err error) {
...
@@ -196,6 +197,8 @@ func updateOptionMap(key string, value string) (err error) {
common
.
QuotaRemindThreshold
,
_
=
strconv
.
Atoi
(
value
)
common
.
QuotaRemindThreshold
,
_
=
strconv
.
Atoi
(
value
)
case
"PreConsumedQuota"
:
case
"PreConsumedQuota"
:
common
.
PreConsumedQuota
,
_
=
strconv
.
Atoi
(
value
)
common
.
PreConsumedQuota
,
_
=
strconv
.
Atoi
(
value
)
case
"RetryTimes"
:
common
.
RetryTimes
,
_
=
strconv
.
Atoi
(
value
)
case
"ModelRatio"
:
case
"ModelRatio"
:
err
=
common
.
UpdateModelRatioByJSONString
(
value
)
err
=
common
.
UpdateModelRatioByJSONString
(
value
)
case
"GroupRatio"
:
case
"GroupRatio"
:
...
...
web/src/components/OperationSetting.js
View file @
8a0f707d
...
@@ -20,6 +20,7 @@ const OperationSetting = () => {
...
@@ -20,6 +20,7 @@ const OperationSetting = () => {
DisplayInCurrencyEnabled
:
''
,
DisplayInCurrencyEnabled
:
''
,
DisplayTokenStatEnabled
:
''
,
DisplayTokenStatEnabled
:
''
,
ApproximateTokenEnabled
:
''
,
ApproximateTokenEnabled
:
''
,
RetryTimes
:
0
,
});
});
const
[
originInputs
,
setOriginInputs
]
=
useState
({});
const
[
originInputs
,
setOriginInputs
]
=
useState
({});
let
[
loading
,
setLoading
]
=
useState
(
false
);
let
[
loading
,
setLoading
]
=
useState
(
false
);
...
@@ -122,6 +123,9 @@ const OperationSetting = () => {
...
@@ -122,6 +123,9 @@ const OperationSetting = () => {
if
(
originInputs
[
'QuotaPerUnit'
]
!==
inputs
.
QuotaPerUnit
)
{
if
(
originInputs
[
'QuotaPerUnit'
]
!==
inputs
.
QuotaPerUnit
)
{
await
updateOption
(
'QuotaPerUnit'
,
inputs
.
QuotaPerUnit
);
await
updateOption
(
'QuotaPerUnit'
,
inputs
.
QuotaPerUnit
);
}
}
if
(
originInputs
[
'RetryTimes'
]
!==
inputs
.
RetryTimes
)
{
await
updateOption
(
'RetryTimes'
,
inputs
.
RetryTimes
);
}
break
;
break
;
}
}
};
};
...
@@ -133,7 +137,7 @@ const OperationSetting = () => {
...
@@ -133,7 +137,7 @@ const OperationSetting = () => {
<
Header
as
=
'h3'
>
<
Header
as
=
'h3'
>
通用设置
通用设置
<
/Header
>
<
/Header
>
<
Form
.
Group
widths
=
{
3
}
>
<
Form
.
Group
widths
=
{
4
}
>
<
Form
.
Input
<
Form
.
Input
label
=
'充值链接'
label
=
'充值链接'
name
=
'TopUpLink'
name
=
'TopUpLink'
...
@@ -162,6 +166,17 @@ const OperationSetting = () => {
...
@@ -162,6 +166,17 @@ const OperationSetting = () => {
step
=
'0.01'
step
=
'0.01'
placeholder
=
'一单位货币能兑换的额度'
placeholder
=
'一单位货币能兑换的额度'
/>
/>
<
Form
.
Input
label
=
'失败重试次数'
name
=
'RetryTimes'
type
=
{
'number'
}
step
=
'1'
min
=
'0'
onChange
=
{
handleInputChange
}
autoComplete
=
'new-password'
value
=
{
inputs
.
RetryTimes
}
placeholder
=
'失败重试次数'
/>
<
/Form.Group
>
<
/Form.Group
>
<
Form
.
Group
inline
>
<
Form
.
Group
inline
>
<
Form
.
Checkbox
<
Form
.
Checkbox
...
...
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