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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ data/
.gomodcache/
.gocache-temp
.gopath
.air.toml
docker-compose.dev.yml
2 changes: 1 addition & 1 deletion common/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func SendEmail(subject string, receiver string, content string) error {
return err2
}
if SMTPServer == "" && SMTPAccount == "" {
return fmt.Errorf("SMTP 服务器未配置")
return fmt.Errorf("SMTP server is not configured")
}
encodedSubject := fmt.Sprintf("=?UTF-8?B?%s?=", base64.StdEncoding.EncodeToString([]byte(subject)))
mail := []byte(fmt.Sprintf("To: %s\r\n"+
Expand Down
1 change: 0 additions & 1 deletion common/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ func InitEnv() {
ss := os.Getenv("SESSION_SECRET")
if ss == "random_string" {
log.Println("WARNING: SESSION_SECRET is set to the default value 'random_string', please change it to a random string.")
log.Println("警告:SESSION_SECRET被设置为默认值'random_string',请修改为随机字符串。")
log.Fatal("Please set SESSION_SECRET to a random string.")
} else {
SessionSecret = ss
Expand Down
6 changes: 3 additions & 3 deletions common/pprof.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ func Monitor() {
if _, err := os.Stat("./pprof"); os.IsNotExist(err) {
err := os.Mkdir("./pprof", os.ModePerm)
if err != nil {
SysLog("创建pprof文件夹失败 " + err.Error())
SysLog("failed to create pprof directory: " + err.Error())
continue
}
}
f, err := os.Create("./pprof/" + fmt.Sprintf("cpu-%s.pprof", time.Now().Format("20060102150405")))
if err != nil {
SysLog("创建pprof文件失败 " + err.Error())
SysLog("failed to create pprof file: " + err.Error())
continue
}
err = pprof.StartCPUProfile(f)
if err != nil {
SysLog("启动pprof失败 " + err.Error())
SysLog("failed to start pprof: " + err.Error())
continue
}
time.Sleep(10 * time.Second) // profile for 30 seconds
Expand Down
4 changes: 2 additions & 2 deletions common/totp.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,12 @@ func ValidateNumericCode(code string) (string, error) {
code = strings.ReplaceAll(code, " ", "")

if len(code) != 6 {
return "", fmt.Errorf("验证码必须是6位数字")
return "", fmt.Errorf("verification code must be 6 digits")
}

// 检查是否为纯数字
if _, err := strconv.Atoi(code); err != nil {
return "", fmt.Errorf("验证码只能包含数字")
return "", fmt.Errorf("verification code must contain digits only")
}

return code, nil
Expand Down
12 changes: 6 additions & 6 deletions common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,26 +162,26 @@ func Bytes2Size(num int64) string {

func Seconds2Time(num int) (time string) {
if num/31104000 > 0 {
time += strconv.Itoa(num/31104000) + " "
time += strconv.Itoa(num/31104000) + " years "
num %= 31104000
}
if num/2592000 > 0 {
time += strconv.Itoa(num/2592000) + " 个月 "
time += strconv.Itoa(num/2592000) + " months "
num %= 2592000
}
if num/86400 > 0 {
time += strconv.Itoa(num/86400) + " "
time += strconv.Itoa(num/86400) + " days "
num %= 86400
}
if num/3600 > 0 {
time += strconv.Itoa(num/3600) + " 小时 "
time += strconv.Itoa(num/3600) + " hours "
num %= 3600
}
if num/60 > 0 {
time += strconv.Itoa(num/60) + " 分钟 "
time += strconv.Itoa(num/60) + " minutes "
num %= 60
}
time += strconv.Itoa(num) + " "
time += strconv.Itoa(num) + " seconds"
return
}

Expand Down
9 changes: 5 additions & 4 deletions controller/channel-billing.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/QuantumNous/new-api/common"
"github.com/QuantumNous/new-api/constant"
"github.com/QuantumNous/new-api/i18n"
"github.com/QuantumNous/new-api/model"
"github.com/QuantumNous/new-api/service"
"github.com/QuantumNous/new-api/setting/operation_setting"
Expand Down Expand Up @@ -367,7 +368,7 @@ func updateChannelBalance(channel *model.Channel) (float64, error) {
baseURL = channel.GetBaseURL()
}
case constant.ChannelTypeAzure:
return 0, errors.New("尚未实现")
return 0, errors.New("not implemented yet")
case constant.ChannelTypeCustom:
baseURL = channel.GetBaseURL()
//case common.ChannelTypeOpenAISB:
Expand All @@ -387,7 +388,7 @@ func updateChannelBalance(channel *model.Channel) (float64, error) {
case constant.ChannelTypeMoonshot:
return updateChannelMoonshotBalance(channel)
default:
return 0, errors.New("尚未实现")
return 0, errors.New("not implemented yet")
}
url := fmt.Sprintf("%s/v1/dashboard/billing/subscription", baseURL)

Expand Down Expand Up @@ -435,7 +436,7 @@ func UpdateChannelBalance(c *gin.Context) {
if channel.ChannelInfo.IsMultiKey {
c.JSON(http.StatusOK, gin.H{
"success": false,
"message": "多密钥渠道不支持余额查询",
"message": i18n.T(c, i18n.MsgChannelMultiKeyBalanceUnsupported),
})
return
}
Expand Down Expand Up @@ -473,7 +474,7 @@ func updateAllChannelsBalance() error {
} else {
// err is nil & balance <= 0 means quota is used up
if balance <= 0 {
service.DisableChannel(*types.NewChannelError(channel.Id, channel.Type, channel.Name, channel.ChannelInfo.IsMultiKey, "", channel.GetAutoBan()), "余额不足")
service.DisableChannel(*types.NewChannelError(channel.Id, channel.Type, channel.Name, channel.ChannelInfo.IsMultiKey, "", channel.GetAutoBan()), "insufficient balance")
}
}
time.Sleep(common.RequestInterval)
Expand Down
10 changes: 5 additions & 5 deletions controller/channel-test.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,9 +488,9 @@ func testChannel(channel *model.Channel, testModel string, endpointType string,
PromptTokens: usage.PromptTokens,
CompletionTokens: usage.CompletionTokens,
ModelName: info.OriginModelName,
TokenName: "模型测试",
TokenName: "model test",
Quota: quota,
Content: "模型测试",
Content: "model test",
UseTimeSeconds: int(consumedTime),
IsStream: info.IsStream,
Group: info.UsingGroup,
Expand Down Expand Up @@ -790,7 +790,7 @@ func testAllChannels(notify bool) error {
testAllChannelsLock.Lock()
if testAllChannelsRunning {
testAllChannelsLock.Unlock()
return errors.New("测试已在运行中")
return errors.New("test is already running")
}
testAllChannelsRunning = true
testAllChannelsLock.Unlock()
Expand Down Expand Up @@ -830,7 +830,7 @@ func testAllChannels(notify bool) error {
// 当错误检查通过,才检查响应时间
if common.AutomaticDisableChannelEnabled && !shouldBanChannel {
if milliseconds > disableThreshold {
err := fmt.Errorf("响应时间 %.2fs 超过阈值 %.2fs", float64(milliseconds)/1000.0, float64(disableThreshold)/1000.0)
err := fmt.Errorf("response time %.2fs exceeded threshold %.2fs", float64(milliseconds)/1000.0, float64(disableThreshold)/1000.0)
newAPIError = types.NewOpenAIError(err, types.ErrorCodeChannelResponseTimeExceeded, http.StatusRequestTimeout)
shouldBanChannel = true
}
Expand All @@ -851,7 +851,7 @@ func testAllChannels(notify bool) error {
}

if notify {
service.NotifyRootUser(dto.NotifyTypeChannelTest, "通道测试完成", "所有通道测试已完成")
service.NotifyRootUser(dto.NotifyTypeChannelTest, "Channel test completed", "All channel tests have completed")
}
})
return nil
Expand Down
Loading