2024-04-05 17:50:12 +00:00
|
|
|
package monitor
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/songquanpeng/one-api/common/config"
|
|
|
|
"github.com/songquanpeng/one-api/relay/model"
|
|
|
|
"net/http"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
func ShouldDisableChannel(err *model.Error, statusCode int) bool {
|
|
|
|
if !config.AutomaticDisableChannelEnabled {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if err == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if statusCode == http.StatusUnauthorized {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
switch err.Type {
|
|
|
|
case "insufficient_quota":
|
|
|
|
return true
|
|
|
|
// https://docs.anthropic.com/claude/reference/errors
|
|
|
|
case "authentication_error":
|
|
|
|
return true
|
|
|
|
case "permission_error":
|
|
|
|
return true
|
|
|
|
case "forbidden":
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if err.Code == "invalid_api_key" || err.Code == "account_deactivated" {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if strings.HasPrefix(err.Message, "Your credit balance is too low") { // anthropic
|
|
|
|
return true
|
|
|
|
} else if strings.HasPrefix(err.Message, "This organization has been disabled.") {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
//if strings.Contains(err.Message, "quota") {
|
|
|
|
// return true
|
|
|
|
//}
|
|
|
|
if strings.Contains(err.Message, "credit") {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if strings.Contains(err.Message, "balance") {
|
|
|
|
return true
|
|
|
|
}
|
2024-09-21 14:12:09 +00:00
|
|
|
if strings.Contains(err.Message, "Organization has been restricted") { // groq
|
|
|
|
return true
|
|
|
|
}
|
2024-04-05 17:50:12 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func ShouldEnableChannel(err error, openAIErr *model.Error) bool {
|
|
|
|
if !config.AutomaticEnableChannelEnabled {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if openAIErr != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|