Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ tiktoken_cache
.aider*
.history/
.kiro/
.venv
.venv
main
6 changes: 3 additions & 3 deletions controller/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func Relay(c *gin.Context) {
if openaiErr == nil {
// 检查是否实际写入了响应内容
responseWritten := c.GetBool("response_written")
if !responseWritten && model_setting.GetGlobalSettings().AutoRetryEnabled {
if !responseWritten && model_setting.ShouldTreatEmptyResponseAsError() {
// 创建一个表示空回复的错误,以便触发重试
openaiErr = service.OpenAIErrorWrapperLocal(
fmt.Errorf("empty response from upstream"),
Expand Down Expand Up @@ -392,8 +392,8 @@ func shouldRetryWithAutoConfig(c *gin.Context, openaiErr *dto.OpenAIErrorWithSta
return false
}

// 对于空回复的情况,也应该重试
if openaiErr.Error.Message == "" || strings.Contains(strings.ToLower(openaiErr.Error.Message), "empty") {
// 对于空回复的情况,根据配置决定是否重试
if model_setting.ShouldTreatEmptyResponseAsError() && (openaiErr.Error.Message == "" || strings.Contains(strings.ToLower(openaiErr.Error.Message), "empty")) {
return true
}

Expand Down
7 changes: 7 additions & 0 deletions setting/model_setting/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type GlobalSettings struct {
AutoRetryCount int `json:"auto_retry_count"`
AutoRetryForceChannelSwitch bool `json:"auto_retry_force_channel_switch"`
AutoRetryStatusCodes string `json:"auto_retry_status_codes"`
EmptyResponseRetryEnabled bool `json:"empty_response_retry_enabled"`
}

// 默认配置
Expand All @@ -49,6 +50,7 @@ var defaultOpenaiSettings = GlobalSettings{
AutoRetryCount: 3,
AutoRetryForceChannelSwitch: false,
AutoRetryStatusCodes: "5xx,4xx",
EmptyResponseRetryEnabled: false,
}

// 全局实例
Expand Down Expand Up @@ -84,6 +86,11 @@ func ShouldForceChannelSwitch() bool {
return globalSettings.AutoRetryEnabled && globalSettings.AutoRetryForceChannelSwitch
}

// ShouldTreatEmptyResponseAsError 是否将空回复视为错误并触发重试
func ShouldTreatEmptyResponseAsError() bool {
return globalSettings.AutoRetryEnabled && globalSettings.EmptyResponseRetryEnabled
}

// ShouldRetryForStatusCode 检查状态码是否应该重试
func ShouldRetryForStatusCode(statusCode int) bool {
if !globalSettings.AutoRetryEnabled {
Expand Down
4 changes: 3 additions & 1 deletion web/src/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1525,5 +1525,7 @@
"请先选择要设置标签的渠道!": "Please select the channel to set the tag first!",
"标签不能为空!": "Tag cannot be empty!",
"已为 {{count}} 个渠道设置标签!": "{{count}} channels have been set with tags!",
"已选择 {{count}} 个渠道": "{{count}} channels selected"
"已选择 {{count}} 个渠道": "{{count}} channels selected",
"空回复视为错误": "Treat empty responses as errors",
"空回复将触发自动重试与渠道切换": "Empty responses trigger automatic retry and channel switching"
}
4 changes: 3 additions & 1 deletion web/src/i18n/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,7 @@
"已完成": "已完成",
"失败": "失败",
"已取消": "已取消",
"刷新": "刷新"
"刷新": "刷新",
"空回复视为错误": "空回复视为错误",
"空回复将触发自动重试与渠道切换": "空回复将触发自动重试与渠道切换"
}
17 changes: 17 additions & 0 deletions web/src/pages/Setting/Model/SettingGlobalModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export default function SettingGlobalModel(props) {
'global.auto_retry_count': 3,
'global.auto_retry_force_channel_switch': false,
'global.auto_retry_status_codes': '5xx,4xx',
'global.empty_response_retry_enabled': false,
'general_setting.ping_interval_enabled': false,
'general_setting.ping_interval_seconds': 60,
});
Expand Down Expand Up @@ -279,6 +280,22 @@ export default function SettingGlobalModel(props) {
/>
</Col>
</Row>
<Row>
<Col xs={24} sm={12} md={8} lg={8} xl={8}>
<Form.Switch
label={t('空回复视为错误')}
field={'global.empty_response_retry_enabled'}
onChange={(value) =>
setInputs({
...inputs,
'global.empty_response_retry_enabled': value,
})
}
extraText={t('空回复将触发自动重试与渠道切换')}
disabled={!inputs['global.auto_retry_enabled']}
/>
</Col>
</Row>
</Form.Section>

<Form.Section text={t('连接保活设置')}>
Expand Down