mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-11-02 14:53:41 +08:00
Compare commits
5 Commits
v0.4.7-alp
...
v0.4.7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6b1a24d650 | ||
|
|
94ba3dd024 | ||
|
|
f6eb4e5628 | ||
|
|
57bd907f83 | ||
|
|
dd8e8d5ee8 |
@@ -32,6 +32,9 @@ func GetSubscription(c *gin.Context) {
|
|||||||
if common.DisplayInCurrencyEnabled {
|
if common.DisplayInCurrencyEnabled {
|
||||||
amount /= common.QuotaPerUnit
|
amount /= common.QuotaPerUnit
|
||||||
}
|
}
|
||||||
|
if token != nil && token.UnlimitedQuota {
|
||||||
|
amount = 99999999.9999
|
||||||
|
}
|
||||||
subscription := OpenAISubscriptionResponse{
|
subscription := OpenAISubscriptionResponse{
|
||||||
Object: "billing_subscription",
|
Object: "billing_subscription",
|
||||||
HasPaymentMethod: true,
|
HasPaymentMethod: true,
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"io"
|
"io"
|
||||||
@@ -29,6 +30,25 @@ func relayTextHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode {
|
|||||||
if relayMode == RelayModeModeration && textRequest.Model == "" {
|
if relayMode == RelayModeModeration && textRequest.Model == "" {
|
||||||
textRequest.Model = "text-moderation-latest"
|
textRequest.Model = "text-moderation-latest"
|
||||||
}
|
}
|
||||||
|
// request validation
|
||||||
|
if textRequest.Model == "" {
|
||||||
|
return errorWrapper(errors.New("model is required"), "required_field_missing", http.StatusBadRequest)
|
||||||
|
}
|
||||||
|
switch relayMode {
|
||||||
|
case RelayModeCompletions:
|
||||||
|
if textRequest.Prompt == "" {
|
||||||
|
return errorWrapper(errors.New("prompt is required"), "required_field_missing", http.StatusBadRequest)
|
||||||
|
}
|
||||||
|
case RelayModeChatCompletions:
|
||||||
|
if len(textRequest.Messages) == 0 {
|
||||||
|
return errorWrapper(errors.New("messages is required"), "required_field_missing", http.StatusBadRequest)
|
||||||
|
}
|
||||||
|
case RelayModeEmbeddings:
|
||||||
|
case RelayModeModeration:
|
||||||
|
if textRequest.Input == "" {
|
||||||
|
return errorWrapper(errors.New("input is required"), "required_field_missing", http.StatusBadRequest)
|
||||||
|
}
|
||||||
|
}
|
||||||
baseURL := common.ChannelBaseURLs[channelType]
|
baseURL := common.ChannelBaseURLs[channelType]
|
||||||
requestURL := c.Request.URL.String()
|
requestURL := c.Request.URL.String()
|
||||||
if c.GetString("base_url") != "" {
|
if c.GetString("base_url") != "" {
|
||||||
@@ -139,17 +159,25 @@ func relayTextHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode {
|
|||||||
if ratio != 0 && quota <= 0 {
|
if ratio != 0 && quota <= 0 {
|
||||||
quota = 1
|
quota = 1
|
||||||
}
|
}
|
||||||
|
totalTokens := promptTokens + completionTokens
|
||||||
|
if totalTokens == 0 {
|
||||||
|
// in this case, must be some error happened
|
||||||
|
// we cannot just return, because we may have to return the pre-consumed quota
|
||||||
|
quota = 0
|
||||||
|
}
|
||||||
quotaDelta := quota - preConsumedQuota
|
quotaDelta := quota - preConsumedQuota
|
||||||
err := model.PostConsumeTokenQuota(tokenId, quotaDelta)
|
err := model.PostConsumeTokenQuota(tokenId, quotaDelta)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.SysError("error consuming token remain quota: " + err.Error())
|
common.SysError("error consuming token remain quota: " + err.Error())
|
||||||
}
|
}
|
||||||
tokenName := c.GetString("token_name")
|
if quota != 0 {
|
||||||
logContent := fmt.Sprintf("模型倍率 %.2f,分组倍率 %.2f", modelRatio, groupRatio)
|
tokenName := c.GetString("token_name")
|
||||||
model.RecordConsumeLog(userId, promptTokens, completionTokens, textRequest.Model, tokenName, quota, logContent)
|
logContent := fmt.Sprintf("模型倍率 %.2f,分组倍率 %.2f", modelRatio, groupRatio)
|
||||||
model.UpdateUserUsedQuotaAndRequestCount(userId, quota)
|
model.RecordConsumeLog(userId, promptTokens, completionTokens, textRequest.Model, tokenName, quota, logContent)
|
||||||
channelId := c.GetInt("channel_id")
|
model.UpdateUserUsedQuotaAndRequestCount(userId, quota)
|
||||||
model.UpdateChannelUsedQuota(channelId, quota)
|
channelId := c.GetInt("channel_id")
|
||||||
|
model.UpdateChannelUsedQuota(channelId, quota)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user