mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-09-18 09:36:37 +08:00
fix: Switch to channel-ratio
- Use channel ratios instead of group ratios in all applicable places - Start using the lowest channel ratio of the specified channel's groups
This commit is contained in:
parent
ba827b95e3
commit
dbe3930a8c
@ -85,6 +85,16 @@ func Distribute() func(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func SetupContextForSelectedChannel(c *gin.Context, channel *model.Channel, modelName string) {
|
func SetupContextForSelectedChannel(c *gin.Context, channel *model.Channel, modelName string) {
|
||||||
|
// set minimal group ratio as channel_ratio
|
||||||
|
var minimalRatio float64
|
||||||
|
for _, grp := range strings.Split(channel.Group, ",") {
|
||||||
|
v := common.GetGroupRatio(grp)
|
||||||
|
if minimalRatio == 0 || v < minimalRatio {
|
||||||
|
minimalRatio = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c.Set("channel_ratio", minimalRatio)
|
||||||
|
|
||||||
c.Set("channel", channel.Type)
|
c.Set("channel", channel.Type)
|
||||||
c.Set("channel_id", channel.Id)
|
c.Set("channel_id", channel.Id)
|
||||||
c.Set("channel_name", channel.Name)
|
c.Set("channel_name", channel.Name)
|
||||||
|
@ -28,7 +28,7 @@ func RelayAudioHelper(c *gin.Context, relayMode int) *relaymodel.ErrorWithStatus
|
|||||||
channelType := c.GetInt("channel")
|
channelType := c.GetInt("channel")
|
||||||
channelId := c.GetInt("channel_id")
|
channelId := c.GetInt("channel_id")
|
||||||
userId := c.GetInt("id")
|
userId := c.GetInt("id")
|
||||||
group := c.GetString("group")
|
// group := c.GetString("group")
|
||||||
tokenName := c.GetString("token_name")
|
tokenName := c.GetString("token_name")
|
||||||
|
|
||||||
var ttsRequest openai.TextToSpeechRequest
|
var ttsRequest openai.TextToSpeechRequest
|
||||||
@ -47,7 +47,8 @@ func RelayAudioHelper(c *gin.Context, relayMode int) *relaymodel.ErrorWithStatus
|
|||||||
}
|
}
|
||||||
|
|
||||||
modelRatio := common.GetModelRatio(audioModel)
|
modelRatio := common.GetModelRatio(audioModel)
|
||||||
groupRatio := common.GetGroupRatio(group)
|
// groupRatio := common.GetGroupRatio(group)
|
||||||
|
groupRatio := c.GetFloat64("channel_ratio")
|
||||||
ratio := modelRatio * groupRatio
|
ratio := modelRatio * groupRatio
|
||||||
var quota int
|
var quota int
|
||||||
var preConsumedQuota int
|
var preConsumedQuota int
|
||||||
|
@ -6,15 +6,16 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/songquanpeng/one-api/common"
|
"github.com/songquanpeng/one-api/common"
|
||||||
"github.com/songquanpeng/one-api/common/logger"
|
"github.com/songquanpeng/one-api/common/logger"
|
||||||
"github.com/songquanpeng/one-api/model"
|
"github.com/songquanpeng/one-api/model"
|
||||||
"github.com/songquanpeng/one-api/relay/channel/openai"
|
"github.com/songquanpeng/one-api/relay/channel/openai"
|
||||||
relaymodel "github.com/songquanpeng/one-api/relay/model"
|
relaymodel "github.com/songquanpeng/one-api/relay/model"
|
||||||
"github.com/songquanpeng/one-api/relay/util"
|
"github.com/songquanpeng/one-api/relay/util"
|
||||||
"io"
|
|
||||||
"net/http"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
@ -37,7 +38,7 @@ func RelayImageHelper(c *gin.Context, relayMode int) *relaymodel.ErrorWithStatus
|
|||||||
channelType := c.GetInt("channel")
|
channelType := c.GetInt("channel")
|
||||||
channelId := c.GetInt("channel_id")
|
channelId := c.GetInt("channel_id")
|
||||||
userId := c.GetInt("id")
|
userId := c.GetInt("id")
|
||||||
group := c.GetString("group")
|
// group := c.GetString("group")
|
||||||
|
|
||||||
var imageRequest openai.ImageRequest
|
var imageRequest openai.ImageRequest
|
||||||
err := common.UnmarshalBodyReusable(c, &imageRequest)
|
err := common.UnmarshalBodyReusable(c, &imageRequest)
|
||||||
@ -131,7 +132,8 @@ func RelayImageHelper(c *gin.Context, relayMode int) *relaymodel.ErrorWithStatus
|
|||||||
}
|
}
|
||||||
|
|
||||||
modelRatio := common.GetModelRatio(imageModel)
|
modelRatio := common.GetModelRatio(imageModel)
|
||||||
groupRatio := common.GetGroupRatio(group)
|
// groupRatio := common.GetGroupRatio(group)
|
||||||
|
groupRatio := c.GetFloat64("channel_ratio")
|
||||||
ratio := modelRatio * groupRatio
|
ratio := modelRatio * groupRatio
|
||||||
userQuota, err := model.CacheGetUserQuota(userId)
|
userQuota, err := model.CacheGetUserQuota(userId)
|
||||||
|
|
||||||
|
@ -35,7 +35,8 @@ func RelayTextHelper(c *gin.Context) *model.ErrorWithStatusCode {
|
|||||||
meta.ActualModelName = textRequest.Model
|
meta.ActualModelName = textRequest.Model
|
||||||
// get model ratio & group ratio
|
// get model ratio & group ratio
|
||||||
modelRatio := common.GetModelRatio(textRequest.Model)
|
modelRatio := common.GetModelRatio(textRequest.Model)
|
||||||
groupRatio := common.GetGroupRatio(meta.Group)
|
// groupRatio := common.GetGroupRatio(meta.Group)
|
||||||
|
groupRatio := meta.ChannelRatio
|
||||||
ratio := modelRatio * groupRatio
|
ratio := modelRatio * groupRatio
|
||||||
// pre-consume quota
|
// pre-consume quota
|
||||||
promptTokens := getPromptTokens(textRequest, meta.Mode)
|
promptTokens := getPromptTokens(textRequest, meta.Mode)
|
||||||
|
@ -26,6 +26,7 @@ type RelayMeta struct {
|
|||||||
ActualModelName string
|
ActualModelName string
|
||||||
RequestURLPath string
|
RequestURLPath string
|
||||||
PromptTokens int // only for DoResponse
|
PromptTokens int // only for DoResponse
|
||||||
|
ChannelRatio float64
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetRelayMeta(c *gin.Context) *RelayMeta {
|
func GetRelayMeta(c *gin.Context) *RelayMeta {
|
||||||
@ -43,6 +44,7 @@ func GetRelayMeta(c *gin.Context) *RelayMeta {
|
|||||||
APIKey: strings.TrimPrefix(c.Request.Header.Get("Authorization"), "Bearer "),
|
APIKey: strings.TrimPrefix(c.Request.Header.Get("Authorization"), "Bearer "),
|
||||||
Config: nil,
|
Config: nil,
|
||||||
RequestURLPath: c.Request.URL.String(),
|
RequestURLPath: c.Request.URL.String(),
|
||||||
|
ChannelRatio: c.GetFloat64("channel_ratio"),
|
||||||
}
|
}
|
||||||
if meta.ChannelType == common.ChannelTypeAzure {
|
if meta.ChannelType == common.ChannelTypeAzure {
|
||||||
meta.APIVersion = GetAzureAPIVersion(c)
|
meta.APIVersion = GetAzureAPIVersion(c)
|
||||||
|
Loading…
Reference in New Issue
Block a user