diff --git a/Dockerfile b/Dockerfile index ade561e408..9cca655c20 100644 --- a/Dockerfile +++ b/Dockerfile @@ -41,4 +41,4 @@ RUN apk update \ COPY --from=builder2 /build/one-api / EXPOSE 3000 WORKDIR /data -ENTRYPOINT ["/one-api"] \ No newline at end of file +ENTRYPOINT ["/one-api"] diff --git a/controller/token.go b/controller/token.go index 668ccd9788..f9e6f418a1 100644 --- a/controller/token.go +++ b/controller/token.go @@ -2,6 +2,9 @@ package controller import ( "fmt" + "net/http" + "strconv" + "github.com/gin-gonic/gin" "github.com/songquanpeng/one-api/common/config" "github.com/songquanpeng/one-api/common/ctxkey" @@ -9,8 +12,6 @@ import ( "github.com/songquanpeng/one-api/common/network" "github.com/songquanpeng/one-api/common/random" "github.com/songquanpeng/one-api/model" - "net/http" - "strconv" ) func GetAllTokens(c *gin.Context) { @@ -213,22 +214,37 @@ func UpdateToken(c *gin.Context) { }) return } - if token.Status == model.TokenStatusEnabled { - if cleanToken.Status == model.TokenStatusExpired && cleanToken.ExpiredTime <= helper.GetTimestamp() && cleanToken.ExpiredTime != -1 { + + switch token.Status { + case model.TokenStatusEnabled: + if cleanToken.Status == model.TokenStatusExpired && + cleanToken.ExpiredTime <= helper.GetTimestamp() && cleanToken.ExpiredTime != -1 && + token.ExpiredTime != -1 && token.ExpiredTime < helper.GetTimestamp() { c.JSON(http.StatusOK, gin.H{ "success": false, "message": "令牌已过期,无法启用,请先修改令牌过期时间,或者设置为永不过期", }) return } - if cleanToken.Status == model.TokenStatusExhausted && cleanToken.RemainQuota <= 0 && !cleanToken.UnlimitedQuota { + if cleanToken.Status == model.TokenStatusExhausted && + cleanToken.RemainQuota <= 0 && !cleanToken.UnlimitedQuota && + token.RemainQuota <= 0 && !token.UnlimitedQuota { c.JSON(http.StatusOK, gin.H{ "success": false, "message": "令牌可用额度已用尽,无法启用,请先修改令牌剩余额度,或者设置为无限额度", }) return } + case model.TokenStatusExhausted: + if token.RemainQuota > 0 || token.UnlimitedQuota { + token.Status = model.TokenStatusEnabled + } + case model.TokenStatusExpired: + if token.ExpiredTime == -1 || token.ExpiredTime > helper.GetTimestamp() { + token.Status = model.TokenStatusEnabled + } } + if statusOnly != "" { cleanToken.Status = token.Status } else { @@ -239,6 +255,8 @@ func UpdateToken(c *gin.Context) { cleanToken.UnlimitedQuota = token.UnlimitedQuota cleanToken.Models = token.Models cleanToken.Subnet = token.Subnet + cleanToken.RemainQuota = token.RemainQuota + cleanToken.Status = token.Status } err = cleanToken.Update() if err != nil { diff --git a/monitor/manage.go b/monitor/manage.go index 44c13612d3..268d3924ec 100644 --- a/monitor/manage.go +++ b/monitor/manage.go @@ -34,7 +34,7 @@ func ShouldDisableChannel(err *model.Error, statusCode int) bool { strings.Contains(lowerMessage, "credit") || strings.Contains(lowerMessage, "balance") || strings.Contains(lowerMessage, "permission denied") || - strings.Contains(lowerMessage, "organization has been restricted") || // groq + strings.Contains(lowerMessage, "organization has been restricted") || // groq strings.Contains(lowerMessage, "已欠费") { return true } diff --git a/relay/adaptor/anthropic/constants.go b/relay/adaptor/anthropic/constants.go index cb574706d4..ab0b91480b 100644 --- a/relay/adaptor/anthropic/constants.go +++ b/relay/adaptor/anthropic/constants.go @@ -4,10 +4,10 @@ var ModelList = []string{ "claude-instant-1.2", "claude-2.0", "claude-2.1", "claude-3-haiku-20240307", "claude-3-5-haiku-20241022", + "claude-3-5-haiku-latest", "claude-3-sonnet-20240229", - "claude-3-opus-20240229", "claude-3-5-sonnet-20240620", "claude-3-5-sonnet-20241022", "claude-3-5-sonnet-latest", - "claude-3-5-haiku-20241022", + "claude-3-opus-20240229", } diff --git a/relay/adaptor/ollama/main.go b/relay/adaptor/ollama/main.go index 43317ff66f..fa1b05f0c5 100644 --- a/relay/adaptor/ollama/main.go +++ b/relay/adaptor/ollama/main.go @@ -31,8 +31,8 @@ func ConvertRequest(request model.GeneralOpenAIRequest) *ChatRequest { TopP: request.TopP, FrequencyPenalty: request.FrequencyPenalty, PresencePenalty: request.PresencePenalty, - NumPredict: request.MaxTokens, - NumCtx: request.NumCtx, + NumPredict: request.MaxTokens, + NumCtx: request.NumCtx, }, Stream: request.Stream, } @@ -122,7 +122,7 @@ func StreamHandler(c *gin.Context, resp *http.Response) (*model.ErrorWithStatusC for scanner.Scan() { data := scanner.Text() if strings.HasPrefix(data, "}") { - data = strings.TrimPrefix(data, "}") + "}" + data = strings.TrimPrefix(data, "}") + "}" } var ollamaResponse ChatResponse diff --git a/relay/adaptor/vertexai/gemini/adapter.go b/relay/adaptor/vertexai/gemini/adapter.go index ceff1ed2a0..f86baee0e2 100644 --- a/relay/adaptor/vertexai/gemini/adapter.go +++ b/relay/adaptor/vertexai/gemini/adapter.go @@ -15,7 +15,7 @@ import ( ) var ModelList = []string{ - "gemini-1.5-pro-001", "gemini-1.5-flash-001", "gemini-pro", "gemini-pro-vision", "gemini-1.5-pro-002", "gemini-1.5-flash-002", + "gemini-1.5-pro-001", "gemini-1.5-flash-001", "gemini-pro", "gemini-pro-vision", "gemini-1.5-pro-002", "gemini-1.5-flash-002", } type Adaptor struct { diff --git a/relay/billing/ratio/model.go b/relay/billing/ratio/model.go index 1b58ec0902..cd87fecb61 100644 --- a/relay/billing/ratio/model.go +++ b/relay/billing/ratio/model.go @@ -80,10 +80,13 @@ var ModelRatio = map[string]float64{ "claude-2.1": 8.0 / 1000 * USD, "claude-3-haiku-20240307": 0.25 / 1000 * USD, "claude-3-5-haiku-20241022": 1.0 / 1000 * USD, + "claude-3-5-haiku-latest": 1.0 / 1000 * USD, "claude-3-sonnet-20240229": 3.0 / 1000 * USD, "claude-3-5-sonnet-20240620": 3.0 / 1000 * USD, "claude-3-5-sonnet-20241022": 3.0 / 1000 * USD, + "claude-3-5-sonnet-latest": 3.0 / 1000 * USD, "claude-3-opus-20240229": 15.0 / 1000 * USD, + "claude-3-opus-latest": 15.0 / 1000 * USD, // https://cloud.baidu.com/doc/WENXINWORKSHOP/s/hlrk4akp7 "ERNIE-4.0-8K": 0.120 * RMB, "ERNIE-3.5-8K": 0.012 * RMB,