feat: support tts model (#713)

* Added support for Text-to-Speech models and
endpoints

* chore: update impl

---------

Co-authored-by: JustSong <songquanpeng@foxmail.com>
This commit is contained in:
ckt1031
2023-11-17 21:18:51 +08:00
committed by GitHub
parent 1d15157f7d
commit ddcaf95f5f
7 changed files with 151 additions and 66 deletions

View File

@@ -1,6 +1,7 @@
package controller
import (
"context"
"encoding/json"
"fmt"
"github.com/gin-gonic/gin"
@@ -8,6 +9,7 @@ import (
"io"
"net/http"
"one-api/common"
"one-api/model"
"strconv"
"strings"
)
@@ -186,3 +188,20 @@ func getFullRequestURL(baseURL string, requestURL string, channelType int) strin
}
return fullRequestURL
}
func postConsumeQuota(ctx context.Context, tokenId int, quota int, userId int, channelId int, modelRatio float64, groupRatio float64, modelName string, tokenName string) {
err := model.PostConsumeTokenQuota(tokenId, quota)
if err != nil {
common.SysError("error consuming token remain quota: " + err.Error())
}
err = model.CacheUpdateUserQuota(userId)
if err != nil {
common.SysError("error update user quota cache: " + err.Error())
}
if quota != 0 {
logContent := fmt.Sprintf("模型倍率 %.2f,分组倍率 %.2f", modelRatio, groupRatio)
model.RecordConsumeLog(ctx, userId, channelId, 0, 0, modelName, tokenName, quota, logContent)
model.UpdateUserUsedQuotaAndRequestCount(userId, quota)
model.UpdateChannelUsedQuota(channelId, quota)
}
}